public function actionIndex()
 {
     $this->pageName = Yii::t('StatsModule.default', 'MODULE_NAME');
     $this->breadcrumbs = array(Yii::t('StatsModule.default', 'MODULE_NAME') => array('/admin/shop'), $this->pageName);
     $result = array();
     $stats = Yii::app()->stats;
     $s = $stats->initRun();
     foreach (StatsMainh::model()->findAll(array('order' => '`t`.`i` ASC')) as $rw) {
         $dt_i = $rwz["dt"][] = $rw->dt;
         $rwz["cnt1"][$dt_i] = $rw->cnt1;
         $rwz["cnt2"][$dt_i] = $rw->cnt2;
         $rwz["cnt3"][$dt_i] = $rw->cnt3;
         $rwz["cnt4"][$dt_i] = $rw->cnt4;
         $rwz["cnt5"][$dt_i] = $rw->cnt5;
     }
     foreach (StatsMainp::model()->findAll() as $rww) {
         $dt_i = $rww["dt"] . $rww->god;
         $rwzz[$dt_i]["cnt1"] = $rww->cnt1;
         $rwzz[$dt_i]["cnt2"] = $rww->cnt2;
         $rwzz[$dt_i]["cnt3"] = $rww->cnt3;
         $rwzz[$dt_i]["cnt4"] = $rww->cnt4;
         $rwzz[$dt_i]["cnt5"] = $rww->cnt5;
     }
     $c = 0;
     $all_uniqs = 0;
     $all_hits = 0;
     $all_se = 0;
     $all_other = 0;
     $all_fix = 0;
     $sdate = 0;
     $r = Yii::app()->db->createCommand();
     $r->selectDistinct('day, dt');
     $r->from('cms_surf');
     $r->order('i DESC');
     $res = $r->queryRow(false);
     //$sql = "SELECT DISTINCT day,dt from cms_surf ORDER BY i";
     //$cmd = Yii::app()->db->createCommand($sql)->queryRow();
     //unset($res[count($res)-1]);
     $fdate = date('Ymd');
     foreach ($r->queryAll() as $dtm) {
         if (substr($sdate, 4, 2) != substr($dtm['dt'], 4, 2) and $sdate != 0) {
             $c++;
         }
         $sdate = $dtm['dt'];
         if ($dtm['dt'] != $fdate and !empty($rwz["cnt2"][$dtm['dt']])) {
             $m_uniqs[$dtm['dt']] = $rwz["cnt1"][$dtm['dt']];
             $m_hits[$dtm['dt']] = $rwz["cnt2"][$dtm['dt']];
         } else {
             //die(print_r($this->c_uniqs_hits($dtm[1]['dt'])));
             list($m_uniqs[$dtm['dt']], $m_hits[$dtm['dt']]) = $stats->countVisits($dtm['dt']);
         }
     }
     $sdate = $res['dt'];
     $i = 0;
     //mysql_data_seek($r, 0);
     $max_hits = max($m_hits);
     foreach ($r->queryAll() as $row) {
         $dt = $row['dt'];
         if ($dt != $fdate and isset($rwz["cnt3"][$dt])) {
             $m_se[$dt] = $rwz["cnt3"][$dt];
             $m_other[$dt] = $rwz["cnt4"][$dt];
             $m_fix[$dt] = $rwz["cnt5"][$dt];
         } else {
             $m_se[$dt] = $stats->countSearchEngine($dt);
             $m_other[$dt] = $stats->countOther($dt);
             if ($stats->fx) {
                 $m_fix[$dt] = $stats->countFix($dt);
             } else {
                 $m_fix[$dt] = 0;
             }
             //if (isset($rwz)) {
             if ($dt != $fdate and !in_array($dt, $rwz["dt"])) {
                 // die('save');
                 $sql_insert = "INSERT INTO cms_mainh(dt,cnt1,cnt2,cnt3,cnt4,cnt5) VALUES('" . $dt . "','" . $m_uniqs[$dt] . "','" . $m_hits[$dt] . "','" . $m_se[$dt] . "','" . $m_other[$dt] . "','" . $m_fix[$dt] . "')";
                 Yii::app()->db->createCommand($sql_insert)->execute();
                 $sql_del = "DELETE me FROM cms_mainh as me, cms_mainh as clone WHERE me.dt = clone.dt AND me.i > clone.i";
                 Yii::app()->db->createCommand($sql_del)->execute();
                 //mysql_query("INSERT INTO mainh(dt,cnt1,cnt2,cnt3,cnt4,cnt5) VALUES('" . $dt . "','" . $m_uniqs[$dt] . "','" . $m_hits[$dt] . "','" . $m_se[$dt] . "','" . $m_other[$dt] . "','" . $m_fix[$dt] . "')");
                 //mysql_query("DELETE me FROM mainh as me, mainh as clone WHERE me.dt = clone.dt AND me.i > clone.i");
             }
             // }
         }
         if ($m_uniqs[$dt] == $m_hits[$dt]) {
             $graphic = "<img src=/stats/pxu.gif width=" . ceil(372 * $m_uniqs[$dt] / $max_hits) . " height=11 border=0>";
         } else {
             $graphic = "<img src=/stats/pxu.gif width=" . round(372 * $m_uniqs[$dt] / $max_hits) . " height=11 border=0><img src=/stats/pxh.gif width=" . (ceil(372 * $m_hits[$dt] / $max_hits) - ceil(372 * $m_uniqs[$dt] / $max_hits) - 1) . " height=11 border=0>";
         }
         $result[] = array('date' => StatsHelper::$DAY[$row['day']] . StatsHelper::dtconv($dt), 'graphic' => $graphic, 'hosts' => Html::link($m_uniqs[$dt], '/admin/stats/detail/hosts/?date=' . $dt), 'hits' => Html::link($m_hits[$dt], '/admin/stats/detail/hits/?date=' . $dt), 'search' => Html::link($m_se[$dt], '/admin/stats/detail/search/?date=' . $dt), 'sites' => Html::link($m_other[$dt], '/admin/stats/detail/other/?date=' . $dt));
     }
     $dataProvider = new CArrayDataProvider($result, array('sort' => array('attributes' => array('date' => array('asc' => 'date DESC', 'desc' => 'date ASC'))), 'pagination' => array('pageSize' => 10)));
     $this->render('index', array('dataProvider' => $dataProvider));
 }
