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.

325 lines
13 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-2021
  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('fax_extension_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['fax_servers'])) {
  39. $action = $_POST['action'];
  40. $search = $_POST['search'];
  41. $fax_servers = $_POST['fax_servers'];
  42. }
  43. //process the http post data by action
  44. if ($action != '' && is_array($fax_servers) && @sizeof($fax_servers) != 0) {
  45. switch ($action) {
  46. case 'copy':
  47. if (permission_exists('fax_extension_copy')) {
  48. $obj = new fax;
  49. $obj->copy($fax_servers);
  50. }
  51. break;
  52. case 'delete':
  53. if (permission_exists('fax_extension_delete')) {
  54. $obj = new fax;
  55. $obj->delete($fax_servers);
  56. }
  57. break;
  58. }
  59. header('Location: fax.php'.($search != '' ? '?search='.urlencode($search) : null));
  60. exit;
  61. }
  62. //get order and order by
  63. $order_by = $_GET["order_by"];
  64. $order = $_GET["order"];
  65. //add the search
  66. if (isset($_GET["search"])) {
  67. $search = strtolower($_GET["search"]);
  68. }
  69. //get record counts
  70. if (permission_exists('fax_extension_view_domain')) {
  71. //count the fax extensions
  72. $sql = "select count(f.fax_uuid) from v_fax as f ";
  73. $sql .= "where f.domain_uuid = :domain_uuid ";
  74. if (isset($search)) {
  75. $sql .= "and (";
  76. $sql .= " lower(fax_name) like :search ";
  77. $sql .= " or lower(fax_email) like :search ";
  78. $sql .= " or lower(fax_extension) like :search ";
  79. $sql .= " or lower(fax_destination_number) like :search ";
  80. $sql .= " or lower(fax_caller_id_name) like :search ";
  81. $sql .= " or lower(fax_caller_id_number) like :search ";
  82. $sql .= " or lower(fax_forward_number) like :search ";
  83. $sql .= " or lower(fax_description) like :search ";
  84. $sql .= ") ";
  85. $parameters['search'] = '%'.$search.'%';
  86. }
  87. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  88. }
  89. else {
  90. //ciount the assigned fax extensions
  91. $sql = "select count(f.fax_uuid) ";
  92. $sql .= "from v_fax as f, v_fax_users as u ";
  93. $sql .= "where f.fax_uuid = u.fax_uuid ";
  94. $sql .= "and f.domain_uuid = :domain_uuid ";
  95. $sql .= "and u.user_uuid = :user_uuid ";
  96. if (isset($search)) {
  97. $sql .= "and (";
  98. $sql .= " lower(fax_name) like :search ";
  99. $sql .= " or lower(fax_email) like :search ";
  100. $sql .= " or lower(fax_extension) like :search ";
  101. $sql .= " or lower(fax_destination_number) like :search ";
  102. $sql .= " or lower(fax_caller_id_name) like :search ";
  103. $sql .= " or lower(fax_caller_id_number) like :search ";
  104. $sql .= " or lower(fax_forward_number) like :search ";
  105. $sql .= " or lower(fax_description) like :search ";
  106. $sql .= ") ";
  107. $parameters['search'] = '%'.$search.'%';
  108. }
  109. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  110. $parameters['user_uuid'] = $_SESSION['user_uuid'];
  111. }
  112. $database = new database;
  113. $num_rows = $database->select($sql, $parameters, 'column');
  114. //prepare paging
  115. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  116. $param = "&search=".$search;
  117. $page = is_numeric($_GET['page']) ? $_GET['page'] : 0;
  118. list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
  119. list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
  120. $offset = $rows_per_page * $page;
  121. //get fax extensions
  122. if (permission_exists('fax_extension_view_domain')) {
  123. //show all fax extensions
  124. $sql = "select f.fax_uuid, fax_extension, fax_prefix, fax_name, fax_email, fax_description ";
  125. $sql .= "from v_fax as f ";
  126. $sql .= "where f.domain_uuid = :domain_uuid ";
  127. if (isset($search)) {
  128. $sql = "and (";
  129. $sql .= " lower(fax_name) like :search ";
  130. $sql .= " or lower(fax_email) like :search ";
  131. $sql .= " or lower(fax_extension) like :search ";
  132. $sql .= " or lower(fax_destination_number) like :search ";
  133. $sql .= " or lower(fax_caller_id_name) like :search ";
  134. $sql .= " or lower(fax_caller_id_number) like :search ";
  135. $sql .= " or lower(fax_forward_number) like :search ";
  136. $sql .= " or lower(fax_description) like :search ";
  137. $sql .= ") ";
  138. $parameters['search'] = '%'.$search.'%';
  139. }
  140. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  141. }
  142. else {
  143. //show only assigned fax extensions
  144. $sql = "select f.fax_uuid, fax_extension, fax_prefix, fax_name, fax_email, fax_description ";
  145. $sql .= "from v_fax as f, v_fax_users as u ";
  146. $sql .= "where f.fax_uuid = u.fax_uuid ";
  147. $sql .= "and f.domain_uuid = :domain_uuid ";
  148. $sql .= "and u.user_uuid = :user_uuid ";
  149. if (isset($search)) {
  150. $sql = "and (";
  151. $sql .= " lower(fax_name) like :search ";
  152. $sql .= " or lower(fax_email) like :search ";
  153. $sql .= " or lower(fax_extension) like :search ";
  154. $sql .= " or lower(fax_destination_number) like :search ";
  155. $sql .= " or lower(fax_caller_id_name) like :search ";
  156. $sql .= " or lower(fax_caller_id_number) like :search ";
  157. $sql .= " or lower(fax_forward_number) like :search ";
  158. $sql .= " or lower(fax_description) like :search ";
  159. $sql .= ") ";
  160. $parameters['search'] = '%'.$search.'%';
  161. }
  162. $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
  163. $parameters['user_uuid'] = $_SESSION['user_uuid'];
  164. }
  165. $sql .= order_by($order_by, $order, 'f.fax_name', 'asc');
  166. $sql .= limit_offset($rows_per_page, $offset);
  167. //echo $sql."\n";
  168. //view_array($parameters);
  169. $database = new database;
  170. $result = $database->select($sql, $parameters, 'all');
  171. unset($sql, $parameters);
  172. //create token
  173. $object = new token;
  174. $token = $object->create($_SERVER['PHP_SELF']);
  175. //additional includes
  176. $document['title'] = $text['title-fax'];
  177. require_once "resources/header.php";
  178. //show the content
  179. echo "<div class='action_bar' id='action_bar'>\n";
  180. echo " <div class='heading'><b>".$text['title-fax']." (".$num_rows.")</b></div>\n";
  181. echo " <div class='actions'>\n";
  182. if (permission_exists('fax_extension_add')) {
  183. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'fax_edit.php']);
  184. }
  185. if (permission_exists('fax_extension_copy') && $result) {
  186. 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');"]);
  187. }
  188. if (permission_exists('fax_extension_delete') && $result) {
  189. 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');"]);
  190. }
  191. echo "<form id='form_search' class='inline' method='get'>\n";
  192. echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
  193. echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
  194. //echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'fax.php','style'=>($search == '' ? 'display: none;' : null)]);
  195. if ($paging_controls_mini != '') {
  196. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
  197. }
  198. echo " </form>\n";
  199. echo " </div>\n";
  200. echo " <div style='clear: both;'></div>\n";
  201. echo "</div>\n";
  202. if (permission_exists('fax_extension_copy') && $result) {
  203. 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');"])]);
  204. }
  205. if (permission_exists('fax_extension_delete') && $result) {
  206. 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');"])]);
  207. }
  208. echo $text['description']."\n";
  209. echo "<br /><br />\n";
  210. echo "<form id='form_list' method='post'>\n";
  211. echo "<input type='hidden' id='action' name='action' value=''>\n";
  212. echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
  213. echo "<table class='list'>\n";
  214. echo "<tr class='list-header'>\n";
  215. if (permission_exists('fax_extension_add') || permission_exists('fax_extension_delete')) {
  216. echo " <th class='checkbox'>\n";
  217. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($result ?: "style='visibility: hidden;'").">\n";
  218. echo " </th>\n";
  219. }
  220. echo th_order_by('fax_name', $text['label-name'], $order_by, $order);
  221. echo th_order_by('fax_extension', $text['label-extension'], $order_by, $order);
  222. echo th_order_by('fax_email', $text['label-email'], $order_by, $order);
  223. echo " <th>".$text['label-tools']."</th>";
  224. echo th_order_by('fax_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'");
  225. if (permission_exists('fax_extension_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  226. echo " <td class='action-button'>&nbsp;</td>\n";
  227. }
  228. echo "</tr>\n";
  229. if (is_array($result) && @sizeof($result) != 0) {
  230. $x = 0;
  231. foreach ($result as $row) {
  232. if (permission_exists('fax_extension_edit')) {
  233. $list_row_url = "fax_edit.php?id=".urlencode($row['fax_uuid']);
  234. }
  235. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  236. if (permission_exists('fax_extension_add') || permission_exists('fax_extension_delete')) {
  237. echo " <td class='checkbox'>\n";
  238. echo " <input type='checkbox' name='fax_servers[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
  239. echo " <input type='hidden' name='fax_servers[$x][uuid]' value='".escape($row['fax_uuid'])."' />\n";
  240. echo " </td>\n";
  241. }
  242. echo " <td>";
  243. if (permission_exists('fax_extension_edit')) {
  244. echo "<a href='".$list_row_url."'>".escape($row['fax_name'])."</a>";
  245. }
  246. else {
  247. echo escape($row['fax_name']);
  248. }
  249. echo " </td>\n";
  250. echo " <td>".escape($row['fax_extension'])."</td>\n";
  251. echo " <td class='overflow' style='min-width: 25%;'>".escape(str_replace("\\",'', $row['fax_email']))."&nbsp;</td>\n";
  252. echo " <td class='no-link no-wrap'>";
  253. if (permission_exists('fax_send')) {
  254. echo " <a href='fax_send.php?id=".urlencode($row['fax_uuid'])."'>".$text['label-new']."</a>&nbsp;&nbsp;";
  255. }
  256. if (permission_exists('fax_inbox_view')) {
  257. if ($row['fax_email_inbound_subject_tag'] != '') {
  258. $file = "fax_files_remote.php";
  259. $box = escape($row['fax_email_connection_mailbox']);
  260. }
  261. else {
  262. $file = "fax_files.php";
  263. $box = 'inbox';
  264. }
  265. echo " <a href='".$file."?order_by=fax_date&order=desc&id=".urlencode($row['fax_uuid'])."&box=".$box."'>".$text['label-inbox']."</a>&nbsp;&nbsp;";
  266. //echo " <a href='fax_outbox.php?id=".urlencode($row['fax_uuid'])."'>".$text['label-outbox']."</a>&nbsp;&nbsp;";
  267. }
  268. if (permission_exists('fax_sent_view')) {
  269. echo " <a href='fax_files.php?order_by=fax_date&order=desc&id=".urlencode($row['fax_uuid'])."&box=sent'>".$text['label-sent']."</a>&nbsp;&nbsp;";
  270. }
  271. if (permission_exists('fax_log_view')) {
  272. echo " <a href='fax_logs.php?id=".urlencode($row['fax_uuid'])."'>".$text['label-log']."</a>";
  273. }
  274. if (permission_exists('fax_active_view') && isset($_SESSION['fax']['send_mode']['text']) && $_SESSION['fax']['send_mode']['text'] == 'queue') {
  275. echo " <a href='fax_active.php?id=".urlencode($row['fax_uuid'])."'>".$text['label-active']."</a>";
  276. }
  277. echo " </td>\n";
  278. echo " <td class='description overflow hide-sm-dn'>".escape($row['fax_description'])."&nbsp;</td>\n";
  279. if (permission_exists('fax_extension_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  280. echo " <td class='action-button'>";
  281. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  282. echo " </td>\n";
  283. }
  284. echo "</tr>\n";
  285. $x++;
  286. }
  287. unset($result);
  288. }
  289. echo "</table>\n";
  290. echo "<br />\n";
  291. echo "<div align='center'>".$paging_controls."</div>\n";
  292. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  293. echo "</form>\n";
  294. //include the footer
  295. require_once "resources/footer.php";
  296. ?>