<?php
class Helper
{
	function Helper()
	{
		$GLOBALS['Templ']->assign('base_weburl',BASE_WEBURL);
		$GLOBALS['Templ']->assign('domain_name',DOMAIN_NAME);
		$GLOBALS['Templ']->assign('employee_weburl',EMPLOYEE_WEBURL);
		//$GLOBALS['Templ']->assign('webroot_url',BASE_WEBURL);
	}
	function getip()
	{
			if ($_SERVER["HTTP_X_FORWARDED_FOR"]) 
			{ 
				$getip = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
			}elseif ($_SERVER["HTTP_CLIENT_IP"]) 
			{ 
				$getip = $_SERVER["HTTP_CLIENT_IP"]; 
			}elseif ($_SERVER["REMOTE_ADDR"]) 
			{ 
				$getip = $_SERVER["REMOTE_ADDR"]; 
			}elseif ($_SERVER["HTTP_X_FORWARDED_FOR"]) 
			{ 
				$getip = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
			}elseif ($_SERVER["HTTP_CLIENT_IP"]) 
			{ 
				$getip = $_SERVER["HTTP_CLIENT_IP"]; 
			}elseif ($_SERVER["REMOTE_ADDR"]) 
			{ 
				$getip = $_SERVER["REMOTE_ADDR"]; 
			}elseif (getenv("HTTP_X_FORWARDED_FOR")) 
			{ 
				$getip = getenv("HTTP_X_FORWARDED_FOR"); 
			}elseif (getenv("HTTP_CLIENT_IP")) 
			{ 
				$getip = getenv("HTTP_CLIENT_IP"); 
			}elseif (getenv("REMOTE_ADDR"))
			{
				$getip = getenv("REMOTE_ADDR"); 
			}else 
			{ 
				$getip = "Unknown"; 
			} 
			//["QUERY_STRING"]
			return  $getip;
	}
	
	function addKeyword( $newkeyword ='' , $type = 'new')
	{
		$keyid = '';
		if( $newkeyword != '')
		{
			//查询是否存在关键字
			$selectsql = " SELECT key_id FROM ".SQL_PREFIX."keywork WHERE key_word ='".$newkeyword."' ";
			$idarray   = $GLOBALS['MySql'] -> selectOne( $selectsql );
			
			if($idarray["key_id"]!='')
			{
				$keyid = $idarray["key_id"];
				$upsql = " UPDATE  ".SQL_PREFIX."keywork SET key_count = key_count + 1 WHERE key_id ='".$idarray["key_id"]."' ";
				$GLOBALS['MySql'] -> querySql( $upsql );
				
				
			}else{
				$insertsql = " INSERT INTO `".SQL_PREFIX."keywork` ( `key_word` , `key_isup` , `key_count` ) VALUES (  '".$newkeyword."', '0', '1' )";
				$keyid = $GLOBALS['MySql'] -> insertSql( $insertsql );
			}
		}
		return $keyid;
	}
	
	
	function get_config()
	{
		$sql = " SELECT cfs_id, cfs_name, cfs_codestr, cfs_value FROM ".SQL_PREFIX."configsys WHERE 	cfs_type = 'web' or ( cfs_codestr ='default' and cfs_type='temp')  GROUP BY cfs_id ORDER BY  cfs_id  LIMIT 100 ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sql);
			
		if ($info[0])
		{
		   $configRe = array();
		   foreach ($info as $row)
		   {
				$configRe[$row["cfs_codestr"]] = $row["cfs_value"]; 
		   }
		}

		return $configRe;
	}
	
	function build_contact($valarray)
	{
		//$conArray = array('webqq' => 'QQ：','webphote' => '电话：','webmail' => 'Email：','webadmin' => "联系人：",'webaddress' => '地址：');
		
		$reArray = array();
		foreach($valarray as $vkey => $vval)
		{
			$keyarray = explode(",", $vval);
			
			switch($vkey)
			{
				case 'webqq':
					foreach($keyarray as $kkkey => $kkval)
					{
						if($kkval!='')
						{
							$reArray[] = '<a href="http://wpa.qq.com/msgrd?V=1&amp;Uin='.$kkval.'&amp;Site=在线客服&amp;Menu=yes" target="_black" title="您好！很高兴为您服务，请问有什么可以帮您吗？"><img border="0" src="http://wpa.qq.com/pa?p=1:'.$kkval.':41" /></a>';
							
						}
					}
					break;
				case 'webphote':
					foreach($keyarray as $kkkey => $kkval)
					{
						if($kkval!='')
						{
							$reArray[] = '电话：'.$kkval;
						}
					}
					break;
				case 'webmail':
					foreach($keyarray as $kkkey => $kkval)
					{
						if($kkval!='')
						{
							$reArray[] = '邮箱：<a href="mailto:'.$kkval.'">'.$kkval.'</a>';
						}
					}
					break;
				case 'webadmin':
					foreach($keyarray as $kkkey => $kkval)
					{
						if($kkval!='')
						{
							$reArray[] = '联系人：'.$kkval;
						}
					}
					break;
				case 'webaddress':
					foreach($keyarray as $kkkey => $kkval)
					{
						if($kkval!='')
						{
							$reArray[] = '地址：'.$kkval;
						}
					}
					break;
		    }
		 }
		 return $reArray;
	}

