- use vendor class in vendor admin

- improve existing vendor admin
- fix adding a vendor which was broken
- allow editing of a vendor
This commit is contained in:
Jonathan Ernst
2005-02-07 23:54:29 +00:00
committed by WineHQ
parent a3820b468d
commit 5fc48e8106
3 changed files with 75 additions and 90 deletions

View File

@@ -1,41 +1,44 @@
<?php <?php
include("path.php"); include("path.php");
include(BASE."include/"."incl.php"); require(BASE."include/incl.php");
include(BASE."include/"."tableve.php"); require(BASE."include/vendor.php");
if(!$_SESSION['current']->hasPriv("admin")) if(!$_SESSION['current']->hasPriv("admin"))
{ {
errorpage(); errorpage();
exit; exit;
} }
$oVendor = new Vendor($_REQUEST['vendorId']);
if($_REQUEST['submit'])
{
$oVendor->update($_REQUEST['name'],$_REQUEST['webpage']);
redirect(apidb_fullurl("admin/adminVendors.php"));
}
else else
{ {
global $admin_mode;
$admin_mode = 1;
}
apidb_header("Add Vendor"); apidb_header("Add Vendor");
echo "<form method=\"post\" action=\"addVendor.php\">
$t = new TableVE("create"); <input type=\"hidden\" name=\"vendorId\" value=\"".$oVendor->iVendorId."\" />
<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
if($_POST) <tr>
{ <td width=\"15%\" class=\"box-label\"><b>Vendor name</b></td>
$t->update($_POST); <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>";
} }
else
{
$table = "vendor";
$query = "INSERT INTO $table VALUES(0, 'NONAME', null)";
query_appdb("DELETE FROM $table WHERE vendorName = 'NONAME'");
if(debugging())
echo "$query <br /><br />\n";
$t->create($query, $table, "vendorId");
}
apidb_footer(); apidb_footer();
?> ?>

View File

