<?php

/*
'**************************************************************************************************
' 程序名称: CCTVAI开源音乐管理系统
' 官方网站: http://www.cctvai.com
' 联系 Q Q: 1542367792
' QQ交流群：136687984
' 版本：(终结版)
' 备注：未经书面授权，不得向任何第三方提供本软件系统！
' 功能，模板，插件，扩展，定制请联系QQ：1542367792
'**************************************************************************************************
*/
error_reporting(0);
include "../../include/cctvai.conn.php";
include "../function_common.php";
admincheck(4);
/*if(Smallfivesolution()==$_SERVER['SERVER_NAME']) {
} else {
	echo Smallfivesq();
	exit();
}*/
$action=SafeRequest("action", "get");
$CD_ClassID=SafeRequest("CD_ClassID", "get");
?>
<!DOCTYPE html>
<html>
 <head> 
  <meta charset="gbk" /> 
  <meta name="renderer" content="webkit" /> 
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> 
  <title>后台管理中心</title> 
  <link href="../css/add.css" rel="stylesheet" /> 
  <script type="text/javascript" src="../js/ajax.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/space/layer/jquery.js"></script> 
  <script type="text/javascript" src="<?php echo cd_webpath?>user/static/space/layer/lib.js"></script> 
  <script type="text/javascript">
var pop = {
	up : function (text, url, width, height, top) {
		$.layer({
			type : 2,
			maxmin : true,
			title : text,
			iframe : {
				src : url
			},
			area : [width, height],
			offset : [top, '50%'],
			shade : [0]
		});
	}
}
function MM_jumpMenu(targ, selObj, restore) { //v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore)
		selObj.selectedIndex = 0;
}
</script> 
  <style type="text/css">