	function get_bbsconfig()
	{
		$sql = " SELECT cfs_id, cfs_name, cfs_codestr, cfs_value FROM ".SQL_PREFIX."configsys WHERE 	cfs_type = 'bbs'  GROUP BY cfs_id ORDER BY  cfs_id  LIMIT 100 ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sql);
			
		if ($info[0])
		{
		   $configRe = array();
		   foreach ($info as $row)
		   {
				$configRe[$row["cfs_codestr"]] = $row["cfs_value"]; 
		   }
		}
		if($configRe["default"]!=''){ $GLOBALS['tpl_path'] = $configRe["default"]; }
		
		if($configRe["webclose"]==1)
		{
			echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
			echo '<br><center>'.$configRe["webclosevalue"].'</center>'; 
			exit('');
		}
		return $configRe;	
	}

	function get_menu()
	{
		$sql = " SELECT web_id, web_name, web_url, web_place, web_targetval FROM ".SQL_PREFIX."webmenu WHERE web_enabled = 1 GROUP BY web_id ORDER BY web_list LIMIT 30 ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sql);
		if(isset($info[0]))
		{
		   $webmenuRe = array();
		   foreach ($info as $row)
		   {
				if(strstr($row["web_url"],'http://'))
				{
					$webmenuRe[$row["web_place"]][]['relurl'] = '<a href="'.$row["web_url"].'" target="'.$row["web_targetval"].'" >'.$row["web_name"].'</a>' ; 
				}else{
					$webmenuRe[$row["web_place"]][]['relurl'] = '<a href="'.BASE_WEBURL.$row["web_url"].'" target="'.$row["web_targetval"].'" >'.$row["web_name"].'</a>' ; 
				}
		   }
		}
 
		return $webmenuRe;
	}
	
