六步走完成OPENCART安装程序编写工作

上一篇 / 下一篇  2007-10-07 11:04:10 / 个人分类:OpenCart

我们需要DW来进行辅助的可视化设计,如果你的html基本功很强大,可以用记事本

step 1编写css文件“stylesheet.css”:

body, form {
  color: #FFFFFF;
  margin: 0;
  padding: 0;
  background-image: url(JDSJ042.jpg)
}
 
}

body, td, th, input, select, textarea {
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size: 11px;
  color: #000000;
}

#container {
 margin-top: 50px;
 width: 600px;
 position: absolute;
 left: 50%;
 margin-left: -300px;
 border: thin 1px #CCCCCC;
}

#header {
    color: #FFFFF;
 background-color: #00000;
 padding: 5px;
 margin: 5px;
 height: 30px;
 border: hidden;
 font-size: 24px;
 font-weight: bold;
}

#content {
    color: #FFFFF;
 padding: 5px;
 margin: 5px;
 border: 0px dashed #CCCCCC; 
}

#footer {
 padding: 5px;
 margin: 5px;
 border: 0px dashed #CCCCCC;
 text-align: center;
}

.required {
 color: #FF0000;
 margin-right: 5px;
}

.error {
 color: #FF0000;
 display: block;
 clear: both; 
}

.warning {
 background-color: #FFB3B5;
 padding: 3px;
}

.good {
 color: #669900;
 font-weight: bold;
}

.bad {
 color: #FF0000;
 font-weight: bold; 
}

step 2生成一个html文件取名step1.html,把title改成“系统安装”,配置css文件,指向我们生成的stylesheet.css:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统安装</title>

<link rel="stylesheet" type="text/css" href="stuff/stylesheet.css" />
</head>
<body>

</body>
</html>

step 3设计安装程序的第一个界面,你可以复制下面的源代码,再重新进行布局:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统安装</title>

<link rel="stylesheet" type="text/css" href="stuff/stylesheet.css" />
<style type="text/css">
<!--
body {
 background-image: url(stuff/JDSJ042.jpg);
}
-->
</style></head>
<body>
<div id="container">
<form action="index.php?step=1" method="post" enctype="multipart/form-data">
  <div id="header" >步骤 1 - 准备安装</div>
  <div id="content">
    <?php if (isset($error['message'])) { ?>
    <div class="warning"><?php echo $error['message']; ?></div>
    <?php } ?>
    <br>1. 请调整php.ini相关参数确保安装需要需要.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th width="35%" align="left">PHP 参数</th>
        <th width="25%" align="left">当前</th>
        <th width="25%" align="left">需要</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>PHP 版本:</td>
        <td><?php echo phpversion(); ?></td>
        <td>5.0+</td>
        <td><?php echo (phpversion() >= '5.0' ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>Register Globals:</td>
        <td><?php echo (ini_get('register_globals') ? 'On' : 'Off'); ?></td>
        <td>Off</td>
        <td><?php echo (!ini_get('register_globals') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>File Uploads:</td>
        <td><?php echo (ini_get('file_uploads') ? 'On' : 'Off'); ?></td>
        <td>On</td>
        <td><?php echo (ini_get('file_uploads') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>Session Auto Start:</td>
        <td><?php echo (ini_get('session.auto_start') ? 'On' : 'Off'); ?></td>
        <td>Off</td>
        <td><?php echo (!ini_get('session.auto_start') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
    </table>
    <br>2. 请确定下列PHP扩展已安装.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th width="35%" align="left">PHP 扩展</th>
        <th width="25%" align="left">当前设置</th>
        <th width="25%" align="left">需要设置</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>MySQL:</td>
        <td><?php echo (extension_loaded('mysql') ? 'On' : 'Off'); ?></td>
        <td>On</td>
        <td><?php echo (extension_loaded('mysql') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>GD:</td>
        <td><?php echo (extension_loaded('gd') ? 'On' : 'Off'); ?></td>
        <td>On</td>
        <td><?php echo (extension_loaded('gd') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
    </table>
    <br>3. 请确定你有下列文件的读写权限.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th align="left">文件</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../config.php'); ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../config.php') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
    </table>
    <br>4. 请确定你有下列目录的读写权限.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th align="left">目录</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../APP') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../APP') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../images') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../images') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../templates') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../templates') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../templates_C') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../templates_C') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../upload') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../upload') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>  
    </table>
  </div>
  <div id="footer">
    <input type="submit" value="继续" />
  </div>
