<?php
defined('IN_PHPCMS') or exit('Access Denied');

$module = 'down';
if(!is_dir(PHPCMS_ROOT.'/'.$module.'/'))
{
	dir_copy(PHPCMS_ROOT.'/module/'.$module.'/copy/', PHPCMS_ROOT.'/'.$module.'/');
}
elseif(!is_writable(PHPCMS_ROOT.'/'.$module.'/config.inc.php'))
{
	showmessage('Please chmod 0777 ./'.$module.'/config.inc.php !');
}

$sql = '';
if($db->version() > '4.1' && $CONFIG['dbcharset'])
{
	$sql = " DEFAULT CHARSET=".$CONFIG['dbcharset'];
}

$db->query("INSERT INTO `".$CONFIG['tablepre']."module` (`name`, `module`, `moduledir`, `moduledomain`, `iscore`, `iscopy`, `isshare`, `version`, `author`, `site`, `email`, `introduce`, `license`, `faq`, `setting`, `disabled`, `publishdate`, `installdate`, `updatedate`) VALUES ('下载', 'down', 'down', '', 0, 1, 0, '1.0.0', 'phpcms团队', 'http://www.phpcms.cn/', 'phpcms@163.com', '下载管理', '', '', 'a:23:{s:4:\"mode\";s:1:\"0\";s:11:\"mirror_file\";s:13:\"phpcms_mirror\";s:8:\"auth_key\";s:6:\"PHPCMS\";s:13:\"local_showurl\";s:1:\"0\";s:14:\"remote_showurl\";s:1:\"1\";s:11:\"thumb_width\";s:3:\"150\";s:12:\"thumb_height\";s:3:\"150\";s:8:\"password\";s:1:\"0\";s:6:\"expire\";s:2:\"15\";s:16:\"enable_guest_add\";s:1:\"1\";s:10:\"check_code\";s:1:\"1\";s:13:\"enable_reword\";s:1:\"0\";s:14:\"enable_keylink\";s:1:\"0\";s:13:\"keywords_show\";s:1:\"1\";s:12:\"keywords_add\";s:1:\"1\";s:11:\"editor_mode\";s:6:\"editor\";s:12:\"editor_width\";s:4:\"100%\";s:13:\"editor_height\";s:3:\"200\";s:6:\"uptype\";s:1:\"1\";s:5:\"upnum\";s:1:\"5\";s:10:\"enable_rss\";s:1:\"1\";s:7:\"rss_num\";s:2:\"50\";s:10:\"rss_length\";s:3:\"200\";}', 0, '0000-00-00', '0000-00-00', '0000-00-00')");

$db->query("INSERT INTO `".$CONFIG['tablepre']."channel` (`module`, `channelname`, `style`, `channelpic`, `introduce`, `seo_title`, `seo_keywords`, `seo_description`, `listorder`, `islink`, `channeldir`, `channeldomain`, `disabled`, `templateid`, `skinid`, `items`, `comments`, `categorys`, `specials`, `hits`, `enablepurview`, `arrgroupid_browse`, `purview_message`, `point_message`, `enablecontribute`, `enablecheck`, `emailofreject`, `emailofpassed`, `enableupload`, `uploaddir`, `maxfilesize`, `uploadfiletype`, `linkurl`, `setting`, `ishtml`, `cat_html_urlruleid`, `item_html_urlruleid`, `special_html_urlruleid`, `cat_php_urlruleid`, `item_php_urlruleid`, `special_php_urlruleid`) VALUES ('down', '下载', '', '', '', '', '', '', 2, 0, 'down', '', 0, '0', '0', 0, 0, 0, 0, 0, 0, '', '<div align=''center'' style=''color:red''>对不起，您没有阅读权限！</div>', '<p align=''center''><span style=''background:#E3E3E3''><a href=''\{\$readurl\}'' class=''read''>此下载需要消耗<font color=''red''>\{\$readpoint\}</font>点，您确认下载吗？</a></span></p><br/>', 1, 1, '退稿时站内短信/Email通知内容：\r\n', '稿件被采用时站内短信/Email通知内容：\r\n', 1, 'uploadfile', 2048000, 'gif|jpg|bmp|png|doc|rar|zip|txt', 'down/', '', 1, 0, 0, 0, 0, 0, 0)");
$channelid = $db->insert_id();

