diff --git a/admin/addCategory.php b/admin/addCategory.php deleted file mode 100644 index 0159249..0000000 --- a/admin/addCategory.php +++ /dev/null @@ -1,56 +0,0 @@ -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 "
- iCatId."\" /> - - - - - - - - - - - - - - - - -
Category name - sName."\" /> -
Description - sDescription."\" /> -
Parent - ".html_select("parentId",$aCatsIds,$oCat->iParentId,$aCatsNames)." -
- -
-
"; -} -apidb_footer(); -?> diff --git a/appbrowse.php b/appbrowse.php index 037d608..b1e4401 100644 --- a/appbrowse.php +++ b/appbrowse.php @@ -17,9 +17,13 @@ function admin_menu() global $aClean; $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"; - $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(); } diff --git a/include/category.php b/include/category.php index c91dd0e..6cfd6a6 100644 --- a/include/category.php +++ b/include/category.php @@ -76,58 +76,31 @@ class Category { /** * Creates a new category. */ - function create($sName=null, $sDescription=null, $iParentId=null) + function create() { $hResult = query_parameters("INSERT INTO appCategory (catName, catDescription, catParent) ". "VALUES('?', '?', '?')", - $sName, $sDescription, $iParentId); + $this->sName, $this->sDescription, $this->iParentId); if($hResult) { $this->iCatId = query_appdb_insert_id(); $this->category($this->iCatId); return true; } - else - { - addmsg("Error while creating a new vendor.", "red"); - return false; - } - } + return false; + } /** * Update category. * Returns true on success and false on failure. */ - function update($sName=null, $sDescription=null, $iParentId=null) + function update() { - if(!$this->iCatId) - return $this->create($sName, $sDescription, $iParentId); + if(!query_parameters("UPDATE appCategory SET catName = '?', catDescription = '?', catParent = '?' WHERE catId = '?'", + $this->sName, $this->sDescription, $this->iParentId, $this->iCatId)) + return false; - if($sName) - { - if (!query_parameters("UPDATE appCategory SET catName = '?' WHERE catId = '?'", - $sName, $this->iCatId)) - 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; } @@ -135,26 +108,38 @@ class Category { /** * Deletes the category from the database. */ - function delete($bSilent=false) + function delete() { - if(!$_SESSION['current']->canDeleteCategory($this)) + if(!$this->canEdit()) return false; if(sizeof($this->aApplicationsIds)>0) - { - addmsg("The category has not been deleted because there are still applications linked to it.", "red"); - } else - { - $sQuery = "DELETE FROM appCategory - WHERE catId = '?' - LIMIT 1"; - query_parameters($sQuery, $this->iCatId); - addmsg("The category has been deleted.", "green"); - } + return FALSE; + + $sQuery = "DELETE FROM appCategory + WHERE catId = '?' + LIMIT 1"; + query_parameters($sQuery, $this->iCatId); 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: @@ -248,6 +233,77 @@ class Category { 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 " + + + + + + + + + + + + +
Category name + sName."\" /> +
Description + sDescription."\" /> +
Parent + ".html_select("iParentId",$aCatIds,$this->iParentId, $aCatNames)." +
"; + } + + 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 */ diff --git a/include/sidebar_admin.php b/include/sidebar_admin.php index 4447157..0ee3db5 100644 --- a/include/sidebar_admin.php +++ b/include/sidebar_admin.php @@ -59,7 +59,7 @@ function global_admin_menu() { $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=". "false&sAction=add&sTitle=Add%20Vendor"); diff --git a/include/user.php b/include/user.php index b23f005..11145ab 100644 --- a/include/user.php +++ b/include/user.php @@ -604,14 +604,6 @@ class User { /* 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 */