	function get_usermenu()
	{
		$sqlQuery = " SELECT web_id, web_name, web_url, web_place,web_list,web_parentid FROM  ".SQL_PREFIX."webmenu  WHERE  web_place = 'user' and  web_enabled = 1 GROUP BY web_id ORDER BY `web_id` LIMIT  0 , 100";

		$infosm = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$webmenuInfo = array();
		  foreach ($infosm as $rowkey => $rowval)
		  {
		   		if($rowval["web_parentid"] == 0)
				{
					$webmenuInfo[$rowval["web_id"]]['web_id'] 		 = $rowval["web_id"] ;
					$webmenuInfo[$rowval["web_id"]]['web_name'] 	 = $rowval["web_name"] ;
					$webmenuInfo[$rowval["web_id"]]['web_parentid']  = $rowval["web_parentid"] ;
					$webmenuInfo[$rowval["web_id"]]['web_place']     = $rowval["web_place"] ;
					$webmenuInfo[$rowval["web_id"]]['web_url'] 	     = $rowval["web_url"] ;
					$webmenuInfo[$rowval["web_id"]]['web_list'] 	 = $rowval["web_list"] ;
					$webmenuInfo[$rowval["web_id"]]['web_list'] 	 = $rowval["web_list"] ;
				}else{
					$webmenuInfo[$rowval["web_parentid"]]['array'][] = $rowval;	
				}
		 }
		   
		$GLOBALS['Templ'] -> assign('webmenuInfo',$webmenuInfo);
	}
	
	
	function get_prosort()
	{
		$sql = " SELECT prs_id,prs_name, prs_parentid, prs_enabled,prs_list FROM  ".SQL_PREFIX."prosort  WHERE 1 GROUP BY prs_id ORDER BY prs_list,`prs_id` LIMIT 600 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sql);
		
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			foreach ((array)$infosm as $rowkey => $rowval)
			{
					if($rowval["prs_parentid"] == 0)
					{
						$info[$rowval["prs_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/pro-list-1-'.$rowval["prs_id"].'.html" >'.$rowval["prs_name"].'</a>' ;  //target="_blank"
	
					}else{
						$info[$rowval["prs_parentid"]]['array'][$rowval["prs_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/pro-list-1-'.$rowval["prs_id"].'.html" >'.$rowval["prs_name"].'</a>' ;   //target="_blank"
					}
			}
		}else{
			foreach ((array)$infosm as $rowkey => $rowval)
			{
					if($rowval["prs_parentid"] == 0)
					{
						$info[$rowval["prs_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=pro&act=infolist&sid='.$rowval["prs_id"].'" >'.$rowval["prs_name"].'</a>' ;  //target="_blank"
	
					}else{
						$info[$rowval["prs_parentid"]]['array'][$rowval["prs_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=pro&act=infolist&sid='.$rowval["prs_id"].'" >'.$rowval["prs_name"].'</a>' ;  //target="_blank"
					}
			}
		}

		return $info;
	}


	
	
	function get_artsort()
	{
		$sql = " SELECT ars_id,ars_name, ars_parentid, ars_enabled,ars_list FROM  ".SQL_PREFIX."artsort  WHERE ars_enabled = 1 and ars_id <> 1 GROUP BY ars_id ORDER BY ars_list,`ars_id` LIMIT 600 ";

		$infosm = $GLOBALS['MySql'] -> selectInfo($sql);
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{	
			foreach ((array)$infosm as $rowkey => $rowval)
			{
				if($rowval["ars_parentid"] == 0 and $rowval["ars_id"]!='')
				{
					$info[$rowval["ars_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/art-list-1-'.$rowval["ars_id"].'.html" >'.$rowval["ars_name"].'</a>' ;  //target="_blank"
				}else if($rowval["ars_id"]!=''){
					$info[$rowval["ars_parentid"]]['array'][$rowval["ars_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/art-list-1-'.$rowval["ars_id"].'.html" >'.$rowval["ars_name"].'</a>' ;
				}	
			}
		}else{
			foreach ((array)$infosm as $rowkey => $rowval)
			{
				if($rowval["ars_parentid"] == 0 and $rowval["ars_id"]!='')
				{
					$info[$rowval["ars_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=art&act=infolist&sid='.$rowval["ars_id"].'" >'.$rowval["ars_name"].'</a>' ;  //target="_blank"
				}else if($rowval["ars_id"]!=''){
					$info[$rowval["ars_parentid"]]['array'][$rowval["ars_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=art&act=infolist&sid='.$rowval["ars_id"].'" >'.$rowval["ars_name"].'</a>' ;
				}
			}
		}

		return $info;
	}
	
	
	
	function get_picsort()
	{
		$sql = " SELECT pis_id,pis_name, pis_parentid, pis_enabled,pis_list FROM  ".SQL_PREFIX."picsort  WHERE 1 GROUP BY pis_id ORDER BY pis_list,`pis_id` LIMIT 600 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sql);
		
		$info = array();
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{	
			foreach ((array)$infosm as $rowkey => $rowval)
			{
					if($rowval["pis_parentid"] == 0)
					{
						$info[$rowval["pis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/pic-list-1-'.$rowval["pis_id"].'.html" >'.$rowval["pis_name"].'</a>' ;  //target="_blank"
	
					}else{
						$info[$rowval["pis_parentid"]]['array'][$rowval["pis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/pic-list-1-'.$rowval["pis_id"].'.html" >'.$rowval["pis_name"].'</a>' ; 
					}
			}
		}else{
			foreach ((array)$infosm as $rowkey => $rowval)
			{
					if($rowval["pis_parentid"] == 0)
					{
						$info[$rowval["pis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=pic&act=infolist&sid='.$rowval["pis_id"].'" >'.$rowval["pis_name"].'</a>' ;  //target="_blank"
	
					}else{
						$info[$rowval["pis_parentid"]]['array'][$rowval["pis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=pic&act=infolist&sid='.$rowval["pis_id"].'" >'.$rowval["pis_name"].'</a>' ; 
					}
			}
		}

		return $info;
	}


	function get_vidsort()
	{
		$sql = " SELECT vis_id,vis_name, vis_parentid, vis_enabled,vis_list FROM  ".SQL_PREFIX."vidsort  WHERE 1 GROUP BY vis_id ORDER BY vis_list,`vis_id` LIMIT 600 ";
		
		$infosm = $GLOBALS['MySql'] -> selectInfo($sql);
		
		$info = array();
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{	
			foreach ((array)$infosm as $rowkey => $rowval)
			{
					if($rowval["vis_parentid"] == 0)
					{
						$info[$rowval["vis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/vid-list-1-'.$rowval["vis_id"].'.html" >'.$rowval["vis_name"].'</a>' ;  //target="_blank"
	
					}else{
						$info[$rowval["vis_parentid"]]['array'][$rowval["vis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/vid-list-1-'.$rowval["vis_id"].'.html" >'.$rowval["vis_name"].'</a>' ; 
					}
			}
		}else{
			foreach ((array)$infosm as $rowkey => $rowval)
			{
					if($rowval["vis_parentid"] == 0)
					{
						$info[$rowval["vis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=vid&act=infolist&sid='.$rowval["vis_id"].'" >'.$rowval["vis_name"].'</a>' ;  //target="_blank"
	
					}else{
						$info[$rowval["vis_parentid"]]['array'][$rowval["vis_id"]]['relurl'] = '<a href="'.BASE_WEBURL.'/?load=vid&act=infolist&sid='.$rowval["vis_id"].'" >'.$rowval["vis_name"].'</a>' ; 
					}
			}
		}

		return $info;
	}
	

	
	function get_link()
	{

		$sql = " SELECT lin_id, lin_name, lin_url FROM ".SQL_PREFIX."link WHERE lin_enabled = 1 GROUP BY lin_id ORDER BY lin_list LIMIT 10 ";
		$info = $GLOBALS['MySql'] -> selectInfo($sql);
		$linksRe = array();	
		if ($info[0])
		{ 
		   foreach ($info as $row)
		   {
				$linksRe[$row["lin_id"]]["relurl"] = '<a href="'.$row["lin_url"].'" target="_blank">'.$row["lin_name"].'</a>' ; 
		   }
		}
		return $linksRe;
	}
	
	
	function get_ads( $instr = '1,2,3,4,5,6,7,8,9,10,11' )
	{
		//时间还不起作用。没处理
		$nowtime  = time();
		$sql = " SELECT p.adp_id, p.adp_width,p.adp_height,ad.ad_name,ad.ad_link,ad.ad_mediatype,ad.ad_code,ad.ad_starttime,ad.ad_endtime  FROM  ".SQL_PREFIX."adposition as p left join ".SQL_PREFIX."ad as ad on p.adp_id = ad.adp_id  WHERE p.adp_id in ( $instr ) and  ad.ad_id  is not null and ad_endtime > $nowtime  and ad_starttime < $nowtime  GROUP BY p.adp_id ORDER BY p.adp_id LIMIT 50  ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sql);
		//var_dump($info);
		$adsRe = array();
		
		
		//1 图片,2 FLASH, 3代码, 4 文字。
		
		if (isset($info[0]))
		{ 
		   foreach ($info as $row)
		   {
				if( $row["ad_mediatype"] == 1)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<a href="'.$row["ad_link"].'" target="_blank"><img src="'.BASE_WEBURL.$row["ad_code"].'" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'" border="0" ></a>';
				}else if($row["ad_mediatype"] == 2)
				{
					$adsRe[$row["adp_id"]]["relurl"] = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'"><param name="movie" value="'.BASE_WEBURL.$row["ad_code"].'" /><param name="quality" value="high" /><embed src="'.BASE_WEBURL.$row["ad_code"].'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'.$row["adp_width"].'" height="'.$row["adp_height"].'"></embed></object>';
				}else if($row["ad_mediatype"] == 3)
				{
					$adsRe[$row["adp_id"]]["relurl"] = $row["ad_code"];
				}else if($row["ad_mediatype"] == 4){
				
					$adsRe[$row["adp_id"]]["relurl"] = $row["ad_code"];
				}else{
					$adsRe[$row["adp_id"]]["relurl"] = '';
				}
		   }
		}
		//var_dump( $adsRe );
		return $adsRe;
		
	}
	
	function build_xml( $arrval = array(), $contenthtml ='', $file_name ='')
	{
		foreach($arrval as $key => $val)
		{
			$contenthtml = str_replace("{".$key."}", $val , $contenthtml);
		}
		$this -> write_file($file_name,$contenthtml,$method="w+");
	}
	
	//写文件生成文件
	function write_file($file_name,$content,$method="w+")
	{
		if($filenum=fopen($file_name,$method)){
			flock($filenum,LOCK_EX);
			$file_data=fwrite($filenum,$content);
			flock($filenum,LOCK_UN);
			fclose($filenum);
			return true;
		}else{
			return false;
		}
	}
	
	function get_areadict( $parentid = 0 , $are_type=0)
	{

		$sql = " SELECT are_id, are_parentid, are_name  FROM ".SQL_PREFIX."areadict WHERE are_parentid = $parentid GROUP BY are_id ORDER BY are_id  ";
		$info = $GLOBALS['MySql'] -> selectInfo($sql);
		
		$linksRe = array();	
		if ($info[0])
		{ 
		   foreach ($info as $row)
		   {
				$linksRe[$row["lin_id"]]["relurl"] = '<a href="'.$row["lin_url"].'" target="_blank">'.$row["lin_name"].'</a>' ; 
		   }
		}
		return $linksRe;
	}
	
	
	function get_rank( $num = 0 , $type = 'all' )
	{
		$basenum = 4 ;
		
		//星星 月亮 太阳 金 紫金 黄金 白金 宝石 钻石 至尊王者
		//1 X 4 = 4 星星 
		//4 X 4 = 16 月亮
		//16 X 4 =64 太阳
		//64 X 4 = 256 金
		//256 X 4 = 1024 紫金
		//1024 X 4 = 4096 黄金
		//4096 X 4 = 16384 白金
		//16384 X 4 = 65536 宝石
		//65536 X 4 = 262144 钻石
		//262144 X4 = 1048576 至尊王者

		$rankArray = array( 'ten'=> 0, 'nine'=> 0, 'eight'=> 0, 'seven'=> 0, 'six'=> 0, 'five'=> 0, 'foure'=> 0, 'three'=> 0, 'two'=> 0, 'one'=> 0 );
		
		$nextnum = $num ;
		$rankArray['ten'] =  floor( $num / 1048576 );
		
		
		if($nextnum >= 0 )
		{
			$nextnum = $num - ( $rankArray['ten'] * 1048576);
			$rankArray['nine'] = floor( $nextnum / 262144 );
		}
		

		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ( $rankArray['nine'] * 262144);
			$rankArray['eight'] = floor($nextnum/65536);	
		}


		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ( $rankArray['eight'] * 65536);
			$rankArray['seven'] = floor($nextnum/16384);
		}

		if($nextnum >= 0 )
		{	
			$nextnum = $nextnum - ($rankArray['seven'] * 16384);
			$rankArray['six'] = floor($nextnum/4096);
		}
		

		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ( $rankArray['six'] * 4096);
			$rankArray['five'] = floor($nextnum/1024);
		}
		
		

		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ($rankArray['five'] * 1024);
			$rankArray['foure'] = floor($nextnum/256);
		}



		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ($rankArray['foure'] * 256);
			$rankArray['three'] = floor($nextnum/64);
		}



		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ($rankArray['three'] * 64);
			$rankArray['two'] = floor($nextnum/16);
		}


		if($nextnum >= 0 )
		{
			$nextnum = $nextnum - ($rankArray['two'] * 16);
			$rankArray['one'] = floor($nextnum/4);
			$this -> get_userRankimg($rankArray['one'],1);
		}
		
		$str = '';
		if($type =='all')
		{
			$str .= $this -> get_userRankimg($rankArray['ten'],10);
			$str .= $this -> get_userRankimg($rankArray['nine'],9);
			$str .= $this -> get_userRankimg($rankArray['eight'],8);
			$str .= $this -> get_userRankimg($rankArray['seven'],7);
			$str .= $this -> get_userRankimg($rankArray['six'],6);
			$str .= $this -> get_userRankimg($rankArray['five'],5);
			$str .= $this -> get_userRankimg($rankArray['foure'],4);
			$str .= $this -> get_userRankimg($rankArray['three'],3);
			$str .= $this -> get_userRankimg($rankArray['two'],2);
			$str .= $this -> get_userRankimg($rankArray['one'],1);
			
		}else{
			
			$str = $this -> get_userRankimg($rankArray['one'],1);
			$strtwo = $this -> get_userRankimg($rankArray['two'],2);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['three'],3);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['foure'],4);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['five'],5);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['six'],6);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['seven'],7);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['eight'],8);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['nine'],9);
			$str = $strtwo !='' ?   $strtwo : $str;
			$strtwo = $this -> get_userRankimg($rankArray['ten'],10);
			$str = $strtwo !='' ?   $strtwo : $str;
			

		}
		return $str;
		//var_dump($rankArray);
	}
	
	function get_userRankimg($num,$rank)
	{
		for($i=0; $i < $num; $i++)
		{
			$str .= '<img src="'.BASE_WEBURL.'/img/g/'.$rank.'.gif">';
		}
		//echo $str;
		return $str;
	}
	
	/*
		编辑器生成方法
		$toolbar = 'Full' , 'Basic';
	*/
	function load_ckeditor( $textName = 'textContent', $textValue = '' , $toolbar = 'Full' , $uiColor = '#D3D3D3', $width = '800',$height = '220', $ckeditorLoadName = 'ckeditorLoad' ,$Loadjs = true )
	{
		$ckeditorLoad = '';
		if($Loadjs==true)
		{  
			$ckeditorLoad = '<script type="text/javascript" src="'.BASE_WEBURL.'/application/ckeditor/ckeditor.js"></script>';
		}
		if($width=='')
		{
			$ckeditorLoad .= '<textarea name="'.$textName.'" id="'.$textName.'">'.$textValue.'</textarea>
							<script type="text/javascript">
							var ckwidthval = window.screen.width - 300;
							CKEDITOR.replace(\''.$textName.'\',{ toolbar :\''.$toolbar.'\',uiColor : \'#9AB8F3\',height:120 ,width:ckwidthval });
							</script>';
		}else{
			$ckeditorLoad .= '<textarea name="'.$textName.'" id="'.$textName.'">'.$textValue.'</textarea>
							<script type="text/javascript">
							CKEDITOR.replace(\''.$textName.'\',{ toolbar :\''.$toolbar.'\',uiColor : \'#9AB8F3\', height:'.$height.' ,width:'.$width.' });
							</script>';
		}
		$GLOBALS['Templ']->assign( $ckeditorLoadName ,$ckeditorLoad);
	}
	
	
	//用户及图片
	function builddir( $rootdir = 'com' , $type = 'num', $strfornum = 2, $buildforNum = 2  )
	{
		$numArray = array('0','1','2','3','4','5','6','7','8','9'); //全数字字符 10个
		
		$strArray = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');  //全合适符号共,36个符号
		$rArray = array();//$strfornum = 2; //位数处理 1 , 2 ,3 , 4, 5 组合 规定不超过5 位数
		
		if($type=='num')
		{
			$toforArray = $numArray;
		}else{
			$toforArray = $strArray;
		}
		
		for($i=0; $i < $strfornum; $i++)
		{
			if($i==0)
			{
				$rArray[$i+1] =  $toforArray;
			}else{
				foreach($toforArray as $nval )
				{
					foreach($rArray[$i] as $dval)
					{
						$rArray[$i+1][] = $nval.$dval;	
					}
				}
			}
		}
 
		
		for($bi=0; $bi < $buildforNum; $bi++)
		{
			//生成目录
			if($bi==0)
			{
				foreach($rArray[$strfornum] as $fval)
				{
					$fordir[$bi+1][] =  $fval;
					$this -> mkdiraction( $rootdir , $fval );
				}
			}else{
				foreach( $rArray[$strfornum] as $twodnval )
				{
					foreach($fordir[$bi] as $tddval)
					{
						$fordir[$bi+1][] = $tddval.'/'.$twodnval;
						$this -> mkdiraction( $rootdir , $tddval.'/'.$twodnval );
					}
				}
			}
		}
		return true;
		
	}
	
	function mkdiraction( $rootdir , $dirname )
	{
			//生成目录
			if($rootdir!='')
			{
				$filedir = DOCUMENT_ROOT.'/'.$rootdir.'/'.$dirname;
			}else{
				$filedir = DOCUMENT_ROOT.'/com' .$dirname;
			}
			if(!file_exists($filedir)){ mkdir($filedir, 0755); }
			return true;
	}
	
	
	

	function SecuritySumbit()
	{
		$strServerName 	= $_SERVER["SERVER_NAME"];
		$intLen 		= strlen($strServerName);
		$strFromURL 	= $_SERVER["HTTP_REFERER"];
		$strFromURL 	= substr($strFromURL, 7, $intLen);
		if($strFromURL != $strServerName)
		{
			die("对不起，本站禁止跨站提交信息！");
		}
	}


	function CheckEmail( $mailval ) 
	{ 
		if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$",$mailval))
		{ 
			return false; 
		} 
		return true; 
	} 
	
	// 生成HTML文件时的路径
	function getHtmlPage( $username="" , $subdir="" ,$rootdir = 'list/')
	{
	
		//生成目录
		$filedir = ROOT_PATH.$rootdir. substr($username,0,3);
 
		if(!file_exists($filedir)) 
			mkdir($filedir, 0755);

		return substr($username,0,3);
	}
	
	// 生成HTML文件时的路径
	function getHtmlitem( $username="" , $subdir="" ,$rootdir = 'item/' )
	{
	
		//生成目录
		$ret = $first = substr($username,0,2);
		$filedir = ROOT_PATH.$rootdir . $first ;
 
		if(!file_exists($filedir)) 
			mkdir($filedir, 0755);
			
		$two = substr($username,2,2);
		
		if($two!='')
		{
		$filedir .= '/' .$two;
		$ret .= '/' .$two;	
		}else{
		$filedir .= '/0' ;
		$ret .= '/0';	
		}
		if(!file_exists($filedir)) 
			mkdir($filedir, 0755);

		return $ret;
	}

	function mystr_toabc($intstr) 
	{ 
		static $arr=array( //16=>'o',
		10=> 'a', 20 =>'b', 30=>'c',40=>'d',50=>'e',60=>'f',70=>'g',80=>'h',90=>'i',
		11=>'j',12=>'k',13=>'L',14=>'m',15=>'n',17=>'p',18=>'q',19=>'r',
		21=>'s',22=>'t',23=>'u',24=>'v',25=>'w',26=>'x',27=>'y',28=>'z'
		);
		
		foreach( $arr as $key => $val ){
			  $intstr = str_replace($key,$val ,$intstr );
		
		}
		
		return $intstr; 
	}

	function myabc_tostr($intstr) 
	{ 
		 $arr=array( //16=>'o',
		10=> 'a', 20 =>'b', 30=>'c',40=>'d',50=>'e',60=>'f',70=>'g',80=>'h',90=>'i',
		11=>'j',12=>'k',13=>'L',14=>'m',15=>'n',17=>'p',18=>'q',19=>'r',
		21=>'s',22=>'t',23=>'u',24=>'v',25=>'w',26=>'x',27=>'y',28=>'z'
		);
		
		foreach( $arr as $key => $val ){
			  $intstr = str_replace($val,$key,$intstr );
		}
		
		return $intstr; 
	}
	
	function orderby_list($oderbydefault ,$listval , $listtype )
	{
		$orderbyval = "";
		$listhtml = '';	//反向排序参数
		if($listval!='' and $listtype =='DESC' )
		{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			$endArray["listtype"] = '';
			$endArray["listval"]  = $listval;

		}else{
			$endArray["listtype"] = 'DESC';
			$endArray["listval"]  = 'art_uptime';
			$orderbyval = " a.art_uptime DESC , `art_id` DESC ";	
		}
		
		$GLOBALS['Templ']->assign('listhtml',$listhtml);
		$GLOBALS['Templ']->assign('listval',$listval);
		$GLOBALS['Templ']->assign('listtype',$listtype);
		
		return $re;
	}
	
	function getdirs( $dir ) 
    {
         $array = array();
         $d = @dir($dir);
         if($d)
         {
               while (false !== ($entry = $d->read())) 
               {
                   if($entry!='.' && $entry!='..') 
                   {
                       $back = $entry;
					   $entry = $dir.'/'.$entry;
                      
					   if(is_dir($entry)) 
                       {

                          $array[] = $back;
                       }
                   }
               }
               $d->close();
         }
         return $array;
     } 
	 
	//取一字母作为目录前缀
	function buildsmartydir( $type = 'n', $smdirid = '0')
	{
		if($smdirid==''){ //$smdirid = 0 ;
			return 	'';
		}else{
			return 	substr( $smdirid ,-1).$type;
		}
	}
	
	
	function buildImg( $fileName )
	{
		$ftype = end(explode('.', $fileName));
		return $small_img   	= 	$fileName.IMG_SMALLWIDTH."X".IMG_SMALLHEIGHT.".".$ftype;
	}
	
	//伪静态及动态生成URL处理
	function buildUrl( $valid , $type = 'pro' ,$pageNumval = 1 )
	{
		//伪静态
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			switch ($type)
			{
				case 'art':
					$retUrl = BASE_WEBURL."/art-".$valid.".html";
					break;

				case 'pro':
					$retUrl = BASE_WEBURL."/pro-".$valid.".html";
					break;

				case 'pic':
					$retUrl = BASE_WEBURL."/pic-".$valid.".html";
					break;

				case 'vid':
					$retUrl = BASE_WEBURL."/vid-".$valid.".html";
					break;

				case 'vot':
					$retUrl = BASE_WEBURL."/vote-".$valid.".html";
					break;

				case 'inv':
					$retUrl = BASE_WEBURL."/invite-".$valid.".html";
					break;

				case 'dow':
					$retUrl = BASE_WEBURL."/download-".$valid.".html";
					break;
/*
				case 'artlist':
					if($pageNumval > 0)
					{
						$retUrl = BASE_WEBURL."/art-".$pageNumval."-".$valid.".html";
					}else{
						$retUrl = BASE_WEBURL."/art-1-".$valid.".html";
					}
					break;
					
				case 'prolist':
					if($pageNumval > 0)
					{
						$retUrl = BASE_WEBURL."/pro-".$pageNumval."-".$valid.".html";
					}else{
						$retUrl = BASE_WEBURL."/pro-1-".$valid.".html";
					}
					break;
					
				case 'vidlist':
					if($pageNumval > 0)
					{
						$retUrl = "/vid-".$pageNumval."-".$valid.".html";
					}else{
						$retUrl = "/vid-1-".$valid.".html";
					}
					break;	
					
				case 'piclist':
					if($pageNumval > 0)
					{
						$retUrl = BASE_WEBURL."/pic-".$pageNumval."-".$valid.".html";
					}else{
						$retUrl = BASE_WEBURL."/pic-1-".$valid.".html";
					}
					break;
					
				case 'votlist':
					if($pageNumval > 0)
					{
						$retUrl = BASE_WEBURL."/vote-".$pageNumval."-".$valid.".html";
					}else{
						$retUrl = BASE_WEBURL."/vote-1-".$valid.".html";
					}
					break;

				case 'dowlist':
					if($pageNumval > 0)
					{
						$retUrl = BASE_WEBURL."/downloadlist-".$pageNumval."-".$valid.".html";
					}else{
						$retUrl = BASE_WEBURL."/downloadlist-1-".$valid.".html";
					}
					break;
					*/
				default:
					$retUrl = BASE_WEBURL."/";
			}

		//动态信息
		}else{
			switch ($type)
			{
				case 'art':
					$retUrl = BASE_WEBURL."/?load=art&act=detail&id=".$valid;
					break;

				case 'pro':
					$retUrl = BASE_WEBURL."/?load=pro&act=detail&id=".$valid;
					break;

				case 'pic':
					$retUrl = BASE_WEBURL."/?load=pic&act=detail&id=".$valid;
					break;

				case 'vid':
					$retUrl = BASE_WEBURL."/?load=vid&act=detail&id=".$valid;
					break;

				case 'vot':
					$retUrl = BASE_WEBURL."/?load=vote&act=detail&id=".$valid;
					break;

				case 'inv':
					$retUrl = BASE_WEBURL."/?load=invite&act=detail&id=".$valid;
					break;
				case 'dow':
					$retUrl = BASE_WEBURL."/?load=download&act=detail&id=".$valid;
					break;
				/*
				case 'artlist':
					if($pageNumval> 0)
					{
						$retUrl = BASE_WEBURL."/?load=art&act=infolist&sid=".$valid."&pageNum=".$pageNumval;
					}else{
						$retUrl = BASE_WEBURL."/?load=art&act=infolist&sid=".$valid."&pageNum=1";
					}
					break;
					
				case 'prolist':
					if($pageNumval> 0)
					{
						$retUrl = BASE_WEBURL."/?load=pro&act=infolist&sid=".$valid."&pageNum=".$pageNumval;
					}else{
						$retUrl = BASE_WEBURL."/?load=pro&act=infolist&sid=".$valid."&pageNum=1";
					}
					break;
					
				case 'vidlist':
					if($pageNumval> 0)
					{
						$retUrl = BASE_WEBURL."/?load=vid&act=infolist&sid=".$valid."&pageNum=".$pageNumval;
					}else{
						$retUrl = BASE_WEBURL."/?load=vid&act=infolist&sid=".$valid."&pageNum=1";
					}
					break;
				case 'piclist':
					if($pageNumval> 0)
					{
						$retUrl = BASE_WEBURL."/?load=pic&act=infolist&sid=".$valid."&pageNum=".$pageNumval;
					}else{
						$retUrl = BASE_WEBURL."/?load=pic&act=infolist&sid=".$valid."&pageNum=1";
					}
					break;
					
					
				case 'votlist':
					if($pageNumval> 0)
					{
						$retUrl = BASE_WEBURL."/?load=vote&act=infolist&sid=".$valid."&pageNum=".$pageNumval;
					}else{
						$retUrl = BASE_WEBURL."/?load=vote&act=infolist&sid=".$valid."&pageNum=1";
					}
					break;		
				case 'dowlist':
					if($pageNumval> 0)
					{
						$retUrl = BASE_WEBURL."/?load=download&act=infolist&sid=".$valid."&pageNum=".$pageNumval;
					}else{
						$retUrl = BASE_WEBURL."/?load=download&act=infolist&sid=".$valid."&pageNum=1";
					}
					break;
					*/
				default:
					$retUrl = BASE_WEBURL."/";
			}
		}
 		return $retUrl;
	}
	
	
	function error404()
	{
		$GLOBALS['Templ'] -> display('error404_tpl.html');
		exit();
	}
	
}
$Helpe = new Helper();
?>