[AppDB] appData / screenshot submit

Jonathan Ernst Jonathan at ErnstFamily.ch
Tue Dec 14 10:42:27 CST 2004


This patch let anonymous and registered user to submit screenshots that 
will be queued until reviewed.

As stated in the TODO:

# screenshot submission isn't very friendly.  it would be really cool if
people could submit screenshots via a web interface.  We would store the
image and related information in the database and send email to the 
database
admins and to any maintainers of the app.  They would then be able to click
on a link in the email to view the image and accept/reject it.  If the 
image
sat for too long it would be rejected and an email would be send to the
submitter saying it timed out.  If the admin/maintainer clicked on 
accept it
would go into the db like every other image.

There is a new file (see atached) to add and that is not included in the 
patch as I don't have diff on this computer so you'll ahve to add it 
yourself.
The administration part is not yet finished but I'll do it tonight.

There is a new table that should be added to the mysql database online.
(see appdb_tables.sql, table appDataQueue)

This table will allow us to do the same with user submitted links if we 
want to.

CHANGELOG:
- implemented the user friendly screenshot submitting feature


File changed:
- index.php
- screenshots.php
- include/sidebar_admin.php
- include/util.php
- tables/appdb_tables.sql
- admin/adminAppDataQueue.php (_new file_)






-------------- next part --------------
Index: index.php
===================================================================
RCS file: /home/wine/appdb/index.php,v
retrieving revision 1.9
diff -u -r1.9 index.php
--- index.php	12 Dec 2004 22:36:31 -0000	1.9
+++ index.php	14 Dec 2004 16:26:34 -0000
@@ -33,7 +33,10 @@
 stomping out Wine issues will be greatly appreciated.</p>
 
 <p>
-If you have anything to contribute (screenshots, howtos), contact us at:
+If you have screenshots or links to contribute, please browse the database and use the AppDB interface to send us your contributions.
+</p>
+<p>
+If you have anything else to contribute (howtos, etc.), contact us at:
 <a href="mailto:appdb at winehq.org">appdb at winehq.org</a><br />
 Note that this address is not for end-user support, for end user support please contact the
 wine-users mailing list or the wine newsgroup, for more information visit
