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

/**
* 添加模型
**/

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

if(REQUEST_METHOD == 'GET'){
	$menus = $this_module->get_menu($this_system->SITE);
	$templates = $this_module->get_sites_templates();
	include template($this_module, 'menu_edit', 'admin');
	
}else if(REQUEST_METHOD == 'POST'){
	
	isset($_POST['name']) && strlen($_POST['name']) or message('menu_name_can_not_be_empty');
	$name = html_entities($_POST['name']);	
	//有URL的情况数据可以任意,以URL为准
	$url = isset($_POST['url']) ? $_POST['url'] : '';
	$target = isset($_POST['target']) ? $_POST['target'] : '';	
	$parent = isset($_POST['parent']) ? intval($_POST['parent']) : 0;		
	$color = isset($_POST['color']) ? $_POST['color'] : '';	
	$display = isset($_POST['display']) ? intval($_POST['display']) : 0;
	$display_order = isset($_POST['display_order']) ? intval($_POST['display_order']) : 0;	
	$this_module->add_menu(
		array(
			'name' => $name,
			'parent' => $parent,
			'site' => $this_system->SITE,
			'color' => $color,
			'url' => $url,
			'target' => $target,
			'display' => $display,
			'display_order' => $display_order
		)
	) or message('fail');
	$this_system->log(array(
		'title' => $P8LANG['_module_add_menu_admin_log'],
		'request' => $_POST,
	));
	message('done',$this_router.'-menu_list');
}
