⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gallery_ac.php

📁 没用的东西? 国外php免费程序,相册 留言板 等
💻 PHP
字号:
<?php
global $action,$cate,$superName,$_GALLERY;

$this->set('_GALLERY',$_GALLERY);
require_once("../app/files.php");
switch($cate){
	case "save":
		$currentID=p('id');
		$ONE["gName"]=p("picName");
		$ONE["gShow"]=p("picShow");
		$ONE["gCate"]=p("picCate");
		$ONE["gDesc"]=p("picDesc");
		
		//if(!$ONE['gName']) $msg='Picture Name can not be empty.';
		
		require_once("../app/files.php");
		$pic = new uploadPic;
		
		if($currentID!=0){
			$sql="update gallery set gName='".$ONE['gName'][0]."',gDesc='".$ONE['gDesc'][0]."',gShow=".($ONE['gShow'][0]?1:0).",gCate=".$ONE['gCate'][0].",gUpdated=".time();
			
			if($_FILES["pic1"]["name"] != ""){
				$pic->upfile("../".$_GALLERY[0]."/","pic1");
				$iPic = $pic->picname;
				$sqlD="select gImage from gallery where ID=$currentID";
				$imgD=$this->db->get_one($sqlD);
				if($imgD){
					delete_file("../".$_GALLERY[0]."/".$imgD['gImage']);
					delete_file("../".$_GALLERY[0]."/".$_GALLERY[1].$imgD['gImage']);
				}
				makethumb("../".$_GALLERY[0]."/$iPic","../".$_GALLERY[0]."/".$_GALLERY[1].$iPic,$_GALLERY[2],$_GALLERY[3]);
				$sql.=",gImage='$iPic'";
			}
			$sql.=" where ID=$currentID";
			
			$this->db->query($sql,'U_B');
			$title='Picture updated!';
			$msg[]='Picture updated successfully.';
			$msg[]='<a href="index.php?action=gallery">Back to view pictures</a>';
		}
		else{
			$upCount=0;
			for($i=0;$i<count($ONE['gName']);$i++){
				if($ONE['gName'][$i]!=''){
					$pic->upfile("../".$_GALLERY[0]."/","pic".($i+1));
					$iPic = $pic->picname;
					makethumb("../".$_GALLERY[0]."/$iPic","../".$_GALLERY[0]."/".$_GALLERY[1].$iPic,$_GALLERY[2],$_GALLERY[3]);					
					$sql="insert into gallery(gName,gDesc,gShow,gCate,gImage,gCreated) values('".$ONE['gName'][$i]."','".$ONE['gDesc'][$i]."',".($ONE['gShow'][$i]?1:0).",".$ONE['gCate'][$i].",'$iPic',".time().")";
					$this->db->query($sql,'U_B');
					++$upCount;
				}
			}
			
			$title='Picture added!';
			$msg[]='pictures added successfully.';
			$msg[]='<a href="index.php?action=gallery">Back to view pictures</a>';
		}
		
		if(!isset($sql)){$title='Warning!';}
		
		
		$this->set('finalTitle',$title);
		$this->set('msg',$msg);
		$this->set('final','warning');
	break;
	case "add":
		$currentID=g('id');
		$title='Add New Picture';
		
		$ONE=array('ID'=>0,'gName'=>'','gImage'=>'','gShow'=>1,'gCate'=>1,'gDesc'=>'');
		if($currentID){
			$title='Edit Picture';			
			if($result=$this->db->get_one('select * from gallery where id='.$currentID)){
				$ONE['ID']				=$currentID;
				$ONE['gName']			=$result['gName'];
				$ONE['gImage']			=$result['gImage'];
				$ONE['gShow']			=$result['gShow'];
				$ONE['gCate']			=$result['gCate'];
				$ONE['gDesc']			=$result['gDesc'];
			}
			else{
				$msg[]='Picture No. not found.';
				$msg[]='<a href="index.php?action=gallery">Back to view pictures</a>';
			}
		}
		
		if(isset($msg)){
			$this->set('finalTitle','Warning!');
			$this->set('msg',$msg);
			$this->set('final','warning');
		}
		else{
			$this->set('finalTitle',$title);
			$this->set('ONE',$ONE);
			$this->set('final','gallery_edit');
		}
		if($_GALLERY[5]==1){
			$sql = "select ID,gName from gcate";
			$result=$this->db->query($sql);
			while($row=$this->db->fetch_array($result)){
				$gcate[]=array($row['ID'],$row['gName']);
			}
			if(isset($gcate)){
				$this->set('gcate',$gcate);
			}
			else{
				unset($msg);
				$msg[]='You must add an category before you try to add picture';
				$msg[]='<a href="index.php?action=gcate&cate=add">Add New Category</a>';
				$this->set('finalTitle','Warning!');
				$this->set('msg',$msg);
				$this->set('final','warning');
			}
		}
	break;
	case "delete":
		$pid=g('id')?g('id'):(p('id')?join(p('id'),','):false);
		if($pid){
			require_once("../app/files.php");
			$sql="select gImage from gallery where id in($pid)";
			$result=$this->db->query($sql);
			while($row=$this->db->fetch_array($result)){
				delete_file("../".$_GALLERY[0]."/".$row['gImage']);
				delete_file("../".$_GALLERY[0]."/".$_GALLERY[1].$row['gImage']);
			}
			$sql="delete from gallery where id in($pid)";
			$this->db->query($sql,'U_B');
			$msg[]='Pictures deleted successfully.';
			$msg[]='<a href="index.php?action=gallery">Back to view pictures</a>';
			$this->set('finalTitle','Pictures deleted!');
			$this->set('msg',$msg);
			$this->set('final','warning');
		}
		else{
			$msg[]='Pictures deleted unsuccessfully';
			$msg[]='<a href="index.php?action=gallery">Back to view pictures</a>';
			$this->set('finalTitle','Warning!');
			$this->set('msg',$msg);
			$this->set('final','warning');
		}
	break;
	default:
		$page[]=25;
		if(g('page')){$page[]=intval(g('page'));}else{$page[]=1;}
		$sql = "select count(id) as amount from gallery"; 
		$result=$this->db->query($sql);
		$row=$this->db->fetch_array($result);
		$amount = $row['amount'];
		if($amount){
			if($amount % $page[0]){$page[]=(int)($amount/$page[0])+1;}else{$page[]=$amount/$page[0];}
			$page[]=$amount;
		}
		else{$page[]=0;$page[]=0;}
		
		$sql = "select id,gName,gImage,gShow,gCate,gCreated from gallery limit ".($page[1]-1)*$page[0].",".$page[0];
		$result=$this->db->query($sql);
		while($row=$this->db->fetch_array($result)){
			$id=$row['id'];
			$name=$row['gName'];
			$show=$row["gShow"]==1?'<font color="#990000">Yes</font>':'No';
			$cate=$row["gCate"];
			$cateName='';
			if($cate!=0){
				$rcate=$this->db->get_one("select gName from gcate where id=$cate");
				if($rcate) $cateName=$rcate['gName'];
			}
			$Times=date('Y-m-d h:i:s',$row['gCreated']);
			$gallery[]=array($id,$name,$show,$cate,$cateName,$Times);
		}
		if(isset($gallery)) $this->set('gallery',$gallery);
		$this->set('page',$page);
		$this->set('finalTitle','View Pictures');
		$this->set('final','gallery');
	break;
}
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -