Example #1
0
// Tempo de início de para verificar tempo de execução do BackEnd
$exec_ini = execTime();
/*
 * Verificar se usuário está logado. 
 * Pego de SGDC/acesso.php 
 */
if (!isset($_COOKIE['l'])) {
    Header('Location: ../login.php');
} else {
    $tpl = new Template('html_libs/template_all.html');
    if (!isset($_GET['page'])) {
        include "src/pages/index.php";
    } else {
        switch ($_GET['page']) {
            // Colocar aqui, casos de valores para page.
            // Páginas estão em src/pages/*.php
            case "view":
                include "src/pages/view.php";
                break;
            default:
                include "src/pages/index.php";
                var_dump($funcionarios);
                break;
        }
    }
    // Calcula tempo de execução e mostra no Template.
    $exec_fin = execTime();
    $elapsed_time = number_format($exec_fin - $exec_ini, 6);
    $tpl->EXECTIME = "Tempo de Execução: <b>" . $elapsed_time . "</b> segundos";
    $tpl->show();
}
 function parseExcel()
 {
     /*
     		New scenario !
     		1. Parse data xls 
     		2. Validate data before upload
     		3. Store data to tmp table
     		3. Try to move data from tmp table to real table
     		4. Done
     */
     global $EXCEL;
     $username = $this->user['login']['username'];
     logFile(serialize($_FILES));
     // pr($_FILES);exit;
     if ($_FILES) {
         $numberOfSheet = 4;
         $startRowData = 1;
         $startColData = 1;
         $formNametmp = array_keys($_FILES);
         $formName = $formNametmp[0];
         if (empty($formName)) {
             die;
         }
         $startTime = microtime(true);
         /* parse data excel */
         logFile('load excel begin');
         // empty log file
         $parseExcel = $this->excelHelper->fetchExcel($formName, $numberOfSheet, $startRowData, $startColData);
         if ($parseExcel) {
             // logFile('Extract File ', $username);
             foreach ($parseExcel as $key => $val) {
                 $field = implode(',', $val['field_name']);
                 $data = array();
                 if ($val['data']) {
                     foreach ($val['data'] as $keys => $value) {
                         foreach ($value as $k => $v) {
                             $data[$val['field_name'][$k]] = $v;
                         }
                         $newData[$val['sheet']]['data'][] = $data;
                     }
                 } else {
                     print json_encode(array('status' => false, 'msg' => 'Data tidak tersedia'));
                     exit;
                 }
             }
             /* here begin process */
             if ($newData) {
                 $emptyTmptable = $this->collectionHelper->truncateData(false, true);
                 if ($emptyTmptable) {
                     logFile('empty tmp table before insert');
                     $referenceQuery = $this->collectionHelper->tmp_data($newData);
                     logFile('store data from xls to tmp table');
                     if ($referenceQuery) {
                         // logFile('Preparing database ', $username);
                         $insertData = false;
                         if ($referenceQuery) {
                             $this->collectionHelper->startTransaction();
                             $getRef = $this->collectionHelper->getRefData($newData);
                             $referenceQuery = $this->excelHelper->referenceData($getRef);
                             $insertRef = $this->collectionHelper->storeRefData($referenceQuery);
                             if (!$insertRef) {
                                 $this->collectionHelper->rollbackTransaction();
                                 print json_encode(array('status' => false, 'msg' => 'Upload data gagal'));
                                 exit;
                             }
                             $getMaster = $this->collectionHelper->getMasterData();
                             // insert indiv
                             $indivQuery = $this->excelHelper->parseMasterData($getMaster, true);
                             $insertIndiv = $this->collectionHelper->storeIndivData($indivQuery);
                             // insert det,obs,coll
                             sleep(1);
                             $getMaster = $this->collectionHelper->getMasterData();
                             $masterQuery = $this->excelHelper->parseMasterData($getMaster);
                             $insertIndiv = $this->collectionHelper->storeMasterData($masterQuery);
                             // update tmp photo
                             $updateTmpPhoto = $this->collectionHelper->updateTmpPhoto();
                             // insert collector
                             $getMaster = $this->collectionHelper->getMasterData();
                             $collectorQuery = $this->excelHelper->parseMasterData($getMaster, true, 5, 'collector');
                             $insertCollector = $this->collectionHelper->storeSingleData($collectorQuery);
                             $getMaster = $this->collectionHelper->getMasterData(true, 'tmp_photo');
                             $imgQuery = $this->excelHelper->parseMasterData($getMaster, true, 4, 'img');
                             $insertImage = $this->collectionHelper->storeSingleData($imgQuery, 'img');
                             if ($insertImage) {
                                 $log_upload = $this->collectionHelper->insert_log_upload($_FILES[$formName]['name']);
                                 logFile('log xls file');
                                 $this->collectionHelper->commitTransaction();
                                 $insertData = true;
                             } else {
                                 $this->collectionHelper->rollbackTransaction();
                             }
                         } else {
                             print json_encode(array('status' => false, 'msg' => 'Gagal mengunggah data'));
                             exit;
                         }
                         /*
                         [Old script]
                         
                         $masterQuery = $this->excelHelper->parseMasterData($newData);
                         $masterQuery['rawdata']['img'] =  $referenceQuery['rawdata']['img'];
                         
                         $priority = array('taxon','locn','person');
                         $masterPriority = array('indiv','img','det','obs','coll','collector');
                         
                         $param['ref'] = $referenceQuery;
                         $param['ref_priority'] = $priority;
                         $param['master'] = $masterQuery;
                         $param['master_priority'] = $masterPriority;
                         
                         
                         $insertData = $this->collectionHelper->insertCollFromExcel($param);
                         */
                         $endTime = microtime(true);
                         if ($insertData) {
                             sleep(1);
                             logFile('Insert xls success');
                             $this->log('upload', 'success upload xls');
                             print json_encode(array('status' => true, 'finish' => true, 'msg' => 'Insert success  (' . execTime($startTime, $endTime) . ')'));
                             // send mail to user
                             // $sendMail = $this->sendMail();
                             // if ($sendMail){
                             // 	logFile('Send mail success');
                             // 	print json_encode(array('status'=>true, 'finish'=>true, 'msg'=>'Insert success  ('. execTime($startTime,$endTime).')'));
                             // exit;
                             // }else{
                             // 	logFile('Send mail failed');
                             // 	print json_encode(array('status'=>true, 'msg'=>'Kirim akun gagal'));
                             // exit;
                             // }
                             exit;
                         } else {
                             logFile('Insert xls failed');
                             // echo 'Insert data failed';
                             print json_encode(array('status' => false, 'msg' => 'Insert data gagal'));
                             exit;
                         }
                     } else {
                         logFile('failed insert to tmp database');
                         print json_encode(array('status' => false, 'msg' => 'Insert data gagal'));
                         exit;
                     }
                 }
             } else {
                 print json_encode(array('status' => false, 'msg' => 'Tidak ada data yang tersedia'));
                 exit;
             }
         } else {
             print json_encode(array('status' => false, 'msg' => 'Ekstrak gagal'));
             exit;
         }
     } else {
         logFile('File xls empty');
         // echo "File is empty";
         print json_encode(array('status' => true, 'msg' => 'File kosong'));
     }
     exit;
 }
