PEAR_Frontend_Web
[ class tree: PEAR_Frontend_Web ] [ index: PEAR_Frontend_Web ] [ all elements ]

Source for file Web.php

Documentation is available at Web.php

  1. <?php
  2. /*
  3.   +----------------------------------------------------------------------+
  4.   | PHP Version 4                                                        |
  5.   +----------------------------------------------------------------------+
  6.   | Copyright (c) 1997-2003 The PHP Group                                |
  7.   +----------------------------------------------------------------------+
  8.   | This source file is subject to version 2.02 of the PHP license,      |
  9.   | that is bundled with this package in the file LICENSE, and is        |
  10.   | available at through the world-wide-web at                           |
  11.   | http://www.php.net/license/2_02.txt.                                 |
  12.   | If you did not receive a copy of the PHP license and are unable to   |
  13.   | obtain it through the world-wide-web, please send a note to          |
  14.   | license@php.net so we can mail you a copy immediately.               |
  15.   +----------------------------------------------------------------------+
  16.   | Author: Christian Dickmann <dickmann@php.net>                        |
  17.   +----------------------------------------------------------------------+
  18.  
  19.   $Id: Web.php,v 1.43 2007/04/03 23:21:00 cellog Exp $
  20. */
  21.  
  22. require_once "PEAR/Frontend.php";
  23. require_once "PEAR/Remote.php";
  24. require_once "HTML/Template/IT.php";
  25. require_once "Net/UserAgent/Detect.php";
  26.  
  27. /**
  28. * PEAR_Frontend_Web is a HTML based Webfrontend for the PEAR Installer
  29. *
  30. * The Webfrontend provides basic functionality of the Installer, such as
  31. * a package list grouped by categories, a search mask, the possibility
  32. * to install/upgrade/uninstall packages and some minor things.
  33. * PEAR_Frontend_Web makes use of the PEAR::HTML_IT Template engine which
  34. * provides the possibillity to skin the Installer.
  35. *
  36. @author  Christian Dickmann <dickmann@php.net>
  37. @package PEAR_Frontend_Web
  38. @access  private
  39. */
  40.  
  41. class PEAR_Frontend_Web extends PEAR_Frontend
  42. {
  43.     // {{{ properties
  44.  
  45.     /**
  46.      * What type of user interface this frontend is for.
  47.      * @var string 
  48.      * @access public
  49.      */
  50.     var $type 'Web';
  51.  
  52.     /**
  53.      * Container, where values can be saved temporary
  54.      * @var array 
  55.      * @access private
  56.      */
  57.     var $_data = array();
  58.     var $_savedOutput = array();
  59.  
  60.     // }}}
  61.     var $config;
  62.  
  63.     var $_no_delete_pkgs = array(
  64.         'Archive_Tar',
  65.         'Console_Getopt',
  66.         'HTML_Template_IT',
  67.         'Net_UserAgent_Detect',
  68.         'PEAR',
  69.         'PEAR_Frontend_Web',
  70.         'Structures_Graph',
  71.     );
  72.  
  73.     var $_no_delete_chans = array(
  74.         'pear.php.net',
  75.         '__uri',
  76.         );
  77.  
  78.     /**
  79.      * Flag to determine whether to treat all output as information from a post-install script
  80.      * @var bool 
  81.      * @access private
  82.      */
  83.     var $_installScript = false;
  84.     // {{{ constructor
  85.  
  86.     function PEAR_Frontend_Web()
  87.     {
  88.         parent::PEAR();
  89.         $GLOBALS['_PEAR_Frontend_Web_log''';
  90.         $this->config &$GLOBALS['_PEAR_Frontend_Web_config'];
  91.     }
  92.  
  93.     // }}}
  94.  
  95.     function setConfig(&$config)
  96.     {
  97.         $this->config &$config;
  98.     }
  99.  
  100.     // {{{ displayLine()
  101.  
  102.     /* XXX some methods from CLI following. should be deleted in the near future */
  103.     function displayLine($text)
  104.     {
  105.         trigger_error("Frontend::display deprecated"E_USER_ERROR);
  106.     }
  107.  
  108.     // }}}
  109.     // {{{ display()
  110.  
  111.     function display($text)
  112.     {
  113.         trigger_error("Frontend::display deprecated"E_USER_ERROR);
  114.     }
  115.  
  116.     // }}}
  117.     // {{{ userConfirm()
  118.  
  119.     function userConfirm($prompt$default 'yes')
  120.     {
  121.         trigger_error("Frontend::display deprecated"E_USER_ERROR);
  122.         return false;
  123.     }
  124.  
  125.     // }}}
  126.     // {{{ displayStart(prompt, [default])
  127.  
  128.     function displayStart()
  129.     {
  130.         $tpl $this->_initTemplate("start.tpl.html"'PEAR Installer');
  131.         $tpl->setVariable('Version''0.5');
  132.         $tpl->show();
  133.         exit;
  134.     }
  135.  
  136.     // }}}
  137.     // {{{ _initTemplate()
  138.  
  139.     /**
  140.      * Initialize a TemplateObject, add a title, and icon and add JS and CSS for DHTML
  141.      *
  142.      * @param string  $file     filename of the template file
  143.      * @param string  $title    (optional) title of the page
  144.      * @param string  $icon     (optional) iconhandle for this page
  145.      * @param boolean $useDHTML (optional) add JS and CSS for DHTML-features
  146.      *
  147.      * @access private
  148.      *
  149.      * @return object Object of HTML/IT - Template - Class
  150.      */
  151.  
  152.     function _initTemplate($file$title ''$icon ''$useDHTML = true)
  153.     {
  154.         $tpl = new HTML_Template_IT(dirname(__FILE__)."/Web");
  155.         $tpl->loadTemplateFile($file);
  156.         $tpl->setVariable("InstallerURL"$_SERVER["PHP_SELF"]);
  157.         if ($this->config->get('preferred_mirror'!= $this->config->get('default_channel')) {
  158.             $mirror ' (mirror ' .$this->config->get('preferred_mirror'')';
  159.         else {
  160.             $mirror '';
  161.         }
  162.         $tpl->setVariable("_default_channel"$this->config->get('default_channel'$mirror);
  163.         $tpl->setVariable("ImgPEAR"$_SERVER["PHP_SELF"].'?img=pear');
  164.         if ($title{
  165.             $tpl->setVariable("Title"$title);
  166.         }
  167.         if ($icon{
  168.             $tpl->setCurrentBlock("TitleBlock");
  169.             $tpl->setVariable("_InstallerURL"$_SERVER["PHP_SELF"]);
  170.             $tpl->setVariable("_Title"$title);
  171.             $tpl->setVariable("_Icon"$icon);
  172.             $tpl->parseCurrentBlock();
  173.         }
  174.  
  175.         $tpl->setCurrentBlock();
  176.  
  177.         if ($useDHTML && Net_UserAgent_Detect::getBrowser('ie5up'== 'ie5up'{
  178.             $dhtml = true;
  179.         else {
  180.             $dhtml = false;
  181.         }
  182.  
  183.         if ($dhtml{
  184.             $tpl->setVariable("JS"'dhtml');
  185.             $css '<link rel="stylesheet" href="'.$_SERVER['PHP_SELF'].'?css=dhtml" />';
  186.             $tpl->setVariable("DHTMLcss"$css);
  187.         else {
  188.             $tpl->setVariable("JS"'nodhtml');
  189.         }
  190.  
  191.         if (!isset($_SESSION['_PEAR_Frontend_Web_js']|| $_SESSION['_PEAR_Frontend_Web_js'== false{
  192.             $tpl->setCurrentBlock('JSEnable');
  193.             $tpl->setVariable('RedirectURL'$_SERVER['REQUEST_URI'](!empty($_GET'&' '?'.'enableJS=1');
  194.             $tpl->parseCurrentBlock();
  195.             $tpl->setCurrentBlock();
  196.         }
  197.  
  198.         return $tpl;
  199.     }
  200.  
  201.     // }}}
  202.     // {{{ displayError()
  203.  
  204.     /**
  205.      * Display an error page
  206.      *
  207.      * @param mixed   $eobj  PEAR_Error object or string containing the error message
  208.      * @param string  $title (optional) title of the page
  209.      * @param string  $img   (optional) iconhandle for this page
  210.      * @param boolean $popup (optional) popuperror or normal?
  211.      *
  212.      * @access public
  213.      *
  214.      * @return null does not return anything, but exit the script
  215.      */
  216.  
  217.     function displayError($eobj$title 'Error'$img 'error'$popup = false)
  218.     {
  219.         $msg '';
  220.         if (isset($GLOBALS['_PEAR_Frontend_Web_log']&& trim($GLOBALS['_PEAR_Frontend_Web_log'])) {
  221.             $msg trim($GLOBALS['_PEAR_Frontend_Web_log'])."\n\n";
  222.         }
  223.  
  224.         if (PEAR::isError($eobj)) {
  225.             $msg .= trim($eobj->getMessage());
  226.         else {
  227.             $msg .= trim($eobj);
  228.         }
  229.  
  230.         $msg nl2br($msg."\n");
  231.  
  232.         $tplfile ($popup "error.popup.tpl.html" "error.tpl.html");
  233.         $tpl $this->_initTemplate($tplfile$title$img);
  234.  
  235.         $tpl->setVariable("Error"$msg);
  236.         $command_map = array(
  237.             "install"   => "list-all",
  238.             "uninstall" => "list-all",
  239.             "upgrade"   => "list-all",
  240.             );
  241.         if (isset($_GET['command'])) {
  242.             if (isset($command_map[$_GET['command']])) {
  243.                 $_GET['command'$command_map[$_GET['command']];
  244.             }
  245.             $tpl->setVariable("param"'?command='.$_GET['command']);
  246.         }
  247.  
  248.         $tpl->show();
  249.         exit;
  250.     }
  251.  
  252.     // }}}
  253.     // {{{ displayFatalError()
  254.  
  255.     /**
  256.      * Alias for PEAR_Frontend_Web::displayError()
  257.      *
  258.      * @see PEAR_Frontend_Web::displayError()
  259.      */
  260.  
  261.     function displayFatalError($eobj$title 'Error'$img 'error')
  262.     {
  263.         $this->displayError($eobj$title$img);
  264.     }
  265.  
  266.     function displayErrorImg($eobj)
  267.     {
  268.         $msg '';
  269.         if (isset($GLOBALS['_PEAR_Frontend_Web_log']&& trim($GLOBALS['_PEAR_Frontend_Web_log']))
  270.             $msg trim($GLOBALS['_PEAR_Frontend_Web_log'])."\n\n";
  271.  
  272.         $_SESSION['_PEAR_Frontend_Web_LastError']     $eobj;
  273.         $_SESSION['_PEAR_Frontend_Web_LastError_log'$msg;
  274.         echo '<script language="javascript">';
  275.         printf('window.open("%s?command=show-last-error", "PEAR", "width=600, height=400");',
  276.             $_SERVER["PHP_SELF"]);
  277.         echo ' </script>';
  278.         printf('<img src="%s?img=install_fail" border="0">'$_SERVER['PHP_SELF']);
  279.         exit;
  280.     }
  281.  
  282.     // }}}
  283.     // {{{ _outputListChannels()
  284.  
  285.     function _outputListChannels($data$title 'Manage Installer Channels',
  286.                             $img 'pkglist'$useDHTML = false$paging = true)
  287.     {
  288.         $tpl $this->_initTemplate("channel.list.tpl.html"$title$img$useDHTML);
  289.         if (!isset($data['data'])) {
  290.             $data['data'= array();
  291.         }
  292.         $pageId = isset($_GET['from']$_GET['from': 0;
  293.         $paging_data $this->__getData($pageId5count($data['data'])false);
  294.  
  295.         $data['data'array_slice($data['data']$pageId5);
  296.  
  297.         $links = array();
  298.         $from $paging_data['from'];
  299.         $to $paging_data['to'];
  300.  
  301.         // Generate Linkinformation to redirect to _this_ page after performing an action
  302.         $link_str '<a href="?command=%s&from=%s" class="paging_link">%s</a>';
  303.  
  304.         $command = isset($_GET['command']$_GET['command''list-channels';
  305.  
  306.         if ($paging_data['from']>1{
  307.             $links['back'sprintf($link_str$command$paging_data['prev']'&lt;&lt;');
  308.         else {
  309.             $links['back''';
  310.         }
  311.  
  312.         if $paging_data['next']{
  313.             $links['next'sprintf($link_str$command$paging_data['next']'&gt;&gt;');
  314.         else {
  315.             $links['next''';
  316.         }
  317.  
  318.         $links['current''&from=' $paging_data['from'];
  319.  
  320.         $tpl->setVariable('Prev'$links['back']);
  321.         $tpl->setVariable('Next'$links['next']);
  322.         $tpl->setVariable('PagerFrom'$from);
  323.         $tpl->setVariable('PagerTo'$to);
  324.         $tpl->setVariable('PagerCount'$paging_data['numrows']);
  325.         $reg &$this->config->getRegistry();
  326.         foreach($data['data'as $row{
  327.             list($channel$summary$row;
  328.             $tpl->setCurrentBlock("Row");
  329.             $tpl->setVariable("ImgPackage"$_SERVER["PHP_SELF"].'?img=package');
  330.             $images = array(
  331.                 'delete' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="delete">',
  332.                 'info' => '<img src="'.$_SERVER["PHP_SELF"].'?img=info"  width="17" height="19" border="0" alt="info">',
  333.                 );
  334.             $urls   = array(
  335.                 'delete' => sprintf('%s?command=channel-delete&chan=%s%s',
  336.                     $_SERVER["PHP_SELF"]urlencode($channel)$links['current']),
  337.                 'info' => sprintf('%s?command=channel-info&chan=%s',
  338.                     $_SERVER["PHP_SELF"]urlencode($channel)),
  339.                 );
  340.  
  341.             // detect whether any packages from this channel are installed
  342.             $anyinstalled $reg->listPackages($channel);
  343.             $id 'id="'.$channel.'_href"';
  344.             if (is_array($anyinstalled&& count($anyinstalled)) {
  345.                 $del '';
  346.             else {
  347.                 $del sprintf('<a href="%s" onClick="return deleteChan(\'%s\');" %s >%s</a>',
  348.                     $urls['delete']$channel$id$images['delete']);
  349.             }
  350.             $info    sprintf('<a href="%s">%s</a>'$urls['info'],    $images['info']);
  351.  
  352.             if (in_array($channel$this->_no_delete_chans)) {
  353.                 $del '';
  354.             }
  355.  
  356.             $tpl->setVariable("NewChannelURL"$_SERVER['PHP_SELF']);
  357.             $tpl->setVariable("Delete"$del);
  358.             $tpl->setVariable("Info"$info);
  359.             $tpl->setVariable("Channel"$channel);
  360.             $tpl->setVariable("Summary"nl2br($summary));
  361.             $tpl->parseCurrentBlock();
  362.         }
  363.         $tpl->show();
  364.         return true;
  365.     }
  366.     // }}}
  367.     // {{{ _outputListAll()
  368.  
  369.     /**
  370.      * Output a list of packages, grouped by categories. Uses Paging
  371.      *
  372.      * @param array   $data     array containing all data to display the list
  373.      * @param string  $title    (optional) title of the page
  374.      * @param string  $img      (optional) iconhandle for this page
  375.      * @param boolean $useDHTML (optional) add JS and CSS for DHTML-features
  376.      * @param boolean $paging   (optional) use Paging or not
  377.      *
  378.      * @access private
  379.      *
  380.      * @return boolean true (yep. i am an optimist)
  381.      */
  382.  
  383.     function _outputListAll($data$title 'Install / Upgrade / Remove PEAR Packages',
  384.                             $img 'pkglist'$useDHTML = false$paging = true)
  385.     {
  386.         $tpl $this->_initTemplate("package.list.tpl.html"$title$img$useDHTML);
  387.  
  388.         if (!isset($data['data'])) {
  389.             $data['data'= array();
  390.         }
  391.  
  392.         $pageId = isset($_GET['from']$_GET['from': 0;
  393.         $paging_data $this->__getData($pageId5count($data['data'])false);
  394.  
  395.         $data['data'array_slice($data['data']$pageId5);
  396.  
  397.         $links = array();
  398.         $from $paging_data['from'];
  399.         $to $paging_data['to'];
  400.  
  401.         // Generate Linkinformation to redirect to _this_ page after performing an action
  402.         $link_str '<a href="?command=%s&from=%s&mode=%s" class="paging_link">%s</a>';
  403.  
  404.  
  405.  
  406.         $command = isset($_GET['command']$_GET['command']:'list-all';
  407.         $mode = isset($_GET['mode'])?$_GET['mode']:'';
  408.  
  409.  
  410.  
  411.         if ($paging_data['from']>1{
  412.             $links['back'sprintf($link_str$command$paging_data['prev']$mode'&lt;&lt;');
  413.         else {
  414.             $links['back''';
  415.         }
  416.  
  417.         if $paging_data['next']{
  418.             $links['next'sprintf($link_str$command$paging_data['next']$mode'&gt;&gt;');
  419.         else {
  420.             $links['next''';
  421.         }
  422.  
  423.         $links['current''&from=' $paging_data['from']  '&mode=' $mode;
  424.  
  425.         if (isset($_GET['command']&& $_GET['command'== 'search'{
  426.             $links['current'.= '&redirect=search&0='.$_REQUEST[0].'&1='.$_REQUEST[1];
  427.         }
  428.  
  429.         $modes = array(
  430.             'installed'    => 'list installed packages',
  431.             ''             => 'list all packages',
  432.             'notinstalled' => 'list non-installed packages',
  433.             'upgrades'     => 'list avail. upgrades',
  434.             );
  435.  
  436.         $i = 1;
  437.         foreach($modes as $mode => $text{
  438.             $tpl->setVariable('mode' $i !empty($mode'&mode='.$mode '');
  439.             $tpl->setVariable('mode' $i.'text'$text);
  440.             $i++;
  441.         }
  442.  
  443.         $tpl->setVariable('Prev'$links['back']);
  444.         $tpl->setVariable('Next'$links['next']);
  445.         $tpl->setVariable('PagerFrom'$from);
  446.         $tpl->setVariable('PagerTo'$to);
  447.         $tpl->setVariable('PagerCount'$paging_data['numrows']);
  448.  
  449.         $reg &$this->config->getRegistry();
  450.         foreach($data['data'as $category => $packages{
  451.             foreach($packages as $row{
  452.                 list($pkgName$pkgVersionLatest$pkgVersionInstalled$pkgSummary$row;
  453.                 $parsed $reg->parsePackageName($pkgName$this->config->get('default_channel'));
  454.                 $pkgChannel $parsed['channel'];
  455.                 $pkgName $parsed['package'];
  456.                 $tpl->setCurrentBlock("Row");
  457.                 $tpl->setVariable("ImgPackage"$_SERVER["PHP_SELF"].'?img=package');
  458.                 $images = array(
  459.                     'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">',
  460.                     'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="uninstall">',
  461.                     'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">',
  462.                     'info' => '<img src="'.$_SERVER["PHP_SELF"].'?img=info"  width="17" height="19" border="0" alt="info">',
  463.                     'infoExt' => '<img src="'.$_SERVER["PHP_SELF"].'?img=infoplus"  width="18" height="19" border="0" alt="extended info">',
  464.                     );
  465.                 $urls   = array(
  466.                     'install' => sprintf('%s?command=install&pkg=%s%s',
  467.                         $_SERVER["PHP_SELF"]$pkgName$links['current']),
  468.                     'uninstall' => sprintf('%s?command=uninstall&pkg=%s%s',
  469.                         $_SERVER["PHP_SELF"]$pkgName$links['current']),
  470.                     'upgrade' => sprintf('%s?command=upgrade&pkg=%s%s',
  471.                         $_SERVER["PHP_SELF"]$pkgName$links['current']),
  472.                     'info' => sprintf('%s?command=remote-info&pkg=%s',
  473.                         $_SERVER["PHP_SELF"]$pkgName),
  474.                     'infoExt' => 'http://' $this->config->get('preferred_mirror')
  475.                          . '/package/' $row[0],
  476.                     );
  477.  
  478.                 $compare version_compare($pkgVersionLatest$pkgVersionInstalled);
  479.                 $id 'id="'.$pkgName.'_href"';
  480.                 if (!$pkgVersionInstalled || $pkgVersionInstalled == "- no -"{
  481.                     $inst sprintf('<a href="%s" onClick="return perform(\'%s\');" %s>%s</a>',
  482.                         $urls['install']$pkgName$id$images['install']);
  483.                     $del '';
  484.                 else if ($compare == 1{
  485.                     $inst sprintf('<a href="%s" onClick="return perform(\'%s\');" %s>%s</a>',
  486.                         $urls['upgrade']$pkgName$id$images['upgrade']);
  487.                     $del sprintf('<a href="%s" onClick="return deletePkg(\'%s\');" %s >%s</a>',
  488.                         $urls['uninstall']$pkgName$id$images['uninstall']);
  489.                 else {
  490.                     $del sprintf('<a href="%s" onClick="return deletePkg(\'%s\');" %s >%s</a>',
  491.                         $urls['uninstall']$pkgName$id$images['uninstall']);
  492.                     $inst '';
  493.                 }
  494.                 $info    sprintf('<a href="%s">%s</a>'$urls['info'],    $images['info']);
  495.                 $infoExt sprintf('<a href="%s">%s</a>'$urls['infoExt']$images['infoExt']);
  496.  
  497.                 if ($reg->channelName($pkgChannel== 'pear.php.net' &&
  498.                       in_array($pkgName$this->_no_delete_pkgs)) {
  499.                     $del '';
  500.                 }
  501.  
  502.                 $tpl->setVariable("Latest"$pkgVersionLatest);
  503.                 $tpl->setVariable("Installed"$pkgVersionInstalled);
  504.                 $tpl->setVariable("Install"$inst);
  505.                 $tpl->setVariable("Delete"$del);
  506.                 $tpl->setVariable("Info"$info);
  507.                 $tpl->setVariable("InfoExt"$infoExt);
  508.                 $tpl->setVariable("Package"$pkgName);
  509.                 $tpl->setVariable("Channel"$pkgChannel);
  510.                 $tpl->setVariable("Summary"nl2br($pkgSummary));
  511.                 $tpl->parseCurrentBlock();
  512.             }
  513.             $tpl->setCurrentBlock("Category");
  514.             $tpl->setVariable("categoryName"$category);
  515.             $tpl->setVariable("ImgCategory"$_SERVER["PHP_SELF"].'?img=category');
  516.             $tpl->parseCurrentBlock();
  517.         }
  518.         $tpl->show();
  519.  
  520.         return true;
  521.     }
  522.  
  523.     function _getPackageDeps($deps)
  524.     {
  525.         if (count($deps== 0{
  526.             return "<i>No dependencies registered.</i>\n";
  527.         else {
  528.             $lastversion '';
  529.             $rel_trans = array(
  530.                 'lt' => 'older than %s',
  531.                 'le' => 'version %s or older',
  532.                 'eq' => 'version %s',
  533.                 'ne' => 'any version but %s',
  534.                 'gt' => 'newer than %s',
  535.                 'ge' => '%s or newer',
  536.                 );
  537.             $dep_type_desc = array(
  538.                 'pkg'    => 'PEAR Package',
  539.                 'ext'    => 'PHP Extension',
  540.                 'php'    => 'PHP Version',
  541.                 'prog'   => 'Program',
  542.                 'ldlib'  => 'Development Library',
  543.                 'rtlib'  => 'Runtime Library',
  544.                 'os'     => 'Operating System',
  545.                 'websrv' => 'Web Server',
  546.                 'sapi'   => 'SAPI Backend',
  547.                 );
  548.             $result "      <dl>\n";
  549.             foreach($deps as $row{
  550.  
  551.                 // Print link if it's a PEAR package
  552.                 if ($row['type'== 'pkg'{
  553.                     $row['name'sprintf('<a class="green" href="%s?command=remote-info&pkg=%s">%s</a>',
  554.                         $_SERVER['PHP_SELF']$row['name']$row['name']);
  555.                 }
  556.  
  557.                 if (isset($rel_trans[$row['rel']])) {
  558.                     $rel sprintf($rel_trans[$row['rel']]$row['version']);
  559.                     $optional = isset($row['optional']&& $row['optional'== 'yes';
  560.                     $result .= sprintf("%s: %s %s" $optional,
  561.                            $dep_type_desc[$row['type']]@$row['name']$rel);
  562.                 else {
  563.                     $result .= sprintf("%s: %s"$dep_type_desc[$row['type']]$row['name']);
  564.                 }
  565.                 $lastversion $row['version'];
  566.                 $result .= '<br>';
  567.             }
  568.             if ($lastversion{
  569.             }
  570.             $result .= "      </dl>\n";
  571.         }
  572.         return $result;
  573.     }
  574.  
  575.     /**
  576.      * Output details of one package
  577.      *
  578.      * @param array $data array containing all information about the package
  579.      *
  580.      * @access private
  581.      *
  582.      * @return boolean true (yep. i am an optimist)
  583.      */
  584.  
  585.     function _outputPackageInfo($data)
  586.     {
  587.         include_once "PEAR/Downloader.php";
  588.         $tpl $this->_initTemplate("package.info.tpl.html"'Package Management :: '.$data['name']'pkglist');
  589.  
  590.         $tpl->setVariable("PreferredMirror"$this->config->get('preferred_mirror'));
  591.         /*
  592.         $dl = &new PEAR_Downloader($this, array(), $this->config);
  593.         // don't call private functions
  594.         // gives error, not gonna fix, but gonna skip
  595.         $info = $dl->_getPackageDownloadUrl(array('package' => $data['name'],
  596.             'channel' => $this->config->get('default_channel'), 'version' => $data['stable']));
  597.         if (isset($info['url'])) {
  598.             $tpl->setVariable("DownloadURL", $info['url']);
  599.         } else {
  600.             $tpl->setVariable("DownloadURL", $_SERVER['PHP_SELF']);
  601.         }
  602.         */
  603.         $tpl->setVariable("Latest"$data['stable']);
  604.         $tpl->setVariable("Installed"$data['installed']);
  605.         $tpl->setVariable("Package"$data['name']);
  606.         $tpl->setVariable("License"$data['license']);
  607.         $tpl->setVariable("Category"$data['category']);
  608.         $tpl->setVariable("Summary"nl2br($data['summary']));
  609.         $tpl->setVariable("Description"nl2br($data['description']));
  610.         $deps @$data['releases'][$data['stable']]['deps'];
  611.         $tpl->setVariable("Dependencies"$this->_getPackageDeps($deps));
  612.  
  613.         $compare version_compare($data['stable']$data['installed']);
  614.  
  615.         $images = array(
  616.             'install' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">',
  617.             'uninstall' => '<img src="'.$_SERVER["PHP_SELF"].'?img=uninstall" width="18" height="17"  border="0" alt="uninstall">',
  618.             'upgrade' => '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="upgrade">',
  619.             );
  620.  
  621.         $opt_img = array();
  622.         $opt_text = array();
  623.         if (!$data['installed'|| $data['installed'== "- no -"{
  624.             $opt_img[sprintf(
  625.                 '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>',
  626.                 $_SERVER["PHP_SELF"]$data['name']$images['install']);
  627.             $opt_text[sprintf(
  628.                 '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>',
  629.                 $_SERVER["PHP_SELF"]$data['name']);
  630.         else if ($compare == 1{
  631.             $opt_img[sprintf(
  632.                 '<a href="%s?command=upgrade&pkg=%s&redirect=info">%s</a><br>',
  633.                 $_SERVER["PHP_SELF"]$data['name']$images['upgrade']);
  634.             $opt_text[sprintf(
  635.                 '<a href="%s?command=upgrade&pkg=%s&redirect=info" class="green">Upgrade package</a>',
  636.                 $_SERVER["PHP_SELF"]$data['name']);
  637.             if (!in_array($data['name']$this->_no_delete_pkgs)) {
  638.                 $opt_img[sprintf(
  639.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>',
  640.                     $_SERVER["PHP_SELF"]$data['name'],
  641.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"',
  642.                     $images['uninstall']);
  643.                 $opt_text[sprintf(
  644.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>',
  645.                     $_SERVER["PHP_SELF"]$data['name'],
  646.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"');
  647.            }
  648.         else {
  649.             if (!in_array($data['name']$this->_no_delete_pkgs)) {
  650.                 $opt_img[sprintf(
  651.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" %s>%s</a>',
  652.                     $_SERVER["PHP_SELF"]$data['name'],
  653.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"',
  654.                     $images['uninstall']);
  655.                 $opt_text[sprintf(
  656.                     '<a href="%s?command=uninstall&pkg=%s&redirect=info" class="green" %s>Uninstall package</a>',
  657.                     $_SERVER["PHP_SELF"]$data['name'],
  658.                     'onClick="return confirm(\'Do you really want to uninstall \\\''.$data['name'].'\\\'?\')"');
  659.            }
  660.         }
  661.  
  662.         if (isset($opt_img[0]))
  663.         {
  664.             $tpl->setVariable("Opt_Img_1"$opt_img[0]);
  665.             $tpl->setVariable("Opt_Text_1"$opt_text[0]);
  666.         }
  667.         if (isset($opt_img[1]))
  668.         {
  669.             $tpl->setVariable("Opt_Img_2"$opt_img[1]);
  670.             $tpl->setVariable("Opt_Text_2"$opt_text[1]);
  671.         }
  672.  
  673.         $tpl->show();
  674.         return true;
  675.     }
  676.  
  677.     /**
  678.      * Output details of one channel
  679.      *
  680.      * @param array $data array containing all information about the channel
  681.      *
  682.      * @access private
  683.      *
  684.      * @return boolean true (yep. i am an optimist)
  685.      */
  686.  
  687.     function _outputChannelInfo($data)
  688.     {
  689.         $tpl $this->_initTemplate("channel.info.tpl.html",
  690.             'Channel Management :: '.$data['main']['data']['server'][1]'pkglist');
  691.  
  692.         $tpl->setVariable("Channel"$data['main']['data']['server'][1]);
  693.         if (isset($data['main']['data']['alias'])) {
  694.             $tpl->setVariable("Alias"$data['main']['data']['alias'][1]);
  695.         else {
  696.             $tpl->setVariable("Alias"$data['main']['data']['server'][1]);
  697.         }
  698.         $tpl->setVariable("Summary"$data['main']['data']['summary'][1]);
  699.         $tpl->setVariable("ValidationPackage"$data['main']['data']['vpackage'][1]);
  700.         $tpl->setVariable("ChannelValidationPackageVersion",
  701.             $data['main']['data']['vpackageversion'][1]);
  702.         if (!in_array($data['main']['data']['server'][1]array('pear.php.net''__uri'))) {
  703.             // see if the validation package is installed.  If not, allow the user to install it
  704.             $reg &$this->config->getRegistry();
  705.             do {
  706.                 if ($reg->packageExists($data['main']['data']['vpackage'][1],
  707.                       $data['main']['data']['server'][1])) {
  708.                     $installed = true;
  709.                     if ($reg->packageInfo($data['main']['data']['vpackage'][1]'version',
  710.                           $data['main']['data']['server'][1]==
  711.                           $data['main']['data']['vpackageversion'][1]{
  712.                         break; // poor man's throw
  713.                     }
  714.                 else {
  715.                     $installed = false;
  716.                 }
  717.                 // finish this
  718.                 $pname $reg->parsedPackageNameToString(array('channel' =>
  719.                     $data['main']['data']['server'][1],
  720.                     'package' => $data['main']['data']['vpackage'][1],
  721.                     'version' => $data['main']['data']['vpackageversion'][1]));
  722.                 $opt_img[sprintf(
  723.                     '<a href="%s?command=install&pkg=%s&redirect=info">%s</a>',
  724.                     $_SERVER["PHP_SELF"]$pname
  725.                     '<img src="'.$_SERVER["PHP_SELF"].'?img=install" width="13" height="13" border="0" alt="install">');
  726.                 $opt_text[sprintf(
  727.                     '<a href="%s?command=install&pkg=%s&redirect=info" class="green">Install package</a>',
  728.                     $_SERVER["PHP_SELF"]$data['name']);
  729.             while (false);
  730.         }
  731.         $tpl->show();
  732.         return true;
  733.     }
  734.  
  735.     /**
  736.      * Output all kinds of data depending on the command which called this method
  737.      *
  738.      * @param mixed  $data    datastructure containing the information to display
  739.      * @param string $command (optional) command from which this method was called
  740.      *
  741.      * @access public
  742.      *
  743.      * @return mixed highly depends on the command
  744.      */
  745.  
  746.     function outputData($data$command '_default')
  747.     {
  748.         switch ($command{
  749.             case 'config-show':
  750.                 $prompt  = array();
  751.                 $default = array();
  752.                 foreach($data['data'as $group{
  753.                     foreach($group as $row{
  754.                         $prompt[$row[1]]  $row[0];
  755.                         $default[$row[1]] $row[2];
  756.                     }
  757.                 }
  758.                 $title 'Configuration :: '.$GLOBALS['pear_user_config'];
  759.                 $GLOBALS['_PEAR_Frontend_Web_Config'=
  760.                     $this->userDialog($command$promptarray()$default$title'config');
  761.                 return true;
  762.             case 'list-all':
  763.                 return $this->_outputListAll($data);
  764.             case 'list-channels':
  765.                 return $this->_outputListChannels($data);
  766.             case 'search':
  767.                 return $this->_outputListAll($data'Package Search :: Result''pkgsearch'falsefalse);
  768.             case 'remote-info':
  769.                 return $this->_outputPackageInfo($data);
  770.             case 'channel-info':
  771.                 return $this->_outputChannelInfo($data);
  772.             case 'install':
  773.             case 'upgrade':
  774.             case 'uninstall':
  775.                 return true;
  776.             case 'login':
  777.                 if ($_SERVER["REQUEST_METHOD"!= "POST")
  778.                     $this->_data[$command$data;
  779.                 return true;
  780.             case 'logout':
  781.                 $this->displayError($data'Logout''logout');
  782.                 break;
  783.             case 'package':
  784.             case 'channel-discover':
  785.             case 'channel-delete':
  786.             case 'update-channels':
  787.                 $this->_savedOutput[$data;
  788.                 break;
  789.             case 'channel-update':
  790.                 $this->_savedOutput[$data;
  791.                 break;
  792.             case 'config-set':
  793.                 $this->_savedOutput[$data;
  794.                 break;
  795.             default:
  796.                 if ($this->_installScript{
  797.                     $this->_savedOutput[$_SESSION['_PEAR_Frontend_Web_SavedOutput'][$data;
  798.                     break;
  799.                 }
  800.                 /* TODO: figure out a sane way to manage the inconsisten new error msg */
  801.                 if (!is_array($data)) {
  802.                     echo $data."<br />\n";
  803.                 }
  804.         }
  805.  
  806.         return true;
  807.     }
  808.  
  809.     function startSession()
  810.     {
  811.         if ($this->_installScript{
  812.             if (!isset($_SESSION['_PEAR_Frontend_Web_SavedOutput'])) {
  813.                 $_SESSION['_PEAR_Frontend_Web_SavedOutput'= array();
  814.             }
  815.             $this->_savedOutput $_SESSION['_PEAR_Frontend_Web_SavedOutput'];
  816.         else {
  817.             $this->_savedOutput = array();
  818.         }
  819.     }
  820.  
  821.     function finishOutput($command$redirectLink = false)
  822.     {
  823.         unset($_SESSION['_PEAR_Frontend_Web_SavedOutput']);
  824.         $tpl $this->_initTemplate('info.tpl.html'"$command output");
  825.         foreach($this->_savedOutput as $row{
  826.             $tpl->setCurrentBlock('Infoloop');
  827.             $tpl->setVariable("Info"$row);
  828.             $tpl->parseCurrentBlock();
  829.         }
  830.         if ($redirectLink{
  831.             $tpl->setCurrentBlock('Infoloop');
  832.             $tpl->setVariable("Info"'<a href="' $redirectLink['link''">' .
  833.                 $redirectLink['text''</a>');
  834.             $tpl->parseCurrentBlock();
  835.         }
  836.         $tpl->show();
  837.     }
  838.  
  839.     /**
  840.      * @param array An array of PEAR_Task_Postinstallscript objects (or related scripts)
  841.      * @param PEAR_PackageFile_v2 
  842.      */
  843.     function runPostinstallScripts(&$scripts$pkg)
  844.     {
  845.         if (!isset($_SESSION['_PEAR_Frontend_Web_Scripts'])) {
  846.             $saves = array();
  847.             foreach ($scripts as $i => $task{
  848.                 $saves[$i= (array) $task->_obj;
  849.             }
  850.             $_SESSION['_PEAR_Frontend_Web_Scripts'$saves;
  851.             $nonsession = true;
  852.         else {
  853.             $nonsession = false;
  854.         }
  855.         foreach ($scripts as $i => $task{
  856.             if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptIndex'])) {
  857.                 $_SESSION['_PEAR_Frontend_Web_ScriptIndex'$i;
  858.             }
  859.             if ($i != $_SESSION['_PEAR_Frontend_Web_ScriptIndex']{
  860.                 continue;
  861.             }
  862.             if (!$nonsession{
  863.                 // restore values from previous sessions to the install script
  864.                 foreach ($_SESSION['_PEAR_Frontend_Web_Scripts'][$ias $name => $val{
  865.                     if ($name{0== '_'{
  866.                         // only public variables will be restored
  867.                         continue;
  868.                     }
  869.                     $scripts[$i]->_obj->$name $val;
  870.                 }
  871.             }
  872.             $this->_installScript = true;
  873.             $this->startSession();
  874.             $this->runInstallScript($scripts[$i]->_params$scripts[$i]->_obj$pkg);
  875.             $saves $scripts;
  876.             foreach ($saves as $i => $task{
  877.                 $saves[$i= (array) $task->_obj;
  878.             }
  879.             $_SESSION['_PEAR_Frontend_Web_Scripts'$saves;
  880.             unset($_SESSION['_PEAR_Frontend_Web_ScriptIndex']);
  881.         }
  882.         $this->_installScript = false;
  883.         unset($_SESSION['_PEAR_Frontend_Web_Scripts']);
  884.         $this->finishOutput($pkg->getPackage(' Install Script',
  885.             array('link' => $GLOBALS['URL'.
  886.             '?command=remote-info&pkg='.$pkg->getPackage(),
  887.                 'text' => 'Click for ' .$pkg->getPackage(' Information'));
  888.     }
  889.  
  890.     /**
  891.      * Instruct the runInstallScript method to skip a paramgroup that matches the
  892.      * id value passed in.
  893.      *
  894.      * This method is useful for dynamically configuring which sections of a post-install script
  895.      * will be run based on the user's setup, which is very useful for making flexible
  896.      * post-install scripts without losing the cross-Frontend ability to retrieve user input
  897.      * @param string 
  898.      */
  899.     function skipParamgroup($id)
  900.     {
  901.         $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$sectionName= true;
  902.     }
  903.  
  904.     /**
  905.      * @param array $xml contents of postinstallscript tag
  906.      * @param object $script post-installation script
  907.      * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2$pkg 
  908.      * @param string $contents contents of the install script
  909.      */
  910.     function runInstallScript($xml&$script&$pkg)
  911.     {
  912.         if (!isset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'])) {
  913.             $_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'= array();
  914.             $_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'= array();
  915.         }
  916.         if (isset($_SESSION['_PEAR_Frontend_Web_ScriptObj'])) {
  917.             foreach ($_SESSION['_PEAR_Frontend_Web_ScriptObj'as $name => $val{
  918.                 if ($name{0== '_'{
  919.                     // only public variables will be restored
  920.                     continue;
  921.                 }
  922.                 $script->$name $val;
  923.             }
  924.         else {
  925.             $_SESSION['_PEAR_Frontend_Web_ScriptObj'= (array) $script;
  926.         }
  927.         if (!is_array($xml|| !isset($xml['paramgroup'])) {
  928.             $script->run(array()'_default');
  929.         else {
  930.             if (!isset($xml['paramgroup'][0])) {
  931.                 $xml['paramgroup'][0= array($xml['paramgroup']);
  932.             }
  933.             foreach ($xml['paramgroup'as $i => $group{
  934.                 if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections'][$group['id']])) {
  935.                     continue;
  936.                 }
  937.                 if (isset($_SESSION['_PEAR_Frontend_Web_ScriptSection'])) {
  938.                     if ($i $_SESSION['_PEAR_Frontend_Web_ScriptSection']{
  939.                         $lastgroup $group;
  940.                         continue;
  941.                     }
  942.                 }
  943.                 if (isset($_SESSION['_PEAR_Frontend_Web_answers'])) {
  944.                     $answers $_SESSION['_PEAR_Frontend_Web_answers'];
  945.                 }
  946.                 if (isset($group['name'])) {
  947.                     if (isset($answers)) {
  948.                         if (isset($answers[$group['name']])) {
  949.                             switch ($group['conditiontype']{
  950.                                 case '=' :
  951.                                     if ($answers[$group['name']] != $group['value']{
  952.                                         continue 2;
  953.                                     }
  954.                                 break;
  955.                                 case '!=' :
  956.                                     if ($answers[$group['name']] == $group['value']{
  957.                                         continue 2;
  958.                                     }
  959.                                 break;
  960.                                 case 'preg_match' :
  961.                                     if (!@preg_match('/' $group['value''/',
  962.                                           $answers[$group['name']])) {
  963.                                         continue 2;
  964.                                     }
  965.                                 break;
  966.                                 default :
  967.                                     $this->_clearScriptSession();
  968.                                 return;
  969.                             }
  970.                         }
  971.                     else {
  972.                         $this->_clearScriptSession();
  973.                         return;
  974.                     }
  975.                 }
  976.                 if (!isset($group['param'][0])) {
  977.                     $group['param'= array($group['param']);
  978.                 }
  979.                 $_SESSION['_PEAR_Frontend_Web_ScriptSection'$i;
  980.                 if (!isset($answers)) {
  981.                     $answers = array();
  982.                 }
  983.                 if (isset($group['param'])) {
  984.                     if (method_exists($script'postProcessPrompts')) {
  985.                         $prompts $script->postProcessPrompts($group['param']$group['name']);
  986.                         if (!is_array($prompts|| count($prompts!= count($group['param'])) {
  987.                             $this->outputData('postinstall''Error: post-install script did not ' .
  988.                                 'return proper post-processed prompts');
  989.                             $prompts $group['param'];
  990.                         else {
  991.                             foreach ($prompts as $i => $var{
  992.                                 if (!is_array($var|| !isset($var['prompt']||
  993.                                       !isset($var['name']||
  994.                                       ($var['name'!= $group['param'][$i]['name']||
  995.                                       ($var['type'!= $group['param'][$i]['type'])) {
  996.                                     $this->outputData('postinstall''Error: post-install script ' .
  997.                                         'modified the variables or prompts, severe security risk. ' .
  998.                                         'Will instead use the defaults from the package.xml');
  999.                                     $prompts $group['param'];
  1000.                                 }
  1001.                             }
  1002.                         }
  1003.                         $answers array_merge($answers,
  1004.                             $this->confirmDialog($prompts$pkg->getPackage()));
  1005.                     else {
  1006.                         $answers array_merge($answers,
  1007.                             $this->confirmDialog($group['param']$pkg->getPackage()));
  1008.                     }
  1009.                 }
  1010.                 if ($answers{
  1011.                     array_unshift($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'],
  1012.                         $group['id']);
  1013.                     if (!$script->run($answers$group['id'])) {
  1014.                         $script->run($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases'],
  1015.                             '_undoOnError');
  1016.                         $this->_clearScriptSession();
  1017.                         return;
  1018.                     }
  1019.                 else {
  1020.                     $script->run(array()'_undoOnError');
  1021.                     $this->_clearScriptSession();
  1022.                     return;
  1023.                 }
  1024.                 $lastgroup $group;
  1025.                 foreach ($group['param'as $param{
  1026.                     // rename the current params to save for future tests
  1027.                     $answers[$group['id''::' $param['name']] $answers[$param['name']];
  1028.                     unset($answers[$param['name']]);
  1029.                 }
  1030.                 // save the script's variables and user answers for the next round
  1031.                 $_SESSION['_PEAR_Frontend_Web_ScriptObj'= (array) $script;
  1032.                 $_SESSION['_PEAR_Frontend_Web_answers'$answers;
  1033.                 $_SERVER['REQUEST_METHOD''';
  1034.             }
  1035.         }
  1036.         $this->_clearScriptSession();
  1037.     }
  1038.  
  1039.     function _clearScriptSession()
  1040.     {
  1041.         unset($_SESSION['_PEAR_Frontend_Web_ScriptObj']);
  1042.         unset($_SESSION['_PEAR_Frontend_Web_answers']);
  1043.         unset($_SESSION['_PEAR_Frontend_Web_ScriptSection']);
  1044.         unset($_SESSION['_PEAR_Frontend_Web_ScriptCompletedPhases']);
  1045.         unset($_SESSION['_PEAR_Frontend_Web_ScriptSkipSections']);
  1046.     }
  1047.  
  1048.     /**
  1049.      * Ask for user input, confirm the answers and continue until the user is satisfied
  1050.      * @param array an array of arrays, format array('name' => 'paramname', 'prompt' =>
  1051.      *               'text to display', 'type' => 'string'[, default => 'default value'])
  1052.      * @param string Package Name
  1053.      * @return array|false
  1054.      */
  1055.     function confirmDialog($params$pkg)
  1056.     {
  1057.         $answers = array();
  1058.         $prompts $types = array();
  1059.         foreach ($params as $param{
  1060.             $prompts[$param['name']] $param['prompt'];
  1061.             $types[$param['name']] $param['type'];
  1062.             if (isset($param['default'])) {
  1063.                 $answers[$param['name']] $param['default'];
  1064.             else {
  1065.                 $answers[$param['name']] '';
  1066.             }
  1067.         }
  1068.         $attempt = 0;
  1069.         do {
  1070.             if ($attempt{
  1071.                 $_SERVER['REQUEST_METHOD''';
  1072.             }
  1073.             $title !$attempt $pkg ' Install Script Input' 'Please fill in all values';
  1074.             $answers $this->userDialog('run-scripts'$prompts$types$answers$title'',
  1075.                 array('pkg' => $pkg));
  1076.             if ($answers === false{
  1077.                 return false;
  1078.             }
  1079.             $attempt++;
  1080.         while (count(array_filter($answers)) != count($prompts));
  1081.         $_SERVER['REQUEST_METHOD''POST';
  1082.         return $answers;
  1083.     }
  1084.  
  1085.     /**
  1086.      * Display a formular and return the given input (yes. needs to requests)
  1087.      *
  1088.      * @param string $command  command from which this method was called
  1089.      * @param array  $prompts  associative array. keys are the inputfieldnames
  1090.      *                          and values are the description
  1091.      * @param array  $types    (optional) array of inputfieldtypes (text, password,
  1092.      *                          etc.) keys have to be the same like in $prompts
  1093.      * @param array  $defaults (optional) array of defaultvalues. again keys have
  1094.      *                          to be the same like in $prompts
  1095.      * @param string $title    (optional) title of the page
  1096.      * @param string $icon     (optional) iconhandle for this page
  1097.      * @param array  $extra    (optional) extra parameters to put in the form action
  1098.      *
  1099.      * @access public
  1100.      *
  1101.      * @return array input sended by the user
  1102.      */
  1103.  
  1104.     function userDialog($command$prompts$types = array()$defaults = array()$title '',
  1105.                         $icon ''$extra = array())
  1106.     {
  1107.         // If this is an POST Request, we can return the userinput
  1108.         if (isset($_GET["command"]&& $_GET["command"]==$command
  1109.             && $_SERVER["REQUEST_METHOD"== "POST"{
  1110.             if (isset($_POST['cancel'])) {
  1111.                 return false;
  1112.             }
  1113.             $result = array();
  1114.             foreach($prompts as $key => $prompt{
  1115.                 $result[$key$_POST[$key];
  1116.             }
  1117.             return $result;
  1118.         }
  1119.  
  1120.         // If this is an Answer GET Request , we can return the userinput
  1121.         if (isset($_GET["command"]&& $_GET["command"]==$command
  1122.             && isset($_GET["userDialogResult"]&& $_GET["userDialogResult"]=='get'{
  1123.             $result = array();
  1124.             foreach($prompts as $key => $prompt{
  1125.                 $result[$key$_GET[$key];
  1126.             }
  1127.             return $result;
  1128.         }
  1129.  
  1130.         // Assign title and icon to some commands
  1131.         if ($command == 'login'{
  1132.             $title 'Login';
  1133.             $icon 'login';
  1134.         }
  1135.  
  1136.         $tpl $this->_initTemplate("userDialog.tpl.html"$title$icon);
  1137.         $tpl->setVariable("Command"$command);
  1138.         $extrap '';
  1139.         if (count($extra)) {
  1140.             $extrap '&';
  1141.             foreach ($extra as $name => $value{
  1142.                 $extrap .= urlencode($name'=' urlencode($value);
  1143.             }
  1144.         }
  1145.         $tpl->setVariable("extra"$extrap);
  1146.         if (isset($this->_data[$command])) {
  1147.             $tpl->setVariable("Headline"nl2br($this->_data[$command]));
  1148.         }
  1149.  
  1150.         if (is_array($prompts)) {
  1151.             $maxlen = 0;
  1152.             foreach($prompts as $key => $prompt{
  1153.                 if (strlen($prompt$maxlen{
  1154.                     $maxlen strlen($prompt);
  1155.                 }
  1156.             }
  1157.  
  1158.             foreach($prompts as $key => $prompt{
  1159.                 $tpl->setCurrentBlock("InputField");
  1160.                 $type    (isset($types[$key])    $types[$key]    'text');
  1161.                 $default (isset($defaults[$key]$defaults[$key'');
  1162.                 $tpl->setVariable("prompt"$prompt);
  1163.                 $tpl->setVariable("name"$key);
  1164.                 $tpl->setVariable("default"$default);
  1165.                 $tpl->setVariable("type"$type);
  1166.                 if ($maxlen > 25{
  1167.                     $tpl->setVariable("width"'width="275"');
  1168.                 }
  1169.                 $tpl->parseCurrentBlock();
  1170.             }
  1171.         }
  1172.         if ($command == 'run-scripts'{
  1173.             $tpl->setVariable("cancel"'<input type="submit" value="Cancel" name="cancel">');
  1174.         }
  1175.         $tpl->show();
  1176.         exit;
  1177.     }
  1178.  
  1179.     /**
  1180.      * Write message to log
  1181.      *
  1182.      * @param string $text message which has to written to log
  1183.      *
  1184.      * @access public
  1185.      *
  1186.      * @return boolean true
  1187.      */
  1188.  
  1189.     function log($text)
  1190.     {
  1191.         $GLOBALS['_PEAR_Frontend_Web_log'.= $text."\n";
  1192.         $this->_savedOutput[$text;
  1193.         return true;
  1194.     }
  1195.  
  1196.     /**
  1197.      * Sends the required file along with Headers and exits the script
  1198.      *
  1199.      * @param string $handle handle of the requested file
  1200.      * @param string $group  group of the requested file
  1201.      *
  1202.      * @access public
  1203.      *
  1204.      * @return null nothing, because script exits
  1205.      */
  1206.  
  1207.     function outputFrontendFile($handle$group)
  1208.     {
  1209.         $handles = array(
  1210.             "css" => array(
  1211.                 "style" => "style.css",
  1212.                 "dhtml" => "dhtml.css",
  1213.                 ),
  1214.             "js" => array(
  1215.                 "dhtml" => "dhtml.js",
  1216.                 "nodhtml" => "nodhtml.js",
  1217.                 ),
  1218.             "image" => array(
  1219.                 "logout" => array(
  1220.                     "type" => "gif",
  1221.                     "file" => "logout.gif",
  1222.                     ),
  1223.                 "login" => array(
  1224.                     "type" => "gif",
  1225.                     "file" => "login.gif",
  1226.                     ),
  1227.                 "config" => array(
  1228.                     "type" => "gif",
  1229.                     "file" => "config.gif",
  1230.                     ),
  1231.                 "pkglist" => array(
  1232.                     "type" => "png",
  1233.                     "file" => "pkglist.png",
  1234.                     ),
  1235.                 "pkgsearch" => array(
  1236.                     "type" => "png",
  1237.                     "file" => "pkgsearch.png",
  1238.                     ),
  1239.                 "package" => array(
  1240.                     "type" => "jpeg",
  1241.                     "file" => "package.jpg",
  1242.                     ),
  1243.                 "category" => array(
  1244.                     "type" => "jpeg",
  1245.                     "file" => "category.jpg",
  1246.                     ),
  1247.                 "install" => array(
  1248.                     "type" => "gif",
  1249.                     "file" => "install.gif",
  1250.                     ),
  1251.                 "install_wait" => array(
  1252.                     "type" => "gif",
  1253.                     "file" => "install_wait.gif",
  1254.                     ),
  1255.                 "install_ok" => array(
  1256.                     "type" => "gif",
  1257.                     "file" => "install_ok.gif",
  1258.                     ),
  1259.                 "install_fail" => array(
  1260.                     "type" => "gif",
  1261.                     "file" => "install_fail.gif",
  1262.                     ),
  1263.                 "uninstall" => array(
  1264.                     "type" => "gif",
  1265.                     "file" => "trash.gif",
  1266.                     ),
  1267.                 "info" => array(
  1268.                     "type" => "gif",
  1269.                     "file" => "info.gif",
  1270.                     ),
  1271.                 "infoplus" => array(
  1272.                     "type" => "gif",
  1273.                     "file" => "infoplus.gif",
  1274.                     ),
  1275.                 "pear" => array(
  1276.                     "type" => "gif",
  1277.                     "file" => "pearsmall.gif",
  1278.                     ),
  1279.                 "error" => array(
  1280.                     "type" => "gif",
  1281.                     "file" => "error.gif",
  1282.                     ),
  1283.                 "manual" => array(
  1284.                     "type" => "gif",
  1285.                     "file" => "manual.gif",
  1286.                     ),
  1287.                 "download" => array(
  1288.                     "type" => "gif",
  1289.                     "file" => "download.gif",
  1290.                     ),
  1291.                 ),
  1292.             );
  1293.  
  1294.         $file $handles[$group][$handle];
  1295.         switch ($group{
  1296.             case 'css':
  1297.                 header("Content-Type: text/css");
  1298.                 readfile(dirname(__FILE__).'/Web/'.$file);
  1299.                 exit;
  1300.             case 'image':
  1301.                 $filename dirname(__FILE__).'/Web/'.$file['file'];
  1302.                 header("Content-Type: image/".$file['type']);
  1303.                 header("Expires: ".gmdate("D, d M Y H:i:s \G\M\T"time(+ 60*60*24*100));
  1304.                 header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T"filemtime($filename)));
  1305.                 header("Cache-Control: public");
  1306.                 header("Pragma: ");
  1307.                 readfile($filename);
  1308.                 exit;
  1309.             case 'js':
  1310.                 header("Content-Type: text/javascript");
  1311.                 readfile(dirname(__FILE__).'/Web/'.$file);
  1312.                 exit;
  1313.         }
  1314.     }
  1315.  
  1316.     /*
  1317.      * From DB::Pager. Removing Pager dependency.
  1318.      * @private
  1319.      */
  1320.     function __getData($from$limit$numrows$maxpages = false)
  1321.     {
  1322.         if (empty($numrows|| ($numrows < 0)) {
  1323.             return null;
  1324.         }
  1325.         $from (empty($from)) ? 0 : $from;
  1326.  
  1327.         if ($limit <= 0{
  1328.             return false;
  1329.         }
  1330.  
  1331.         // Total number of pages
  1332.         $pages ceil($numrows/$limit);
  1333.         $data['numpages'$pages;
  1334.  
  1335.         // first & last page
  1336.         $data['firstpage'= 1;
  1337.         $data['lastpage']  $pages;
  1338.  
  1339.         // Build pages array
  1340.         $data['pages'= array();
  1341.         for ($i=1; $i <= $pages$i++{
  1342.             $offset $limit ($i-1);
  1343.             $data['pages'][$i$offset;
  1344.             // $from must point to one page
  1345.             if ($from == $offset{
  1346.                 // The current page we are
  1347.                 $data['current'$i;
  1348.             }
  1349.         }
  1350.         if (!isset($data['current'])) {
  1351.             return PEAR::raiseError (null'wrong "from" param'null,
  1352.                                      nullnull'DB_Error'true);
  1353.         }
  1354.               // Limit number of pages (Goole algorithm)
  1355.         if ($maxpages{
  1356.             $radio floor($maxpages/2);
  1357.             $minpage $data['current'$radio;
  1358.             if ($minpage < 1{
  1359.                 $minpage = 1;
  1360.             }
  1361.             $maxpage $data['current'$radio - 1;
  1362.             if ($maxpage $data['numpages']{
  1363.                 $maxpage $data['numpages'];
  1364.             }
  1365.             foreach (range($minpage$maxpageas $page{
  1366.                 $tmp[$page$data['pages'][$page];
  1367.             }
  1368.             $data['pages'$tmp;
  1369.             $data['maxpages'$maxpages;
  1370.         else {
  1371.             $data['maxpages'= null;
  1372.         }
  1373.  
  1374.         // Prev link
  1375.         $prev $from $limit;
  1376.         $data['prev'($prev >= 0$prev : null;
  1377.  
  1378.         // Next link
  1379.         $next $from $limit;
  1380.         $data['next'($next $numrows$next : null;
  1381.  
  1382.         // Results remaining in next page & Last row to fetch
  1383.         if ($data['current'== $pages{
  1384.             $data['remain'= 0;
  1385.             $data['to'$numrows;
  1386.         else {
  1387.             if ($data['current'== ($pages - 1)) {
  1388.                 $data['remain'$numrows ($limit*($pages-1));
  1389.             else {
  1390.                 $data['remain'$limit;
  1391.             }
  1392.             $data['to'$data['current'$limit;
  1393.         }
  1394.         $data['numrows'$numrows;
  1395.         $data['from']    $from + 1;
  1396.         $data['limit']   $limit;
  1397.  
  1398.         return $data;
  1399.     }
  1400.  
  1401.     // }}}
  1402. }
  1403.  
  1404. ?>

Documentation generated on Mon, 11 Mar 2019 14:57:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.