<?php
/**
 * Copy Right IJH.CC
 * Each engineer has a duty to keep the code elegant
 * $Id: index.ctl.php 14351 2016-01-14 01:25:14Z youyi $
 */
if(!defined('__CORE_DIR')){
    exit("Access Denied");
}

class Ctl_Index extends Ctl
{
    public function __construct(&$system) {
        parent::__construct($system);
    }

    public function index($addr_id=null)
    {   
        //if(!defined('IS_MOBILE') && !$this->system->cookie->get('is_view')){
            //header("Location:".$this->mklink('welcome/index'));
            //exit;
        //}else{
           //$this->pagedata['cate_tree'] = K::M('shop/cate')->items(array('parent_id'=>0));
           $addr_id = (int) $addr_id;
           $this->pagedata['addr'] = K::M('member/addr')->detail($addr_id);
           $this->pagedata['last_cate'] = $this->MEMBER['last_cate'];
           $this->pagedata['cates'] = K::M('cate/cate')->fetch_all(); 
           $this->pagedata['have_msg'] = K::M('member/message')->find(array('uid'=>$this->uid,'is_read'=>0));
           $this->tmpl = 'index.html';
        //}
    }
    
    public function getstaffpoi()
    {
        $items = $filter = array();
        $SouthWlng = $this->GP('SouthWlng');
        $SouthWlat = $this->GP('SouthWlat');
        $NorthElng = $this->GP('NorthElng');
        $NorthElat = $this->GP('NorthElat');
        $cate_id = $this->GP('cate_id');
        if(!$SouthWlng || !$SouthWlat || !$NorthElng || !$NorthElat){
            $this->msgbox->add('经度纬度不完整',211);
        }else{
            $filter['lat'] = $SouthWlat.'~'.$NorthElat;   //左下纬度和右上纬度
            $filter['lng'] = $SouthWlng.'~'.$NorthElng;   //左下经度和右上经度
            $filter['status'] = 0;
            $filter['cate_id'] = $cate_id;
            $catess = K::M('cate/cate')->fetch_all();
            foreach($catess as $k=>$val){
                if($val['parent_id'] != 0){
                    $cates[$k] = $val;
                }
            }
            $items = K::M('staff/staff')->items($filter,null,1,500);
            foreach ($items as $k=>$val){
                $items[$k] = $this->filter_fields('staff_id,mobile,orders,name,intro,face,skill,title,lat,lng,score,comments,praise_num,year_num', $val);
            }
            $count = count($items);
            if(empty($items)){
                $items = array();
            }
            $this->msgbox->add('success');
            $this->msgbox->set_data('data', array('items' => $items,'count'=>$count));
            $this->msgbox->response();
            
        }
    }
    
    
    
    public function get_addr(){
        $lat = $this->GP('lat');
        $lng = $this->GP('lng');
        $url = 'http://api.map.baidu.com/geocoder?location='.$lat.','.$lng.'&output=xml&output=json&pois=1';
        $json = file_get_contents($url);
        $json = json_decode($json);  
        $addr= $json->{'result'}->{'addressComponent'}->{'city'};
        $this->msgbox->set_data('addr',$addr);
    }
    
    
    public function cookie()
    {
        $a = $this->cookie->get('UxLocation');
        $this->cookie->delete("UxLocation");
        $this->cookie->clear();
        $this->cookie->set('UxLocation', '{}');
        echo "<pre>";
        print_r($a);
        print_r($_COOKIE);
        print_r($this->cookie->_COOKIE);
        print_r($_SERVER);
        echo 'clear cookie success';
        echo "</pre>";
        exit();
    }

    

}