[AppDB] Let users browse vendors.

Tony Lambregts tony.lambregts at gmail.com
Sun Oct 23 00:38:31 CDT 2005


There was an extra line added at the end  of include/vendor.php in the last one 
that broke some things. doh!

Change log: Let users browse vendors and get rid of some duplication of
code.

Files Changed: vendorview.php admin/editVendor.php include/sidebar.php
include/sidebar_admin.php include/vendor.php

Files Removed: include/addVendor.php admin/adminVendor.php

-------------- next part --------------
Index: vendorview.php
===================================================================
RCS file: /home/wine/appdb/vendorview.php,v
retrieving revision 1.11
diff -u -r1.11 vendorview.php
--- vendorview.php	9 Feb 2005 23:52:49 -0000	1.11
+++ vendorview.php	23 Oct 2005 02:14:13 -0000
@@ -7,69 +7,105 @@
  * application environment
  */ 
 include("path.php");
-require(BASE."include/incl.php");
-require(BASE."include/application.php");
+require_once(BASE."include/incl.php");
+require_once(BASE."include/application.php");
+require_once(BASE."include/vendor.php");
 
-$vendorId = $_REQUEST['vendorId'];
+$oVendor = new Vendor($_REQUEST['vendorId']);
 
-//exit with error if no vendor
-if(!$vendorId) {
-    errorpage("No vendor ID specified!");
-    exit;
-}
-
-//get vendor, die with error if no match
-$result = query_appdb("SELECT * FROM vendor WHERE vendorId = $vendorId");
-if(!$result || mysql_num_rows($result) != 1) {
-    errorpage("Invalid vendor ID!");
-    exit;
-}
-
-//show admin sidebar if user is admin
-if($_SESSION['current']->hasPriv("admin")) {
-    apidb_sidebar_add("admin_menu");
-}
+if ($_REQUEST['sub'])
+{
+    if(!$_SESSION['current']->hasPriv("admin"))
+    {
+        errorpage("Insufficient privileges.");
+        exit;
+    }
+
+    if($_REQUEST['sub'] == 'delete')
+    {
+        $oVendor->delete();
+        redirect($_SERVER['PHP_SELF']);
+   }
 
-//get data
-$vendor = mysql_fetch_object($result);
+} 
 
-//display page
-apidb_header("View Vendor");
-echo html_frame_start("Vendor Information",500);
 
