[appdb] Notify Patch (this time with Patch)

Tony Lambregts tony_lambregts at telusplanet.net
Tue Nov 9 00:01:57 CST 2004


This patch is reletive to Chris Morgans Maintainer patch

you need to run the following command in the tables directory 
after the patch is applied.

mysql -u root < prefs_list.sql

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

files changed: addcomment.php
               deletecomment.php
               include/incl.php
               include/user.php
               tables/prefs_list.sql

-------------- next part --------------
diff -u -r ../appdbchris/appdb/addcomment.php ./addcomment.php
--- ../appdbchris/appdb/addcomment.php	2004-03-15 09:22:00.000000000 -0700
+++ ./addcomment.php	2004-11-08 20:44:18.000000000 -0700
@@ -2,6 +2,7 @@
     
 include("path.php");
 require(BASE."include/"."incl.php");
+require(BASE."include/"."application.php");
 
 global $current;
 
@@ -29,24 +30,46 @@
     
     $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;
-    }
-		
-    addmsg("New Comment Posted", "green");
-    redirect(apidb_fullurl("appview.php?appId=$appId&versionId=$versionId"));
+    } 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
 {
diff -u -r ../appdbchris/appdb/deletecomment.php ./deletecomment.php
--- ../appdbchris/appdb/deletecomment.php	2004-11-08 21:53:25.000000000 -0700
+++ ./deletecomment.php	2004-11-08 20:44:22.000000000 -0700
@@ -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 @@
 $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 @@
     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"));
diff -u -r ../appdbchris/appdb/include/application.php ./include/application.php
--- ../appdbchris/appdb/include/application.php	2004-03-15 09:22:03.000000000 -0700
+++ ./include/application.php	2004-11-07 18:31:23.000000000 -0700
@@ -76,3 +76,24 @@
         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;
+}
+
+?>
diff -u -r ../appdbchris/appdb/include/incl.php ./include/incl.php
--- ../appdbchris/appdb/include/incl.php	2004-03-24 08:58:57.000000000 -0700
+++ ./include/incl.php	2004-11-08 20:30:08.000000000 -0700
@@ -238,4 +238,9 @@
     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");
+
+
 ?>

diff -u -r ../appdbchris/appdb/include/user.php ./include/user.php
--- ../appdbchris/appdb/include/user.php	2004-11-08 21:53:25.000000000 -0700
+++ ./include/user.php	2004-11-08 20:37:28.000000000 -0700
@@ -351,5 +351,61 @@
     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;
+}
 
 ?>
diff -u -r ../appdbchris/appdb/tables/prefs_list.sql ./tables/prefs_list.sql
--- ../appdbchris/appdb/tables/prefs_list.sql	2004-03-24 08:51:49.000000000 -0700
+++ ./tables/prefs_list.sql	2004-11-08 14:31:25.000000000 -0700
@@ -21,3 +21,4 @@
 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');


More information about the wine-patches mailing list