<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');


class Index extends CI_Controller
{
    public function __construct() 
    {
        parent::__construct();
        $this->permission->is_admin(true);
        $this->load->model('Partners_model');
    }
    //公司与联系人查找
    public function index($tpl=false) 
    {
        $data=array();
        $data['navtitle']='公司与联系人';

        $data['CompanyBN']=$this->input->post('company')?$this->input->post('company'):false;
        $data['name']=$this->input->post('partners')?$this->input->post('partners'):false;
        $data['list']=$this->Partners_model->get_list($data);

        if (!$tpl) {
            $this->load->view('header', $data);
            $this->load->view('index/index');
            $this->load->view('footer');
        }elseif (empty($data['list'])) {
            echo 0;
        }else{
            $this->load->view('index/'.$tpl,$data);
        }
        
    }
    //外联订单管理
    public function group($status=5,$COLI_ID=false)
    {
        $data=array();
        $data['navtitle']='外联管理';
        $session_webht=$this->session->userdata('admin_chtcdn');
        $user=$session_webht['OPI_SN'];

        $date1=$date2=false;
        if ($this->input->post('date1')) {
            $date1=$this->input->post('date1');
            $date2=$this->input->post('date2')!=''?$this->input->post('date2'):date('Y-m-d');
            $status=$this->input->post('status');
        }

        $data['date1']=$date1;
        $data['date2']=$date2;
        $data['status']=$status;
        $data['list']=$this->Partners_model->get_orders($user,$status,$date1,$date2,$COLI_ID);
        //if ($COLI_ID!==false) {
            $grouptpl='index/order_search';
            if ($this->session->userdata('isapp')) {
                $grouptpl='index/group_app';
            }
            $this->load->view($grouptpl,$data);
            return;
        //}

        if($status==5) $data['navtitle']='外联管理-成行订单';
        $this->load->view('header', $data);
        $this->load->view('index/group');
        $this->load->view('footer');
    }

    //地接与导游信息
    public function guideinfo($GRI_SN='')
    {
        $data=array();
        if (!$GRI_SN=='') {
            $data['guides']=$this->Partners_model->get_guides($GRI_SN);
        }else {
            $data['guides']=false;
        }
        $this->load->view('index/guideinfo', $data);
    }
    //团信息
    public function groupinfo($GRI_SN='')
    {
        $data=array();
        $data['groupinfo']=$this->Partners_model->get_group_info($GRI_SN);
        $this->load->view('index/groupinfo', $data);
    }
    //客人信息
    public function customerinfo($COLI_SN='')
    {
        $data=array();
        $data['customerinfo']=$this->Partners_model->get_customer_info($COLI_SN);
        $this->load->view('index/customerinfo', $data);
    }
    //来往邮件列表
    public function mail_info($COLI_ID='X141011018')
    {
        $data=array();
        $this->load->model('Mailinfo_model');
        $data['mailinfo']=$this->Mailinfo_model->get_mail_info($COLI_ID);
        $tpl='index/mailinfo';
        if ($this->session->userdata('isapp')) {
            $tpl='index/mailinfo_app';
        }
        $this->load->view($tpl, $data);
    }
    //来往邮件正文内容
    public function mail_detail($MAI_SN)
    {
        $data=array();
        $this->load->model('Mailinfo_model');
        $data['maildetail']=$this->Mailinfo_model->mail_detail($MAI_SN);
        $data['mailattach']=$this->Mailinfo_model->mail_attach($MAI_SN);
        $tpl='index/maildetail';
        if ($this->session->userdata('isapp')) {
            $tpl='index/maildetail_app';
        }
        $this->load->view($tpl, $data);
    }

}