-echo "Vendor Name: $vendor->vendorName <br />\n";
+if($oVendor->iVendorId)
+{
+    //display page
+    apidb_header("View Vendor");
+    echo html_frame_start("Vendor Information",500);
 
-if ($vendor->vendorURL) {
-	echo "Vendor URL:  <a href='$vendor->vendorURL'>$vendor->vendorURL</a> <br />\n";
-}
+    echo 'Vendor Name: '.$oVendor->sName.'<br />',"\n";
 
-$result = query_appdb("SELECT * FROM appFamily WHERE vendorId = $vendorId ORDER BY appName");
-if($result)
-{
-    echo "<br />Applications by $vendor->vendorName<br /><ol>\n";
-    while($app = mysql_fetch_object($result))
-	{
-	    echo "<li> <a href='appview.php?appId=$app->appId'> $app->appName </a> </li>\n";
-	}
-    echo "</ol>\n";
-}
+    if ($oVendor->sWebpage)
+        echo 'Vendor URL:  <a href="'.$oVendor->sWebpage.'">'.$oVendor->vendorURL.'</a> <br />',"\n";
 
-echo html_frame_end();
-echo html_back_link(1);
-apidb_footer();
 
+    if($oVendor->aApplicationsIds)
+    {
+        echo '<br />Applications by '.$oVendor->sName.'<br /><ol>',"\n";
+        foreach($oVendor->aApplicationsIds as $iAppId)
+        {
+            $oApp  = new application($iAppId);
+            echo '<li> <a href="appview.php?appId='.$oApp->iAppId.'">'.$oApp->sName.'</a> </li>',"\n";
+        }
+        echo '.</ol>',"\n";
+    }
 
 
-// SUBS //
+    echo html_frame_end();
+    echo html_back_link(1);
+    apidb_footer();
 
-//admin menu for sidebar
-function admin_menu()
+}
+else
 {
-    global $vendorId;
+    apidb_header("View Vendors");
+
+    //get available vendors
+    $sQuery = "SELECT vendorId FROM vendor ORDER BY vendorName, vendorId;";
+    $hResult = query_appdb($sQuery);
+
+    // show vendorlist
+    echo "<table width='100%' border=0 cellpadding=3 cellspacing=0>\n\n";
+
+    echo '<tr class="color4">',"\n";
+    echo '<td>Vendor name</td>',"\n";
+    echo '<td>Vendor\'s Web Page</td>',"\n";
+    echo '<td align="right">linked Apps</td>',"\n";
+    if ($_SESSION['current']->hasPriv("admin"))
+    {
+        echo '<td align="center">Action</td>',"\n";
+    }
+    echo '</tr>',"\n";
+        
+    $c = 1;
+    while($ob = mysql_fetch_object($hResult))
+    {
+        if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
+        $oVendor = new Vendor($ob->vendorId);
+        echo '<tr class="'.$bgcolor.'">',"\n";
+        echo '<td><a href="'.BASE.'vendorview.php?vendorId='.$oVendor->iVendorId.'">'.$oVendor->sName.'</a></td>',"\n";
+        echo '<td><a href="'.$oVendor->sWebpage.'">'.substr($oVendor->sWebpage,0,30).'</a></td>',"\n";
+        echo '<td align="right">'.sizeof($oVendor->aApplicationsIds).'</td>',"\n";
+        if ($_SESSION['current']->hasPriv("admin"))
+        {
+            echo '<td align="center">',"\n";
+            echo '[<a href="'.BASE.'admin/editVendor.php?iVendorId='.$oVendor->iVendorId.'">edit</a>]',"\n";
+            if(!sizeof($oVendor->aApplicationsIds)) 
+                echo '&nbsp[<a href="'.$_SERVER['PHP_SELF'].'?sub=delete&vendorId='.$oVendor->iVendorId.'">delete</a>]',"\n";
+            echo '</td>',"\n";
+        }
+        echo '</tr>',"\n";
+        $c++;
+    }
+
+    echo '<tr><td>',"\n";
+    echo html_back_link(1);
+    echo '</td></tr></table>',"\n";
+    apidb_footer();
 
-    $m = new htmlmenu("Admin");
-    $m->add("Edit this vendor", "admin/editVendor.php?vendorId=$vendorId");
-    $m->done();
 }
 
 ?>
Index: admin/editVendor.php
===================================================================
RCS file: /home/wine/appdb/admin/editVendor.php,v
retrieving revision 1.8
diff -u -r1.8 editVendor.php
--- admin/editVendor.php	21 Oct 2005 02:48:27 -0000	1.8
+++ admin/editVendor.php	23 Oct 2005 02:14:13 -0000
@@ -1,44 +1,39 @@
 <?php
 include("path.php");
-require(BASE."include/incl.php");
-require(BASE."include/vendor.php");
+require_once(BASE."include/incl.php");
+require_once(BASE."include/vendor.php");
 
 if(!$_SESSION['current']->hasPriv("admin"))
 {
     errorpage();
     exit;
 }
-$oVendor = new Vendor($_REQUEST['vendorId']);
-if($_REQUEST['submit'])
+
+$oVendor = new Vendor($_REQUEST['iVendorId']);
+if($_REQUEST['Submit'])
 {
-    $oVendor->update($_REQUEST['name'],$_REQUEST['webpage']);
-    redirect(apidb_fullurl("admin/adminVendors.php"));
+    $oVendor->update($_REQUEST['sName'],$_REQUEST['sWebpage']);
+    redirect(apidb_fullurl("vendorview.php"));
 }
 else
 {
-    apidb_header("Edit Vendor");
-    echo "<form method=\"post\" action=\"addVendor.php\">
-          <input type=\"hidden\" name=\"vendorId\" value=\"".$oVendor->iVendorId."\" /> 
-          <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
-            <tr>
-              <td width=\"15%\" class=\"box-label\"><b>Vendor name</b></td>
-              <td class=\"box-body\">
-                <input type=\"text\" size=\"50\" name=\"name\" value=\"".$oVendor->sName."\" /> 
-              </td>
-            </tr>
-            <tr>
-              <td width=\"15%\" class=\"box-label\"><b>Vendor URL</b></td>
-              <td class=\"box-body\">
-                <input type=\"text\" size=\"50\" name=\"webpage\" value=\"".$oVendor->sWebpage."\" /> 
-              </td>
-            </tr>
-            <tr>
-              <td colspan=\"2\" class=\"box-body\">
-                <input type=\"submit\" name=\"submit\" value=\"Submit\" />
-              </td>
-            </tr>
-          </table>
-          </form>";
+    if($oVendor->iVendorId)
+        apidb_header("Edit Vendor");
+    else
+        apidb_header("Add Vendor");
+
+    // Show the form
+    echo '<form name="qform" action="'.$_SERVER['PHP_SELF'].'" method="post" enctype="multipart/form-data">',"\n";
+
+    $oVendor->OutputEditor();
+
+    echo '<tr valign=top><td class=color3 align=center colspan=2>',"\n";
+    echo '<input name="Submit" type="submit" value="Submit" class="button" >&nbsp',"\n";
+    echo '</td></tr>',"\n";
+
+    echo "</form>";
+    echo html_frame_end("&nbsp;");
     apidb_footer();
+
 }
 ?>
