CWIS Developer Documentation
Privilege.php
Go to the documentation of this file.
1 <?PHP
2 
3 #
4 # FILE: Privilege.php
5 #
6 # Part of the Collection Workflow Integration System (CWIS)
7 # Copyright 2007-2013 Edward Almasy and Internet Scout Research Group
8 # http://scout.wisc.edu/cwis/
9 #
10 
16 class Privilege {
17 
18  # ---- PUBLIC INTERFACE --------------------------------------------------
19 
22 
29  function Privilege($Id, $Name = NULL)
30  {
31  global $G_PrivDescriptions;
32 
33  # if caller requested creation of new entry
34  if ($Id === NULL)
35  {
36  # get highest current ID
37  $DB = new Database();
38  $HighestId = $DB->Query("SELECT Id FROM CustomPrivileges"
39  ." ORDER BY Id DESC LIMIT 1", "Id");
40 
41  # select new ID
42  $this->Id = max(100, ($HighestId + 1));
43 
44  # add new entry to database
45  $DB->Query("INSERT INTO CustomPrivileges (Id, Name)"
46  ." VALUES (".$this->Id.", '".addslashes($Name)."')");
47  $this->Name = $Name;
48  }
49  else
50  {
51  # save ID
52  $this->Id = intval($Id);
53 
54  # if ID indicates predefined privilege
55  if ($this->IsPredefined())
56  {
57  # load privilege info from predefined priv array
58  $this->Name = $G_PrivDescriptions[$this->Id];
59  }
60  else
61  {
62  # load privilege info from database
63  $DB = new Database();
64  $this->Name = $DB->Query("SELECT Name FROM CustomPrivileges"
65  ." WHERE Id = ".$this->Id, "Name");
66  }
67  }
68  }
69 
74  function Delete()
75  {
76  if (!$this->IsPredefined())
77  {
78  $DB = new Database();
79  $DB->Query("DELETE FROM CustomPrivileges"
80  ." WHERE Id = ".$this->Id);
81  }
82  }
83 
88 
90  function Id() { return $this->Id; }
91 
97  function Name($NewValue = NULL)
98  {
99  if (($NewValue !== NULL) && !$this->IsPredefined())
100  {
101  $DB = new Database();
102  $DB->Query("UPDATE CustomPrivileges"
103  ." SET Name = '".addslashes($NewValue)."'"
104  ." WHERE Id = ".$this->Id);
105  $this->Name = $NewValue;
106  }
107  return $this->Name;
108  }
109 
116  function IsPredefined($Id = NULL)
117  {
118  if ($Id === NULL)
119  {
120  $Id = $this->Id;
121  }
122  return (($Id > 0) && ($Id < 100)) ? TRUE : FALSE;
123  }
124 
127  # ---- PRIVATE INTERFACE -------------------------------------------------
128 
129  private $Id;
130  private $Name;
131 }
User rights management framework allowing custom privege definition.
Definition: Privilege.php:16
SQL database abstraction object with smart query caching.
PHP
Definition: OAIClient.php:39
Delete()
Delete this privelege from the DB NOTE: the object should not be used after calling this...
Definition: Privilege.php:74
IsPredefined($Id=NULL)
Report whether privilege is predefined or custom Can be called as Privilege::IsPredefind(ID) ...
Definition: Privilege.php:116
Name($NewValue=NULL)
Get or set Name.
Definition: Privilege.php:97
Privilege($Id, $Name=NULL)
Object Constructor Pass in a value for the name and a NULL id to make a new privilege.
Definition: Privilege.php:29
Id()
Get Id.
Definition: Privilege.php:90