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


/**
 * Advertisement.php Class 
 *
 * @package         zsb
 * @subpackage      Libraries
 * @category        Libraries
 * @author          esf Dev Team
 * @link		
 */
class AdvertisementTest
{
    public function __construct()
    {
        $this->ci =& get_instance();
        $this->dbmain = $this->ci->load->database('dbmain',TRUE);
    }

    function get_ad_commons_html($sortid,$wbhr=0,$w=0,$h=0,$h_t=0) 
    {
        $fodler = "cache/ad_cache/";
        $file_name = $fodler.$sortid.".html";
        $per = 10800;//设置缓存时间
        @mkdir($fodler, 0777);//判断目录是否存在
        if(time()-@filemtime($file_name)>$per || (isset($update) && $update == 1)){
            $time=strtotime(date("Y-m-d H:i"));
            $con_str = "sortid = $sortid and starttime<='$time' and endtime>='$time'";
            $q = " select * from njhouse.news_ad ".$con_str." order by id desc";
            $this->dbmain->where($con_str);
            $this->dbmain->order_by('id', 'desc');
			if(GB_CITY=='nj')
			{
				$row = $this->dbmain->get('njhouse.news_ad')->row_array();
			}
			else
			{
				$IpHostAllow =explode('.',GetIp());
                if($IpHostAllow['0']=='192' || $IpHostAllow['0']=='127')
                {
                    //$row = $this->dbmain->getRow($q);
                }
                else
                {
                    echo 123;
                    print_r($this->dbmain);die;
                    $row = $this->dbmain->getRow($q);
                }
			}
            
            if($row){
                $pics=$row['src'];
                $links="http://www.house365.com/adclick.php?id=".$row['id'];
                $texts=$row['txt'];
                $type=$row['filetype'];
                $istrans=$row['istransparent'];
                if($w==0&&$h==0){
                  $w=$row['width'];
                  $h=$row['height'];
                }
                if($type=='f'){
                    $ss="<script type=text/javascript>
                        <!--
                        var focus_wh=$w;
                        var focus_ht=$h;
                        var text_ht=$h_t;
                        var swf_ht = focus_ht+text_ht;

                        var pics='$pics';
                        var links='$links';
                        var texts='$texts';
                        var istrans=$istrans;

                        document.write('<embed src=\"'+pics+'\" quality=\"high\" width=\"'+focus_wh+'\" height=\"'+swf_ht+'\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\"transparent\"></embed>');
                        //-->
                        </script>";
                }else{
                    if($wbhr==1)
                        if($row['href']) $ss="<a href='$links' target='_blank'><img src='$pics' width='$w' height='$h' border='0' align='left'></a>";
                        else $ss="<img src='$pics' width='$w' height='$h' border='0' align='left'>";
                    else
                        if($row['href']) $ss="<a href='$links' target='_blank'><img src='$pics' width='$w' height='$h' border='0'></a>";
                        else $ss="<img src='$pics' width='$w' height='$h' border='0'>";
                }

            } else {
                $ss='';
            }
            $fp=@fopen($file_name, "w+"); //打开文件指针，创建文件
            if($fp){
                @fputs($fp,$ss);
                @fclose($fp);//关闭指针
            }
        }else{
            $ss=file_get_contents($file_name);
        }

        return $ss;
    }
}