diff --git a/appbrowse.php b/appbrowse.php index edf633e..2a96800 100644 --- a/appbrowse.php +++ b/appbrowse.php @@ -9,170 +9,9 @@ // application environment require("path.php"); require(BASE."include/"."incl.php"); -require_once(BASE."include/"."appdb.php"); -require_once(BASE."include/"."category.php"); -function admin_menu() -{ - global $aClean; +$iId = getInput('iCatId', $aClean); - $m = new htmlmenu("Admin"); - $m->add('Edit this Category', BASE."objectManager.php?iId=${aClean[iCatId]}&sClass=category&sAction=edit"); - - /* 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(); -} - -$iCatId = isset($aClean['iCatId']) ? $aClean['iCatId'] : 0; -// list sub categories -$oCat = new Category( $iCatId ); -$sCatFullPath = Category::make_cat_path($oCat->getCategoryPath()); -$subs = $oCat->aSubcatsIds; - -//display admin box -if($_SESSION['current']->hasPriv("admin") && isset($aClean['iCatId']) && $aClean['iCatId'] != 0 ) - apidb_sidebar_add("admin_menu"); - -//output header -apidb_header("Browse Applications"); - -echo "
\n"; - -if($subs) -{ - echo html_frame_start("",'98%','',2); - echo "

Category: ". $sCatFullPath ."
\n"; - echo html_frame_end(); - - echo html_frame_start("","98%","",0); - - $oTable = new Table(); - $oTable->SetWidth("100%"); - $oTable->SetBorder(0); - $oTable->SetCellPadding(3); - $oTable->SetCellSpacing(1); - - $oTableRow = new TableRow(); - $oTableRow->SetClass("color4"); - $oTableRow->AddTextCell("Sub Category"); - $oTableRow->AddTextCell("Description"); - $oTableRow->AddTextCell("No. Apps"); - $oTable->SetHeader($oTableRow); - - while(list($i,$iSubcatId) = each($subs)) - { - $oSubCat= new Category($iSubcatId); - - //set row color - $sColor = ($i % 2) ? "color0" : "color1"; - - $oTableRowHighlight = GetStandardRowHighlight($i); - - $sUrl = "appbrowse.php?iCatId=$iSubcatId"; - - $oTableRowClick = new TableRowClick($sUrl); - $oTableRowClick->SetHighlight($oTableRowHighlight); - - //get number of apps in this sub-category - $iAppcount = $oSubCat->getApplicationCount(); - - //format desc - $sDesc = substr(stripslashes($oSubCat->sDescription),0,70); - - //display row - $oTableRow = new TableRow(); - $oTableRow->SetClass($sColor); - $oTableRow->SetRowClick($oTableRowClick); - - $oTableCell = new TableCell($oSubCat->sName); - $oTableCell->SetCellLink($sUrl); - $oTableRow->AddCell($oTableCell); - $oTableRow->AddTextCell("$sDesc  "); - $oTableRow->AddTextCell("$iAppcount  "); - - $oTable->AddRow($oTableRow); - } - - // output the table - echo $oTable->GetString(); - - echo html_frame_end( count($subs) . ' categories'); -} - - - -// list applications in this category -$apps = $oCat->aApplicationsIds; -if($apps) -{ - echo html_frame_start("",'98%','',2); - echo "

Category: ". $sCatFullPath ."
\n"; - echo html_frame_end(); - - echo html_frame_start("","98%","",0); - - $oTable = new Table(); - $oTable->SetWidth("100%"); - $oTable->SetBorder(0); - $oTable->SetCellPadding(3); - $oTable->SetCellSpacing(1); - - $oTableRow = new TableRow(); - $oTableRow->SetClass("color4"); - $oTableRow->AddTextCell("Application name"); - $oTableRow->AddTextCell("Description"); - $oTableRow->AddTextCell("No. Versions"); - - $oTable->SetHeader($oTableRow); - - while(list($i, $iAppId) = each($apps)) - { - $oApp = new Application($iAppId); - - //set row color - $sColor = ($i % 2) ? "color0" : "color1"; - - $oTableRowHighlight = GetStandardRowHighlight($i); - - $sUrl = $oApp->objectMakeUrl(); - - $oTableRowClick = new TableRowClick($sUrl); - $oTableRowClick->SetHighlight($oTableRowHighlight); - - //format desc - $sDesc = util_trim_description($oApp->sDescription); - - //display row - $oTableRow = new TableRow(); - $oTableRow->SetRowClick($oTableRowClick); - $oTableRow->SetClass($sColor); - $oTableRow->AddTextCell($oApp->objectMakeLink()); - $oTableRow->AddTextCell("$sDesc  "); - $oTableRow->AddTextCell(sizeof($oApp->aVersionsIds)); - - $oTable->AddRow($oTableRow); - } - - // output table - echo $oTable->GetString(); - - echo html_frame_end( count($apps) . " applications in this category"); -} - -// Disabled for now -//if ($aClean['iCatId'] != 0) -//{ -// log_category_visit($cat->id); -//} - -echo p(); - -echo "

