dashboard.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2021-2024
  17. the Initial Developer. All Rights Reserved.
  18. */
  19. //includes files
  20. require_once dirname(__DIR__, 2) . "/resources/require.php";
  21. require_once "resources/check_auth.php";
  22. //check permissions
  23. if (permission_exists('dashboard_view')) {
  24. //access granted
  25. }
  26. else {
  27. echo "access denied";
  28. exit;
  29. }
  30. //add multi-lingual support
  31. $language = new text;
  32. $text = $language->get();
  33. //get the http post data
  34. if (!empty($_POST['dashboard'])) {
  35. $action = $_POST['action'];
  36. $search = $_POST['search'];
  37. $dashboard = $_POST['dashboard'];
  38. }
  39. //process the http post data by action
  40. if (!empty($action) && is_array($dashboard) && @sizeof($dashboard) != 0) {
  41. switch ($action) {
  42. case 'copy':
  43. if (permission_exists('dashboard_add')) {
  44. $obj = new dashboard;
  45. $obj->copy($dashboard);
  46. }
  47. break;
  48. case 'toggle':
  49. if (permission_exists('dashboard_edit')) {
  50. $obj = new dashboard;
  51. $obj->toggle($dashboard);
  52. }
  53. break;
  54. case 'delete':
  55. if (permission_exists('dashboard_delete')) {
  56. $obj = new dashboard;
  57. $obj->delete($dashboard);
  58. }
  59. break;
  60. }
  61. //redirect the user
  62. header('Location: dashboard.php'.($search != '' ? '?search='.urlencode($search) : null));
  63. exit;
  64. }
  65. //get order and order by
  66. $order_by = $_GET["order_by"] ?? null;
  67. $order = $_GET["order"] ?? null;
  68. //add the search
  69. if (isset($_GET["search"])) {
  70. $search = strtolower($_GET["search"]);
  71. }
  72. //get the count
  73. $sql = "select count(dashboard_uuid) ";
  74. $sql .= "from v_dashboard ";
  75. if (isset($search)) {
  76. $sql .= "where (\n";
  77. $sql .= " dashboard_name = :search \n";
  78. $sql .= " or dashboard_description = :search \n";
  79. $sql .= ")\n";
  80. $parameters['search'] = '%'.$search.'%';
  81. }
  82. $database = new database;
  83. $num_rows = $database->select($sql, $parameters ?? null, 'column');
  84. unset($sql, $parameters);
  85. //get the list
  86. $sql = "select \n";
  87. $sql .= "dashboard_uuid, \n";
  88. $sql .= "dashboard_name, \n";
  89. $sql .= "dashboard_icon, \n";
  90. $sql .= "( \n";
  91. $sql .= " select \n";
  92. $sql .= " string_agg(g.group_name, ', ') \n";
  93. $sql .= " from \n";
  94. $sql .= " v_dashboard_groups as dg, \n";
  95. $sql .= " v_groups as g \n";
  96. $sql .= " where \n";
  97. $sql .= " dg.group_uuid = g.group_uuid \n";
  98. $sql .= " and d.dashboard_uuid = dg.dashboard_uuid \n";
  99. $sql .= ") AS dashboard_groups, \n";
  100. $sql .= "dashboard_order, \n";
  101. $sql .= "cast(dashboard_enabled as text), \n";
  102. $sql .= "dashboard_description \n";
  103. $sql .= "from v_dashboard as d \n";
  104. if (isset($_GET["search"])) {
  105. $sql .= "where (\n";
  106. $sql .= " lower(dashboard_name) like :search \n";
  107. $sql .= " or lower(dashboard_description) like :search \n";
  108. $sql .= ")\n";
  109. $parameters['search'] = '%'.strtolower($search).'%';
  110. }
  111. $sql .= order_by($order_by, $order, 'dashboard_order, dashboard_name', 'asc');
  112. $sql .= limit_offset($rows_per_page ?? null, $offset ?? null);
  113. $database = new database;
  114. $dashboard = $database->select($sql, $parameters ?? null, 'all');
  115. unset($sql, $parameters);
  116. //create token
  117. $object = new token;
  118. $token = $object->create($_SERVER['PHP_SELF']);
  119. //additional includes
  120. $document['title'] = $text['title-dashboard'];
  121. require_once "resources/header.php";
  122. //show the content
  123. echo "<div class='action_bar' id='action_bar'>\n";
  124. echo " <div class='heading'><b>".$text['title-dashboard']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
  125. echo " <div class='actions'>\n";
  126. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','name'=>'btn_back','style'=>'margin-right: 15px;','link'=>'index.php']);
  127. if (permission_exists('dashboard_add')) {
  128. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'dashboard_edit.php']);
  129. }
  130. if (permission_exists('dashboard_add') && !empty($dashboard)) {
  131. echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
  132. }
  133. if (permission_exists('dashboard_edit') && !empty($dashboard)) {
  134. echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]);
  135. }
  136. if (permission_exists('dashboard_delete') && !empty($dashboard)) {
  137. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  138. }
  139. echo "<form id='form_search' class='inline' method='get'>\n";
  140. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search ?? '')."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  141. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  142. //echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'dashboard.php','style'=>($search == '' ? 'display: none;' : null)]);
  143. if (!empty($paging_controls_mini)) {
  144. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  145. }
  146. echo " </form>\n";
  147. echo " </div>\n";
  148. echo " <div style='clear: both;'></div>\n";
  149. echo "</div>\n";
  150. if (permission_exists('dashboard_add') && !empty($dashboard)) {
  151. echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
  152. }
  153. if (permission_exists('dashboard_edit') && !empty($dashboard)) {
  154. echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]);
  155. }
  156. if (permission_exists('dashboard_delete') && !empty($dashboard)) {
  157. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
  158. }
  159. echo "<form id='form_list' method='post'>\n";
  160. echo "<input type='hidden' id='action' name='action' value=''>\n";
  161. echo "<input type='hidden' name='search' value=\"".escape($search ?? '')."\">\n";
  162. echo "<div class='card'>\n";
  163. echo "<table class='list'>\n";
  164. echo "<tr class='list-header'>\n";
  165. if (permission_exists('dashboard_add') || permission_exists('dashboard_edit') || permission_exists('dashboard_delete')) {
  166. echo " <th class='checkbox'>\n";
  167. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($dashboard) ?: "style='visibility: hidden;'").">\n";
  168. echo " </th>\n";
  169. }
  170. echo th_order_by('dashboard_name', $text['label-dashboard_name'], $order_by, $order);
  171. echo th_order_by('dashboard_groups', $text['label-dashboard_groups'], $order_by, $order);
  172. echo th_order_by('dashboard_icon', $text['label-icons'], $order_by, $order);
  173. echo th_order_by('dashboard_order', $text['label-dashboard_order'], $order_by, $order);
  174. echo th_order_by('dashboard_enabled', $text['label-dashboard_enabled'], $order_by, $order, null, "class='center'");
  175. echo " <th class='hide-sm-dn'>".$text['label-dashboard_description']."</th>\n";
  176. if (permission_exists('dashboard_edit') && isset($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  177. echo " <td class='action-button'>&nbsp;</td>\n";
  178. }
  179. echo "</tr>\n";
  180. if (!empty($dashboard)) {
  181. $x = 0;
  182. foreach ($dashboard as $row) {
  183. if (permission_exists('dashboard_edit')) {
  184. $list_row_url = "dashboard_edit.php?id=".urlencode($row['dashboard_uuid']);
  185. }
  186. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  187. if (permission_exists('dashboard_add') || permission_exists('dashboard_edit') || permission_exists('dashboard_delete')) {
  188. echo " <td class='checkbox'>\n";
  189. echo " <input type='checkbox' name='dashboard[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  190. echo " <input type='hidden' name='dashboard[$x][dashboard_uuid]' value='".escape($row['dashboard_uuid'])."' />\n";
  191. echo " </td>\n";
  192. }
  193. echo " <td>\n";
  194. if (permission_exists('dashboard_edit')) {
  195. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['dashboard_name'])."</a>\n";
  196. }
  197. else {
  198. echo " ".escape($row['dashboard_name']);
  199. }
  200. echo " </td>\n";
  201. echo " <td>".escape($row['dashboard_groups'])."</td>\n";
  202. echo " <td>".escape($row['dashboard_icon'])."</td>\n";
  203. echo " <td>".escape($row['dashboard_order'])."</td>\n";
  204. if (permission_exists('dashboard_edit')) {
  205. echo " <td class='no-link center'>\n";
  206. echo " <input type='hidden' name='number_translations[$x][dashboard_enabled]' value='".escape($row['dashboard_enabled'])."' />\n";
  207. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.($row['dashboard_enabled']?:'false')],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  208. }
  209. else {
  210. echo " <td class='center'>\n";
  211. echo $text['label-'.($row['dashboard_enabled']?:'false')];
  212. }
  213. echo " </td>\n";
  214. echo " <td class='description overflow hide-sm-dn'>".escape($row['dashboard_description'])."</td>\n";
  215. if (permission_exists('dashboard_edit') && isset($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  216. echo " <td class='action-button'>\n";
  217. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  218. echo " </td>\n";
  219. }
  220. echo "</tr>\n";
  221. $x++;
  222. }
  223. unset($dashboard);
  224. }
  225. echo "</table>\n";
  226. echo "</div>\n";
  227. echo "<br />\n";
  228. echo "<div align='center'>".($paging_controls ?? '')."</div>\n";
  229. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  230. echo "</form>\n";
  231. //include the footer
  232. require_once "resources/footer.php";
  233. ?>