<?php include 'header.tpl.php';?>
<style>
.temp_box1{float:left;width:800px;text-align:left}
.temp_box1 li{float:left;padding:5px 0px 3px 10px;list-style-type:none;white-space:nowrap;text-align:left}
.temp_box1 .x_sel{float:left;width:790px;font-weight:bold;text-align:left}
.temp_box3 .x_folder{float:left;width:790px;padding:5px 0px 0px 10px;text-align:left}
.temp_box3 .x_folder li{float:left;padding:5px 0px 3px 0px;width:790px;text-align:left}
.temp_box3 .x_sel{float:left;width:790px;font-weight:bold;padding:10px 0px 0px 10px;text-align:left}
.temp_box3 .x_folder .x_1{padding-left:20px;width:770px}
.temp_box3 .x_folder .x_2{padding-left:40px;width:750px}
.temp_box3 .x_folder .x_3{padding-left:60px;width:730px}
.temp_box3 .x_folder .x_4{padding-left:70px;width:710px}
.temp_box3 .x_folder .x_5{padding-left:100px;width:690px}
.temp_box3 .x_folder .x_6{padding-left:120px;width:670px}

.temp_box2{float:left;width:800px}
.temp_box3{float:left;width:800px}
.temp_next{float:left;padding-left:20px;width:90%;text-align:left}

</style>
<div class="pMenu">
<?php if($get_funid>0):?>
<li><a href="javascript:frmSet('funid',0);frmExecute('default');">数据生成</a></li>
<li><a href="javascript:frmSet('funid',0);frmExecute('funfolder');">函数库</a></li>
<li class="sel"><a href="javascript:frmExecute('default');">编辑函数</a></li>
<?php else:?>
<li class="sel"><a href="javascript:frmExecute('default');">数据生成</a></li>
<li><a href="javascript:frmExecute('funfolder');">函数库</a></li>
<?php endif;?>
<li class="info"><a href="javascript:inc_show_help(223);" style="color:#ff0000">帮助</a></li>
</div>
<div id="id_step1" style="width:100%">
	<div class="temp_box1">
		<li class="x_sel">请选择数据源</li>
		<li><select name="table_name" onchange="me_source();" id="id_table_name"><option value="hr_company">公司数据</option><option value="company_job"<?php if(isset($arr_fun["fun_perms"]["table_name"]) && $arr_fun["fun_perms"]["table_name"]=="company_job") echo ' selected';?>>公司加职位</option><option value="hr_job"<?php if(isset($arr_fun["fun_perms"]["table_name"]) && $arr_fun["fun_perms"]["table_name"]=="hr_job") echo ' selected';?>>职位数据</option><option value="hr_resume"<?php if(isset($arr_fun["fun_perms"]["table_name"]) && $arr_fun["fun_perms"]["table_name"]=="hr_resume") echo ' selected';?>>简历数据</option><option value="article"<?php if(isset($arr_fun["fun_perms"]["table_name"]) && $arr_fun["fun_perms"]["table_name"]=="article") echo ' selected';?>>文章</option></select></li>
	</div>
	<div class='temp_box3' id="id_folder_box" style="display:none">
		<div class="x_sel">选择目录</div>
		<div id="id_folder_list" class="x_folder"></div>
		<div class="x_sel">选择属性</div>
		<div id="id_attribute" class="x_folder">
		<?php foreach($arr_article_attribute as $item){?><input type="checkbox" name="attribute_val[]" value="<?php echo $item?>"<?php if(isset($arr_fun["fun_perms"]["attribute_val"]) && in_array($item,$arr_fun["fun_perms"]["attribute_val"])) echo " checked";?>><?php echo $item;?><?php }?>
		</div>
	</div>
	<div class="temp_box1">
		<li class="x_sel">排序规则</li>
		<li>
		<span  id="id_field_sort"><select name="field_sort">
		<?php
		foreach($arr_source["hr_company_sort"] as $item=>$key){
			$str_sel="";
			if(isset($arr_fun["fun_perms"]["field_sort"]) && $item==$arr_fun["fun_perms"]["field_sort"]) $str_sel=" selected";
			echo "<option value='".$item."'>".$key."</option>";
		}
		?>
		</select></span>&nbsp;<select name="fields_sort_act"><option value='desc'>倒序</option><option value="asc"<?php if(isset($arr_fun["fun_perms"]["fields_sort_act"]) && "asc"==$arr_fun["fun_perms"]["fields_sort_act"]) echo " selected";?>>顺序</option></select>
		</li>
		<li class="x_sel">是否分页</li>
		<li><input type="radio" name="ispage" value="0" onclick="me_ispage(0)" checked>否&nbsp;&nbsp;<input type="radio" name="ispage" value="1" onclick="me_ispage(1)"<?php if(isset($arr_fun["fun_perms"]["ispage"]) && "1"==$arr_fun["fun_perms"]["ispage"]) echo " checked";?>>是</li>
		<li class="x_sel" id="id_limit_tit"><?php if(!isset($arr_fun["fun_perms"]["ispage"]) || "1"!=$arr_fun["fun_perms"]["ispage"]){echo "显示数量";}else{echo '分页大小';};?></li>
		<li id="id_ispagesize" <?php if(!isset($arr_fun["fun_perms"]["ispage"]) || "1"!=$arr_fun["fun_perms"]["ispage"]) echo " style='display:none'";?>><input type="text" name="ispagesize" value="10" style="width:30px"></li>
		<li id="id_limit" <?php if(isset($arr_fun["fun_perms"]["ispage"]) && "1"==$arr_fun["fun_perms"]["ispage"]) echo " style='display:none'";?>><input type="radio" name="field_limit" value="0" checked>取前 <input type="text" name="limit_0" value="10" style="width:30px"> 条&nbsp;&nbsp;[或]&nbsp;&nbsp;<input type="radio" name="field_limit" value="1"> 从 <input type="text" name="limit_1" value="" style="width:30px"> 取到 <input type="text" name="limit_2" value="" style="width:30px"> 条</li>
	</div>
	<div class="temp_box2">
		<li></li>
	</div>
	<div class="temp_next"><input type="button" name="btn_next1" value="下一步" onclick="meStep(2);"></div>
