UI.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 endHtml() {
  23. $version = (file_exists(APP_PATH_ROOT . '/VERSION'))? file_get_contents(APP_PATH_ROOT . '/VERSION') : null;
  24. if ($version) {
  25. echo '<div style="border-top:1px solid #ddd;margin-top:10px;padding:0 30px;font-size:xx-small;color:#888;">version: '.$version.'</div>';
  26. }
  27. echo "\n</body></html>";
  28. }
  29. public static function menu() {
  30. if (!User::logged()) return;
  31. if (User::hasAccess('menu')) {
  32. Lib::loadClass('ProcesMenu');
  33. $procesMenu = ProcesMenu::getInstance();
  34. $procesMenu->show();
  35. if (!V::get('MENU_INIT', '', $_GET)) {
  36. Lib::loadClass('UserActivity');
  37. //echo UserActivity::showListInContainer();
  38. }
  39. }
  40. else {
  41. UI::loadTemplate('menuLevel6');
  42. }
  43. }
  44. public static function loadTemplate($tmplName, $data = array()) {
  45. if (is_array($data) && !empty($data)) {
  46. extract($data);
  47. }
  48. include APP_PATH_LIB . "/tmpl/{$tmplName}.php";
  49. }
  50. public static function hotKeyDBG($str) {
  51. if (User::hasAccess('dbg')) {
  52. echo '<span class="hidden-dbg">' . htmlspecialchars($str) . '</span>';
  53. }
  54. }
  55. public static function showMessagesForTable($tblName) {
  56. if (empty($tblName)) return;
  57. $msgsRoute = Router::getRoute('Msgs');
  58. $msgs = $msgsRoute->getActiveMessagesForTable($tblName);
  59. if (!empty($msgs)) {
  60. self::loadTemplate('msgsForTable', array('msgs' => $msgs));
  61. }
  62. }
  63. public static function alert($alertType, $msg) {
  64. ?>
  65. <div class="alert alert-<?php echo $alertType; ?>">
  66. <?php echo $msg; ?>
  67. </div>
  68. <?php
  69. }
  70. public static function setTitleJsTag($title) {
  71. ?>
  72. <script>
  73. document.title = '<?php echo $title; ?>';
  74. </script>
  75. <?php
  76. }
  77. /**
  78. * $params - Array
  79. * $params['caption'] (optional) -> <caption>...</caption>
  80. * $params['cols'] (optional) -> cols, if not set read from first row
  81. * $params['rows'] -> rows, if not set - empty table
  82. * $params['rows'] -> rows, if not set - empty table
  83. * $params['disable_lp'] -> disable lp. col
  84. */
  85. public static function table($params) {
  86. $cols = V::get('cols', array(), $params);
  87. $rows = V::get('rows', array(), $params);
  88. $caption = V::get('caption', '', $params);
  89. $showLp = (!V::get('disable_lp', false, $params));
  90. if (empty($cols) && !empty($rows)) {
  91. $firstRow = array();
  92. foreach ($rows as $row) {
  93. $firstRow = $row;
  94. break;
  95. }
  96. $cols = array_keys((array)$firstRow);
  97. }
  98. // if (empty($cols)) return;
  99. $hiddenCols = V::get('hidden_cols', array(), $params);
  100. $html_id = V::get('__html_id', '', $params);
  101. ?>
  102. <table class="table table-bordered table-hover" <?php echo ($html_id)? 'id="' . $html_id . '"' : ''; ?>>
  103. <?php if ($caption) : ?>
  104. <caption><?php echo $caption; ?></caption>
  105. <?php endif; ?>
  106. <thead>
  107. <tr>
  108. <?php if ($showLp) : ?>
  109. <th style="padding:2px">Lp.</th>
  110. <?php endif; ?>
  111. <?php foreach ($cols as $colName) : ?>
  112. <?php if (in_array($colName, $hiddenCols)) continue; ?>
  113. <th style="padding:2px"><?php echo $colName; ?></th>
  114. <?php endforeach; ?>
  115. </tr>
  116. </thead>
  117. <tbody>
  118. <?php $i = 0; foreach ($rows as $row) : $i++; ?>
  119. <tr <?php echo (!empty($row['__js_on_click']))? 'onClick="' . $row['__js_on_click'] . '"' : ''; ?>>
  120. <?php if ($showLp) : ?>
  121. <td style="padding:2px; color:#ccc"><?php echo $i; ?></td>
  122. <?php endif; ?>
  123. <?php foreach ($cols as $colName) : ?>
  124. <?php if (in_array($colName, $hiddenCols)) continue; ?>
  125. <td style="padding:2px"><?php echo V::get($colName, '', $row); ?></td>
  126. <?php endforeach; ?>
  127. </tr>
  128. <?php endforeach; ?>
  129. </tbody>
  130. </table>
  131. <?php
  132. }
  133. public static function jsAjaxTable($params) {
  134. }
  135. public static function price($value) {
  136. // TODO: if not number type - string wwith wrong format - try to convert?
  137. return number_format($value, 2, ',', ' ');
  138. }
  139. }