<?
$C_126cmsadmin_tname = 'wnm_config';

include(dirname(__FILE__)."/../global.php");


include("../../../include/js.php");

/*
	//连接数据库
    include("../../../include/db.cfg.php");
	//连接数据库
	include("../../../include/cfg.php");
	include("../../../include/function.php");
	include("../../../include/file_type.php");
	include("../../../include/js.php");
	
	*/
@$job=$submitted_vars['job'];

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="../css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px;
}
.red {color: #FF0000}
-->
</style>

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
  return confirm(msg);
}
//-->
</script>
</head>

<body>
	<?
	  if( $job == 'del' ){  

	  	  $module_id  =  $_GET["module_id"];
		  
		  if(!$module_id){
			exit ( 'ID出错' );
		   }
		  
	  	    $query="DELETE FROM `w6_module` WHERE `module_id`='$module_id' ";
	  	  //echo $query;
	  	    $result=mysql_query($query) or die( mysql_error() );
	  	  //echo $result;
		    $query2="DROP TABLE `w6_module_content_$module_id`";
			$result2=mysql_query($query2) or die( mysql_error() );
	  	  if($result)
	  	  {
			
			   jsTWinAlert( "成功删除！！" );
	  	  }
	  	  else
	  	  {
	  	    jsTWinAlert( "删除失败！！" );
	  	    jsTWinBack();
	  	    exit();
	  	  }
	
	}elseif( $job == 'modify' ){
	  
                  $id            =    addslashes($_POST["id"]);
				  $link_url            =    addslashes($_POST["link_url"]);
				  $taxis            =    addslashes($_POST["taxis"]);
				  $link_name            =    addslashes($_POST["link_name"]);
  
  //修改数据库

  $query=" UPDATE `link` 
          SET `taxis`='$taxis' , `link_url`='$link_url' , `link_name`='$link_name'
		  WHERE `id`=$id"; 

  //echo $query;		  
  $result=mysql_query($query);
  if($result)
  {
	jsTWinAlert( "修改成功！" );
  }
  else
  {
	jsTWinAlert( "修改失败！" );
  }
  

	}elseif( $job == 'insert' ){  
  
  //$module_taxis         =    addslashes($_POST["module_taxis"]);
  $module_name     =    addslashes($_POST["module_name"]);
  
        /////////记录数据  =====开始
 	$query = "insert into `w6_module`
                          ( `module_name` )
                  values
                         ( '".$module_name."' ) ";

	$result = mysql_query($query) or die(mysql_error());
	
    $module_id   = mysql_insert_id();

	mysql_query("UPDATE `w6_module` 
          SET `module_taxis`='$module_id'
		  WHERE `module_id`=$module_id");	
	
	//创建相应的模块表格
	$query2 = "CREATE TABLE `w6_module_content_$module_id` (
  `id` int(11) NOT NULL auto_increment,
  `aid` int(11) NOT NULL,
  `uid` int(11) NOT NULL,
  `adminid` int(11) NOT NULL,
  `content_list` int(11) NOT NULL,
  `module_id` int(11) NOT NULL,
  `fid` int(11) NOT NULL,
  `fname` VARCHAR( 40 ) NOT NULL,
  `yz` tinyint(1) NOT NULL,
  `yzer` VARCHAR( 40 ) NOT NULL,
  `yztime` int(10) NOT NULL,
  `shows` tinyint(1) NOT NULL,
  `showser` VARCHAR( 40 ) NOT NULL,
  `showstime` int(10) NOT NULL,
  `top` tinyint(1) NOT NULL,
  `toptime` int(10) NOT NULL,
  `levels` tinyint(1) NOT NULL,
  `levelstime` int(10) NOT NULL,
  `jumpurl` VARCHAR( 255 ) NOT NULL,
  `title` VARCHAR( 255 ) NOT NULL,
  `count` int(11) NOT NULL default '0',
  `posttime` int(10) NOT NULL default '0',
  `updatatime` int(10) NOT NULL default '0',
  `autotime` int(10) NOT NULL default '0', 
  `lastview` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`)
  )";

	if(mysql_get_server_info() > '4.1'){
		@$extra = $cfg_dbcharset ? "ENGINE=MyISAM DEFAULT CHARSET=$cfg_dbcharset;" : "ENGINE=MyISAM;";
	}else{
		@$extra = "TYPE=MyISAM;";
	}
	
	$query2 .= $extra;

	$result2 = mysql_query($query2) or die(mysql_error());
	//mysql_query("ALTER TABLE `w6_module_content_$module_id` CHANGE `id` `id` INT( 11 ) AUTO_INCREMENT ");

        /////////记录数据  =====结束

  }
  ?>

<table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#A4B6D7" class="font">
  <tr>
    <td height="25" align="center" background="../images/titlebg.jpg" class="font_title">编辑模块分类</td>
  </tr>
  <tr>
    <td height="30" align="center" bgcolor="#FFFFFF"><table width="90%" border="0" cellpadding="1" cellspacing="1" bgcolor="#A4B6D7">
      <tr>
        <td width="21%" align="center" bgcolor="#FFFFFF"><strong>排 序</strong></td>
        <td width="27%" align="center" bgcolor="#FFFFFF"><strong>模块名称</strong></td>
        <td width="18%" align="center" bgcolor="#FFFFFF"><strong>字段设置</strong></td>
        <td width="16%" align="center" bgcolor="#FFFFFF"><strong>生成模板</strong></td>
        <td width="18%" align="center" bgcolor="#FFFFFF"><strong>删 除</strong></td>
      </tr>
      <?
                $query="SELECT * FROM `w6_module` ORDER BY `module_taxis` ASC";
                $result=mysql_query($query);
                $i=0;
                while($row=mysql_fetch_array($result))
                  {
                  $module_id            =    stripslashes($row["module_id"]);
				  $module_taxis       =    stripslashes($row["module_taxis"]);
                  $module_name     =    stripslashes( $row["module_name"] );
                ?>
      <form id="form2" name="form2" method="post" action="">
        <tr>
          <td height="34" align="center" bgcolor="#FFFFFF"><input name="module_taxis" type="text" id="module_taxis" value="<?=$module_taxis?>" size="3" />
            <input name="id" type="hidden" id="id" value="<?=$id?>" />
            <input name="job" type="hidden" id="job" value="modify" /></td>
          <td align="center" bgcolor="#FFFFFF">【<?=$module_name?>】</td>
          <td align="center" bgcolor="#FFFFFF"><a href="field_list.php?module_id=<?=$module_id;?>">字段修改</a>&nbsp;</td>
          <td align="center" bgcolor="#FFFFFF"><a href="makeWNtpl.php?mid=<?=$module_id;?>">生成模板</a></td>
          <td align="center" bgcolor="#FFFFFF"><a href="?module_id=<?=$module_id;?>&job=del" onclick="return MM_popupMsg('确定要删除吗“<?=$module_name?>”！！')">删除</a></td>
        </tr>
        
      </form>
      <?
		$i++;
		}
		?>
        <tr>
          <td height="34" colspan="5" align="left" bgcolor="#FFFFFF"> 注意：修改模板后请重新生成模板文件</td>
        </tr>
    </table></td>
  </tr>
</table>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="100%"  border="0" cellpadding="3" cellspacing="1" bgcolor="#A4B6D7" class="font">
    <tr>
      <td height="25" align="center" background="../images/titlebg.jpg" class="font_title">添加模块分类</td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF"><table width="90%" border="0" cellpadding="1" cellspacing="1" bgcolor="#A4B6D7" class="font">
        <tr>
          <td width="27%" align="center" bgcolor="#FFFFFF"><strong>模块名称</strong></td>
          <td width="18%" align="center" bgcolor="#FFFFFF"><strong>提 交</strong></td>
        </tr>
        <tr>
          <td height="30" align="center" bgcolor="#FFFFFF"><input name="module_name" type="text" id="module_name" size="22" />          </td>
          <td align="center" bgcolor="#FFFFFF"><input name="job" type="hidden" id="job" value="insert" />
            <input type="submit" name="Submit2" value="提 交" /></td>
        </tr>
      </table></td>
    </tr>
  </table>
</form>
</body>
</html>
