sessiontalk_directory.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-2023
  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. require_once "resources/paging.php";
  25. //check permissions
  26. require_once "resources/check_auth.php";
  27. if (permission_exists('company_directory_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 the http values and set them as variables
  38. $order_by = check_str($_REQUEST["order_by"]);
  39. $order = check_str($_REQUEST["order"]);
  40. //handle search term
  41. $search = check_str($_REQUEST["search"]);
  42. if (strlen($search) > 0) {
  43. $sql_mod = "and ( ";
  44. $sql_mod .= "e.extension ILIKE '%".$search."%' ";
  45. $sql_mod .= "or e.call_group ILIKE '%".$search."%' ";
  46. $sql_mod .= "or e.directory_last_name ILIKE '%".$search."%' ";
  47. $sql_mod .= "or e.directory_first_name ILIKE '%".$search."%' ";
  48. $sql_mod .= ") ";
  49. }
  50. if (strlen($order_by) < 1) {
  51. $order_by = "extension";
  52. $order = "ASC";
  53. }
  54. $domain_uuid = $_SESSION['domain_uuid'];
  55. //lookup the domain count
  56. $sql = "select count(*) as num_rows from v_extensions as e\n";
  57. $sql .= "WHERE domain_uuid = '$domain_uuid' and directory_visible = 'true' \n";
  58. $sql .= $sql_mod; //add search mod from above"
  59. $prep_statement = $db->prepare($sql);
  60. if ($prep_statement) {
  61. $prep_statement->execute();
  62. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  63. $numeric_extension_count = $row['num_rows'];
  64. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  65. $numeric_extension_count = $row['num_rows'];
  66. }
  67. }
  68. unset($prep_statement, $row);
  69. //prepare to page the results
  70. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  71. $param = "&search=".$search;
  72. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  73. $_GET['page'] = check_str($_GET['page']);
  74. list($paging_controls_mini, $rows_per_page, $var_3) = paging($numeric_extension_count, $param, $rows_per_page, true); //top
  75. list($paging_controls, $rows_per_page, $var_3) = paging($numeric_extension_count, $param, $rows_per_page); //bottom
  76. $offset = $rows_per_page * $_GET['page'];
  77. //get all the counts from the database
  78. $sql = "SELECT \n";
  79. $sql .= "e.directory_first_name AS first_name, \n";
  80. $sql .= "e.directory_last_name AS last_name, \n";
  81. $sql .= "e.extension AS phone, \n";
  82. $sql .= "e.call_group AS group\n";
  83. $sql .= "FROM v_extensions as e \n";
  84. $sql .= "WHERE e.domain_uuid = '$domain_uuid' and e.directory_visible = 'true' \n";
  85. $sql .= $sql_mod; //add search mod from above
  86. $sql .= "ORDER BY ".$order_by." ".$order." \n";
  87. if ($export != "true") {$sql .= "limit $rows_per_page offset $offset ";}
  88. $database = new database;
  89. $directory = $database->select($sql, null, 'all');
  90. unset($database,$result);
  91. //set the headers
  92. header('Content-type: application/octet-binary');
  93. header("Content-Disposition: attachment; filename=company-directory_" . date("Y-m-d") . ".csv");
  94. //show the column names on the first line
  95. $z = 0;
  96. foreach($directory[1] as $key => $val) {
  97. if ($z == 0) {
  98. echo '"'.$key.'"';
  99. }
  100. else {
  101. echo ',"'.$key.'"';
  102. }
  103. $z++;
  104. }
  105. echo "\n";
  106. //add the values to the csv
  107. $x = 0;
  108. foreach($directory as $key => $row){
  109. echo '"'.$row['first_name'].'"';
  110. echo ',"'.$row['last_name'].'"';
  111. echo ',"'.$row['phone'].'"';
  112. echo ',"'.$row['group'].'"';
  113. echo "\n";
  114. $x++;
  115. }
  116. exit;
  117. ?>