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
24 # ---- PUBLIC INTERFACE --------------------------------------------------
33 function EventLog($DB, $UserId = -1, $LoggingEnabled = TRUE)
36 $this->Enabled = $LoggingEnabled;
37 $this->UserId = intval($UserId);
46 function Log($Type, $DataOne =
"", $DataTwo =
"")
48 # if logging is turned on
51 # write event out to log
52 $this->DB->Query(
"INSERT INTO EventLog"
53 .
" (EventType, EventDate, UserId, DataOne, DataTwo) VALUES"
54 .
" (".intval($Type).
", NOW(), ".$this->UserId.
","
55 .
" '".addslashes($DataOne).
"',"
56 .
" '".addslashes($DataTwo).
"')");
73 $StartDate = NULL, $EndDate = NULL, $EventCount = 999999999, $EventType)
75 # retrieve arguments (if supplied)
81 $Args = func_get_args();
82 if (count($Args)) { $StartDate = array_shift($Args); }
83 if (count($Args)) { $EndDate = array_shift($Args); }
84 if (count($Args)) { $StartIndex = array_shift($Args); }
85 if (count($Args)) { $EventCount = array_shift($Args); }
88 $Types[] = array_shift($Args);
91 # add start and/or end date to query condition (if supplied)
95 $Conditions .=
" EventDate >= '".addslashes($StartDate).
"'";
99 $Conditions .= (strlen($Conditions) ?
" AND" :
"")
100 .
" EventDate <= '".addslashes($EndDate).
"'";
103 # add event types to query condition (if supplied)
105 foreach ($Types as $Type)
107 $SubCondition .= (strlen($SubCondition) ?
" OR" :
"")
108 .
" EventType = ".intval($Type);
110 if (strlen($SubCondition))
112 $Conditions .= (strlen($Conditions) ?
" AND" :
"")
113 .
" (".$SubCondition.
")";
116 # if user privilege exclusions have been specified
117 if (isset($this->ExcludedPrivilegesForFind))
119 # add beginning of exclusion conditions and subquery
120 $Conditions .= (strlen($Conditions) ?
" AND" :
"")
121 .
" UserId NOT IN (SELECT UserId FROM APUserPrivileges WHERE ";
123 # add subquery condition for each exclusion
125 foreach ($this->ExcludedPrivilegesForFind as $Exclusion)
127 $Conditions .= $Connector.
"Privilege "
128 .$Exclusion[
"Operator"].
" ".$Exclusion[
"Value"];
132 # close out subquery condition
136 # if SQL query conditions have been specified
137 if (isset($this->ConditionsForFind))
139 # add conditions to condition string
140 foreach ($this->ConditionsForFind as $Condition)
142 $Conditions .= (strlen($Conditions) ?
" AND " :
" ").$Condition;
147 $Query =
"SELECT * FROM EventLog"
148 .(strlen($Conditions) ?
" WHERE ".$Conditions :
"")
149 .
" ORDER BY EventDate DESC LIMIT ".$StartIndex.
", ".$EventCount;
151 # run query and retrieve event information
152 $this->DB->Query($Query);
154 while ($EventInfo = $this->DB->FetchRow()) { $Events[] = $EventInfo; }
156 # return event information to caller
171 # if caller requested clear
172 if (($Operator === NULL) && ($Value === NULL))
175 unset($this->ExcludedPrivilegesForFind);
179 # add specified exclusion
180 $Exclusion[
"Operator"] = $Operator;
181 $Exclusion[
"Value"] = $Value;
182 $this->ExcludedPrivilegesForFind[] = $Exclusion;
194 # if caller requested clear
195 if ($Conditions === NULL)
197 # clear all conditions
198 unset($this->ConditionsForFind);
202 # convert condition to array if only one specified
203 if (!is_array($Conditions)) { $Conditions = array($Conditions); }
205 # add conditions to list
206 $this->ConditionsForFind = isset($this->ConditionsForFind)
207 ? array_merge($this->ConditionsForFind, $Conditions)
219 if ($UserId === NULL)
221 $UserId = $this->UserId;
237 $DataOne = NULL, $DataTwo = NULL, $Condition = NULL)
239 if ($DataOne || $DataTwo)
241 $this->DB->Query(
"UPDATE EventLog SET"
242 .($DataOne ?
" DataOne = '".addslashes($DataOne).
"'" :
"")
243 .(($DataOne && $DataTwo) ?
", " :
"")
244 .($DataTwo ?
" DataTwo = '".addslashes($DataTwo).
"'" :
"")
245 .
" WHERE EventType = '".addslashes($EventType).
"'"
246 .
" AND EventDate = '".addslashes($EventDate).
"'"
247 .
" AND UserId = '".addslashes($UserId).
"'");
252 # ---- PRIVATE INTERFACE -------------------------------------------------
257 private $ExcludedPrivilegesForFind;
258 private $ConditionsForFind;
LimitFindToUser($UserId=NULL)
Limit FindEvents() results to user with specified ID.
FindEvents($StartDate=NULL, $EndDate=NULL, $EventCount=999999999, $EventType)
Retrieve specified range of events.
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.
EventLog($DB, $UserId=-1, $LoggingEnabled=TRUE)
Object constructor.