document.body.style.minHeight = '' + (window.innerHeight - 2) + 'px';"; } } public static function endHtml() { $version = (file_exists(APP_PATH_ROOT . '/VERSION'))? file_get_contents(APP_PATH_ROOT . '/VERSION') : null; if ($version) { echo '
version: '.$version.'
'; } echo UI::fixFooterPosition('footer_js_tag'); echo "\n"; } public static function menu() { if (!User::logged()) return; if (User::hasAccess('menu')) { Lib::loadClass('ProcesMenu'); $procesMenu = ProcesMenu::getInstance(); $procesMenu->show(); if (!V::get('MENU_INIT', '', $_GET)) { Lib::loadClass('UserActivity'); //echo UserActivity::showListInContainer(); } } else { UI::loadTemplate('menuLevel6'); } } public static function loadTemplate($tmplName, $data = array()) { if (is_array($data) && !empty($data)) { extract($data); } include APP_PATH_LIB . "/tmpl/{$tmplName}.php"; } public static function hotKeyDBG($str) { if (User::hasAccess('dbg')) { echo '' . htmlspecialchars($str) . ''; } } public static function showMessagesForTable($tblName) { if (empty($tblName)) return; Lib::loadClass('Router'); $msgsRoute = Router::getRoute('Msgs'); $msgs = $msgsRoute->getActiveMessagesForTable($tblName); if (!empty($msgs)) { self::loadTemplate('msgsForTable', array('msgs' => $msgs)); } } public static function alert($alertType, $msg, $outputHtml = true) { if (!$outputHtml) { $type = ('danger' == $alertType) ? "ERROR" : strtoupper($alertType); echo "{$type}: {$msg}\n"; return; } UI::tag('div', ['class'=>"alert alert-{$alertType}"], $msg, "\n"); } public static function setTitleJsTag($title) { self::setTitle($title); } public static function setTitle($title) { self::tag('script', null, "document.title = '{$title}';", "\n"); } /** * $params - Array * $params['caption'] (optional) -> ... * $params['cols'] (optional) -> cols, if not set read from first row * $params['rows'] -> rows, if not set - empty table * $params['rows'] -> rows, if not set - empty table * $params['disable_lp'] -> disable lp. col */ public static function table($params) { $cols = V::get('cols', array(), $params); $rows = V::get('rows', array(), $params); $caption = V::get('caption', '', $params); $showLp = (!V::get('disable_lp', false, $params)); if (empty($cols) && !empty($rows)) { $firstRow = array(); foreach ($rows as $row) { $firstRow = $row; break; } $cols = array_keys((array)$firstRow); } // if (empty($cols)) return; $hiddenCols = V::get('hidden_cols', array(), $params); $tableAttrs = [ 'class' => "table table-bordered table-hover" ]; $html_id = V::get('__html_id', '', $params); if ($html_id) $tableAttrs['id'] = $html_id; self::startTag('table', $tableAttrs); echo "\n"; if ($caption) { self::tag('caption', null, $caption); echo "\n"; } if (!empty($cols)) { self::startTag('thead', null); echo "\n"; self::startTag('tr', null); echo "\n"; if ($showLp) { self::tag('th', [ 'style' => "padding:2px" ], "Lp."); echo "\n"; } foreach ($cols as $colName) { if (in_array($colName, $hiddenCols)) continue; self::tag('th', [ 'style' => "padding:2px"], $colName); echo "\n"; } self::endTag('tr'); echo "\n"; self::endTag('thead'); echo "\n"; } self::startTag('tbody', null); echo "\n"; if (empty($rows)) { self::startTag('tr'); echo "\n"; self::tag('td', [ 'style' => "padding:2px" ], V::get('empty_msg', "Brak danych", $params)); echo "\n"; self::endTag('tr'); echo "\n"; } else { $i = 0; foreach ($rows as $row) { $i++; $trAttrs = array(); if (!empty($row['__js_on_click'])) $trAttrs['onClick'] = $row['__js_on_click']; self::startTag('tr', $trAttrs); echo "\n"; if ($showLp) { self::tag('th', [ 'style' => "padding:2px; color:#ccc" ], $i); echo "\n"; } foreach ($cols as $colName) { if (in_array($colName, $hiddenCols)) continue; self::tag('td', [ 'style' => "padding:2px" ], V::get($colName, '', $row)); echo "\n"; } self::endTag('tr'); echo "\n"; } } self::endTag('tbody'); echo "\n"; self::endTag('table'); echo "\n"; } public static function startContainer($attrs = array()) {// echo '
' . "\n"; $attrs['class'] = (!empty($attrs['class'])) ? $attrs['class'] . ' ' . 'container' : 'container'; self::startTag('div', $attrs, "\n"); } public static function endContainer() { self::endTag('div', "\n"); } public static function startTag($tag, $attrs = array(), $addWhiteSpace = false) { $outAttrs = ''; if (is_array($attrs)) { foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\""; } echo '<' . $tag . $outAttrs . '>' . self::whiteSpace($addWhiteSpace); } public static function whiteSpace($addWhiteSpace = false) { return (!$addWhiteSpace) ? '' : (true === $addWhiteSpace) ? " " : $addWhiteSpace; } public static function endTag($tag, $addWhiteSpace = false) { echo '' . self::whiteSpace($addWhiteSpace); } public static function tag($tag, $attrs = array(), $childrens = array(), $addWhiteSpace = false) { $whiteSpace = self::whiteSpace($addWhiteSpace); self::startTag($tag, $attrs); echo $whiteSpace; if (!empty($childrens) && is_array($childrens)) throw new Exception("UI::tag() children as nodes not implemented".json_encode($childrens)); if (is_scalar($childrens)) echo $childrens; echo $whiteSpace; self::endTag($tag); echo $whiteSpace; } public static function emptyTag($tag, $attrs = array(), $addWhiteSpace = false) { $outAttrs = ''; if (is_array($attrs)) { foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\""; } echo '<' . $tag . $outAttrs . '/>' . self::whiteSpace($addWhiteSpace); } public static function link($type, $content, $href, $attrs = array()) { $attrs['class'] = V::get('class', '', $attrs); $attrs['class'] .= "btn btn-{$type}"; if (!empty($attrs['className'])) { foreach ($attrs['className'] as $cls => $bool) { if ($bool) $attrs['class'] .= " {$cls}"; } unset($attrs['className']); } $attrs['href'] = $href; UI::tag('a', $attrs, $content); } public static function jsAjaxTable($params) { } public static function price($value, $dec = ',') { // TODO: if not number type - string wwith wrong format - try to convert? return number_format($value, 2, $dec, ' '); } }