Exemplo n.º 1
0
 private static function &_query($query, $args = NULL)
 {
     $false = FALSE;
     if (empty($query)) {
         return $false;
     }
     if (!isset($GLOBALS['sql_query_count'])) {
         $GLOBALS['sql_query_count'] = 0;
     } else {
         $GLOBALS['sql_query_count']++;
     }
     if (utopia::DebugMode()) {
         $tID = 'QRY' . $GLOBALS['sql_query_count'] . ': ' . $query;
         timer_start($tID, $args);
     }
     $pdo = self::connect();
     $pdo->reset();
     if (is_array($args)) {
         foreach ($args as $a) {
             $pdo->addByVal($a, self::getType($a));
         }
     }
     try {
         self::$queryCount++;
         $stm = $pdo->call($query);
         $stm->setFetchMode(PDO::FETCH_ASSOC);
     } catch (Exception $e) {
         if (utopia::DebugMode()) {
             $timetaken = timer_end($tID);
         }
         throw $e;
     }
     if (utopia::DebugMode()) {
         $timetaken = timer_end($tID);
     }
     return $stm;
 }
Exemplo n.º 2
0
 /**
  * Internal timer stop/start.
  * 
  * @param string One of 'start' or 'stop'.
  * @return void
  */
 protected function timer($start_stop)
 {
     $this->timer[$start_stop] = microtime(true);
     if (function_exists('timer_start')) {
         if ('start' === $start_stop) {
             timer_start('router');
         } else {
             if ('stop' === $start_stop) {
                 timer_end('router');
             }
         }
     }
 }
