Fix category administration
This commit is contained in:
committed by
Chris Morgan
parent
30c5b93d6f
commit
6ebd4cfa34
@@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
require("path.php");
|
|
||||||
require(BASE."include/incl.php");
|
|
||||||
require_once(BASE."include/category.php");
|
|
||||||
|
|
||||||
if(!$_SESSION['current']->hasPriv("admin"))
|
|
||||||
util_show_error_page_and_exit();
|
|
||||||
|
|
||||||
$aClean['iCatId'] = (isset($aClean['iCatId']) ? $aClean['iCatId'] : '');
|
|
||||||
$oCat = new Category( $aClean['iCatId'] );
|
|
||||||
if(isset($aClean['sSubmit']))
|
|
||||||
{
|
|
||||||
$oCat->update($aClean['sName'],$aClean['sDescription'],$aClean['iParentId']);
|
|
||||||
util_redirect_and_exit(apidb_fullurl("appbrowse.php?iCatId=".$oCat->iCatId));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
apidb_header("Add Category");
|
|
||||||
$sQuery = "SELECT catId, catName FROM appCategory WHERE catId!='?'";
|
|
||||||
$hResult = query_parameters($sQuery, $aClean['iCatId']);
|
|
||||||
while($oRow = query_fetch_object($hResult))
|
|
||||||
{
|
|
||||||
$aCatsIds[]=$oRow->catId;
|
|
||||||
$aCatsNames[]=$oRow->catName;
|
|
||||||
}
|
|
||||||
echo "<form method=\"post\" action=\"addCategory.php\">
|
|
||||||
<input type=\"hidden\" name=\"iCatId\" value=\"".$oCat->iCatId."\" />
|
|
||||||
<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
|
|
||||||
<tr>
|
|
||||||
<td width=\"15%\" class=\"box-label\"><b>Category name</b></td>
|
|
||||||
<td class=\"box-body\">
|
|
||||||
<input type=\"text\" size=\"50\" name=\"sName\" value=\"".$oCat->sName."\" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td width=\"15%\" class=\"box-label\"><b>Description</b></td>
|
|
||||||
<td class=\"box-body\">
|
|
||||||
<input type=\"text\" size=\"50\" name=\"sDescription\" value=\"".$oCat->sDescription."\" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td width=\"15%\" class=\"box-label\"><b>Parent</b></td>
|
|
||||||
<td class=\"box-body\">
|
|
||||||
".html_select("parentId",$aCatsIds,$oCat->iParentId,$aCatsNames)."
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td colspan=\"2\" class=\"box-body\">
|
|
||||||
<input type=\"submit\" name=\"sSubmit\" value=\"Submit\" />
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</form>";
|
|
||||||
}
|
|
||||||
apidb_footer();
|
|
||||||
?>
|
|
||||||
@@ -17,9 +17,13 @@ function admin_menu()
|
|||||||
global $aClean;
|
global $aClean;
|
||||||
|
|
||||||
$m = new htmlmenu("Admin");
|
$m = new htmlmenu("Admin");
|
||||||
$m->add("Edit this Category", BASE."admin/addCategory.php?iCatId=".$aClean['iCatId']);
|
$m->add('Edit this Category', BASE."objectManager.php?iId=${aClean[iCatId]}&sClass=category&sAction=edit");
|
||||||
$url = BASE."admin/deleteAny.php?sWhat=category&iCatId=".$aClean['iCatId']."&sConfirmed=yes";
|
$url = BASE."admin/deleteAny.php?sWhat=category&iCatId=".$aClean['iCatId']."&sConfirmed=yes";
|
||||||
$m->add("Delete this Category", "javascript:deleteURL(\"Are you sure?\", \"".$url."\")");
|
|
||||||
|
/* We only allow deletion of the category if it is empty */
|
||||||
|
$oCat = new category($aClean['iCatId']);
|
||||||
|
if(!sizeof($oCat->aApplicationsIds))
|
||||||
|
$m->add('Delete this Category', BASE."objectManager.php?iId=${aClean[iCatId]}&sClass=category&sAction=delete");
|
||||||
|
|
||||||
$m->done();
|
$m->done();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,57 +76,30 @@ class Category {
|
|||||||
/**
|
/**
|
||||||
* Creates a new category.
|
* Creates a new category.
|
||||||
*/
|
*/
|
||||||
function create($sName=null, $sDescription=null, $iParentId=null)
|
function create()
|
||||||
{
|
{
|
||||||
$hResult = query_parameters("INSERT INTO appCategory (catName, catDescription, catParent) ".
|
$hResult = query_parameters("INSERT INTO appCategory (catName, catDescription, catParent) ".
|
||||||
"VALUES('?', '?', '?')",
|
"VALUES('?', '?', '?')",
|
||||||
$sName, $sDescription, $iParentId);
|
$this->sName, $this->sDescription, $this->iParentId);
|
||||||
if($hResult)
|
if($hResult)
|
||||||
{
|
{
|
||||||
$this->iCatId = query_appdb_insert_id();
|
$this->iCatId = query_appdb_insert_id();
|
||||||
$this->category($this->iCatId);
|
$this->category($this->iCatId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
addmsg("Error while creating a new vendor.", "red");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update category.
|
* Update category.
|
||||||
* Returns true on success and false on failure.
|
* Returns true on success and false on failure.
|
||||||
*/
|
*/
|
||||||
function update($sName=null, $sDescription=null, $iParentId=null)
|
function update()
|
||||||
{
|
{
|
||||||
if(!$this->iCatId)
|
if(!query_parameters("UPDATE appCategory SET catName = '?', catDescription = '?', catParent = '?' WHERE catId = '?'",
|
||||||
return $this->create($sName, $sDescription, $iParentId);
|
$this->sName, $this->sDescription, $this->iParentId, $this->iCatId))
|
||||||
|
|
||||||
if($sName)
|
|
||||||
{
|
|
||||||
if (!query_parameters("UPDATE appCategory SET catName = '?' WHERE catId = '?'",
|
|
||||||
$sName, $this->iCatId))
|
|
||||||
return false;
|
return false;
|
||||||
$this->sName = $sName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($sDescription)
|
|
||||||
{
|
|
||||||
if (!query_parameters("UPDATE appCategory SET catDescription = '?' WHERE catId = '?'",
|
|
||||||
$sDescription, $this->iCatId))
|
|
||||||
return false;
|
|
||||||
$this->sDescription = $sDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($iParentId)
|
|
||||||
{
|
|
||||||
if (!query_parameters("UPDATE appCategory SET catParent = '?' WHERE catId = '?'",
|
|
||||||
$iParentId, $this->iCatId))
|
|
||||||
return false;
|
|
||||||
$this->iParentId = $iParentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -135,26 +108,38 @@ class Category {
|
|||||||
/**
|
/**
|
||||||
* Deletes the category from the database.
|
* Deletes the category from the database.
|
||||||
*/
|
*/
|
||||||
function delete($bSilent=false)
|
function delete()
|
||||||
{
|
{
|
||||||
if(!$_SESSION['current']->canDeleteCategory($this))
|
if(!$this->canEdit())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(sizeof($this->aApplicationsIds)>0)
|
if(sizeof($this->aApplicationsIds)>0)
|
||||||
{
|
return FALSE;
|
||||||
addmsg("The category has not been deleted because there are still applications linked to it.", "red");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
$sQuery = "DELETE FROM appCategory
|
$sQuery = "DELETE FROM appCategory
|
||||||
WHERE catId = '?'
|
WHERE catId = '?'
|
||||||
LIMIT 1";
|
LIMIT 1";
|
||||||
query_parameters($sQuery, $this->iCatId);
|
query_parameters($sQuery, $this->iCatId);
|
||||||
addmsg("The category has been deleted.", "green");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction)
|
||||||
|
{
|
||||||
|
return new mailOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
function objectGetChildren()
|
||||||
|
{
|
||||||
|
/* We don't have any (or we do, sort of, but we don't use them for anything at the moment) */
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function objectGetMail($sAction, $bMailSubmitter, $bParentAction)
|
||||||
|
{
|
||||||
|
/* We don't send notification mails */
|
||||||
|
return array(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns a path like:
|
* returns a path like:
|
||||||
@@ -248,6 +233,77 @@ class Category {
|
|||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function objectGetId()
|
||||||
|
{
|
||||||
|
return $this->iCatId;
|
||||||
|
}
|
||||||
|
|
||||||
|
function objectGetSubmitterId()
|
||||||
|
{
|
||||||
|
/* We don't log that */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function outputEditor()
|
||||||
|
{
|
||||||
|
$sQuery = "SELECT catId, catName FROM appCategory WHERE catId!='?'";
|
||||||
|
$hResult = query_parameters($sQuery, $this->iCatId);
|
||||||
|
|
||||||
|
/* Add the virtual 'Main' category */
|
||||||
|
$aCatIds = array(0);
|
||||||
|
$aCatNames = array('Main');
|
||||||
|
|
||||||
|
/* Add the rest from the database */
|
||||||
|
while($oRow = query_fetch_object($hResult))
|
||||||
|
{
|
||||||
|
$aCatIds[] = $oRow->catId;
|
||||||
|
$aCatNames[] = $oRow->catName;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">
|
||||||
|
<tr>
|
||||||
|
<td width=\"15%\" class=\"box-label\"><b>Category name</b></td>
|
||||||
|
<td class=\"box-body\">
|
||||||
|
<input type=\"text\" size=\"50\" name=\"sName\" value=\"".$this->sName."\" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width=\"15%\" class=\"box-label\"><b>Description</b></td>
|
||||||
|
<td class=\"box-body\">
|
||||||
|
<input type=\"text\" size=\"50\" name=\"sDescription\" value=\"".$this->sDescription."\" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width=\"15%\" class=\"box-label\"><b>Parent</b></td>
|
||||||
|
<td class=\"box-body\">
|
||||||
|
".html_select("iParentId",$aCatIds,$this->iParentId, $aCatNames)."
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>";
|
||||||
|
}
|
||||||
|
|
||||||
|
function allowAnonymousSubmissions()
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOutputEditorValues($aClean)
|
||||||
|
{
|
||||||
|
$this->sName = $aClean['sName'];
|
||||||
|
$this->iParentId = $aClean['iParentId'];
|
||||||
|
$this->sDescription = $aClean['sDescription'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function mustBeQueued()
|
||||||
|
{
|
||||||
|
return $_SESSION['current']->hasPriv('admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
function canEdit()
|
||||||
|
{
|
||||||
|
return $_SESSION['current']->hasPriv('admin');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* display the full path of the Category we are looking at
|
* display the full path of the Category we are looking at
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ function global_admin_menu() {
|
|||||||
|
|
||||||
$g->addmisc(" ");
|
$g->addmisc(" ");
|
||||||
|
|
||||||
$g->add("Add Category", BASE."admin/addCategory.php");
|
$g->add("Add Category", BASE."objectManager.php?sClass=category&sAction=add&sTitle=Add+Category");
|
||||||
$g->add("Add Vendor", BASE."objectManager.php?sClass=vendor&bQueue=".
|
$g->add("Add Vendor", BASE."objectManager.php?sClass=vendor&bQueue=".
|
||||||
"false&sAction=add&sTitle=Add%20Vendor");
|
"false&sAction=add&sTitle=Add%20Vendor");
|
||||||
|
|
||||||
|
|||||||
@@ -604,14 +604,6 @@ class User {
|
|||||||
/* Permission functions */
|
/* Permission functions */
|
||||||
/************************/
|
/************************/
|
||||||
|
|
||||||
function canDeleteCategory($oCategory)
|
|
||||||
{
|
|
||||||
if($this->hasPriv("admin"))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true or false depending on whether the user can view the image
|
* Returns true or false depending on whether the user can view the image
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user