.table2{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table2 td{font-size: 12px;border-top: 1px solid #ddd;padding: 8px;vertical-align: top;}
.table2 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table2 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
.table3{width: 100%;max-width: 100%;border-collapse: collapse;border-spacing: 0;}
.table3 tr:hover{text-decoration: none;background-color: #e6f2fb;}
.table3 td{font-size: 12px;line-height:25px;border-top: 1px solid #ddd;padding: 5px;vertical-align: top;border-right: solid 1px #ddd;}
.table3 th{border-bottom: 2px solid #ddd;vertical-align: bottom;padding: 2px;text-align: left;}
</style> 
<script type="text/javascript">
function CheckAll(form){
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.name != 'chkall')
			e.checked = form.chkall.checked;
	}
}
function MM_jumpMenu(targ, selObj, restore) { //v3.0
	eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore)
		selObj.selectedIndex = 0;
}
</script>
 </head> 
 <body> 
<?php
switch($action){
	case 'del':
		del();
		break;
	case 'alldel':
		alldel();
		break;
		break;
	case 'keyword':
		$key=SafeRequest("key","get");
		main("select * from ".tname('pic')." where cd_uid='".$key."' order by cd_addtime desc",20);
		break;
	default:
		main("select * from ".tname('pic')." order by cd_id desc",20);
		break;
	}
?>
 </body>
</html>
<?php
Function main($sql,$size){
global $db;
$Arr=getpagerow($sql,$size);//sql,每页显示条数
$result=$db->query($Arr[2]);
$videonum=$db->num_rows($result);
?>
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head">
     <strong>所有相册照片</strong>
    </div> 
  <form method="get" action="album.php"> 
   <div class="search_type cc mb10"> 
    <div class="ul_wrap"> 
     <ul class="cc"> 
      <li> <label>关键字：</label> <input type="hidden" name="action" value="keyword" /> <input name="key" id="key" value="" type="text" class="input length_3" placeholder="支持帐号ID搜索" /> &nbsp;&nbsp;<button class="btn mr20" type="submit">搜索</button> </li> 
     </ul> 
    </div> 
   </div> 
  </form>
<form name="form" method="post" action="?action=alldel">
    <table class="table2" id="dellist"> 
     <tbody>
      <tr>
       <td width="100" align="left"> 序号</td>
       <td align="left">照片</td>
	   <td align="left">标题</td>
	   <td align="left">上传用户</td>
	   <td align="left">上传时间</td>
	   <td width="60" align="left">操作</td>
      </tr>
<?php
if($videonum==0) echo "<tr><td height='30' colspan='12' align='center' bgcolor='#FFFFFF' class='td_border'><br><br>没有数据<br><br><br></td></tr>";
if($result){
while ($row = $db ->fetch_array($result)){
?>
      <tr>
       <td width="100" align="left"> <input class="checkbox" type="checkbox" name="cd_id[]" id="cd_id" value="<?php echo $row['cd_id']; ?>"><?php echo $row['cd_id']; ?></td>
       <td align="left"><a href="<?php echo getalbumthumb($row['cd_url'], 0)?>" title="查看图片" target="_blank"><img width="80" height="60" src="<?php echo getalbumthumb($row['cd_url'], 1)?>"></a></td>
	   <td align="left"><?php echo str_checkhtml($row['cd_title'])?></a></td>
	   <td align="left"><a href="?action=keyword&key=<?php echo $row['cd_uid']; ?>"><?php echo GetAlias("cctvai_user", "cd_nicheng", "cd_id", $row['cd_uid'])?>(<?php echo GetAlias("cctvai_user", "cd_name", "cd_id", $row['cd_uid'])?>)</a></td>
	   <td align="left"><?php echo datetime(date('Y-m-d H:i:s',$row['cd_addtime'])); ?></td>
	   <td width="60" align="left"><a href="?action=del&cd_id=<?php echo $row['cd_id']; ?>" class="btn" onClick="return confirm('确定要删除吗？不可恢复！');">删除</a></td>
      </tr>
<?php
}
}
?> 
       <tr> 
        <td height="35" colspan="12" align="left" bgcolor="#FAFBF7" class="td_border"><input type="checkbox" id="chkall" class="checkbox" onClick="CheckAll(this.form)" /><label for="chkall">全选</label> &nbsp;&nbsp; <input type="submit" name="alldel" class="btn btn_submit J_ajax_submit_btn" value="批量删除" onClick="{if(confirm('确定要删除吗？不可恢复！')){this.document.form.submit();return true;}return false;}" /></td> 
       </tr> 
     </tbody>
    </table> 
</form>
   </div> 
   </div> 
<div class="p10" style="margin-bottom: 0px;">
<div class="pages"><?php echo $Arr[0];?></div>
</div>
 </body>
</html>
<?php			
}
//删除
function del()
{
    global $db;
    $cd_id=SafeRequest("cd_id", "get");
    $sqls="select * from " . tname('pic') . " where cd_id=" . $cd_id;
    if($row=$db->getrow($sqls)) {
		@unlink(_cctvai_root_ . getalbumthumb($row['cd_url'], 0));
		@unlink(_cctvai_root_ . getalbumthumb($row['cd_url'], 1));
		@unlink(_cctvai_root_ . getalbumthumb($row['cd_url'], 2));
		$db->query("delete from " . tname('pic') . " where cd_id=" . $cd_id . "");
		$db->query("update " . tname('user') . " set cd_points=cd_points-" . cd_userdeletepicpoints . ",cd_rank=cd_rank-" . cd_userdeletepicrank . " where cd_id='" . $row['cd_uid'] . "'");
        if(cd_userdeletepicpoints >= 1) {
            $setarr=array(
                'cd_type'=>0,
                'cd_uid'=>$row['cd_uid'],
                'cd_uname'=>GetAlias("cctvai_user", "cd_name", "cd_id", $row['cd_uid']),
                'cd_icon'=>'album',
                'cd_title'=>'照片被删除',
                'cd_points'=>cd_userdeletepicpoints,
                'cd_state'=>0,
                'cd_addtime'=>date('Y-m-d H:i:s'),
                'cd_endtime'=>date('Y-m-d H:i:s')
            );
            inserttable('bill', $setarr, 1);
        }
		showmessage("恭喜您，删除成功！", "album.php", 0);
    }else{
		showmessage("删除失败，数据不存在！", "album.php", 0);
	}
}
//批量删除
function alldel()
{
    global $db;
    $cd_id=RequestBox("cd_id");
    if($cd_id == 0) {
        showmessage("出错了，请先勾选要删除的照片", "album.php", 0);
    } else {
		$query=$db->query("select cd_url from " . tname('pic') . " where cd_id in ($cd_id)");
		while($row=$db->fetch_array($query)) {
					@unlink(_cctvai_root_ . getalbumthumb($row['cd_url'], 0));
					@unlink(_cctvai_root_ . getalbumthumb($row['cd_url'], 1));
					@unlink(_cctvai_root_ . getalbumthumb($row['cd_url'], 2));
		}
		$db->query("delete from " . tname('pic') . " where cd_id in ($cd_id)");
        showmessage("恭喜您，删除成功！", "album.php", 0);
    }
}
?>