From c547b5532d3819a8d235a9077324f94ba6d20e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Mon, 12 May 2008 21:36:51 +0200 Subject: [PATCH] Add ability to e-mail all maintainers --- admin/adminMaintainers.php | 163 ++++++++++++++++++------------------- contact.php | 80 +++++++++++++----- include/maintainer.php | 19 +++++ 3 files changed, 160 insertions(+), 102 deletions(-) diff --git a/admin/adminMaintainers.php b/admin/adminMaintainers.php index c2588df..db9221c 100644 --- a/admin/adminMaintainers.php +++ b/admin/adminMaintainers.php @@ -16,99 +16,98 @@ if(!$_SESSION['current']->hasPriv("admin")) apidb_header("Admin Maintainers"); echo '
',"\n"; -if (isset($aClean['sSub'])) -{ -} else -{ - // get available maintainers - $sQuery = "SELECT * FROM appMaintainers, user_list where appMaintainers.userId = user_list.userid"; - $sQuery.= " AND state='accepted' ORDER BY realname;"; - $hResult = query_parameters($sQuery); - if(!$hResult || !query_num_rows($hResult)) - { - // no apps - echo html_frame_start("","90%"); - echo '

There are no application maintainers.

',"\n"; - echo html_frame_end(" "); - } - else - { - // show applist - echo html_frame_start("","90%","",0); - echo "\n\n"; - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "\n\n"; - - $c = 1; - $oldUserId = 0; - while($oRow = query_fetch_object($hResult)) +// get available maintainers +$sQuery = "SELECT * FROM appMaintainers, user_list where appMaintainers.userId = user_list.userid"; +$sQuery.= " AND state='accepted' ORDER BY realname;"; +$hResult = query_parameters($sQuery); + +if(!$hResult || !query_num_rows($hResult)) +{ + // no apps + echo html_frame_start("","90%"); + echo '

There are no application maintainers.

',"\n"; + echo html_frame_end(" "); +} +else +{ + echo '
E-mail all maintainers
'; + + // show applist + echo html_frame_start("","90%","",0); + echo "
Submission DateMaintainerApplicationVersionAction
\n\n"; + + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n\n"; + + $c = 1; + $oldUserId = 0; + while($oRow = query_fetch_object($hResult)) + { + $oUser = new User($oRow->userId); + $oApp = new application($oRow->appId); + if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; } + + /* if this is a new user we should print a header that has the aggregate of the applications */ + /* the user super maintains and versions they maintain */ + if($oRow->userId != $oldUserId) { - $oUser = new User($oRow->userId); - $oApp = new application($oRow->appId); - if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; } + $style = "border-top:thin solid;border-bottom:thin solid"; - /* if this is a new user we should print a header that has the aggregate of the applications */ - /* the user super maintains and versions they maintain */ - if($oRow->userId != $oldUserId) - { - $style = "border-top:thin solid;border-bottom:thin solid"; + echo "\n"; + echo " \n"; + if($oUser->sRealname == "") + echo " \n"; + else + echo " \n"; - echo "\n"; - echo " \n"; - if($oUser->sRealname == "") - echo " \n"; - else - echo " \n"; - - $count = Maintainer::getMaintainerCountForUser($oUser, true); - if($count == 0) - echo " \n"; - else if($count <= 1) - echo " \n"; - else - echo " \n"; + $count = Maintainer::getMaintainerCountForUser($oUser, true); + if($count == 0) + echo " \n"; + else if($count <= 1) + echo " \n"; + else + echo " \n"; - $count = Maintainer::getMaintainerCountForUser($oUser, false); - if($count == 0) - echo " \n"; - else if($count <= 1) - echo " \n"; - else - echo " \n"; + $count = Maintainer::getMaintainerCountForUser($oUser, false); + if($count == 0) + echo " \n"; + else if($count <= 1) + echo " \n"; + else + echo " \n"; - echo " \n"; - echo "\n\n"; - - $oldUserId = $oRow->userId; - } - - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - if($oRow->superMaintainer) - { - echo " \n"; - } else - { - $oVersion = new version($oRow->versionId); - echo " \n"; - } - echo " \n"; + echo " \n"; echo "\n\n"; - $c++; + + $oldUserId = $oRow->userId; } - echo "
Submission DateMaintainerApplicationVersionAction
Maintainer summarysEmail."\"> sEmail."\">".$oUser->sRealname."
Maintainer summarysEmail."\"> sEmail."\">".$oUser->sRealname." ".$count." app".$count." apps ".$count." app".$count." apps ".$count." version".$count." versions ".$count." version".$count." versions 
".print_date(mysqldatetime_to_unixtimestamp($oRow->submitTime))."  sEmail."\">".$oUser->sRealname."".$oApp->objectMakeLink()."*".$oVersion->objectMakeLink()."[delete] 
\n\n"; - echo html_frame_end(" "); + + echo "\n"; + echo " ".print_date(mysqldatetime_to_unixtimestamp($oRow->submitTime))."  \n"; + echo " sEmail."\">".$oUser->sRealname."\n"; + echo " ".$oApp->objectMakeLink()."\n"; + if($oRow->superMaintainer) + { + echo " *\n"; + } else + { + $oVersion = new version($oRow->versionId); + echo " ".$oVersion->objectMakeLink()."\n"; + } + echo " [delete]\n"; + echo "\n\n"; + $c++; } + echo "\n\n"; + echo html_frame_end(" "); } echo "
"; diff --git a/contact.php b/contact.php index 4635322..cafb40f 100644 --- a/contact.php +++ b/contact.php @@ -17,11 +17,40 @@ if(!$oUser->isLoggedIn()) exit; } +$oRecipient = null; +$sRecipientText = ''; +$iRecipientId = null; +$sRecipientGroup = getInput('sRecipientGroup', $aClean); +$sRecipients = ''; -$oRecipient = new User($aClean['iRecipientId']); +if($sRecipientGroup) +{ + if(!$oUser->hasPriv('admin')) + util_show_error_page_and_exit("Only admins can do this"); -if(!User::exists($oRecipient->sEmail)) - util_show_error_page_and_exit("User not found"); + switch($sRecipientGroup) + { + case 'maintainers': + $sRecipientText = 'all maintainers'; + $sRecipients = maintainer::getSubmitterEmails(); + if($sRecipients === FALSE) + util_show_error_page_and_exit("Failed to get list of maintainers"); + break; + + default: + util_show_error_page_and_exit("Invalid recipient group"); + } +} else +{ + $oRecipient = new User($aClean['iRecipientId']); + $iRecipientId = $oRecipient->iUserId; + $sRecipients = $oRecipient->sEmail; + + if(!User::exists($oRecipient->sEmail)) + util_show_error_page_and_exit("User not found"); + + $sRecipientText = $oRecipient->sRealname; +} /* Check for errors */ if((!$aClean['sMessage'] || !$aClean['sSubject']) && $aClean['sSubmit']) @@ -34,28 +63,29 @@ if((!$aClean['sMessage'] || !$aClean['sSubject']) && $aClean['sSubmit']) /* Display the feedback form if nothing else is specified */ if(!$aClean['sSubmit']) { - apidb_header("E-mail $oRecipient->sRealname"); - echo html_frame_start("Send us your suggestions",400,"",0); + apidb_header("E-mail $sRecipientText"); + echo ' '; + echo html_frame_start("Composer",400,"",0); echo $error; echo "
"; /* User manager */ - if($_SESSION['current']->hasPriv("admin")) + if($_SESSION['current']->hasPriv("admin") && $oRecipient) { echo "

