rights.lib.php 1.3 KB

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