UI.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. class UI {
  3. public static function getTitle() {
  4. $title = 'SE';
  5. $host = $_SERVER['SERVER_NAME'];
  6. if (substr($host, 0, 5) == 'biuro') {
  7. $host = substr($host, 6);
  8. }
  9. $title = "{$host}-SE";
  10. return $title;
  11. }
  12. public static function gora() {
  13. UI::startHtml();
  14. }
  15. public static function startHtml() {
  16. Lib::loadClass('S');
  17. UI::loadTemplate('_layout_gora');
  18. }
  19. public static function dol() {
  20. UI::endHtml();
  21. }
  22. public static function fixFooterPosition($type) {
  23. $fixFooterPosition = true;// from config?
  24. if (!$fixFooterPosition) return;
  25. switch ($type) {
  26. case 'footer_style': return 'position:absolute; bottom:0; left:0; width:100%; ';
  27. case 'body_style': return 'position:relative; padding-bottom:32px;';
  28. case 'footer_js_tag': return "\n<script>document.body.style.minHeight = '' + (window.innerHeight - 2) + 'px';</script>";
  29. }
  30. }
  31. public static function endHtml() {
  32. $version = (file_exists(APP_PATH_ROOT . '/VERSION'))? file_get_contents(APP_PATH_ROOT . '/VERSION') : null;
  33. if ($version) {
  34. echo '<div style="' . UI::fixFooterPosition('footer_style') . 'border-top:1px solid #ddd; margin-top:10px; padding:0 30px; font-size:xx-small; color:#888">version: '.$version.'</div>';
  35. }
  36. echo UI::fixFooterPosition('footer_js_tag');
  37. echo "\n</body></html>";
  38. }
  39. public static function menu() {
  40. if (!User::logged()) return;
  41. if (User::hasAccess('menu')) {
  42. Lib::loadClass('ProcesMenu');
  43. $procesMenu = ProcesMenu::getInstance();
  44. $procesMenu->show();
  45. if (!V::get('MENU_INIT', '', $_GET)) {
  46. Lib::loadClass('UserActivity');
  47. //echo UserActivity::showListInContainer();
  48. }
  49. }
  50. else {
  51. UI::loadTemplate('menuLevel6');
  52. }
  53. }
  54. public static function loadTemplate($tmplName, $data = array()) {
  55. if (is_array($data) && !empty($data)) {
  56. extract($data);
  57. }
  58. include APP_PATH_LIB . "/tmpl/{$tmplName}.php";
  59. }
  60. public static function hotKeyDBG($str) {
  61. if (User::hasAccess('dbg')) {
  62. echo '<span class="hidden-dbg">' . htmlspecialchars($str) . '</span>';
  63. }
  64. }
  65. public static function showMessagesForTable($tblName) {
  66. if (empty($tblName)) return;
  67. Lib::loadClass('Router');
  68. $msgsRoute = Router::getRoute('Msgs');
  69. $msgs = $msgsRoute->getActiveMessagesForTable($tblName);
  70. if (!empty($msgs)) {
  71. self::loadTemplate('msgsForTable', array('msgs' => $msgs));
  72. }
  73. }
  74. public static function alert($alertType, $msg, $outputHtml = true) {
  75. if (!$outputHtml) {
  76. $type = ('danger' == $alertType) ? "ERROR" : strtoupper($alertType);
  77. echo "{$type}: {$msg}\n";
  78. return;
  79. }
  80. ?>
  81. <div class="alert alert-<?php echo $alertType; ?>">
  82. <?php echo $msg; ?>
  83. </div>
  84. <?php
  85. }
  86. public static function setTitleJsTag($title) {
  87. ?>
  88. <script>
  89. document.title = '<?php echo $title; ?>';
  90. </script>
  91. <?php
  92. }
  93. /**
  94. * $params - Array
  95. * $params['caption'] (optional) -> <caption>...</caption>
  96. * $params['cols'] (optional) -> cols, if not set read from first row
  97. * $params['rows'] -> rows, if not set - empty table
  98. * $params['rows'] -> rows, if not set - empty table
  99. * $params['disable_lp'] -> disable lp. col
  100. */
  101. public static function table($params) {
  102. $cols = V::get('cols', array(), $params);
  103. $rows = V::get('rows', array(), $params);
  104. $caption = V::get('caption', '', $params);
  105. $showLp = (!V::get('disable_lp', false, $params));
  106. if (empty($cols) && !empty($rows)) {
  107. $firstRow = array();
  108. foreach ($rows as $row) {
  109. $firstRow = $row;
  110. break;
  111. }
  112. $cols = array_keys((array)$firstRow);
  113. }
  114. // if (empty($cols)) return;
  115. $hiddenCols = V::get('hidden_cols', array(), $params);
  116. $html_id = V::get('__html_id', '', $params);
  117. ?>
  118. <table class="table table-bordered table-hover" <?php echo ($html_id)? 'id="' . $html_id . '"' : ''; ?>>
  119. <?php if ($caption) : ?>
  120. <caption><?php echo $caption; ?></caption>
  121. <?php endif; ?>
  122. <thead>
  123. <tr>
  124. <?php if ($showLp) : ?>
  125. <th style="padding:2px">Lp.</th>
  126. <?php endif; ?>
  127. <?php foreach ($cols as $colName) : ?>
  128. <?php if (in_array($colName, $hiddenCols)) continue; ?>
  129. <th style="padding:2px"><?php echo $colName; ?></th>
  130. <?php endforeach; ?>
  131. </tr>
  132. </thead>
  133. <tbody>
  134. <?php $i = 0; foreach ($rows as $row) : $i++; ?>
  135. <tr <?php echo (!empty($row['__js_on_click']))? 'onClick="' . $row['__js_on_click'] . '"' : ''; ?>>
  136. <?php if ($showLp) : ?>
  137. <td style="padding:2px; color:#ccc"><?php echo $i; ?></td>
  138. <?php endif; ?>
  139. <?php foreach ($cols as $colName) : ?>
  140. <?php if (in_array($colName, $hiddenCols)) continue; ?>
  141. <td style="padding:2px"><?php echo V::get($colName, '', $row); ?></td>
  142. <?php endforeach; ?>
  143. </tr>
  144. <?php endforeach; ?>
  145. </tbody>
  146. </table>
  147. <?php
  148. }
  149. public static function startContainer($attrs = array()) {
  150. // echo '<div class="container">' . "\n";
  151. if (!empty($attrs['class'])) $attrs['class'] .= ' container';
  152. $attrs['class'] = ' container';
  153. self::startTag('div', $attrs);
  154. }
  155. public static function endContainer() { echo '</div>' . "\n"; }
  156. public static function startTag($tag, $attrs = array()) {
  157. $outAttrs = '';
  158. if (is_array($attrs)) {
  159. foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\"";
  160. }
  161. echo '<' . $tag . $outAttrs . '>';
  162. }
  163. public static function endTag($tag) { echo '</' . $tag . '>'; }
  164. public static function tag($tag, $attrs = array(), $childrens = array()) {
  165. self::startTag($tag, $attrs);
  166. if (!empty($childrens) && is_array($childrens)) throw new Exception("UI::tag() children as nodes not implemented".json_encode($childrens));
  167. if (is_scalar($childrens)) echo $childrens;
  168. self::endTag($tag);
  169. }
  170. public static function jsAjaxTable($params) {
  171. }
  172. public static function price($value) {
  173. // TODO: if not number type - string wwith wrong format - try to convert?
  174. return number_format($value, 2, ',', ' ');
  175. }
  176. }