//--------------------------------
// Work functions
//--------------------------------
// Read records
// Main working function, which reads the corresponding records from the table based on the given conditions
// The returned value is a two-dimensional array. Result [Record Number] [field name]
Function ReadList (){
$ SQL = "SELECT * FROM". $ this-> Table. "". $ this-> Condition. "ORDER BY". $ this-> Id. "DESC ";
$ Stmt = OCIParse ($ this-> LinkId, $ SQL );
$ Bool = OCIExecute ($ stmt );
If (! $ Bool ){
Echo "connection failed! ";
OCILogoff ($ this-> LinkId );
Exit;
}
Else {
$ Ncols = OCINumCols ($ stmt );
For ($ I = 1; $ I <= $ ncols; $ I ++)
$ Column_name [$ I] = OCIColumnName ($ stmt, $ I );
$ K = 0;
For ($ j = 0; $ j <$ this-> StartRec + $ this-> Offset; $ j ++) OCIFetch ($ stmt );
For ($ j = 0; $ j <$ this-> MaxLine; $ j ++ ){
If (OCIFetch ($ stmt )){
$ K ++;
For ($ I = 1; $ I <= $ ncols; $ I ++)
$ Temp [$ column_name [$ I] = OCIResult ($ stmt, $ I );
$ This-> Result [] = $ temp;
}
Else break;
}
$ This-> Number = $ k;
}
OCIFreeStatement ($ stmt );
Return $ this-> Result;
}
// Read the latest record
// Topnum specifies the number of records to read
Function ReadTopList ($ topnum ){
$ SQL = "SELECT * FROM". $ this-> Table. "". $ this-> Condition. "ORDER BY". $ this-> Id. "DESC ";
$ Stmt = OCIParse ($ this-> LinkId, $ SQL );
$ Bool = OCIExecute ($ stmt );
If (! $ Bool ){
Echo "connection failed! ";
OCILogoff ($ this-> LinkId );
Exit;
}
Else {
$ Ncols = OCINumCols ($ stmt );
For ($ I = 1; $ I <= $ ncols; $ I ++)
$ Column_name [$ I] = OCIColumnName ($ stmt, $ I );
$ K = 0;
For ($ j = 0; $ j <$ topnum; $ j ++ ){
If (OCIFetch ($ stmt )){
$ K ++;
For ($ I = 1; $ I <= $ ncols; $ I ++)
$ Temp [$ column_name [$ I] = OCIResult ($ stmt, $ I );
$ This-> TopResult [] = $ temp;
}
Else break;
}
$ This-> TopNumber = $ k;
}
OCIFreeStatement ($ stmt );
Return $ this-> TopResult;
}
//---------------------------
// Paging related
//---------------------------
// Display the current page and the total number of pages
// This function is called after GetPage.
Function ThePage (){
Echo "no.". $ this-> CPages. "Page/total". $ this-> TPages. "Page ";
}
// Display the flip button
// This function must be called after the GetPage () function
// Display the next and last pages, and add the parameters to be passed
Function Page (){
$ K = count ($ this-> PageQuery );
$ StrQuery = ""; // generate a parameter string to be passed
For ($ I = 0; $ I <$ k; $ I ++ ){
$ StrQuery. = "&". $ this-> PageQuery [$ I] [key]. "=". $ this-> PageQuery [$ I] [value];
}
Return $ strQuery;
}
Function PrePage ($ strQuery ){
$ Prev = $ this-> Offset-$ this-> MaxLine;
If ($ prev> = 0)
Echo "<A href = $ PHP_SELF? Offset = ". $ prev. $ strQuery." class = newslink> previous page </A> ";
Else if ($ this-> TheFirstPage! = NULL)
Echo "<A href =". $ this-> TheFirstPage. "class = newslink> previous page </A> ";
Else echo "Previous Page ";
}
Function NexPage ($ strQuery ){
$ Next = $ this-> Offset + $ this-> MaxLine;
$ K = $ this-> Total-$ this-> StartRec;
If ($ next <$ k)
Echo "<A href = $ PHP_SELF? Offset = ". $ next. $ strQuery." class = newslink> next page </A> ";
Else
Echo "next page ";
}
//------------------------------------
// Record group
//----------------------------------
// Display group
Function NumPage (){
$ First = ($ this-> CGroup-1) * ($ this-> PGroup) + 1;
$ Last = ($ first + $ this-> PGroup> $ this-> TPages )? ($ This-> TPages + 1) :( $ first + $ this-> PGroup );
$ Pr = ($ this-> CGroup-2> = 0 )? ($ This-> CGroup-2) * ($ this-> PGroup) + 1) :(-1 );
$ Prev = ($ pr! =-1 )? ($ Pr-1) * $ this-> MaxLine) :( 0 );
$ Ne = ($ this-> CGroup * $ this-> PGroup + 1 <= $ this-> TPages )? ($ This-> CGroup * $ this-> PGroup + 1) :(-1 );
$ Next = ($ ne! =-1 )? ($ Ne-1) * $ this-> MaxLine) :( 0 );
$ K = count ($ this-> PageQuery );
$ StrQuery = ""; // generate a parameter string to be passed
For ($ I = 0; $ I <$ k; $ I ++ ){
$ StrQuery. = "&". $ this-> PageQuery [$ I] [key]. "=". $ this-> PageQuery [$ I] [value];
}
If ($ first! = 1)
Echo "<A href = $ PHP_SELF? Offset = ". $ prev. $ strQuery."> </a> ";
For ($ I = $ first; $ I <$ last; $ I ++ ){
If ($ this-> CPages! = $ I ){
$ Current = ($ i-1) * $ this-> MaxLine;
Echo "<A href = $ PHP_SELF? Offset = ". $ current. $ strQuery."> ". $ I." </a> ";
}
Else echo "<font color = # e00729>". $ I. "</font> ";
}
If ($ ne! =-1)
Echo "<A href = $ PHP_SELF? Offset = ". $ next. $ strQuery." >></a> ";
}
// ***** End class
}
?>