Ejemplo n.º 1
0
    public function Top_Department()
    {
        $bl = new BLogger();
        $beginDate = addslashes($_GET['begindate']);
        if ($beginDate == "") {
            $month = date("n");
            $day = 1;
            $year = date("Y");
            $timeAwal = mktime(0, 0, 0, $month, $day, $year);
            $timeAkhir = mktime(0, 0, 0, $month + 1, $day, $year);
            $mon = $month;
            $y = $year;
            $timeAwalText = date("Y") . "-" . date("m") . "-01 00:00:00";
            $ts = mktime(0, 0, 0, date("n") + 1, 1, date("Y"));
            $timeAkhirText = date("Y-m-d H:i:s", $ts);
        } else {
            $timeAwalText = $beginDate . " 00:00:00";
            $bgindatestr = strtotime($beginDate);
            $mon = date("n", $bgindatestr);
            $y = date("Y", $bgindatestr);
            $ts = mktime(0, 0, 0, $mon + 1, 1, $y);
            $timeAkhirText = date("Y-m-d H:i:s", $ts);
            $year = $y;
        }
        /*echo $timeAwal;
          echo "<br>";
          echo $timeAkhir;
          */
        ?>
        <h1>Top Department</h1>    
         <?php 
        $text = "(b_log_time BETWEEN '{$timeAwalText}' AND '{$timeAkhirText}')";
        $textAs = "b_timestamp >= {$timeAwal} AND b_timestamp < {$timeAkhir}";
        // echo "<br>";
        // echo $text;
        $arrLogs = $bl->getWhere("{$text} ORDER BY b_timestamp ASC");
        //pr($arrLogs);
        foreach ($arrLogs as $h) {
            if ($h->log_user_org == "" || $h->log_user_org == 0) {
                continue;
            }
            $newArr["org_" . $h->log_user_org][] = $h;
        }
        foreach ($newArr as $url => $n) {
            $newArrs[$url] = count($n);
        }
        asort($newArrs);
        $jadi = array_reverse($newArrs);
        // pr($newArr);
        $t = time();
        //pr($jadi);
        ?>
<div class="table-responsive">
    <form class="form-inline">
  <div class="form-group">
    <label for="monselection_<?php 
        echo $t;
        ?>
">Select Month</label>
    <select class="form-control" id="monselection_<?php 
        echo $t;
        ?>
"><?php 
        $beginyear = date("Y") - 5;
        $endyear = date("Y");
        $beginyear = 2015;
        $mons = array(1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec");
        for ($x = $beginyear; $x <= $endyear; $x++) {
            for ($m = 1; $m < 13; $m++) {
                if ($m == $mon && $x == $year) {
                    $select = "selected";
                    echo "in";
                } else {
                    $select = "";
                }
                if ($x == date("Y")) {
                    if ($m > date("n")) {
                        continue;
                    }
                }
                ?>
                <option <?php 
                echo $select;
                ?>
 value="<?php 
                echo $x;
                ?>
-<?php 
                echo $m;
                ?>
-01"><?php 
                echo $x;
                ?>
 <?php 
                echo $mons[$m];
                ?>
 </option>   
                 <?php 
            }
        }
        ?>
    </select> 
  </div>
 <button class="btn btn-default" onclick="window.open('<?php 
        echo _SPPATH . _PHOTOURL . "logs/TopDepartment_" . $year . "_" . $mon;
        ?>
.xls', '_blank');event.preventDefault();">Download</button>
</form>
    <script>
        $('#monselection_<?php 
        echo $t;
        ?>
').change(function(){
            var slc = $('#monselection_<?php 
        echo $t;
        ?>
').val();
            openLw('Top_Department','<?php 
        echo _SPPATH;
        ?>
BLoggerWeb/Top_Department?begindate='+slc,'fade'); 
        });
        </script>
    <div style="padding: 10px;"></div>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Rank</th>
                
                <th>Department</th>
                <th>URL</th>
                <th>No.Visits</th>
            </tr>
        </thead>
        <?php 
        $num = 0;
        $arrExcel = array();
        $arrExcel2 = array();
        $arrExcel[] = "Rank;Department;No.Visits";
        foreach ($jadi as $url => $n) {
            $alog = $newArr[$url];
            $num++;
            $dp = new RoleOrganization();
            $id = explode("_", $url);
            //pr($id);
            $dp->getByID($id[1]);
            $arrExcel[] = "{$num};{$dp->organization_name};{$n}";
            ?>
        <tr>
            <td><?php 
            echo $num;
            ?>
</td>
            <td><span style="cursor:pointer; text-decoration: underline;" onclick="$('.detail_<?php 
            echo $url;
            ?>
').toggle();"><?php 
            echo $dp->organization_name;
            ?>
</span></td>    
            <td></td>
            <td><?php 
            echo $n;
            ?>
</td>
        </tr>
        <?php 
            $obje = array();
            $obje["Rank"] = $num;
            $obje["Department"] = $dp->organization_name;
            $obje["URL"] = "";
            $obje["No Visits"] = $n;
            $arrExcel2[] = $obje;
            $key = $url;
            $newArr_dalam = array();
            foreach ($alog as $h) {
                $newArr_dalam[$h->b_log_url][] = $h;
            }
            $newArrs_dalam = array();
            foreach ($newArr_dalam as $url => $n) {
                $newArrs_dalam[$url] = count($n);
            }
            asort($newArrs_dalam);
            $jadi_dalam = array_reverse($newArrs_dalam);
            ?>
        <?php 
            $num_dalam = 0;
            foreach ($jadi_dalam as $url_dalam => $n_dalam) {
                $num_dalam++;
                ?>
        <tr  class="detail_<?php 
                echo $key;
                ?>
" style="display:none;">
            <td></td>
            <td></td>
            <td><?php 
                echo $url_dalam;
                ?>
 <a href="<?php 
                echo $url_dalam;
                ?>
" target="_blank">link</a></td>           
            <td><?php 
                echo $n_dalam;
                ?>
</td>
        </tr>
        <?php 
                $obje2 = array();
                $obje2["Rank"] = " ";
                $obje2["Department"] = " ";
                $obje2["URL"] = $url_dalam;
                $obje2["No Visits"] = $n_dalam;
                $arrExcel2[] = $obje2;
            }
            ?>
        
        <?php 
        }
        ?>
    </table>
</div>    
         <?php 
        /*
                $fname = "TopDepartment_".$year."_".$mon. ".csv";
                $file = fopen(_PHOTOPATH . "logs/" . $fname, "w+");
        
                foreach ($arrExcel as $line) {
                        fputcsv($file, explode(';', $line));
                }
        
                fclose($file);*/
        $fname = _PHOTOPATH . "logs/" . "TopDepartment_" . $year . "_" . $mon . ".xls";
        ExcelExporter::saveIt($arrExcel2, $fname);
    }
            }
        </script>
        <?php 
/*
 <script src="<?= _SPPATH; ?>plugins/jQuery_File_Upload/js/vendor/jquery.ui.widget.js"></script>
 <script src="<?= _SPPATH; ?>plugins/jQuery_File_Upload/js/jquery.iframe-transport.js"></script>
 <script src="<?= _SPPATH; ?>plugins/jQuery_File_Upload/js/jquery.fileupload.js"></script>
*/
?>
        <script>
            (function (i, s, o, g, r, a, m) {
                i['GoogleAnalyticsObject'] = r;
                i[r] = i[r] || function () {
                    (i[r].q = i[r].q || []).push(arguments)
                }, i[r].l = 1 * new Date();
                a = s.createElement(o),
                        m = s.getElementsByTagName(o)[0];
                a.async = 1;
                a.src = g;
                m.parentNode.insertBefore(a, m)
            })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

            ga('create', 'UA-57533726-1', 'auto');
            ga('send', 'pageview');

        </script>
        <?php 
BLogger::addLog();
?>
    </body>
</html>
Ejemplo n.º 3
0
 public static function getUserOnlineLastXMinutes($min = 10)
 {
     $newtime = time() - $min * 60;
     $bl = new BLogger();
     $arrp = $bl->getWhere("b_timestamp > {$newtime} ORDER BY b_timestamp DESC");
     $arrSudah = array();
     $dipakai = array();
     foreach ($arrp as $log) {
         if (!in_array($log->b_log_userid, $arrSudah)) {
             $arrSudah[] = $log->b_log_userid;
             $dipakai[] = $log;
         }
     }
     $return['nr'] = count($dipakai);
     $return['unique'] = $dipakai;
     $return['all'] = $arrp;
     return $return;
 }
    public function show()
    {
        $url = $_GET['gurl'];
        $id = addslashes($_GET['id']);
        if ($id < 0) {
            die("no ID");
        }
        //Log
        BLogger::addLog("file_id = {$id}", "open_file");
        //echo $url;echo "<br>";
        //echo $id;
        $auth = 1;
        $if = new InputFileModel();
        if ($url == "dm") {
            $if = new DocumentsPortal();
            //cek parent id ada 2 "company policy"
            /*
            			$d = new DMWeb();
            			$arrCHild2 = $d->findChildren(2);
            			$arrCHild = explode(",", $arrCHild2);
            * 
            */
            //pr($arrCHild);
            //Perbaikan 27 Feb 2015
            // Cek parents terluarnya apakah dia saveable
            $if->getByID($id);
            //grand grand parents- init folder - folder awal
            $InitparentsFolder = $if->findInitParent();
            //folder simpannya
            $terletakDiFolder = new DocumentsPortalFolder();
            $terletakDiFolder->getByID($if->file_folder_id);
            //pr($InitparentsFolder);
            //cek KMType nya
            //untuk cek channel
            /*
             * LOAD page con, cek apakah bisa ini sub atau main con
             */
            $a = NewsChannel::myChannels();
            //pr($a);
            /*foreach($a as $chn){
                  $str = " page_channel_id = '$chn' ";
                  $imp[] = $str;
              }
              $wherechannel = implode("OR", $imp);
              $wherechannel = "(".$wherechannel.")";
              */
            $kmtype = new KMType();
            $arrKMTYPE = $kmtype->getWhere("km_folder_id = '{$InitparentsFolder->folder_id}'");
            //kalau punya channel id nya
            if (in_array($arrKMTYPE[0]->webapps_channel_id, $a)) {
                //boleh masuk
            } else {
                if ($_SESSION['DocumentPortal_view_only'] < 1) {
                } else {
                    //nggak boleh lihat
                    $auth = 0;
                }
                //die('Not Authorized To View this Documents');
            }
        }
        if ($auth) {
            $if->getByID($id);
            /*
             * cek folder if apakah ada di child
             */
            //if ($if->file_folder_id == 2 || in_array($if->file_folder_id, $arrCHild)) {
            if (!$InitparentsFolder->folder_saveable) {
                $if->bolehsave = "reg";
                //nosave
            } else {
                $if->bolehsave = "als";
                //save
            }
            //pr($if);
            $path = _SPPATH . $if->upload_url;
            $fil = $if->file_filename;
            $inp = new \Leap\View\InputFile();
            if (in_array($if->file_ext, $inp->arrImgExt)) {
                $this->showImage($if);
            } elseif (in_array($if->file_ext, $inp->arrVideoExt)) {
                $this->showVideo($if);
            } elseif ($if->file_ext == "pdf") {
                $this->showPDF($if);
            } else {
                $this->showDefault($if);
            }
        } else {
            ?>
<h2><?php 
            echo Lang::t('Not Authorized to view this documents');
            ?>
</h2>    
                    <?php 
        }
        //else auth
    }
 public function moveFileAction()
 {
     $fid = isset($_GET['fid']) ? addslashes($_GET['fid']) : die('no FID');
     // file id
     $to = isset($_GET['to']) ? addslashes($_GET['to']) : die('no To ID');
     $df = new DocumentsPortal();
     $df->getByID($fid);
     $df->file_folder_id = $to;
     $df->load = 1;
     $df->save();
     //log
     BLogger::addLog("file_id = {$fid} folder_id = {$to} ", "move_file");
 }
 public function uploadfiles()
 {
     $data = array();
     $c = isset($_GET['c']) ? addslashes($_GET['c']) : die('no c');
     $wc = isset($_GET['wc']) ? addslashes($_GET['wc']) : die('no wc');
     $t = isset($_GET['t']) ? addslashes($_GET['t']) : die('no t');
     $upload_location = _PHOTOPATH . "imports/";
     $upload_location = _PHOTOPATH;
     $fname = $wc . "__" . $c;
     $obj = new $c();
     //cek access right
     if (!$obj->crud_setting['import']) {
         die('not allowed');
     }
     if (isset($_GET['files'])) {
         $error_size = 0;
         $error = false;
         $files = array();
         $uploaddir = $upload_location;
         foreach ($_FILES as $file) {
             //$f->file_url = basename($file['name']);
             $ext = end(explode(".", $file['name']));
             //$f->file_ext = $ext;
             $ffile_filename = $fname . "." . $ext;
             //$f->file_date = leap_mysqldate();
             // if pdf
             //cek size
             $size_awal = $file['size'];
             $data_location = $uploaddir . $ffile_filename;
             $excels = array();
             unlink($data_location);
             if (move_uploaded_file($file['tmp_name'], $data_location)) {
                 $files[] = $uploaddir . $file['name'];
                 $ffile_size = filesize($data_location);
                 //size akhir
                 $size_akhir = $ffile_size;
                 //cek apakah tengah2 gagal
                 if ($size_awal != $size_akhir) {
                     //hapus file corrupt
                     unlink($data_location);
                     //delete file corrupt di db
                     //$f->delete($fid);
                     $error = true;
                     $error_size = 1;
                 } else {
                     if ($ext == "xls") {
                         // masukan ke data..
                         //disini extract excelnya
                         // ExcelFile($filename, $encoding);
                         $xls = new Spreadsheet_Excel_Reader();
                         // Set output Encoding.
                         $xls->setOutputEncoding('CP1251');
                         $xls->read($data_location);
                         //ambil main ID
                         $id_colom = Lang::t($obj->main_id);
                         $id_posisi = 0;
                         $posisi = array();
                         for ($i = 1; $i <= $xls->sheets[0]['numRows']; $i++) {
                             for ($j = 1; $j <= $xls->sheets[0]['numCols']; $j++) {
                                 //$excels[$i][] = "\"".$xls->sheets[0]['cells'][$i][$j]."\",";
                                 //bagian ID databasenya..mari kita extract pakai Lang
                                 if ($i == 1) {
                                     if ($xls->sheets[0]['cells'][$i][$j] == $id_colom) {
                                         $id_posisi = $j;
                                     }
                                     //simpan semua posisi ke array
                                     foreach ($obj->crud_import_allowed as $ids) {
                                         $lang = Lang::t($ids);
                                         if ($xls->sheets[0]['cells'][$i][$j] == $lang) {
                                             $posisi[$ids] = $j;
                                         }
                                     }
                                 } else {
                                     break;
                                 }
                                 //ada tidak ada ID
                                 //karena sekarang semua posisi sudah tahu
                                 //if($id_posisi==0)break;
                             }
                             //$excels[$i][] = "\n";
                             if ($id_posisi == 0) {
                                 break;
                             }
                             if ($i > 1) {
                                 //saving process
                                 $id_active = $xls->sheets[0]['cells'][$i][$id_posisi];
                                 $obj->getById($id_active);
                                 foreach ($obj->crud_import_allowed as $ids) {
                                     $attr_pos = $posisi[$ids];
                                     $obj->{$ids} = $xls->sheets[0]['cells'][$i][$attr_pos];
                                 }
                                 $obj->load = 1;
                                 $excels[$id_active] = $obj->save();
                             }
                         }
                     }
                     //$f->load = 1;
                     //$f->save();
                     //log
                     BLogger::addLog("classname = {$c}, webname = " . $wc, "import_data");
                 }
                 //else cek size
             } else {
                 $error = true;
                 //$f->delete($fid);
             }
         }
         $data = $error ? array('error' => 'There was an error uploading your files') : array('files' => $files, 'excels' => $excels);
     } else {
         $data = array('success' => 'Form was submitted', 'formData' => $_POST);
     }
     if ($error_size) {
         $data['err_size'] = 1;
     }
     //$data['fil'] = $_FILES;
     echo json_encode($data);
 }