Пример #1
0
 public function showstep()
 {
     if ($this->step == 0) {
         //默认系统显示
         include "templates/index.tpl";
     }
     if ($this->step == 1) {
         //第一步安装,首先清空指定目录下的文件
         $this->clearcontent('safe', true);
         $this->clearcontent('caches', false);
         $this->clearcontent('admin_safe_ims/logs', false);
         $this->clearcontent('templates/templates_compile/', false);
         include "templates/step1.tpl";
     }
     if ($this->step == 2) {
         $host = trim($_POST["dhost"]);
         $database = trim($_POST["dname"]);
         $user = trim($_POST["duname"]);
         $passwd = trim($_POST["dpasswd"]);
         $prefix = trim($_POST["dprefix"]);
         //往配置文件里写入数据库信息
         $conffile = file_get_contents(MSGROOT . "config.simple.php");
         $pattern = array("/(cfg\\[\"dbhost\"\\]=)([^;]+);/i", "/(cfg\\[\"dbuser\"\\]=)([^;]+);/i", "/(cfg\\[\"dbpassword\"\\]=)([^;]+);/i", "/(cfg\\[\"dbname\"\\]=)([^;]+);/i", "/(cfg\\[\"prefix\"\\]=)([^;]+);/i");
         $replace = array("\$1 " . "\"" . $host . "\";", "\$1 " . "\"" . $user . "\";", "\$1 " . "\"" . $passwd . "\";", "\$1 " . "\"" . $database . "\";", "\$1 " . "\"" . $prefix . "\";");
         $conffile = preg_replace($pattern, $replace, $conffile);
         //创建数据库
         $sql = trim(file_get_contents(MSGROOT . "install/install.sql"));
         $sql_arr = explode("Create table ims_", $sql);
         array_shift($sql_arr);
         require MSGROOT . "include/db.class.php";
         $mysql = new Mysql($host, $user, $passwd, $database, $prefix);
         foreach ($sql_arr as $sql) {
             $sql = "Create table ims_" . $sql;
             $mysql->setQuery($sql);
             $mysql->query();
         }
         $error1 = $mysql->get_error();
         //获取要创建的用户名和密码
         $admin = trim($_POST['uname']);
         $name = trim($_POST['trname']);
         $upasswd = sha1(trim($_POST['upasswd']));
         $createuser = "******"{$admin}\",\"{$upasswd}\",1,\"{$name}\")";
         $mysql->setQuery($createuser);
         $mysql->query();
         $error2 = $mysql->get_error();
         if ($error1 > 0 || $error2 > 0) {
             echo "安装过程中似乎哪里出错了,请检查或者手动编辑根目录下的config.simple.php并改名为config.php文件";
         } else {
             echo "系统安装成功,正在转向管理后台!";
             //写入安装锁定文件
             file_put_contents(MSGROOT . "install/install.lock", "If you want to reinstall the system,please remove this file!");
             //写入新的配置文件
             file_put_contents(MSGROOT . "config.php", $conffile);
             echo "<script>setTimeout(function(){window.location.href=\"../admin_safe_ims/\";},1500);</script>";
         }
     }
 }
Пример #2
0
//获取sql语言,如果返回结果为数字,则是因为必填项不合法
$sql = $msg_ins->getsql();
//如果$sql为整数,则用户输入出现错误,否则,则提交数据库
if (gettype($sql) == "integer") {
    $errorcode = $sql;
    showui($errorcode);
    //goto view;
    exit;
} else {
    //加载数据库类,并实例化
    require_once MSGROOT . "include/db.class.php";
    $mysql = new Mysql($sysconf->dbhost, $sysconf->dbuser, $sysconf->dbpassword, $sysconf->dbname, $sysconf->prefix, $sysconf->lang);
    $mysql->setQuery($sql);
    $mysql->query();
    //获取mysql的执行错误代码
    $errorcode = $mysql->get_error();
    showui($errorcode);
    exit;
}
//其它未知错误
$errorcode = 8;
showui($errorcode);
//当检查到错误代码出现时,直接程序直接跳转到这里
//执行结果展示
//PHP5.2以上版本
function showui($errorcode)
{
    $cachefile = MSGROOT . "caches/caches_" . $lang . "_" . $errorcode . ".html";
    //缓存文件的存放地址
    global $userlang, $timer, $sysconf;
    //如果系统开启缓存,则直接显示缓存文件