\n"; - -apidb_footer(); +util_redirect_and_exit(BASE."objectManager.php?sClass=category&iId=$iId&sAction=view&sTitle=Browse+Applications"); ?> diff --git a/include/application.php b/include/application.php index 75a12e2..75f1bb5 100644 --- a/include/application.php +++ b/include/application.php @@ -761,7 +761,7 @@ class Application { // cat display $oCategory = new Category($this->iCatId); - $oCategory->display($this->iAppId); + $oCategory->displayPath($this->iAppId); // set developer $oVendor = new Vendor($this->iVendorId); diff --git a/include/category.php b/include/category.php index dc51bd4..87f8c9d 100644 --- a/include/category.php +++ b/include/category.php @@ -274,11 +274,39 @@ class Category { return $str; } + public function objectGetState() + { + // We currenly don't queue categories + return 'accepted'; + } + function objectGetId() { return $this->iCatId; } + public function objectMakeLink() + { + return '{$this->sName}'"; + } + + public function objectMakeUrl() + { + return BASE."objectManager.php?sClass=category&sAction=view&iId={$this->iCatId}&sTitle=Browse+Applications"; + } + + public function objectAllowNullId($sAction) + { + switch($sAction) + { + case 'view': + return true; + + default: + return false; + } + } + function objectGetSubmitterId() { /* We don't log that */ @@ -344,13 +372,160 @@ class Category { /** * display the full path of the Category we are looking at */ - function display($appId, $versionId = '') + function displayPath($appId, $versionId = '') { $sCatFullPath = Category::make_cat_path($this->getCategoryPath(), $appId, $versionId); echo html_frame_start("",'98%','',2); echo "

Category: ". $sCatFullPath ."
\n"; echo html_frame_end(); } + + public function display() + { + // list sub categories + $sCatFullPath = Category::make_cat_path($this->getCategoryPath()); + $aSubs = $this->aSubcatsIds; + + echo "

\n"; + + // Allow editing categories + if($this->canEdit()) + { + $oM = new objectManager('category', '', $this->iCatId); + $oM->setReturnTo($this->objectMakeUrl()); + echo "

\n"; + echo 'Add'; + if($this->iCatId) // We can't edit the 'Main' category + { + echo '     '; + echo 'Edit'; + echo '     '; + echo 'Delete'; + } + echo "

\n"; + } + + if($aSubs) + { + echo html_frame_start("",'98%','',2); + echo "

Category: ". $sCatFullPath ."
\n"; + echo html_frame_end(); + + echo html_frame_start("","98%","",0); + + $oTable = new Table(); + $oTable->SetWidth("100%"); + $oTable->SetBorder(0); + $oTable->SetCellPadding(3); + $oTable->SetCellSpacing(1); + + $oTableRow = new TableRow(); + $oTableRow->SetClass("color4"); + $oTableRow->AddTextCell("Sub Category"); + $oTableRow->AddTextCell("Description"); + $oTableRow->AddTextCell("No. Apps"); + $oTable->SetHeader($oTableRow); + + while(list($i,$iSubcatId) = each($aSubs)) + { + $oSubCat= new Category($iSubcatId); + + //set row color + $sColor = ($i % 2) ? "color0" : "color1"; + + $oTableRowHighlight = GetStandardRowHighlight($i); + + $sUrl = $oSubCat->objectMakeUrl(); + + $oTableRowClick = new TableRowClick($sUrl); + $oTableRowClick->SetHighlight($oTableRowHighlight); + + //get number of apps in this sub-category + $iAppcount = $oSubCat->getApplicationCount(); + + //format desc + $sDesc = substr(stripslashes($oSubCat->sDescription),0,70); + + //display row + $oTableRow = new TableRow(); + $oTableRow->SetClass($sColor); + $oTableRow->SetRowClick($oTableRowClick); + + $oTableCell = new TableCell($oSubCat->sName); + $oTableCell->SetCellLink($sUrl); + $oTableRow->AddCell($oTableCell); + $oTableRow->AddTextCell("$sDesc  "); + $oTableRow->AddTextCell("$iAppcount  "); + + $oTable->AddRow($oTableRow); + } + + // output the table + echo $oTable->GetString(); + + echo html_frame_end( count($aSubs) . ' categories'); + } + + + + // list applications in this category + $aApps = $this->aApplicationsIds; + if($aApps) + { + echo html_frame_start("",'98%','',2); + echo "

Category: ". $sCatFullPath ."
\n"; + echo html_frame_end(); + + echo html_frame_start("","98%","",0); + + $oTable = new Table(); + $oTable->SetWidth("100%"); + $oTable->SetBorder(0); + $oTable->SetCellPadding(3); + $oTable->SetCellSpacing(1); + + $oTableRow = new TableRow(); + $oTableRow->SetClass("color4"); + $oTableRow->AddTextCell("Application name"); + $oTableRow->AddTextCell("Description"); + $oTableRow->AddTextCell("No. Versions"); + + $oTable->SetHeader($oTableRow); + + while(list($i, $iAppId) = each($aApps)) + { + $oApp = new Application($iAppId); + + //set row color + $sColor = ($i % 2) ? "color0" : "color1"; + + $oTableRowHighlight = GetStandardRowHighlight($i); + + $sUrl = $oApp->objectMakeUrl(); + + $oTableRowClick = new TableRowClick($sUrl); + $oTableRowClick->SetHighlight($oTableRowHighlight); + + //format desc + $sDesc = util_trim_description($oApp->sDescription); + + //display row + $oTableRow = new TableRow(); + $oTableRow->SetRowClick($oTableRowClick); + $oTableRow->SetClass($sColor); + $oTableRow->AddTextCell($oApp->objectMakeLink()); + $oTableRow->AddTextCell("$sDesc  "); + $oTableRow->AddTextCell(sizeof($oApp->aVersionsIds)); + + $oTable->AddRow($oTableRow); + } + + // output table + echo $oTable->GetString(); + + echo html_frame_end( count($aApps) . " applications in this category"); + } + } } ?> diff --git a/include/objectManager.php b/include/objectManager.php index 8f4ce34..593c0d2 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -188,6 +188,17 @@ class ObjectManager return TRUE; } + public function IsNullIdAllowed($sAction) + { + $oObject = new $this->sClass(); + $bAllowed = method_exists($oObject, 'objectAllowNullId'); + + if($bAllowed) + $bAllowed = $oObject->objectAllowNullId($sAction); + + return $bAllowed; + } + public static function error_exit($shMessage) { echo '

'.$shMessage.'

sClass($this->iId); /* Check that the entry exists */ - if(!$oObject->objectGetId()) + if(!$oObject->objectGetId() && !$this->isNullIdAllowed('view')) $this->error_exit("Entry not found (class: {$this->sClass}, id: {$this->iId})"); /* Check if the entry has been deleted */ diff --git a/include/version.php b/include/version.php index bb0dc36..7d0bf10 100644 --- a/include/version.php +++ b/include/version.php @@ -840,7 +840,7 @@ class version { // cat $oCategory = new Category($oApp->iCatId); - $oCategory->display($oApp->iAppId, $this->iVersionId); + $oCategory->displayPath($oApp->iAppId, $this->iVersionId); // set URL $appLinkURL = ($oApp->sWebpage) ? trimmed_link($oApp->sWebpage,30) : " "; diff --git a/objectManager.php b/objectManager.php index 7283027..aa1db6d 100644 --- a/objectManager.php +++ b/objectManager.php @@ -116,7 +116,7 @@ if(!$sAction) apidb_header($oObject->get_title($sAction)); /* display a particular element */ -if($oObject->getId() && $sAction != "add") +if(($oObject->getId() || $oObject->IsNullIdAllowed($sAction)) && $sAction != "add") { switch($sAction) {