<?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/BiaoCommon.class.php";

	$table_name		= $_REQUEST[table_name];
	$module_name	= $_REQUEST[module_name];
	
	//时间段
	if(!$start_time){
		$start_time=date("Y-m-d",(time()-$TIME_SLOT));
		$end_time=date("Y-m-d",time());
	}
	
	global $boxesDB;
	$boxesDB=new BiaoCommon($conn);
	
	if($_POST[search_confirm]){
		if($_REQUEST[start_time]){
			$return_array="new Array('search_start_time','".$_REQUEST[start_time]."'),";
		}
		if($_REQUEST[end_time]){
			$return_array.="new Array('search_end_time','".$_REQUEST[end_time]."'),";
		}
		$boxesDB->setTableName("field_display_table");
		$boxesDB->setSelectField("*");
		$sql="where (table_name='$table_name' and search_is_display='1') order by search_display_number asc";
		$boxesDB->setCondition($sql);
		$boxes_search=$boxesDB->selectResult();
		for($i=0;$i<count($boxes_search);$i++){
			$row=$boxes_search[$i];
			$return_array.="new Array('search_".$row[field_name]."','".$_POST[$row[field_name]]."'),";
		}
		
		if($return_array){//去掉最后一个","
			$return_array=substr($return_array,0,strlen($return_array)-1);
		}
		echo"<script>";	
		echo"var value=new Array($return_array);";
		echo"window.returnValue = value;";
		echo"self.close();";
		echo"</script>";
		exit;
	}
	
	$boxesDB->setTableName("field_display_table");
	$boxesDB->setSelectField("*");
	$sql="where (table_name='$table_name' and search_is_display='1') order by search_display_number asc";
	$boxesDB->setCondition($sql);
	$boxes_search=$boxesDB->selectResult();
	
	for($i=0;$i<count($boxes_search);$i++){
		$row=$boxes_search[$i];
		
		if($row[search_display_type]=="select"){
			$$row[field_name]="<select name=\"".$row[field_name]."\">";
			$$row[field_name].="<option value=''>";
				for($k=$row[search_display_width]-3;$k>0;$k--){
					$$row[field_name].="&nbsp;";
				}
			$$row[field_name].="</option>";
			
			$boxesDB->setTableName($table_name);
			$boxesDB->setSelectField("*");
			$sql="group by ".$row[field_name]." order by ".$row[field_name]." asc";
			$boxesDB->setCondition($sql);
			$boxes_temp=$boxesDB->selectResult();
			for($j=0;$j<count($boxes_temp);$j++){
				$row_temp=$boxes_temp[$j];
				$$row[field_name].="<option value='".$row_temp[$row[field_name]]."'>".$row_temp[$row[field_name]]."</option>";
			}
			$$row[field_name].="</select>";
			
			$type="hidden";
			$name="";
		}
		else if($row[search_display_type]=="time" and strrchr($row[field_name],"_")=="_time"){
			$$row[field_name]=" <script language=JavaScript>
							arrowtag('start_time','".$start_time."');
						</script>
							——
						<script language=JavaScript>
							arrowtag('end_time','".$end_time."');
						</script>";
			$type="hidden";
			$name="";
		}
		else{
			$type="text";
			$name=$row[field_name];
		}
		
		
		$search_array[]=array(	"display_name"	=>	$row[display_name],
								"name"			=>	$name,
								"type"			=>	$type,
								"size"			=>	$row[search_display_width],
								"select"		=>	$$row[field_name]);
	}

	
	
	/**********************************************************************************/
	/*                                   套用模板显示                                  */
	/**********************************************************************************/
	$action_file=$_SERVER['PHP_SELF']."?table_name=$table_name&&module_name=$module_name";
	$smart->assign(array(
					"module_name"			=>	$module_name,
					"table_name"			=>	$table_name,
					"search_array"			=>	$search_array));

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