<?php
require_once(dirname(__FILE__)."/admin_inc.php");
/*******************************************************************************************
' Software name: DJCMS Content Management System
' Version:3.0
' Web: http://www.djcms.net
' Author: 心情(qq:1130731)
' Copyright (C) 2009-2010 DJCMS官方 版权所有
' 法律申明：DJCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'*******************************************************************************************/
checkPower();
viewHead("扩展模块"."-" .$menuList[7][0]);
$action = getForm("action", "get");
switch ($action) {
	case "modifyside" : modifyside();break;
	case "addside" : addside();break;
	case "delside" : delside();break;
	case "sidemoveup" : sidemoveup();break;
	case "sidemovedown" : sidemovedown();break;
	default : main();break;
}

viewFoot();

function main() {
	global $menuList;
?>
<script type="text/javascript">
function upformone(i){
	$('id').value=i,$('item_url').value=$('item_url'+i).value,$('link').value=$('link'+i).value,$('title').value=$('title'+i).value,$('desc').value=$('desc'+i).value;
	$('form1').submit();
}
var _1;
function onUpClick(tg,el){
	_1=el;openWindow2(101,320,25,0);
	var msgDiv=$("msg");
	var _t = tg.offsetTop;
    var _l = tg.offsetLeft;
    while (tg = tg.offsetParent){_t+=tg.offsetTop; _l+=tg.offsetLeft;}
    msgDiv.style.cssText+="border:1px solid #55BBFF;background: #C1E7FF;padding:3px 0px 3px 4px;"
	msgDiv.style.top = (_t-1)+"px";
    msgDiv.style.left = (_l-1)+"px";
	msgDiv.innerHTML='<button type="button" class="btn" style="margin:0 6px 0 0;height:23px;float:right;padding:0;" onclick="closeWin()">关闭</button><iframe src="fckeditor/upload.htm?isslide=1" scrolling="no" topmargin="0" width="270" height="25" marginwidth="0" marginheight="0" frameborder="0" align="center"></iframe>';
}

function onUploadBack(fn){
	if(!!_1) _1.value=fn;
	closeWin();
}
</script>
<div id="append_parent"></div>
<div class="container" id="cpcontainer">
<!--当前导航-->
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<?=$menuList[7][0]?>&nbsp;&raquo;&nbsp;扩展模块';</script>
<table class="tb">
	<tr class="thead"><td colspan="6">幻灯片管理(<em style="color:red">幻灯图片请放在pic/slide目录下，只需将图片名填进来,不需要再填路径</em>)</td></tr>
	<tr>
		<td width="35">ID</td>
		<td width="205">图片</td>
		<td width="145">链接</td>
		<td width="100">标题</td>
		<td width="205">说明</td>
		<td>操作</td>
	</tr>
<form id="form1" name="form1" method="post" action="?action=modifyside" target="hiddensubmit">
<input type="hidden" name="id" id="id" value="" />
<input type="hidden" name="item_url" id="item_url" value="" />
<input type="hidden" name="link" id="link" value="" />
<input type="hidden" name="title" id="title" value="" />
<input type="hidden" name="desc" id="desc" value="" />
</form>
<form id="form2" name="form2" method="post" action="?action=modifyside&method=all">
	<?php
   $query = DB::query("SELECT m_id,m_name,m_pic,m_url,m_des,m_sort FROM ".DB::table('slide')." ORDER BY m_sort ASC");
   while($row = DB::fetch($query)) {
?>
	<tr>
		<td><input type="checkbox" value="<?=$row['m_id']?>" name="id[]" class="checkbox" /><?=$row['m_id']?></td>
		<td><input type="text" name="item_url<?=$row['m_id']?>" value="<?=$row['m_pic']?>" />&nbsp;<button type="button" class="btn" style="width:60px;height:22px;" onclick="onUpClick(this,this.form.elements['item_url<?=$row['m_id']?>'])">浏览...</button></td>
		<td><input type="text" name="link<?=$row['m_id']?>" value="<?=$row['m_url']?>" /></td>
		<td><input type="text" name="title<?=$row['m_id']?>" value="<?=$row['m_name']?>" style="width:100px"/></td>
		<td><input type="text" name="desc<?=$row['m_id']?>" value="<?=$row['m_des']?>" style="width:200px"/></td>
        <td><a href="?action=sidemoveup&id=<?=$row['m_id']?>" target="hiddensubmit">上移</a> <a href="?action=sidemovedown&id=<?=$row['m_id']?>" target="hiddensubmit">下移</a> <a href="javascript://" onclick="upformone(<?=$row['m_id']?>)">修改</a> <a href="?action=delside&id=<?=$row['m_id']?>" onClick="return confirm('确定要删除吗')">删除</a></td>
	</tr>
	<?php };?>
	<tr class="thead"><td colspan="6"><input type="checkbox" class="checkbox" id="chkall" onclick="checkAll(this.checked,'input','id[]')"/>全选 <input type="submit" name="submit" value="修改选中项" class="btn" /></td></tr>
</form>
<form id="form3" name="form3" method="post" action="?action=addside">
	<tr>
		<td>新增</td>
		<td><input type="text" name="item_url" value="" />&nbsp;<button type="button" class="btn" style="width:60px;height:22px;" onclick="onUpClick(this,this.form.elements['item_url'])">浏览...</button></td>
		<td><input type="text" name="link" value="" /></td>
		<td><input type="text" name="title" value="" style="width:100px"/></td>
		<td><input type="text" name="desc" value="" style="width:200px"/></td>
		<td><input type="submit" name="submit" value="确定" class="btn" /></td>
	</tr>
</form>
</table>
<iframe frameborder="0" scrolling="no" height="0" width="0" name="hiddensubmit" id="hiddensubmit" src="about:blank"></iframe>
<?php
}

