1. <?php
  2. /**
  3. * A Web GUI frontend for the PEAR_PackageFileManager2 class.
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * LICENSE: This source file is subject to version 3.01 of the PHP license
  8. * that is available through the world-wide-web at the following URI:
  9. * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
  10. * the PHP License and are unable to obtain it through the web, please
  11. * send a note to license@php.net so we can mail you a copy immediately.
  12. *
  13. * @category   PEAR
  14. * @package    PEAR_PackageFileManager_Frontend_Web
  15. * @author     Laurent Laville <pear@laurent-laville.org>
  16. * @copyright  2005-2006 Laurent Laville
  17. * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  18. * @version    CVS: $Id:$
  19. * @since      File available since Release 0.1.0
  20. */
  21.  
  22. if (!defined('PEAR_PACKAGEFILEMANAGER_FRONTEND_WEBDIR')) {
  23.     define('PEAR_PACKAGEFILEMANAGER_FRONTEND_WEBDIR',
  24.         dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Web' . DIRECTORY_SEPARATOR);
  25. }
  26.  
  27. require_once 'HTML/QuickForm/Controller.php';
  28. require_once 'HTML/QuickForm/Action/Submit.php';
  29. require_once 'HTML/QuickForm/Action/Jump.php';
  30. require_once 'HTML/QuickForm/Action/Display.php';
  31. require_once 'HTML/QuickForm/Action/Direct.php';
  32. require_once PEAR_PACKAGEFILEMANAGER_FRONTEND_WEBDIR . 'pages.php';
  33. require_once 'PHP/Compat.php';
  34.  
  35. PHP_Compat::loadFunction('array_combine');
  36.  
  37. /**
  38. * A Web GUI frontend for the PEAR_PackageFileManager2 class.
  39. *
  40. * A Web frontend for the PEAR_PackageFileManager2 class.
  41. * It makes it easier for developers to create and maintain
  42. * PEAR package.xml files (versions 1.0 and 2.0).
  43. *
  44. * @category   PEAR
  45. * @package    PEAR_PackageFileManager_Frontend_Web
  46. * @author     Laurent Laville <pear@laurent-laville.org>
  47. * @copyright  2005-2006 Laurent Laville
  48. * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  49. * @version    Release: @package_version@
  50. * @since      Class available since Release 0.1.0
  51. */
  52.  
  53. class PEAR_PackageFileManager_Frontend_Web extends PEAR_PackageFileManager_Frontend
  54. {
  55.     /**
  56.      * Instance of a QF controller
  57.      *
  58.      * @var    object
  59.      * @since  0.1.0
  60.      * @access private
  61.      */
  62.     var $_qfc;
  63.  
  64.     /**
  65.      * Constructor (ZE1)
  66.      *
  67.      * @param  mixed     $packagedirectory    Path to the base directory of the package
  68.      * @param  mixed     $pathtopackagefile   Path to an existing package file to read in
  69.      * @since  0.1.0
  70.      * @access public
  71.      */
  72.     function PEAR_PackageFileManager_Frontend_Web($driver, $packagedirectory, $pathtopackagefile)
  73.     {
  74.         $this->__construct($driver, $packagedirectory, $pathtopackagefile);
  75.     }
  76.  
  77.     /**
  78.      * Constructor (ZE2)
  79.      *
  80.      * @param  mixed     $packagedirectory    Path to the base directory of the package
  81.      * @param  mixed     $pathtopackagefile   Path to an existing package file to read in
  82.      * @since  0.1.0
  83.      * @access protected
  84.      */
  85.     function __construct($driver, $packagedirectory, $pathtopackagefile)
  86.     {
  87.         parent::PEAR_PackageFileManager_Frontend($driver, $packagedirectory, $pathtopackagefile);
  88.  
  89.         // build a new non-modal controller
  90.         $this->_qfc = new HTML_QuickForm_Controller($driver, false);
  91.     }
  92.  
  93.     /**
  94.      * Adds all pages of wizard at once
  95.      *
  96.      * @access public
  97.      * @since  0.1.0
  98.      */
  99.     function addPages()
  100.     {
  101.          $pages = $this->getOption(array('settings', 'gui', 'pages'), false);
  102.  
  103.          foreach($pages['pages']['page'] as $page) {
  104.              $pageN = array('settings', 'gui', 'pages', array('page', array('id' => $page['@']['id'])));
  105.              $this->addPage($pageN);
  106.          }
  107.     }
  108.  
  109.     /**
  110.      * Add a specific page to wizard or each page one by one
  111.      *
  112.      * @access public
  113.      * @since  0.1.0
  114.      */
  115.     function addPage($pagePath)
  116.     {
  117.         $page = $this->getOption($pagePath, false);
  118.         if ($this->hasErrors()) {
  119.             return;
  120.         }
  121.  
  122.         $page = array_values($page);
  123.         $className = $page[0]['@']['class'];
  124.         $pageName  = $page[0]['@']['name'];
  125.  
  126.         $qfcPage =& new $className($pageName);
  127.         $this->_qfc->addPage($qfcPage);
  128.  
  129.         // adds additional action
  130.         foreach ($page[0] as $action => $attr) {
  131.             if ($action == '#' || $action == '@') {
  132.                 continue;
  133.             }
  134.             $qfcPage->addAction($action, new $attr['@']['class']);
  135.         }
  136.  
  137.         // adds common action on each page
  138.         $this->_qfc->addAction($pageName, new HTML_QuickForm_Action_Direct());
  139.     }
  140.  
  141.     /**
  142.      * Adds common actions for the frontend wizard
  143.      *
  144.      * @access public
  145.      * @since  0.1.0
  146.      */
  147.     function addActions()
  148.     {
  149.         // adds display driver
  150.         $ActionDisplay = $this->getOption(array('settings','gui','actions','display'));
  151.         if (!class_exists($ActionDisplay)) {
  152.             include_once PEAR_PACKAGEFILEMANAGER_FRONTEND_WEBDIR . 'Default.php';
  153.             $ActionDisplay = 'ActionDisplay';
  154.         }
  155.         $this->_qfc->addAction('display', new $ActionDisplay() );
  156.  
  157.         // adds basic actions (abort, commit, reset)
  158.         $ActionProcess = $this->getOption(array('settings','gui','actions','process'));
  159.         if (!class_exists($ActionProcess)) {
  160.             include_once PEAR_PACKAGEFILEMANAGER_FRONTEND_WEBDIR . 'Process.php';
  161.             $ActionProcess = 'ActionProcess';
  162.         }
  163.         $this->_qfc->addAction('abort'new $ActionProcess() );
  164.         $this->_qfc->addAction('commit', new $ActionProcess() );
  165.         $this->_qfc->addAction('reset'new $ActionProcess() );
  166.  
  167.         // adds dump class action (if necessary)
  168.         $ActionDump = $this->getOption(array('settings','gui','actions','dump'));
  169.         if ($ActionDump) {
  170.             if (!class_exists($ActionDump)) {
  171.                 include_once PEAR_PACKAGEFILEMANAGER_FRONTEND_WEBDIR . 'Dump.php';
  172.                 $ActionDump = 'ActionDump';
  173.             }
  174.             $this->_qfc->addAction('dump', new $ActionDump() );
  175.         }
  176.     }
  177.  
  178.     /**
  179.      * Applies all defaults
  180.      *
  181.      * @access public
  182.      * @since  0.1.0
  183.      */
  184.     function applyDefaults()
  185.     {
  186.         $sess =& $this->container();
  187.  
  188.         $hasDefaults = (count($sess['defaults']) > 0);
  189.         if ($hasDefaults) {
  190.             $defaults = $sess['defaults'];
  191.         } else {
  192.             $settings = $this->getOption(array('settings','gui','pages'), false);
  193.             $defaults = array();
  194.             foreach($settings['pages']['page'] as $page) {
  195.                 $type = strtolower($page['@']['name']);
  196.                 $def = $this->getDefaults($type);
  197.                 if (is_array($def)) {
  198.                     $defaults = array_merge($defaults, $def);
  199.                 }
  200.             }
  201.         }
  202.         $this->_qfc->setDefaults($defaults);
  203.     }
  204.  
  205.     /**
  206.      * Processes the request.
  207.      *
  208.      * @access public
  209.      * @since  0.1.0
  210.      */
  211.     function run()
  212.     {
  213.         $this->applyDefaults();
  214.         $this->_qfc->run();
  215.     }
  216. }
  217. ?>