Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
11 KiB

2 years ago
  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 <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. require_once "resources/paging.php";
  26. //check permissions
  27. if (permission_exists('var_view')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //get posted data
  38. if (is_array($_POST['vars'])) {
  39. $action = $_POST['action'];
  40. $search = $_POST['search'];
  41. $vars = $_POST['vars'];
  42. }
  43. //process the http post data by action
  44. if ($action != '' && is_array($vars) && @sizeof($vars) != 0) {
  45. switch ($action) {
  46. case 'copy':
  47. if (permission_exists('var_add')) {
  48. $obj = new vars;
  49. $obj->copy($vars);
  50. }
  51. break;
  52. case 'toggle':
  53. if (permission_exists('var_edit')) {
  54. $obj = new vars;
  55. $obj->toggle($vars);
  56. }
  57. break;
  58. case 'delete':
  59. if (permission_exists('var_delete')) {
  60. $obj = new vars;
  61. $obj->delete($vars);
  62. }
  63. break;
  64. }
  65. header('Location: vars.php'.($search != '' ? '?search='.urlencode($search) : null));
  66. exit;
  67. }
  68. //get order and order by
  69. $order_by = $_GET["order_by"];
  70. $order = $_GET["order"];
  71. //add the search string
  72. $search = strtolower($_GET["search"]);
  73. if (strlen($search) > 0) {
  74. $sql_search = "where (";
  75. $sql_search .= " lower(var_category) like :search ";
  76. $sql_search .= " or lower(var_name) like :search ";
  77. $sql_search .= " or lower(var_value) like :search ";
  78. $sql_search .= " or lower(var_hostname) like :search ";
  79. $sql_search .= " or lower(var_enabled) like :search ";
  80. $sql_search .= " or lower(var_description) like :search ";
  81. $sql_search .= ") ";
  82. $parameters['search'] = '%'.$search.'%';
  83. }
  84. //get the count
  85. $sql = "select count(var_uuid) from v_vars ";
  86. $sql .= $sql_search;
  87. $database = new database;
  88. $num_rows = $database->select($sql, $parameters, 'column');
  89. //prepare to page the results
  90. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  91. $param = $search ? "&search=".$search : null;
  92. $param = $order_by ? "&order_by=".$order_by."&order=".$order : null;
  93. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  94. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  95. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  96. $offset = $rows_per_page * $page;
  97. //get the list
  98. $sql = str_replace('count(var_uuid)', '*', $sql);
  99. $sql .= $order_by != '' ? order_by($order_by, $order) : " order by var_category, var_order asc, var_name asc ";
  100. $sql .= limit_offset($rows_per_page, $offset);
  101. $database = new database;
  102. $vars = $database->select($sql, $parameters, 'all');
  103. unset($sql);
  104. //create token
  105. $object = new token;
  106. $token = $object->create($_SERVER['PHP_SELF']);
  107. //include the header
  108. $document['title'] = $text['title-variables'];
  109. require_once "resources/header.php";
  110. //show the content
  111. echo "<div class='action_bar' id='action_bar'>\n";
  112. echo " <div class='heading'><b>".$text['header-variables']." (".$num_rows.")</b></div>\n";
  113. echo " <div class='actions'>\n";
  114. if (permission_exists('var_add')) {
  115. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'var_edit.php']);
  116. }
  117. if (permission_exists('var_add') && $vars) {
  118. 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');"]);
  119. }
  120. if (permission_exists('var_edit') && $vars) {
  121. 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');"]);
  122. }
  123. if (permission_exists('var_delete') && $vars) {
  124. 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');"]);
  125. }
  126. echo "<form id='form_search' class='inline' method='get'>\n";
  127. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  128. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  129. //echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'vars.php','style'=>($search == '' ? 'display: none;' : null)]);
  130. if ($paging_controls_mini != '') {
  131. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  132. }
  133. echo " </form>\n";
  134. echo " </div>\n";
  135. echo " <div style='clear: both;'></div>\n";
  136. echo "</div>\n";
  137. if (permission_exists('var_add') && $vars) {
  138. 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');"])]);
  139. }
  140. if (permission_exists('var_edit') && $vars) {
  141. 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');"])]);
  142. }
  143. if (permission_exists('var_delete') && $vars) {
  144. 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');"])]);
  145. }
  146. echo $text['description-variables']."\n";
  147. echo "<br /><br />\n";
  148. echo "<form id='form_list' method='post'>\n";
  149. echo "<input type='hidden' id='action' name='action' value=''>\n";
  150. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  151. echo "<table class='list'>\n";
  152. function write_header($modifier) {
  153. global $text, $order_by, $order, $vars;
  154. $modifier = str_replace('/', '', $modifier);
  155. $modifier = str_replace(' ', ' ', $modifier);
  156. $modifier = str_replace(' ', '_', $modifier);
  157. $modifier = str_replace(':', '', $modifier);
  158. $modifier = strtolower(trim($modifier));
  159. echo "\n";
  160. echo "<tr class='list-header'>\n";
  161. if (permission_exists('var_edit') || permission_exists('var_delete')) {
  162. echo " <th class='checkbox'>\n";
  163. echo " <input type='checkbox' id='checkbox_all_".$modifier."' name='checkbox_all' onclick=\"list_all_toggle('".$modifier."'); checkbox_on_change(this);\" ".($vars ?: "style='visibility: hidden;'").">\n";
  164. echo " </th>\n";
  165. }
  166. echo th_order_by('var_name', $text['label-name'], $order_by, $order, null, "class='pct-30'");
  167. echo th_order_by('var_value', $text['label-value'], $order_by, $order, null, "class='pct-40'");
  168. echo th_order_by('var_hostname', $text['label-hostname'], $order_by, $order, null, "class='hide-sm-dn'");
  169. echo th_order_by('var_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
  170. echo "<th class='hide-sm-dn'>".$text['label-description']."</th>\n";
  171. if (permission_exists('var_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  172. echo "<td class='action-button'>&nbsp;</td>\n";
  173. }
  174. echo "</tr>\n";
  175. }
  176. if (is_array($vars) && @sizeof($vars) != 0) {
  177. $previous_category = '';
  178. foreach ($vars as $x => $row) {
  179. //write category and column headings
  180. if ($previous_category != $row["var_category"]) {
  181. echo "<tr>\n";
  182. echo "<td colspan='7' class='no-link'>\n";
  183. echo ($previous_category != '' ? '<br />' : null)."<b>".$row["var_category"]."</b>";
  184. echo "</td>\n";
  185. echo "</tr>\n";
  186. write_header($row["var_category"]);
  187. }
  188. if (permission_exists('var_edit')) {
  189. $list_row_url = "var_edit.php?id=".urlencode($row['var_uuid']);
  190. }
  191. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  192. if (permission_exists('var_add') || permission_exists('var_edit') || permission_exists('var_delete')) {
  193. $modifier = strtolower(trim($row["var_category"]));
  194. $modifier = str_replace('/', '', $modifier);
  195. $modifier = str_replace(' ', ' ', $modifier);
  196. $modifier = str_replace(' ', '_', $modifier);
  197. $modifier = str_replace(':', '', $modifier);
  198. echo " <td class='checkbox'>\n";
  199. echo " <input type='checkbox' name='vars[$x][checked]' id='checkbox_".$x."' class='checkbox_".$modifier."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all_".$modifier."').checked = false; }\">\n";
  200. echo " <input type='hidden' name='vars[$x][uuid]' value='".escape($row['var_uuid'])."' />\n";
  201. echo " </td>\n";
  202. }
  203. echo " <td class='overflow'>";
  204. if (permission_exists('var_edit')) {
  205. echo "<a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['var_name'])."</a>";
  206. }
  207. else {
  208. echo escape($row['var_name']);
  209. }
  210. echo " </td>\n";
  211. echo " <td class='overflow'>".$row['var_value']."</td>\n";
  212. echo " <td class='hide-sm-dn'>".$row['var_hostname']."&nbsp;</td>\n";
  213. if (permission_exists('var_edit')) {
  214. echo " <td class='no-link center'>\n";
  215. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['var_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  216. }
  217. else {
  218. echo " <td class='center'>\n";
  219. echo $text['label-'.$row['var_enabled']];
  220. }
  221. echo " </td>\n";
  222. echo " <td class='description overflow hide-sm-dn'>".escape(base64_decode($row['var_description']))."</td>\n";
  223. if (permission_exists('var_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  224. echo " <td class='action-button'>\n";
  225. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  226. echo " </td>\n";
  227. }
  228. echo "</tr>\n";
  229. $previous_category = $row["var_category"];
  230. $x++;
  231. }
  232. }
  233. unset($vars);
  234. echo "</table>\n";
  235. echo "<br />\n";
  236. echo "<div align='center'>".$paging_controls."</div>\n";
  237. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  238. echo "</form>\n";
  239. //include the footer
  240. require_once "resources/footer.php";
  241. ?>