iUserId."&sSearch=Administrator&iLimit". "=100&sOrderBy=email\">User manager

"; } - echo "

E-mail $oRecipient->sRealname.

"; - + echo "

E-mail $sRecipientText.

"; + $oTable = new Table(); $oTable->SetWidth("100%"); $oTable->SetBorder(0); $oTable->SetCellPadding(2); $oTable->SetCellSpacing(2); - + $oTableRow = new TableRow(); $oTableRow->SetClass("color4"); $oTableRow->AddTextCell("Subject"); @@ -83,7 +113,10 @@ if(!$aClean['sSubmit']) echo $oTable->GetString(); echo "iUserId\">"; + "value=\"$iRecipientId\">"; + + echo ""; echo "
\n"; @@ -91,19 +124,26 @@ if(!$aClean['sSubmit']) } else if ($aClean['sSubject'] && $aClean['sMessage']) { - $sSubjectRe = $aClean['sSubject']; - if(substr($sSubjectRe, 0, 4) != "Re: ") - $sSubjectRe = "Re: $sSubjectRe"; + if($oRecipient) + { + $sSubjectRe = $aClean['sSubject']; + if(substr($sSubjectRe, 0, 4) != "Re: ") + $sSubjectRe = "Re: $sSubjectRe"; - $sSubjectRe = urlencode($sSubjectRe); + $sSubjectRe = urlencode($sSubjectRe); - $sMsg = "The following message was sent to you from $oUser->sRealname "; - $sMsg .= "through the Wine AppDB contact form.\nTo Reply, visit "; - $sMsg .= APPDB_ROOT."contact.php?iRecipientId=$oUser->iUserId&sSubject="; - $sMsg .= $sSubjectRe."\n\n"; - $sMsg .= $aClean['sMessage']; + $sMsg = "The following message was sent to you from $oUser->sRealname "; + $sMsg .= "through the Wine AppDB contact form.\nTo Reply, visit "; + $sMsg .= APPDB_ROOT."contact.php?iRecipientId=$oUser->iUserId&sSubject="; + $sMsg .= $sSubjectRe."\n\n"; + $sMsg .= $aClean['sMessage']; + } else + { + $sMsg = "The following message was sent to you by the AppDB admins:\n\n"; + $sMsg .= $aClean['sMessage']; + } - mail_appdb($oRecipient->sEmail, $aClean['sSubject'], $sMsg); + mail_appdb($sRecipients, $aClean['sSubject'], $sMsg); util_redirect_and_exit(BASE."index.php"); } diff --git a/include/maintainer.php b/include/maintainer.php index 9a7e633..54a4b31 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -395,6 +395,25 @@ class maintainer return $hResult; } + function getSubmitterEmails() + { + $sRecipients = ''; + $sQuery = "SELECT DISTINCT(user_list.email) FROM appMaintainers, user_list WHERE + appMaintainers.userId = user_list.userId + AND + appMaintainers.state = 'accepted'"; + $hResult = query_parameters($sQuery); + if(!$hResult) + return FALSE; + for($i = 0; $oRow = query_fetch_object($hResult); $i++) + { + if($i) + $sRecipients .= ' '; + $sRecipients = $oRow->email; + } + return $sRecipients; + } + function ObjectGetEntries($sState, $iRows = 0, $iStart = 0, $sOrderBy = '', $bAscending = true) { /* Not implemented */