4 # FILE: Scout--EventLog.php 9 # SomeMethod($SomeParameter, $AnotherParameter) 10 # - short description of method 12 # AUTHOR: Edward Almasy 14 # Copyright 2007 Internet Scout 15 # http://scout.wisc.edu 25 # ---- PUBLIC INTERFACE -------------------------------------------------- 34 public function __construct($DB, $UserId = -1, $LoggingEnabled = TRUE)
37 $this->Enabled = $LoggingEnabled;
38 $this->UserId = intval($UserId);
47 public function Log($Type, $DataOne =
"", $DataTwo =
"")
49 # if logging is turned on 52 # write event out to log 53 $this->DB->Query(
"INSERT INTO EventLog" 54 .
" (EventType, EventDate, UserId, DataOne, DataTwo) VALUES" 55 .
" (".intval($Type).
", NOW(), ".$this->UserId.
"," 56 .
" '".addslashes($DataOne).
"'," 57 .
" '".addslashes($DataTwo).
"')");
74 $StartDate = NULL, $EndDate = NULL, $EventCount = 999999999)
76 # retrieve arguments (if supplied) 82 $Args = func_get_args();
83 if (count($Args)) { $StartDate = array_shift($Args); }
84 if (count($Args)) { $EndDate = array_shift($Args); }
85 if (count($Args)) { $StartIndex = array_shift($Args); }
86 if (count($Args)) { $EventCount = array_shift($Args); }
89 $Types[] = array_shift($Args);
92 # add start and/or end date to query condition (if supplied) 96 $Conditions .=
" EventDate >= '".addslashes($StartDate).
"'";
100 $Conditions .= (strlen($Conditions) ?
" AND" :
"")
101 .
" EventDate <= '".addslashes($EndDate).
"'";
104 # add event types to query condition (if supplied) 106 foreach ($Types as $Type)
108 $SubCondition .= (strlen($SubCondition) ?
" OR" :
"")
109 .
" EventType = ".intval($Type);
111 if (strlen($SubCondition))
113 $Conditions .= (strlen($Conditions) ?
" AND" :
"")
114 .
" (".$SubCondition.
")";
117 # if user privilege exclusions have been specified 118 if (isset($this->ExcludedPrivilegesForFind))
120 # add beginning of exclusion conditions and subquery 121 $Conditions .= (strlen($Conditions) ?
" AND" :
"")
122 .
" UserId NOT IN (SELECT UserId FROM APUserPrivileges WHERE ";
124 # add subquery condition for each exclusion 126 foreach ($this->ExcludedPrivilegesForFind as $Exclusion)
128 $Conditions .= $Connector.
"Privilege " 129 .$Exclusion[
"Operator"].
" ".$Exclusion[
"Value"];
133 # close out subquery condition 137 # if SQL query conditions have been specified 138 if (isset($this->ConditionsForFind))
140 # add conditions to condition string 141 foreach ($this->ConditionsForFind as $Condition)
143 $Conditions .= (strlen($Conditions) ?
" AND " :
" ").$Condition;
148 $Query =
"SELECT * FROM EventLog" 149 .(strlen($Conditions) ?
" WHERE ".$Conditions :
"")
150 .
" ORDER BY EventDate DESC LIMIT ".$StartIndex.
", ".$EventCount;
152 # run query and retrieve event information
153 $this->DB->Query($Query);
155 while ($EventInfo = $this->DB->FetchRow()) { $Events[] = $EventInfo; }
157 # return event information to caller 172 # if caller requested clear 173 if (($Operator === NULL) && ($Value === NULL))
176 unset($this->ExcludedPrivilegesForFind);
180 # add specified exclusion 181 $Exclusion[
"Operator"] = $Operator;
182 $Exclusion[
"Value"] = $Value;
183 $this->ExcludedPrivilegesForFind[] = $Exclusion;
196 # if caller requested clear 197 if ($Conditions === NULL)
199 # clear all conditions 200 unset($this->ConditionsForFind);
204 # convert condition to array if only one specified 205 if (!is_array($Conditions)) { $Conditions = array($Conditions); }
207 # add conditions to list 208 $this->ConditionsForFind = isset($this->ConditionsForFind)
209 ? array_merge($this->ConditionsForFind, $Conditions)
221 if ($UserId === NULL)
223 $UserId = $this->UserId;
241 $DataOne = NULL, $DataTwo = NULL, $Condition = NULL)
243 if ($DataOne || $DataTwo)
245 $this->DB->Query(
"UPDATE EventLog SET" 246 .($DataOne ?
" DataOne = '".addslashes($DataOne).
"'" :
"")
247 .(($DataOne && $DataTwo) ?
", " :
"")
248 .($DataTwo ?
" DataTwo = '".addslashes($DataTwo).
"'" :
"")
249 .
" WHERE EventType = '".addslashes($EventType).
"'" 250 .
" AND EventDate = '".addslashes($EventDate).
"'" 251 .
" AND UserId = '".addslashes($UserId).
"'");
256 # ---- PRIVATE INTERFACE ------------------------------------------------- 261 private $ExcludedPrivilegesForFind;
262 private $ConditionsForFind;
LimitFindToUser($UserId=NULL)
Limit FindEvents() results to user with specified ID.
FindEvents($StartDate=NULL, $EndDate=NULL, $EventCount=999999999)
Retrieve specified range of events.
__construct($DB, $UserId=-1, $LoggingEnabled=TRUE)
Object constructor.
Class for storing and retrieving event information from database.
Log($Type, $DataOne="", $DataTwo="")
Add event to log.
ExcludeUsersWithPrivilegesForFind($Operator, $Value)
Add privilege to exclude from FindEvents() results.
AddSqlConditionForFind($Conditions)
Add SQL condition to apply to FindEvents().
ModifyEvents($EventType, $EventDate, $UserId, $DataOne=NULL, $DataTwo=NULL, $Condition=NULL)
Modify existing events.