function makeviewbytype($typeid, $ids, $allnum)
{
    global $action, $action2, $flag, $stime, $sql, $sql1, $makeinterval, $db, $cache;
    $macpage = be("all", "page");
    $num = be("get", "num");
    if (isN($num)) {
        $num = 0;
    } else {
        $num = intval($num);
    }
    if (isN($macpage)) {
        $macpage = 1;
    } else {
        $macpage = intval($macpage);
    }
    if ($flag == "art") {
        $typearr = getValueByArray($cache[1], "t_id", $typeid);
        $sql = $sql . " and a_type=" . $typeid;
        $sql1 = $sql1 . " and a_type=" . $typeid;
    } else {
        $typearr = getValueByArray($cache[0], "t_id", $typeid);
        $sql = $sql . " and d_type=" . $typeid;
        $sql1 = $sql1 . " and d_type=" . $typeid;
    }
    $sql .= " limit " . 100 * ($macpage - 1) . ",100";
    $typename = $typearr["t_name"];
    $nums = $db->getOne($sql1);
    $pcount = ceil($nums / 100);
    if ($nums == 0) {
        if (isN($action2) && $num > $allnum) {
            echo "<font color='red'>ID为 " . $typeid . " 的分类没有数据</font><br>";
        } else {
            echo "恭喜<font color='red'>" . $typename . "</font>搞定<br>暂停" . $makeinterval . "秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextPage();\"," . $makeinterval . "000);function makeNextPage(){location.href='?action=" . $action . "&mtype=" . $ids . "&flag=" . $flag . "&num=" . ($num + 1) . "&page=" . $macpage . "&action2=" . $action2 . "';}</script>";
            return;
        }
    }
    $rs = $db->query($sql);
    echo "正在开始生成栏目<font color='red'>" . $typename . "</font>的内容页,当前是第<font color='red'>" . $macpage . "</font>页,共<font color='red'>" . $pcount . "</font>页<br>";
    while ($row = $db->fetch_array($rs)) {
        makeviewbyrs($row, $typearr);
    }
    unset($rs);
    if ($macpage == $pcount || $nums < 100) {
        echo "<font color='red'>恭喜" . $typename . "搞定</font>";
    }
    echo "页面生成时间: " . (execTime() - $stime) . "秒 &nbsp;<br>暂停" . $makeinterval . "秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextPage();\"," . $makeinterval . "000);function makeNextPage(){location.href='?action=" . $action . "&mtype=" . $ids . "&page=" . ($macpage + 1) . "&action2=" . $action2 . "&num=" . $num . "&flag=" . $flag . "';}</script>";
}
Example #4
0
 function actNewfolder()
 {
     global $post;
     if (empty($_POST['path'])) {
         $path = '.';
     } else {
         $path = $_POST['path'];
     }
     mkdir($path . '/' . $post->get('name'));
     echo printJSON(execTime());
 }