@@ -8,84 +8,55 @@
*/ */
include("path.php"); include("path.php");
require(BASE."include/incl.php"); require(BASE."include/incl.php");
require_once(BASE."include/vendor.php");
if(!$_SESSION['current']->hasPriv("admin")) if(!$_SESSION['current']->hasPriv("admin"))
{ {
errorpage("Insufficient privileges."); errorpage("Insufficient privileges.");
exit; exit;
} }
apidb_header("Admin Vendors");
echo '<form name="qform" action="adminVendors.php" method="post" enctype="multipart/form-data">',"\n";
if ($_REQUEST['sub']) if ($_REQUEST['sub'])
{ {
if($_REQUEST['sub'] == 'delete') if($_REQUEST['sub'] == 'delete')
{ {
$sQuery = "SELECT * FROM appFamily WHERE vendorId = ".$_REQUEST['vendorId'].";"; $oVendor = new Vendor($_REQUEST['vendorId']);
if (debugging()) echo "$sQuery"; $oVendor->delete();
$hResult = query_appdb($sQuery); redirect(apidb_fullurl("admin/adminVendors.php"));
if(!$hResult || !mysql_num_rows($hResult))
{
$sQuery = "DELETE FROM vendor WHERE vendorId = ".$_REQUEST['vendorId'].";";
if (debugging()) echo "$sQuery";
$hResult = query_appdb($sQuery);
echo html_frame_start("Delete vendor: ".$_REQUEST['vendorId'],400,"",0);
if($hResult)
{
//success
echo "<p>Vendor was successfully deleted</p>\n";
}
} else
{
echo "<p><b> Error: Can not delete a vendor with applications attached to it!</b></p>\n";
}
echo html_frame_end("&nbsp;");
echo html_back_link(1,'adminVendors.php');
} }
} else } else
{ {
apidb_header("Admin Vendors");
//get available vendors //get available vendors
$sQuery = "SELECT * FROM vendor ORDER BY vendorName, vendorId;"; $sQuery = "SELECT vendorId FROM vendor ORDER BY vendorName, vendorId;";
$hResult = query_appdb($sQuery); $hResult = query_appdb($sQuery);
if(!$hResult || !mysql_num_rows($hResult)) // show vendorlist
{ echo html_frame_start("","90%","",0);
// no vendors echo "<table width='100%' border=0 cellpadding=3 cellspacing=0>\n\n";
echo html_frame_start("","90%");
echo '<p><b>There are no application vendors.</b></p>',"\n";
echo html_frame_end("&nbsp;");
}
else
{
// show vendorlist
echo html_frame_start("","90%","",0);
echo "<table width='100%' border=0 cellpadding=3 cellspacing=0>\n\n";
echo "<tr class=color4>\n"; echo "<tr class=color4>\n";
echo " <td><font color=white>Vendor name</font></td>\n"; echo " <td>Vendor name</td>\n";
echo " <td><font color=white>Vendor url</font></td>\n"; echo " <td>Vendor url</td>\n";
echo " <td>&nbsp;</td>\n"; echo " <td>Action</td>\n";
echo "</tr>\n\n"; echo "</tr>\n\n";
$c = 1; $c = 1;
while($ob = mysql_fetch_object($hResult)) while($ob = mysql_fetch_object($hResult))
{ {
if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; } if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
echo "<tr class=$bgcolor>\n"; $oVendor = new Vendor($ob->vendorId);
echo " <td><a href=".BASE."vendorview.php?vendorId=".$ob->vendorId.">".$ob->vendorName."</a></td>\n"; echo "<tr class=\"$bgcolor\">\n";
echo " <td><a href=\"".$ob->vendorURL."\">".$ob->vendorURL."</a></td>\n"; echo " <td><a href=\"".BASE."vendorview.php?vendorId=".$oVendor->iVendorId."\">".$oVendor->sName."</a></td>\n";
echo " <td>[<a href='adminVendors.php?sub=delete&vendorId=$ob->vendorId'>delete</a>]</td>\n"; echo " <td><a href=\"".$oVendor->sWebpage."\">".$oVendor->sWebpage."</a></td>\n";
echo "</tr>\n\n"; echo " <td>[<a href='adminVendors.php?sub=delete&vendorId=".$oVendor->iVendorId."'>delete</a>] &nbsp; ";
$c++; echo " [<a href='addVendor.php?vendorId=".$oVendor->iVendorId."'>edit</a>]</td>\n";
} echo "</tr>\n\n";
echo "</table>\n\n"; $c++;
echo html_frame_end("&nbsp;");
} }
echo "</table>\n\n";
echo html_frame_end("&nbsp;");
} }
echo "</form>";
apidb_footer(); apidb_footer();
?> ?>

View File

@@ -81,14 +81,17 @@ class Vendor {
*/ */
function update($sName=null, $sWebpage=null) function update($sName=null, $sWebpage=null)
{ {
if ($sName) if(!$this->iVendorId)
return $this->create($sName, $sWebpage);
if($sName)
{ {
if (!query_appdb("UPDATE vendor SET vendorName = '".$sName."' WHERE vendorId = ".$this->iVendorId)) if (!query_appdb("UPDATE vendor SET vendorName = '".$sName."' WHERE vendorId = ".$this->iVendorId))
return false; return false;
$this->sName = $sName; $this->sName = $sName;
} }
if ($sWebpage) if($sWebpage)
{ {
if (!query_appdb("UPDATE vendor SET vendorURL = '".$sWebpage."' WHERE vendorId = ".$this->iVendorId)) if (!query_appdb("UPDATE vendor SET vendorURL = '".$sWebpage."' WHERE vendorId = ".$this->iVendorId))
return false; return false;
@@ -104,9 +107,17 @@ class Vendor {
*/ */
function delete($bSilent=false) function delete($bSilent=false)
{ {
$sQuery = "DELETE FROM vendor if(sizeof($this->aApplicationsIds)>0)
WHERE vendorId = ".$this->iVendorId." {
LIMIT 1"; addmsg("The vendor has not been deleted because there are still applications linked to it.", "red");
} else
{
$sQuery = "DELETE FROM vendor
WHERE vendorId = ".$this->iVendorId."
LIMIT 1";
query_appdb($sQuery);
addmsg("The vendor has been deleted.", "green");
}
} }
} }
?> ?>