PEAR Progress2 logo

HTML_Progress2 : The Definitive Guide

Progress Generator wizard usage

Figure 21.6. Progress Generator wizard usage

Progress Generator wizard usage

Goals of this example are to show how to use another driver (HTMLPage2) than the standard (Default), use another external stylesheet to change color scheme easily, and add a user-process to download the PHP/CSS code results.

HTMLPage2 driver used its own default stylesheet which is a blue skin. Here, we prefer to use the dark-grey skin of SmartyDynamic driver (see $css).

Example 21.6. Progress Generator build with PEAR::HTML_Page2

  1. <?php
  2. require_once 'HTML/Progress2/Generator.php';
  3. require_once 'HTML/Progress2/Generator/HTMLPage2.php';
  4. require_once 'HTML/Progress2/Generator/Process.php';
  5.  
  6. class MyProcessHandler extends ActionProcess
  7. {
  8.     function perform(&$page, $actionName)
  9.     {
  10.         if ($actionName == 'cancel') {
  11.             echo '<h1>Progress2 Generator Demonstration is Over</h1>';
  12.             echo '<p>Hope you\'ve enjoyed. See you later!</p>';
  13.         } else {
  14.             // Checks whether the pages of the controller are valid
  15.             $page->isFormBuilt() or $page->buildForm();
  16.             $page->controller->isValid();
  17.  
  18.             // what kind of source code is requested
  19.             $code = $page->exportValue('phpcss');
  20.             $pb = $page->controller->createProgressBar();
  21.  
  22.             $phpCode = (isset($code['P']) === true);
  23.             $cssCode = (isset($code['C']) === true);
  24.  
  25.             if ($cssCode && !$phpCode) {
  26.                 $strCSS = $this->sprintCSS($pb);
  27.                 $this->exportOutput($strCSS, 'text/css');
  28.             }
  29.             if ($phpCode) {
  30.                 $strPHP = $this->sprintPHP($pb, $cssCode);
  31.                 $this->exportOutput($strPHP, 'text/php');
  32.             }
  33.  
  34.             // reset session data
  35.             $page->controller->container(true);
  36.         }
  37.     }
  38. }
  39.  
  40. session_start();
  41.  
  42. $tabbed =& HTML_Progress2_Generator::singleton();
  43.  
  44. $tabbed->addActions(array('dump' => 'ActionDump', 'process' => 'MyProcessHandler'));
  45.  
  46. $pear = 'c:\php4';
  47. $css  = $pear . '\pear\data\HTML_Progress2\smartydynamic.css';
  48. $tabbed->addAction('display', new ActionDisplay($css));
  49.  
  50. $tabbed->run();
  51. ?>
[Caution] Caution
Of course you should fix the path of $pear to your own PEAR directory installation.
HTML_Progress2 : The Definitive Guide v 2.4.0 : April 20, 2007