dialplan_tools.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. /*
  3. Copyright (c) 2019-2024 Mark J Crane <[email protected]>
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
  13. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  14. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  16. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  17. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  18. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  19. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  20. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  21. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  22. SUCH DAMAGE.
  23. */
  24. //includes files
  25. require_once dirname(__DIR__, 2) . "/resources/require.php";
  26. require_once "resources/check_auth.php";
  27. require_once "resources/paging.php";
  28. //check permissions
  29. if (permission_exists('dialplan_tool_view')) {
  30. //access granted
  31. }
  32. else {
  33. echo "access denied";
  34. exit;
  35. }
  36. //add multi-lingual support
  37. $language = new text;
  38. $text = $language->get();
  39. //get the http post data
  40. if (!empty($_POST['dialplan_tools']) && is_array($_POST['dialplan_tools'])) {
  41. $action = $_POST['action'];
  42. $search = $_POST['search'] ?? null;
  43. $dialplan_tools = $_POST['dialplan_tools'];
  44. }
  45. //process the http post data by action
  46. if (!empty($action) && is_array($dialplan_tools) && @sizeof($dialplan_tools) != 0) {
  47. //validate the token
  48. $token = new token;
  49. if (!$token->validate($_SERVER['PHP_SELF'])) {
  50. message::add($text['message-invalid_token'],'negative');
  51. header('Location: dialplan_tools.php');
  52. exit;
  53. }
  54. //prepare the array
  55. $x = 0;
  56. foreach ($dialplan_tools as $row) {
  57. $array['dialplan_tools'][$x]['checked'] = $row['checked'] ?? null;
  58. $array['dialplan_tools'][$x]['dialplan_tool_uuid'] = $row['dialplan_tool_uuid'];
  59. $array['dialplan_tools'][$x]['enabled'] = $row['enabled'] ?? null;
  60. $x++;
  61. }
  62. //prepare the database object
  63. $database = new database;
  64. $database->app_name = 'dialplan_tools';
  65. $database->app_uuid = 'dbe1a32f-4cf2-4986-af22-154ef66abfae';
  66. //send the array to the database class
  67. switch ($action) {
  68. case 'copy':
  69. if (permission_exists('dialplan_tool_add')) {
  70. $database->copy($array);
  71. }
  72. break;
  73. case 'toggle':
  74. if (permission_exists('dialplan_tool_edit')) {
  75. $database->toggle($array);
  76. }
  77. break;
  78. case 'delete':
  79. if (permission_exists('dialplan_tool_delete')) {
  80. $database->delete($array);
  81. }
  82. break;
  83. }
  84. //redirect the user
  85. header('Location: dialplan_tools.php'.($search != '' ? '?search='.urlencode($search) : null));
  86. exit;
  87. }
  88. //get order and order by
  89. $order_by = $_GET["order_by"] ?? null;
  90. $order = $_GET["order"] ?? null;
  91. //add the search
  92. if (isset($_GET["search"])) {
  93. $search = strtolower($_GET["search"]);
  94. }
  95. //get the count
  96. $sql = "select count(dialplan_tool_uuid) ";
  97. $sql .= "from v_dialplan_tools ";
  98. if (permission_exists('dialplan_tool_all') && isset($_GET['show']) && $_GET['show'] == 'all') {
  99. $sql .= "where true ";
  100. }
  101. else {
  102. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  103. $parameters['domain_uuid'] = $domain_uuid;
  104. }
  105. if (isset($search)) {
  106. $sql .= "and (";
  107. $sql .= " lower(name) like :search ";
  108. $sql .= " or lower(application) like :search ";
  109. $sql .= " or lower(data) like :search ";
  110. $sql .= " or lower(description) like :search ";
  111. $sql .= ") ";
  112. $parameters['search'] = '%'.$search.'%';
  113. }
  114. $database = new database;
  115. $num_rows = $database->select($sql, $parameters ?? null, 'column');
  116. unset($sql, $parameters);
  117. //prepare to page the results
  118. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  119. $param = !empty($search) ? "&search=".$search : null;
  120. $param = !empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('dialplan_tool_all') ? "&show=all" : null;
  121. $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 0;
  122. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  123. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  124. $offset = $rows_per_page * $page;
  125. //get the list
  126. $sql = "select ";
  127. $sql .= "domain_uuid, ";
  128. $sql .= "(select domain_name from v_domains where domain_uuid = d.domain_uuid) as domain_name, ";
  129. $sql .= "dialplan_tool_uuid, ";
  130. $sql .= "name, ";
  131. $sql .= "application, ";
  132. $sql .= "data, ";
  133. $sql .= "cast(enabled as text), ";
  134. $sql .= "description ";
  135. $sql .= "from v_dialplan_tools as d ";
  136. if (permission_exists('dialplan_tool_all') && isset($_GET['show']) && $_GET['show'] == 'all') {
  137. $sql .= "where true ";
  138. }
  139. else {
  140. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  141. $parameters['domain_uuid'] = $domain_uuid;
  142. }
  143. if (isset($_GET["search"])) {
  144. $sql .= "and (";
  145. $sql .= " lower(name) like :search ";
  146. $sql .= " or lower(application) like :search ";
  147. $sql .= " or lower(data) like :search ";
  148. $sql .= " or lower(description) like :search ";
  149. $sql .= ") ";
  150. $parameters['search'] = '%'.$search.'%';
  151. }
  152. $sql .= order_by($order_by, $order, 'name', 'asc');
  153. $sql .= limit_offset($rows_per_page, $offset);
  154. $database = new database;
  155. $dialplan_tools = $database->select($sql, $parameters ?? null, 'all');
  156. unset($sql, $parameters);
  157. //create token
  158. $object = new token;
  159. $token = $object->create($_SERVER['PHP_SELF']);
  160. //additional includes
  161. $document['title'] = $text['title-dialplan_tools'];
  162. require_once "resources/header.php";
  163. //show the content
  164. echo "<div class='action_bar' id='action_bar'>\n";
  165. echo " <div class='heading'><b>".$text['title-dialplan_tools']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
  166. echo " <div class='actions'>\n";
  167. if (permission_exists('dialplan_tool_add')) {
  168. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'dialplan_tool_edit.php']);
  169. }
  170. if (permission_exists('dialplan_tool_add') && $dialplan_tools) {
  171. 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');"]);
  172. }
  173. if (permission_exists('dialplan_tool_edit') && $dialplan_tools) {
  174. 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');"]);
  175. }
  176. if (permission_exists('dialplan_tool_delete') && $dialplan_tools) {
  177. 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');"]);
  178. }
  179. echo "<form id='form_search' class='inline' method='get'>\n";
  180. if (permission_exists('dialplan_tool_all')) {
  181. if (!empty($_GET['show']) && $_GET['show'] == 'all') {
  182. echo " <input type='hidden' name='show' value='all'>\n";
  183. }
  184. else {
  185. echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
  186. }
  187. }
  188. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search ?? null)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
  189. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  190. if ($paging_controls_mini != '') {
  191. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  192. }
  193. echo " </form>\n";
  194. echo " </div>\n";
  195. echo " <div style='clear: both;'></div>\n";
  196. echo "</div>\n";
  197. if (permission_exists('dialplan_tool_add') && $dialplan_tools) {
  198. 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');"])]);
  199. }
  200. if (permission_exists('dialplan_tool_edit') && $dialplan_tools) {
  201. 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');"])]);
  202. }
  203. if (permission_exists('dialplan_tool_delete') && $dialplan_tools) {
  204. 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');"])]);
  205. }
  206. echo $text['title_description-dialplan_tools']."\n";
  207. echo "<br /><br />\n";
  208. echo "<form id='form_list' method='post'>\n";
  209. echo "<input type='hidden' id='action' name='action' value=''>\n";
  210. echo "<input type='hidden' name='search' value=\"".escape($search ?? null)."\">\n";
  211. echo "<div class='card'>\n";
  212. echo "<table class='list'>\n";
  213. echo "<tr class='list-header'>\n";
  214. if (permission_exists('dialplan_tool_add') || permission_exists('dialplan_tool_edit') || permission_exists('dialplan_tool_delete')) {
  215. echo " <th class='checkbox'>\n";
  216. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($dialplan_tools) ? "style='visibility: hidden;'" : null).">\n";
  217. echo " </th>\n";
  218. }
  219. if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) {
  220. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  221. }
  222. echo th_order_by('name', $text['label-name'], $order_by, $order);
  223. echo th_order_by('application', $text['label-application'], $order_by, $order);
  224. echo th_order_by('data', $text['label-data'], $order_by, $order);
  225. echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
  226. echo th_order_by('description', $text['label-description'], $order_by, $order);
  227. if (permission_exists('dialplan_tool_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  228. echo " <td class='action-button'>&nbsp;</td>\n";
  229. }
  230. echo "</tr>\n";
  231. if (is_array($dialplan_tools) && @sizeof($dialplan_tools) != 0) {
  232. $x = 0;
  233. foreach ($dialplan_tools as $row) {
  234. if (permission_exists('dialplan_tool_edit')) {
  235. $list_row_url = "dialplan_tool_edit.php?id=".urlencode($row['dialplan_tool_uuid']);
  236. }
  237. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  238. if (permission_exists('dialplan_tool_add') || permission_exists('dialplan_tool_edit') || permission_exists('dialplan_tool_delete')) {
  239. echo " <td class='checkbox'>\n";
  240. echo " <input type='checkbox' name='dialplan_tools[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  241. echo " <input type='hidden' name='dialplan_tools[$x][dialplan_tool_uuid]' value='".escape($row['dialplan_tool_uuid'])."' />\n";
  242. echo " </td>\n";
  243. }
  244. if (!empty($_GET['show']) && $_GET['show'] == 'all' && permission_exists('dialplan_tool_all')) {
  245. echo " <td>".(isset($row['domain_name']) ? escape($row['domain_name']) : $text['label-global'])."</td>\n";
  246. }
  247. echo " <td>\n";
  248. if (permission_exists('dialplan_tool_edit')) {
  249. echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['name'])."</a>\n";
  250. }
  251. else {
  252. echo " ".escape($row['name']);
  253. }
  254. echo " </td>\n";
  255. echo " <td>".escape($row['application'])."</td>\n";
  256. echo " <td>".escape($row['data'])."</td>\n";
  257. if (permission_exists('dialplan_tool_edit')) {
  258. echo " <td class='no-link center'>\n";
  259. echo " <input type='hidden' name='dialplan_tools[$x][enabled]' value='".escape($row['enabled'] ?? 'false')."' />\n";
  260. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.($row['enabled'] ?? 'false')],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  261. }
  262. else {
  263. echo " <td class='center'>\n";
  264. echo $text['label-'.$row['enabled']];
  265. }
  266. echo " </td>\n";
  267. echo " <td class='description overflow hide-sm-dn'>".escape($row['description'])."</td>\n";
  268. if (permission_exists('dialplan_tool_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  269. echo " <td class='action-button'>\n";
  270. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  271. echo " </td>\n";
  272. }
  273. echo "</tr>\n";
  274. $x++;
  275. }
  276. unset($dialplan_tools);
  277. }
  278. echo "</table>\n";
  279. echo "</div>\n";
  280. echo "<br />\n";
  281. echo "<div align='center'>".$paging_controls."</div>\n";
  282. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  283. echo "</form>\n";
  284. //include the footer
  285. require_once "resources/footer.php";
  286. ?>