<?php
	
	/*公共方法处理类*/
	class Jqlib{
		/*
		* 菜单缓存生成
		*
		*/
		public function CategoryCreate($id,$Table,$file='nav.json'){
			global $conn;
			$json_str = json_encode(self::ShowMenu_All($id,$Table));
			PHP_Write("../CacheData/".$file,$json_str);
		}
		
		//循环获取菜单的json样式
		public 	function ShowMenu_All($ID,$Table){
				global $tempcataStr; 
				$db = mysql_query("select id,title,CatalogParentId,Mlevel from ".DB_TablePre.$Table." where CatalogParentId=".$ID." order by SortId asc");
				while($rsSM = mysql_fetch_array($db)){
					$Smt=$rsSM["title"];//==标题==
					$tempcataStr[$rsSM['CatalogParentId']][$rsSM['id']] = array('id'=>$rsSM['id'],'title'=>$Smt,'Mlevel'=>$rsSM['Mlevel']);
					self::ShowMenu_All($rsSM["id"],$Table);
				}				
				return $tempcataStr;
		}
		
		//根据缓存判断菜单根目录应该点击那个ID
		public function showNavByid($navtpye,$page,$file='nav.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				if(empty($xia_arr)){
					$cid = $navtpye;
				}elseif(is_array($xia_arr)){
					foreach ($xia_arr as $key => $value) {
						$cid = $key;
						break;
					}
				}else{
					$cid = $navtpye;
				}
				return $page.'?cid='.$cid;
			}
		}

		//显示子栏目，下拉菜单形式
		public function showNavXia($navtpye,$page,$file='nav.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				if(empty($xia_arr)){
					return ;
				}elseif(is_array($xia_arr)){
					foreach ($xia_arr as $key => $value){
						$li .= '<li><a href="'.$page.'?cid='.$key.'">'.$value['title'].'</a></li>';
					}
					return $li;
				}else{
					return ;
				}
				return ;
			}
		}
		
		//显示子栏目，下拉菜单形式
		public function linkinfo($navtpye,$page,$file='nav.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return $page.'?cid='.$navtpye;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				//如果没有下级分类数组
				if(empty($xia_arr)){
					return $page.'?cid='.$navtpye;
				}elseif(is_array($xia_arr)){
					//如果存在数组分类，循环显示，并且显示第一个
					foreach ($xia_arr as $key => $value){
						$li = $page.'?cid='.$key;
						return $li;
					}
					return $li;
				}else{
					//其他情况直接显示
					return $page.'?cid='.$navtpye;
				}
				return $page.'?cid='.$navtpye;
			}
		}
		//读取所以菜单项目
		public function showNavArray($path,$file='nav.json'){
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile($path.'./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				return $data;
			}
		}
	
	}

	class Jqlib_library{
		/*
		* 菜单缓存生成
		*
		*/
		public function CategoryCreate($id,$Table,$file='library.json'){
			global $conn;
			$json_str = json_encode(self::ShowMenu_All($id,$Table));
			PHP_Write("../CacheData/".$file,$json_str);
		}
		
		//循环获取菜单的json样式
		public 	function ShowMenu_All($ID,$Table){
				global $tempcataStr; 
				$db = mysql_query("select id,title,CatalogParentId,Mlevel from ".DB_TablePre.$Table." where CatalogParentId=".$ID." order by SortId asc");
				while($rsSM = mysql_fetch_array($db)){
					$Smt=$rsSM["title"];//==标题==
					$tempcataStr[$rsSM['CatalogParentId']][$rsSM['id']] = array('id'=>$rsSM['id'],'title'=>$Smt,'Mlevel'=>$rsSM['Mlevel']);
					self::ShowMenu_All($rsSM["id"],$Table);
				}				
				return $tempcataStr;
		}
		
		//根据缓存判断菜单根目录应该点击那个ID
		public function showNavByid($navtpye,$page,$file='library.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				if(empty($xia_arr)){
					$cid = $navtpye;
				}elseif(is_array($xia_arr)){
					foreach ($xia_arr as $key => $value) {
						$cid = $key;
						break;
					}
				}else{
					$cid = $navtpye;
				}
				return $page.'?cid='.$cid;
			}
		}

		//显示子栏目，下拉菜单形式
		public function showNavXia($navtpye,$page,$file='library.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				if(empty($xia_arr)){
					return ;
				}elseif(is_array($xia_arr)){
					foreach ($xia_arr as $key => $value){
						$li .= '<li><a href="'.$page.'?cid='.$key.'">'.$value.'</a></li>';
					}
					return $li;
				}else{
					return ;
				}
				return ;
			}
		}
		
		//读取所以菜单项目
		public function showNavArray($path,$file='library.json'){
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile($path.'./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				return $data;

			}
		}
	
	}

	class Jqlib_jobmarket{
		/*
		* 菜单缓存生成
		*
		*/
		public function CategoryCreate($id,$Table,$file='jobmarket.json'){
			global $conn;
			$json_str = json_encode(self::ShowMenu_All($id,$Table));
			PHP_Write("../CacheData/".$file,$json_str);
		}
		
		//循环获取菜单的json样式
		public 	function ShowMenu_All($ID,$Table){
				global $tempcataStr; 
				$db = mysql_query("select id,title,CatalogParentId,Mlevel from ".DB_TablePre.$Table." where CatalogParentId=".$ID." order by SortId asc");
				while($rsSM = mysql_fetch_array($db)){
					$Smt=$rsSM["title"];//==标题==
					$tempcataStr[$rsSM['CatalogParentId']][$rsSM['id']] = array('id'=>$rsSM['id'],'title'=>$Smt,'Mlevel'=>$rsSM['Mlevel']);
					self::ShowMenu_All($rsSM["id"],$Table);
				}				
				return $tempcataStr;
		}
		
		//根据缓存判断菜单根目录应该点击那个ID
		public function showNavByid($navtpye,$page,$file='jobmarket.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				if(empty($xia_arr)){
					$cid = $navtpye;
				}elseif(is_array($xia_arr)){
					foreach ($xia_arr as $key => $value) {
						$cid = $key;
						break;
					}
				}else{
					$cid = $navtpye;
				}
				return $page.'?cid='.$cid;
			}
		}

		//显示子栏目，下拉菜单形式
		public function showNavXia($navtpye,$page,$file='jobmarket.json'){
			$navtpye = floatval($navtpye);
			if($navtpye==0){return ;}
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile('./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				$xia_arr = $data[$navtpye];
				if(empty($xia_arr)){
					return ;
				}elseif(is_array($xia_arr)){
					foreach ($xia_arr as $key => $value){
						$li .= '<li><a href="'.$page.'?cid='.$key.'">'.$value.'</a></li>';
					}
					return $li;
				}else{
					return ;
				}
				return ;
			}
		}
		
		//读取所以菜单项目
		public function showNavArray($path,$file='jobmarket.json'){
			$file_name = '../CacheData/'.$file;
			$str  =  readfromfile($path.'./CacheData/'.$file);
			if(empty($str)){
				return ;
			}else{
				$data = json_decode($str,true);
				return $data;

			}
		}
	
	}
