home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / SmartyDynamic.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.9 KB  |  77 lines

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2004 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/3_0.txt.                                  |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Author: Laurent Laville <pear@laurent-laville.org>                   |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: SmartyDynamic.php,v 1.1 2004/02/13 15:36:55 farell Exp $
  19.  
  20. require_once 'HTML/QuickForm/Renderer/Array.php';
  21. // fix this if your Smarty is somewhere else
  22. require_once 'Smarty.class.php';
  23.  
  24. /**
  25.  * The ActionDisplay class provides a dynamic form rendering
  26.  * with Smarty template engine.
  27.  *
  28.  * @version    1.1
  29.  * @author     Laurent Laville <pear@laurent-laville.org>
  30.  * @access     public
  31.  * @category   HTML
  32.  * @package    HTML_Progress
  33.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  34.  */
  35.  
  36. class ActionDisplay extends HTML_QuickForm_Action_Display
  37. {
  38.     function _renderForm(&$page) 
  39.     {
  40.         $pageName = $page->getAttribute('name');
  41.         $tabPreview = array_slice ($page->controller->_tabs, -2, 1);
  42.  
  43.         // setup a template object
  44.         $tpl =& new Smarty();
  45.         $tpl->template_dir = './templates';
  46.         $tpl->compile_dir  = './templates_c';
  47.  
  48.         // on preview tab, add progress bar javascript and stylesheet
  49.         if ($pageName == $tabPreview[0][0]) {
  50.             $bar = $page->controller->createProgressBar();
  51.  
  52.             $tpl->assign(array(
  53.                 'qf_style'  => $bar->getStyle(),
  54.                 'qf_script' => $bar->getScript()
  55.                 )
  56.             );
  57.  
  58.             $barElement =& $page->getElement('progressBar');
  59.             $barElement->setText( $bar->toHtml() );
  60.         }
  61.  
  62.         $renderer =& new HTML_QuickForm_Renderer_Array(true);
  63.  
  64.         $page->accept($renderer);
  65.         $tpl->assign('form', $renderer->toArray());
  66.  
  67.         // capture the array stucture 
  68.         // (only for showing in sample template)
  69.         ob_start();
  70.         print_r($renderer->toArray());
  71.         $tpl->assign('dynamic_array', ob_get_contents());
  72.         ob_end_clean();
  73.  
  74.         $tpl->display('smarty-dynamic.tpl');
  75.     }
  76. }
  77. ?>