install/includes/ui.php
changeset 348 87e08a6e4fec
child 354 979d99a0b00e
equal deleted inserted replaced
347:299a90e28abc 348:87e08a6e4fec
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
       
     5  * Version 1.1.1
       
     6  * Copyright (C) 2006-2007 Dan Fuhry
       
     7  * Installation package
       
     8  * ui.php - User interface for installations and upgrades
       
     9  *
       
    10  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
       
    11  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
       
    12  *
       
    13  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
       
    14  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
       
    15  */
       
    16 
       
    17 /**
       
    18  * The class for drawing and managing UI components.
       
    19  * @package Enano
       
    20  * @subpackage Installer
       
    21  * @author Dan Fuhry
       
    22  */
       
    23 
       
    24 class Enano_Installer_UI
       
    25 {
       
    26   /**
       
    27    * The list of installer stages.
       
    28    * @var array
       
    29    */
       
    30   
       
    31   var $stages = array();
       
    32   
       
    33   /**
       
    34    * The GUID of the active stage
       
    35    * @var string
       
    36    */
       
    37   
       
    38   var $current_stage = '';
       
    39   
       
    40   /**
       
    41    * The application name, or the name displayed after the stage name in the title bar. Should be localized.
       
    42    * @var string
       
    43    */
       
    44   
       
    45   var $app_name = '';
       
    46   
       
    47   /**
       
    48    * If the header should be simplified (stripped of the Enano logo and top heading), this will be true.
       
    49    * @var bool
       
    50    */
       
    51   
       
    52   var $simple = false;
       
    53   
       
    54   /**
       
    55    * Text inserted into the header on the right.
       
    56    * @var string
       
    57    */
       
    58   
       
    59   var $step = '';
       
    60   
       
    61   /**
       
    62    * Extra text to add to the HTML <head> section
       
    63    * @var array Will be implode()'ed
       
    64    */
       
    65   
       
    66   var $additional_headers = array();
       
    67   
       
    68   /**
       
    69    * Constructor.
       
    70    * @param string The name displayed in the <title> tag
       
    71    * @param bool If true, the simplified header format is displayed.
       
    72    */
       
    73   
       
    74   function __construct($app_name, $simple_header)
       
    75   {
       
    76     $this->stages = array(
       
    77         'main' => array(),
       
    78         'hide' => array()
       
    79       );
       
    80     $this->app_name = $app_name;
       
    81     $this->simple = ( $simple_header ) ? true : false;
       
    82   }
       
    83   
       
    84   /**
       
    85    * Adds more text to the HTML header.
       
    86    * @param string
       
    87    */
       
    88   
       
    89   function add_header($html)
       
    90   {
       
    91     $this->additional_headers[] = $html;
       
    92   }
       
    93   
       
    94   /**
       
    95    * Adds a stage to the installer.
       
    96    * @param string Title of the stage, should be already put through $lang->get()
       
    97    * @param bool If true, the stage is shown among possible stages at the top of the window. If false, acts as a hidden stage
       
    98    * @return string Unique identifier for stage, used later on set_visible_stage()
       
    99    */
       
   100   
       
   101   function add_stage($stage, $visible = true)
       
   102   {
       
   103     $key = ( $visible ) ? 'main' : 'hide';
       
   104     $guid = md5(microtime() . mt_rand());
       
   105     $this->stages[$key][$guid] = $stage;
       
   106     if ( empty($this->current_stage) )
       
   107       $this->current_stage = $guid;
       
   108     return $guid;
       
   109   }
       
   110   
       
   111   /**
       
   112    * Resets the active stage of installation. This is for the UI only; it doesn't actually change how the backend works.
       
   113    * @param string GUID of stage, returned from add_stage()
       
   114    * @return bool true on success, false if stage GUID not found
       
   115    */
       
   116   
       
   117   function set_visible_stage($guid)
       
   118   {
       
   119     foreach ( $this->stages['main'] as $key => $stage_name )
       
   120     {
       
   121       if ( $key == $guid )
       
   122       {
       
   123         $this->current_stage = $guid;
       
   124         return true;
       
   125       }
       
   126     }
       
   127     foreach ( $this->stages['hide'] as $key => $stage_name )
       
   128     {
       
   129       if ( $key == $guid )
       
   130       {
       
   131         $this->current_stage = $guid;
       
   132         return true;
       
   133       }
       
   134     }
       
   135     return false;
       
   136   }
       
   137   
       
   138   /**
       
   139    * Outputs the HTML headers and start of the <body>, including stage indicator
       
   140    */
       
   141   
       
   142   function show_header()
       
   143   {
       
   144     // Determine the name of the current stage
       
   145     $stage_name = false;
       
   146     
       
   147     if ( isset($this->stages['main'][$this->current_stage]) )
       
   148       $stage_name = $this->stages['main'][$this->current_stage];
       
   149     else if ( isset($this->stages['hide'][$this->current_stage]) )
       
   150       $stage_name = $this->stages['hide'][$this->current_stage];
       
   151     else
       
   152       // Can't determine name of stage
       
   153       return false;
       
   154       
       
   155     $this->app_name = htmlspecialchars($this->app_name);
       
   156     $stage_name = htmlspecialchars($stage_name);
       
   157     
       
   158     global $lang;
       
   159     if ( is_object($lang) && isset($GLOBALS['lang_uri']) )
       
   160     {
       
   161       $lang_uri = sprintf($GLOBALS['lang_uri'], $lang->lang_code);
       
   162       $this->add_header('<script type="text/javascript" src="' . $lang_uri . '"></script>');
       
   163     }
       
   164     
       
   165     $additional_headers = implode("\n    ", $this->additional_headers);
       
   166     $title = addslashes(str_replace(' ', '_', $stage_name));
       
   167     $js_dynamic = '<script type="text/javascript">
       
   168         var title="' . $title . '";
       
   169         var scriptPath="'.scriptPath.'";
       
   170         var ENANO_SID="";
       
   171         var AES_BITS='.AES_BITS.';
       
   172         var AES_BLOCKSIZE=' . AES_BLOCKSIZE . ';
       
   173         var pagepass=\'\';
       
   174         var ENANO_LANG_ID = 1;
       
   175         var DISABLE_MCE = true;
       
   176       </script>';
       
   177     
       
   178     echo <<<EOF
       
   179 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
       
   180 <html xmlns="http://www.w3.org/1999/xhtml">
       
   181   <head>
       
   182     <title>{$stage_name} &bull; {$this->app_name}</title>
       
   183     <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
       
   184     <link rel="stylesheet" type="text/css" href="../includes/clientside/css/enano-shared.css" />
       
   185     <link rel="stylesheet" type="text/css" href="images/css/installer.css" id="mdgCss" />
       
   186     $js_dynamic
       
   187     <script type="text/javascript" src="../includes/clientside/static/enano-lib-basic.js"></script>
       
   188     $additional_headers
       
   189   </head>
       
   190   <body>
       
   191     <div id="enano">
       
   192 
       
   193 EOF;
       
   194     if ( !$this->simple )
       
   195     {
       
   196       $step = ( !empty($this->step) ) ? '<div id="step">' . htmlspecialchars($this->step) . '</div>' : '';
       
   197       echo <<<EOF
       
   198       <div id="header">
       
   199         $step
       
   200         <img alt="Enano logo" src="images/enano-artwork/installer-header-blue.png" />
       
   201       </div>
       
   202 
       
   203 EOF;
       
   204     }
       
   205     $stages_class = ( $this->simple ) ? 'stages' : 'stages stages-fixed';
       
   206     echo <<<EOF
       
   207       <div class="stages-holder">
       
   208         <ul class="$stages_class">
       
   209     
       
   210 EOF;
       
   211     foreach ( $this->stages['main'] as $guid => $stage )
       
   212     {
       
   213       $class = ( $guid == $this->current_stage ) ? 'stage stage-active' : 'stage';
       
   214       $stage = htmlspecialchars($stage);
       
   215       echo "      <li class=\"$class\">$stage</li>\n    ";
       
   216     }
       
   217     echo "    </ul>\n      <div style=\"clear: both;\"></div>\n      </div>\n";
       
   218     echo "      <div id=\"enano-fill\">\n        ";
       
   219     echo "  <div id=\"enano-body\">\n            ";
       
   220   }
       
   221   
       
   222   /**
       
   223    * Displays the page footer.
       
   224    */
       
   225   
       
   226   function show_footer()
       
   227   {
       
   228     echo <<<EOF
       
   229           <div id="copyright">
       
   230             Enano and its various components, related documentation, and artwork are copyright &copy; 2006-2008 Dan Fuhry.<br />
       
   231             This program is Free Software; see the file "GPL" included with this package for details.
       
   232           </div>
       
   233         </div> <!-- div#enano-body -->
       
   234       </div> <!-- div#enano-fill -->
       
   235     </div> <!-- div#enano -->
       
   236   </body>
       
   237 </html>
       
   238 EOF;
       
   239   }
       
   240   
       
   241 }
       
   242  
       
   243 ?>