default_setting_toggle.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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-2021
  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. //check permissions
  25. if (permission_exists('default_setting_edit')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //connect to the database
  33. $database = new database;
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //get submitted variables
  38. $search = $_REQUEST['search'];
  39. $default_setting_uuids = $_REQUEST["id"];
  40. //toggle the setting
  41. $toggled = 0;
  42. if (is_array($default_setting_uuids) && sizeof($default_setting_uuids) > 0) {
  43. foreach ($default_setting_uuids as $default_setting_uuid) {
  44. if (is_uuid($default_setting_uuid)) {
  45. //get current status
  46. $sql = "select default_setting_enabled from v_default_settings where default_setting_uuid = :default_setting_uuid ";
  47. $parameters['default_setting_uuid'] = $default_setting_uuid;
  48. $default_setting_enabled = $database->select($sql, $parameters, 'column');
  49. $new_status = ($default_setting_enabled == 'true') ? 'false' : 'true';
  50. unset($sql, $parameters);
  51. //set new status
  52. $array['default_settings'][0]['default_setting_uuid'] = $default_setting_uuid;
  53. $array['default_settings'][0]['default_setting_enabled'] = $new_status;
  54. $database->app_name = 'default_settings';
  55. $database->app_uuid = '2c2453c0-1bea-4475-9f44-4d969650de09';
  56. $database->save($array);
  57. $message = $database->message;
  58. unset($array);
  59. //increment toggle total
  60. $toggled++;
  61. }
  62. }
  63. if ($toggled > 0) {
  64. $_SESSION["message"] = $text['message-toggled'].': '.$toggled;
  65. }
  66. }
  67. //redirect the user
  68. $search = preg_replace('#[^a-zA-Z0-9_\-\.]# ', '', $search);
  69. header("Location: default_settings.php".($search != '' ? '?search='.$search : null));
  70. ?>