Index: trunk/kernel/include/parseditem.php
===================================================================
diff -u -r123 -r133
--- trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 123)
+++ trunk/kernel/include/parseditem.php (.../parseditem.php) (revision 133)
@@ -976,6 +976,7 @@
function Query_Item($sql, $offset=-1,$rows=-1)
{
global $Errors;
+
$dummy =& $this->GetDummy();
if( !$dummy->TableExists() )
{
@@ -990,7 +991,6 @@
$result = $this->adodbConnection->SelectLimit($sql, $rows,$offset);
}
else {
- //echo $sql."
";
$result = $this->adodbConnection->Execute($sql);
}
@@ -1433,6 +1433,7 @@
{
var $Page;
var $PerPageVar;
+ var $DefaultPerPage; // use this perpage value in case if no found in config
var $EnablePaging;
var $MaxListCount = 0;
var $PageEnvar;
@@ -1475,56 +1476,46 @@
function GetPageOffset()
{
- global $objConfig;
-
$Start = 0;
-
if($this->EnablePaging)
{
- if($this->Page<1)
- $this->Page=1;
- if(is_numeric($objConfig->Get($this->PerPageVar)))
- {
- $Start = ($this->Page-1)*$objConfig->Get($this->PerPageVar);
- }
+ if($this->Page < 1) $this->Page = 1;
+ $PerPage = $this->GetPerPage();
+ $Start = ($this->Page - 1) * $PerPage;
}
else
{
- if((int)$this->MaxListCount==0)
- $Start = -1;
+ if((int)$this->MaxListCount == 0) $Start = -1;
}
- return $Start;
+ return $Start;
}
function GetPageRowCount()
{
- global $objConfig;
-
if($this->EnablePaging)
{
- if($this->Page<1)
- $this->Page=1;
-// echo "PerPageVar = ".$this->PerPageVar."
\n";
-// echo "
"; print_r($objConfig); echo "
";
- return $objConfig->Get($this->PerPageVar);
+ if($this->Page < 1) $this->Page = 1;
+ return $this->GetPerPage();
}
else
return (int)$this->MaxListCount;
}
- function Query_Item($sql,$limit=NULL)
+ function Query_Item($sql,$limit = null, $fix_method = 'set_first')
{
+ // query itemlist (module items) using $sql specified
+ // apply direct limit clause ($limit) or calculate it if not specified
+ // fix invalid page in case if needed by method specified in $fix_method
if(strlen($limit))
{
$sql .= " ".$limit;
- //echo "[$sql]
\n";
return parent::Query_Item($sql);
}
else
{
-// echo "-------------------
$sql
\n";
-// echo "Paging: ".$this->EnablePaging." Offset: ".$this->GetPageOffset()." Count: ".$this->GetPageRowCount()."
\n";
-// echo "===================
\n";
+ //echo "page fix pre (class: ".get_class($this).")
";
+ $this->QueryItemCount = QueryCount($sql); // must get total item count before fixing
+ $this->FixInvalidPage($fix_method);
return parent::Query_Item($sql,$this->GetPageOffset(),$this->GetPageRowCount());
}
}
@@ -1564,6 +1555,46 @@
return $this->Query_Item($sql);
}
+ function GetPerPage()
+ {
+ // return category perpage
+ global $objConfig;
+ $PerPage = $objConfig->Get( $this->PerPageVar );
+ if( !is_numeric($PerPage) ) $PerPage = $this->DefaultPerPage ? $this->DefaultPerPage : 10;
+ return $PerPage;
+ }
+
+ function FixInvalidPage($fix_method = 'set_first')
+ {
+ // in case if current page > total page count,
+ // then set current page to last possible "set_last"
+ // or first possible "set_first"
+ $PerPage = $this->GetPerPage();
+ $NumPages = ceil( $this->GetNumPages($PerPage) );
+ /*
+ echo "=====
";
+ echo "Class ".get_class($this).": Page ".$this->Page." of $NumPages
";
+ echo "PerPage: $PerPage
";
+ echo "Items Queries: ".$this->QueryItemCount."
";
+ echo "=====
";
+ */
+ if($this->Page > $NumPages)
+ {
+ switch($fix_method)
+ {
+ case 'set_first': $this->Page = 1; break;
+ case 'set_last': $this->Page = $NumPages; break;
+ }
+ $this->SaveNewPage();
+ }
+ }
+
+ function SaveNewPage()
+ {
+ // redefine in each list, should save to env array new page value
+
+ }
+
function GetPageLinkList($dest_template=NULL,$page = "",$PagesToList=10, $HideEmpty=TRUE)
{
global $objConfig, $var_list_update, $var_list;
Index: trunk/kernel/admin/include/toolbar/advanced_view.php
===================================================================
diff -u -r129 -r133
--- trunk/kernel/admin/include/toolbar/advanced_view.php (.../advanced_view.php) (revision 129)
+++ trunk/kernel/admin/include/toolbar/advanced_view.php (.../advanced_view.php) (revision 133)
@@ -92,12 +92,12 @@
if(strlen($SearchQuery))
{
$SearchQuery = " (".$SearchQuery.")".($CategoryFilter ? 'AND ('.$CategoryFilter.')' : '');
- $objCatList->LoadCategories($SearchQuery,$OrderBy);
+ $objCatList->LoadCategories($SearchQuery,$OrderBy, false, 'set_last');
$IsSearch = TRUE;
}
else
- $objCatList->LoadCategories($CategoryFilter,$OrderBy);
-
+ $objCatList->LoadCategories($CategoryFilter,$OrderBy, false, 'set_last');
+
$TotalItemCount += $objCatList->QueryItemCount;
Index: trunk/kernel/include/portaluser.php
===================================================================
diff -u -r98 -r133
--- trunk/kernel/include/portaluser.php (.../portaluser.php) (revision 98)
+++ trunk/kernel/include/portaluser.php (.../portaluser.php) (revision 133)
@@ -680,14 +680,14 @@
} /* class clsPortalUser*/
-class clsUserManager extends clsItemCollection
+class clsUserManager extends clsItemList //clsItemCollection
{
/*this class wraps common user-related functions */
- var $Page;
+ // var $Page;
function clsUserManager()
{
- $this->clsItemCollection();
+ $this->clsItemCollection(); // clsItemList() // need to use this, but double limit clause being created (normal+default 0,100)
$this->classname = "clsPortalUser";
$this->SourceTable = GetTablePrefix()."PortalUser";
$this->AdminSearchFields = array("Login","FirstName","LastName","Email","Street","City","State","Zip","Country","Phone");
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;
}