<?php
error_reporting(0);
include "../../../include/cctvai.conn.php";
include "../../function_common.php";
admincheck(9);
$action=SafeRequest("action", "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="/user/static/space/layer/jquery.js"></script> 
  <script type="text/javascript" src="/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>
 </head>   
 <body> 
<?php
switch($action) {
	case 'add':
		Add();
		break;
	case 'saveadd':
		SaveAdd();
		break;
	case 'edit':
		Edit();
		break;
	case 'saveedit':
		SaveEdit();
		break;
	case 'del':
		Del();
		break;
	default:
		main("select * from " . tname('myppt') . " order by cd_order asc", 30);
		break;
}
?>
</body>
</html>
<?php
Function EditBoard($Arr, $url)
{
    $cd_order=$Arr[0];
    $cd_title=$Arr[1];
    $cd_pic=$Arr[2];
    $cd_url=$Arr[3];
	$cd_word=$Arr[4];
?>
<div class="contents"> 
   <div class="panel"> 
    <div style="padding: 8px;"> 
     <a href="index.php" class="btn btn-default">幻灯片设置</a> 
     <a href="myppt.php" class="btn btn-default">幻灯片列表</a> 
     <a href="myppt.php?action=add" class="btn btn_success"><?php if($_GET['action']=="add"){echo"添加";}else{echo"编辑";}?>幻灯片</a> 
    </div> 
   </div> 
  </div> 
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong><?php if($_GET['action']=="add"){echo"添加";}else{echo"编辑";}?>幻灯片</strong> 
    </div> 
    <form action="<?php echo $url?>" method="post" name="form2"> 
     <table class="table3"> 
      <tbody> 
       <tr> 
        <td width="90" align="left" class="p10">排 序</td> 
        <td align="left"> <input type="text" class="input input_hd length_1" value="<?php echo $cd_order?>" name="cd_order" id="cd_order" />　 </td> 
       </tr> 
       <tr> 
        <td align="left" class="p10">幻灯片名称</td> 
        <td align="left"> <input type="text" class="input input_hd length_6" value="<?php echo $cd_title?>" name="cd_title" id="cd_title" /></td> 
       </tr> 
       <tr> 
        <td align="left" class="p10">幻灯片图片</td> 
        <td align="left"> <input type="text" class="input input_hd length_5" value="<?php echo $cd_pic?>" name="cd_pic"/><input type="hidden" name="cd_jpic" id="cd_jpic" value="<?php echo $cd_pic?>" /> 
		<button type="button" onClick="pop.up('上传图片', '../../upload/?ac=dancepic&f=form2.cd_pic', '406px', '180px', '140px');" class="btn">上传图片</button></td> 
       </tr> 
       <tr> 
        <td align="left" class="p10">幻灯片地址</td> 
        <td align="left"> <input type="text" class="input input_hd length_5" value="<?php echo $cd_url?>" name="cd_url" id="cd_url" /></td> 
       </tr> 
       <tr> 
        <td align="left">幻灯片介绍</td> 
        <td align="left"><textarea class="length_6" name="cd_word" style="line-height:25px;font-size:16px;"><?php echo $cd_word?></textarea></td>
       </tr> 
       <tr> 
        <td height="35" colspan="2" align="left" bgcolor="#FAFBF7" class="td_border">
<button type="submit" name="form2" class="btn btn_submit J_ajax_submit_btn" style="margin-left: 100px;" onClick="return CheckForm();">确定提交</button>
　<a href="myppt.php" class="btn btn-default">返回幻灯片列表</a>
</td>
       </tr> 
      </tbody> 
     </table> 
    </form>
   </div> 
  </div>
<?php
}
Function main($sql, $size)
{
 global $db;
 $Arr=getpagerow($sql, $size);
 $result=$db->query($Arr[2]);
 $videonum=$db->num_rows($result);
?><div class="contents"> 
   <div class="panel"> 
    <div style="padding: 8px;"> 
     <a href="index.php" class="btn btn-default">幻灯片设置</a> 
     <a href="myppt.php" class="btn btn_success">幻灯片列表</a> 
     <a href="myppt.php?action=add" class="btn btn-default">添加幻灯片</a> 
    </div> 
   </div> 
  </div> 
  <div class="contents"> 
   <div class="panel"> 
    <div class="panel-head"> 
     <strong>幻灯片管理</strong> 
    </div>  
    <table class="table2"> 
     <tbody> 
      <tr> 
       <td width="30" align="left">序号</td> 
       <td align="left">幻灯片名称</td> 
       <td align="left">图片地址</td> 
       <td align="left">链接地址</td> 
       <td width="120" align="left">操作</td> 
      </tr> 
<?php
if($videonum==0)
	echo "<tr><td height='30' colspan='5' align='center' bgcolor='#FFFFFF' class='td_border'>没有数据</td></tr>";
if($result) {
	while($row=$db->fetch_array($result)) {
?> 
      <tr> 
       <td align="left"> <?php echo $row['cd_order']?></td> 
       <td align="left"><?php echo $row['cd_title']?></td>
       <td align="left"><?php echo $row['cd_pic']?></td>  
       <td align="left"><?php echo $row['cd_url']?></td> 
       <td align="left"><a class="btn" href="?action=edit&cd_id=<?php echo $row['cd_id']?>">编辑</a> <a class="btn" href="?action=del&cd_id=<?php echo $row['cd_id']?>" onClick="return confirm('确定将链接删除吗?');">删除</a></td> 
      </tr>  
<?php
}}
?> 
     </tbody> 
    </table> 
   </div> 
  </div> 
<?php			
}
function Del() {
	global $db;
	$cd_id=SafeRequest("cd_id", "get");
	$row=$db->Getrow("Select cd_pic from " . tname('myppt') . " where cd_id=$cd_id");
	$sql="delete from " . tname('myppt') . " where cd_id=$cd_id";
	if($db->query($sql)) {
		if(delunlink($row['cd_pic']) == true) {@unlink(_cctvai_root_ . $row['cd_pic']);}
		die("<script>window.location='" . $_SERVER['HTTP_REFERER'] . "'</script>");
	}
}
function Edit() {
	global $db;
	$cd_id=SafeRequest("cd_id", "get");
	$sql="Select * from " . tname('myppt') . " where cd_id=$cd_id";
	if($row=$db->Getrow($sql)) {
		$Arr=array(
			$row['cd_order'],
			$row['cd_title'],
			$row['cd_pic'],
			$row['cd_url'],
			$row['cd_word']
		);
	}
	EditBoard($Arr, "?action=saveedit&cd_id=" . $cd_id . "", "编辑");
}
function Add() {
	$Arr=array("","","","");
	EditBoard($Arr, "?action=saveadd", "添加");
}
function SaveAdd() {
	global $db;
	$cd_order=SafeRequest("cd_order", "post");
	$cd_title=SafeRequest("cd_title", "post");
	$cd_pic=SafeRequest("cd_pic", "post");
	$cd_url=SafeRequest("cd_url", "post");
	$cd_word=SafeRequest("cd_word", "post");
	$setarr=array(
		'cd_order'=>$cd_order,
		'cd_title'=>$cd_title,
		'cd_pic'=>$cd_pic,
		'cd_url'=>$cd_url,
		'cd_word'=>$cd_word
	);
	inserttable('myppt', $setarr, 1);
	showmessage("恭喜您，添加幻灯片成功！", "myppt.php", 0);
}
function SaveEdit() {
	global $db;
	$cd_id=SafeRequest("cd_id", "get");
	$cd_order=SafeRequest("cd_order", "post");
	$cd_title=SafeRequest("cd_title", "post");
	$cd_pic=SafeRequest("cd_pic", "post");
	$cd_jpic=SafeRequest("cd_jpic", "post");
	$cd_url=SafeRequest("cd_url", "post");
	$cd_word=SafeRequest("cd_word", "post");
	if($cd_jpic!==$cd_pic){if(delunlink($cd_jpic) == true) {@unlink(_cctvai_root_ . $cd_jpic);}}
	$setarr=array(
		'cd_order'=>$cd_order,
		'cd_title'=>$cd_title,
		'cd_pic'=>$cd_pic,
		'cd_url'=>$cd_url,
		'cd_word'=>$cd_word
	);
	updatetable('myppt', $setarr, array(
		'cd_id'=>$cd_id
	));
	showmessage("恭喜您，编辑幻灯片成功！", "myppt.php", 0);
}
?>