</form>
</Div>
</body>
</html>

图片一 安装程序的第一个界面:

当然里面有代码啊,否则怎么叫动态网页?这个部分,套流行的说法,是MVC中V的部分,V的部分是交互的部分,也是安装程序的关键部分,这部分解决了,其它相对就容易了,下面设计第二个界面。

step 4设计安装程序的第二个界面,同样的,你可以复制下面的源代码,再重新进行布局,可以从step1.php复制出来,再添加<form></form>部分:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统安装</title>

<link rel="stylesheet" type="text/css" href="stuff/stylesheet.css" />
</head>
<body>
<div id="container">
<form action="index.php?step=2" method="post" enctype="multipart/form-data">
  <div id="header">步骤 2 - 数据库信息</div>
  <div id="content">
    <?php if (isset($error['message'])) { ?>
    <div class="warning"><?php echo $error['message']; ?></div>
    <?php } ?>
    <p>请输入你的数据库连接信息.</p>
    <table>
      <tr bgcolor="#AFC4CF">
        <td width="185"><span class="required">*</span>主机名称:</td>
        <td><?php if (isset($_POST['db_host'])) { ?>
          <input type="text" name="db_host" value="<?php echo $_POST['db_host']; ?>" />
          <?php } elseif (isset($_SESSION['db_host'])) { ?>
          <input type="text" name="db_host" value="<?php echo $_SESSION['db_host']; ?>" />
          <?php } else {?>
          <input type="text" name="db_host" value="localhost" />
          <?php } ?>
          <?php if (isset($error['db_host'])) { ?>
          <span class="required"><?php echo $error['db_host']; ?></span>
          <?php } ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><span class="required">*</span>用户名:</td>
        <td><input type="text" name="db_user" value="<?php echo (isset($_POST['db_user']) ? $_POST['db_user'] : @$_SESSION['db_user']); ?>" />
          <?php if (isset($error['db_user'])) { ?>
          <span class="required"><?php echo $error['db_user']; ?></span>
          <?php } ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><span class="required">*</span>密码:</td>
        <td><input type="text" name="db_password" value="<?php echo (isset($_POST['db_password']) ? $_POST['db_password'] : @$_SESSION['db_password']); ?>" />
          <?php if (isset($error['db_password'])) { ?>
          <span class="required"><?php echo $error['db_password']; ?></span>
          <?php } ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><span class="required">*</span>数据库名称:</td>
        <td><input type="text" name="db_name" value="<?php echo (isset($_POST['db_name']) ? $_POST['db_name'] : @$_SESSION['db_name']); ?>" />
          <?php if (isset($error['db_name'])) { ?>
          <span class="required"><?php echo $error['db_name']; ?></span>
          <?php } ?></td>
      </tr>
    </table>
  </div>
  <div id="footer">
    <input type="submit" value="继续" />
  </div>
</form>
</div>
</body>
</html>

图片二 安装程序的第二个界面:

step 5设计安装程序的第二个界面,同样的,你可以复制下面的源代码,再重新进行布局,可以从step1.php复制出来,再添加<form></form>部分:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统安装</title>

<link rel="stylesheet" type="text/css" href="stuff/stylesheet.css" />
</head>
<body>
<div id="container">
<form action="index.php?step=3" method="post" enctype="multipart/form-data">
<div id="header">步骤 3 - 安装完成!</div>
<div id="content">
  <p>恭喜你! 演示程序已经成功地安装在你的电脑上.</p>
  <div class="warning">不要忘记删除你的安装目录!</div>
</div>
<div id="footer">
  <input type="submit" value="继续" />
</div>
</form>
</div>

</body>
</html>

图片三 安装程序的第三个界面:

