From 2311d4d572c34b679864c3174dd60ebe9a468f7a Mon Sep 17 00:00:00 2001 From: Tony Lambregts Date: Fri, 30 Sep 2005 01:55:51 +0000 Subject: [PATCH] Add the ability for user to monitor changes to applications --- appview.php | 52 +++++++++++++++- include/application.php | 14 ++--- include/bugs.php | 8 +-- include/monitor.php | 134 ++++++++++++++++++++++++++++++++++++++++ include/note.php | 8 +-- include/url.php | 10 +-- include/user.php | 35 +++++++++++ include/version.php | 14 ++--- tables/create_tables | 3 + tables/monitors.sql | 18 ++++++ 10 files changed, 266 insertions(+), 30 deletions(-) create mode 100644 include/monitor.php create mode 100644 tables/monitors.sql diff --git a/appview.php b/appview.php index 7473fa9..30612f1 100644 --- a/appview.php +++ b/appview.php @@ -14,6 +14,7 @@ require(BASE."include/vote.php"); require(BASE."include/category.php"); require(BASE."include/maintainer.php"); require(BASE."include/mail.php"); +require(BASE."include/monitor.php"); $oApp = new Application($_REQUEST['appId']); @@ -161,6 +162,24 @@ if ($_REQUEST['sub']) redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId'])); exit; } + if($_REQUEST['sub'] == 'StartMonitoring') + { + $oMonitor = new Monitor(); + $oMonitor->create($_SESSION['current']->iUserId,$_REQUEST['appId'],$_REQUEST['versionId']); + redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId'])); + exit; + } + if($_REQUEST['sub'] == 'StopMonitoring') + { + $oMonitor = new Monitor(); + $oMonitor->find($_SESSION['current']->iUserId,$_REQUEST['appId'],$_REQUEST['versionId']); + if($oMonitor->iMonitorId) + { + $oMonitor->delete(); + } + redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId'])); + exit; + } } @@ -397,6 +416,9 @@ else if($_REQUEST['versionId']) echo '
'; echo ''; echo ''; + echo "iAppId."\">"; + echo "iVersionId."\">"; + echo "
"; } else { /* are we already a maintainer? */ @@ -405,16 +427,28 @@ else if($_REQUEST['versionId']) echo '
'; echo ''; echo ''; + echo "iAppId."\">"; + echo "iVersionId."\">"; + echo "
"; } else /* nope */ { echo '
'; echo ''; + echo "iAppId."\">"; + echo "iVersionId."\">"; + echo "
"; + $oMonitor = new Monitor(); + $oMonitor->find($_SESSION['current']->iUserId,$oApp->iAppId,$oVersion->iVersionId); + if(!$oMonitor->iMonitorId) + { + echo '
iVersionId.'&appId='.$oApp->iAppId.'>'; + echo ''; + echo ''; + echo "
"; + } } } - echo "iAppId."\">"; - echo "iVersionId."\">"; - echo ""; } else { echo '
'; @@ -451,7 +485,19 @@ else if($_REQUEST['versionId']) echo '
'; echo ""; } + $oMonitor = new Monitor(); + $oMonitor->find($_SESSION['current']->iUserId,$oApp->iAppId,$oVersion->iVersionId); + if($oMonitor->iMonitorId) + { + echo ''; + echo ''; + echo '
iVersionId.'>'; + echo ''; + echo ''; + echo '
'; + echo ""; + } echo "\n"; // description diff --git a/include/application.php b/include/application.php index bcd10e6..69dffc3 100644 --- a/include/application.php +++ b/include/application.php @@ -136,7 +136,7 @@ class Application { { $this->iAppId = mysql_insert_id(); $this->application($this->iAppId); - $this->mailSupermaintainers(); // Only administrators will be mailed as no supermaintainers exist for this app. + $this->SendNotificationMail(); // Only administrators will be mailed as no supermaintainers exist for this app. return true; } else @@ -210,7 +210,7 @@ class Application { $this->iCatId = $iCatId; } if($sWhatChanged) - $this->mailSupermaintainers("edit",$sWhatChanged); + $this->SendNotificationMail("edit",$sWhatChanged); return true; } @@ -252,7 +252,7 @@ class Application { } if(!$bSilent) - $this->mailSupermaintainers("delete"); + $this->SendNotificationMail("delete"); } @@ -272,7 +272,7 @@ class Application { $this->sQueued = 'false'; // we send an e-mail to intersted people $this->mailSubmitter(); - $this->mailSupermaintainers(); + $this->SendNotificationMail(); // the application has been unqueued addmsg("The application has been unqueued.", "green"); @@ -291,7 +291,7 @@ class Application { $this->sQueued = 'rejected'; // we send an e-mail to intersted people $this->mailSubmitter("reject"); - $this->mailSupermaintainers("reject"); + $this->SendNotificationMail("reject"); // the application has been rejectedd addmsg("The application has been rejected.", "green"); @@ -308,7 +308,7 @@ class Application { { $this->sQueued = 'true'; // we send an e-mail to intersted people - $this->mailSupermaintainers(); + $this->SendNotificationMail(); // the application has been re-queued addmsg("The application has been re-queued.", "green"); @@ -355,7 +355,7 @@ class Application { } - function mailSupermaintainers($sAction="add",$sMsg=null) + function SendNotificationMail($sAction="add",$sMsg=null) { switch($sAction) { diff --git a/include/bugs.php b/include/bugs.php index a76b467..6a63183 100644 --- a/include/bugs.php +++ b/include/bugs.php @@ -136,7 +136,7 @@ class Bug { } /*End of Hack */ - $this->mailMaintainers(); + $this->SendNotificationMail(); return true; }else { @@ -156,7 +156,7 @@ class Bug { if($hResult = query_appdb($sQuery)) { if(!$bSilent) - $this->mailMaintainers(true); + $this->SendNotificationMail(true); } if($this->iSubmitterId) { @@ -181,7 +181,7 @@ class Bug { $this->bQueued = false; // we send an e-mail to intersted people $this->mailSubmitter(); - $this->mailMaintainers(); + $this->SendNotificationMail(); // the Bug has been unqueued addmsg("The Bug has been unqueued.", "green"); } @@ -210,7 +210,7 @@ class Bug { } - function mailMaintainers($bDeleted=false) + function SendNotificationMail($bDeleted=false) { if(!$bDeleted) { diff --git a/include/monitor.php b/include/monitor.php new file mode 100644 index 0000000..6feb5bf --- /dev/null +++ b/include/monitor.php @@ -0,0 +1,134 @@ +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) + { + $aInsert = compile_insert_string(array( 'versionId' => $iVersionId, + 'appId' => $iAppId, + 'userId' => $iUserId )); + + $sFields = "({$aInsert['FIELDS']})"; + $sValues = "({$aInsert['VALUES']})"; + if(query_appdb("INSERT INTO appMonitors $sFields VALUES $sValues", "Error while creating a new Monitor.")) + { + $this->Monitor(mysql_insert_id()); + $sWhatChanged = "New monitor\n\n"; + $this->SendNotificationMail("add", $sWhatChanged); + return true; + } + else + return false; + } + + + /** + * Removes the current Monitor from the database. + * Informs interested people about the deletion. + */ + function delete($bSilent=false) + { + $hResult = query_appdb("DELETE FROM appMonitors WHERE MonitorId = '".$this->iMonitorId."'"); + if(!$bSilent) + $this->SendNotificationMail("delete"); + } + + + function SendNotificationMail($sAction="add",$sMsg=null) + { + switch($sAction) + { + case "add": + if (isset($this->iVersionId)) + { + $oVersion = new Version($this->iVersionId); + $sSubject = "Monitor for ".lookup_app_name($oVersion->iAppId)." ".lookup_version_name($this->iVersionId); + $sSubject .= " added: ".$_SESSION['current']->sRealname; + $sMsg .= APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n"; + addmsg("You will now recieve an email whenever changes are made to this Application version.", "green"); + } else + { + $sSubject = "Monitor for ".lookup_app_name($this->iAppId)." added: ".$_SESSION['current']->sRealname; + $sMsg .= APPDB_ROOT."appview.php?appId=".$this->iAppid."\n"; + addmsg("You will now recieve an email whenever changes are made to this Application.", "green"); + } + break; + case "delete": + if (isset($this->iVersionId)) + { + $oVersion = new Version($this->iVersionId); + $sSubject = "Monitor for ".lookup_app_name($oVersion->iAppId)." ".lookup_version_name($this->iVersionId); + $sSubject .= " removed: ".$_SESSION['current']->sRealname; + $sMsg .= APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n"; + addmsg("You will no longer recieve an email whenever changes are made to this Application version.", "green"); + } else + { + $sSubject = "Monitor for ".lookup_app_name($this->iAppId)." removed: ".$_SESSION['current']->sRealname; + $sMsg .= APPDB_ROOT."appview.php?appId=".$this->iAppid."\n"; + addmsg("You will no longer recieve an email whenever changes are made to this Application.", "green"); + } + break; + } + $sEmail = get_notify_email_address_list(null, $this->iVersionId); + if($sEmail) + mail_appdb($sEmail, $sSubject ,$sMsg); + } +} +?> diff --git a/include/note.php b/include/note.php index 2be3c7f..7709d3b 100644 --- a/include/note.php +++ b/include/note.php @@ -55,7 +55,7 @@ class Note { { $this->note(mysql_insert_id()); $sWhatChanged = "Description is:\n".$sDescription.".\n\n"; - $this->mailMaintainers("add", $sWhatChanged); + $this->SendNotificationMail("add", $sWhatChanged); return true; } else @@ -101,7 +101,7 @@ class Note { $this->iAppId = $oVersionAfter->iAppId; } if($sWhatChanged) - $this->mailMaintainers("edit",$sWhatChanged); + $this->SendNotificationMail("edit",$sWhatChanged); return true; } @@ -114,11 +114,11 @@ class Note { { $hResult = query_appdb("DELETE FROM appNotes WHERE noteId = '".$this->iNoteId."'"); if(!$bSilent) - $this->mailMaintainers("delete"); + $this->SendNotificationMail("delete"); } - function mailMaintainers($sAction="add",$sMsg=null) + function SendNotificationMail($sAction="add",$sMsg=null) { switch($sAction) { diff --git a/include/url.php b/include/url.php index 3540e38..fea8e1b 100644 --- a/include/url.php +++ b/include/url.php @@ -70,7 +70,7 @@ class Url { { $this->iUrlId = mysql_insert_id(); $this->url($this->iUrlId,$this->bQueued); - $this->mailMaintainers(); + $this->SendNotificationMail(); return true; } else @@ -91,7 +91,7 @@ class Url { if($hResult = query_appdb($sQuery)) { if(!$bSilent) - $this->mailMaintainers(true); + $this->SendNotificationMail(true); } if($this->iSubmitterId) { @@ -114,7 +114,7 @@ class Url { { // we send an e-mail to intersted people $this->mailSubmitter(); - $this->mailMaintainers(); + $this->SendNotificationMail(); // the url has been unqueued addmsg("The url has been unqueued.", "green"); } @@ -170,7 +170,7 @@ class Url { $this->iAppId = $iAppId; } if($sWhatChanged) - $this->mailMaintainers("edit",$sWhatChanged); + $this->SendNotificationMail("edit",$sWhatChanged); return true; } @@ -197,7 +197,7 @@ class Url { } - function mailMaintainers($bDeleted=false) + function SendNotificationMail($bDeleted=false) { if(!$bDeleted) { diff --git a/include/user.php b/include/user.php index 8d79c63..9e85720 100644 --- a/include/user.php +++ b/include/user.php @@ -794,6 +794,41 @@ function get_notify_email_address_list($iAppId = null, $iVersionId = null) } } + /* + * Retrieve version Monitors. + */ + /* + * If versionId was supplied we fetch superMonitors of application and Monitors of version. + */ + if($iVersionId) + { + $sQuery = "SELECT appMonitors.userId + FROM appMonitors, appVersion + WHERE appVersion.appId = appMonitors.appId + AND appVersion.versionId = '".$iVersionId."'"; + } + /* + * If versionId was not supplied we fetch superMonitors of application and Monitors of all versions. + */ + elseif($iAppId) + { + $sQuery = "SELECT userId + FROM appMonitors + WHERE appId = '".$iAppId."'"; + } + if($sQuery) + { + $hResult = query_appdb($sQuery); + if(mysql_num_rows($hResult) > 0) + { + while($oRow = mysql_fetch_object($hResult)) + { + $aUserId[$c] = array($oRow->userId); + $c++; + } + } + } + /* * Retrieve administrators. */ diff --git a/include/version.php b/include/version.php index 9263472..ee618f4 100644 --- a/include/version.php +++ b/include/version.php @@ -159,7 +159,7 @@ class Version { { $this->iVersionId = mysql_insert_id(); $this->version($this->iVersionId); - $this->mailMaintainers(); + $this->SendNotificationMail(); return true; } else @@ -238,7 +238,7 @@ class Version { $this->iAppId = $iAppId; } if($sWhatChanged) - $this->mailMaintainers("edit",$sWhatChanged); + $this->SendNotificationMail("edit",$sWhatChanged); return true; } @@ -301,7 +301,7 @@ class Version { } if(!$bSilent) - $this->mailMaintainers("delete"); + $this->SendNotificationMail("delete"); $this->mailSubmitter("delete"); } @@ -328,7 +328,7 @@ class Version { $this->sQueued = 'false'; // we send an e-mail to intersted people $this->mailSubmitter("unQueue"); - $this->mailMaintainers(); + $this->SendNotificationMail(); // the version has been unqueued addmsg("The version has been unqueued.", "green"); @@ -355,7 +355,7 @@ class Version { if(!$bSilent) { $this->mailSubmitter("reject"); - $this->mailMaintainers("reject"); + $this->SendNotificationMail("reject"); } // the version has been unqueued addmsg("The version has been rejected.", "green"); @@ -377,7 +377,7 @@ class Version { { $this->sQueued = 'true'; // we send an e-mail to intersted people - $this->mailMaintainers(); + $this->SendNotificationMail(); // the version has been unqueued addmsg("The version has been re-submitted", "green"); @@ -425,7 +425,7 @@ class Version { } - function mailMaintainers($sAction="add",$sMsg=null) + function SendNotificationMail($sAction="add",$sMsg=null) { $oApp = new Application($this->iAppId); switch($sAction) diff --git a/tables/create_tables b/tables/create_tables index fe47bc3..6ffc3ff 100644 --- a/tables/create_tables +++ b/tables/create_tables @@ -27,3 +27,6 @@ mysql -p -u root < maintainers.sql echo Adding bug links mysql -p -u root < buglinks.sql +echo Adding monitors +mysql -p -u root < monitors.sql + diff --git a/tables/monitors.sql b/tables/monitors.sql new file mode 100644 index 0000000..fd87ab8 --- /dev/null +++ b/tables/monitors.sql @@ -0,0 +1,18 @@ +use apidb; + +drop table if exists appMonitors; + +/* + * Let users monitor changes to applications + */ +create table appMonitors ( + monitorId int not null auto_increment, + appId int not null, + versionId int not null, + submitTime timestamp(14) NOT NULL, + userId int(11) NOT NULL default '0', + key(monitorId), + index(appid), + index(versionId), + index(userId) +);