From cc912964d6f3c8facec3abfce3e1f934ccc1fd38 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Sun, 31 Jul 2005 17:53:11 +0000 Subject: [PATCH] Move some maintainer code into user class, don't let a user maintain the same app more than once --- admin/adminMaintainerQueue.php | 40 ++++++-------------------- include/user.php | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 31 deletions(-) diff --git a/admin/adminMaintainerQueue.php b/admin/adminMaintainerQueue.php index f0188bd..79a9387 100644 --- a/admin/adminMaintainerQueue.php +++ b/admin/adminMaintainerQueue.php @@ -62,7 +62,7 @@ if ($_REQUEST['sub']) $firstDisplay = true; /* if false we need to fix up table rows appropriately */ - $other_users = getMaintainersUserIdsFromAppIdVersionId($ob->appId, $ob->versionId); + $other_users = getMaintainersUserIdsFromAppIdVersionId($ob->versionId); if($other_users) { $foundMaintainers = true; @@ -174,37 +174,15 @@ if ($_REQUEST['sub']) } else if ($_REQUEST['add'] && $_REQUEST['queueId']) { - // insert the new entry into the maintainers list - $query = "INSERT into appMaintainers VALUES(null,". - "$ob->appId,". - "$ob->versionId,". - "$ob->userId,". - "$ob->superMaintainer,". - "NOW());"; + /* create a new user object for the maintainer */ + $maintainerUser = new User($ob->userId); - if (query_appdb($query)) - { - $statusMessage = "

The maintainer was successfully added into the database

\n"; - - //delete the item from the queue - query_appdb("DELETE from appMaintainerQueue where queueId = ".$_REQUEST['queueId'].";"); - $oApp = new Application($ob->appId); - $oVersion = new Version($ob->versionId); - //Send Status Email - $sEmail = $oUser->sEmail; - if ($sEmail) - { - $sSubject = "Application Maintainer Request Report"; - $sMsg = "Your application to be the maintainer of ".$oApp->sName." ".$oVersion->sName." has been accepted. "; - $sMsg .= $_REQUEST['replyText']; - $sMsg .= "We appreciate your help in making the Application Database better for all users.\n\n"; - - mail_appdb($sEmail, $sSubject ,$sMsg); - } - - //done - addmsg("

$statusMessage

", 'green'); - } + /* add the user as a maintainer and return the statusMessage */ + $statusMessage = $maintainerUser->addAsMaintainer($ob->appId, $ob->versionId, + $ob->superMaintainer, + $_REQUEST['queueId']); + //done + addmsg("

$statusMessage

", 'green'); } else if (($_REQUEST['reject'] || ($_REQUEST['sub'] == 'reject')) && $_REQUEST['queueId']) { diff --git a/include/user.php b/include/user.php index c67547a..7bd695b 100644 --- a/include/user.php +++ b/include/user.php @@ -242,6 +242,58 @@ class User { return mysql_num_rows($hResult); } + /** + * Add the user as a maintainer + */ + function addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iQueueId) + { + /* if the user isn't already a supermaintainer of the application and */ + /* if they are trying to become a maintainer and aren't already a maintainer of */ + /* the version, then continue processing the request */ + if(!$this->isSuperMaintainer($iAppId) && + ((!$bSuperMaintainer && !$this->isMaintainer($iVersionId)) | $bSuperMaintainer)) + { + // insert the new entry into the maintainers list + $sQuery = "INSERT into appMaintainers VALUES(null,". + "$iAppId,". + "$iVersionId,". + "$this->iUserId,". + "$bSuperMaintainer,". + "NOW());"; + + if (query_appdb($sQuery)) + { + $statusMessage = "

The maintainer was successfully added into the database

\n"; + + //delete the item from the queue + query_appdb("DELETE from appMaintainerQueue where queueId = ".$iQueueId.";"); + $oApp = new Application($iAppId); + $oVersion = new Version($iVersionId); + //Send Status Email + $sEmail = $oUser->sEmail; + if ($sEmail) + { + $sSubject = "Application Maintainer Request Report"; + $sMsg = "Your application to be the maintainer of ".$oApp->sName." ".$oVersion->sName." has been accepted. "; + $sMsg .= $_REQUEST['replyText']; + $sMsg .= "We appreciate your help in making the Application Database better for all users.\n\n"; + + mail_appdb($sEmail, $sSubject ,$sMsg); + } + } + } else + { + //delete the item from the queue + query_appdb("DELETE from appMaintainerQueue where queueId = ".$iQueueId.";"); + + if($this->isSuperMaintainer($iAppId) && !$bSuperMaintainer) + $statusMessage = "

User is already a super maintainer of this application

\n"; + else + $statusMessage = "

User is already a maintainer/super maintainer of this application/version

\n"; + } + + return $statusMessage; + } function addPriv($sPriv) {