Index: trunk/kernel/include/category.php =================================================================== diff -u -r123 -r133 --- trunk/kernel/include/category.php (.../category.php) (revision 123) +++ trunk/kernel/include/category.php (.../category.php) (revision 133) @@ -1315,25 +1315,30 @@ } -class clsCatList extends clsItemCollection +class clsCatList extends clsItemList //clsItemCollection { -// var $Categories; -// var $adodbConnection; - var $Page; - var $PerPageVar; + //var $Page; // no need because clsItemList class used instead of clsItemCollection + //var $PerPageVar; - function clsCatList() - { - global $m_var_list; - $this->clsItemCollection(); - $this->classname="clsCategory"; - $this->AdminSearchFields = array("Name","Description"); - $this->Page=(int)$m_var_list["p"]; - $this->PerPageVar = "Perpage_Category"; - $this->SourceTable = GetTablePrefix()."Category"; - $this->BasePermission="CATEGORY"; - } + function clsCatList() + { + global $m_var_list; + $this->clsItemCollection(); + $this->classname="clsCategory"; + $this->AdminSearchFields = array("Name","Description"); + $this->Page = (int)$m_var_list["p"]; + $this->PerPageVar = "Perpage_Category"; + $this->SourceTable = GetTablePrefix()."Category"; + $this->BasePermission="CATEGORY"; + $this->DefaultPerPage = 20; + } + function SaveNewPage() + { + global $m_var_list; + $m_var_list["p"] = $this->Page; + } + function GetCountSQL($PermName,$CatId=NULL, $GroupId=NULL, $AdditonalWhere="") { global $objSession, $objPermissions, $objCatList; @@ -1494,28 +1499,27 @@ } - function LoadCategories($where="",$orderBy = "") - { - global $objConfig; - $PerPage = $objConfig->Get($this->PerPageVar); - if(!is_numeric($PerPage)) - $PerPage = 10; + function LoadCategories($where="", $orderBy = "", $no_limit = true, $fix_method = 'set_first') + { + // load category list using $where clause + // apply ordering specified in $orderBy + // show all cats ($no_limit = true) or only from current page ($no_limit = false) + // in case if stored page is greather then page count issue page_fixing with + // method specified (see "FixInvalidPage" method for details) + $PerPage = $this->GetPerPage(); - $this->QueryItemCount=TableCount($this->SourceTable,$where,0); - //echo $this->QueryItemCount." Items Loaded
\n"; - if(is_numeric($objConfig->Get($this->PerPageVar))) - { - $Start = ($this->Page-1)*$PerPage; - $limit = "LIMIT ".$Start.",".$PerPage; - - } - else - $limit = NULL; - - $limit = NULL; + $this->QueryItemCount = TableCount($this->SourceTable,$where,0); + if($no_limit == false) + { + $this->FixInvalidPage($fix_method); + $Start = ($this->Page-1) * $PerPage; + $limit = "LIMIT ".$Start.",".$PerPage; + } + else + $limit = NULL; - return $this->Query_Category($where,$orderBy,$limit); - } + return $this->Query_Category($where, $orderBy, $limit); + } function Query_Category($whereClause="",$orderByClause="",$limit=NULL) { @@ -1547,6 +1551,7 @@ $sql .= " ".$limit; if($objSession->HasSystemPermission("DEBUG.LIST")) echo $sql; + return $this->Query_item($sql); } @@ -1562,17 +1567,11 @@ if(!strlen($page)) $page = GetIndexURL(); - $NumPages = ceil($this->GetNumPages($objConfig->Get($this->PerPageVar))); + $PerPage = $this->GetPerPage(); + $NumPages = ceil( $this->GetNumPages($PerPage) ); + + if($NumPages == 1 && $HideEmpty) return ''; - $PerPage = $objConfig->Get($this->PerPageVar); - if($PerPage<1) - $PerPage=20; - - $NumPages = ceil($this->GetNumPages($PerPage)); - - if($NumPages==1 && $HideEmpty) - return ""; - if(strlen($dest_template)) { $var_list_update["t"] = $dest_template; @@ -1628,64 +1627,58 @@ unset($m_var_list_update,$var_list_update["t"] ); return $o; } + + function GetAdminPageLinkList($url) + { + global $objConfig, $m_var_list_update, $var_list_update, $var_list; + + $PerPage = $this->GetPerPage(); + $NumPages = ceil($this->GetNumPages($PerPage)); + $o = ""; + if($this->Page>1) + { + $m_var_list_update["p"]=$this->Page-1; + $prev_url = $url."?env=".BuildEnv(); + unset($m_var_list_update["p"]); + $o .= "<<"; + } - function GetAdminPageLinkList($url) - { - global $objConfig, $m_var_list_update, $var_list_update, $var_list; + if($this->Page<$NumPages) + { + $m_var_list_update["p"]=$this->Page+1; + $next_url = $url."?env=".BuildEnv(); + unset($m_var_list_update["p"]); + } - $PerPage = $objConfig->Get($this->PerPageVar); - if(!is_numeric($PerPage)) - $PerPage = 10; - - $NumPages = ceil($this->GetNumPages($PerPage)); - $o = ""; - - if($this->Page>1) - { - $m_var_list_update["p"]=$this->Page-1; - $prev_url = $url."?env=".BuildEnv(); - unset($m_var_list_update["p"]); - $o .= "<<"; - } - - if($this->Page<$NumPages) - { - $m_var_list_update["p"]=$this->Page+1; - $next_url = $url."?env=".BuildEnv(); - unset($m_var_list_update["p"]); - } - - for($p=1;$p<=$NumPages;$p++) - { - if($p!=$this->Page) - { - $m_var_list_update["p"]=$p; - $href = $url."?env=".BuildEnv(); - unset($m_var_list_update["p"]); - $o .= "-$p-"; - } - else - { + for($p=1;$p<=$NumPages;$p++) + { + if($p != $this->Page) + { + $m_var_list_update["p"]=$p; + $href = $url."?env=".BuildEnv(); + unset($m_var_list_update["p"]); + $o .= " $p "; + } + else $o .= "$p"; - } - } - if($this->Page<$NumPages) - { - $o .= ">>"; - } + } + + if($this->Page < $NumPages) + $o .= ">>"; - return $o; - } + return $o; + } function Search_Category($orderByClause) { global $objSession, $objConfig, $Errors; - $Start = ($this->Page-1)*$objConfig->Get("Perpage_Category"); + $PerPage = $this->GetPerPage(); + $Start = ($this->Page-1) * $PerPage; $objResults = new clsSearchResults("Category","clsCategory"); $this->Clear(); - $this->Categories = $objResults->LoadSearchResults($Start,$objConfig->Get("Perpage_Category")); + $this->Categories = $objResults->LoadSearchResults($Start,$PerPage); return $this->Categories; }