Index: screenshots.php
===================================================================
RCS file: /home/wine/appdb/screenshots.php,v
retrieving revision 1.6
diff -u -r1.6 screenshots.php
--- screenshots.php	14 Dec 2004 04:37:31 -0000	1.6
+++ screenshots.php	14 Dec 2004 16:22:09 -0000
@@ -14,189 +14,227 @@
 
 if($_REQUEST['cmd'])
 {
-    if(havepriv("admin") || isMaintainer($_REQUEST['appId'], $_REQUEST['versionId']))
-    {
     //process screenshot upload
     if($_REQUEST['cmd'] == "screenshot_upload")
-    {    
-        if(!copy($_FILES['imagefile']['tmp_name'], "data/screenshots/".$_REQUEST['appId']."-".$_REQUEST['versionId']."-".basename($_FILES['imagefile']['name'])))
-        {
-            // whoops, copy failed. do something
-            errorpage("debug: copy failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']);
-            exit;
-        }
+    {   
+        if(havepriv("admin") || isMaintainer($_REQUEST['appId'], $_REQUEST['versionId']))
+        {     
+            if(!copy($_FILES['imagefile']['tmp_name'], "data/screenshots/".$_REQUEST['appId']."-".$_REQUEST['versionId']."-".basename($_FILES['imagefile']['name'])))
+            {
+                // whoops, copy failed. do something
+                errorpage("debug: copy failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']);
+                exit;
+            }
 
-        $query = "INSERT INTO appData VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId'].", 'image', ".
-        "'".addslashes($_REQUEST['screenshot_desc'])."', '".$_REQUEST['appId']."-".$_REQUEST['versionId']."-".basename($_FILES['imagefile']['name'])."')";
+            $query = "INSERT INTO appData VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId'].", 'image', ".
+                     "'".addslashes($_REQUEST['screenshot_desc'])."', '".$_REQUEST['appId']."-".$_REQUEST['versionId']."-".basename($_FILES['imagefile']['name'])."')";
 
-        if(debugging()) addmsg("<p align=center><b>query:</b> $query </p>",green);
+            if(debugging()) addmsg("<p align=center><b>query:</b> $query </p>","green");
     
-        if (mysql_query($query))
-        {
-            //success
-            $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
-            if($email)
-            {
-                 $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
-                 $ms .= APPDB_ROOT."screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\n";
-                 $ms .= "\n";
-                 $ms .= ($_SESSION['current']->username ? $_SESSION['current']->username : "Anonymous")." added screenshot ".$_REQUEST['screenshot_desc']." to ".$fullAppName."\n";
-                 $ms .= "\n";
-                 $ms .= STANDARD_NOTIFY_FOOTER;
+            if (mysql_query($query))
+            {
+                //success
+                $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
+                if($email)
+                {
+                    $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
+                    $ms .= APPDB_ROOT."screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\n";
+                    $ms .= "\n";
+                    $ms .= $_SESSION['current']->username." added screenshot ".$_REQUEST['screenshot_desc']." to ".$fullAppName."\n";
+                    $ms .= "\n";
+                    $ms .= STANDARD_NOTIFY_FOOTER;
+ 
+                    mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
+                } else
+                {
+                    $email = "no one";
+                }
+                addmsg("mesage sent to: ".$email, "green");
 
-                 mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
-            } else
+                addmsg("The image was successfully added into the database", "green");
+                redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
+            }
+            else
+            {
+                //error
+                $statusMessage = "<p><b>Database Error!<br>".mysql_error()."</b></p>\n";
+                addmsg($statusMessage, "red");
+            }
+        } else // we are a normal user or an anonymous and submitted a screenshot
+        {   
+            if(!$str_data = addslashes(fread(fopen($_FILES['imagefile']['tmp_name'], "r"), filesize($_FILES['imagefile']['tmp_name']))))
             {
-                $email = "no one";
+                // whoops, copy failed. do something
+                errorpage("debug: reading of file failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']);
+                exit;
             }
-            addmsg("mesage sent to: ".$email, green);
+            $str_query = "INSERT INTO appDataQueue VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId'].", 'image', ".
+                     "'".addslashes($_REQUEST['screenshot_desc'])."', '".$_REQUEST['appId']."-".$_REQUEST['versionId']."-".basename($_FILES['imagefile']['name'])."', '$str_data', NOW())";
 
-            addmsg("The image was successfully added into the database", "green");
-            redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
-        }
-        else
-        {
-            //error
-            $statusMessage = "<p><b>Database Error!<br>".mysql_error()."</b></p>\n";
-            addmsg($statusMessage, "red");
+            if(debugging()) addmsg("<p align=center><b>query:</b> $str_query </p>","green");
+    
+            if (mysql_query($str_query))
+            {
+                //success
+                $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
+                if($email)
+                {
+                    $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
+                    $ms .= APPDB_ROOT."admin/adminAppDataQueue.php?sub=inside_form&queueId=".mysql_insert_id()."\n";
+                    $ms .= "\n";
+                    $ms .= ($_SESSION['current']->username ? $_SESSION['current']->username : "an anonymous user")." submitted a screenshot ".$_REQUEST['screenshot_desc']." for ".$fullAppName."\n";
+                    $ms .= "\n";
+                    $ms .= STANDARD_NOTIFY_FOOTER;
+ 
+                    mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
+                } else
+                {
+                    $email = "no one";
+                }
+                addmsg("mesage sent to: ".$email, "green");
+
+                addmsg("The image you submitted will be added to the database database after being reviewed", "green");
+                redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
+            }
+            else
+            {
+                //error
+                $statusMessage = "<p><b>Database Error!<br>".mysql_error()."</b></p>\n";
+                addmsg($statusMessage, "red");
+            }
         }
-    } else
+    } elseif($_REQUEST['cmd'] == "delete")
     {
-        if($_REQUEST['cmd'] == "delete")
-        {
+        if(havepriv("admin") || isMaintainer($_REQUEST['appId'], $_REQUEST['versionId']))
+        {     
             $result = mysql_query("DELETE FROM appData WHERE id = ".$_REQUEST['imageId']);
             if($result)
+            {
+                $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
+                if($email)
                 {
-                    $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
-                    if($email)
-                    {
-                        $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
-                        $ms .= APPDB_ROOT."screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\n";
-                        $ms .= "\n";
-                        $ms .= ($_SESSION['current']->username ? $_SESSION['current']->username : "Anonymous")." deleted screenshot from ".$fullAppName."\n";
-                        $ms .= "\n";
-                        $ms .= STANDARD_NOTIFY_FOOTER;
+                    $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
+                    $ms .= APPDB_ROOT."screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\n";
+                    $ms .= "\n";
+                    $ms .= ($_SESSION['current']->username ? $_SESSION['current']->username : "Anonymous")." deleted screenshot from ".$fullAppName."\n";
+                    $ms .= "\n";
+                    $ms .= STANDARD_NOTIFY_FOOTER;
    
-                        mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
+                    mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
  
-                    } else
-                    {
-                        $email = "no one";
-                    }
-                    addmsg("mesage sent to: ".$email, green);
-
-                    addmsg("Image deleted", "green");
-                    redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
                 } else
                 {
-                    addmsg("Failed to delete image: ".mysql_error(), "red");
-                    redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
+                    $email = "no one";
                 }
+                addmsg("mesage sent to: ".$email, "green");
+
+                addmsg("Image deleted", "green");
+                redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
+            } else
+            {
+                addmsg("Failed to delete image: ".mysql_error(), "red");
+                redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
             }
-        } 
-    }
+        }
+    } 
     exit;
 }
 
+// we didn't issue any command
 if($_REQUEST['versionId'])
     $result = mysql_query("SELECT * FROM appData WHERE type = 'image' AND appId = ".$_REQUEST['appId']." AND versionId = ".$_REQUEST['versionId']);
 else
     $result = mysql_query("SELECT * FROM appData WHERE type = 'image' AND appId = ".$_REQUEST['appId']." ORDER BY versionId");
      
-if((!$result || !mysql_num_rows($result)) && (!havepriv("admin") && !isMaintainer($_REQUEST['appId'], $_REQUEST['versionId']))) 
-{
-    errorpage("No Screenshots Found","There are no screenshots currently linked to this application.");
-    exit;
-} else
+$app=new Application($_REQUEST['appId']);
+apidb_header("Screenshots");
+if($result && mysql_num_rows($result))
 {
-    $app=new Application($_REQUEST['appId']);
-    apidb_header("Screenshots");
-    if($result && mysql_num_rows($result))
-    {
-        echo html_frame_start("Screenshot Gallery for ".$app->data->appName,500);
+    echo html_frame_start("Screenshot Gallery for ".$app->data->appName,500);
 
-        // display thumbnails
-        $c = 1;
-        echo "<div align=center><table><tr>\n";
-        while($ob = mysql_fetch_object($result))
+    // display thumbnails
+    $c = 1;
+    echo "<div align=center><table><tr>\n";
+    while($ob = mysql_fetch_object($result))
+    {
+        if(!$_REQUEST['versionId'] && $ob->versionId!=$currentVersionId)
         {
-            if(!$_REQUEST['versionId'] && $ob->versionId!=$currentVersionId)
+            if($currentVersionId)
             {
-                if($currentVersionId)
-                {
-                    echo "</tr></table></div>\n";
-                    echo html_frame_end();
-                }
-                $currentVersionId=$ob->versionId;
-                echo html_frame_start("Version ".lookupVersionName($_REQUEST['appId'], $currentVersionId));
-                echo "<div align=center><table><tr>\n";
+                echo "</tr></table></div>\n";
+                echo html_frame_end();
+                $c=1;
             }
-            // set img tag
-            $imgSRC = '<img src="appimage.php?imageId='.$ob->id.'&width=128&height=128" border=0 alt="'.$ob->description.'">';
+            $currentVersionId=$ob->versionId;
+            echo html_frame_start("Version ".lookupVersionName($_REQUEST['appId'], $currentVersionId));
+            echo "<div align=center><table><tr>\n";
+        }
+        // set img tag
+        $imgSRC = '<img src="appimage.php?imageId='.$ob->id.'&width=128&height=128" border=0 alt="'.$ob->description.'">';
 
-            // get image size
-            $size = getimagesize("data/screenshots/".$ob->url);
+        // get image size
+        $size = getimagesize("data/screenshots/".$ob->url);
 
-            // generate random tag for popup window
-            $randName = generate_passwd(5);
+        // generate random tag for popup window
+        $randName = generate_passwd(5);
 
-            // set image link based on user pref
-            $img = '<a href="javascript:openWin(\'appimage.php?imageId='.$ob->id.'\',\''.$randName.'\','.$size[0].','.$size[1].');">'.$imgSRC.'</a>';
-            if (loggedin())
+        // set image link based on user pref
+        $img = '<a href="javascript:openWin(\'appimage.php?imageId='.$ob->id.'\',\''.$randName.'\','.$size[0].','.$size[1].');">'.$imgSRC.'</a>';
+        if (loggedin())
+        {
+            if ($_SESSION['current']->getpref("window:screenshot") == "no")
             {
-                if ($_SESSION['current']->getpref("window:screenshot") == "no")
-                {
-                    $img = '<a href="appimage.php?imageId='.$ob->id.'">'.$imgSRC.'</a>';
-                }
+                $img = '<a href="appimage.php?imageId='.$ob->id.'">'.$imgSRC.'</a>';
             }
+        }
 
-            // display image
-            echo "<td>\n";
-            echo html_frame_start(substr(stripslashes($ob->description),0,20),128,"",0);
-            echo $img;
-
-            //show admin delete link
-            if(loggedin() && (havepriv("admin") || isMaintainer($_REQUEST['appId'], $_REQUEST['versionId'])))
-            {
-                echo "<div align=center>[<a href='screenshots.php?cmd=delete&imageId=$ob->id&appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."'>Delete Image</a>]</div>";
-            }
+        // display image
+        echo "<td>\n";
+        echo html_frame_start(substr(stripslashes($ob->description),0,20),128,"",0);
+        echo $img;
 
-            echo html_frame_end("&nbsp;");
-            echo "</td>\n";
+        //show admin delete link
+        if(loggedin() && (havepriv("admin") || isMaintainer($_REQUEST['appId'], $_REQUEST['versionId'])))
+        {
+            echo "<div align=center>[<a href='screenshots.php?cmd=delete&imageId=$ob->id&appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."'>Delete Image</a>]</div>";
+        }
 
-            // end row if counter of 3
-            if ($c % 3 == 0) echo "</tr><tr>\n";
+        echo html_frame_end("&nbsp;");
+        echo "</td>\n";
 
-            $c++;
-        }
-        echo "</tr></table></div><br>\n";
+        // end row if counter of 3
+        if ($c % 3 == 0) echo "</tr><tr>\n";
 
-        echo html_frame_end("Click thumbnail to view image in new window.");
+        $c++;
     }
-    if((havepriv("admin") || isMaintainer($_REQUEST['appId'], $_REQUEST['versionId']))
-       && $_REQUEST['versionId'])
-    {
-        //image upload box
-        echo '<form enctype="multipart/form-data" action="screenshots.php" name=imageForm method="post">',"\n";
-        echo html_frame_start("Upload Screenshot","400","",0);
-        echo '<table border=0 cellpadding=6 cellspacing=0 width="100%">',"\n";
+    echo "</tr></table></div><br>\n";
+
+    echo html_frame_end("Click thumbnail to view image in new window.");
+} else {
+	echo "<p align=\"center\">There are currently no screenshot for the selected version of this application.";
+	echo "<br />Please consider submitting a screenshot for the selected version yourself.</p>";
+}
+
+if($_REQUEST['versionId'])
+{
+    //image upload box
+    echo '<form enctype="multipart/form-data" action="screenshots.php" name=imageForm method="post">',"\n";
+    echo html_frame_start("Upload Screenshot","400","",0);
+    echo '<table border=0 cellpadding=6 cellspacing=0 width="100%">',"\n";
       
-        echo '<tr><td class=color1>Image</td><td class=color0><input name="imagefile" type="file"></td></tr>',"\n";
-        echo '<tr><td class=color1>Description</td><td class=color0><input type="text" name="screenshot_desc"></td></tr>',"\n";
+    echo '<tr><td class=color1>Image</td><td class=color0><input name="imagefile" type="file"></td></tr>',"\n";
+    echo '<tr><td class=color1>Description</td><td class=color0><input type="text" name="screenshot_desc"></td></tr>',"\n";
        
-        echo '<tr><td colspan=2 align=center class=color3><input type="submit" value="Send File"></td></tr>',"\n";
+    echo '<tr><td colspan=2 align=center class=color3><input type="submit" value="Send File"></td></tr>',"\n";
        
-        echo '</table>',"\n";
-        echo html_frame_end();
-        echo '<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />',"\n";
-        echo '<input type="hidden" name="cmd" value="screenshot_upload" />',"\n";
-        echo '<input type="hidden" name="appId" value="'.$_REQUEST['appId'].'" />',"\n";
-        echo '<input type="hidden" name="versionId" value="'.$_REQUEST['versionId'].'"></form />',"\n";
-    }
-    echo html_back_link(1);
-
-    apidb_footer();
-
+    echo '</table>',"\n";
+    echo html_frame_end();
+    echo '<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />',"\n";
+    echo '<input type="hidden" name="cmd" value="screenshot_upload" />',"\n";
+    echo '<input type="hidden" name="appId" value="'.$_REQUEST['appId'].'" />',"\n";
+    echo '<input type="hidden" name="versionId" value="'.$_REQUEST['versionId'].'"></form />',"\n";
 }
+echo html_back_link(1);
+apidb_footer();
 
-?>
+?>
\ No newline at end of file
Index: include/sidebar_admin.php
===================================================================
RCS file: /home/wine/appdb/include/sidebar_admin.php,v
retrieving revision 1.7
diff -u -r1.7 sidebar_admin.php
--- include/sidebar_admin.php	12 Dec 2004 03:55:14 -0000	1.7
+++ include/sidebar_admin.php	14 Dec 2004 16:30:42 -0000
@@ -16,6 +16,7 @@
     $g->addmisc("&nbsp;");
     $g->add("List Users", $apidb_root."admin/");
     $g->add("View App Queue (".getQueuedAppCount().")", $apidb_root."admin/adminAppQueue.php");
+    $g->add("View App Data Queue (".getQueuedAppDataCount().")", $apidb_root."admin/adminAppDataQueue.php");
     $g->add("View Maintainer Queue (".getQueuedMaintainerCount().")", $apidb_root."admin/adminMaintainerQueue.php");
     $g->add("View Maintainers (".getMaintainerCount().")", $apidb_root."admin/adminMaintainers.php");
 
Index: include/util.php
===================================================================
RCS file: /home/wine/appdb/include/util.php,v
retrieving revision 1.8
diff -u -r1.8 util.php
--- include/util.php	13 Dec 2004 03:50:11 -0000	1.8
+++ include/util.php	14 Dec 2004 16:31:30 -0000
@@ -243,6 +243,15 @@
 }
 
 /* get the number of applications in the appQueue table */
+function getQueuedAppDataCount()
+{
+    $qstring = "SELECT count(*) as queued_appdata FROM appDataQueue";
+    $result = mysql_query($qstring);
+    $ob = mysql_fetch_object($result);
+    return $ob->queued_appdata;
+}
+
+/* get the number of applications in the appQueue table */
 function getQueuedMaintainerCount()
 {
     $qstring = "SELECT count(*) as queued_maintainers FROM appMaintainerQueue";
Index: tables/appdb_tables.sql
===================================================================
RCS file: /home/wine/appdb/tables/appdb_tables.sql,v
retrieving revision 1.9
diff -u -r1.9 appdb_tables.sql
--- tables/appdb_tables.sql	14 Dec 2004 02:36:49 -0000	1.9
+++ tables/appdb_tables.sql	14 Dec 2004 16:20:19 -0000
@@ -13,6 +13,7 @@
 drop table if exists appOwners;
 drop table if exists appComments;
 drop table if exists appData;
+drop table if exists appDataQueue;
 drop table if exists appQueue;
 drop table if exists appCrosslink;
 drop table if exists appBundle;
@@ -184,7 +185,6 @@
 );
 
 
-
 /*
  * links to screenshots and other stuff
  */
@@ -198,6 +198,24 @@
 	key(id),
 	index(appId),
 	index(versionId)
+);
+
+
+/*
+ * links to screenshots and other stuff waiting to be accepted
+ */
+create table appDataQueue (
+	queueid		int not null auto_increment,
+	queueappId		int not null,
+	queueversionId	int default 0,
+	queuetype		enum('image', 'url'),
+	queuedescription	text,
+	queueurl		varchar(255),
+	queuecontent	blob,
+	submitTime	timestamp,
+	key(queueid),
+	index(queueappId),
+	index(queueversionId)
 );
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winehq.org/pipermail/wine-patches/attachments/20041214/9a9dca72/adminAppDataQueue.htm


More information about the wine-patches mailing list