Set up notify system. Send notify emails for ad and delete Coments

This commit is contained in:
Tony Lambregts
2004-11-09 22:42:12 +00:00
committed by Jeremy Newman
parent c81eebd949
commit 90ac967f43
6 changed files with 147 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
include("path.php");
require(BASE."include/"."incl.php");
require(BASE."include/"."application.php");
global $current;
@@ -29,24 +30,46 @@ if($body)
$subject = strip_tags($subject);
$subject = mysql_escape_string($subject);
$body = mysql_escape_string($body);
$body1 = mysql_escape_string($body);
// get current userid
$userId = (loggedin()) ? $current->userid : 0;
$result = mysql_query("INSERT INTO appComments VALUES (null, null, $thread, ".
"$appId, $versionId, $userId, '$hostname', '$subject', ".
"'$body', 0)");
"'$body1', 0)");
if (!$result)
{
errorpage('Internal Database Access Error',mysql_error());
exit;
} else
{
$email = getNotifyEmailAddressList($appId, $versionId);
if($email)
{
$fullAppName = "Application: ".lookupAppName($appId)." Version: ".lookupVersionName($appId, $versionId);
$ms .= apidb_fullurl("appview.php?appId=$appId&versionId=$versionId")."\n";
$ms .= "\n";
$ms .= ($current->username ? $current->username : "Anonymous")." added comment to ".$fullAppName."\n";
$ms .= "\n";
$ms .= "Subject: ".$subject."\n";
$ms .= "\n";
$ms .= $body."\n";
$ms .= "\n";
$ms .= STANDARD_NOTIFY_FOOTER;
mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
} else
{
$email = "no one";
}
addmsg("mesage sent to: ".$email, green);
addmsg("New Comment Posted", "green");
redirect(apidb_fullurl("appview.php?appId=$appId&versionId=$versionId"));
}
}
else
{

View File

@@ -2,6 +2,8 @@
include("path.php");
require(BASE."include/"."incl.php");
require(BASE."include/"."application.php");
$appId = strip_tags($_POST['appId']);
$versionId = strip_tags($_POST['versionId']);
@@ -31,7 +33,19 @@ if (!$result)
$ob = mysql_fetch_object($result);
$deletedParentId = $ob->parentId;
/* get the subject and body from the comment */
$result = mysql_query("select * FROM appComments WHERE commentId = '$commentId'");
if (!$result)
{
errorpage('Internal Database Access Error',mysql_error());
exit;
}
$ob = mysql_fetch_object($result);
$body = $ob->body;
$subject = $ob->subject;
/* delete the comment from the database */
$result = mysql_query("DELETE FROM appComments WHERE commentId = '$commentId'");
if (!$result)
@@ -47,6 +61,27 @@ if(!$result)
errorpage('Internal database error fixing up the parentId of child comments');
exit;
}
$email = getNotifyEmailAddressList($appId, $versionId);
if($email)
{
$fullAppName = "Application: ".lookupAppName($appId)." Version: ".lookupVersionName($appId, $versionId);
$ms .= apidb_fullurl("appview.php?appId=$appId&versionId=$versionId")."\n";
$ms .= "\n";
$ms .= ($current->username ? $current->username : "Anonymous")." deleted comment from ".$fullAppName."\n";
$ms .= "\n";
$ms .= "Subject: ".$subject."\n";
$ms .= "\n";
$ms .= $body."\n";
$ms .= "\n";
$ms .= STANDARD_NOTIFY_FOOTER;
mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
} else
{
$email = "no one";
}
addmsg("mesage sent to: ".$email, green);
addmsg("Comment deleted", "green");
redirect(apidb_fullurl("appview.php?appId=$appId&versionId=$versionId"));

View File

@@ -76,3 +76,24 @@ class Application {
return $list;
}
}
function lookupVersionName($appId, $versionId)
{
$result = mysql_query("SELECT versionName FROM appVersion WHERE versionId = $versionId and appId = $appId");
if(!$result || mysql_num_rows($result) != 1)
return null;
$ob = mysql_fetch_object($result);
return $ob->versionName;
}
function lookupAppName($appId)
{
$result = mysql_query("SELECT appName FROM appFamily WHERE appId = $appId");
if(!$result || mysql_num_rows($result) != 1)
return null;
$ob = mysql_fetch_object($result);
return $ob->appName;
}
?>

View File

@@ -238,4 +238,9 @@ function dumpmsgbuffer()
mysql_query("DELETE FROM sessionMessages WHERE sessionId = '$PHPSESSID'");
}
define("STANDARD_NOTIFY_FOOTER","------- You are receiving this mail because: -------\n".
"You are an maintainer of this app or an appdb administrator\n".
"to change your preverences go to: http://appdb.winehq.org/preferences.php\n");
?>

View File

@@ -351,5 +351,61 @@ function lookupEmail($userid)
return $ob->email;
}
function UserWantsEmail($userid)
{
$result = mysql_query("SELECT * FROM user_prefs WHERE userid = $userid AND name = 'send_email'");
if(!$result || mysql_num_rows($result) == 0)
{
return true;
}
$ob = mysql_fetch_object($result);
return ($ob->value == 'no' ? false : true);
}
/*
* get the email address of people to notify for this appId and versionId
*/
function getNotifyEmailAddressList($appId, $versionId)
{
$aUserId = array();
$c = 0;
$retval = "";
$query = "SELECT userId FROM ".
"appMaintainers WHERE appId = '$appId' " .
"AND versionId = '$versionId';";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
$aUserId[$c] = array($row->userId);
$c++;
}
}
$result = mysql_query("SELECT * FROM user_privs WHERE priv = 'admin'");
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
$i = array_search($row->userid, $aUserId);
if ($aUserId[$i] != array($row->userid))
{
$aUserId[$c] = array($row->userid);
$c++;
}
}
}
if ($c > 0)
{
while(list($index, list($userIdValue)) = each($aUserId))
{
if (UserWantsEmail($userIdValue))
$retval .= lookupEmail($userIdValue)." ";
}
}
return $retval;
}
?>

View File

@@ -21,3 +21,4 @@ INSERT INTO prefs_list VALUES (0, 'window:offsite', 'no', 'yes|no', 'Display off
INSERT INTO prefs_list VALUES (0, 'query:mode', 'view', 'view|edit', 'Default API details mode');
INSERT INTO prefs_list VALUES (0, 'query:hide_header', 'no', 'yes|no', 'Hide apidb header in query results');
INSERT INTO prefs_list VALUES (0, 'query:hide_sidebar', 'no', 'yes|no', 'Hide apidb sidebar in query results');
INSERT INTO prefs_list VALUES (0, 'send_email', 'yes', 'yes|no', 'Send email notifications');