<?php 
    require "../Run.php";
    $nums = $_GET['nums'];
	if($admin != 1 && $admin != 2)
	{
		ehtml('权限不足!');
		exit();
	}
	echo head('添加更多栏目');
    echo topNav("添加多个栏目","<a href=../indexadmin.php?cid=".$_GET['cid'].">排版</a>"," ");
	  if($_GET['action']=='add'){
			$gro = $_GET['cid'] == null ? 0 : $_GET['cid'];
			for($i=0;$i<$nums;$i++)
			{
				$a  = $i+1;
				$cn = 'cn'.$i;
				$cn = $_POST["$cn"];
				$xuhao = $xuhao+$i;
				if($cn == '' || $cn == NULL){
					echo '栏目名称为空，拒绝添加！';
				}
				else
				{
				$class = mysql_query("INSERT INTO class(cn,url,siteid,q,xuhao,gro,list,top,bottom)VALUES ('{$cn}','{$_POST["url"]}','{$wapid}','{$_POST["q"]}','{$xuhao}','{$gro}','{$_POST["list"]}','','')");
				if($class && mysql_affected_rows()>0){
				if($_POST['xuhao'] == '')
				{
					$AutoID = mysql_insert_id();          
					mysql_query("UPDATE class SET xuhao='{$AutoID}' WHERE cid='{$AutoID}' AND siteid={$wapid}");
				}
			echo "<div class=\"tip\">"; 
			echo "成功添加栏目".$a ;
			echo "</div>";
			}
			else
			{
				echo "栏目".$a."添加失败!";
	        }
		}
	} 
}
else
{
	  function mk_list(){
	  $sql="SELECT id,name,url,list,time FROM mkinfo";
      $result = mysql_query($sql);
      while(list($mk_id,$mk_name,$mk_url,$mk_list,$mk_time) = mysql_fetch_row($result)){
	    
	    $html_list.='<option value="'.$mk_id.'">'.$mk_name.'</option>';
	
	    }
		return $html_list;
	} 
	  echo '<div class="subtitle"><form method="get" action="more_class.php">
	        添加
	        <input type="text" name="nums" value="'.$_GET['nums'].'" style="width:50px;"/>
			<input type="hidden" name="cid" value="'.$_GET['cid'].'"/>
			<input type="submit" value="个栏目"/></form>
			</div>';
	  echo "<div class=\"content\"><form method=\"post\" action=\"more_class.php?action=add&nums=".$_GET['nums']."&cid=".$_GET['cid']."\">
      栏目名称<br>";
      for($i=0;$i<$nums;$i++){
      $a = $i+1;
      echo "栏目".$a.":<input type=\"text\" name=\"cn".$i."\" value=\"\"><br>"; 
      }
      echo "指向模块<br>
<select name=\"url\" >
".mk_list()."
</select><br>
栏目前内容[支持UBB]<br>
<input type=\"text\" name=\"q\" value=\"\"><br>
是否隐藏<br>
<select name=\"list\" >
<option value=\"0\">[1]否</option>
<option value=\"1\">[2]是</option>
</select><br>
栏目序号<br>
<input type=\"text\" name=\"xuhao\" value=\"\"><br>
<input type=\"submit\" value=\"提交\"></form></div>";
      }
echo footer(1);