step 6三个界面的内容已经确定,目的就是能把里面的部分代码拷贝出来,放到我们的安装程序中去:

没有什么关子好卖,源代码列在下面,关键是程序的结构,下面的源代码也就是最终的源代码,它们经过了提炼,把共用的部分提了出来放到程序的最后,然后打开输出缓冲,先把<form>部分的内容存到变量$content中,再到最终的部分把内容吐出来,组成一个完整的HTML网页输出到浏览器上,实际设计的过程不一定会一步走到step6,可能的行为是你把代码放进去,先让index.php(安装程序)运行起来,再做提炼工作

    另一个好玩的事情就是:安装程序总是喜欢让一个单一的文件完成所有的工作,这样简洁高效,我也赞成不必要把MVC的设计思想放到安装程序的编写上,毕竟,这是个易拉罐的壳,喝完就扔垃圾桶了。

   程序运行后,先判断"/index.php?step=1"中的那个变量step有没有设定,if语句的条件在程序第一次运行时运行时会命中,然后程序简单地让step=1后进入switch语句。沿着switch规定的线路,进入1号分支第一次,if ((strtoupper($_SERVER['REQUEST_METHOD']) == 'POST'))并不会满足,于是程序生成一个完整的“界面一”的HTML代码进行第一次人机交互;用户从界面上读取系统要求的设置,按“继续”按钮“post”,上述的if条件得到满足,程序进行一系列的判断,看相关参数是否符合要求,不符合再次给出“界面一”,否则header到step2; 与分支1相似,一开始step2的if条件不会满足,程序生成完整的HTML代码给出界面二,完成与MYSQL连接信息的设置,POST后IF条件中的语句对录入信息进行校验,并测试连接的有效性,连接有效后,把SQL文件中的数据导入MYSQL,系统进入step3,这一步要讲一下的就是系统会把收集的信息导入到config.php文件中,其它就没有什么嚼头了。

    文章到此结束,事情总是这样,没有掌握的人会有兴趣看一下这篇文章,老鸟早就拍拍翅膀飞走了,连个脚印也不会留下。哈哈,不管怎样,研读OpenCart的系列文章还在继续,这几天开始准备一篇使用OpenCart框架来做一个示例应用的文章,看看OpenCart的团队是如何的雄心勃勃,建立了一个适合开发各类PHP程序的基础框架

附完整的index.php源代码(版权归OpenCart所有The OpenCart owns the copyright of the below source code):

<?php
error_reporting(E_ALL);

header('Content-Type: text/html; charset=utf-8');

session_start();

 

$ds =  DIRECTORY_SEPARATOR; // too much typing ;)

if (!isset($_GET['step'])) {
 $step = 1;
} else {
 $step = $_GET['step'];
}

