permissions.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. Copyright (C) 2016 All Rights Reserved.
  17. */
  18. /**
  19. * permission class
  20. *
  21. * @method string add
  22. * @method string delete
  23. * @method string exists
  24. */
  25. if (!class_exists('permissions')) {
  26. class permissions {
  27. /**
  28. * Add the permission
  29. * @var string $permission
  30. */
  31. public function add($permission, $type) {
  32. //add the permission if it is not in array
  33. if (!$this->exists($permission)) {
  34. $_SESSION["permissions"][$permission] = $type;
  35. }
  36. }
  37. /**
  38. * Remove the permission
  39. * @var string $permission
  40. */
  41. public function delete($permission, $type) {
  42. if ($this->exists($permission)) {
  43. if ($type === "temp") {
  44. if ($_SESSION["permissions"][$permission] === "temp") {
  45. unset($_SESSION["permissions"][$permission]);
  46. }
  47. }
  48. else {
  49. if ($_SESSION["permissions"][$permission] !== "temp") {
  50. unset($_SESSION["permissions"][$permission]);
  51. }
  52. }
  53. }
  54. }
  55. /**
  56. * Check to see if the permission exists
  57. * @var string $permission
  58. */
  59. function exists($permission) {
  60. //set default false
  61. $result = false;
  62. //search for the permission
  63. if (is_array($_SESSION["permissions"]) && isset($_SESSION["permissions"][$permission])) {
  64. $result = true;
  65. }
  66. //return the result
  67. return $result;
  68. }
  69. }
  70. }
  71. //examples
  72. /*
  73. //add the permission
  74. $p = new permissions;
  75. $p->add($permission);
  76. //delete the permission
  77. $p = new permissions;
  78. $p->delete($permission);
  79. */
  80. ?>