$db->query("DROP TABLE IF EXISTS `".$CONFIG['tablepre']."down_".$channelid."`");
$db->query("CREATE TABLE `".$CONFIG['tablepre']."down_".$channelid."` (  `downid` int(10) unsigned NOT NULL auto_increment,  `catid` smallint(5) unsigned NOT NULL default '0',  `specialid` smallint(5) unsigned NOT NULL default '0',  `typeid` smallint(5) unsigned NOT NULL default '0',  `title` varchar(100) NOT NULL default '',  `style` varchar(50) NOT NULL default '',  `introduce` text NOT NULL,  `keywords` varchar(100) NOT NULL default '',  `author` varchar(50) NOT NULL default '',  `homepage` varchar(255) NOT NULL default '',  `mode` tinyint(1) unsigned NOT NULL default '0',  `downurls` text NOT NULL,  `filesize` varchar(30) NOT NULL default '0',  `hits` int(10) unsigned NOT NULL default '0',  `comments` int(10) unsigned NOT NULL default '0',  `totaldowns` int(10) unsigned NOT NULL default '0',  `todaydowns` int(10) unsigned NOT NULL default '0',  `weekdowns` int(10) unsigned NOT NULL default '0',  `monthdowns` int(10) unsigned NOT NULL default '0',  `thumb` varchar(255) NOT NULL default '',  `username` varchar(20) NOT NULL default '',  `addtime` int(10) unsigned NOT NULL default '0',  `lastdowntime` int(10) NOT NULL default '0',  `editor` varchar(25) NOT NULL default '',  `edittime` int(10) unsigned NOT NULL default '0',  `checker` varchar(25) NOT NULL default '',  `checktime` int(10) unsigned NOT NULL default '0',  `templateid` varchar(20) NOT NULL default '0',  `skinid` varchar(20) NOT NULL default '0',  `stars` tinyint(1) NOT NULL default '0',  `arrposid` varchar(50) NOT NULL default '',  `status` tinyint(1) NOT NULL default '0',  `listorder` smallint(4) unsigned NOT NULL default '0',  `arrgroupidview` varchar(255) NOT NULL default '',  `readpoint` smallint(5) unsigned NOT NULL default '0',  `ishtml` tinyint(1) unsigned NOT NULL default '1',  `htmldir` varchar(20) NOT NULL default '',  `prefix` varchar(50) NOT NULL default '',  `urlruleid` tinyint(3) unsigned NOT NULL default '0',  `islink` tinyint(1) unsigned NOT NULL default '0',  `linkurl` varchar(255) NOT NULL default '',  `my_version` varchar(255) NOT NULL default '',  `my_classtype` varchar(255) NOT NULL default '',  `my_language` varchar(255) NOT NULL default '',  `my_copytype` varchar(255) NOT NULL default '',  `my_system` varchar(255) NOT NULL default '',  `my_demourl` varchar(255) NOT NULL default '',  `my_regurl` varchar(255) NOT NULL default '',  `my_plugin` varchar(255) NOT NULL default '',  PRIMARY KEY  (`downid`),  KEY `catid` (`catid`,`status`,`listorder`,`downid`),  KEY `typeid` (`typeid`,`catid`,`status`,`listorder`,`downid`),  KEY `endtime` (`status`,`arrposid`),  KEY `username` (`username`(10)),  KEY `hits` (`status`,`hits`,`downid`)) TYPE=MyISAM".$sql);

$db->query("DROP TABLE IF EXISTS `".$CONFIG['tablepre']."down_server`");
$db->query("CREATE TABLE `".$CONFIG['tablepre']."down_server` (  `sid` int(10) unsigned NOT NULL auto_increment,  `url` varchar(100) NOT NULL default '',  `name` varchar(30) NOT NULL default '',  `logo` varchar(100) NOT NULL default '',  `showtype` tinyint(1) unsigned NOT NULL default '0',  `islock` tinyint(1) unsigned NOT NULL default '0',  `listorder` smallint(4) unsigned NOT NULL default '0',  PRIMARY KEY  (`sid`)) TYPE=MyISAM".$sql);

