<?php

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


class Mailinfo_model extends CI_Model {
    private $M_ht;
    function __construct() 
    {
        parent::__construct();
        $this->M_ht = $this->load->database('HT229', TRUE);
    }

	//来往邮件列表
	public function get_mail_info($COLI_ID)
	{
        $sql="SELECT    MAI_SN,
                        MAI_SendDate,
                        MOI_ReadState,
                        MAI_COLI_SN,
                        MAI_From,
                        MAI_To,
                        MAI_Subject,
                        MAI_Direction 
                from    ML_MailInfo 
                        inner join Ml_MailOwnerInfo on MOI_MAI_SN=MAI_SN 
               where    MAI_COLI_ID=? 
               order by MAI_SendDate DESC";

	    $query = $this->M_ht->query($sql,array($COLI_ID));
        $result=$query->result();
        return $result;
    }

    //邮件内容
    public function mail_detail($MAI_SN)
    {
        $sql="SELECT    MAI_SN,
                        MAI_COLI_SN,
                        MAI_SendDate,
                        MAI_From,
                        MAI_To,
                        MAI_Subject,
                        MAI_BlobContent,
                        MAI_Direction 
                from    ML_MailInfo  
                        inner join Ml_MailOwnerInfo on MOI_MAI_SN=MAI_SN 
               where    MAI_SN=?";

        $query = $this->M_ht->query($sql,array($MAI_SN));
        $result=$query->result();
        if($result){
            return $result[0];
        }
        return false;
    }

    public function mail_attach($MAI_SN)
    {
        $sql="SELECT    top 10 
                        'http://202.103.68.35/attachment'+ATI_ServerFile as attach 
                from    ML_AttachmentInfo 
               where    ATI_MAI_SN=?";
        $query = $this->M_ht->query($sql,array($MAI_SN));
        $result=$query->result();
        return $result;
    }
	
}