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

$this_system->check_manager($ACTION) or message('no_privilege');

if(REQUEST_METHOD == 'GET'){
	$MODEL = '';
	$data['model'] = isset($_GET['model']) ? $_GET['model'] : '';
	$data['parent'] = isset($_GET['parent']) ? $_GET['parent'] : 0;
	$data['type']=isset($_GET['type']) ? $_GET['type'] : 2;
	load_language($core, 'config');
	
	$models = $this_system->get_models();
	$core->get_cache('role');
	
	include template($this_module, 'edit', 'admin');
	
}else if(REQUEST_METHOD == 'POST'){
	
	//如果魔法引号开启strip掉
	$_POST = p8_stripslashes2($_POST);
	
	$this_system->check_suv();
	$names = isset($_POST['name']) ? array_filter(array_map('trim', explode("\r\n", $_POST['name']))) : array();
	$item_config = $core->get_config($this_system->name, 'item');
	
	//如果模块配置是静态化,默认就设置分类静态化
	$_POST['htmlize'] = empty($item_config['htmlize']) ? 0 : 1;
	if(!empty($names)){
		//批量添加
		$ids = array();
		ksort($names);
		foreach($names as $name){
			$_POST['name'] = $name;
			$id = $this_controller->add($_POST) or message('fail');
			$ids[$id] = 1;
		}
		
		$this_module->cache(false, true, $ids);
	}
    $this_system->log(array(
		'title' => $P8LANG['_module_add_admin_log'],
		'request' => $_POST,
	));

	if(P8_AJAX_REQUEST){
		exit('<script type="text/javascript">document.domain = \''. $core->CONFIG['base_domain'] .'\';parent.edit_dialog.close();parent.ajaxing({action: \'hide\'});</script>');
	}else{
		message('done', $this_router.'-list');
	}
}
