<?php 
function list_mk($id,$str){
   $sql = "SELECT id,{$str} FROM mkinfo WHERE id=
	'{$id}'";
	$result = mysql_query($sql);
	list($id,$back)=mysql_fetch_row($result);
	return $back;
	}
function add_mk($url,$list,$name,$time){
   $sql="INSERT INTO mkinfo(url,list,name,time)VALUES
	('{$url}','{$list}','{$name}','{$time}')";
	$result=mysql_query($sql);
    if($result && mysql_affected_rows()>0){
	$back=1;
	}else{
	$back=0;
	}
	return $back;
}
$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.='['.$mk_name.']
		<br>[URL]'.$mk_url.'<br>[显示]'.$mk_list.'[<a href="?action=add_mk&mod=yes&id='.$mk_id.'&">修改</a>]<br>['.$mk_time.']<hr>';
	
	}
	if($_GET['mod']=='yes'){
	  $mid=$_GET['id'];
	    if($_GET['mod_info']=='yes'){
		    	$sql="UPDATE mkinfo SET name='{$_POST['mkname']}',url='{$_POST['url']}',list='{$_POST['list']}' WHERE id='{$_GET['id']}'";
				$result = mysql_query($sql);
				if($result && mysql_affected_rows()>0){
	            $html = '<div class="tip">修改成功</div>';
                }else{
                $html = '<div class="tip">修改失败</div>';
                }
		     $html = $html.'<div class="subtitle">
			 <a href="?action=add_mk&cid='.$_GET['cid'].'&mod=yes&id='.$_GET['id'].'&">返回修改</a><br>
			 <a href="?cid='.$_GET['cid'].'&">管理员后台</a><br>
             <a href="../index.php?cid='.$_GET['cid'].'&">网站首页</a>
			 </div>';
		}else{
	   $html='<div class="subtitle">
       <form method="post"  action="?action=add_mk&mod=yes&mod_info=yes&id='.$_GET['id'].'&">
       [模块名称]<br>
       <input name="mkname" value="'.list_mk($mid,'name').'" type="text">
       <br>[模块地址]
       <br>
       <input name="url" value="'.list_mk($mid,'url').'" type="text">
       <br>[是否开放|开放YSE/停用NO]
       <br>
       <input name="list" value="'.list_mk($mid,'list').'" type="text"><br>
        <input type="submit" value="修改模块信息">
       </form>
       </div>
	   <div class="mylink">
 <a href="?action=add_mk&cid='.$_GET['cid'].'&">模块列表</a>|
 <a href="../index.php?cid='.$_GET['cid'].'&">网站首页</a>
 </div>';
	   }
	}else{
	if($_POST['add']=='yes'){
	 $time='00';
	  $add_tip=add_mk($_POST['url'],$_POST['list'],$_POST['name'],$time);
	     if($add_tip==1){
		   $tip='<div class="tip">模块添加成功</div>';
		   }else{
		     $tip='<div class="tip">模块添加失败</div>';}
	  }
$html=$tip.' <div class="subtitle">
<form method="post"  action="?action=add_mk&">
      [模块名称]<br>
<input name="name" value="" type="text">
<br>[模块地址]
<br>
<input name="url" value="" type="text">
<br>[是否开放|开放YSE/停用NO]
<br>
<input name="list" value="" type="text">
<input name="add" value="yes" type="hidden">
<br>
<input type="submit" value="添加模块">
</form></div><div class="content">'. $html_list.'</div>
<div class="mylink">
 <a href="?cid='.$_GET['cid'].'&">管理员后台</a><a href="../index.php?cid='.$_GET['cid'].'&">网站首页</a>
 </div>';
 }
?>