rights.lib.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class Rights {
  3. private static $rights_cache = array();
  4. private static $rights = array (
  5. 'show_tabs:reports' =>
  6. array (
  7. 'type' => 'const',
  8. 'const' => 'true' )
  9. );
  10. // warning the goal of this function is to enforce rights managment in Chamilo
  11. // thus default return value is always true
  12. public static function hasRight($handler) {
  13. if (array_key_exists($handler, self::$rights_cache))
  14. return self::$rights_cache[$handler];
  15. if (!array_key_exists($handler, self::$rights))
  16. return true; // handler does not exists
  17. if (self::$rights[$handler]['type'] == 'sql') {
  18. $result = Database::query(self::$rights[$handler]['sql']);
  19. if (Database::num_rows($result) > 0)
  20. $result = true;
  21. else
  22. $result = false;
  23. } else if (self::$rights[$handler]['type'] == 'const')
  24. $result = self::$rights[$handler]['const'];
  25. else if (self::$rights[$handler]['type'] == 'func')
  26. $result = self::$rights[$handler]['func']();
  27. else // handler type not implemented
  28. return true;
  29. self::$rights_cache[$handler] = $result;
  30. return $result;
  31. }
  32. public static function hasRightClosePageWithError($handler) {
  33. if (hasRight($handler) == false)
  34. die("You are not allowed here"); //FIXME
  35. }
  36. }