2005-09-30 01:55:51 +00:00
|
|
|
<?php
|
|
|
|
|
/***************************************/
|
|
|
|
|
/* Monitor class and related functions */
|
|
|
|
|
/***************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Monitor class for handling Monitors
|
|
|
|
|
*/
|
|
|
|
|
class Monitor {
|
|
|
|
|
var $iMonitorId;
|
2007-04-21 02:30:22 +00:00
|
|
|
|
|
|
|
|
// variables necessary for creating a monitor
|
2005-09-30 01:55:51 +00:00
|
|
|
var $iAppId;
|
|
|
|
|
var $iVersionId;
|
|
|
|
|
var $iUserId;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
* If $iMonitorId is provided, fetches Monitor.
|
|
|
|
|
*/
|
2007-07-30 01:22:55 +00:00
|
|
|
function Monitor($iMonitorId="", $oRow = null)
|
2005-09-30 01:55:51 +00:00
|
|
|
{
|
2007-07-30 01:22:55 +00:00
|
|
|
if(!$iMonitorId && !$oRow)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(!$oRow)
|
2005-09-30 01:55:51 +00:00
|
|
|
{
|
|
|
|
|
$sQuery = "SELECT *
|
|
|
|
|
FROM appMonitors
|
2005-10-29 04:41:10 +00:00
|
|
|
WHERE monitorId = '".$iMonitorId."'";
|
2005-09-30 01:55:51 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
|
|
|
|
$oRow = mysql_fetch_object($hResult);
|
2007-07-30 01:22:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($oRow)
|
|
|
|
|
{
|
|
|
|
|
$this->iMonitorId = $oRow->monitorId;
|
|
|
|
|
$this->iAppId = $oRow->appId;
|
|
|
|
|
$this->iVersionId = $oRow->versionId;
|
|
|
|
|
$this->iUserId = $oRow->userId;
|
2005-09-30 01:55:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-10 01:25:18 +00:00
|
|
|
function find($iUserId, $iVersionId=0)
|
2005-09-30 01:55:51 +00:00
|
|
|
{
|
2007-01-10 01:25:18 +00:00
|
|
|
if($iUserId && $iVersionId)
|
2005-09-30 01:55:51 +00:00
|
|
|
{
|
2007-01-10 01:25:18 +00:00
|
|
|
$sQuery = "SELECT *
|
2005-09-30 01:55:51 +00:00
|
|
|
FROM appMonitors
|
|
|
|
|
WHERE userId = '".$iUserId."'
|
|
|
|
|
AND versionId = '".$iVersionId."'";
|
2007-01-10 01:25:18 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
2007-07-24 01:45:19 +00:00
|
|
|
if( $oRow = mysql_fetch_object($hResult) )
|
|
|
|
|
{
|
|
|
|
|
$this->iMonitorId = $oRow->monitorId;
|
|
|
|
|
$this->iAppId = $oRow->appId;
|
|
|
|
|
$this->iVersionId = $oRow->versionId;
|
|
|
|
|
$this->iUserId = $oRow->userId;
|
|
|
|
|
}
|
2005-09-30 01:55:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Creates a new Monitor.
|
|
|
|
|
* Informs interested people about the creation.
|
|
|
|
|
* Returns true on success, false on failure
|
|
|
|
|
*/
|
2007-04-21 02:30:22 +00:00
|
|
|
function create()
|
2005-09-30 01:55:51 +00:00
|
|
|
{
|
2007-03-10 03:36:28 +00:00
|
|
|
/* Check for duplicate entries */
|
|
|
|
|
$oMonitor = new monitor();
|
2007-04-21 02:30:22 +00:00
|
|
|
$oMonitor->find($this->iUserId, $this->iVersionId);
|
2007-03-10 03:36:28 +00:00
|
|
|
if($oMonitor->iVersionId)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2007-04-21 02:30:22 +00:00
|
|
|
// create the new monitor entry
|
2006-06-24 04:20:32 +00:00
|
|
|
$hResult = query_parameters("INSERT INTO appMonitors (versionId, appId, userId) ".
|
|
|
|
|
"VALUES ('?', '?', '?')",
|
2007-04-21 02:30:22 +00:00
|
|
|
$this->iVersionId, $this->iAppId, $this->iUserId);
|
2005-09-30 01:55:51 +00:00
|
|
|
|
2006-06-24 04:20:32 +00:00
|
|
|
if($hResult)
|
2005-09-30 01:55:51 +00:00
|
|
|
{
|
|
|
|
|
$this->Monitor(mysql_insert_id());
|
|
|
|
|
$sWhatChanged = "New monitor\n\n";
|
|
|
|
|
$this->SendNotificationMail("add", $sWhatChanged);
|
|
|
|
|
return true;
|
2006-06-24 04:20:32 +00:00
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
addmsg("Error while creating a new Monitor.", "red");
|
2005-09-30 01:55:51 +00:00
|
|
|
return false;
|
2006-06-24 04:20:32 +00:00
|
|
|
}
|
2005-09-30 01:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the current Monitor from the database.
|
|
|
|
|
* Informs interested people about the deletion.
|
|
|
|
|
*/
|
|
|
|
|
function delete($bSilent=false)
|
|
|
|
|
{
|
2006-06-27 19:16:27 +00:00
|
|
|
$hResult = query_parameters("DELETE FROM appMonitors WHERE monitorId = '?'", $this->iMonitorId);
|
2005-09-30 01:55:51 +00:00
|
|
|
if(!$bSilent)
|
|
|
|
|
$this->SendNotificationMail("delete");
|
|
|
|
|
|
2007-07-30 01:22:55 +00:00
|
|
|
if(!$hResult)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2005-09-30 01:55:51 +00:00
|
|
|
|
|
|
|
|
function SendNotificationMail($sAction="add",$sMsg=null)
|
|
|
|
|
{
|
2007-04-08 23:04:31 +00:00
|
|
|
/* Set variables depending on whether it is an application or version monitor */
|
2006-06-29 16:07:19 +00:00
|
|
|
if(isset($this->iVersionId))
|
2007-04-08 23:04:31 +00:00
|
|
|
{
|
|
|
|
|
$oVersion = new version($this->iVersionId);
|
|
|
|
|
$sAppName = version::fullName($this->iVersionId);
|
|
|
|
|
$sUrl = $oVersion->objectMakeUrl();
|
|
|
|
|
$sVersion = " version";
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
$oApp = new application($this->iAppId);
|
2006-06-29 18:05:44 +00:00
|
|
|
$sAppName = Application::lookup_name($this->iAppId);
|
2007-04-08 23:04:31 +00:00
|
|
|
$sUrl = $oApp->objectMakeUrl();
|
|
|
|
|
}
|
2006-06-29 16:07:19 +00:00
|
|
|
|
2005-09-30 01:55:51 +00:00
|
|
|
switch($sAction)
|
|
|
|
|
{
|
|
|
|
|
case "add":
|
2007-04-08 23:04:31 +00:00
|
|
|
$sSubject = "Monitor for ".$sAppName;
|
|
|
|
|
$sSubject .= " added: ".$_SESSION['current']->sRealname;
|
|
|
|
|
$sMsg .= "$sUrl\n";
|
|
|
|
|
addmsg("You will now receive an email whenever changes are made ".
|
|
|
|
|
"to this application$sVersion.", "green");
|
2005-09-30 01:55:51 +00:00
|
|
|
break;
|
|
|
|
|
case "delete":
|
2007-04-08 23:04:31 +00:00
|
|
|
$sSubject = "Monitor for ".$sAppName;
|
|
|
|
|
$sSubject .= " removed: ".$_SESSION['current']->sRealname;
|
|
|
|
|
$sMsg .= "$sUrl\n";
|
|
|
|
|
addmsg("You will no longer receive an email whenever changes ".
|
|
|
|
|
"are made to this application$sVersion.", "green");
|
2005-09-30 01:55:51 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2006-06-29 15:54:29 +00:00
|
|
|
$sEmail = User::get_notify_email_address_list(null, $this->iVersionId);
|
2005-09-30 01:55:51 +00:00
|
|
|
if($sEmail)
|
|
|
|
|
mail_appdb($sEmail, $sSubject ,$sMsg);
|
2006-12-16 03:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
2007-07-30 01:22:55 +00:00
|
|
|
function canEdit()
|
|
|
|
|
{
|
|
|
|
|
if($_SESSION['current']->hasPriv("admin") ||
|
|
|
|
|
($this->iUserId == $_SESSION['current']->iUserId))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mustBeQueued()
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function display()
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function getOutputEditorValues()
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function objectGetHeader()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectGetId()
|
|
|
|
|
{
|
|
|
|
|
return $this->iMonitorId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function objectGetTableRow()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function objectMakeLink()
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function objectMakeUrl()
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Stub */
|
|
|
|
|
function outputEditor()
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectGetEntries($bQueued, $bRejected)
|
|
|
|
|
{
|
|
|
|
|
$hResult = query_parameters("SELECT * FROM appMonitors");
|
|
|
|
|
|
|
|
|
|
if(!$hResult)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return $hResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function objectGetEntriesCount($bQueued, $bRejected)
|
|
|
|
|
{
|
|
|
|
|
$hResult = query_parameters("SELECT COUNT(DISTINCT monitorId) as count
|
|
|
|
|
FROM appMonitors");
|
|
|
|
|
|
|
|
|
|
if(!$hResult)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
$oRow = mysql_fetch_object($hResult);
|
|
|
|
|
|
|
|
|
|
if(!$oRow)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return $oRow->count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function allowAnonymousSubmissions()
|
|
|
|
|
{
|
|
|
|
|
/* That makes no sense */
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-16 03:20:37 +00:00
|
|
|
/* Retrieve the user's monitored versions */
|
|
|
|
|
function getVersionsMonitored($oUser)
|
|
|
|
|
{
|
|
|
|
|
$hResult = query_parameters("SELECT appId, versionId FROM appMonitors WHERE userId = '?'", $oUser->iUserId);
|
|
|
|
|
|
|
|
|
|
if(!$hResult || mysql_num_rows($hResult) == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
$aVersionsMonitored = array();
|
|
|
|
|
|
|
|
|
|
for($i = 0; $oRow = mysql_fetch_object($hResult); $i++)
|
|
|
|
|
$aVersionsMonitored[$i] = array($oRow->appId, $oRow->versionId);
|
|
|
|
|
|
|
|
|
|
return $aVersionsMonitored;
|
|
|
|
|
}
|
2005-09-30 01:55:51 +00:00
|
|
|
}
|
|
|
|
|
?>
|