<?php
defined('PHP168_PATH') or die();

/**
* 添加模型
**/
$mysites = $this_system->get_manage_sites();
$alias = html_entities(isset($_GET['alias'])?$_GET['alias']:$_POST['alias']);
in_array($alias,$mysites) || $this_controller->check_admin_action($ACTION) or message('no_privilege');

if(REQUEST_METHOD == 'GET'){
	$alias = html_entities($_GET['alias']);
	$data = $this_module->get_site($alias);
    $data['config'] = mb_unserialize($data['config']);
	$templates = $this_module->get_sites_templates();
	include template($this_module, 'edit', 'admin');
	
}else if(REQUEST_METHOD == 'POST'){
	//如果魔法引号开启strip掉
	$_POST = p8_stripslashes2($_POST);
	$countsites = $DB_master->fetch_one("select count(*) as count from ".$this_module->table." where `status`=1");
	var_dump($countsites);
	//允许启用的站点数量
	$allow_sites_num = 100;
	if($_POST['status']==1 && intval($countsites['count'])>=$allow_sites_num){
		message(p8lang($P8LANG['add_sites_fail'], $allow_sites_num));
	}
	$this_controller->update($_POST) or message('fail');
	$this_system->log(array(
		'title' => $P8LANG['_module_update_admin_log'],
		'request' => $_POST,
	));
	message('done',$this_router.'-list');
}