Exemplo n.º 3
0
 public function ShowData($dataset = null)
 {
     echo '<h1>' . $this->GetTitle() . '</h1>';
     echo '{list.' . get_class($this) . '}';
     array_sort_subkey($this->fields, 'order');
     $this->GetLimit($limit, $page);
     if (!$dataset) {
         $dataset = $this->GetDataset();
     }
     $dataset->GetPage($page, $limit);
     $num_rows = $dataset->CountRecords();
     uEvents::TriggerEvent('OnShowDataList', $this);
     // first draw header for list
     if (!isset($GLOBALS['inlineListCount'])) {
         $GLOBALS['inlineListCount'] = 0;
     } else {
         $GLOBALS['inlineListCount']++;
     }
     ob_start();
     if (!$this->isAjax) {
         echo '<form class="uf" action="" onsubmit="this.action = window.location" method="post"><input type="hidden" name="__ajax" value="updateField">';
     }
     echo "<div class=\"table-wrapper\"><table class=\"" . get_class($this) . " layoutListSection module-content\">";
     $sectionFieldTitles = array();
     // TODO: pagination for list record display
     if (!$this->flag_is_set(LIST_HIDE_HEADER)) {
         echo '<thead>';
         ob_start();
         // start of SECTION headers
         if (count($this->layoutSections) > 1) {
             echo '<tr>';
             // need first 'empty' column for buttons?
             if ($this->flag_is_set(ALLOW_DELETE)) {
                 echo "<td>&nbsp;</td>";
             }
             $sectionCount = 0;
             $sectionID = NULL;
             $keys = array_keys($this->fields);
             $lastFieldName = end($keys);
             foreach ($this->fields as $fieldName => $fieldData) {
                 if ($fieldData['visiblename'] === NULL) {
                     continue;
                 }
                 if ($sectionID === NULL) {
                     $sectionID = $fieldData['layoutsection'];
                 }
                 if ($fieldData['layoutsection'] !== $sectionID) {
                     // write the section, and reset the count
                     $sectionName = $this->layoutSections[$sectionID]['title'];
                     $secClass = empty($sectionName) ? '' : ' sectionHeader';
                     echo "<td colspan=\"{$sectionCount}\" class=\"{$secClass}\">" . nl2br($sectionName) . "</td>";
                     $sectionCount = 0;
                     $sectionID = $fieldData['layoutsection'];
                 }
                 $sectionFieldTitles[$sectionID] = array_key_exists($sectionID, $sectionFieldTitles) ? $sectionFieldTitles[$sectionID] : !empty($fieldData['visiblename']);
                 $sectionCount++;
             }
             $sectionName = $this->layoutSections[$sectionID]['title'];
             $secClass = empty($sectionName) ? '' : ' sectionHeader';
             echo "<td colspan=\"{$sectionCount}\" class=\"{$secClass}\">" . nl2br($sectionName) . "</td>";
             echo "</tr>";
         }
         // start of FIELD headers
         $colcount = 0;
         echo '<tr class="field-headers">';
         if ($this->flag_is_set(ALLOW_DELETE)) {
             echo '<th"></th>';
             $colcount++;
         }
         foreach ($this->fields as $fieldName => $fieldData) {
             if ($fieldData['visiblename'] === NULL) {
                 continue;
             }
             $colcount++;
             // sort?
             $icon = '';
             $o = $this->GetOrderBy(true);
             if (is_array($o)) {
                 foreach ($o as $order) {
                     if (strpos($order, '`' . $fieldName . '`') !== FALSE) {
                         $icon = ' sort-up';
                         if (stripos($order, 'desc') !== FALSE) {
                             $icon = ' sort-down';
                         }
                         break;
                     }
                 }
             }
             echo '<th class="field-' . $fieldName . ' sortable' . $icon . '" data-field="' . $fieldName . '" data-mid="' . $this->GetModuleId() . '">';
             // title
             echo nl2br($fieldData['visiblename']);
             echo "</th>";
         }
         echo '</tr>';
         // close column headers
         $header_output = ob_get_clean();
         if ($this->flag_is_set(ALLOW_FILTER) && $this->hasEditableFilters === true && $this->hideFilters !== TRUE) {
             echo '<tr class="noprint"><td class="uFilters" colspan="' . $colcount . '">';
             // other filters
             foreach ($this->filters as $fType) {
                 foreach ($fType as $filterset) {
                     //flag_is_set($fieldData['options'],ALLOW_FILTER)) {
                     foreach ($filterset as $filterInfo) {
                         if ($filterInfo['it'] === itNONE) {
                             continue;
                         }
                         echo $this->GetFilterBox($filterInfo);
                     }
                 }
             }
             echo '</td></tr>';
         }
         if ($num_rows > 0 || $this->flag_is_set(ALLOW_ADD) || $this->hasEditableFilters === true) {
             echo $header_output;
         }
         echo "</thead>\n";
     }
     // now display data rows
     // process POST filters
     $total = array();
     $totalShown = array();
     timer_start('Draw Rows: ' . get_class($this));
     $gUrl = '';
     $body = "<tbody{$gUrl}>";
     if ($num_rows == 0) {
     } else {
         $i = 0;
         $fields = $this->GetFields();
         while ($row = $dataset->fetch()) {
             $i++;
             // move totals here
             foreach ($fields as $fieldName => $fieldData) {
                 switch ($this->GetFieldType($fieldName)) {
                     case ftNUMBER:
                     case ftCURRENCY:
                     case ftPERCENT:
                         if (!array_key_exists($fieldName, $total)) {
                             $total[$fieldName] = 0;
                         }
                         if (!array_key_exists($fieldName, $totalShown)) {
                             $totalShown[$fieldName] = 0;
                         }
                         $preProcessValue = floatval(preg_replace('/[^0-9\\.-]/', '', $this->PreProcess($fieldName, $row[$fieldName], $row)));
                         if ($i <= 150) {
                             $totalShown[$fieldName] += $preProcessValue;
                         }
                         $total[$fieldName] += $preProcessValue;
                         break;
                     default:
                         break;
                 }
             }
             $body .= $this->DrawRow($row);
         }
     }
     $body .= "</tbody>";
     timer_end('Draw Rows: ' . get_class($this));
     $foot = '';
     $canadd = false;
     foreach ($this->fields as $fieldName => $fieldData) {
         if ($this->flag_is_set(ALLOW_ADD, $fieldName)) {
             $canadd = true;
             break;
         }
     }
     if ($canadd) {
         $hideNew = $this->GetMaxRows() && $num_rows >= $this->GetMaxRows() ? ' style="display:none"' : '';
         $foot .= '<tr class="newRow"' . $hideNew . '>';
         if ($this->flag_is_set(ALLOW_DELETE)) {
             $foot .= "<td class=\"new-ident\"></td>";
         }
         foreach ($this->fields as $fieldName => $fieldData) {
             if ($fieldData['visiblename'] === NULL) {
                 continue;
             }
             $classes = array();
             $class = count($classes) > 0 ? ' class="' . join(' ', $classes) . '"' : '';
             if ($this->flag_is_set(ALLOW_ADD, $fieldName)) {
                 $foot .= "<td{$class}>" . $this->GetCell($fieldName, NULL) . '</td>';
             }
             // TODO: Default value not showing on new records (list)
         }
         $foot .= '</tr>';
     }
     if (!empty($total) && $this->flag_is_set(SHOW_TOTALS)) {
         $foot .= '<tr>';
         if ($this->flag_is_set(ALLOW_DELETE)) {
             $foot .= "<td class=\"totals-ident\"></td>";
         }
         foreach ($this->fields as $fieldName => $fieldData) {
             if ($fieldData['visiblename'] === NULL) {
                 continue;
             }
             $classes = array();
             $class = count($classes) > 0 ? ' class="' . join(' ', $classes) . '"' : '';
             if (array_key_exists($fieldName, $total)) {
                 $foot .= "<td{$class}><b>";
                 if ($totalShown[$fieldName] != $total[$fieldName]) {
                     $foot .= htmlentities($this->PreProcess($fieldName, $totalShown[$fieldName])) . '(shown)<br/>';
                 }
                 $foot .= htmlentities($this->PreProcess($fieldName, $total[$fieldName]));
                 $foot .= '</b></td>';
             } else {
                 $foot .= "<td{$class}></td>";
             }
         }
         $foot .= '</tr>';
     }
     if (!empty($foot)) {
         echo "<tfoot>{$foot}</tfoot>";
     }
     echo $body;
     // now finish table
     echo "</table></div>";
     //"</div>";
     if (!$this->isAjax) {
         echo '</form>';
     }
     if ($limit) {
         $pages = max(ceil($num_rows / $limit), 1);
         ob_start();
         utopia::OutputPagination($pages, '_p_' . $this->GetModuleId());
         $pagination = ob_get_clean();
         if ($pagination) {
             echo '<div class="pagination right module-content">' . $pagination . '</div>';
         }
     }
     echo '<div class="right module-content">Showing ' . ($page * $limit + 1) . ' - ' . min($page * $limit + $limit, $num_rows) . ' of ' . $num_rows . '</div>';
     $cont = ob_get_clean();
     echo $cont;
 }