function sidemoveup() {
	$id=getForm("id","get");
	if (empty($id)) alertMsg("","admin_topic.php");
	$cur = DB::result_first("SELECT m_sort FROM ".DB::table('slide')." WHERE m_id=".$id);
	$cou = DB::result_first("SELECT count(*) FROM ".DB::table('slide')." WHERE m_sort<'$cur'");
	if ($cou > 0) {
	    $flag = DB::result_first("SELECT m_sort FROM ".DB::table('slide')." WHERE m_sort<'$cur' ORDER BY m_sort DESC");
		DB::update('slide', array('m_sort' => $flag),array('m_id' => $id));
	} else {
		DB::query("UPDATE ".DB::table('slide')." SET m_sort=m_sort-1 WHERE m_id='$id'");
	}
	echo "<script>parent.location.reload();</script>";
}


function sidemovedown() {
	$id=getForm("id","get");
	if (empty($id)) alertMsg("","admin_topic.php");
	$cur = DB::result_first("SELECT m_sort FROM ".DB::table('slide')." WHERE m_id=".$id);
	$cou = DB::result_first("SELECT count(*) FROM ".DB::table('slide')." WHERE m_sort>'$cur'");
	if ($cou > 0) {
		$flag = DB::result_first("SELECT m_sort FROM ".DB::table('topic')." WHERE m_sort>'$cur' ORDER BY m_sort DESC");
		DB::update('slide', array('m_sort' => $flag),array('m_id' => $id));
	} else {
		DB::query("UPDATE ".DB::table('slide')." SET m_sort=m_sort+1 WHERE m_id='$id'");
	}
	echo "<script>parent.location.reload();</script>";
}

function modifyside() {
	$method=getForm("method","both");
	$back = getRefer();
	$ids = getForm("id","post");
	if (!empty($ids)) {;
        if ($method == "all") {
		    foreach ($ids as $id) {
				$item_url = getForm("item_url".$id,"post");
				$link = getForm("link".$id,"post");
				$title = getForm("title".$id,"post");
				$desc = getForm("desc".$id,"post");
				$typearr = array(
				'm_name' => $title,
				'm_pic' => $item_url,
				'm_url' => $link,
				'm_des' => $desc,
				);
	            DB::update('slide', $typearr, array('m_id' => $id));
	        }
		    alertMsg("",$back);
	    } else {
		    $item_url = getForm("item_url","post");
			$link = getForm("link","post");
			$title = getForm("title","post");
			$desc = getForm("desc","post");
			$typearr = array(
			'm_name' => $title,
			'm_pic' => $item_url,
			'm_url' => $link,
			'm_des' => $desc,
			);
	        DB::update('slide', $typearr, array('m_id' => $ids));
	        echo "<script>alert('修改成功');parent.location.reload();</script>";
	    }
	    alertMsg("操作成功","admin_expand.php");
	} else {
		alertMsg("没选择要修改的项目","javascript:history.go(-1);");
	}
}

function delside() {
	$id = getForm("id","get");
	DB::delete('slide', array('m_id' => $id));
	alertMsg("",getRefer());
}

function addside() {
	$item_url = getForm("item_url","post");
	$link = getForm("link","post");
	$title = getForm("title","post");
	$desc = getForm("desc","post");
	$typearr = array(
	'm_name' => $title,
	'm_pic' => $item_url,
	'm_url' => $link,
	'm_des' => $desc,
	);
	DB::insert('slide', $typearr);
	alertMsg("操作成功","admin_expand.php");
}
?>
