2 /***************************************/
3 /* Monitor class and related functions */
4 /***************************************/
8 * Monitor class for handling Monitors
13 // variables necessary for creating a monitor
20 * If $iMonitorId is provided, fetches Monitor.
22 function Monitor($iMonitorId="", $oRow = null)
24 if(!$iMonitorId && !$oRow)
31 WHERE monitorId = '".$iMonitorId."'";
32 $hResult = query_appdb($sQuery);
33 $oRow = query_fetch_object($hResult);
38 $this->iMonitorId
= $oRow->monitorId
;
39 $this->iAppId
= $oRow->appId
;
40 $this->iVersionId
= $oRow->versionId
;
41 $this->iUserId
= $oRow->userId
;
45 function find($iUserId, $iVersionId=0)
47 if($iUserId && $iVersionId)
51 WHERE userId = '".$iUserId."'
52 AND versionId = '".$iVersionId."'";
53 $hResult = query_appdb($sQuery);
54 if( $oRow = query_fetch_object($hResult) )
56 $this->iMonitorId
= $oRow->monitorId
;
57 $this->iAppId
= $oRow->appId
;
58 $this->iVersionId
= $oRow->versionId
;
59 $this->iUserId
= $oRow->userId
;
64 function objectGetChildren($bIncludeDeleted = false)
71 * Creates a new Monitor.
72 * Informs interested people about the creation.
73 * Returns true on success, false on failure
77 /* Check for duplicate entries */
78 $oMonitor = new monitor();
79 $this->iUserId
= $_SESSION['current']->iUserId
;
80 $oMonitor->find($this->iUserId
, $this->iVersionId
);
81 if($oMonitor->iVersionId
)
84 // create the new monitor entry
85 $hResult = query_parameters("INSERT INTO appMonitors (versionId, appId,".
86 "submitTime, userId) ".
87 "VALUES ('?', '?', ?, '?')",
88 $this->iVersionId
, $this->iAppId
,
89 "NOW()", $this->iUserId
);
93 $this->Monitor(query_appdb_insert_id());
94 $sWhatChanged = "New monitor\n\n";
95 $this->SendNotificationMail("add", $sWhatChanged);
99 addmsg("Error while creating a new Monitor.", "red");
112 return true; // We don't queue monitors
115 function objectGetSubmitterId()
117 return $this->iUserId
;
120 function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction)
122 return new mailOptions();
125 function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
130 if($this->iVersionId
)
133 $sName = version
::fullName($this->iVersionId
);
134 $oVersion = new version($this->iVersionId
);
135 $sUrl = $oVersion->objectMakeUrl();
138 $sWhat = "application";
139 $oApp = new application($this->iAppId
);
140 $sName = $oApp->sName
;
141 $sUrl = $oApp->objectMakeUrl();
151 $sSubject = "Monitored $sWhat deleted";
152 $sMsg = "The $sWhat $sName which you monitored has been ".
153 "deleted by ".$_SESSION['current']->iUserId
.".";
160 $oUser = new user($this->iUserId
);
161 $sUser = $oUser->sName
;
167 $sSubject = "Monitor for $sName removed: $sUser";
172 User
::get_notify_email_address_list(null, $this->iVersionId
);
174 return array($sSubject, $sMsg, $aMailTo);
179 return $this->delete();
183 * Removes the current Monitor from the database.
184 * Informs interested people about the deletion.
188 $hResult = query_parameters("DELETE FROM appMonitors WHERE monitorId = '?'", $this->iMonitorId
);
196 function SendNotificationMail($sAction="add",$sMsg=null)
198 /* Set variables depending on whether it is an application or version monitor */
199 if(isset($this->iVersionId
))
201 $oVersion = new version($this->iVersionId
);
202 $sAppName = version
::fullName($this->iVersionId
);
203 $sUrl = $oVersion->objectMakeUrl();
204 $sVersion = " version";
207 $oApp = new application($this->iAppId
);
208 $sAppName = Application
::lookup_name($this->iAppId
);
209 $sUrl = $oApp->objectMakeUrl();
215 $sSubject = "Monitor for ".$sAppName;
216 $sSubject .= " added: ".$_SESSION['current']->sRealname
;
218 addmsg("You will now receive an email whenever changes are made ".
219 "to this application$sVersion.", "green");
222 $sSubject = "Monitor for ".$sAppName;
223 $sSubject .= " removed: ".$_SESSION['current']->sRealname
;
225 addmsg("You will no longer receive an email whenever changes ".
226 "are made to this application$sVersion.", "green");
229 $sEmail = User
::get_notify_email_address_list(null, $this->iVersionId
);
231 mail_appdb($sEmail, $sSubject ,$sMsg);
234 function objectGetState()
236 // We don't queue monitors
242 if($_SESSION['current']->hasPriv("admin") ||
243 ($this->iUserId
== $_SESSION['current']->iUserId
))
249 function mustBeQueued()
261 function getOutputEditorValues($aClean)
263 $this->iVersionId
= $aClean['iVersionId'];
264 $this->iAppId
= $aClean['iAppId'];
268 function objectGetHeader()
273 function objectGetId()
275 return $this->iMonitorId
;
279 function objectGetTableRow()
285 function objectMakeLink()
291 function objectMakeUrl()
297 function outputEditor()
302 function objectGetEntries($sState, $iRows = 0, $iStart = 0, $sOrderBy = '', $bAscending = true)
304 $hResult = query_parameters("SELECT * FROM appMonitors");
312 function objectGetEntriesCount($sState)
314 $hResult = query_parameters("SELECT COUNT(DISTINCT monitorId) as count
320 $oRow = query_fetch_object($hResult);
328 function allowAnonymousSubmissions()
330 /* That makes no sense */
334 /* Retrieve the user's monitored versions */
335 function getVersionsMonitored($oUser)
337 $hResult = query_parameters("SELECT appId, versionId FROM appMonitors WHERE userId = '?'", $oUser->iUserId
);
339 if(!$hResult ||
query_num_rows($hResult) == 0)
342 $aVersionsMonitored = array();
344 for($i = 0; $oRow = query_fetch_object($hResult); $i++
)
345 $aVersionsMonitored[$i] = array($oRow->appId
, $oRow->versionId
);
347 return $aVersionsMonitored;