</div>
<div id="id_step2" style="display:none;width:100%">
	<div class="temp_box1" id="id_source_box">
		<?php
		foreach($arr_source["hr_company"] as $item=>$key){
			echo "<li><a href=\"javascript:textarea_insertstr('id_content','{\$item[\'".$item."\']}');\">".$key."</a></li>";
		}
		?>
	</div>
	<div class="temp_box2">
		<textarea id="id_content" style="width:700px;height:100px" name="content"><?php if(isset($arr_fun["fun_cont"])) echo $arr_fun["fun_cont"];?></textarea>
	</div>
	<div class="temp_next"><input type="button" name="btn_next1" value="上一步" onclick="meStep(1);"><?php if(empty($get_funid)){?>&nbsp;&nbsp;<input type="button" name="btn_next1" value="生成代码" onclick="meStep(3);"><?php }?>&nbsp&nbsp;<input type="button" name="btn_next1" value=" 保 存 " onclick="meSaveFun(0);"><?php if($get_funid>0):?>
&nbsp&nbsp;<input type="button" name="btn_next1" value="另存为" onclick="meSaveFun(1);"><?php endif;?></div>
</div>
<div id="id_step3" style="display:none;width:100%">
	<div class="temp_box2">
		<textarea id="id_html" style="width:700px;height:200px" onpropertychange='this.style.posHeight=this.scrollHeight+2'></textarea>
	</div>
	<div class="temp_next"><input type="button" name="btn_next1" value="上一步" onclick="meStep(2);">&nbsp;&nbsp;<input type="button" name="btn_next1" value="复制" onclick="meCopy();">&nbsp&nbsp;<input type="button" name="btn_next1" value="插入" onclick="meInsert();"></div>