Example #5
0
File: conn.php Project: klarclm/sgv
<?php

define('MAC_ROOT', substr(__FILE__, 0, -13));
require MAC_ROOT . '/inc/config/config.php';
require MAC_ROOT . '/inc/config/cache.php';
require MAC_ROOT . '/inc/common/class.php';
require MAC_ROOT . '/inc/common/function.php';
require MAC_ROOT . '/inc/common/template.php';
require MAC_ROOT . "/inc/common/template_diy.php";
define('MAC_PATH', $MAC['site']['installdir']);
define('MAC_ROOT_TEMPLATE', MAC_ROOT . '/template/' . $MAC['site']['templatedir'] . '/' . $GLOBALS['MAC']['site']['htmldir']);
define('MAC_STARTTIME', execTime());
define('MAC_URL', 'http://www.maccms.com/');
define('MAC_NAME', 'ƻ��CMS');
@session_start();
@header('Content-Type:text/html;Charset=utf-8');
@date_default_timezone_set('Etc/GMT-8');
@ini_set('display_errors', 'On');
@error_reporting(7);
@set_error_handler('my_error_handler');
@ob_start();
function makeviewday()
{
    global $action, $action2, $flag, $sql, $sql1, $stime, $makeinterval, $db, $cache;
    $macpage = be("get", "page");
    $num = be("get", "num");
    if (isN($num)) {
        $num = 0;
    } else {
        $num = intval($num);
    }
    if ($flag == "art") {
        $sql2 = "SELECT DISTINCT a_type FROM {pre}art WHERE 1=1 ";
        //$where = " and STR_TO_DATE(a_time,'%Y-%m-%d')='".date("Y-m-d")."'";
        $where = " and to_days(a_time) = to_days(now())";
    } else {
        $sql2 = "SELECT DISTINCT d_type FROM {pre}vod WHERE 1=1 ";
        //$where = " and STR_TO_DATE(d_time,'%Y-%m-%d')='".date("Y-m-d")."'";
        $where = " and to_days(d_time) = to_days(now())";
    }
    $sql = $sql . $where;
    $nums = $db->getOne($sql1 . $where);
    $pcount = ceil($nums / 100);
    if (isN($macpage)) {
        $macpage = 1;
    } else {
        $macpage = intval($macpage);
    }
    if ($nums == 0) {
        echo "<font color='red'>今天没有更新数据</font><br>";
        return;
    }
    $sql = $sql . " limit " . 100 * ($macpage - 1) . ",100";
    $rs = $db->query($sql);
    echo "正在开始生成<font color='red'>今日数据</font>的内容页,当前是第<font color='red'>" . $macpage . "</font>页,共<font color='red'>" . $pcount . "</font>页<br>";
    while ($row = $db->fetch_array($rs)) {
        if ($flag == "art") {
            $typearr = getValueByArray($cache[1], "t_id", $row["a_type"]);
        } else {
            $typearr = getValueByArray($cache[0], "t_id", $row["d_type"]);
        }
        makeviewbyrs($row, $typearr);
    }
    unset($rs);
    if ($macpage == $pcount || $nums < 100) {
        echo "<font color='red'>恭喜今日数据搞定</font>";
        maketypeday($sql2 . $where);
        return;
    }
    echo "页面生成时间: " . (execTime() - $stime) . "秒 &nbsp;<br>暂停" . $makeinterval . "秒后继续生成<script language=\"javascript\">setTimeout(\"makeNextPage();\"," . $makeinterval . "000);function makeNextPage(){location.href='?action=viewday&page=" . ($macpage + 1) . "&action2=" . $action2 . "&num=" . $num . "&flag=" . $flag . "';}</script>";
}
Example #7
0
function getRunTime()
{
    $t2 = execTime() - MAC_STARTTIME;
    $size = memory_get_usage();
    $memory = getFormatSize($size);
    unset($unit);
    return 'Processed in: ' . round($t2, 4) . ' second(s),&nbsp;' . $GLOBALS['db']->sql_qc . '  queries ' . $memory . ' Mem On.';
}