switch ($step) {
 case '1':
  if ((strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')) {
     $error = array();
 
     if (phpversion() < '5.0') {
       $error['message'] = '警告: 你需要使用PHP5以上的版本以便正常工作!';
     }

     if (ini_get('register_globals')) {
       $error['message'] = '警告:演示程序要求将register_globals设置为Off!';
     }

     if (!ini_get('file_uploads')) {
       $error['message'] = '警告:file_uploads需要设置为On!';
     }

     if (ini_get('session.auto_start')) {
       $error['message'] = '警告:演示程序需要将session.auto_start设置为Off!';
     }

     if (!extension_loaded('mysql')) {
       $error['message'] = '警告:MySQL extention 需要装入,请修改php.ini相关参数!';
     }

     if (!extension_loaded('gd')) {
       $error['message'] = '警告:GD extention 需要装入,请修改php.ini相关参数!';
     }

     if (!is_writable(dirname(__FILE__) . '/../config.php')) {
       $error['message'] = '警告:config.php在安装时必须设置成可读写状态!';
     }
      

    if (!is_writable(dirname(__FILE__) . '/../APP')) {
       $error['message'] = '警告:APP 目录在安装时必须设置成可读写状态!';
     }

    if (!is_writable(dirname(__FILE__) . '/../images')) {
       $error['message'] = '警告:Images 目录在安装时必须设置成可读写状态!';
     }

    if (!is_writable(dirname(__FILE__) . '/../templates')) {
       $error['message'] = '警告:templets 目录在安装时必须设置成可读写状态!';
     }
   
    if (!is_writable(dirname(__FILE__) . '/../templates_c')) {
       $error['message'] = '警告:templets_c 目录在安装时必须设置成可读写状态!';
     }

    if (!is_writable(dirname(__FILE__) . '/../upload')) {
       $error['message'] = '警告:upload 目录在安装时必须设置成可读写状态!';
     }                       
   if (!$error) {
    header('Location: index.php?step=2');
    exit();
   }
  }
  
  ob_start();
?>
<form action="index.php?step=1" method="post" enctype="multipart/form-data">
  <div id="header" >步骤 1 - 准备安装</div>
  <div id="content">
    <?php if (isset($error['message'])) { ?>
    <div class="warning"><?php echo $error['message']; ?></div>
    <?php } ?>
    <br>1. 请调整php.ini相关参数确保安装需要需要.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th width="35%" align="left">PHP 参数</th>
        <th width="25%" align="left">当前</th>
        <th width="25%" align="left">需要</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>PHP 版本:</td>
        <td><?php echo phpversion(); ?></td>
        <td>5.0+</td>
        <td><?php echo (phpversion() >= '5.0' ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>Register Globals:</td>
        <td><?php echo (ini_get('register_globals') ? 'On' : 'Off'); ?></td>
        <td>Off</td>
        <td><?php echo (!ini_get('register_globals') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>File Uploads:</td>
        <td><?php echo (ini_get('file_uploads') ? 'On' : 'Off'); ?></td>
        <td>On</td>
        <td><?php echo (ini_get('file_uploads') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>Session Auto Start:</td>
        <td><?php echo (ini_get('session.auto_start') ? 'On' : 'Off'); ?></td>
        <td>Off</td>
        <td><?php echo (!ini_get('session.auto_start') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
    </table>
    <br>2. 请确定下列PHP扩展已安装.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th width="35%" align="left">PHP 扩展</th>
        <th width="25%" align="left">当前设置</th>
        <th width="25%" align="left">需要设置</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>MySQL:</td>
        <td><?php echo (extension_loaded('mysql') ? 'On' : 'Off'); ?></td>
        <td>On</td>
        <td><?php echo (extension_loaded('mysql') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td>GD:</td>
        <td><?php echo (extension_loaded('gd') ? 'On' : 'Off'); ?></td>
        <td>On</td>
        <td><?php echo (extension_loaded('gd') ? '<span class="good">符合</span>' : '<span class="bad">错误</span>'); ?></td>
      </tr>
    </table>
    <br>3. 请确定你有下列文件的读写权限.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th align="left">文件</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../config.php'); ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../config.php') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
    </table>
    <br>4. 请确定你有下列目录的读写权限.</br>
    <table width="100%">
      <tr bgcolor="597380">
        <th align="left">目录</th>
        <th width="15%" align="left">状态</th>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../APP') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../APP') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../images') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../images') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../templates') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../templates') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../templates_C') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../templates_C') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><?php echo realpath(dirname(__FILE__) . '/../upload') . '/'; ?></td>
        <td><?php echo (is_writable(dirname(__FILE__) . '/../upload') ? '<span class="good">可读写</span>' : '<span class="bad">只读</span>'); ?></td>
      </tr>  
    </table>
  </div>
  <div id="footer">
    <input type="submit" value="继续" />
  </div>
</form>
<?php
    $content = ob_get_contents();

       ob_end_clean();
  break;
 case '2':
  if ($_POST) {
     $error = array();
 
     if (!$_POST['db_host']) {
       $error['db_host'] = '* Host 必须填写!';
     }
 
     if (!$_POST['db_user']) {
       $error['db_user'] = '* User 必须填写!';
     }
 
     if (!$_POST['db_name']) {
       $error['db_name'] = '* Database 名称必须填写!';
     }
 
     if (!$error) {
       if (!$connection = @mysql_connect($_POST['db_host'], $_POST['db_user'], $_POST['db_password'])) {
     $error['message'] = '出错: 不能连接到数据库,请确认主机名称,用户名,密码是否正确!' . "\n";
    } else {
     if (!@mysql_select_db($_POST['db_name'], $connection)) {
      $error['message'] = '出错: 数据库不存在!' . "\n";
     }   
    }
   }
   
   if (!$error) {
    mysql_query("set character set utf8", $connection);
    
    $file = dirname(__FILE__) . $ds.'openframeworkexample.sql';
   
       if ($sql = file($file)) {  //read a file into a array
       $query = '';

       foreach($sql as $line) {
            $tsl = trim($line);

       
      if (($sql != '') && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != '#')) {
               $query .= $line;
         
         if (preg_match('/;\s*$/', $line)) {

       
                 $result = mysql_query($query, $connection);
         
           if (!$result) {
           die(mysql_error());
                 }
   
        $query = '';
               }
            }
          }
          
     mysql_close($connection);
    } else {
     $error['message'] = '出错: 安装SQL文件 ' . $file . ' 不存在!' . "\n";
    }   
   }
       
   if (!$error) {
    $_SESSION['db_host']     = $_POST['db_host'];
    $_SESSION['db_user']     = $_POST['db_user'];
    $_SESSION['db_password'] = $_POST['db_password'];
    $_SESSION['db_name']     = $_POST['db_name'];
    
    header('Location: index.php?step=3');
    exit();
   }
  }
  
  ob_start();
?>
<form action="index.php?step=2" method="post" enctype="multipart/form-data">
  <div id="header">步骤 2 - 数据库信息</div>
  <div id="content">
    <?php if (isset($error['message'])) { ?>
    <div class="warning"><?php echo $error['message']; ?></div>
    <?php } ?>
    <p>请输入你的数据库连接信息.</p>
    <table>
      <tr bgcolor="#AFC4CF">
        <td width="185"><span class="required">*</span>主机名称:</td>
        <td><?php if (isset($_POST['db_host'])) { ?>
          <input type="text" name="db_host" value="<?php echo $_POST['db_host']; ?>" />
          <?php } elseif (isset($_SESSION['db_host'])) { ?>
          <input type="text" name="db_host" value="<?php echo $_SESSION['db_host']; ?>" />
          <?php } else {?>
          <input type="text" name="db_host" value="localhost" />
          <?php } ?>
          <?php if (isset($error['db_host'])) { ?>
          <span class="required"><?php echo $error['db_host']; ?></span>
          <?php } ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><span class="required">*</span>用户名:</td>
        <td><input type="text" name="db_user" value="<?php echo (isset($_POST['db_user']) ? $_POST['db_user'] : @$_SESSION['db_user']); ?>" />
          <?php if (isset($error['db_user'])) { ?>
          <span class="required"><?php echo $error['db_user']; ?></span>
          <?php } ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><span class="required">*</span>密码:</td>
        <td><input type="text" name="db_password" value="<?php echo (isset($_POST['db_password']) ? $_POST['db_password'] : @$_SESSION['db_password']); ?>" />
          <?php if (isset($error['db_password'])) { ?>
          <span class="required"><?php echo $error['db_password']; ?></span>
          <?php } ?></td>
      </tr>
      <tr bgcolor="#AFC4CF">
        <td><span class="required">*</span>数据库名称:</td>
        <td><input type="text" name="db_name" value="<?php echo (isset($_POST['db_name']) ? $_POST['db_name'] : @$_SESSION['db_name']); ?>" />
          <?php if (isset($error['db_name'])) { ?>
          <span class="required"><?php echo $error['db_name']; ?></span>
          <?php } ?></td>
      </tr>
    </table>
  </div>
  <div id="footer">
    <input type="submit" value="继续" />
  </div>
</form>
<?php  
  $content = ob_get_contents();

       ob_end_clean();
  break;
 case '3':
  if ((strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')) {
     $error = array();
   
   $server = $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0 , (strpos($_SERVER['PHP_SELF'], 'install/index.php')));
   
   $config = realpath(dirname(__FILE__) . '/../config.php');


   if (is_writable($config)) {
    $output  = '<?php' . "\n";
    $output .= '// HTTP' . "\n";
    $output .= 'define(\'HTTP_SERVER\', \'http://' . $server . '\');' . "\n";
    $output .= 'define(\'HTTP_IMAGE\', \'http://' . $server . 'image/\');' . "\n\n";

    $output .= '// HTTPS' . "\n";
    $output .= 'define(\'HTTPS_SERVER\', \'\');' . "\n";
    $output .= 'define(\'HTTPS_IMAGE\', \'\');' . "\n\n";

    $output .= '// DIR' . "\n";
    $output .= 'define(\'DIR_APP\', \'' . realpath(dirname(__FILE__) . '/..') . '/APP/\');' . "\n";
    $output .= 'define(\'DIR_UPLOAD\', \'' . realpath(dirname(__FILE__) . '/..') . '/upload/\');' . "\n";
    $output .= 'define(\'DIR_IMAGES\', \'' . realpath(dirname(__FILE__) . '/..') . '/imageS/\');' . "\n";
    $output .= 'define(\'DIR_LIBRARY\', \'' . realpath(dirname(__FILE__) . '/..') . '/library/\');' . "\n";
    $output .= 'define(\'DIR_TEMPLATES\', \'' . realpath(dirname(__FILE__) . '/..') . '/templates/\');' . "\n";
    $output .= 'define(\'DIR_TEMPLATES_C\', \'' . realpath(dirname(__FILE__) . '/..') . '/templates_c/\');' . "\n";
   
    $output .= '// DB' . "\n";
    $output .= 'define(\'DB_HOST\', \'' . $_SESSION['db_host'] . '\');' . "\n";
    $output .= 'define(\'DB_USER\', \'' . $_SESSION['db_user'] . '\');' . "\n";
    $output .= 'define(\'DB_PASSWORD\', \'' . $_SESSION['db_password'] . '\');' . "\n";
    $output .= 'define(\'DB_NAME\', \'' . $_SESSION['db_name'] . '\');' . "\n";
   
    $output .= '?>';    
       
    $file = fopen($config, 'w');
    
    fwrite($file, $output);
  
       fclose($file);
   } else {
    $error['message'] = '错误: 不能对config.php进行设置,请检查你是否有config目录的读写权限: ' . $config . "\n";
   }
             
   if (!$error) {
                $server = substr($_SERVER['PHP_SELF'], 0 , (strpos($_SERVER['PHP_SELF'], 'install/index.php')));
    header('Location: '.$server);
    exit();
   }
  }
  //header('Location: index.php?step=4');
  //exit();
  ob_start();
?>
<form action="index.php?step=3" method="post" enctype="multipart/form-data">
<div id="header">步骤 3 - 安装完成!</div>
<div id="content">
  <p>恭喜你! 演示程序已经成功地安装在你的电脑上.</p>
  <div class="warning">不要忘记删除你的安装目录!</div>
</div>
<div id="footer">
  <input type="submit" value="继续" />
</div>
</form>
<?php 
    $content = ob_get_contents();

       ob_end_clean();
  break;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统安装</title>
<base href="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0 , (strrpos($_SERVER['PHP_SELF'], "/") + 1)); ?>">
<link rel="stylesheet" type="text/css" href="stuff/stylesheet.css" />
</head>
<body>
<div id="container"><?php echo $content; ?></div>
</body>
</html>


TAG: OpenCart 编写 安装程序

引用 删除 DZfly   /   2008-03-07 22:00:24
~~~~~~~~~~~~DING
引用 删除 yelang   /   2008-03-06 23:06:39
师傅哈
引用 删除 蛛蛛   /   2007-11-30 18:53:02
uueeue
引用 删除 Guest   /   2007-10-22 16:19:33
你有上传文件的权限吗?个人喜欢拿来主义
引用 删除 龙行天下   /   2007-10-14 09:51:49
3
亽 发包   为 额外饿挖出
引用 删除 龙行天下   /   2007-10-14 09:49:53
很好
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 17111
  • 日志数: 87
  • 建立时间: 2007-09-29
  • 更新时间: 2008-04-15

RSS订阅

Open Toolbar