rights.lib.php 1.3 KB

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