logout.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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-2015
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. //destroy session
  25. session_unset();
  26. session_destroy();
  27. //check for login return preference
  28. if ($_SESSION["user_uuid"] != '') {
  29. if (isset($_SESSION['login']['destination_last']) && ($_SESSION['login']['destination_last']['boolean'] == 'true')) {
  30. if ($_SERVER['HTTP_REFERER'] != '') {
  31. //convert to relative path
  32. $referrer = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER["HTTP_HOST"]) + strlen($_SERVER["HTTP_HOST"]));
  33. //check if destination url already exists
  34. $sql = "select count(*) as num_rows from v_user_settings ";
  35. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  36. $sql .= "and user_uuid = '".$_SESSION["user_uuid"]."' ";
  37. $sql .= "and user_setting_category = 'login' ";
  38. $sql .= "and user_setting_subcategory = 'destination' ";
  39. $sql .= "and user_setting_name = 'url' ";
  40. $prep_statement = $db->prepare($sql);
  41. if ($prep_statement) {
  42. $prep_statement->execute();
  43. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  44. $exists = ($row['num_rows'] > 0) ? true : false;
  45. }
  46. unset($sql, $prep_statement, $row);
  47. //if exists, update
  48. if ($exists) {
  49. $sql = "update v_user_settings set ";
  50. $sql .= "user_setting_value = '".$referrer."', ";
  51. $sql .= "user_setting_enabled = 'true' ";
  52. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  53. $sql .= "and user_uuid = '".$_SESSION["user_uuid"]."' ";
  54. $sql .= "and user_setting_category = 'login' ";
  55. $sql .= "and user_setting_subcategory = 'destination' ";
  56. $sql .= "and user_setting_name = 'url' ";
  57. $db->exec(check_sql($sql));
  58. unset($sql);
  59. }
  60. //otherwise, insert
  61. else {
  62. $sql = "insert into v_user_settings ";
  63. $sql .= "( ";
  64. $sql .= "user_setting_uuid, ";
  65. $sql .= "domain_uuid, ";
  66. $sql .= "user_uuid, ";
  67. $sql .= "user_setting_category, ";
  68. $sql .= "user_setting_subcategory, ";
  69. $sql .= "user_setting_name, ";
  70. $sql .= "user_setting_value, ";
  71. $sql .= "user_setting_enabled ";
  72. $sql .= ") ";
  73. $sql .= "values ";
  74. $sql .= "( ";
  75. $sql .= "'".uuid()."', ";
  76. $sql .= "'".$_SESSION['domain_uuid']."', ";
  77. $sql .= "'".$_SESSION["user_uuid"]."', ";
  78. $sql .= "'login', ";
  79. $sql .= "'destination', ";
  80. $sql .= "'url', ";
  81. $sql .= "'".$referrer."', ";
  82. $sql .= "'true' ";
  83. $sql .= ") ";
  84. $db->exec(check_sql($sql));
  85. unset($sql);
  86. }
  87. }
  88. }
  89. }
  90. //redirect the user to the index page
  91. header("Location: ".PROJECT_PATH."/login.php");
  92. return;
  93. ?>