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

/**
* 添加模型
**/

$this_controller->check_admin_action($ACTION) or message('no_privilege');

if(REQUEST_METHOD == 'GET'){
	
	$Role = &$core->load_module('role');
	$Role->cache_role();
	$roles = $Role->roles;
	$alias = $_GET['alias'];
	$role_json = p8_json($roles);
	$managers = array();
	if(!empty($this_system->sites[$alias]['manager'])){
		$uids = $this_system->sites[$alias]['manager'];
		$member = &$core->load_module('member');
		$managers = $core->DB_master->fetch_all("SELECT id,username FROM {$member->table} WHERE id IN ($uids)");
	}
	if(!empty($this_system->sites[$alias]['poster'])){
		$uids = $this_system->sites[$alias]['poster'];
		$member = &$core->load_module('member');
		$poster = $core->DB_master->fetch_all("SELECT id,username FROM {$member->table} WHERE id IN ($uids)");
	}
	$manager_roles = !empty($this_system->sites[$alias]['manager_role'])? explode(',',$this_system->sites[$alias]['manager_role']):array();
			
	include template($this_module, 'acl', 'admin');
	
}else if(REQUEST_METHOD == 'POST'){
	
	$alias =html_entities($_POST['alias']);
	$manager = isset($_POST['manager'])?array_filter($_POST['manager']):array();
	$manager = $manager? implode(',',$manager):'';
	$poster = isset($_POST['poster'])?array_filter($_POST['poster']):array();
	$poster = $poster? implode(',',$poster):'';
	
	$manager_role = isset($_POST['role'])?array_filter($_POST['role']):array();
	$manager_role = $manager_role? implode(',',$manager_role):'';
	
	$this_module->update(
		$alias,
		array('manager'=>$manager,'manager_role'=>$manager_role,'poster'=>$poster)
		
	);
	
	message('done',$this_router.'-list');
}
