[phpwebapp-commits] CVS: web_app/parser class.RSNavigTpl.php,NONE,1.1 package.ParseRender.php,1.3,1.
Brought to you by:
dashohoxha
From: Dashamir H. <das...@us...> - 2004-07-13 16:14:58
|
Update of /cvsroot/phpwebapp/web_app/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8772/parser Modified Files: package.ParseRender.php class.Template.php class.RepeatTpl.php class.Render.php class.Parser.php Added Files: class.RSNavigTpl.php Log Message: Modified the <Repeat> tag; added the tag <RSNavig. --- NEW FILE: class.RSNavigTpl.php --- <?php /* Copyright 2001,2002,2003 Dashamir Hoxha, das...@us... This file is part of phpWebApp. phpWebApp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. phpWebApp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with phpWebApp; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** * Recordset Navigator declares the navigation variables * of a paged recordset: {{PrevPage}}, {{NextPage}}, etc. * @package parser */ class RSNavigTpl extends Template { /** The id of the paged recordset. */ var $rsId; function RSNavigTpl($rs_id) { static $id = "RSNavigTpl_01"; Template::Template($id++, "RSNavigTpl"); //call the constructor of the superclass $this->rsId = $rs_id; } /** for debug */ function attribs2html() { $html = Template::attribs2html() . " <tr> <td bgcolor='#eeeeee' valign='top' align='right'>RS:</td> <td bgcolor='#f9f9f9'>" . $this->rsId ." </td> </tr> "; return $html; } } ?> Index: package.ParseRender.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/package.ParseRender.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** package.ParseRender.php 25 Aug 2003 13:18:32 -0000 1.3 --- package.ParseRender.php 13 Jul 2004 16:14:48 -0000 1.4 *************** *** 32,35 **** --- 32,36 ---- include_once PARSER_PATH."class.IfTpl.php"; include_once PARSER_PATH."class.RepeatTpl.php"; + include_once PARSER_PATH."class.RSNavigTpl.php"; include_once PARSER_PATH."class.WebClassTpl.php"; include_once PARSER_PATH."class.WebObjectTpl.php"; Index: class.Template.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.Template.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** class.Template.php 13 Jul 2004 13:18:08 -0000 1.8 --- class.Template.php 13 Jul 2004 16:14:48 -0000 1.9 *************** *** 159,163 **** <br> <a name='$this->id'> </a>[<a href='javascript: back()'>Back</a>] ! <table class='webapp' width='90%' bgcolor='#aaaaaa' border='0' cellspacing='1' cellpadding='2'> <tr> <td bgcolor='#eeeeee' align='right' width='1%'>ID:</td> --- 159,176 ---- <br> <a name='$this->id'> </a>[<a href='javascript: back()'>Back</a>] ! <table class='webapp' width='90%' bgcolor='#aaaaaa' border='0' cellspacing='1' cellpadding='2'>". $this->attribs2html() . $this->vars2html() . " ! <tr><td colspan='2' bgcolor='#f9f9ff'> ! " . $this->contents2html() . " ! </td></tr> ! </table> ! "; ! ! return $htmlTable; ! } ! ! function attribs2html() ! { ! $indent = strtr($this->indent, ' ', '#'); ! $html = " <tr> <td bgcolor='#eeeeee' align='right' width='1%'>ID:</td> *************** *** 174,186 **** </td> </tr> - " . $this->vars2html() . " - <tr><td colspan='2' bgcolor='#f9f9ff'> - " . $this->contents2html() . " - </td></tr> - </table> "; ! ! return $htmlTable; ! } /** @see toHtmlTable() */ --- 187,193 ---- </td> </tr> "; ! return $html; ! } /** @see toHtmlTable() */ *************** *** 214,218 **** { $tpl_id = $matches[1]; ! $tpl = $webPage->getTemplate($tpl_id); //$html .= $tpl->indent; $html .= "<a href='#$tpl_id'>&&$tpl_id;;</a>"; --- 221,225 ---- { $tpl_id = $matches[1]; ! //$tpl = $webPage->getTemplate($tpl_id); //$html .= $tpl->indent; $html .= "<a href='#$tpl_id'>&&$tpl_id;;</a>"; Index: class.RepeatTpl.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.RepeatTpl.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** class.RepeatTpl.php 25 Aug 2003 13:18:32 -0000 1.5 --- class.RepeatTpl.php 13 Jul 2004 16:14:48 -0000 1.6 *************** *** 33,42 **** var $if_empty; - /** The header template. */ - var $header; - - /** The footer template. */ - var $footer; - /** The separator template. */ var $separator; --- 33,36 ---- *************** *** 49,54 **** $this->rsId = $rs_id; $this->if_empty = new Template($this->id."_IfEmpty", "IfEmpty"); - $this->header = new Template($this->id."_Header", "Header"); - $this->footer = new Template($this->id."_Footer", "Footer"); $this->separator = new Template($this->id."_Separator", "Separator"); } --- 43,46 ---- Index: class.Render.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.Render.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** class.Render.php 13 Jul 2004 13:18:08 -0000 1.8 --- class.Render.php 13 Jul 2004 16:14:48 -0000 1.9 *************** *** 133,136 **** --- 133,139 ---- $this->render_WebObjectTpl($tpl); break; + case "RSNavigTpl": + $this->render_RSNavigTpl($tpl); + break; case "RepeatTpl": $this->render_RepeatTpl($tpl); *************** *** 188,191 **** --- 191,199 ---- $main_tpl->head->contents .= '</head>'; $main_tpl->body->contents .= '</body>'; + /* + global $webPage; + print $webPage->template_list(); + exit; + */ $this->render_FileTpl($main_tpl); } *************** *** 228,231 **** --- 236,287 ---- /** + * Render it as a normally, but add in the scope of the + * template the page (navigation) variables of the recordset, + * which are: {{NextPage}}, {{PrevPage}}, etc. + */ + function render_RSNavigTpl($tpl) + { + global $webPage, $tplVars; + + //get the recordset id + $rs_id = $tpl->rsId; + $rs_id = WebApp::replaceVars($rs_id); + //get a reference to the recordset of the RepeatTpl + if (isset($webPage->rs_collection[$rs_id])) + { + //we cannot use "$webPage->getRecordset($rs_id);" here + //because we need a reference to the recordset, + //and PHP functions cannot return a reference + $rs = &$webPage->rs_collection[$rs_id]; + } + else //such a recordset does not exist + { + $err_msg = WebApp::error_msg("Recordset '$rs_id' is undefined."); + $this->render_string($err_msg); + $this->render_Template($tpl); + return; + } + + if ($rs->type<>"PagedRS") + { + $err_msg = "Recordset '$rs_id' is not of type PagedRS."; + $this->render_string(WebApp::error_msg($err_msg)); + $this->render_Template($tpl); + return; + } + + $tplVars->pushScope(); //a new scope for the RSNavig element + + //add page vars (PrevPage, NextPage, etc) + $rs->Open(); + $tplVars->addVars($rs->getPageVars()); + + //render the template + $this->render_tpl($tpl); + + $tplVars->popScope(); + } + + /** * Renders the given $tpl of type RepeatTpl. */ *************** *** 253,283 **** } - $tplVars->pushScope(); //a new scope for the Repeat element - //open the recordset ! if ($rs->type=="PagedRS") ! { ! $rs->Open(); ! //add page vars (PrevPage, NextPage, etc) ! $rs_page_vars = $rs->getPageVars(); ! $tplVars->addVars($rs_page_vars); ! } ! else ! { ! $rs->Open(); ! } ! if ($rs->EOF()) { ! //recordset has no records $this->render_Template($tpl->if_empty); - $tplVars->popScope(); return; } ! //render the header ! $this->render_Template($tpl->header); ! ! //repeat the body for each record $row_nr = 1; while ( !$rs->EOF() ) --- 309,322 ---- } //open the recordset ! $rs->Open(); if ($rs->EOF()) { ! //recordset has no records, it is empty $this->render_Template($tpl->if_empty); return; } ! //render the body of repeat for each record $row_nr = 1; while ( !$rs->EOF() ) *************** *** 293,297 **** $tplVars->addVars($rs->Fields()); $tplVars->addVars($tpl->getVars()); ! $this->render_RepeatBody($tpl); if ($row_nr < $rs->count) --- 332,336 ---- $tplVars->addVars($rs->Fields()); $tplVars->addVars($tpl->getVars()); ! $this->render_tpl($tpl); if ($row_nr < $rs->count) *************** *** 301,318 **** } $tplVars->popScope(); $rs->MoveNext(); $row_nr++; } - - //render the footer - $this->render_Template($tpl->footer); - - $tplVars->popScope(); - } - - function render_RepeatBody($tpl) - { - $this->render_tpl($tpl); } } --- 340,348 ---- } + //get ready for the next iteration $tplVars->popScope(); $rs->MoveNext(); $row_nr++; } } } Index: class.Parser.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/parser/class.Parser.php,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** class.Parser.php 13 Jul 2004 13:18:08 -0000 1.9 --- class.Parser.php 13 Jul 2004 16:14:48 -0000 1.10 *************** *** 259,283 **** switch ($name) { - default: - $name = strtolower($name); - $attr_list = $this->get_attr_list($attribs); - $this->append("<${name}${attr_list}>"); - break; - - case 'DUMMYELEM': - case 'REPEATBODY': - //do nothing, just ignore them - break; - - case "IFEMPTY": - case "HEADER": - case "FOOTER": - case "SEPARATOR": - $this->start_Repeat_subtpl($name); - break; - case "TEMPLATE": case "IF": case "REPEAT": case "INCLUDE": case "HEAD": --- 259,268 ---- switch ($name) { case "TEMPLATE": case "IF": case "REPEAT": + case "IFEMPTY": + case "SEPARATOR": + case "RSNAVIG": case "INCLUDE": case "HEAD": *************** *** 292,295 **** --- 277,291 ---- $this->$start_ELEMENT($attribs); break; + + case 'DUMMYELEM': + case 'REPEATBODY': + //do nothing, just ignore them + break; + + default: + $name = strtolower($name); + $attr_list = $this->get_attr_list($attribs); + $this->append("<${name}${attr_list}>"); + break; } } *************** *** 305,332 **** switch ($name) { - default: - $name = strtolower($name); - $this->append("</$name>"); - break; - - case 'DUMMYELEM': - case 'INCLUDE': - case 'REPEATBODY': - //do nothing, just ignore them - break; - case "TEMPLATE": case "IF": case "REPEAT": - $this->end_TEMPLATE(); - break; - case "IFEMPTY": - case "HEADER": - case "FOOTER": case "SEPARATOR": ! $this->end_Repeat_subtpl($name); ! break; ! case "HEAD": case "BODY": --- 301,310 ---- switch ($name) { case "TEMPLATE": case "IF": case "REPEAT": case "IFEMPTY": case "SEPARATOR": ! case "RSNAVIG": case "HEAD": case "BODY": *************** *** 340,343 **** --- 318,332 ---- $this->$end_ELEMENT(); break; + + case 'DUMMYELEM': + case 'INCLUDE': + case 'REPEATBODY': + //do nothing, just ignore them + break; + + default: + $name = strtolower($name); + $this->append("</$name>"); + break; } } *************** *** 473,476 **** --- 462,483 ---- $this->append('&&'.$tpl->id.';;'); } + + function start_INCLUDE($attribs) + { + //get the filename + $tpl_filename = $attribs['SRC']; + $tpl_filename = WebApp::replaceVars($tpl_filename); + + //create a new file template + $tpl = new FileTpl($tpl_filename); + + //parse the file into this FileTpl + $tpl = $this->parse_file($tpl_filename, $tpl); + + if ($tpl<>UNDEFINED) + { + $this->link_template($tpl); + } + } function start_TEMPLATE($attribs) *************** *** 479,483 **** $this->push_current_tpl($tpl); } - function end_TEMPLATE() { --- 486,489 ---- *************** *** 491,494 **** --- 497,505 ---- $this->push_current_tpl($tpl); } + function end_IF() + { + $tpl = $this->pop_current_tpl(); + $this->link_template($tpl); + } function start_REPEAT($attribs) *************** *** 498,542 **** $this->push_current_tpl($tpl); } ! function start_INCLUDE($attribs) { ! //get the filename ! $tpl_filename = $attribs['SRC']; ! $tpl_filename = WebApp::replaceVars($tpl_filename); ! //create a new file template ! $tpl = new FileTpl($tpl_filename); ! //parse the file into this FileTpl ! $tpl = $this->parse_file($tpl_filename, $tpl); ! if ($tpl<>UNDEFINED) { $this->link_template($tpl); } } ! ! /** $tag has the values "IFEMPTY", "HEADER", "FOOTER" or "SEPARATOR" */ ! function start_Repeat_subtpl($tag) { ! switch ($tag) ! { ! case 'IFEMPTY': ! $tpl_type = 'IfEmpty'; ! break; ! case 'HEADER': ! $tpl_type = 'Header'; ! break; ! case 'FOOTER': ! $tpl_type = 'Footer'; ! break; ! case 'SEPARATOR': ! $tpl_type = 'Separator'; ! break; ! } ! $tpl_id = $this->current_tpl->id."_".$tpl_type; //create a new template of this id and this type ! $tpl = new Template($tpl_id, $tpl_type); //the parent of $tpl is the current_tpl --- 509,556 ---- $this->push_current_tpl($tpl); } + function end_REPEAT() + { + $tpl = $this->pop_current_tpl(); + $this->link_template($tpl); + } ! function start_IFEMPTY($attribs) { ! $tpl_id = $this->current_tpl->id.'_IfEmpty'; ! //create a new template of this id and this type ! $tpl = new Template($tpl_id, 'IfEmpty'); ! //the parent of $tpl is the current_tpl ! $tpl->parent = &$this->current_tpl; ! //set $tpl as current_tpl ! $this->push_current_tpl($tpl); ! } ! function end_IFEMPTY() ! { ! $tpl = $this->pop_current_tpl(); ! ! //add the subtemplate to the Repeat template ! if ($this->current_tpl->type=="RepeatTpl") { + $this->current_tpl->if_empty = $tpl; + } + else + { + $msg = "<IfEmpty> element can be used " + ."only inside a <Repeat> element"; + $err_msg = WebApp::error_msg($msg); + $this->append($err_msg); $this->link_template($tpl); } } ! ! function start_SEPARATOR($attribs) { ! $tpl_id = $this->current_tpl->id.'_Separator'; //create a new template of this id and this type ! $tpl = new Template($tpl_id, 'Separator'); //the parent of $tpl is the current_tpl *************** *** 546,559 **** $this->push_current_tpl($tpl); } ! ! /** $tag has the values "IFEMPTY", "HEADER", "FOOTER" or "SEPARATOR" */ ! function end_Repeat_subtpl($tag) { $tpl = $this->pop_current_tpl(); //add the subtemplate to the Repeat template ! if ($this->current_tpl->type<>"RepeatTpl") { ! $msg = "<$tag> element can be used " ."only inside a <Repeat> element"; $err_msg = WebApp::error_msg($msg); --- 560,575 ---- $this->push_current_tpl($tpl); } ! function end_SEPARATOR() { $tpl = $this->pop_current_tpl(); //add the subtemplate to the Repeat template ! if ($this->current_tpl->type=="RepeatTpl") { ! $this->current_tpl->separator = $tpl; ! } ! else ! { ! $msg = "<Separator> element can be used " ."only inside a <Repeat> element"; $err_msg = WebApp::error_msg($msg); *************** *** 561,582 **** $this->link_template($tpl); } ! else ! { ! switch ($tag) ! { ! case "IFEMPTY": ! $this->current_tpl->if_empty = $tpl; ! break; ! case "HEADER": ! $this->current_tpl->header = $tpl; ! break; ! case "FOOTER": ! $this->current_tpl->footer = $tpl; ! break; ! case "SEPARATOR": ! $this->current_tpl->separator = $tpl; ! break; ! } ! } } --- 577,596 ---- $this->link_template($tpl); } ! } ! ! function start_RSNAVIG($attribs) ! { ! $rs_id = $attribs['RS']; ! ! //create a new template of this id and this type ! $tpl = new RSNavigTpl($rs_id); ! ! //set $tpl as current_tpl ! $this->push_current_tpl($tpl); ! } ! function end_RSNAVIG() ! { ! $tpl = $this->pop_current_tpl(); ! $this->link_template($tpl); } *************** *** 597,601 **** $this->push_current_tpl($tpl); } - function end_HEAD() { --- 611,614 ---- *************** *** 629,633 **** $this->append('<body'.$this->get_attr_list($attribs).'>'); } - function end_BODY() { --- 642,645 ---- *************** *** 659,663 **** $this->copy_level = 0; } - function end_WEBBOX() { --- 671,674 ---- *************** *** 716,720 **** $this->copy_level = 0; } - function end_WEBCLASS() { --- 727,730 ---- *************** *** 816,820 **** $this->push_current_tpl($tpl); } - function end_RECORDSET() { --- 826,829 ---- *************** *** 865,869 **** $this->push_current_tpl($tpl); } - function end_DBCOMMAND() { --- 874,877 ---- *************** *** 883,887 **** $this->push_current_tpl($tpl); } - function end_QUERY() { --- 891,894 ---- *************** *** 903,907 **** $this->push_current_tpl($tpl); } - function end_VAR() { --- 910,913 ---- *************** *** 935,943 **** { print "\$this->tpl_stack[$i]"; ! print $this->tpl_stack[$i]->toHtmlTable(); } else { ! print "\$this->tpl_stack[$i]='".$this->tpl_stack[$i]."'<br>\n"; } } --- 941,949 ---- { print "\$this->tpl_stack[$i]"; ! print $this->tpl_stack[$i]->id."\n"; } else { ! print "\$this->tpl_stack[$i]='".$this->tpl_stack[$i]."'\n"; } } |