Exemplo n.º 4
0
 /**
  * добавляет в глобальный шаблон блоки
  */
 function get_blocks($blocks = array())
 {
     foreach ($blocks as $block_name => $block) {
         # создаём объект
         $module_loader =& Registry::get('TModuleLoader');
         $class_name = isset($block['class']) ? $block['class'] : DEFAULT_CLASS;
         //$GLOBALS['blocks'][$class_name] = $module_loader->getModuleObject($class_name);
         $GLOBALS['blocks'][$class_name] =& Registry::get($class_name);
     }
     foreach ($blocks as $block_name => $block) {
         timer_start('block=' . $block_name);
         # массив данных текущего блока
         $data = array();
         $class_name = isset($block['class']) ? $block['class'] : DEFAULT_CLASS;
         $block['cache'] = isset($block['cache']) ? $block['cache'] : false;
         $tables = isset($block['tables']) ? $block['tables'] : array();
         $block['cache_tables'] = isset($block['cache_tables']) ? $block['cache_tables'] : array();
         if (CACHE_BLOCKS && $block['cache']) {
             // Очистка папки cache/blocks с вероятностью 0.001
             if (rand(0, 999) == 13) {
                 $this->cleanCache();
             }
             $cache_id = md5($module_loader->callModuleMethod($class_name, "_cache", array_merge($block, array('block_name' => $block_name))));
             if ($this->is_cached($this->content['type'], $block_name, $cache_id, $tables)) {
                 $data = $this->get_from_cache($this->content['type'], $block_name, $cache_id);
             } else {
                 $data = $this->generate_block_data($block_name, $block);
                 $this->save_in_cache($this->content['type'], $block_name, $cache_id, $data);
             }
         } else {
             $data = $this->generate_block_data($block_name, $block);
         }
         $this->tpl->assign((array) $data);
         timer_end('block=' . $block_name);
     }
 }
