2005-09-30 01:55:51 +00:00
|
|
|
<?php
|
|
|
|
|
/***************************************/
|
|
|
|
|
/* Monitor class and related functions */
|
|
|
|
|
/***************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Monitor class for handling Monitors
|
|
|
|
|
*/
|
|
|
|
|
class Monitor {
|
|
|
|
|
var $iMonitorId;
|
|
|
|
|
var $iAppId;
|
|
|
|
|
var $iVersionId;
|
|
|
|
|
var $iUserId;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor.
|
|
|
|
|
* If $iMonitorId is provided, fetches Monitor.
|
|
|
|
|
*/
|
|
|
|
|
function Monitor($iMonitorId="")
|
|
|
|
|
{
|
|
|
|
|
if($iMonitorId)
|
|
|
|
|
{
|
|
|
|
|
$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);
|
|
|
|
|
$this->iMonitorId = $oRow->monitorId;
|
|
|
|
|
$this->iAppId = $oRow->appId;
|
|
|
|
|
$this->iVersionId = $oRow->versionId;
|
|
|
|
|
$this->iUserId = $oRow->userId;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function find($iUserId, $iAppId=0, $iVersionId=0)
|
|
|
|
|
{
|
|
|
|
|
if($iUserId)
|
|
|
|
|
{
|
|
|
|
|
if($iVersionId)
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "SELECT *
|
|
|
|
|
FROM appMonitors
|
|
|
|
|
WHERE userId = '".$iUserId."'
|
|
|
|
|
AND versionId = '".$iVersionId."'";
|
|
|
|
|
$hResult = query_appdb($sQuery);
|
|
|
|
|
$oRow = mysql_fetch_object($hResult);
|
|
|
|
|
$this->iMonitorId = $oRow->monitorId;
|
|
|
|
|
$this->iAppId = $oRow->appId;
|
|
|
|
|
$this->iVersionId = $oRow->versionId;
|
|
|
|
|
$this->iUserId = $oRow->userId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Creates a new Monitor.
|
|
|
|
|
* Informs interested people about the creation.
|
|
|
|
|
* Returns true on success, false on failure
|
|
|
|
|
*/
|
|
|
|
|
function create($iUserId, $iAppId=0, $iVersionId=0)
|
|
|
|
|
{
|
2006-06-24 04:20:32 +00:00
|
|
|
$hResult = query_parameters("INSERT INTO appMonitors (versionId, appId, userId) ".
|
|
|
|
|
"VALUES ('?', '?', '?')",
|
|
|
|
|
$iVersionId, $iAppId, $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");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function SendNotificationMail($sAction="add",$sMsg=null)
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
/* set $aAppName appropriately */
|
|
|
|
|
if(isset($this->iVersionId))
|
2006-06-29 18:05:44 +00:00
|
|
|
$sAppName = Application::lookup_name($this->iAppId)." ".Version::lookup_name($this->iVersionId);
|
2006-06-29 16:07:19 +00:00
|
|
|
else
|
2006-06-29 18:05:44 +00:00
|
|
|
$sAppName = Application::lookup_name($this->iAppId);
|
2006-06-29 16:07:19 +00:00
|
|
|
|
2005-09-30 01:55:51 +00:00
|
|
|
switch($sAction)
|
|
|
|
|
{
|
|
|
|
|
case "add":
|
|
|
|
|
if (isset($this->iVersionId))
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Monitor for ".$sAppName;
|
2005-09-30 01:55:51 +00:00
|
|
|
$sSubject .= " added: ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg .= APPDB_ROOT."appview.php?iVersionId=".$this->iVersionId."\n";
|
2005-09-30 01:55:51 +00:00
|
|
|
addmsg("You will now recieve an email whenever changes are made to this Application version.", "green");
|
|
|
|
|
} else
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Monitor for ".$sAppName." added: ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg .= APPDB_ROOT."appview.php?iAppId=".$this->iAppid."\n";
|
2005-09-30 01:55:51 +00:00
|
|
|
addmsg("You will now recieve an email whenever changes are made to this Application.", "green");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "delete":
|
|
|
|
|
if (isset($this->iVersionId))
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Monitor for ".$sAppName;
|
2005-09-30 01:55:51 +00:00
|
|
|
$sSubject .= " removed: ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg .= APPDB_ROOT."appview.php?iVersionId=".$this->iVersionId."\n";
|
2005-09-30 01:55:51 +00:00
|
|
|
addmsg("You will no longer recieve an email whenever changes are made to this Application version.", "green");
|
|
|
|
|
} else
|
|
|
|
|
{
|
2006-06-29 16:07:19 +00:00
|
|
|
$sSubject = "Monitor for ".$sAppName." removed: ".$_SESSION['current']->sRealname;
|
2006-07-06 17:27:54 +00:00
|
|
|
$sMsg .= APPDB_ROOT."appview.php?iAppId=".$this->iAppid."\n";
|
2005-09-30 01:55:51 +00:00
|
|
|
addmsg("You will no longer recieve an email whenever changes are made to this Application.", "green");
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|