<?php
//-----------------------------------------------------------------------------
//    ID002同学录 单班级 (PHP & MySQL) 1.0 标准版
//-----------------------------------------------------------------------------
//    Copyright(C) aNErG, 2003. All rights reserved
//
//    技术支持 http://anerg.126.com
//-----------------------------------------------------------------------------
//    本软件对个人完全免费使用
//
//    如用于商业用途,您必须与我联系并支付RMB ￥20
//-----------------------------------------------------------------------------
  if (!file_exists("conn.php")) {
    ?>
<p>找不到文件 conn.php .</p>
<p>确定您已经上载此文件,且此文件在install.php同文件夹下！</p>
<?php } else
{include("conn.php");
   if($servername='' || $dbusername=''){
   ?>
<p>确定您填写了 conn.php 文件的全部细节.</p>
<? }}
if ($step==""){
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ID002校友录<?php echo $version; ?>版安装向导</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>

<body>
<p>感谢你使用ID002校友录<?php echo $version; ?>版。我也是刚学习PHP编程，要是你发现什么问题、或者有什么建议，<br>
  请给我发E-mail: <a href="mailto:zeying@eyou.com">zeying@eyou.com</a> 。想和我交流的话也给我发E-mail好了。</p>
<p>如果你可以建立数据库<a href="install.php?step=2">请点击这里继续 -></a></p>
<p>如果你在已有数据库中建立<a href="install.php?step=3">请点击这里继续 -></a></p>
<?php
}

if ($step==2) {
    
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ID002校友录<?php echo $version; ?>版安装向导</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<p>正在创建数据库...</p>
<?php 
if($mod==""){
  include("conn.php");
  $db_res=mysql_create_db("$dbname");  
  $db_err=mysql_error();
  if ($db_err=="Can't create database '$dbname'. Database exists"){
  $db_res=mysql_drop_db("$dbname");
  $db_res=mysql_create_db("$dbname");
  echo "<p>数据库存在，已经清空数据库<a href=\"install.php?step=3\">点击这里继续 -></a></p>";
  }
  else{
  if ($db_res==1) {
  echo "<p>成功!</p>";
  echo "<p><a href=\"install.php?step=3\">点击这里继续 -></a></p>";
  } else {
  echo "<p>连接失败! 请确认数据库和服务器设置正确然后再试.</p>";
        } 
		}  


}
?>
<?php
}

if ($step==3) {
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ID002校友录<?php echo $version; ?>版安装向导</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<p>正在初始化相关数据表格...</p>
<?php 
  include("conn.php");  
       //设置用户表
	   $query="create table classuser (userid int not null auto_increment,
	                                   username varchar(50),
									   userpwd varchar(50),
									   useremail varchar(50),
									   sex varchar(10),
									   userqq varchar(20),
									   usermsn varchar(50),
									   usericq varchar(20),
									   add_date datetime,
									   birthday varchar(50),
									   userphone varchar(50),
									   mobilephone varchar(50),
									   userinfo text,
									   stat int(1) NOT NULL default '0',
									   PRIMARY KEY(userid));";
	$result=mysql_db_query("$dbname",$query);								   
	//设置相关信息
	$query="create table classconfig (announcement text,
	                                  classname varchar(255),
									  adminemail varchar(50));";
	$result=mysql_db_query("$dbname",$query);
	//留言内容相关信息
	$query="create table classmsg (classmsgid int not null auto_increment,
	                               classmsg longtext,
								   author varchar(50),
								   msgtime datetime,
								   PRIMARY KEY(classmsgid));";								  
    $result=mysql_db_query("$dbname",$query);
	//上传图片记录
	$query="create table photomsg (photoid int not null auto_increment,
								   photourl text,
	                               photoname text,
								   author varchar(50),
								   uptime datetime,
								   PRIMARY KEY(photoid));";								  
    $result=mysql_db_query("$dbname",$query);
	//cookie
	$query="CREATE TABLE classcookie (
  cid varchar(32) NOT NULL default '0',
  cname varchar(50) NOT NULL default '',
  ctime int(10) NOT NULL default '0',
  KEY cid (cid)
)";
 $result=mysql_db_query("$dbname",$query);
	//班级传呼
	$query="CREATE TABLE u2u (
  u2uid int(11) NOT NULL auto_increment,
  u2uto varchar(50) NOT NULL default '',
  u2ufrom varchar(50) NOT NULL default '',
  u2uinfo text NOT NULL,
  u2udate datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (u2uid)
) ";								  
    $result=mysql_db_query("$dbname",$query);
	$db_err=mysql_error();
	if($db_err==""){
	echo "<p>恭喜，安装顺利完成，下面设置管理员账号和密码。<a href=\"install.php?step=4\">点击这里继续 -></a></p>";}
 ?>
 <?php
}

if ($step==4) {
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ID002校友录<?php echo $version; ?>版安装向导</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>

<body>
<form action="install.php" method="post">
<input type="hidden" name="step" value="5">
   <p align="center">同学录相关设置</p>
  <table width="95%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td width="40%" height="16"> 
        <div align="right"> 
          <p>ADMIN:</p>
        </div></td>
      <td width="60%"> <p align="left"> 
          <input type="text" name="adminuser">
        </p>
        </td>
    </tr>
    <tr> 
      <td height="16">
<div align="right">PASS:</div></td>
      <td width="60%"><input type="text" name="adminpwd"></td>
    </tr>
    <tr> 
      <td height="16">
<div align="right">公告:</div></td>
      <td width="60%"><input type="text" name="announcement"></td>
    </tr>
    <tr> 
      <td height="16">
<div align="right">管理员信箱:</div></td>
      <td width="60%"><input type="text" name="adminemail"></td>
    </tr>
    <tr> 
      <td height="16">
<div align="right">班级名称:</div></td>
      <td width="60%"><input type="text" name="classname">
        <input type="submit" name="Submit" value="O K"></td>
    </tr>
  </table></form>
<?php
}

if ($step==5) {
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ID002校友录<?php echo $version; ?>版安装向导</title>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<?php 
  include("conn.php");
  require('function.php');
  $query="insert into classconfig VALUES('$announcement','$classname','$adminemail')";
  $result=mysql_db_query("$dbname",$query);
  $adminpwd=encrypt($adminpwd);
  $query="insert into classuser VALUES('','$adminuser','$adminpwd','$adminemail','','','','','','','','','','1')";
  $result=mysql_db_query("$dbname",$query);
  if (mysql_affected_rows()==1){
  echo "大功告成！！你可以<a href=\"index.php\">点击这里进入首页</a>。";
  $delinstall=unlink("install.php");
  if ($delinstall==1){
  echo "install.php文件已被删除！";}
  else {
  echo "install.php文件无法删除，为了安全请用FTP工具删除之！";}
}else{
echo "有错误发生！";}
?>
<? } exit;?>