<?php
if (!defined('HUCART_ORG')) exit('HuCart.COM No direct script access allowed');
class Webmenu
{
	function Webmenu()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/login/actlogin");
	
		$urlAddArray = array();
		
		//说明是伪静态页面
		$urlAddArray[0]["url"]  = "/?item.html";
		$urlAddArray[0]["name"] = "商品中心";
	
		$urlAddArray[1]["url"]  = "/?article.html";
		$urlAddArray[1]["name"] = "资讯中心";
			
		$urlAddArray[2]["url"]  = "/?invite.html";
		$urlAddArray[2]["name"] = "人才招聘";
	
		$urlAddArray[3]["url"]  = "/?contactus.html";
		$urlAddArray[3]["name"] = "联系我们";
			
			
		$urlAddArray[4]["url"]  = "/?link.html";
		$urlAddArray[4]["name"] = "友情链接";
	
		$urlAddArray[5]["url"]  = "/?message.html";
		$urlAddArray[5]["name"] = "在线咨询";
			
		$urlAddArray[6]["url"]  = "/?copyright.html";
		$urlAddArray[6]["name"] = "版权声明";
	
		$urlAddArray[7]["url"]  = "/?map.html";
		$urlAddArray[7]["name"] = "网站地图";
			
			
		$urlAddArray[8]["url"]  = "/?download.html";
		$urlAddArray[8]["name"] = "下载中心";
			
		$urlAddArray[9]["url"]  = "/?picture.html";
		$urlAddArray[9]["name"] = "图片中心";
	
		$urlAddArray[10]["url"]  = "/?video.html";
		$urlAddArray[10]["name"] = "视频中心";
			
		$urlAddArray[11]["url"]  = "/?vote.html";
		$urlAddArray[11]["name"] = "投票中心";
			
		$urlAddArray[12]["url"]  = "/?aboutus.html";
		$urlAddArray[12]["name"] = "关于我们";
			
		$urlAddArray[13]["url"]  = "/?company.html";
		$urlAddArray[13]["name"] = "公司介绍";
			
		$urlAddArray[14]["url"]  = "/?forum.html";
		$urlAddArray[14]["name"] = "简约论坛";

		$urlAddArray[15]["url"]  = "/mobile/";
		$urlAddArray[15]["name"] = "智能手机版";

		///var_dump($urlAddArray);


		$this -> view -> assign('urlAddArray',$urlAddArray);
		
	}
	
	function info_list()
	{
		$page_size = 160 ;
		$page_num_val 	= $this -> input ->  req["page_num"];
		
		if( $page_num_val > 1 )
		{
			$page_num  = $page_num_val;
			$limit_num = ceil( ( $page_num_val -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}
			
		$sql_query = " SELECT web_id, web_name, web_url, web_enabled, web_place,web_list FROM  ".$this -> db -> prefix."webmenu  WHERE  web_place in ( 'top','middle','bottom' ) GROUP BY web_id ORDER BY web_list , `web_id` LIMIT  $limit_num , $page_size ";

		$infosm = $this -> db -> select_info($sql_query);
		

		if( $infosm !='')
		{
			//top
			foreach( $infosm as $ikey => $ival )
			{

					$info[$ival["web_place"]][] = $ival;
			}
		}
		//var_dump( $info );
		
		$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."webmenu  WHERE web_place in ( 'top','middle','bottom' )   ORDER BY `web_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		//var_dump();
		$page_str = $this -> page ->get_admin_page( $url = '?load=webmenu&act=info_list', $page_num  , $page_size  , $result_count = $infocount["LNUM"]);
		
		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('webmenu.tpl');
		
	}
	
	function add(  )
	{
		//$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		
		//添加栏目可选地址
		
		//商品分类列表
		
		//资讯分类列表

		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=webmenu&act=add");
		$this -> view -> display('webmenuadd.tpl');
	}
	
	function add_info()
	{

		$web_nameval 	= $this -> input ->  delUrl($_REQUEST["web_name"]);
		$web_urlval 	= $this -> input ->  delUrl($_REQUEST["web_url"]);
		$web_enabledval = $this -> input ->  delUrl($_REQUEST["web_enabled"]);
		$web_listval 	= $this -> input ->  delUrl($_REQUEST["web_list"]);
		$web_placeval 	= $this -> input ->  delUrl($_REQUEST["web_place"]);
		$web_targetvalval = $this -> input ->  delUrl($_REQUEST["web_targetval"]); 
		
		if($web_nameval and $web_urlval)
		{
			$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."webmenu  WHERE web_name = '".$web_nameval."' and web_place = '".$web_placeval."' ORDER BY `web_id` ";	
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["LNUM"] < 1 )
			{
				$insertsql =" INSERT INTO `".$this -> db -> prefix."webmenu` (`web_name` , `web_url` , `web_enabled` , `web_list` , `web_targetval` ,`web_place`) VALUES (  '$web_nameval', '$web_urlval', '$web_enabledval', '$web_listval', '$web_targetvalval','$web_placeval')";
				
				$this -> db -> query_sql($insertsql);
				$this -> view ->  assign('info_title',$this->lang['add_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=webmenu&act=info_list");
				$this -> view ->  display('suggestion.tpl');	
			}else{
				
				$this -> view ->  assign('info_title',$this->lang['err_info_exist']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=webmenu&act=add");
				$this -> view ->  display('suggestion.tpl');	
			}
			
		}else{
			
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=webmenu&act=add");
			$this -> view ->  display('suggestion.tpl');		}
		//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $this -> input ->  get["id"];
		$insertip = " DELETE FROM `".$this -> db -> prefix."webmenu` WHERE `web_id` in ( $infoid ) ";
		$this -> db -> query_sql($insertip);
		$this -> view ->  assign('info_title',$this->lang['del_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=webmenu&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function info(  )
	{
		$infoid = $this -> input ->  get["id"];
		
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."webmenu  WHERE web_id = '".$infoid."' ORDER BY `web_id` ";
		$info = $this -> db -> select_one($sql_query);
		//var_dump($info);
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('webmenuedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
		$web_idval 		= intval(trim($_REQUEST["web_id"]));
		$web_nameval 	= $this -> input ->  delUrl($_REQUEST["web_name"]);
		$web_urlval 	= $this -> input ->  delUrl($_REQUEST["web_url"]);
		$web_enabledval = $this -> input ->  delUrl($_REQUEST["web_enabled"]);
		$web_listval 	= $this -> input ->  delUrl($_REQUEST["web_list"]);
		$web_placeval 	= $this -> input ->  delUrl($_REQUEST["web_place"]);
		$web_targetvalval = $this -> input ->  delUrl($_REQUEST["web_targetval"]); 
		
		if($web_nameval !='' and $web_urlval !='' and $web_idval !='')
		{
			
			$updatewebmenu = "UPDATE `".$this -> db -> prefix."webmenu` SET  web_name = '".$web_nameval."' , web_url = '".$web_urlval."' , web_enabled = '".$web_enabledval."', web_list = '".$web_listval."',web_place = '".$web_placeval."' ,web_targetval = '".$web_targetvalval."' WHERE  web_id = '".$web_idval."' ";
			
			$this -> db -> query_sql( $updatewebmenu );
			
			$this -> view ->  assign('info_title',$this->lang['edit_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=webmenu&act=info_list");
			$this -> view ->  display('suggestion.tpl');
				
		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=webmenu&act=info&id=".$web_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//
$Webmenu = new Webmenu();

?>