<?php
class ControllerCommonColumnLeft extends Controller {
	public function index() {
		if (isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
			$this->load->language('common/column_left');

			// Create a 3 level menu array
			// Level 2 can not have children

			// Menu
			$data['menus'][] = array(
				'id'       => 'menu-dashboard',
				'icon'	   => 'fa-dashboard',
				'name'	   => $this->language->get('text_dashboard'),
				'href'     => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
				'children' => array()
			);

		    // Reward
			if ($this->user->hasPermission('access', 'reward/tier')){	
				$reward[] = array(
					'name'	   => $this->language->get('text_tier'),
					'href'     => $this->url->link('reward/tier', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
		   	}

			if ($this->user->hasPermission('access', 'reward/reward')) {
				$reward[] = array(
					'name'	   => $this->language->get('text_reward_settings'),
					'href'     => $this->url->link('reward/reward', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'reward/reward_promotion')) {
				$reward[] = array(
					'name'	   => $this->language->get('text_reward_promotion_settings'),
					'href'     => $this->url->link('reward/reward_promotion', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			$data['menus'][] = array(
				'id'       => 'menu-reward',
				'icon'	   => 'fa-gift',
				'name'	   => $this->language->get('text_reward'),
				'href'     => '',
				'children' => $reward
			);

			// Member
			if ($this->user->hasPermission('access', 'member/member')){	
				$member[] = array(
					'name'	   => $this->language->get('text_member'),
					'href'     => $this->url->link('member/member', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
		   }

		   if ($this->user->hasPermission('access', 'member/reward')){	
				$member[] = array(
					'name'	   => $this->language->get('text_reward'),
					'href'     => $this->url->link('member/reward', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
	   		}

			if ($this->user->hasPermission('access', 'member/point')){	
				$member[] = array(
					'name'	   => $this->language->get('text_point'),
					'href'     => $this->url->link('member/point', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
	   		}

		   if (isset($member)) {
			$data['menus'][] = array(
				'id'       => 'menu-member',
				'icon'	   => 'fa-user',
				'name'	   => $this->language->get('text_member'),
				'href'     => '',
				'children' => $member
			);
			}

			// Users
			$user = array();

			if ($this->user->hasPermission('access', 'user/user')) {
				$user[] = array(
					'name'	   => $this->language->get('text_users'),
					'href'     => $this->url->link('user/user', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'user/user_permission')) {
				$user[] = array(
					'name'	   => $this->language->get('text_user_group'),
					'href'     => $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($user) {
				$system[] = array(
					'name'	   => $this->language->get('text_users'),
					'href'     => '',
					'children' => $user
				);
			}

			// Tools
			$maintenance = array();

			if ($this->user->hasPermission('access', 'tool/upgrade')) {
				$maintenance[] = array(
					'name'	   => $this->language->get('text_upgrade'),
					'href'     => $this->url->link('tool/upgrade', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'tool/backup')) {
				$maintenance[] = array(
					'name'	   => $this->language->get('text_backup'),
					'href'     => $this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'tool/upload')) {
				$maintenance[] = array(
					'name'	   => $this->language->get('text_upload'),
					'href'     => $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($this->user->hasPermission('access', 'tool/log')) {
				$maintenance[] = array(
					'name'	   => $this->language->get('text_log'),
					'href'     => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token'], true),
					'children' => array()
				);
			}

			if ($maintenance) {
				$system[] = array(
					'id'       => 'menu-maintenance',
					'icon'	   => 'fa-cog',
					'name'	   => $this->language->get('text_maintenance'),
					'href'     => '',
					'children' => $maintenance
				);
			}

			if ($system) {
				$data['menus'][] = array(
					'id'       => 'menu-system',
					'icon'	   => 'fa-cog',
					'name'	   => $this->language->get('text_system'),
					'href'     => '',
					'children' => $system
				);

			return $this->load->view('common/column_left', $data);
			}
		}
	}
}
