dashboard.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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-2023
  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. //action add or update
  73. // if (isset($_REQUEST["export"])) {
  74. // $export = $_REQUEST["export"];
  75. // }
  76. //
  77. //expore settings
  78. // if (isset($export) && $export == 'true') {
  79. //
  80. // //get the dashboard
  81. // $sql = "select ";
  82. // $sql .= "dashboard_uuid, ";
  83. // $sql .= "dashboard_name, ";
  84. // $sql .= "dashboard_path, ";
  85. // $sql .= "dashboard_order, ";
  86. // $sql .= "cast(dashboard_enabled as text), ";
  87. // $sql .= "dashboard_description ";
  88. // $sql .= "from v_dashboard ";
  89. // $database = new database;
  90. // $dashboard_widgets = $database->select($sql, $parameters, 'all');
  91. // unset($sql, $parameters);
  92. //
  93. // //prepare the array
  94. // if (is_array($dashboard_widgets)) {
  95. // $x = 0;
  96. // $y = 0;
  97. // foreach ($dashboard_widgets as $row) {
  98. // //add to the array
  99. // $array['dashboard'][$x]['dashboard_uuid'] = $row["dashboard_uuid"];
  100. // $array['dashboard'][$x]['dashboard_name'] = $row["dashboard_name"];
  101. // $array['dashboard'][$x]['dashboard_path'] = $row["dashboard_path"];
  102. // $array['dashboard'][$x]['dashboard_order'] = $row["dashboard_order"];
  103. // $array['dashboard'][$x]['dashboard_enabled'] = $row["dashboard_enabled"] ?? 'false';
  104. // $array['dashboard'][$x]['dashboard_description'] = $row["dashboard_description"];
  105. //
  106. // //get the dashboard groups
  107. // $sql = "select ";
  108. // $sql .= "dashboard_group_uuid, ";
  109. // $sql .= "dashboard_uuid, ";
  110. // $sql .= "group_uuid, ";
  111. // $sql .= "(select group_name from v_groups where v_dashboard_groups.group_uuid = group_uuid) as group_name ";
  112. // $sql .= "from v_dashboard_groups ";
  113. // $sql .= "where dashboard_uuid = :dashboard_uuid ";
  114. // $parameters['dashboard_uuid'] = $row["dashboard_uuid"];
  115. // $database = new database;
  116. // $dashboard_groups = $database->select($sql, $parameters, 'all');
  117. // unset($sql, $parameters);
  118. // if (is_array($dashboard_groups)) {
  119. // $y = 0;
  120. // foreach ($dashboard_groups as $row) {
  121. // $array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = $row["dashboard_group_uuid"];
  122. // $array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = $row["dashboard_uuid"];
  123. // //$array['dashboard'][$x]['dashboard_groups'][$y]['group_uuid'] = $row["group_uuid"];
  124. // $array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = $row["group_name"];
  125. // $y++;
  126. // }
  127. // }
  128. //
  129. // $x++;
  130. // }
  131. // }
  132. //
  133. // //write the code
  134. // echo "<textarea style=\"width: 100%; max-width: 100%; height: 100%; max-height: 100%;\">\n";
  135. // if (is_array($array['dashboard'])) {
  136. // echo "\n\n\n";
  137. // //echo "\$x = 0;\n";
  138. // foreach ($array['dashboard'] as $row) {
  139. // foreach ($row as $key => $value) {
  140. // if (is_array($value)) {
  141. // echo "\$y = 0;\n";
  142. // $count = count($value);
  143. // $i = 1;
  144. // foreach ($value as $row) {
  145. // foreach ($row as $key => $value) {
  146. // echo "\$array['dashboard'][\$x]['dashboard_groups'][\$y]['{$key}'] = '{$value}';\n";
  147. // }
  148. // if ($i < $count) {
  149. // echo "\$y++;\n";
  150. // }
  151. // else {
  152. // echo "\n\n---------------------------\n\n\n";
  153. // }
  154. // $i++;
  155. // }
  156. // }
  157. // else {
  158. // echo "\$array['dashboard'][\$x]['{$key}'] = '{$value}';\n";
  159. // }
  160. // }
  161. // }
  162. // }
  163. //
  164. // echo "</textarea>\n";
  165. // exit;
  166. // }
  167. //get the count
  168. $sql = "select count(dashboard_uuid) ";
  169. $sql .= "from v_dashboard ";
  170. if (isset($search)) {
  171. $sql .= "where (\n";
  172. $sql .= " dashboard_name = :search \n";
  173. $sql .= " or dashboard_description = :search \n";
  174. $sql .= ")\n";
  175. $parameters['search'] = '%'.$search.'%';
  176. }
  177. $database = new database;
  178. $num_rows = $database->select($sql, $parameters ?? null, 'column');
  179. unset($sql, $parameters);
  180. //get the list
  181. $sql = "select \n";
  182. $sql .= "dashboard_uuid, \n";
  183. $sql .= "dashboard_name,\n";
  184. $sql .= "( \n";
  185. $sql .= " select \n";
  186. $sql .= " string_agg(g.group_name, ', ') \n";
  187. $sql .= " from \n";
  188. $sql .= " v_dashboard_groups as dg, \n";
  189. $sql .= " v_groups as g \n";
  190. $sql .= " where \n";
  191. $sql .= " dg.group_uuid = g.group_uuid \n";
  192. $sql .= " and d.dashboard_uuid = dg.dashboard_uuid \n";
  193. $sql .= ") AS dashboard_groups, \n";
  194. $sql .= "dashboard_order, \n";
  195. $sql .= "cast(dashboard_enabled as text), \n";
  196. $sql .= "dashboard_description \n";
  197. $sql .= "from v_dashboard as d \n";
  198. if (isset($_GET["search"])) {
  199. $sql .= "where (\n";
  200. $sql .= " lower(dashboard_name) like :search \n";
  201. $sql .= " or lower(dashboard_description) like :search \n";
  202. $sql .= ")\n";
  203. $parameters['search'] = '%'.strtolower($search).'%';
  204. }
  205. $sql .= order_by($order_by, $order, 'dashboard_order, dashboard_name', 'asc');
  206. $sql .= limit_offset($rows_per_page ?? null, $offset ?? null);
  207. $database = new database;
  208. $dashboard = $database->select($sql, $parameters ?? null, 'all');
  209. unset($sql, $parameters);
  210. //create token
  211. $object = new token;
  212. $token = $object->create($_SERVER['PHP_SELF']);
  213. //additional includes
  214. $document['title'] = $text['title-dashboard'];
  215. require_once "resources/header.php";
  216. //show the content
  217. echo "<div class='action_bar' id='action_bar'>\n";
  218. echo " <div class='heading'><b>".$text['title-dashboard']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
  219. echo " <div class='actions'>\n";
  220. 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']);
  221. if (permission_exists('dashboard_add')) {
  222. 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']);
  223. }
  224. if (permission_exists('dashboard_add') && !empty($dashboard)) {
  225. 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');"]);
  226. }
  227. if (permission_exists('dashboard_edit') && !empty($dashboard)) {
  228. 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');"]);
  229. }
  230. if (permission_exists('dashboard_delete') && !empty($dashboard)) {
  231. 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');"]);
  232. }
  233. echo "<form id='form_search' class='inline' method='get'>\n";
  234. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search ?? '')."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  235. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  236. //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)]);
  237. if (!empty($paging_controls_mini)) {
  238. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  239. }
  240. echo " </form>\n";
  241. echo " </div>\n";
  242. echo " <div style='clear: both;'></div>\n";
  243. echo "</div>\n";
  244. if (permission_exists('dashboard_add') && !empty($dashboard)) {
  245. 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');"])]);
  246. }
  247. if (permission_exists('dashboard_edit') && !empty($dashboard)) {
  248. 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');"])]);
  249. }
  250. if (permission_exists('dashboard_delete') && !empty($dashboard)) {
  251. 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');"])]);
  252. }
  253. echo "<form id='form_list' method='post'>\n";
  254. echo "<input type='hidden' id='action' name='action' value=''>\n";
  255. echo "<input type='hidden' name='search' value=\"".escape($search ?? '')."\">\n";
  256. echo "<div class='card'>\n";
  257. echo "<table class='list'>\n";
  258. echo "<tr class='list-header'>\n";
  259. if (permission_exists('dashboard_add') || permission_exists('dashboard_edit') || permission_exists('dashboard_delete')) {
  260. echo " <th class='checkbox'>\n";
  261. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($dashboard) ?: "style='visibility: hidden;'").">\n";
  262. echo " </th>\n";
  263. }
  264. echo th_order_by('dashboard_name', $text['label-dashboard_name'], $order_by, $order);
  265. echo th_order_by('dashboard_groups', $text['label-dashboard_groups'], $order_by, $order);
  266. echo th_order_by('dashboard_order', $text['label-dashboard_order'], $order_by, $order);
  267. echo th_order_by('dashboard_enabled', $text['label-dashboard_enabled'], $order_by, $order, null, "class='center'");
  268. echo " <th class='hide-sm-dn'>".$text['label-dashboard_description']."</th>\n";
  269. if (permission_exists('dashboard_edit') && isset($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  270. echo " <td class='action-button'>&nbsp;</td>\n";
  271. }
  272. echo "</tr>\n";
  273. if (!empty($dashboard)) {
  274. $x = 0;
  275. foreach ($dashboard as $row) {
  276. if (permission_exists('dashboard_edit')) {
  277. $list_row_url = "dashboard_edit.php?id=".urlencode($row['dashboard_uuid']);
  278. }
  279. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  280. if (permission_exists('dashboard_add') || permission_exists('dashboard_edit') || permission_exists('dashboard_delete')) {
  281. echo " <td class='checkbox'>\n";
  282. 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";
  283. echo " <input type='hidden' name='dashboard[$x][dashboard_uuid]' value='".escape($row['dashboard_uuid'])."' />\n";
  284. echo " </td>\n";
  285. }
  286. echo " <td>\n";
  287. if (permission_exists('dashboard_edit')) {
  288. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['dashboard_name'])."</a>\n";
  289. }
  290. else {
  291. echo " ".escape($row['dashboard_name']);
  292. }
  293. echo " </td>\n";
  294. echo " <td>".escape($row['dashboard_groups'])."</td>\n";
  295. echo " <td>".escape($row['dashboard_order'])."</td>\n";
  296. if (permission_exists('dashboard_edit')) {
  297. echo " <td class='no-link center'>\n";
  298. echo " <input type='hidden' name='number_translations[$x][dashboard_enabled]' value='".escape($row['dashboard_enabled'])."' />\n";
  299. 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')"]);
  300. }
  301. else {
  302. echo " <td class='center'>\n";
  303. echo $text['label-'.($row['dashboard_enabled']?:'false')];
  304. }
  305. echo " </td>\n";
  306. echo " <td class='description overflow hide-sm-dn'>".escape($row['dashboard_description'])."</td>\n";
  307. if (permission_exists('dashboard_edit') && isset($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  308. echo " <td class='action-button'>\n";
  309. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  310. echo " </td>\n";
  311. }
  312. echo "</tr>\n";
  313. $x++;
  314. }
  315. unset($dashboard);
  316. }
  317. echo "</table>\n";
  318. echo "</div>\n";
  319. echo "<br />\n";
  320. echo "<div align='center'>".($paging_controls ?? '')."</div>\n";
  321. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  322. echo "</form>\n";
  323. //include the footer
  324. require_once "resources/footer.php";
  325. ?>