</div>
<script>
function meSelFunDir(){
		dialog_show("fundir","选择存在目录","getsql.php?act=funfolder&isselfolder=1",0,780,250);
}
function meSaveFun(msgtype){
	var funid=document.getElementById("id_funid").value;
		var strcontent="<div style='float:left;padding:10px;line-height:30px'>目录：<span id='id_funfolder'><?php if(isset($arr_fun["folder_name"])) echo $arr_fun["folder_name"];?></span><input type='hidden' id='id_funfolderid' name='funfolderid' value='<?php if(isset($arr_fun["fun_folder_id"])) echo $arr_fun["fun_folder_id"];?>'>&nbsp;<a href=\"javascript:meSelFunDir();\">选择</a><br>";
		strcontent+="名称：<input type='text' name='funname' value='<?php if(isset($arr_fun["fun_name"])) echo $arr_fun["fun_name"];?>' id='id_funname'><br><br>";
		strcontent+="<input type='button' name='btnSaveFun' value='确定' onclick=\"meSaveFunOK("+msgtype+");\"></div>";
	if(msgtype==1 || funid==0){
		dialog_show_cont("mefunname",strcontent,"保存到文件",400,150);
	}else{
		dialog_show_cont("mefunname",strcontent,"保存到文件",400,150,1);
		meSaveFunOK(0);
	}
}
function meSaveFunOK(msgtype){
	var folderid=document.getElementById("id_funfolderid").value;
	var funname=document.getElementById("id_funname").value;
	document.frmMain.action="?funfolderid="+folderid+"&funname="+funname;
	if(msgtype==1) frmSet('funid',0);//另存为
	frmExecute('savefun');
}

function me_ispage(msgx){
	var obj_limit=document.getElementById("id_limit");
	var obj_limit_tit=document.getElementById("id_limit_tit");
	var obj_ispagesize=document.getElementById("id_ispagesize");
	if(msgx==0){
		obj_limit.style.display="";
		obj_limit_tit.innerHTML="显示数量 ";
		obj_ispagesize.style.display="none";
	}else{
		obj_limit.style.display="none";
		obj_limit_tit.innerHTML="分页大小 ";
		obj_ispagesize.style.display="";
	}
}
function meCopy(){
	var strx=document.getElementById("id_html").value;
	copy(strx);
}
function meInsert(){
	var strx=document.getElementById("id_html").value;
	parent.textarea_insertstr('file_content',strx);
	parent.div_hide_show('wingetsql');
}
function meStep(msgx){
	var obj1=document.getElementById("id_step1");
	var obj2=document.getElementById("id_step2");
	var obj3=document.getElementById("id_step3");
	if(msgx==1){
		obj1.style.display="";
		obj2.style.display="none";
	}else if(msgx==2){
		obj1.style.display="none";
		obj2.style.display="";
		obj3.style.display="none";
	}else if(msgx==3){
		me_submit();
		areabox_autoheight("id_html");
		obj2.style.display="none";
		obj3.style.display="";
	}
}
function me_source(msgkey){
	var msgkey=document.getElementById("id_table_name").value;
	yj_ajax_get("getsql.php?isajax=1&act=source&source="+msgkey,function(data){
			if(data!=""){
				obj_x=document.getElementById("id_source_box");
				arr_x=data.split("|||");
				obj_x.innerHTML=arr_x[0];
				if(arr_x.length>1){
					obj_x=document.getElementById("id_field_sort");
					obj_x.innerHTML='<select name="field_sort">'+arr_x[1]+'</select>';
				}
			}
	});
	var obj_x=document.getElementById("id_folder_list");
	var obj_y=document.getElementById("id_folder_box");
	if(msgkey=="article"){
		if(obj_x.innerHTML==""){
			yj_ajax_get("getsql.php?act=folderlist&isajax=1",function(data){
				if(data!=""){
					var obj_x=document.getElementById("id_folder_list");
					obj_x.innerHTML=data;
				}
			});
		}
		obj_y.style.display="";
	}else{
		obj_y.style.display="none";
	}
}
function me_submit(){
	frmSet("act","exe");
	yj_ajax_post(document.frmMain,function(data){
		obj_x=document.getElementById("id_html");
		obj_x.value=data;
	});
}
areabox_autoheight("id_html");
me_source();
</script>
<?php include 'footer.tpl.php';?>