<?php
/***
 *----------------------------------------------------------------------------*
 * ��Ȩ���� 2010-2016 HuCart.COM������������Ȩ����
 * �˳�����HuCart��һ���֡�  
 * ����MIT���֤��Ȩ(���������������и����ж����������Ȩ���������������)
 * �ٷ���ַ:http://www.hucart.com
 *
 * ���������İ�Ȩ�����֤��Ϣ�������MIT-LICENSE.TXT
 * ������ٷ������뱣�����ϰ�Ȩ������
 *
 *@author pgmk<pgmk@hucart.com>
 *@copyright pgmk<pgmk@hucart.com>
 *@link http://www.hucart.com
 *@license The MIT License.
 *----------------------------------------------------------------------------*
**/
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Index  extends HC_Controller
{
	function __construct()
	{
		parent::__construct();
		$this -> load_lang('web,config');
		$this -> load_db();
		$this -> load('helper');     	 	//���ظ�����//
		$this -> load_model('ads'); 		//����ģ��
		$this -> load_model('web_config'); 	//����ģ��
		$web_config = $this -> web_config_mod -> get_sys_config();
		//echo $web_config['temp'] -> dir;
		//$this -> set_view_dir( $web_config['temp'] -> dir );
		///var_dump($web_config);
		$this -> view -> assign('web_config', $web_config);


		$this -> view -> assign('menu_info',$this -> web_config_mod -> get_web_menu('m'));
		$this -> view -> assign('ads_info', $this -> ads_mod -> get_ads( '1,2,3,4,5,6,7,8,9,10' ));
		$user_link = isset($this->lang['user_link']) ? $this->lang['user_link']: '';
		$this -> view -> assign('user_link',$this -> session -> get_user_link(  ));
		
	}
	
	
	function act_default()
	{

		$this -> load_model('slide'); 
		$slide_info = $this->slide_mod->get_slide( 'index' );
		//var_dump( $slide_info );
		$this -> view ->assign('slide_info', $slide_info);
		
		$infoper = array();
		
		$com_info = $this->com_info();
		//var_dump($com_info);
		$this -> view ->assign('com_info', $com_info);
		

		$pro_info = $this->pro_info();
		//var_dump($pro_info);
		$this -> view ->assign('pro_info', $pro_info);
		/*
		$sql_query 	= " SELECT per_id,per_main  FROM  ".$this -> db -> prefix."personal  WHERE per_type = 'index' ORDER BY `per_id`  ";
			
		$infoper 	= $this -> db ->  select_one($sql_query);

		$this -> load_model('page');

		$all_info = $this -> page_mod -> get_per_item( $infoper );
 
		//var_dump($all_info);
		
		$this -> view ->assign('all_info', $all_info);
		*/

		$cache_id = "index";

		$this -> view -> display('index.tpl',$cache_id);
	}


	function com_info()
	{
		
		//��˾���
		 $sql_info = " SELECT art_id,art_title ,art_description ,art_detail,art_pic  FROM  ".$this -> db -> prefix."article   WHERE art_sys_file = 'company' and art_enabled = 1 AND art_delete =0   LIMIT 1  ";
		 $info = $this -> db -> select_one( $sql_info );
		
		
		$com_info = array();
		
		if ($info['art_id'] !='')
		{ 

		   		$com_info["art_title"] 			= $info["art_title"];
				if($info["art_description"]){
					$com_info["art_description"] 	= nl2br($info["art_description"]);
				}else{
					$com_info["art_description"] 	= nl2br($info["art_detail"]);
				}
				$com_info["art_pic"] 			= $info["art_pic"];
				//$com_info["art_id"] 				= $info["art_id"] ;
				$com_info["get_url"] 			= BASE_WEBURL.'?/company.html';	
		}
		return $com_info;
	}
	
	function art_info()
	{
		//���Ŷ�̬��ѯ10������
		$sql = " SELECT a.art_id, a.art_title,a.art_up_time,s.ars_name FROM ".$this -> db -> prefix."article as a left join ".$this -> db -> prefix."art_sort as s on s.ars_id = a.ars_id WHERE a.art_enabled = 1 and s.ars_enabled = 1 and a.art_sysfile = '' and a.ars_id not in ( 2 ) and  a.ars_id not in ( select `ars_id` from ".$this -> db -> prefix."art_sort where ars_enabled = 2 )  GROUP BY a.art_id ORDER BY  a.art_list , a.art_up_time desc  LIMIT 10 ";
		$info 	 = $this -> db -> select_info($sql);
		
		$artInfo = array();

		foreach ((array)$info as $row)
		{
				$artInfo[$row["art_id"]]['art_id'] 		= $row["art_id"] ; 
				$artInfo[$row["art_id"]]['art_title'] 	= $row["art_title"] ;
				$artInfo[$row["art_id"]]["get_url"]		= $this -> helper  -> build_url( $valid = $row["art_id"],'art');
				$artInfo[$row["art_id"]]['art_up_time']  = date("Y-m-d",$row["art_up_time"]) ; 
		}

		return $artInfo;
	}
	
	function pro_info()
	{
		//��Ʒ��ѯ8������
		$sql = " SELECT  pro_id, pro_name, pro_img,pro_sell_price  FROM  ".$this -> db -> prefix."product  WHERE pro_delete = 0 AND pro_enabled = 1 ORDER BY  pro_up_time desc  LIMIT 8 ";  //, paddtime 
		
		$info 	 = $this -> db -> select_info($sql);
		
		$pro_info = array();	

		foreach ((array)$info as $pkey => $row)
		{
				$pro_info[$pkey]["pro_img"]  = $this -> helper -> build_img( $row["pro_img"] ) ;
				$pro_info[$pkey]["pro_sell_price"]  =  $row["pro_sell_price"] ; 
				$pro_info[$pkey]["pro_name"] = $row["pro_name"];
				$pro_info[$pkey]["pro_id"] 	 = $row["pro_id"];
				$pro_info[$pkey]["get_url"]	 = $this -> helper  -> build_url( $valid = $row["pro_id"],'pro');
		}

		
		return $pro_info;
	}

	

}
