<?
(!defined('M_COM') || !defined('M_ADMIN')) && exit('No Permission');
include_once M_ROOT."./include/subsetup.fun.php";
include_once M_ROOT."./include/fields.fun.php";
aheader();
backallow('subsite') || amessage('no_apermission');
$url_type = 'subsite';include 'urlsarr.inc.php';
url_nav(lang('subsitemanager'),$urlsarr,'setup');
sys_cache('fieldwords');
$subsetupdir = M_ROOT.'./dynamic/subsetup/';
if(!is_dir($subsetupdir) || !is_file($subsetupdir.'setupsids.cac.php') || !is_dir($subsetupdir.'cache/') || !is_dir($subsetupdir.'template/')) amessage('upinssubinidataupl','','dynamic/subsetup/');
//作个初始资料是否合法的分析????????????
$action = empty($action) ? 'subsites' : $action;
$setupsids = oread_cache('setupsids');//记录原始资料包中的子站id--$osid,及要安装成的子站id--$nsid
@extract($setupsids);
$stepeds = oread_cache('stepeds');//记录已经操作的步骤
$stepadds = oread_cache('stepadds');//记录每个步骤中添加的id记录,直接用表名来记录id
$idsmap = oread_cache('idsmap');//记录新旧id的对应关系
$stepsarr = array(//所有需要操作的步骤
'subsites' => lang('newsubset'),
'currencys' => lang('currencytype'),
'mchannels' => lang('mchannel'),
'grouptypes' => lang('grouptype'),
'usergroups' => lang('usergroup'),
'commus' => lang('commuitem'),//包含购买字段及送货方式等设置
'channels' => lang('achannel'),
'altypes' => lang('altype'),
'catalogs' => lang('catalog'),
'cotypes' => lang('cotypem'),
'coclasses' => lang('coclasssetting'),
'cnodes' => lang('catascnode'),//包含节点结构
'fchannels' => lang('affixchannel'),
'fcatalogs' => lang('affixcoclass'),
'freeinfos' => lang('isolutepage'),
'templates' => lang('template'),//包含标识,常规模板,功能模板
);
//显示页面顶部链接
$stepurls = array();
$i = 1;
foreach($stepsarr as $k => $v){
$stepurls[] = "$i ".($k == $action ? "<b>$v</b>" : "<a href=\"?entry=subsetup&action=$k\">$v</a>").(isset($stepeds[$k]) ? 'ok' : '');
$i ++;
}
tabheader(lang('contsubsinst').' >><a href="?entry=subsetup&action=delupload">'.lang('delinupdatandrec').'</a>');
echo "<tr class=\"txt\"><td class=\"txtC\" colspan=\"2\">";
echo tab_list($stepurls,8);
echo "</td></tr>";
tabfooter();
unset($stepurls);
if($action == 'subsites'){
$n_operated = empty($nsid) ? false : true;
load_cache('subsites');
$do_enable = $n_operated ? false : true;
$undo_enable = !$n_operated || isset($stepeds['currencys']) ? false : true;
if(!submitcheck('bdo') && !submitcheck('bundo')){
if(!$n_operated){
$submitstr = '';
tabheader(lang('addconsub'),'subsiteadd',"?entry=subsetup&action=subsites",2,1,1);
trbasic(lang('subsitecname'),'subsitenew[sitename]','','text');
trbasic(lang('subsstadir'),'subsitenew[dirname]','','text');
trbasic(lang('substempldir'),'subsitenew[templatedir]','','text');
$submitstr .= makesubmitstr('subsitenew[sitename]',1,0,0,80);
$submitstr .= makesubmitstr('subsitenew[dirname]',1,'tagtype',0,15);
$submitstr .= makesubmitstr('subsitenew[templatedir]',1,'tagtype',0,15);
tabfooter('bdo',lang('nextstep'));
check_submit_func($submitstr);
}else{
tabheader(lang('addconsub'),'subsiteadd',"?entry=subsetup&action=subsites");
trbasic(lang('subsiteid'),'',$nsid,'');
trbasic(lang('subsitecname'),'',$subsites[$nsid]['sitename'],'');
trbasic(lang('subsstadir'),'',$subsites[$nsid]['dirname'],'');
trbasic(lang('substempldir'),'',$subsites[$nsid]['templatedir'],'');
tabfooter();
echo "<input class=\"button\" type=\"submit\" name=\"bundo\" value=\"".lang('undosetting')."\"".($undo_enable ? '' : ' disabled')."> ";
echo "</form>\n";
}
}elseif(submitcheck('bdo')){
if(!$do_enable) amessage('donrepoper');
$subsitenew['sitename'] = trim(strip_tags($subsitenew['sitename']));
$subsitenew['dirname'] = trim(strip_tags($subsitenew['dirname']));
$subsitenew['templatedir'] = trim(strip_tags($subsitenew['templatedir']));
if(!$subsitenew['sitename'] || !$subsitenew['dirname'] || !$subsitenew['templatedir']) amessage('subdatamiss');
if(preg_match("/[^a-zA-Z_0-9]+/",$subsitenew['dirname'])) amessage('substadirill');
if(preg_match("/[^a-zA-Z_0-9]+/",$subsitenew['templatedir'])) amessage('subtemdirill');
$subsitenew['dirname'] = strtolower($subsitenew['dirname']);
$subsitenew['templatedir'] = strtolower($subsitenew['templatedir']);
if(!mmkdir(M_ROOT.$subsitenew['dirname'],0)) anmessage('nowcresubstadir');
if(!mmkdir(M_ROOT.'template/'.$subsitenew['templatedir'],0)) amessage('nowcresubtemdir');
$db->query("INSERT INTO {$tblprefix}subsites SET
sitename='$subsitenew[sitename]',
dirname='$subsitenew[dirname]',
templatedir='$subsitenew[templatedir]',
ineedstatic='$timestamp'
");
if($nsid = $db->insert_id()){
updatecache('subsites');
$subsites = reload_cache('subsites');
include_once M_ROOT."./include/cparse.fun.php";
cn_blank('','i',$nsid);
$setupsids['nsid'] = $nsid;
ocache2file($setupsids,'setupsids');
$stepeds['subsites'] = 1;
ocache2file($stepeds,'stepeds');
amessage('operatesuc','?entry=subsetup&action=currencys');
}else amessage('subaddfai');
}elseif(submitcheck('bundo')){
if(!$undo_enable) amessage('invoperate');
clear_dir(M_ROOT.'template/'.$subsites[$nsid]['templatedir'],true);
clear_dir(M_ROOT.$subsites[$nsid]['dirname'],true);
$db->query("DELETE FROM {$tblprefix}subsites WHERE sid='$nsid'",'SILENT');
updatecache('subsites');
$setupsids['nsid'] = 0;
ocache2file($setupsids,'setupsids');
unset($stepeds['subsites']);
ocache2file($stepeds,'stepeds');
amessage('undo succeed','?entry=subsetup&action=subsites');
}
}elseif($action == 'currencys'){
load_cache('currencys');
$ocurrencys = oread_cache('currencys','','','cache');
$n_operated = isset($stepeds['currencys']);
$do_enable = $n_operated || !isset($stepeds['subsites']) ? false : true;//如果上一步没有完成,这一步不能开始
$undo_enable = !$n_operated || isset($stepeds['mchannels']) ? false : true;//如果上一步没有撤消,这一步不能撤消
if(!submitcheck('bdo') && !submitcheck('bundo')){
tabheader(lang('currtypetran').' - '.($n_operated ? ' Y' : ' N'),'currencys','?entry=subsetup&action=currencys','3');
trcategory(array(lang('sourceid'),lang('sourcecurrencycname'),lang('tranurrentsys')));
foreach($ocurrencys as $k => $v){
echo "<tr class=\"txt\"><td class=\"txtL\">$k</td>\n".
"<td class=\"txtL\">$v[cname]</td>\n".
"<td class=\"txtL\"><select style=\"vertical-align: middle;\" name=\"currencysnew[$k]\">".makeoption(array(0 => lang('add')) + cridsarr(),empty($idsmap['crids'][$k]) ? 0 : $idsmap['crids'][$k])."</select></td></tr>\n";
}
tabfooter();
echo "<input class=\"button\" type=\"submit\" name=\"bdo\" value=\"".lang('nextstep')."\"".($do_enable ? '' : ' disabled')."> ";
echo "<input class=\"button\" type=\"submit\" name=\"bundo\" value=\"".lang('undosetting')."\"".($undo_enable ? '' : ' disabled')."> ";
echo "</form>\n";
}elseif(submitcheck('bdo')){
if(!$do_enable) amessage('donrepoper');
if(!empty($currencysnew)){
foreach($currencysnew as $k => $v){
if(empty($v)){//新增id
$sqlstr = '';
foreach($ocurrencys[$k] as $key => $val){
!in_array($key,array('crid')) && $sqlstr .= (!$sqlstr ? '' : ',')."$key='".addslashes($val)."'";
}
$db->query("INSERT INTO {$tblprefix}currencys SET $sqlstr");
if(!($crid = $db->insert_id())){
amessage('subsetupcancel');//?????????创建积分不成功,需要将本步当前已进行的操作全部自动撤消
}
$db->query("ALTER TABLE {$tblprefix}members ADD currency$crid int(10) NOT NULL default 0", 'SILENT');
$stepadds['currencys'][] = $crid;//将新加入的crid记录在案
$idsmap['crids'][$k] = $crid;//将新旧id的对应关系记录在案
}else{//将id指定为对应现有id
$idsmap['crids'][$k] = $v;
}
}
//