Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- File List
- File Members

# Privilege.php

Go to the documentation of this file.

    00001 <?PHP
    00002
    00003 #
    00004 #   FILE:  Privilege.php
    00005 #
    00006 #   METHODS PROVIDED:
    00007 #       Privilege()
    00008 #           - constructor
    00009 #       SomeMethod($SomeParameter, $AnotherParameter)
    00010 #           - short description of method
    00011 #
    00012 #   AUTHOR:  Edward Almasy
    00013 #
    00014 #   Part of the Collection Workflow Integration System
    00015 #   Copyright 2007 Edward Almasy and Internet Scout
    00016 #   http://scout.wisc.edu
    00017 #
    00018
    00024 class Privilege {
    00025
    00026     # ---- PUBLIC INTERFACE --------------------------------------------------
    00027
    00030
    00037     function Privilege($Id, $Name = NULL)
    00038     {
    00039         global $G_PrivDescriptions;
    00040
    00041         # if caller requested creation of new entry
    00042         if ($Id === NULL)
    00043         {
    00044             # get highest current ID
    00045             $DB = new SPTDatabase();
    00046             $HighestId = $DB->Query("SELECT Id FROM CustomPrivileges"
    00047                     ." ORDER BY Id DESC LIMIT 1", "Id");
    00048
    00049             # select new ID
    00050             $this->Id = max(100, ($HighestId + 1));
    00051
    00052             # add new entry to database
    00053             $DB->Query("INSERT INTO CustomPrivileges (Id, Name)"
    00054                     ." VALUES (".$this->Id.", '".addslashes($Name)."')");
    00055             $this->Name = $Name;
    00056         }
    00057         else
    00058         {
    00059             # save ID
    00060             $this->Id = intval($Id);
    00061
    00062             # if ID indicates predefined privilege
    00063             if ($this->IsPredefined())
    00064             {
    00065                 # load privilege info from predefined priv array
    00066                 $this->Name = $G_PrivDescriptions[$this->Id];
    00067             }
    00068             else
    00069             {
    00070                 # load privilege info from database
    00071                 $DB = new SPTDatabase();
    00072                 $this->Name = $DB->Query("SELECT Name FROM CustomPrivileges"
    00073                         ." WHERE Id = ".$this->Id, "Name");
    00074             }
    00075         }
    00076     }
    00077
    00082     function Delete()
    00083     {
    00084         if (!$this->IsPredefined())
    00085         {
    00086             $DB = new SPTDatabase();
    00087             $DB->Query("DELETE FROM CustomPrivileges"
    00088                        ." WHERE Id = ".$this->Id);
    00089         }
    00090     }
    00091
    00096
    00098     function Id() {  return $this->Id;  }
    00104     function Name($NewValue = NULL)
    00105     {
    00106         if (($NewValue !== NULL) && !$this->IsPredefined())
    00107         {
    00108             $DB = new SPTDatabase();
    00109             $DB->Query("UPDATE CustomPrivileges"
    00110                     ." SET Name = '".addslashes($NewValue)."'"
    00111                     ." WHERE Id = ".$this->Id);
    00112             $this->Name = $NewValue;
    00113         }
    00114         return $this->Name;
    00115     }
    00116
    00123     function IsPredefined($Id = NULL)
    00124     {
    00125         if ($Id === NULL)
    00126         {
    00127             $Id = $this->Id;
    00128         }
    00129         return ($Id < 100) ? TRUE : FALSE;
    00130     }
    00131
    00134     # ---- PRIVATE INTERFACE -------------------------------------------------
    00135
    00136     private $Id;
    00137     private $Name;
    00138 }