Exemplo n.º 5
0
 static function Finish()
 {
     if (self::$finished) {
         return;
     }
     self::$finished = true;
     while (ob_get_level() > 3) {
         ob_end_flush();
     }
     timer_start('Output Template');
     utopia::OutputTemplate();
     timer_end('Output Template');
     if (isset($GLOBALS['timers']) && utopia::DebugMode()) {
         echo '<pre class="uDebug"><table>';
         foreach ($GLOBALS['timers'] as $name => $info) {
             if (!is_array($info)) {
                 continue;
             }
             $time = !array_key_exists('time_taken', $info) ? timer_end($name) : $info['time_taken'];
             $time = number_format($time, 2);
             echo '<tr><td style="vertical-align:top;border-top:1px solid black">' . $time . '</td><td style="vertical-align:top;border-top:1px solid black">' . $name . PHP_EOL . $info['info'] . '</td></tr>';
         }
         echo '</table></pre>';
     }
     header('X-Runtime: ' . number_format((microtime(true) - UCORE_START_TIME) * 1000) . 'ms');
     die;
 }
Exemplo n.º 6
0
    $row['module_name']::Initialise();
    timer_end('Init: ' . $row['module_name']);
}
timer_end('Static Initialise');
uConfig::DefineConfig();
uConfig::ValidateConfig();
uEvents::TriggerEvent('ConfigDefined');
timer_start('Before Init');
uEvents::TriggerEvent('BeforeInit');
timer_end('Before Init');
timer_start('Table Initialise');
uTableDef::TableExists(null);
// cache table exists
$allmodules = utopia::GetModulesOf('uTableDef');
foreach ($allmodules as $row) {
    // must run second due to requiring GLOB_MOD to be setup fully
    timer_start('Init: ' . $row['module_name']);
    $obj = utopia::GetInstance($row['module_name']);
    $obj->AssertTable();
    // setup Parents
    timer_end('Init: ' . $row['module_name']);
}
timer_end('Table Initialise');
define('INIT_COMPLETE', TRUE);
timer_start('After Init');
uEvents::TriggerEvent('InitComplete');
uEvents::TriggerEvent('AfterInit');
timer_end('After Init');
if ($_SERVER['HTTP_HOST'] !== 'cli') {
    utopia::UseTemplate(TEMPLATE_DEFAULT);
}
Exemplo n.º 7
0
/* устанавливается document_status */
$GLOBALS['document_status'] = 200;
require_once PATH_COMMON_LIBS . 'error.lib.php';
require_once PATH_COMMON_LIBS . 'path.lib.php';
//подключаем класс реестра объектов
include_once common_class('registry.php5');
/* устанавливает соединение с базой данных */
// @todo нормальный обработчик ошибок при коннекте к БД
(require_once DB_CONNECT) or log_error('Cannot find file "' . DB_CONNECT . '"to connect to DB');
@mysql_connect(MYSQL_HOST, MYSQL_LOGIN, MYSQL_PASSWORD) or die(mysql_error());
@mysql_select_db(MYSQL_DB) or die(mysql_error());
@mysql_query("SET NAMES \"" . DB_SET_NAMES . "\"");
/* подключаем встроенный дебаггер */
require_once common_lib('debug');
timer_start('all');
//подключаем вывод страницы в gz
require_once common_lib('cache');
ob_start('cache_handler');
/* подключается библиотека функций */
require_once common_lib('utils');
/* подгружаем контроллер, инициализирующий общие классы, для сайта и админки */
require_once common('main.init');
$main =& Registry::get('TMainInit');
require_once PATH_CONFIG . 'settings.cfg.php';
require_once PATH_CONFIG . 'lang.cfg.php';
/* Определение глобальных переменных */
require_once cfg('common');
require_once base('core.dispatcher');
timer_end('all');
echo showDebugInfo();
ob_end_flush();