UI.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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) {
  75. ?>
  76. <div class="alert alert-<?php echo $alertType; ?>">
  77. <?php echo $msg; ?>
  78. </div>
  79. <?php
  80. }
  81. public static function setTitleJsTag($title) {
  82. ?>
  83. <script>
  84. document.title = '<?php echo $title; ?>';
  85. </script>
  86. <?php
  87. }
  88. /**
  89. * $params - Array
  90. * $params['caption'] (optional) -> <caption>...</caption>
  91. * $params['cols'] (optional) -> cols, if not set read from first row
  92. * $params['rows'] -> rows, if not set - empty table
  93. * $params['rows'] -> rows, if not set - empty table
  94. * $params['disable_lp'] -> disable lp. col
  95. */
  96. public static function table($params) {
  97. $cols = V::get('cols', array(), $params);
  98. $rows = V::get('rows', array(), $params);
  99. $caption = V::get('caption', '', $params);
  100. $showLp = (!V::get('disable_lp', false, $params));
  101. if (empty($cols) && !empty($rows)) {
  102. $firstRow = array();
  103. foreach ($rows as $row) {
  104. $firstRow = $row;
  105. break;
  106. }
  107. $cols = array_keys((array)$firstRow);
  108. }
  109. // if (empty($cols)) return;
  110. $hiddenCols = V::get('hidden_cols', array(), $params);
  111. $html_id = V::get('__html_id', '', $params);
  112. ?>
  113. <table class="table table-bordered table-hover" <?php echo ($html_id)? 'id="' . $html_id . '"' : ''; ?>>
  114. <?php if ($caption) : ?>
  115. <caption><?php echo $caption; ?></caption>
  116. <?php endif; ?>
  117. <thead>
  118. <tr>
  119. <?php if ($showLp) : ?>
  120. <th style="padding:2px">Lp.</th>
  121. <?php endif; ?>
  122. <?php foreach ($cols as $colName) : ?>
  123. <?php if (in_array($colName, $hiddenCols)) continue; ?>
  124. <th style="padding:2px"><?php echo $colName; ?></th>
  125. <?php endforeach; ?>
  126. </tr>
  127. </thead>
  128. <tbody>
  129. <?php $i = 0; foreach ($rows as $row) : $i++; ?>
  130. <tr <?php echo (!empty($row['__js_on_click']))? 'onClick="' . $row['__js_on_click'] . '"' : ''; ?>>
  131. <?php if ($showLp) : ?>
  132. <td style="padding:2px; color:#ccc"><?php echo $i; ?></td>
  133. <?php endif; ?>
  134. <?php foreach ($cols as $colName) : ?>
  135. <?php if (in_array($colName, $hiddenCols)) continue; ?>
  136. <td style="padding:2px"><?php echo V::get($colName, '', $row); ?></td>
  137. <?php endforeach; ?>
  138. </tr>
  139. <?php endforeach; ?>
  140. </tbody>
  141. </table>
  142. <?php
  143. }
  144. public static function startContainer() { echo '<div class="container">' . "\n"; }
  145. public static function endContainer() { echo '</div>' . "\n"; }
  146. public static function startTag($tag, $attrs = array()) {
  147. $outAttrs = '';
  148. foreach ($attrs as $attrName => $val) $outAttrs .= " {$attrName}=\"{$val}\"";
  149. echo '<' . $tag . $outAttrs . '>';
  150. }
  151. public static function endTag($tag) { echo '</' . $tag . '>'; }
  152. public static function jsAjaxTable($params) {
  153. }
  154. public static function price($value) {
  155. // TODO: if not number type - string wwith wrong format - try to convert?
  156. return number_format($value, 2, ',', ' ');
  157. }
  158. }