<?
$C_126cmsadmin_tname = 'wnm_config';

include(dirname(__FILE__)."/../global.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'];

$module_id = $_GET['module_id'];

?><!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>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
  return confirm(msg);
}
//-->
</script>
</head>

<body>
 [<a href="module_list.php">模块分类管理</a>] [<a href="field_list.php?module_id=<?=$module_id?>" target="">全部字段</a>] [<a href="field_insert.php?module_id=<?=$module_id;?>">添加字段</a><a href="field_insert.php"></a>] [<a href="field_set.php?module_id=<?=$module_id;?>">综合设置</a>]<br />

<?php
if( $job == 'insert_field_code' ){  
  
  $module_id         =    addslashes($_POST["module_id"]);
  $module_name     =    addslashes($_POST["module_name"]);
  $module_field_name     =    addslashes($_POST["module_field_name"]);
  $module_field_code     =    addslashes($_POST["module_field_code"]);
  
  echo $module_field_name;
  
 	$query = "insert into `w6_module`
                          ( `module_id` , `module_name` , `module_field_name` , `module_field_code`  )
                  values
                         ( '".$module_id."' , '".$module_name."' , '".$module_field_name."' , '".$module_field_code."' ) ";
	$result = mysql_query($query) or die(mysql_error());
	
    $taxis   = mysql_insert_id();
	$id = $taxis;
	mysql_query("UPDATE `w6_module` 
          SET `taxis`='$id'
		  WHERE `id`=$id");
		  	
	if($result){
jsTWinAlert( "上传成功！" );
        }else{
	     jsTWinAlert( "上传失败！" );
        }
		
}elseif( $job == 'modifylist' ){ 

  $postdb         =    $_POST["order"];
  
  
  $query="SELECT * FROM `w6_module` WHERE `module_id`='".$module_id."'";
  $result=mysql_query($query);
  $f_module_config       =  mysql_result($result,"0","module_config");
  $field_db = unserialize($f_module_config);
  
  //数据调序
  foreach( $field_db AS $key=>$value){	
		$postdb[$key]=intval($postdb[$key]);	
		@$field_db[$key][orderlist]=$postdb[$key];	
		$_listdb[$postdb[$key]]=$field_db[$key];	
	}	

	krsort($_listdb);	
	foreach( $_listdb AS $key=>$rs){	
		@$listdb[$rs[field_id]]=$rs;	
	}	
	if(is_array($listdb)){	
		$field_db=$listdb+$field_db;	
	}	
	$array=$field_db;	
  //数据调序
  
  $module_config=addslashes(serialize($array));

  mysql_query("UPDATE `w6_module` SET `module_config`='$module_config' WHERE module_id='$module_id'");

}elseif($job == "del"){

  $module_id = $_GET['module_id'];
  $field_id  = $_GET['field_id'];
  
  //删除表中字段
  $query="ALTER TABLE `w6_module_content_$module_id` DROP `$field_id`";
  $result=mysql_query($query);
  
   
  //删除 w6_module 表中记录
  $query="SELECT * FROM `w6_module` WHERE `module_id`='".$module_id."'";
  $result=mysql_query($query);
  $f_module_config       =  mysql_result($result,"0","module_config");
  $array = unserialize($f_module_config);
  unset($array[$field_id]);	
  $module_config=addslashes(serialize($array));	

  mysql_query("UPDATE `w6_module` SET `module_config`='$module_config' WHERE module_id='$module_id'");

}
?>
<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">编辑字段(<a href="#">默认已加入文章标题字段 <strong>title</strong> </a>)</td>
    </tr>
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF">
	  <form action="" method="post" enctype="multipart/form-data" name="form2" id="form2">
	  <table width="96%" border="0" cellpadding="1" cellspacing="1" bgcolor="#A4B6D7">
          <tr>
            <td width="5%" align="center" bgcolor="#FFFFFF"><strong>排序</strong></td>
            <td width="21%" align="center" bgcolor="#FFFFFF"><strong>字段名称</strong></td>
            <td width="18%" align="center" bgcolor="#FFFFFF"><strong>字段ID</strong></td>
            <td width="22%" align="center" bgcolor="#FFFFFF"><strong>修改</strong></td>
            <td width="23%" align="center" bgcolor="#FFFFFF"><strong>删除</strong></td>
          </tr>
          <?
                  $query="SELECT * FROM `w6_module` WHERE `module_id`='".$module_id."'";
                  $result=mysql_query($query);
                  $module_config       =  mysql_result($result,"0","module_config");
				  
				  $array = unserialize($module_config);
				  
				  //print_r($array);exit;
				  
				  	unset( $array['field_set'] );

				  
				  foreach( (array)$array AS $key=>$rs ){//加“(array)”防止显示错误代码
				  
                ?>
          <tr>
            <td height="40" align="center" bgcolor="#FFFFFF"><input name="order[<?=$rs['field_id']?>]" type="text" value="<?=$rs['orderlist']?>" size="3" />
            </td>
            <td align="center" bgcolor="#FFFFFF"><?=$rs['title']?></td>
            <td align="center" bgcolor="#FFFFFF"><?=$rs['field_id']?></td>
            <td align="center" bgcolor="#FFFFFF"><a href="field_edit.php?module_id=<?=$module_id?>&field_id=<?=$rs['field_id']?>">修改</a></td>
            <td align="center" bgcolor="#FFFFFF"><a href="?job=del&module_id=<?=$module_id?>&field_id=<?=$rs['field_id']?>" onclick="return MM_popupMsg('确定要删除吗“<?=$module_field_name?>”！！')">删除 </a></td>
          </tr>
          <?
		}
		?>
      </table>
	  <input type="submit" value="修改排序" name="Submit22" />
            <input name="job" type="hidden" id="job" value="modifylist" />
	  </form></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="96%" border="0" cellpadding="1" cellspacing="1" bgcolor="#A4B6D7" class="font">
        <tr>
          <td width="27%" align="center" bgcolor="#FFFFFF"><strong>字段名称</strong></td>
          <td width="42%" 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_field_name" type="text" id="module_field_name" size="22" maxlength="40" />
          </td>
          <td align="center" bgcolor="#FFFFFF"><textarea name="module_field_code" cols="50" rows="2" id="module_field_code"></textarea></td>
          <td align="center" bgcolor="#FFFFFF"><input name="module_id" type="hidden" id="module_id" value="1" />
                <input name="module_name" type="hidden" id="module_name" value="文章模块" />
                <input name="job" type="hidden" id="job" value="insert_field_code" />
                <input type="submit" name="Submit2" value="添加" /></td>
        </tr>
      </table></td>
    </tr>
  </table>
</form>
</body>
</html>
