<?
$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");
	
	*/
	
	$make_3_rand = make_3_rand();//取三位随机数
	
@$job=$submitted_vars['job'];

$module_id = $_GET['module_id'];

$query="SELECT `module_name` FROM `w6_module` WHERE `module_id`=$module_id";
//echo $query;
$result=mysql_query($query) or die("Could not connect: " . mysql_error());

$module_name=stripslashes(mysql_result($result,"0","module_name"));
?><!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;
}
.red {color: #FF0000}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
  return confirm(msg);
}

function get_obj(obj){
   return document.getElementById(obj);
}
//-->
</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' ){  

  $array['module_id']         =    $_POST["module_id"];
  $array['title']     =    $_POST["title"];
  $array['field_id']     =    $_POST["field_id"];
  $array['field_type']     =    $_POST["field_type"];
  $array['field_leng']     =    $_POST["field_leng"];
  $array['form_type']     =    $_POST["form_type"];
  $array['form_set']     =    filtrate ( $_POST["form_set"] );
  $array['form_value']     =    $_POST["form_value"];
  $array['form_word']     =    $_POST["form_word"];
  $array['auto_select']     =    $_POST["auto_select"];
  $array['add_field_id']     =    $_POST["add_field_id"];
  $array['add_field_id_more']     =    $_POST["add_field_id_more"];
  $array['td_color']     =    $_POST["td_color"];
  $array['mustfill']     =    $_POST["mustfill"];
  $array['listshow']     =    $_POST["listshow"];
  $array['metashow']     =    $_POST["metashow"];
  
   
   $module_id   =  addslashes($array['module_id']);
   $title   =  addslashes($array['title']);
   $field_id   =  addslashes($array['field_id']);
   $field_type   =  addslashes($array['field_type']);
   $field_leng   =  addslashes($array['field_leng']);
   $form_type   =  addslashes($array['form_type']);
   $form_set   =  addslashes($array['form_set']);
   $form_value   =  addslashes($array['form_value']);
   $form_word   =  addslashes($array['form_word']);
   $td_color   =  addslashes($array['td_color']);
   $mustfill   =  addslashes($array['mustfill']);
   $listshow   =  addslashes($array['listshow']);
   $metashow   =  addslashes($array['metashow']);

   $field_name   =  $field_id;
   $array['orderlist']   =  "0";


//往模块内容表中插入字段	
	$field_leng=intval($field_leng);

	if($field_type=='int')
	{
		if( $field_leng>10 || $field_leng<1 ){
			$field_leng=10;
		}
		mysql_query("ALTER TABLE `w6_module_content_$module_id` ADD `$field_id` INT( $field_leng ) NOT NULL");
	}
	elseif($field_type=='varchar')
	{
		if( $field_leng>255 || $field_leng<1 ){
			$field_leng=255;
		}
		mysql_query("ALTER TABLE `w6_module_content_$module_id` ADD `$field_id` VARCHAR( $field_leng ) NOT NULL");
	}
	elseif($field_type=='mediumtext')
	{
		mysql_query("ALTER TABLE `w6_module_content_$module_id` ADD `$field_id` MEDIUMTEXT NOT NULL");
	}

  //先从数据库中读出原来的设置参数,再加上现在的参数
  $query="SELECT * FROM `w6_module` WHERE `module_id`='".$module_id."'";
  $result=mysql_query($query);
  $f_module_config       =  mysql_result($result,"0","module_config");
  $f_array = unserialize($f_module_config);

  
  $f_array[$field_name]=$array;	
