[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/installation/ -> install2.php (source)

   1  <?php
   2  /**
   3  * @version $Id: install2.php 5975 2006-12-11 01:26:33Z robs $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // Set flag that this is a parent file
  15  define( "_VALID_MOS", 1 );
  16  
  17  // Include common.php
  18  require_once ( 'common.php' );
  19  require_once ( '../includes/database.php' );
  20  
  21  $DBhostname = mosGetParam( $_POST, 'DBhostname', '' );
  22  $DBuserName = mosGetParam( $_POST, 'DBuserName', '' );
  23  $DBpassword = mosGetParam( $_POST, 'DBpassword', '' );
  24  $DBname      = mosGetParam( $_POST, 'DBname', '' );
  25  $DBPrefix      = mosGetParam( $_POST, 'DBPrefix', '' );
  26  $DBDel      = intval( mosGetParam( $_POST, 'DBDel', 0 ) );
  27  $DBBackup      = intval( mosGetParam( $_POST, 'DBBackup', 0 ) );
  28  $DBSample    = intval( mosGetParam( $_POST, 'DBSample', 0 ) );
  29  $DBcreated    = intval( mosGetParam( $_POST, 'DBcreated', 0 ) );
  30  $BUPrefix = 'old_';
  31  $configArray['sitename'] = trim( mosGetParam( $_POST, 'sitename', '' ) );
  32  
  33  $database = null;
  34  
  35  $errors = array();
  36  if (!$DBcreated){
  37      if (!$DBhostname || !$DBuserName || !$DBname) {
  38          db_err ('stepBack3','The database details provided are incorrect and/or empty.');
  39      }
  40  
  41      if($DBPrefix == '') {
  42          db_err ('stepBack','You have not entered a database prefix.');
  43      }
  44  
  45      $database = new database( $DBhostname, $DBuserName, $DBpassword, '', '', false );
  46      $test = $database->getErrorMsg();
  47  
  48      if (!$database->_resource) {
  49          db_err ('stepBack2','The password and username provided are incorrect.');
  50      }
  51  
  52      // Does this code actually do anything???
  53      $configArray['DBhostname'] = $DBhostname;
  54      $configArray['DBuserName'] = $DBuserName;
  55      $configArray['DBpassword'] = $DBpassword;
  56      $configArray['DBname']     = $DBname;
  57      $configArray['DBPrefix']    = $DBPrefix;
  58  
  59      $sql = "CREATE DATABASE `$DBname`";
  60      $database->setQuery( $sql );
  61      $database->query();
  62      $test = $database->getErrorNum();
  63  
  64      if ($test != 0 && $test != 1007) {
  65          db_err( 'stepBack', 'A database error occurred: ' . $database->getErrorMsg() );
  66      }
  67  
  68      // db is now new or existing, create the db object connector to do the serious work
  69      $database = new database( $DBhostname, $DBuserName, $DBpassword, $DBname, $DBPrefix );
  70  
  71      // delete existing mos table if requested
  72      if ($DBDel) {
  73          $query = "SHOW TABLES FROM `$DBname`";
  74          $database->setQuery( $query );
  75          $errors = array();
  76          if ($tables = $database->loadResultArray()) {
  77              foreach ($tables as $table) {
  78                  if (strpos( $table, $DBPrefix ) === 0) {
  79                      if ($DBBackup) {
  80                          $butable = str_replace( $DBPrefix, $BUPrefix, $table );
  81                          $query = "DROP TABLE IF EXISTS `$butable`";
  82                          $database->setQuery( $query );
  83                          $database->query();
  84                          if ($database->getErrorNum()) {
  85                              $errors[$database->getQuery()] = $database->getErrorMsg();
  86                          }
  87                          $query = "RENAME TABLE `$table` TO `$butable`";
  88                          $database->setQuery( $query );
  89                          $database->query();
  90                          if ($database->getErrorNum()) {
  91                              $errors[$database->getQuery()] = $database->getErrorMsg();
  92                          }
  93                      }
  94                      $query = "DROP TABLE IF EXISTS `$table`";
  95                      $database->setQuery( $query );
  96                      $database->query();
  97                      if ($database->getErrorNum()) {
  98                          $errors[$database->getQuery()] = $database->getErrorMsg();
  99                      }
 100                  }
 101              }
 102          }
 103      }
 104  
 105      populate_db( $database, 'joomla.sql' );
 106      if ($DBSample) {
 107          populate_db( $database, 'sample_data.sql' );
 108      }
 109      $DBcreated = 1;
 110  }
 111  
 112  function db_err($step, $alert) {
 113      global $DBhostname,$DBuserName,$DBpassword,$DBDel,$DBname;
 114      echo "<form name=\"$step\" method=\"post\" action=\"install1.php\">
 115      <input type=\"hidden\" name=\"DBhostname\" value=\"$DBhostname\">
 116      <input type=\"hidden\" name=\"DBuserName\" value=\"$DBuserName\">
 117      <input type=\"hidden\" name=\"DBpassword\" value=\"$DBpassword\">
 118      <input type=\"hidden\" name=\"DBDel\" value=\"$DBDel\">
 119      <input type=\"hidden\" name=\"DBname\" value=\"$DBname\">
 120      </form>\n";
 121      //echo "<script>alert(\"$alert\"); window.history.go(-1);</script>";
 122      echo "<script>alert(\"$alert\"); document.location.href='install1.php';</script>";
 123      exit();
 124  }
 125  
 126  /**
 127   * @param object
 128   * @param string File name
 129   */
 130  function populate_db( &$database, $sqlfile='mambo.sql') {
 131      global $errors;
 132  
 133      $mqr = @get_magic_quotes_runtime();
 134      @set_magic_quotes_runtime(0);
 135      $query = fread( fopen( 'sql/' . $sqlfile, 'r' ), filesize( 'sql/' . $sqlfile ) );
 136      @set_magic_quotes_runtime($mqr);
 137      $pieces  = split_sql($query);
 138  
 139      for ($i=0; $i<count($pieces); $i++) {
 140          $pieces[$i] = trim($pieces[$i]);
 141          if(!empty($pieces[$i]) && $pieces[$i] != "#") {
 142              $database->setQuery( $pieces[$i] );
 143              if (!$database->query()) {
 144                  $errors[] = array ( $database->getErrorMsg(), $pieces[$i] );
 145              }
 146          }
 147      }
 148  }
 149  
 150  /**
 151   * @param string
 152   */
 153  function split_sql($sql) {
 154      $sql = trim($sql);
 155      $sql = ereg_replace("\n#[^\n]*\n", "\n", $sql);
 156  
 157      $buffer = array();
 158      $ret = array();
 159      $in_string = false;
 160  
 161      for($i=0; $i<strlen($sql)-1; $i++) {
 162          if($sql[$i] == ";" && !$in_string) {
 163              $ret[] = substr($sql, 0, $i);
 164              $sql = substr($sql, $i + 1);
 165              $i = 0;
 166          }
 167  
 168          if($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") {
 169              $in_string = false;
 170          }
 171          elseif(!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
 172              $in_string = $sql[$i];
 173          }
 174          if(isset($buffer[1])) {
 175              $buffer[0] = $buffer[1];
 176          }
 177          $buffer[1] = $sql[$i];
 178      }
 179  
 180      if(!empty($sql)) {
 181          $ret[] = $sql;
 182      }
 183      return($ret);
 184  }
 185  
 186  $isErr = intval( count( $errors ) );
 187  
 188  echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">";
 189  ?>
 190  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 191  <html xmlns="http://www.w3.org/1999/xhtml">
 192  <head>
 193  <title>Joomla! - Web Installer</title>
 194  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 195  <link rel="shortcut icon" href="../images/favicon.ico" />
 196  <link rel="stylesheet" href="install.css" type="text/css" />
 197  <script type="text/javascript">
 198  <!--
 199  function check() {
 200      // form validation check
 201      var formValid = true;
 202      var f = document.form;
 203      if ( f.sitename.value == '' ) {
 204          alert('Please enter a Site Name');
 205          f.sitename.focus();
 206          formValid = false
 207      }
 208      return formValid;
 209  }
 210  //-->
 211  </script>
 212  </head>
 213  <body onload="document.form.sitename.focus();">
 214  <div id="wrapper">
 215      <div id="header">
 216        <div id="joomla"><img src="header_install.png" alt="Joomla! Installation" /></div>
 217      </div>
 218  </div>
 219  
 220  <div id="ctr" align="center">
 221      <form action="install3.php" method="post" name="form" id="form" onsubmit="return check();">
 222      <input type="hidden" name="DBhostname" value="<?php echo "$DBhostname"; ?>" />
 223      <input type="hidden" name="DBuserName" value="<?php echo "$DBuserName"; ?>" />
 224      <input type="hidden" name="DBpassword" value="<?php echo "$DBpassword"; ?>" />
 225      <input type="hidden" name="DBname" value="<?php echo "$DBname"; ?>" />
 226      <input type="hidden" name="DBPrefix" value="<?php echo "$DBPrefix"; ?>" />
 227      <input type="hidden" name="DBcreated" value="<?php echo "$DBcreated"; ?>" />
 228      <div class="install">
 229          <div id="stepbar">
 230                <div class="step-off">pre-installation check</div>
 231                <div class="step-off">license</div>
 232                <div class="step-off">step 1</div>
 233                <div class="step-on">step 2</div>
 234                <div class="step-off">step 3</div>
 235                <div class="step-off">step 4</div>
 236          </div>
 237          <div id="right">
 238                <div class="far-right">
 239  <?php if (!$isErr) { ?>
 240                      <input class="button" type="submit" name="next" value="Next >>"/>
 241  <?php } ?>
 242                </div>
 243                <div id="step">step 2</div>
 244                <div class="clr"></div>
 245  
 246                <h1>Enter the name of your Joomla! site:</h1>
 247              <div class="install-text">
 248  <?php if ($isErr) { ?>
 249              Looks like there have been some errors with inserting data into your database!<br />
 250                You cannot continue.
 251  <?php } else { ?>
 252              SUCCESS!
 253              <br/>
 254              <br/>
 255                Type in the name for your Joomla! site. This
 256              name is used in email messages so make it something meaningful.
 257  <?php } ?>
 258            </div>
 259            <div class="install-form">
 260                <div class="form-block">
 261                    <table class="content2">
 262  <?php
 263              if ($isErr) {
 264                  echo '<tr><td colspan="2">';
 265                  echo '<b></b>';
 266                  echo "<br/><br />Error log:<br />\n";
 267                  // abrupt failure
 268                  echo '<textarea rows="10" cols="50">';
 269                  foreach($errors as $error) {
 270                      echo "SQL=$error[0]:\n- - - - - - - - - -\n$error[1]\n= = = = = = = = = =\n\n";
 271                  }
 272                  echo '</textarea>';
 273                  echo "</td></tr>\n";
 274                } else {
 275  ?>
 276                    <tr>
 277                        <td width="100">Site name</td>
 278                        <td align="center"><input class="inputbox" type="text" name="sitename" size="50" value="<?php echo "{$configArray['sitename']}"; ?>" /></td>
 279                    </tr>
 280                    <tr>
 281                        <td width="100">&nbsp;</td>
 282                        <td align="center" class="small">e.g. The Home of Joomla!</td>
 283                    </tr>
 284                    </table>
 285  <?php
 286                } // if
 287  ?>
 288                </div>
 289            </div>
 290            <div class="clr"></div>
 291            <div id="break"></div>
 292      </div>
 293      <div class="clr"></div>
 294      </form>
 295  </div>
 296  <div class="clr"></div>
 297  </div>
 298  <div class="ctr">
 299      <a href="http://www.joomla.org" target="_blank">Joomla!</a> is Free Software released under the GNU/GPL License.
 300  </div>
 301  </body>
 302  </html>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics