<?php
require 'inc.php';
$obj_tab_jobcategory=new cls_tab_hr_job_category($obj_db);
$tab_jobcategory=DB_PRE."hr_job_category";

if(!isset($int_pagesize)) $int_pagesize=10;
if(!isset($get_act)) $get_act="";
(!isset($get_page))? $get_page=0:$get_page=intval($get_page);
(!isset($get_id))? $get_id=0:$get_id=intval($get_id);
(isset($get_me_pid))?$get_me_pid=intval($get_me_pid):$get_me_pid=0;
(!isset($get_me_categoryid))?$get_me_categoryid=0:$get_me_categoryid=intval($get_me_categoryid);
$cateogry_path="<a href=\"javascript:meSetpid('0');\">¶¥¼¶</a>";
$cateogry_path.=me_category_path($get_me_pid);

$page_footer_info=<<<HTML
<script>function meSetpid(msgpid){document.getElementById('me_pid').value=msgpid;frmExecute('');}</script>
<input type='hidden' name='me_pid' value='$get_me_pid' id="me_pid">
HTML;

if($get_act=="save"){
	$str_pids="";
	$str_pids=$get_me_pid;
	$str_sql="select category_pids from ".$tab_jobcategory." where category_id='".$get_me_pid."'";
	$obj_result  = $obj_db->query($str_sql);
	$str_names="";
	if($obj_rs=$obj_db->fetch_array($obj_result))
	{
		$str_pids=$obj_rs["category_pids"].",".$get_me_pid;
	}
	for($i=0;$i<count($get_categoryid);$i++)
	{
		(isset($get_categoryid[$i]))?$str_id=intval($get_categoryid[$i]):$str_id=0;
		(isset($get_category_name[$i]))?$str_category_name=$get_category_name[$i]:$str_category_name="";
		(isset($get_category_sort[$i]))?$str_category_sort=$get_category_sort[$i]:$str_category_sort="";
		if($str_category_name!="")
		{			
			$arr_fields=array();
			$arr_fields["category_name"]=$str_category_name;
			$arr_fields["category_sort"]=$str_category_sort;
			$arr_fields["category_pid"]=$get_me_pid;
			$arr_fields["category_pids"]=$str_pids;
			$arr_fields["category_id"]=$str_id;
			$arr_msg=$obj_tab_jobcategory->on_save($arr_fields);
			if($arr_msg["err"]!=""){
				$obj_msg->alert($arr_msg["err"]);
			}

		}
	}
	$get_act="";

}

if($get_act=='del')
{
	$arr_msg=$obj_tab_jobcategory->on_del($get_id);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}


$arr_category = array();
$obj_result = $obj_db->query("SELECT * FROM ".$tab_jobcategory." where category_pid='".$get_me_pid."' order by category_sort,category_id desc");
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$arr_category[] = $obj_rs;
}
include 'tpl/job.category.tpl.php';

function me_category_path($msg_pid)
{
	global $obj_db,$tab_jobcategory;
	$str_sql="select category_id,category_name,category_pid from ".$tab_jobcategory." where category_id='".$msg_pid."'";
	$obj_result = $obj_db->query($str_sql);
	$str_val="";
	if($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$str_val=" -> <a href=\"javascript:meSetpid('".$obj_rs['category_id']."');\">".$obj_rs['category_name']."</a>";
		$str_val=me_category_path($obj_rs['category_pid']).$str_val;
	}
	return $str_val;

}


?>
