<?php
/*插件安装程序*/
define('IN_PHPUP',1);
define('ROOT_PATH',str_replace('plugins/coupon','',str_replace('\\','/',dirname(__FILE__))));
if(is_file(ROOT_PATH.'/plugins/coupon/install.lock'))
{
	exit('请删除plugins/coupon/install.lock后重新安装');
}

include ROOT_PATH.'/inc/common.inc.php';
header("Content-type:text/html;charset=".$GLOBALS['charset']);


$sql[]='CREATE TABLE IF NOT EXISTS '.tname('plugin_coupon').' (  `id` int(11) NOT NULL AUTO_INCREMENT,  `city_name` varchar(32) NOT NULL,  `cityid` varchar(10) NOT NULL,  `title` varchar(100) NOT NULL,  `goods_url` varchar(100) NOT NULL,  `desc` varchar(300) NOT NULL,  `class` tinyint(5) NOT NULL,  `img_url` varchar(100) NOT NULL,  `original_price` float NOT NULL,  `sale_price` float NOT NULL,  `sale_rate` float NOT NULL,  `sales_num` int(5) NOT NULL,  `start_time` int(11) NOT NULL,  `close_time` int(11) NOT NULL,  `merchant_name` varchar(100) NOT NULL,  `merchant_tel` varchar(32) NOT NULL,  `spend_start_time` int(11) NOT NULL,  `spend_close_time` int(11) NOT NULL,  `merchant_addr` varchar(100) NOT NULL,  `hot_area` varchar(100) NOT NULL,  `longitude` varchar(50) NOT NULL,  `latitude` varchar(50) NOT NULL,  `sortorder` int(5) NOT NULL,  PRIMARY KEY (`id`), UNIQUE KEY `title` (`title`)) ENGINE=MyISAM  DEFAULT CHARSET='.$GLOBALS['dbcharset'].';';
$sql[]='CREATE TABLE IF NOT EXISTS '.tname('plugin_coupon_cate').' (  `id` int(5) NOT NULL AUTO_INCREMENT,  `catename` varchar(32) CHARACTER SET '.$GLOBALS['dbcharset'].' NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET='.$GLOBALS['dbcharset'].';';
$plugins=array('title'=>'优惠券','url'=>'coupon','isshow'=>0);
$sql[]='INSERT INTO '.tname('plugins').' (`id`, `pluginsname`, `isok`) VALUES(3, \''.serialize($plugins).'\', 1);';
foreach($sql as $v)
{
	$GLOBALS['db']->query($v);
}
file_put_contents(ROOT_PATH.'/plugins/coupon/install.lock','ok');
exit('<h3><a href="'.SITE_ROOT.'/index.php?pluginid=coupon">优惠券安装成功</a>,请将以下内容添加到plugins/nav.js中</h3><ul><li>t=outlookbar.addtitle(\'优惠券\',\'插件管理\',1)</li><li>
outlookbar.additem(\'优惠券管理\',t,\'index.php?pluginid=coupon&con=admin&act=coupon\')</li><li>
outlookbar.additem(\'优惠券分类\',t,\'index.php?pluginid=coupon&con=admin&act=couponcate\')</li><li>
outlookbar.additem(\'优惠券采集\',t,\'index.php?pluginid=coupon&con=admin&act=couponattach\')</li></ul>');