<?php
/***********************************************************************************/
/* MassCRM客户关系管理系统							   */
/* ========================      						   */
/* 欢迎使用 MassCRM ,在您开始使用之前,请务必完整阅读本软件附带的全部说明档	   */
/***********************************************************************************/
/* Welcome to http://www.massboxes.com & http://masscrm.massboxes.com		   */
/***********************************************************************************/
	require_once "../includes/check_login.inc.php";
	require_once "../includes/config.inc.php";
	require_once "../includes/common.inc.php";
	require_once "../includes/function.inc.php";
	require_once "../includes/tree.inc.php";
	require_once "../includes/BiaoCommon.class.php";
	
	$table_name		=	$_REQUEST[table_name];
	$module_name	=	$_REQUEST[module_name];
	$module_num		=	$_REQUEST[module_num];
	$operator		=	$HTTP_SESSION_VARS["user_name"];
	$bu_auto_id		=	$HTTP_SESSION_VARS["user_auto_id"];
	
	checkRole($table_name,$module_num,$bu_auto_id,"CUSTOMIZE");
	
	global $boxesDB;
	$boxesDB=new BiaoCommon($conn);
	$boxesDB->setTableName("field_display_table");
	
	if($_POST[set_confirm]){
		for($i=0;$i<count($_POST[field_name]);$i++){
			$boxesDB->setUpdateArray("field_type",$_POST[field_type][$i]);
			$boxesDB->setUpdateArray("can_be_empty",$_POST[can_be_empty][$i]);
			$boxesDB->setUpdateArray("can_be_same",$_POST[can_be_same][$i]);
			$boxesDB->setUpdateArray("is_readonly",$_POST[is_readonly][$i]);
			$boxesDB->setUpdateArray("display_name",$_POST[display_name][$i]);
			
			$boxesDB->setUpdateArray("list_is_display",$_POST[list_is_display][$i]);
			$boxesDB->setUpdateArray("list_display_width",$_POST[list_display_width][$i]);
			$boxesDB->setUpdateArray("list_display_number",$_POST[list_display_number][$i]);
			
			$boxesDB->setUpdateArray("admin_is_display",$_POST[admin_is_display][$i]);
			$boxesDB->setUpdateArray("admin_position",$_POST[admin_position][$i]);
			$boxesDB->setUpdateArray("admin_display_type",$_POST[admin_display_type][$i]);
			$boxesDB->setUpdateArray("admin_display_width",$_POST[admin_display_width][$i]);
			$boxesDB->setUpdateArray("admin_display_number",$_POST[admin_display_number][$i]);
			
			$boxesDB->setUpdateArray("search_is_display",$_POST[search_is_display][$i]);
			$boxesDB->setUpdateArray("search_display_type",$_POST[search_display_type][$i]);
			$boxesDB->setUpdateArray("search_display_width",$_POST[search_display_width][$i]);
			$boxesDB->setUpdateArray("search_display_number",$_POST[search_display_number][$i]);
			
			$boxesDB->setUpdateArray("print_is_display",$_POST[print_is_display][$i]);
			$boxesDB->setUpdateArray("print_position",$_POST[print_position][$i]);
			$boxesDB->setUpdateArray("print_display_width",$_POST[print_display_width][$i]);
			$boxesDB->setUpdateArray("print_display_number",$_POST[print_display_number][$i]);
			
			$boxesDB->setUpdateArray("print_list_is_display",$_POST[print_list_is_display][$i]);
			$boxesDB->setUpdateArray("print_list_display_width",$_POST[print_list_display_width][$i]);
			$boxesDB->setUpdateArray("print_list_display_number",$_POST[print_list_display_number][$i]);
			
			$boxesDB->setUpdateArray("select_is_display",$_POST[select_is_display][$i]);
			$boxesDB->setUpdateArray("select_display_width",$_POST[select_display_width][$i]);
			$boxesDB->setUpdateArray("select_display_number",$_POST[select_display_number][$i]);
			
			$boxesDB->setUpdateArray("quote_is_display",$_POST[quote_is_display][$i]);
			$boxesDB->setUpdateArray("quote_display_width",$_POST[quote_display_width][$i]);
			$boxesDB->setUpdateArray("quote_display_number",$_POST[quote_display_number][$i]);
			
			$sql="where (table_name='".$_POST[table_name]."' and field_name='".$_POST[field_name][$i]."')";
			$boxesDB->setCondition($sql);
			$boxes_result=$boxesDB->updateRow();
		}
		echo"<script>";
		echo"alert('设置保存成功，按确定返回！');";
		echo"window.returnValue = 'set_complete';";
		echo"self.close();";
		echo"</script>";
	}
	
	
	$boxesDB->setSelectField("*");
	$sql="where table_name='$table_name' order by field_display_auto_id asc";
	$boxesDB->setCondition($sql);
	$boxes_set=$boxesDB->selectResult();
	for($i=0;$i<count($boxes_set);$i++){
		$row=$boxes_set[$i];
		
		$list_display_number=$row[list_display_number];
		if($list_display_number==0)
			$list_display_number="";			
		$admin_display_number=$row[admin_display_number];
		if($admin_display_number==0)
			$admin_display_number="";
		$search_display_number=$row[search_display_number];
		if($search_display_number==0)
			$search_display_number="";
		$print_display_number=$row[print_display_number];
		if($print_display_number==0)
			$print_display_number="";
		$print_list_display_number=$row[print_list_display_number];
		if($print_list_display_number==0)
			$print_list_display_number="";	
		$select_display_number=$row[select_display_number];
		if($select_display_number==0)
			$select_display_number="";
		$quote_display_number=$row[quote_display_number];
		if($quote_display_number==0)
			$quote_display_number="";	
			
		$set_array[]=array("id"						=>	$i,
						   "table_name"				=>	$row[table_name],
						   "field_name"				=>	$row[field_name],
						   "field_type"				=>	$row[field_type],
						   "can_be_empty"			=>	$row[can_be_empty],
						   "can_be_same"			=>	$row[can_be_same],
						   "is_readonly"			=>	$row[is_readonly],
						   "display_name"			=>	$row[display_name],
						   "list_is_display"		=>	$row[list_is_display],
						   "list_display_width"		=>	$row[list_display_width],
						   "list_display_number"	=>	$list_display_number,
						   "admin_is_display"		=>	$row[admin_is_display],
						   "admin_position"			=>	$row[admin_position],
						   "admin_display_type"		=>	$row[admin_display_type],
						   "admin_display_width"	=>	$row[admin_display_width],
						   "admin_display_number"	=>	$admin_display_number,
						   "search_is_display"		=>	$row[search_is_display],
						   "search_display_type"	=>	$row[search_display_type],
						   "search_display_width"	=>	$row[search_display_width],
						   "search_display_number"	=>	$search_display_number,
						   "print_is_display"		=>	$row[print_is_display],
						   "print_position"			=>	$row[print_position],
						   "print_display_width"	=>	$row[print_display_width],
						   "print_display_number"	=>	$print_display_number,
						   "print_list_is_display"	=>	$row[print_list_is_display],
						   "print_position"			=>	$row[print_position],
						   "print_list_display_width"	=>	$row[print_list_display_width],
						   "print_list_display_number"	=>	$print_list_display_number,
						   "select_is_display"		=>	$row[select_is_display],
						   "select_display_width"	=>	$row[select_display_width],
						   "select_display_number"	=>	$select_display_number,
						   "quote_is_display"		=>	$row[quote_is_display],
						   "quote_display_width"	=>	$row[quote_display_width],
						   "quote_display_number"	=>	$quote_display_number);
	}
	
	
	/**********************************************************************************/
	/*                                   套用模板显示                                  */
	/**********************************************************************************/
	$action_file=$_SERVER['PHP_SELF']."?table_name=$table_name&&module_name=$module_name";
	$smart->assign(array(
					"module_name"			=>	$module_name,
					"table_name"			=>	$table_name,
					"set_array"				=>	$set_array));

	//输出结果
	$smart->display('set_common.tpl.htm');
	/**********************************************************************************/
	/*                                   套用模板显示                                  */
	/**********************************************************************************/
?>