<?php
define('IN_OUN', true);
include_once( "./includes/command.php");
include_once( ROOT_PATH."includes/item_set.php");
/* 用户注册 */
$Aconf['header_title'] = $Aweb_url['webreg'][0]."|".$Aconf["web_title"];
$Ahome["nowNave"]  = '<A HREF="./">首页</A> > '.$Aweb_url['webreg'][0]; 
if($_POST['action'] == "reg")
{
  $user_name = strtolower($_POST['user_name']);
  if (preg_match('/\'\/^\\s*$|^c:\\\\con\\\\con$|[%,\\*\\"\\s\\t\\<\\>\\&\'\\\\]/', $user_name))
  {
     $strMessage = '注册失败：用户名错误！';
  }
  elseif($user_name == '' && $_POST['password'] == '')
  { 
	$strMessage = '注册失败：用户名或者密码不能为空！';
  }
  elseif($_POST['password'] != $_POST['re_password'])
  {
    $strMessage = '注册失败：两次输入的密码不同！';
  }
  elseif(str_len($user_name) <5 || str_len($user_name) > 26)
  {
	 $strMessage = '注册失败：用户名应该为，5-26个英文字母或数字';
  }
  else
  {
     $strMessage =  '';
  } 

  $db_table = $pre.'admin_user';
  $user_name = clean_html(trim($user_name));
  $password  = md5(trim($_POST['password']));
  $sql = "SELECT user_id FROM ".$db_table." 
	       WHERE `user_name` LIKE '".$user_name."' limit 1";
  $Auser = $oPub->selectrow($sql);
  if($Auser['user_id'] > 0)
  {
  	$strMessage = '注册失败：此用户名已经被使用！';
  }
  $strMessage =  ($strMessage ==  '')?'' :'<A HREF="'.PHP_SELF.'">'.$strMessage.'</a>';

  if($strMessage == '')
  {
     $Afields=array('user_name'=>$user_name,'password'=>$password,'add_time'=>gmtime(),'action_list'=>'all');
     $user_id = $oPub->install($db_table,$Afields);
	 $main_dominMessage = '';
     if($user_id)
	  {
	   //注册配置文件
         $db_table = $pre."sysconfig";	
         if($_POST['main_domin'])
		 {
		     $main_domin = str_replace('http://','', $main_domin);
		     $main_domin = str_replace('https://','',$main_domin);
             if(strpos($_POST['main_domin'],$Aconf['mail_url'] ) ) {
                $main_domin = $user_name.'.'.$Aconf['mail_url'];
			 }else{
				$Atmp = explode(".",$main_domin);
				if(count($Atmp) < 2){
					$main_domin = $user_name.'.'.$Aconf['mail_url'];
				}
			 }

            /*查询 $main_domin 是否被使用 */
            $sql = "SELECT scid FROM ".$db_table." WHERE `main_domin` LIKE '".$main_domin."' limit 1";
            $Asc = $oPub->selectrow($sql);
            if($Asc['scid'] > 0)
            {
  	            $main_dominMessage = $main_domin.' 已经被使用,你可以通过 '.$user_name.'.'.$Aconf['mail_url'] .'访问你的网站';
			    $main_domin = $user_name.'.'.$Aconf['mail_url'];
            }
         }
		 else
		 {
            $main_domin = $user_name.'.'.$Aconf['mail_url'];
		 }

		 $notices = '欢迎光临'.$user_name.'的网站！';

		 $sets='cache_time[|]0{|}logo_w[|]190{|}logo_h[|]58{|}big_thumb_w[|]240{|}big_thumb_h[|]180{|}min_thumb_w[|]90{|}min_thumb_h[|]60{|}rewrite[|]0{|}support[|]0{|}links[|]0{|}title[|]by osunit{|}keywords[|]重庆,行业之星,PHP开源全站系统,全站CMS{|}description[|]欢迎光临！{|}zip[|]400060{|}address[|]*********中富大厦{|}shop_name[|]'.$user_name.'{|}contact[|]'.$user_name.'{|}phone[|]{|}fax[|]{|}tel[|]18623309288{|}email[|]xy58@qq.com{|}msn[|]xufyong@gmail.com{|}qq[|]34226966{|}footer_title[|]版权所有 '.$user_name.'{|}icp[|]渝ICP备07500479号 {|}';

		 $home='one|notices:1,,,公告;descs:1,,,公司简介;articat:1,,,新闻分类;productcat:1,,,商品分类;vote:1,,,推荐调查;]two|articles:1,5,,新闻列表;articles_top:0,6,,置顶新闻;articles_focus:0,20,,焦点新闻;articles_trundle:0,10,,滚动新闻;articles_ifpic:1,20,,新闻图库;articles_comms:1,20,,评论最多的文章;products:1,6,,商品列表;products_top:1,20,,推荐商品;probrand:1,20,,推荐品牌;pravail:1,20,,推荐经销商;votes:1,6,,调查列表;links:1,5,,友情连接列表;]three|acids1:1,2,1,更新日志;';
 
	 	 $Afields=array('user_id'=>$user_id,'user_name'=>$user_name,'main_domin'=>$main_domin,'header_title'=>$user_name,'sets'=>$sets,'home'=>$home,'notices'=>$notices,'template'=>'warped','pre_scid'=>$_SESSION[$un_domain_id]);
         $scid = $oPub->install($db_table,$Afields);
		 if($scid ) {
			 $oPub->query("INSERT INTO " . $pre . "sysconfigfast  (scid,main_domin) VALUES ('$scid','$main_domin')");  
			 $db_table = $pre.'admin_user';
             $Afields=array('domain_id'=>$scid);
	         $condition = 'user_id='.$user_id;
             $oPub->update($db_table,$Afields,$condition);
		     //创建缓存目录
             /* 如果是安全模式，检查目录是否存在 */
			if (!is_dir($base_chache_dir.$scid)) {
				if (@!mkdir($base_chache_dir.$scid, 0777)) {
					$strMessage = '序号为：'.$scid.'的网站目录创建失败.';
				}
			} 
			if (!is_dir($base_compile_dir.$scid)) {
				if (@!mkdir($base_compile_dir.$scid, 0777)) {
					$strMessage = '序号为：'.$scid.'的网站目录创建失败。';
				}
			}
         }
         $_SESSION[$un_auser_id] = $user_id;
		 if($strMessage == '') {
			 /*  增加用户默认导航数据 */
             $db_table = $pre.'nav';
             $sql = "INSERT INTO ".$db_table."(  `name` , `url` , `domain_id` ) 
                     VALUES('内部新闻','articles.php','".$scid."'),  
					 ('商家列表','pravail.php','".$scid."'),
					 ('商品列表','products.php','".$scid."'), 
					 ('关于本站','about.php','".$scid."'),
					 ('访客留言','support.php','".$scid."'),
					 ('友情连接','links.php','".$scid."');";
			 $oPub->query($sql);

             $strMessage = '注册成功：<br/><br/>';
	         $strMessage .= '1.<A HREF="http://'.$user_name.'.'.$Aconf['mail_url'].'/'.$SUBPATH.'admin">填写网站基本资料>></A><br/>';
			 if($main_dominMessage != ''){
                 $strMessage .=  '2.'.$main_dominMessage;
			 }else
			 {
				 $strMessage .= '2.<A HREF="http://'.$user_name.'.'.$Aconf['mail_url'].'/'.$SUBPATH.'">浏览默认网站样式：</A>';
			 }
	         
		  }
	  }
	  else{
		 $strMessage = '<A HREF="http://'.$PHP_SELF.'">注册失败：未知错误，请与管理员联系！>></a>';
	  }
  }else
  {
     $reg_succ = false;
  }
} 
$Ahome[strMessage] = $strMessage;
if ((DEBUG_MODE & 2) != 2) {
    $smarty->caching = true;
}

$str_cache_id = $_SESSION[$un_domain_id]; 
$cache_id = sprintf('%X', crc32($str_cache_id));
if (!$smarty->is_cached($Aconf["displayFile"], $cache_id)) {
	assign_template($Aconf); 
	$smarty->assign('home', $Ahome );  
	unset($Ahome);
    /* 页面中的动态内容 */
    assign_dynamic(str_replace('.html','',$str_templates));
}
$smarty->display($Aconf["displayFile"], $cache_id); 
?>
