<?php

/**
 *--------------------------------------
 * 默认模型
 *--------------------------------------
 * @project		: uwa
 * @author		: cblee
 * @created		: 2012-10-11
 * @copyright	: (c)2012 AsThis
 *--------------------------------------
 */

class IndexModl extends Modl
{
	public function get_manageMenu()
	{
		/* 获取档案菜单列表 */
		$_AML = array();
		$_t = M('ArchiveModel')->get_modelList(1, true);
		if(!empty($_t))
		{
			foreach($_t as $am)
			{
				$_AML[] = array(
					'm_name' => $am['am_name'].L('LIST'),
					'm_alias' => 'archive_type_'.$am['am_alias'],
					'm_url' => 'archive/list_archive?archive_model_id='.$am['archive_model_id']
				);
			}
		}
		$_AML[] = array(
			'm_name' => L('SINGLE_PAGE'),
			'm_alias' => 'single_page',
			'm_url' => 'single_page/list_single_page'
		);

		/* 总菜单 */
		$_M = array(
			array(
				'm_name' => L('CONTENT'),
				'm_alias' => 'content',
				'm_sub_key' => 'm_conent',
				'm_sub' => array(
					array(
						'm_group_name' => L('COMMON'),
						'm_alias' => 'common',
						'm_menus' => array(
							array(
								'm_name' => L('ARCHIVE_CHANNEL'),
								'm_alias' => 'archive_channel',
								'm_url' => 'archive_channel/list_channel'
							),
							array(
								'm_name' => L('ALL_ARCHIVE'),
								'm_alias' => 'all_archive',
								'm_url' => 'archive/list_archive'
							),
							array(
								'm_name' => L('NOT_PASSED_ARCHIVE'),
								'm_alias' => 'not_passed_archive',
								'm_url' => 'archive/list_archive?a_status=n'
							),
							array(
								'm_name' => L('MY_ARCHIVE'),
								'm_alias' => 'my_archive',
								'm_url' => 'archive/list_archive?member_id='.ASession::get('member_id')
							),
							array(
								'm_name' => L('ARCHIVE_REVIEW'),
								'm_alias' => 'archive_review',
								'm_url' => 'archive_review/list_review'
							),
						)
					),
					array(
						'm_group_name' => L('CONTENT'),
						'm_alias' => 'content',
						'm_menus' => $_AML
					),
					array(
						'm_group_name' => L('ADVANCE'),
						'm_alias' => 'content_advance',
						'm_menus' => array(
							array(
								'm_name' => L('ARCHIVE_FLAG'),
								'm_alias' => 'archive_flag',
								'm_url' => 'archive_flag/list_flag'
							),
							array(
								'm_name' => L('ARCHIVE_MODEL'),
								'm_alias' => 'archive_model',
								'm_url' => 'archive_model/list_model'
							),
						)
					),
				)
			),
			array(
				'm_name' => L('MEMBER'),
				'm_alias' => 'member',
				'm_sub_key' => 'm_member',
				'm_sub' => array(
					array(
						'm_group_name' => L('MEMBER'),
						'm_alias' => 'member',
						'm_menus' => array(
							array(
								'm_name' => L('MEMBER_LIST'),
								'm_alias' => 'member_list',
								'm_url' => 'member/list_member'
							),
							array(
								'm_name' => L('NOT_PASSED_MEMBER'),
								'm_alias' => 'not_passed_member',
								'm_url' => 'member/list_member?m_status=n'
							),
							array(
								'm_name' => L('MEMBER_NOTIFY'),
								'm_alias' => 'member_notify',
								'm_url' => 'member_notify/list_notify'
							),
							array(
								'm_name' => L('MEMBER_FAVORITE'),
								'm_alias' => 'member_favorite',
								'm_url' => 'member_favorite/list_favorite'
							),
							array(
								'm_name' => L('MEMBER_ORDER'),
								'm_alias' => 'member_order',
								'm_url' => 'member_order/list_order'
							),
						)
					),
					array(
						'm_group_name' => L('ADVANCE'),
						'm_alias' => 'member_advance',
						'm_menus' => array(
							array(
								'm_name' => L('MEMBER_CREDIT_TYPE'),
								'm_alias' => 'member_credit_type',
								'm_url' => 'member_credit_type/list_credit_type'
							),
							array(
								'm_name' => L('MEMBER_LEVEL'),
								'm_alias' => 'member_level',
								'm_url' => 'member_level/list_level'
							),
							array(
								'm_name' => L('MEMBER_MODEL'),
								'm_alias' => 'member_model',
								'm_url' => 'member_model/list_model'
							),
						)
					),
				)
			),
			array(
				'm_name' => L('SYSTEM'),
				'm_alias' => 'system',
				'm_sub_key' => 'm_system',
				'm_sub' => array(
					array(
						'm_group_name' => L('SYSTEM'),
						'm_alias' => 'system',
						'm_menus' => array(
							array(
								'm_name' => L('OPTION'),
								'm_alias' => 'option',
								'm_url' => 'option/edit_option'
							),
							array(
								'm_name' => L('MENU'),
								'm_alias' => 'menu',
								'm_url' => 'menu/list_menu'
							),
						)
					),
					array(
						'm_group_name' => L('ADMIN'),
						'm_alias' => 'admin',
						'm_menus' => array(
							array(
								'm_name' => L('ADMIN'),
								'm_alias' => 'admin',
								'm_url' => 'admin/list_admin'
							),
							array(
								'm_name' => L('ADMIN_ROLE'),
								'm_alias' => 'admin_role',
								'm_url' => 'admin_role/list_role'
							),
							array(
								'm_name' => L('ADMIN_PERMISSION'),
								'm_alias' => 'admin_permission',
								'm_url' => 'admin_permission/list_permission'
							),
							array(
								'm_name' => L('ADMIN_LOG'),
								'm_alias' => 'admin_log',
								'm_url' => 'admin_log/list_log'
							),
						)
					),
				)
			),
			array(
				'm_name' => L('TEMPLATE'),
				'm_alias' => 'template',
				'm_sub_key' => 'm_template',
				'm_sub' => array(
					array(
						'm_group_name' => L('TEMPLATE'),
						'm_alias' => 'template',
						'm_menus' => array(
							array(
								'm_name' => L('TAG_WIZARD'),
								'm_alias' => 'tag_wizard',
								'm_url' => 'template/tag_wizard'
							),
						)
					)
				)
			),
			array(
				'm_name' => L('UPDATE'),
				'm_alias' => 'update',
				'm_sub_key' => 'm_update',
				'm_sub' => array(
					array(
						'm_group_name' => L('UPDATE_CONTENT'),
						'm_alias' => 'update_content',
						'm_menus' => array(
							array(
								'm_name' => L('CLEAR_CACHE'),
								'm_alias' => 'clear_cache',
								'm_url' => 'build/clear_cache'
							),
							array(
								'm_name' => L('UPDATE_ARCHIVE'),
								'm_alias' => 'update_archive',
								'm_url' => 'build/update_archive'
							),
							array(
								'm_name' => L('UPDATE_CHANNEL'),
								'm_alias' => 'update_channel',
								'm_url' => 'build/update_channel'
							),
							array(
								'm_name' => L('UPDATE_INDEX'),
								'm_alias' => 'update_index',
								'm_url' => 'build/update_index_do'
							),
						)
					),
				)
			),
			array(
				'm_name' => L('PLUGIN'),
				'm_alias' => 'plugin',
				'm_sub_key' => 'm_plugin',
				'm_sub' => array(
					array(
						'm_group_name' => L('OTHER'),
						'm_alias' => 'other',
						'm_menus' => array(
							array(
								'm_name' => L('REPORT'),
								'm_alias' => 'report',
								'm_url' => 'report/list_report'
							),
							array(
								'm_name' => L('FILE_EXPLORE'),
								'm_alias' => 'file_explore',
								'm_url' => 'file_explore/list_file'
							),
							array(
								'm_name' => L('AD'),
								'm_alias' => 'ad',
								'm_url' => 'ad_space/list_space'
							),
							array(
								'm_name' => L('GUESTBOOK'),
								'm_alias' => 'guestbook',
								'm_url' => 'guestbook/list_guestbook'
							),
							array(
								'm_name' => L('FLINK'),
								'm_alias' => 'flink',
								'm_url' => 'flink/list_flink'
							),
							array(
								'm_name' => L('UPLOAD'),
								'm_alias' => 'upload',
								'm_url' => 'upload/list_upload'
							),
						)
					)
				)
			)
		);

		/* 所有需检查权限 */
		$allPermission = M('AdminPermission')->get_allPermission();
		$allPermission = explode(',', $allPermission);
		$_all = array();
		foreach($allPermission as $p)
		{
			$_p =explode(':', $p);
			$_all[] = parse_name($_p[0]).'/'.$_p[1];
		}
		/* 拥有权限 */
		$myRole = M('AdminRole')->get_roleInfo(ASession::get('admin_role_id'));
		$myPermission = explode(',', $myRole['ar_permission']);
		$_my = array();
		foreach($myPermission as $p)
		{
			$_p =explode(':', $p);
			$_my[] = parse_name($_p[0]).'/'.$_p[1];
		}
		/* 过滤菜单并生成菜单地址 */
		foreach($_M as $k => $menu)
		{
			foreach($menu['m_sub'] as $k_sub => $m_sub)
			{
				foreach($m_sub['m_menus'] as $k_menu => $m)
				{
					$mUrl = explode('?', $m['m_url']);
					if(!in_array('_all', $myPermission) && in_array($mUrl[0], $_all) && !in_array($mUrl[0], $_my))
					{
						unset($_M[$k]['m_sub'][$k_sub]['m_menus'][$k_menu]);
						continue;
					}
					$_M[$k]['m_sub'][$k_sub]['m_menus'][$k_menu]['m_url'] = Url::U($m['m_url']);
				}
			}
		}

		return $_M;
	}
}

?>