menu.php 7.7 KB

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