/*
  if(!empty($f_module_config)){
  $f_array = unserialize($f_module_config);

    $a_num = count($f_array);

	for($i=0;$i<$a_num;$i++){
	  $array2[] = $f_array[$i];

	}
  
  }
  $array2[]=$array;
  */

  //print_r($f_array);
  $module_config=addslashes(serialize($f_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"><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);
				  
				  	unset( $array['field_set'] );

				  
				  foreach($array AS $key=>$rs){
                ?>
				<form action="" method="post" enctype="multipart/form-data" name="form2" id="form2">
          <tr>
            <td height="40" align="center" bgcolor="#FFFFFF"><input name="taxis" type="text" id="taxis" value="<?=$rs['orderlist']?>" size="3" />
                <input name="id" type="hidden" id="id" value="<?=$id?>" />
            <input name="job2" type="hidden" id="job2" value="modify" /></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="article_del.php?id=<?=$id?>" onclick="return MM_popupMsg('确定要删除吗“<?=$rs[title]?>”！！')">删除 </a></td>
          </tr>
		  </form>
          <?
		}
		?>
      </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">
    <tr>
      <td height="25" colspan="2" background="../images/titlebg.jpg" bgcolor="#FFFFFF"><span class="font_title">添加字段</span></td>
    </tr>
    <tr>
      <td width="37%" bgcolor="#FFFFFF">当前模块名称:</td>
      <td width="63%" bgcolor="#FFFFFF"><?=$module_name?></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF">字段名称:<span class="red">(*)</span></td>
      <td bgcolor="#FFFFFF"><input name="title" type="text" id="title" value="我的字段my_<?=$make_3_rand?>" size="22" maxlength="40" /></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF">数据库字段ID:<span class="red">(*)</span></td>
      <td bgcolor="#FFFFFF"><input name="field_id" type="text" id="field_id" value="my_<?=$make_3_rand?>" size="22" maxlength="40" />
      (必须为3个字母以上,字母后面可以跟数字)</td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF">数据库字段存放数据类型:<span class="red">(*)</span></td>
      <td bgcolor="#FFFFFF"><select name="field_type" id="field_type"  onchange="field_choose(this.options[this.selectedIndex].value)">
        <option value="varchar" >255个字符串以内</option>
        <option value="int" >10位以内纯数字</option>
        <option value="mediumtext"  selected="selected" >文本文档</option>
      </select></td>
    </tr>
    <tr id="field_leng_tr">
      <td bgcolor="#FFFFFF">数据库字段长度:<font color="#FF0000">(*)</font></td>
      <td bgcolor="#FFFFFF"><input name="field_leng" type="text" id="field_leng" value="" /></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF">用户填写的表单类型:<span class="red">(*)</span></td>
      <td bgcolor="#FFFFFF"><select name="form_type" id="form_type"  onchange="form_choose(this.options[this.selectedIndex].value)">
        <option value="text" >单行文本框</option>
        <option value="textarea" >多行文本框</option>
        <option value="select" >下拉菜单</option>
        <option value="radio" >单选框</option>
        <option value="checkbox" >复选框</option>
        <option value="ieedit" >可视化编辑器</option>
        <option value="upfile" >文件上传</option>
        <option value="upfile_big" >大文件上传</option>
        <option value="upphoto" >上传图片（生成缩略图）</option>
        <option value="pingfen" >用户评分</option>
      </select></td>
    </tr>
    <tr id="form_set_tr">
      <td bgcolor="#FFFFFF">表单参数选项:<br />
1、(适用下拉菜单/单选框/复选框,每个值换一行,每行你也可以这样设置<font color="#0000FF">“值</font><font color="#FF0000">|<font color="#0000FF">描述”</font></font>，默认“值”等同于“值|值”<br />
2、上传图片时，<font color="#0000FF">“宽</font><font color="#FF0000">*<font color="#0000FF">高”</font></font>，如“30*40”表示，30*40像素，如同时生成两张小图片先输入如下格式 30*40|90*120) <br />
3、在线编辑器时，<font color="#0000FF">“宽</font><font color="#FF0000">*<font color="#0000FF">高”</font></font>，如“84*16”，留空为“84*16”<br />
4、多行文本框时，<font color="#0000FF">“宽</font><font color="#FF0000">*<font color="#0000FF">高”</font></font>，如“80*8”，留空为“80*8”<br />
5、表单附加功能，如单行文本增加字符筛选功能（ onkeyup="value=value.replace(/[^\d\.]/g,'')" ）</td>
      <td bgcolor="#FFFFFF"><textarea name="form_set" cols="50" rows="5" id="form_set"></textarea></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF">表单默认值:<br />
(一般为空,如果是多选框多个的话,用<b><font color="#FF0000">/</font></b>线隔开,不能换行) </td>
      <td bgcolor="#FFFFFF"><textarea name="form_value" cols="50" rows="3" id="form_value"></textarea></td>
    </tr>
    <tr>
      <td height="13" bgcolor="#FFFFFF">表单附注文字:<br />
(一般为空) </td>
      <td bgcolor="#FFFFFF"><textarea name="form_word" cols="50" rows="4" id="form_word"></textarea></td>
    </tr>
    <tr>
      <td height="14" bgcolor="#FFFFFF">自动随机选择( 适合下拉菜单 ) </td>
      <td bgcolor="#FFFFFF"><input type="radio" name="auto_select" value="1" />
是
  <input name="auto_select" type="radio" value="0" checked="checked" />
否 </td>
    </tr>
    <tr>
      <td height="28" bgcolor="#FFFFFF">插入内容（不替换，适用于下拉菜单）</td>
      <td bgcolor="#FFFFFF"><p>值插入
          <input name="add_field_id" type="text" id="add_field_id" value="" size="16" maxlength="40" />
      内 ( 填写字段名 )<br />
      (和在线编辑器有冲突，因此如想在文章后面插入文字，要多建一个字段)
	  <br />
	  是否多选
	  <input type="radio" name="add_field_id_more" value="1" />
是
<input name="add_field_id_more" type="radio" value="0" checked="checked" /> 
否 ( 多选代表追加 )
</p>      </td>
    </tr>
<tr>
      <td bgcolor="#FFFFFF">表格 td 行背景色:</td>
      <td bgcolor="#FFFFFF"><input name="td_color" type="text" id="td_color" value="" size="22" maxlength="40" /> 
        输入颜色代码,如:#FF0000</td>
    </tr>    <tr>
      <td height="28" bgcolor="#FFFFFF">是否为必填选项:</td>
      <td bgcolor="#FFFFFF"><input type="radio" name="mustfill" value="0"  checked="checked">
不限制
  <input type="radio" name="mustfill" value="1">
必填
<input type="radio" name="mustfill" value="2">
隐藏(不提供给用户填写，可作为二次开发使用) </td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF">是否在列表页调用显示：</td>
      <td bgcolor="#FFFFFF"><input type="radio" value="1" name="listshow" />
列表调用显示
  <input type="radio" checked="checked" value="0" name="listshow" />
不调用显示 </td>
    </tr>
	<tr>
      <td bgcolor="#FFFFFF">是否作为文章meta描述：</td>
      <td bgcolor="#FFFFFF"><input type="radio" value="1" name="metashow" />
        是
          <input type="radio" checked="checked" value="0" name="metashow" />
否 </td>
    </tr>
    <tr>
      <td colspan="2" align="center" bgcolor="#FFFFFF"><input name="module_id" type="hidden" id="module_id" value="<?=$module_id?>" />
        <input name="job" type="hidden" id="job" value="insert" />
<input type="submit" name="Submit" value="提交" /></td>
    </tr>
  </table>
<SCRIPT LANGUAGE="JavaScript">
<!--
function field_choose(t){
	if(t=='mediumtext'){
		get_obj('field_leng_tr').style.display='none';
	}else{
		get_obj('field_leng_tr').style.display='';
	}
}
field_choose('mediumtext');


function form_choose(t){
	if(t=='select'||t=='radio'||t=='checkbox'||t=='select'||t=='upphoto'||t=='pingfen'||t=='ieedit'||t=='textarea'||t=='text'){
		get_obj('form_set_tr').style.display='';
	}else{
		get_obj('form_set_tr').style.display='none';
	}
}
form_choose('text');
//-->
</SCRIPT>
</form>
</body>
</html>