Exemple #2
0
 public function getToday()
 {
     foreach (StatsMainh::model()->findAll() as $rw) {
         $dt_i = $rwz["dt"][] = $rw->dt;
         $rwz["cnt1"][$dt_i] = $rw->cnt1;
         $rwz["cnt2"][$dt_i] = $rw->cnt2;
         $rwz["cnt3"][$dt_i] = $rw->cnt3;
         $rwz["cnt4"][$dt_i] = $rw->cnt4;
         $rwz["cnt5"][$dt_i] = $rw->cnt5;
     }
     foreach (StatsMainp::model()->findAll() as $rww) {
         $dt_i = $rww["dt"] . $rww->god;
         $rwzz[$dt_i]["cnt1"] = $rww->cnt1;
         $rwzz[$dt_i]["cnt2"] = $rww->cnt2;
         $rwzz[$dt_i]["cnt3"] = $rww->cnt3;
         $rwzz[$dt_i]["cnt4"] = $rww->cnt4;
         $rwzz[$dt_i]["cnt5"] = $rww->cnt5;
     }
     list($s_date, $f_date) = str_replace("+", "", array('13.03.2015', '15.03.2015'));
     $sdate = StatsHelper::dtconv2(trim($s_date));
     $fdate = StatsHelper::dtconv2(trim($f_date));
     /* if ($robots = file(Yii::getPathOfAlias('webroot.stats') . "/robots.dat")) {
        $i = 0;
        for ($i = 0; $i < count($robots); $i++)
        $robots[$i] = iconv("CP1251", "UTF-8", $robots[$i]);
        foreach ($robots as $val) {
        list($rb1, $rb2) = explode("|", $val);
        $rb2 = trim($rb2);
        $this->rbd[$i++] = rtrim($rb1);
        if (!empty($rb2))
        $rbdn[$rb2][] = rtrim($rb1);
        $robo[] = $rb2;
        }
        }
        if ($hosts = file(Yii::getPathOfAlias('webroot.stats') . "/hosts.dat")) {
        $i = 0;
        for ($i = 0; $i < count($hosts); $i++)
        $hosts[$i] = iconv("CP1251", "UTF-8", $hosts[$i]);
        foreach ($hosts as $val) {
        list($hb1, $hb2) = explode("|", $val);
        $hb2 = trim($hb2);
        $hbd[$i++] = rtrim($hb1);
        if (!empty($hb2))
        $hbdn[$hb2][] = rtrim($hb1);
        $robo[] = $hb2;
        }
        }
        $this->robo = array_unique($robo); */
     $iniRun = $this->initRun();
     $this->rbd = $iniRun['rbd'];
     $hbd = $iniRun['hbd'];
     foreach ($this->rbd as $val) {
         $zp .= " LOWER(user) NOT LIKE '%" . mb_strtolower($val) . "%' AND";
     }
     if (filesize(Yii::getPathOfAlias('webroot.stats') . "/hosts.dat")) {
         foreach ($hbd as $val) {
             $zp .= " LOWER(host) NOT LIKE '%" . mb_strtolower($val) . "%' AND";
         }
     }
     $zp .= " LOWER(user) NOT LIKE '' AND";
     if (file_exists(Yii::getPathOfAlias('webroot.stats') . "/skip.dat")) {
         if ($skip = file(Yii::getPathOfAlias('webroot.stats') . "/skip.dat")) {
             foreach ($skip as $vl) {
                 list($s1, $s2) = explode("|", $vl);
                 $zp2 .= " {$s1} NOT LIKE '%" . rtrim($s2) . "%' AND";
             }
         }
     }
     $zp .= $zp2;
     $this->_zp = substr($zp, 0, -4);
     if ($se_m = file(Yii::getPathOfAlias('webroot.stats') . "/se.dat")) {
         for ($i = 0; $i < count($se_m); $i++) {
             $se_m[$i] = iconv("CP1251", "UTF-8", $se_m[$i]);
         }
         foreach ($se_m as $vl) {
             list($s1, $s2, $s3) = explode("|", $vl);
             $se_n[$s1] = rtrim($s3);
             $se_nn[$s1] = $s2;
         }
     }
     if (file_exists(Yii::getPathOfAlias('webroot.stats') . "/fix.dat")) {
         if ($fx_m = file(Yii::getPathOfAlias('webroot.stats') . "/fix.dat")) {
             $this->_zfx = "";
             $pf = "";
             for ($i = 0; $i < count($fx_m); $i++) {
                 $fx_m[$i] = iconv("CP1251", "UTF-8", $fx_m[$i]);
             }
             foreach ($fx_m as $vl) {
                 list($s1, $s2, $s3) = explode("|", $vl);
                 $this->_zfx .= $pf . "LOWER(" . $s1 . ") LIKE '%" . mb_strtolower($s2) . "%'";
                 $pf = " OR ";
                 $s3 = rtrim($s3);
                 if (!empty($s3)) {
                     $fxn[$s3][] = $s1 . "|" . $s2;
                 }
                 $fxo[] = $s3;
             }
         }
     }
     foreach ($se_nn as $val) {
         $this->_cse_m .= " OR LOWER(refer) LIKE '%{$val}%'";
         $this->_cot_m .= " AND LOWER(refer) NOT LIKE '%{$val}%'";
     }
     $c = 0;
     $sdate = 0;
     $all_uniqs = 0;
     $all_hits = 0;
     $all_se = 0;
     $all_other = 0;
     $all_fix = 0;
     // $r = Yii::app()->db->createCommand();
     // $r->selectDistinct('day, dt');
     // $r->from('cms_surf');
     // $r->order('i');
     $i = 0;
     //$res1 = $r->queryRow();
     //  $fdate = $res1['dt'];
     $visits = $this->visits(date('Ymd'));
     $system = $this->visitSystem(date('Ymd'));
     return array('hosts' => $visits['hosts'], 'hits' => $visits['hits'], 'search' => $system['search'], 'sites' => $system['sites']);
 }