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;