[AppDB] Main App should have a random screenshot from it's versions.
Jonathan Ernst
Jonathan at ErnstFamily.ch
Fri Dec 10 07:25:41 CST 2004
Change Log:
- Main App has a random screenshot from it's versions.
- Versions have a random screenshot from their screenshots
- code cleanup (more php style than c style + better indentation +
comments + replaced globally some registered vars)
Files changed:
- appview.php
-------------- next part --------------
Index: appview.php
===================================================================
RCS file: /home/wine/appdb/appview.php,v
retrieving revision 1.12
diff -u -r1.12 appview.php
--- appview.php 10 Dec 2004 00:18:01 -0000 1.12
+++ appview.php 10 Dec 2004 13:14:04 -0000
@@ -1,11 +1,9 @@
<?
+/**********************************/
+/* code to display an application */
+/**********************************/
-
-/*
- * Application Database - appview.php
- *
- */
-
+# APPLICATION ENVIRONMENT
include("path.php");
require(BASE."include/"."incl.php");
require(BASE."include/"."application.php");
@@ -18,41 +16,36 @@
require(BASE."include/"."maintainer.php");
-global $apidb_root;
// NOTE: app Owners will see this menu too, make sure we don't show admin-only options
-function admin_menu()
-{
- global $appId;
- global $versionId;
+function admin_menu() {
global $apidb_root;
$m = new htmlmenu("Admin");
- if($versionId)
- {
- $m->add("Add Note", $apidb_root."admin/addAppNote.php?appId=$appId&versionId=$versionId");
+ if($_REQUEST[versionId]) {
+ $m->add("Add Note", $apidb_root."admin/addAppNote.php?appId=$appId&versionId=".$_REQUEST['versionId']);
$m->addmisc(" ");
- $m->add("Edit Version", $apidb_root."admin/editAppVersion.php?appId=$appId&versionId=$versionId");
+ $m->add("Edit Version", $apidb_root."admin/editAppVersion.php?appId=$appId&versionId=".$_REQUEST['versionId']);
- $url = $apidb_root."admin/deleteAny.php?what=appVersion&versionId=$versionId&confirmed=yes";
+ $url = $apidb_root."admin/deleteAny.php?what=appVersion&versionId=".$_REQUEST['versionId']."&confirmed=yes";
$m->add("Delete Version", "javascript:deleteURL(\"Are you sure?\", \"".$url."\")");
- } else
- {
- $m->add("Add Version", $apidb_root."admin/addAppVersion.php?appId=$appId");
+ }
+ else {
+ $m->add("Add Version", $apidb_root."admin/addAppVersion.php?appId=".$_REQUEST['appId']);
$m->addmisc(" ");
- $m->add("Edit App", $apidb_root."admin/editAppFamily.php?appId=$appId");
+ $m->add("Edit App", $apidb_root."admin/editAppFamily.php?appId=".$_REQUEST['appId']);
// global admin options
if(havepriv("admin"))
{
- $url = $apidb_root."admin/deleteAny.php?what=appFamily&appId=$appId&confirmed=yes";
+ $url = $apidb_root."admin/deleteAny.php?what=appFamily&appId=".$_REQUEST['appId']."&confirmed=yes";
$m->add("Delete App", "javascript:deleteURL(\"Are you sure?\", \"".$url."\")");
$m->addmisc(" ");
- $m->add("Edit Owners", $apidb_root."admin/editAppOwners.php?appId=$appId");
- $m->add("Edit Bundle", $apidb_root."admin/editBundle.php?bundleId=$appId");
+ $m->add("Edit Owners", $apidb_root."admin/editAppOwners.php?appId=".$_REQUEST['appId']);
+ $m->add("Edit Bundle", $apidb_root."admin/editBundle.php?bundleId=".$_REQUEST['appId']);
}
}
@@ -60,36 +53,42 @@
}
-function get_screenshot_img($appId, $versionId)
-{
- global $apidb_root;
-
- if(!$versionId)
- $versionId = 0;
+/**
+ * Get a random image for a particular version of an app.
+ * If the version is not set, get a random app image
+ */
+function get_screenshot_img($appId, $versionId="") {
+ global $apidb_root;
- $result = mysql_query("SELECT * FROM appData WHERE appId = $appId AND versionId = $versionId AND type = 'image'");
+ if($versionId) {
+ $result = mysql_query("SELECT *, RAND() AS rand FROM appData WHERE appId = $appId AND versionId = $versionId AND type = 'image' ORDER BY rand");
+ }
+ else {
+ $result = mysql_query("SELECT *, RAND() AS rand FROM appData WHERE appId = $appId AND type = 'image' ORDER BY rand");
+ }
- if(!$result || !mysql_num_rows($result))
- {
- $imgFile = "<img src='".$apidb_root."images/no_screenshot.gif' border=0 alt='No Screenshot'>";
- }
- else
- {
- $ob = mysql_fetch_object($result);
- $imgFile = "<img src='appimage.php?imageId=$ob->id&width=128&height=128' ".
- "border=0 alt='$ob->description'>";
- }
+ if(!$result || !mysql_num_rows($result)) {
+ $imgFile = "<img src='".$apidb_root."images/no_screenshot.gif' border=0 alt='No Screenshot' />";
+ }
+ else {
+ $ob = mysql_fetch_object($result);
+ $imgFile = "<img src='appimage.php?imageId=$ob->id&width=128&height=128' ".
+ "border=0 alt='$ob->description' />";
+ }
- $img = html_frame_start("",'128','',2);
+ $img = html_frame_start("",'128','',2);
+ if($versionId)
$img .= "<a href='screenshots.php?appId=$appId&versionId=$versionId'>$imgFile</a>";
- $img .= html_frame_end()."<br>";
+ else
+ $img .= $imgFile;
+ $img .= html_frame_end()."<br />";
- return $img;
+ return $img;
}
-function display_catpath($catId)
-{
+/* TODO: what does it do ? */
+function display_catpath($catId) {
$cat = new Category($catId);
$catFullPath = make_cat_path($cat->getCategoryPath());
@@ -98,53 +97,48 @@
echo html_frame_end();
}
+
/* display the SUB apps that belong to this app */
-function display_bundle($appId)
-{
- $result = mysql_query("SELECT appFamily.appId, appName, description FROM appBundle, appFamily ".
- "WHERE bundleId = $appId AND appBundle.appId = appFamily.appId");
- if(!$result || mysql_num_rows($result) == 0)
- {
- // do nothing
- return;
+function display_bundle($appId) {
+ $result = mysql_query("SELECT appFamily.appId, appName, description FROM appBundle, appFamily ".
+ "WHERE bundleId = $appId AND appBundle.appId = appFamily.appId");
+ if(!$result || mysql_num_rows($result) == 0) {
+ return; // do nothing
}
- echo html_frame_start("","98%","",0);
- echo "<table width='100%' border=0 cellpadding=3 cellspacing=1>\n\n";
+ echo html_frame_start("","98%","",0);
+ echo "<table width='100%' border=0 cellpadding=3 cellspacing=1>\n\n";
- echo "<tr class=color4>\n";
- echo " <td><font color=white>Application Name</font></td>\n";
- echo " <td><font color=white>Description</font></td>\n";
- echo "</tr>\n\n";
+ echo "<tr class=color4>\n";
+ echo " <td><font color=white>Application Name</font></td>\n";
+ echo " <td><font color=white>Description</font></td>\n";
+ echo "</tr>\n\n";
+
+ $c = 0;
+ while($ob = mysql_fetch_object($result)) {
+ //set row color
+ $bgcolor = ($c % 2 == 0) ? "color0" : "color1";
+
+ //format desc
+ $desc = substr(stripslashes($ob->description),0,50);
+ if(strlen($desc) == 50) $desc .= " ...";
+
+ //display row
+ echo "<tr class=$bgcolor>\n";
+ echo " <td><a href='appview.php?appId=$ob->appId'>".stripslashes($ob->appName)."</a></td>\n";
+ echo " <td>$desc </td>\n";
+ echo "</tr>\n\n";
- $c = 0;
- while($ob = mysql_fetch_object($result))
- {
- //set row color
- $bgcolor = ($c % 2 == 0) ? "color0" : "color1";
-
- //format desc
- $desc = substr(stripslashes($ob->description),0,50);
- if(strlen($desc) == 50)
- $desc .= " ...";
-
- //display row
- echo "<tr class=$bgcolor>\n";
- echo " <td><a href='appview.php?appId=$ob->appId'>".stripslashes($ob->appName)."</a></td>\n";
- echo " <td>$desc </td>\n";
- echo "</tr>\n\n";
-
- $c++;
+ $c++;
}
- echo "</table>\n\n";
- echo html_frame_end();
+ echo "</table>\n\n";
+ echo html_frame_end();
}
/* display the notes for the app */
-function display_notes($appId, $versionId = 0)
-{
+function display_notes($appId, $versionId = 0) {
$result = mysql_query("SELECT noteId,noteTitle FROM appNotes ".
"WHERE appId = $appId AND versionId = $versionId");
@@ -230,23 +224,22 @@
}
}
-/* code to VIEW an application & versions */
$appId = $_REQUEST['appId'];
$versionId = $_REQUEST['versionId'];
-if(!is_numeric($appId))
-{
+######################################################
+# We want to see an application family (=no version) #
+######################################################
+if(!is_numeric($appId)) {
errorpage("Something went wrong with the IDs");
exit;
}
-if($appId && !$versionId)
-{
+if($appId && !$versionId) {
$app = new Application($appId);
$data = $app->data;
- if(!$data)
- {
+ if(!$data) {
// Oops! application not found or other error. do something
errorpage('Internal Database Access Error');
exit;
@@ -272,9 +265,6 @@
//set URL
$appLinkURL = ($data->webPage) ? "<a href='$data->webPage'>".substr(stripslashes($data->webPage),0,30)."</a>": " ";
- //set Image
- $img = get_screenshot_img($appId, $versionId);
-
//start display application
echo html_frame_start("","98%","",0);
@@ -293,10 +283,10 @@
//display notes
display_notes($appId);
- //main URL
+ // main URL
echo " <tr class=color1 valign=top><td align=right> <b>URL</b></td><td>".$appLinkURL."</td></tr>\n";
- //optional links
+ // optional links
$result = mysql_query("SELECT * FROM appData WHERE appId = $appId AND type = 'url'");
if($result && mysql_num_rows($result) > 0)
{
@@ -307,7 +297,11 @@
}
echo " </td></tr>\n";
}
-
+
+ // image
+ $img = get_screenshot_img($appId);
+ echo "<tr><td align=center colspan=2>$img</td></tr>\n";
+
// display app owner
$result = mysql_query("SELECT * FROM appOwners WHERE appId = $appId");
if($result && mysql_num_rows($result) > 0)
@@ -380,7 +374,7 @@
echo " </table>\n"; /* close the table that contains the whole left hand side of the upper table */
- //Desc
+ // description
echo " <td class=color2 valign=top width='100%'>\n";
echo " <table width='100%' border=0><tr><td width='100%' valign=top><b>Description</b><br>\n";
echo add_br(stripslashes($data->description));
@@ -389,17 +383,20 @@
echo html_frame_end("For more details and user comments, view the versions of this application.");
- //display versions
+ // display versions
display_versions($appId,$app->getAppVersionList());
- //display bundle
+ // display bundle
display_bundle($appId);
// disabled for now
//log_application_visit($appId);
}
-else if($appId && $versionId)
-{
+
+#######################################
+# We want to see a particular version #
+#######################################
+else if($appId && $versionId) {
$app = new Application($appId);
$data = $app->data;
if(!$data )
@@ -457,9 +454,8 @@
//notes
display_notes($appId, $versionId);
- //Image
+ // image
$img = get_screenshot_img($appId, $versionId);
-
echo "<tr><td align=center colspan=2>$img</td></tr>\n";
// Display all maintainers of this application
@@ -610,15 +606,15 @@
view_app_comments($appId, $versionId);
}
-else
-{
+else {
// Oops! Called with no params, bad llamah!
errorpage('Page Called with No Params!');
exit;
}
+?>
-echo p();
+<p> </p>
+<?
apidb_footer();
-
-?>
+?>
\ No newline at end of file
More information about the wine-patches
mailing list