<?php
require('../include/common.php');
get_login($_USER->id);
$step = $_POST['step'];
if($step=='2'){
	global $db;
	$db->query("UPDATE ".DB_TABLEPRE.DB_JT."plugin set type='2',date='".get_date('Y-m-d H:i:s',PHP_TIME)."' WHERE id = '".$_POST['pid']."' ");
	$data = file_get_contents('data/db/mysql.sql');
	$data=str_replace(' toa_', ' toa_'.DB_JT, $data);
	$data = str_replace("\r", "\n", $data);
	$regular = "/;\n/";
	$data = preg_split($regular,trim($data));
	//循环导入数据
	foreach($data as $val){
		mysql_query($val) or die('导入数据失败！' . mysql_error());
	}
	show_msg('办公用品组件模块安装成功！', '../admin.php?ac=plugin&fileurl=mana');
}elseif($step=='1'){
	global $db;
	$db->query("UPDATE ".DB_TABLEPRE.DB_JT."plugin set type='1' WHERE id = '".$_POST['pid']."' ");
	//权限
	$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."keytable WHERE id = 163");
	for($i=170;$i<=175;$i++){
		$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."keytable WHERE id = ".$i."");
	}
	for($i=388;$i<=390;$i++){
		$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."keytable WHERE id = ".$i."");
	}
	//菜单
	for($i=122;$i<=127;$i++){
		$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."menu WHERE menuid = ".$i."");
	}
	$db->query("DELETE FROM ".DB_TABLEPRE.DB_JT."menu WHERE menuid = 72");
	//数据库
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."office_goods");
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."office_goods_key");
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."office_goods_record");
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."office_goods_stock");
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."goods_purchase");
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."goods_purchase_view");
	$db->query("DROP TABLE ".DB_TABLEPRE.DB_JT."goods_type");
	show_msg('办公用品组件模块卸载成功！', '../admin.php?ac=plugin&fileurl=mana');
}else{
	global $db;
	$sql = "SELECT * FROM ".DB_TABLEPRE.DB_JT."plugin  WHERE id = '".$_GET['pid']."'";
	$row = $db->fetch_one_array($sql);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<link rel="stylesheet" type="text/css" href="../template/default/content/css/style.css">
<title>天生创想OA办公系统组件集成安装程序</title>
</head>
<body class="bodycolor">
<table width="60%" border="0" align="center" cellpadding="3" cellspacing="0" class="small" style="margin-top:20px;margin-bottom:10px;">
  <tr>
    <td class="Big"><img src="../template/default/content/images/notify_new.gif" align="absmiddle"><span class="big3"> 办公用品集成组件安装</span>&nbsp;&nbsp;&nbsp;&nbsp;
	<span style="font-size:12px; float:right; margin-right:20px;">
	
	<a href="../admin.php?ac=plugin&fileurl=mana" style="font-size:12px;"><<返回组件列表页</a></span>
    </td>
  </tr>
</table>
<form name="form" method="post" action="install.php">
<input type="hidden" name="pid" value="<?php echo $row['id']?>" />
<table class="TableBlock" border="0" width="60%" align="center">
	<tr>
      <td nowrap class="TableHeader" width="120" style="font-size:16px;">组件名称</td>
      <td class="TableData"><?php echo $row['title']?></td>
    </tr>
	<tr>
      <td nowrap class="TableHeader" width="120" style="font-size:16px;">开发商</td>
      <td class="TableData"><?php echo $row['company']?></td>
    </tr>
	<tr>
      <td nowrap class="TableHeader" width="120" style="font-size:16px;">版本号</td>
      <td class="TableData"><?php echo $row['version']?> </td>
    </tr>
	<tr>
      <td nowrap class="TableHeader" width="120" style="font-size:16px;">描述</td>
      <td class="TableData">暂无</td>
    </tr>
	 <tr>
      <td nowrap class="TableHeader" width="120" style="font-size:16px;"></td>
      <td class="TableData">
	<?php if($_GET['type']=='1'){?>
	<input type="hidden" name="step" value="2" />
	<input type="submit" value="开始安装" class="BigButtonBHover" />
	<?php }else{?>
	<input type="hidden" name="step" value="1" />
	<input type="submit" value="开始卸载" class="BigButtonBHover" />
	<?php }?>
</td>
    </tr>
  </table>
</form>
</body>
</html>