<?php 
require "../Run.php";
require "../include/getmkurl.fun.php";
   if($admin != 1&&$admin!=2){
     die('您好，你无权进入此页面！');
	 }
echo head('栏目属性修改');
	$mysql = new D('class');
	if($_GET['action'] == 'mod'){
	if(
	$mysql -> where(
	array(
		'cid'=>$_GET['cid'],
		'siteid'=>WAPID
		)
	) -> update(
	array(
		'cn'=>$_POST['cn'],
		'url'=>$_POST['url'],
		'xuhao'=>$_POST['xuhao'],
		'gro'=>$_POST['gro'],
		'list'=>$_POST['list']
		)
		)
	)
	{
		echo "<div class=\"tip\">修改成功</div>\n";
    }
	else
	{
		echo "<div class=\"tip\">修改失败</div>\n";
    }
	$classinfo = lm_info($_GET['cid']);
    echo '<div class="mylink"><a href="http://'.HTTP_HOST.'/indexadmin.php?cid='.$classinfo['gro'].'">排版页面</a></div>';
}elseif($_GET['action'] == 'del'){

	 if($_GET['type']== 'del'){
	 $result = mysql_query("DELETE FROM class WHERE cid='{$_GET["cid"]}'");
	 echo '<div class="subtitle">栏目删除</div>';
	 echo '<div class="tip">';
	 if($result && mysql_affected_rows()>0){
	 echo '成功删除';
	 }else{
     echo "删除失败";
	 }
	 echo '</div>';
	 
	 }else{
	echo '<div class="tip">确定删除此条记录吗？<br><a href="mod_class.php?system=web&action=del&type=del&cid='.$_GET['cid'].'&id='.$_GET['id'].'">[确定，马上删除。]</a></div>';
	echo '<div class="mylink"><a href="mod_class.php?cid='.$_GET['cid'].'">返回栏目修改</a></div>';
	   }
	   
}else{ 
    function mklist($strurl){
      $result = mysql_query("SELECT id,name,url,list,time FROM mkinfo");
      while(list($id,$mk_name,$mk_url,$mk_list,$mk_time) = mysql_fetch_row($result)){
	    $mrc = $strurl == $id ? ' selected="selected" ':'';
	    $html_list.='<option value="'.$id.'" '.$mrc.'>'.$mk_name.$mrt.'</option>';
	
	    }
		return $html_list;
	} 
	function class_list($id){
		$mysql = new D('class');
		$list = $mysql -> where(array('siteid'=>WAPID,'url'=>get_mkid('NULL')))->order('xuhao ASC')->select();
		if($list){
		$i = 0;
			foreach($list as $value)
			{
				$option[$i]['cid'] = $value['cid'];
				$option[$i]['cn'] = $value['cn'];
			$i++;
			}
			
		}
		$option[$i]['cid'] = '0';
		$option[$i]['cn'] = '网站首页';
		foreach($option as $value)
		{
		$id = $id == null ? '0' : $id;
		$sel = $id == $value['cid'] ? ' selected="selected"' : NULL;
		$options .= '<option value="'.$value['cid'].'" '.$sel.'>'.$value['cn'].'</option>';
		}
		return $options;
	}
	$mysql = new D('class');
	$list = $mysql -> where(array('cid'=>$_GET['cid'],'siteid'=>WAPID))->find();
	if($list){
    echo '<div class="title">'.$list['cn'].'(ID'.$list['cid'].')</div>
	
    <form method="post" action="mod_class.php?&action=mod&cid='.$_GET['cid'].'">
    <div class="content">栏目名称<br>
	<input type="text" name="cn" value="'.$list['cn'].'">
	<br>栏目模块<br>
    <select name="url" >
    '.mklist($list['url']).'
    </select>
	<br>栏目序号<br>
    <input type="text" name="xuhao" value="'.$list['xuhao'].'">
	<br>所属栏目<br>
    <select name="gro" >
    '.class_list($list['gro']).'
    </select>
	<br>是否隐藏<br>
    <select name="list" >';
    if($list['list'] == '0'){
		echo '<option value="0" selected="selected" >[1]否</option>
    <option value="1">[2]是</option>';
	}else{
		echo '<option value="0">[1]否</option>
    <option value="1" selected="selected">[2]是</option>';
	}
    echo '</select><br>
    <input type="submit" value="确认修改"></div>
    </form>高级<a href="mod_class.php?action=del&cid='.$_GET['cid'].'">删除此栏目</a>';
  }
  echo "<div class=\"mylink\"><a href=\"../indexadmin.php?cid=".$list['gro']."\">返回页面综合排版</a></div>";
}
echo footer(1); 