menu.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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) 2008 - 2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (permission_exists('menu_view')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //connect to the database
  33. $database = new database;
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //set additional variables
  38. $search = $_GET["search"] ?? '';
  39. //set from session variables
  40. $list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false';
  41. $button_icon_add = !empty($_SESSION['theme']['button_icon_add']) ? $_SESSION['theme']['button_icon_add'] : '';
  42. //get the http post data
  43. if (!empty($_POST['menus'])) {
  44. $action = $_POST['action'] ?? '';
  45. $search = $_POST['search'] ?? '';
  46. $menus = $_POST['menus'] ?? '';
  47. }
  48. //process the http post data by action
  49. if (!empty($action) && !empty($menus)) {
  50. switch ($action) {
  51. case 'delete':
  52. if (permission_exists('menu_delete')) {
  53. $obj = new menu;
  54. $obj->delete($menus);
  55. }
  56. break;
  57. }
  58. header('Location: menu.php'.(!empty($search) ? '?search='.urlencode($search) : null));
  59. exit;
  60. }
  61. //get order and order by
  62. $order_by = $_GET["order_by"] ?? '';
  63. $order = $_GET["order"] ?? '';
  64. //add the search string
  65. if (!empty($_GET["search"])) {
  66. $search = strtolower($_GET["search"]);
  67. $sql_search = " (";
  68. $sql_search .= " lower(menu_name) like :search ";
  69. $sql_search .= " or lower(menu_language) like :search ";
  70. $sql_search .= " or lower(menu_description) like :search ";
  71. $sql_search .= ") ";
  72. $parameters['search'] = '%'.$search.'%';
  73. }
  74. //get the count
  75. $sql = "select count(menu_uuid) from v_menus ";
  76. if (isset($sql_search)) {
  77. $sql .= "where ".$sql_search;
  78. }
  79. $num_rows = $database->select($sql, $parameters ?? '', 'column');
  80. //get the list
  81. $sql = str_replace('count(menu_uuid)', '*', $sql);
  82. $sql .= order_by($order_by, $order, 'menu_name', 'asc');
  83. $sql .= limit_offset($rows_per_page ?? '', $offset ?? '');
  84. $menus = $database->select($sql, $parameters ?? '', 'all');
  85. unset($sql, $parameters);
  86. //create token
  87. $object = new token;
  88. $token = $object->create($_SERVER['PHP_SELF']);
  89. //include the header
  90. $document['title'] = $text['title-menus'];
  91. require_once "resources/header.php";
  92. //show the content
  93. echo "<div class='action_bar' id='action_bar'>\n";
  94. echo " <div class='heading'><b>".$text['title-menus']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
  95. echo " <div class='actions'>\n";
  96. if (permission_exists('menu_add')) {
  97. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'menu_edit.php']);
  98. }
  99. if (permission_exists('menu_delete') && $menus) {
  100. 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');"]);
  101. }
  102. echo "<form id='form_search' class='inline' method='get'>\n";
  103. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  104. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  105. //echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'menu.php','style'=>($search == '' ? 'display: none;' : null)]);
  106. if (!empty($paging_controls_mini)) {
  107. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  108. }
  109. echo " </form>\n";
  110. echo " </div>\n";
  111. echo " <div style='clear: both;'></div>\n";
  112. echo "</div>\n";
  113. if (permission_exists('menu_delete') && $menus) {
  114. 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');"])]);
  115. }
  116. echo $text['description-menus']."\n";
  117. echo "<br /><br />\n";
  118. echo "<form id='form_list' method='post'>\n";
  119. echo "<input type='hidden' id='action' name='action' value=''>\n";
  120. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  121. echo "<div class='card'>\n";
  122. echo "<table class='list'>\n";
  123. echo "<tr class='list-header'>\n";
  124. if (permission_exists('menu_add') || permission_exists('menu_edit') || permission_exists('menu_delete')) {
  125. echo " <th class='checkbox'>\n";
  126. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($menus) ?: "style='visibility: hidden;'").">\n";
  127. echo " </th>\n";
  128. }
  129. echo th_order_by('menu_name', $text['label-menu_name'], $order_by, $order);
  130. echo th_order_by('menu_language', $text['label-menu_language'], $order_by, $order);
  131. echo " <th class='hide-sm-dn'>".$text['label-menu_description']."</th>\n";
  132. if (permission_exists('menu_edit') && $list_row_edit_button == 'true') {
  133. echo " <td class='action-button'>&nbsp;</td>\n";
  134. }
  135. echo "</tr>\n";
  136. if (!empty($menus)) {
  137. $x = 0;
  138. foreach ($menus as $row) {
  139. if (permission_exists('menu_edit')) {
  140. $list_row_url = "menu_edit.php?id=".urlencode($row['menu_uuid']);
  141. }
  142. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  143. if (permission_exists('menu_add') || permission_exists('menu_edit') || permission_exists('menu_delete')) {
  144. echo " <td class='checkbox'>\n";
  145. echo " <input type='checkbox' name='menus[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  146. echo " <input type='hidden' name='menus[$x][uuid]' value='".escape($row['menu_uuid'])."' />\n";
  147. echo " </td>\n";
  148. }
  149. echo " <td>\n";
  150. if (permission_exists('menu_edit')) {
  151. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['menu_name'])."</a>\n";
  152. }
  153. else {
  154. echo " ".escape($row['menu_name']);
  155. }
  156. echo " </td>\n";
  157. echo " <td>".escape($row['menu_language'])."</td>\n";
  158. echo " <td class='description overflow hide-sm-dn'>".escape($row['menu_description'])."</td>\n";
  159. if (permission_exists('menu_edit') && $list_row_edit_button == 'true') {
  160. echo " <td class='action-button'>\n";
  161. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$button_icon_edit,'link'=>$list_row_url]);
  162. echo " </td>\n";
  163. }
  164. echo "</tr>\n";
  165. $x++;
  166. }
  167. unset($menus);
  168. }
  169. echo "</table>\n";
  170. echo "</div>\n";
  171. echo "<br />\n";
  172. echo "<div align='center'>".!empty($paging_controls)."</div>\n";
  173. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  174. echo "</form>\n";
  175. //include the footer
  176. require_once "resources/footer.php";
  177. ?>