<?php
# Name: PHP版程氏文章CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_label.php");
include_once("../loginstate.php");
SystemPer('0_1');
$ac=CS_Request("ac");
$op=CS_Request("op");
$id=CS_Request("id");
?>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>chshdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<link href="../../public/css/webox.css" rel="stylesheet" />
<script type="text/javascript" src="../res/js/ajax.js"></script>
<script language="javascript" src="../res/js/jquery.js"></script>
<script src="../../public/js/webox.js"></script>
<script language="javascript"> 
 
function del(_id){ 
  if (confirm("确定删除吗？")){
    window.location='?op=del&id='+_id;
    return true;
  }else{
     return false;
  }		
}
</script>
</head>
<body>
<div class="wrap">
<div class="h_a">会员相册管理 &nbsp;&nbsp;&nbsp;&nbsp;<?php if($ac=='pic') echo '<a href="?"><font color=#026E12>返回相册</font></a>';?></div>
<?php if($ac=='pic'){ ?>
<form class="J_ajaxForm" action="?ac=pic&op=delall&id=<?php echo $id?>" method="post" name="formb">
<div class="table_list">
		<div class="works_pic">
			<ul id="piclist">
    <?php
	$sql="select * from ".Getdbname('photo')." where cs_cid=".$id."  order by cs_addtime desc";
	$rs=$db->query($sql);
	$num=$db->num_rows($rs);
	for($i=0;$i<$num;$i++){
		$row=$db->fetch_array($rs);	
                $us=$db->getrow("select * from ".Getdbname('user')." where CS_Name='".$row['CS_User']."'");			 
				echo '<ol><div class="pic_list"><a href="'.userlink('pick',$us['CS_ID'],$row['CS_ID']).'" target="web"><img src="'.piclink('pic',$row['CS_Url']).'"  width="110" height="100"/></a><div class="pic_gl"><input type="checkbox" class="J_check" name="CS_ID[]" value="'.$row['CS_ID'].'" id="CS_ID"/> 时间:'.datetime($row['CS_AddTime']).'</div></div></ol>';
        }
    ?>
			</ul>
		</div>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
                <label class="mr20"><input type="checkbox" class="J_check_all" id="chkall" onClick="return CheckAll(this.form)" value="on">全选</label>
		<input name="button1" type="button" class="btn J_ajax_submit_btn" value="批量删除" onClick="DelInfo(this.form)">
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
</form>

<?php 

          //批量删除
          if($op=='delall'){
		global $db;
		$CS_ID=CS_RequestBox("CS_ID");
	        $Arr=explode(',',$CS_ID);
		for($i=0;$i<count($Arr);$i++){
                       $row=$db->getrow("Select * from ".Getdbname('photo')." where cs_id=".$Arr[$i]."");
                        //删除图片
	                $fileurl="../../annex/pic/".$row['CS_Url'];
	                if(file_exists($fileurl)){
	                  @unlink($fileurl);
	                }
			$db->query("delete from ".Getdbname('photo')." where CS_ID=".$Arr[$i]."");
		}
                        echo '<script>document.getElementById("Msg").className="tips_success";$("#Msg").text("恭喜,删除成功!").css("color","#026E12");</script>';
	                echo "<script>setTimeout(\"window.location='pic.php'\",2000);</script>";
          }

}else{ 
?>
<form class="J_ajaxForm" action="?op=delall" method="post" name="formb">
<div class="table_list">
		<div class="album">
<?php
		global $db;
                $sql="select * from ".Getdbname('pic')." order by CS_AddTime desc";
		$dancenum=$db->num_rows($db->query($sql));
		$Arr=getpagerow($sql,20);//sql,每页显示条数
		$result=$db->query($Arr[2]);
		$adminnum=$db->num_rows($result);
	if($adminnum==0){
                   echo '<tr><td class="tac" colspan="6">啊哦，没有符合条件的内容！</td></tr>';
        }else{
                if($result){
	                 while ($row = $db ->fetch_array($result)){
                        $picnum=$db->getRow("select count(CS_ID) as rc from ".Getdbname('photo')." where CS_CID=".$row['CS_ID']."");
?>
			<dl>
						
				<dt><div><a href="?ac=pic&id=<?php echo $row['CS_ID']?>" title="<?php echo $row['CS_Name']?>"><img src="<?php echo piclink('pic',$row['CS_Pic'])?>" width="100" height="100" alt="<?php echo $row['CS_Name']?>" /></a></div></dt>
				<dd><br />
					<strong><a href="?ac=pic&id=<?php echo $row['CS_ID']?>"><?php echo $row['CS_Name']?></a></strong><br />
					会员：<a href="<?php echo userlink('index',getuser('uid',$row['CS_User']))?>" target="web"><?php echo $row['CS_User']?></a><br />
					照片：<?php echo $picnum['rc']?>张<br />
					更新：<?php echo datetime($row['CS_AddTime'])?><br />
					<a href="?ac=pic&id=<?php echo $row['CS_ID']?>">详细</a> | <a style="cursor:pointer;"  onclick="del(<?php echo $row['CS_ID']?>)">删除</a>
				</dd>
			</dl>
<?php
	                 }
                }
        }
?>
	</div>
			<div class="p10">
				<div class="pages">
				     <?php if($dancenum>20) echo $Arr[0];?>
                                </div>
			</div>
</div>
</form>
</div>
<?php 
          //删除
          if($op=='del'){
		global $db;
		$CS_ID=CS_Request("id");
                $picnum=$db->getRow("select count(CS_ID) as rc from ".Getdbname('photo')." where CS_CID=".$id."");
                if($picnum['rc']>0) exit("<script>alert('该相册下有相片数据不能删除，请先移除该相册的相片！');window.location='?ac=pic&id=".$CS_ID."';</script>");
                $row=$db->getrow("Select * from ".Getdbname('pic')." where cs_id=".$CS_ID."");
                $pic=$row['CS_Pic'];
                $sql="delete from ".Getdbname('pic')." where CS_ID=".$CS_ID;
		if($db->query($sql)){
                        //删除图片
	                $fileurl="../../annex/pic/".$pic;
	                if(file_exists($fileurl)){
	                  @unlink($fileurl);
	                }
                        echo '<script>alert("恭喜,删除成功!");</script>';
	                echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",1000);</script>";
		}
          }
?>
<?php } ?>
</div>
</body>
</html>