Index: include/sidebar.php
===================================================================
RCS file: /home/wine/appdb/include/sidebar.php,v
retrieving revision 1.14
diff -u -r1.14 sidebar.php
--- include/sidebar.php	21 Oct 2005 02:48:27 -0000	1.14
+++ include/sidebar.php	23 Oct 2005 02:14:13 -0000
@@ -3,6 +3,7 @@
 /* SideBar */
 /***********/
 require_once(BASE."include/distributions.php");
+require_once(BASE."include/vendor.php");
   
 function global_sidebar_menu() {
   
@@ -19,6 +20,7 @@
     $g->add("Help &amp; Documentation", BASE."help/");
     $g->add("AppDB Stats", BASE."appdbStats.php");
     $g->add("View Distributions (".getNumberOfDistributions().")", BASE."distributionView.php");
+    $g->add("View Vendors (".getNumberOfvendors().")", BASE."vendorview.php");
 
     $g->add("Email your suggestions for improving the AppDB", "mailto:appdb at winehq.org");
     $g->done();    
Index: include/sidebar_admin.php
===================================================================
RCS file: /home/wine/appdb/include/sidebar_admin.php,v
retrieving revision 1.19
diff -u -r1.19 sidebar_admin.php
--- include/sidebar_admin.php	21 Oct 2005 02:48:27 -0000	1.19
+++ include/sidebar_admin.php	23 Oct 2005 02:14:13 -0000
@@ -10,7 +10,7 @@
     $g = new htmlmenu("Global Admin");
     
     $g->add("Add Category", BASE."admin/addCategory.php");
-    $g->add("Add Vendor", BASE."admin/addVendor.php");
+    $g->add("Add Vendor", BASE."admin/editVendor.php");
     
     $g->addmisc("&nbsp;");
     $g->add("View App Queue (".$_SESSION['current']->getQueuedAppCount()."/".$_SESSION['current']->getQueuedVersionCount().")", BASE."admin/adminAppQueue.php");
Index: include/vendor.php
===================================================================
RCS file: /home/wine/appdb/include/vendor.php,v
retrieving revision 1.4
diff -u -r1.4 vendor.php
--- include/vendor.php	23 Mar 2005 23:56:38 -0000	1.4
+++ include/vendor.php	23 Oct 2005 02:14:14 -0000
@@ -115,5 +115,37 @@
             addmsg("The vendor has been deleted.", "green");
         }
     }
+
+    function OutputEditor()
+    {
+        echo html_frame_start("Vendor Form", "90%", "", 0);
+        echo "<table width='100%' border=0 cellpadding=2 cellspacing=0>\n";
+
+        // Name
+        echo '<tr valign=top><td class="color1" width="20%"><b>Vendor Name</b></td>',"\n";
+        echo '<td class="color0"><input type=text name="sName" value="'.$this->sName.'" size="50"></td></tr>',"\n";
+        // Url
+        echo '<tr valign=top><td class="color1"><b>Vendor Url</b></td>',"\n";
+        echo '<td class="color0"><input type=text name="sWebpage" value="'.$this->sWebpage.'" size="50"></td></tr>',"\n";
+
+        echo  '<input type="hidden" name="iVendorId" value="'.$this->iVendorId.'">',"\n";
+
+        echo "</table>\n";
+        echo html_frame_end();
+    }
+
+}
+
+/* Get the total number of Vendors in the database */
+function getNumberOfVendors()
+{
+    $hResult = query_appdb("SELECT count(*) as num_vendors FROM vendor");
+    if($hResult)
+    {
+      $row = mysql_fetch_object($hResult);
+      return $row->num_vendors;
+    }
+    return 0;
 }
 ?>


More information about the wine-patches mailing list