$db->query("INSERT INTO `".$CONFIG['tablepre']."field` (`tablename`, `name`, `title`, `note`, `type`, `defaultvalue`, `options`, `enablenull`, `enablesearch`) VALUES ('".$CONFIG['tablepre']."down_".$channelid."', 'my_version', '版本号', '', 'input', '1.0', '', 1, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_classtype', '软件类型', '', 'select', '国产软件', '国产软件\r\n国外软件\r\n汉化补丁\r\n程序源码\r\n其他', 1, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_language', '软件语言', '', 'select', '简体中文', '英文\r\n简体中文\r\n繁体中文\r\n简繁中文\r\n多国语言\r\n其他语言', 0, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_copytype', '软件授权形式', ' 请选择软件授权形式', 'select', '免费版', '免费版\r\n共享版\r\n试用版\r\n演示版\r\n注册版\r\n破解版\r\n零售版\r\nOEM版', 0, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_system', '软件平台', '<br/><script language=\"javascript\" type=\"text/javascript\">\r\n<!--\r\nfunction ToSystem(addTitle)\r\n{\r\n    var str=$(\"my_system\").value;\r\n    var opsys=$(\"my_system\");\r\n    if (opsys.value==\"\")\r\n	{\r\n        opsys.value=opsys.value+addTitle;\r\n    }else\r\n	{\r\n        if (str.substr(str.length-1,1)==\"/\")\r\n		{\r\n            opsys.value=opsys.value+addTitle;\r\n        }else\r\n		{\r\n            opsys.value=opsys.value+\"/\"+addTitle;\r\n        }\r\n    }\r\n    opsys.focus();\r\n}\r\n// -->\r\n</script>\r\n点击添加 <<\r\n<a href=\"javascript:ToSystem(''Windows'')\">Windows</a>/\r\n<a href=\"javascript:ToSystem(''Win98'')\">Win98</a>/\r\n<a href=\"javascript:ToSystem(''NT'')\">WinNT</a>/\r\n<a href=\"javascript:ToSystem(''2000'')\">Win2000</a>/\r\n<a href=\"javascript:ToSystem(''XP'')\">WinXP</a>/\r\n<a href=\"javascript:ToSystem(''2003'')\">Win2003</a>/\r\n<a href=\"javascript:ToSystem(''Unix'')\">Unix</a>/\r\n<a href=\"javascript:ToSystem(''Linux'')\">Linux</a>/\r\n<a href=\"javascript:ToSystem(''MacOS'')\">MacOS</a>', 'input', 'Win2000/WinXP/Win2003', '', 0, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_demourl', '软件演示地址', '', 'input', '', '', 1, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_regurl', '软件注册地址', '', 'input', '', '', 1, 0),('".$CONFIG['tablepre']."down_".$channelid."', 'my_plugin', '插件认证', '', 'select', '无插件', '不详\r\n无插件\r\n可选插件', 1, 0)");

$db->query("INSERT INTO `".$CONFIG['tablepre']."menu` (`position`, `name`, `title`, `url`, `target`, `style`, `listorder`, `arrgroupid`, `arrgrade`, `username`) VALUES ('admin_quick_make', '下载首页', '生成下载首页', '?mod=".$current."&file=createhtml&action=index&channelid=".$channelid."', '_self', '', 1, '1', '', '')");
$db->query("INSERT INTO `".$CONFIG['tablepre']."menu` (`position`, `name`, `title`, `url`, `target`, `style`, `listorder`, `arrgroupid`, `arrgrade`, `username`) VALUES ('admin_quick_make', '下载html', '生成下载栏目，内容html页面', '?mod=".$current."&file=createhtml&channelid=".$channelid."', '_self', '', 5, '1', '', '')");
$db->query("INSERT INTO `".$CONFIG['tablepre']."menu` (`position`, `name`, `title`, `url`, `target`, `style`, `listorder`, `arrgroupid`, `arrgrade`, `username`) VALUES ('admin_quick_add', '添加下载', '下载管理首页', '?mod=".$current."&file=".$current."&action=main&channelid=".$channelid."', '_self', '', 0, '1', '', '')");

$config = "<?php\n\$mod = '$module';\n\$channelid = ".$channelid.";\n?>";
file_put_contents(PHPCMS_ROOT.'/'.$module.'/config.inc.php', $config);
chmod(PHPCMS_ROOT.'/'.$module.'/config.inc.php', 0777);
?>