<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/favicon.ico" rel="icon" type="image/x-icon" />
<link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="/favicon.ico" rel="bookmark"> 
<title>Install--iQQol 飞翔版[3.5] Powered by IZzx.</title>
<link rel="stylesheet" type="text/css" href="../common.css">
</head>
<body>
<?php
    @set_time_limit(0);
    @ignore_user_abort(true);
    define("iZzx_IQQOL","Powered by iQQol.");
    define('IQQOL_FILE_ROOT',dirname(dirname(__FILE__)));
    include '../config.inc.php';

    function get_client_ip() 
    { 
        if ($_SERVER['REMOTE_ADDR']) { 
            $cip = $_SERVER['REMOTE_ADDR']; 
        } elseif (getenv("REMOTE_ADDR")) { 
            $cip = getenv("REMOTE_ADDR"); 
        } elseif (getenv("HTTP_CLIENT_IP")) { 
            $cip = getenv("HTTP_CLIENT_IP"); 
        } else { 
            $cip = "unknown"; 
        } 
    return $cip; 
    }
            function Data_config(){
                $host=$_POST['host'];
                $user=$_POST['user'];
                $password=$_POST['pass'];
                $db=$_POST['db'];
                $table=$_POST['table'];
                $conn=mysql_pconnect($host,$user,$password) or die("<h1>数据库链接失败！请检查您填写的数据库信息。");
                mysql_query("set names 'utf8'");
                $select=mysql_select_db($db,$conn);
                $tblist= mysql_list_tables($db);

            while($r=mysql_fetch_row($tblist)){
            /*CREATE iQQOL_config*/
                if($r[0]==$table."config"){

                    if(mysql_query("drop table {$table}config")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
            /*CREATE iQQOL_query*/
                else if($r[0]==$table."query"){

                    if(mysql_query("drop table {$table}query")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
            /*CREATE iQQOL_online*/
                else if($r[0]==$table."online"){

                    if(mysql_query("drop table {$table}online")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
             /*CREATE iQQOL_members*/
                else if($r[0]==$table."members"){

                    if(mysql_query("drop table {$table}members")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
               /*CREATE iQQOL_admincp_power*/
                else if($r[0]==$table."admincp_power"){

                    if(mysql_query("drop table {$table}admincp_power")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
               /*CREATE iQQOL_group_power*/
                else if($r[0]==$table."group_power"){

                    if(mysql_query("drop table {$table}group_power")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
               /*CREATE iQQOL_idcode*/
                else if($r[0]==$table."idcode"){

                    if(mysql_query("drop table {$table}idcode")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
               /*CREATE iQQOL_friends_links*/
                else if($r[0]==$table."friends_links"){

                    if(mysql_query("drop table {$table}friends_links")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
               /*CREATE iQQOL_iqqol_adv*/
                else if($r[0]==$table."adv"){

                    if(mysql_query("drop table {$table}adv")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
                /*CREATE iQQOL_service_group*/
                else if($r[0]==$table."service_group"){

                    if(mysql_query("drop table {$table}service_group")){
                        echo "数据表[$table.$r]清理成功<br>";}
                        else{
                            echo "数据表[$r]清理失败<br>";
                            exit();
                    }

                }
}
            if($conn and $select){
            $fpsql=fopen('data.sql','r+');
            $sqltext=fread($fpsql,filesize("data.sql"));
                $data_text=str_replace("iqqol_","{$table}",$sqltext);
                $explode = explode(";",$data_text);
                $cnt = count($explode);
                for($i=0;$i<$cnt ;$i++){
                    $sql = $explode[$i];
                    $result = mysql_query($sql);
                }

                    if($result){
                            return "数据库初始化成功，共".$i."个查询<br>";
                    }
                    else{
                            echo "<h1>数据库初始化失败".mysql_error();
                    }
}
            else{

                echo "<h1>数据库连接失败!";
                exit();
            }
}
?>
<?php

    @$type=$_GET['type'];

    if(file_exists("../install/install.lock")){

        include('Error.php');
        exit;

    }

    if(!isset($_GET['agree']) or $_GET['agree']==""){

        $agree="";

    }

    else{

        $agree=$_GET['agree'];
    }

    if($agree=="yes"){


        if($type=="1"){

            include('Type_1.php');

        }


        if ($type=="2"){
        if(strlen($_POST['dlappid'])<10){
            $dlappid='11111111111';
        }else{
            $dlappid=$_POST['dlappid'];
        }
        if(strlen($_POST['dlapikey'])<10){
            $dlapikey='2222222222';
        }else{
            $dlapikey=$_POST['dlapikey'];
        }
        if($_POST['dlapikey']==$_POST['dlappid']){
            die('Error! DengLu APPID or APIKEY is useless.');
        }
        $txt="<?php

        date_default_timezone_set('PRC');

            define(\"IQQOL_ROOT\",\"http://_QROOT_\");
                //Constant data
                define(\"iZzx_IQQOL\",\"Powered by iQQol.\");    /*DBHost*/
                define(\"IQQOL_SQLHOST\",\"$_POST[host]\");    /*DBHost*/
                define(\"IQQOL_DBNAME\",\"$_POST[db]\");    /*DBName*/
                define(\"IQQOL_SQLUSER\",\"$_POST[user]\");    /*DBUser*/
                define(\"IQQOL_SQLPASS\",\"$_POST[pass]\");    /*DBPassword*/
                define(\"IQQOL_SQLTABLE\",\"$_POST[table]\");    /*Table prefix*/
                define(\"IQQOL_SPPASS\",'".md5(md5($_POST[sppass]).iZzx_IQQOL)."');    /*Super Password*/
                
                //Variable data
                ".'$host'."     = IQQOL_SQLHOST;
                ".'$db'."       = IQQOL_DBNAME;
                ".'$user'."     = IQQOL_SQLUSER;
                ".'$password'." = IQQOL_SQLPASS;
                ".'$table'."    = IQQOL_SQLTABLE;
                ".'$kfqq'."     = IQQOL_KFQQ;
                ".'$kfpwd'."    = IQQOL_KFPWD;
";

$txt.='

                //Denglu APP information
                define("DL_APPID","'.$dlappid.'");
                define("DL_APIKEY","'.$dlapikey.'");';

$txt.="


            //UCenter config
            define(\"UC_CONNECT\",dirname(__FILE__));
            require_once UC_CONNECT.'/data/uc_config.php';
                /****如果该应用到数据库时填写,连接UC的数据库,解决同步登陆问题***/
                \$dbhost = UC_DBHOST;		// 数据库服务器
                \$dbuser = UC_DBUSER;			// 数据库用户名
                \$dbpw = UC_DBPW;			// 数据库密码
                \$dbname = UC_DBNAME;		// 数据库名
                \$pconnect = 0;				// 数据库持久连接 0=关闭, 1=打开
                \$tablepre = UC_DBTABLEPRE;   		// 表名前缀, 同一数据库安装多个论坛请修改此处
                \$dbcharset = UC_DBCHARSET;		// MySQL 字符集
                //同步登录 Cookie 设置
                \$cookiedomain = ''; 		// cookie 作用域
                \$cookiepath = '/';			// cookie 作用路径
";


$txt=str_replace('_QROOT_',str_replace('/install/index.php','',$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']),$txt);
        $fp=fopen("../config.inc.php","w+");
        flock($fp,LOCK_EX);
        $write=fputs($fp,$txt);
        flock($fp,LOCK_UN);
        fclose($fp);

            $host=$_POST['host'];
            $user=$_POST['user'];
            $password=$_POST['pass'];
            $db=$_POST['db'];
            $table=$_POST['table'];
            $conn=mysql_connect($_POST['host'],$_POST['user'],$_POST['pass']);
            mysql_query("set names 'utf8'",$conn);
            $select=mysql_select_db($_POST['db'],$conn);
        if($conn and $select){

            Data_config();
            //mysql_query("set names 'utf8'",$conn);
            $i1=mysql_query("INSERT INTO {$_POST['table']}config (id,style,sppass,webname,webkeyword,webdescript,status) VALUES (NULL,'".$_POST['style']."','".$_POST['sppass']."','','','','on')",$conn);
            //echo mysql_error()."INSERT INTO {$_POST['table']}config (id,style,notice,sppass,webname,webkeyword,webdescript,status) VALUES (NULL,'".$_POST['style']."','".$_POST['notice']."','".$_POST['sppass']."','','','','on')";
            $i2=mysql_query("INSERT INTO {$_POST['table']}service_group (qq,password) VALUES ('{$_POST['kfqq']}','".md5($_POST['kfpwd'])."')");
            //$i2=mysql_query("INSERT INTO {$_POST['table']}users (uid,name,mname,pass) VALUES (NULL,'".$_POST['spuser']."','".$_POST['mname']."','".$_POST['sppass']."')",$conn);

            if(!$i1 or !$i2){
                echo '<h1>写入数据失败，请重试！<br><br>'.'['.$_POST['table'].'config]<br>';
                echo 'HOST:'.$host.'<br>','USER:'.$user.'<br>','PASS:'.$password.'<br>','DATABASE:'.$db.'<br>','TABLE:'.$table.'config<br><h3>'.mysql_error().'</h3>';
                exit();
                }
            //else if(!$i2){
            //    echo '<h1>写入数据失败，请重试！<br><br>'.'[iqqol_users]<br>';
            //    echo 'HOST:'.$host.'<br>','USER:'.$user.'<br>','PASS:'.$password.'<br>','DATABASE:'.$db.'<br>','TABLE:'.$table.'users';
           //     exit();
            //    }
            else if($write){
                echo '<script>location.href="index.php?agree=yes&type=3"</script>';
                }
            else{
                echo "<h1>保存配置失败！请开启目录0777权限。无法进一步安装<br />";
                }
    }
        else{
            echo "<h1>链接数据库失败！无法进一步安装<br />";
            }
        }
   if ($type=="3"){
	   include('Type_2.php');}

	if ($type=="4"){
            include '../config.inc.php';
            @$conn=mysql_connect(IQQOL_SQLHOST,IQQOL_SQLUSER,IQQOL_SQLPASS) or die("<h1>数据库链接失败！请检查您填写的数据库信息。");
            mysql_select_db(IQQOL_DBNAME,$conn);
            @mysql_query($conn,"set names 'utf8'");
            $install=mysql_query("UPDATE ".IQQOL_SQLTABLE."config
 SET webname='{$_POST['webname']}'
 WHERE id = '1'");
            $install.=mysql_query("UPDATE ".IQQOL_SQLTABLE."config
 SET webkeyword='{$_POST['keyword']}' 
 WHERE id = '1'");
            $install.=mysql_query("UPDATE ".IQQOL_SQLTABLE."config
 SET webdescript='{$_POST['webdescript']}' 
 WHERE id = '1'");
            $txt="<?php
        date_default_timezone_set('PRC');
                define(\"APIKEY\",\"$_POST[apikey]\");
                define(\"APIPASS\",\"$_POST[password]\");
";
        $fp=fopen("../data/auth.php","w+");
        flock($fp,LOCK_EX);
        $write=fputs($fp,$txt);
        flock($fp,LOCK_UN);
        fclose($fp);
       if($install){
	         $fp2=fopen("../install/install.lock","w");
             flock($fp2,LOCK_EX);
             $write2=fputs($fp2,"<h1>安装成功！");
             flock($fp2,LOCK_UN);
             fclose($fp2);
             include('Success.php');}else{
		     echo "<h1>保存配置失败！请检查数据库是否可写<br />".mysql_error();
		}?>
       

       
       <?php }} ?>

<?php if(!isset($_GET['type']) or $_GET['type']==""){include('Faq.php'); } ?>