<?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');


            // $module_name =  $easy_visibility=$this->config->get('easy_visibility') ? 'Easy Entegre':'Pazaryeri Entegrasyon';

            if (VERSION < 3) {
                $token = $this->session->data['token'];
                $token_link = 'token=' . $this->session->data['token'];
            } else {
                $token = $this->session->data['user_token'];
                $token_link = 'user_token=' . $this->session->data['user_token'];
            }
            $data['token'] = $token;
            $data['token_link'] = $token_link;


            $data['menus'][] = array(
                'id' => 'menu-catalog',
                'icon' => 'fa-tags',
                'name' => 'Dashboard',
                'href' => $this->url->link('entegrasyon/dashboard', $token_link, true),
                'children' => array()
            );
// Catalog
            $catalogum = array();


            if ($this->user->hasPermission('access', 'entegrasyon/product')) {
          

                $catalogum[] = array(
                    'name' => 'Trendyol Ürün Bulucu',
                    'href' => $this->url->link('catalog/product_finder', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );
                $catalogum[] = array(
                    'name' => 'Market Ürünleri',
                    'href' => $this->url->link('catalog/market_product', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );

                /*$catalogum[] = array(
                    'name'	   => 'Toplu Ürün Yükleme',
                    'href'     => $this->url->link('entegrasyon/easyxml', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );
                $catalogum[] = array(
                    'name'	   => 'Kategori Yönetimi',
                    'href'     => $this->url->link('entegrasyon/category', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );*/


                $catalogum[] = array(
                    'name' => 'Marka Yönetimi',
                    'href' => $this->url->link('entegrasyon/manufacturer', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );

            }


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



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

            if ($catalogum) {
                $data['menus'][] = array(
                    'id' => 'menu-catalog',
                    'icon' => 'fa-tags',
                    'name' => 'Katalog İşlemleri',
                    'href' => '',
                    'children' => $catalogum
                );
            }


            $dev = array();


            if ($this->user->hasPermission('access', 'catalog/category')) {
                $dev[] = array(
                    'name' => 'Kategori Yönetimi',
                    'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );

            }

                $dev[] = array(
                    'name' => 'Oto Ürün Yükleyici',
                    'href' => $this->url->link('entegrasyon/setting/auto', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );

            $dev[] = array(
                    'name' => 'Hepsiburada Rapor Yükle',
                    'href' => $this->url->link('extension/module/hb_rapor', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );



            if ($dev) {
                $data['menus'][] = array(
                    'id' => 'menu-catalog',
                    'icon' => 'fa-tags',
                    'name' => 'Developer',
                    'href' => '',
                    'children' => $dev
                );
            }


            $data['menus'][] = array(
                'id' => 'menu-catalog',
                'icon' => 'fa-list',
                'name' => 'Siparişler',
                'href' => $this->url->link('entegrasyon/order', $token_link, true),
                'children' => array()
            );


         //   if ($this->user->hasPermission('access', 'entegrasyon/all_order')) {
                $data['menus'][] = array(
                    'id' => 'menu-catalog',
                    'icon' => 'fa-list',
                    'name' => 'Tüm Siparişler',
                    'href' => $this->url->link('entegrasyon/all_order', $token_link, true),
                    'children' => array()
                );
         //   }


            $data['menus'][] = array(
                'id'       => 'menu-catalog',
                'icon'	   => 'fa-tags',
                'name'	   => 'Ürün Soruları',
                'href'     => $this->url->link('entegrasyon/product_question', $token_link, true),
                'children' => array()
            );


            $data['menus'][] = array(
                'id'       => 'menu-catalog',
                'icon'	   => 'fa-tags',
                'name'	   => 'Destek Talepleri',
                'href'     => $this->url->link('entegrasyon/support', $token_link, true),
                'children' => array()
            );


            // Attributes
            $setting = array();

            if ($this->user->hasPermission('access', 'catalog/attribute')) {
                $setting[] = array(
                    'name'     => 'Pazaryeri Ayarları',
                    'href'     => $this->url->link('entegrasyon/setting', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );
            }

            if ($this->user->hasPermission('access', 'setting/setting')) {
                $setting[] = array(
                    'name'     => 'Para Birimi Ayarları',
                    'href'     => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );
            }

            if ($this->user->hasPermission('access', 'setting/setting')) {
                $setting[] = array(
                    'name'     => 'Vergi Ayarları',
                    'href'     => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );
            }


         $data['menus'][] = array(
                'id'       => 'menu-catalog',
                'icon'	   => 'fa-setting',
             'name'	   => 'Ayarlar',
             'href'     => $this->url->link('entegrasyon/setting', $token_link, true),
             'children' => $setting
            );


            // System
            $system = array();

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

            // 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 ($this->user->hasPermission('access', 'user/api')) {
                $user[] = array(
                    'name'	   => $this->language->get('text_api'),
                    'href'     => $this->url->link('user/api', 'user_token=' . $this->session->data['user_token'], true),
                    'children' => array()
                );
            }

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

            // Localisation
            $localisation = array();

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

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

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

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

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

            // Returns
            $return = array();

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

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

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

            if ($return) {
                $localisation[] = array(
                    'name'	   => $this->language->get('text_return'),
                    'href'     => '',
                    'children' => $return
                );
            }

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

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

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

            // Tax
            $tax = array();

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

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

            if ($tax) {
                $localisation[] = array(
                    'name'	   => $this->language->get('text_tax'),
                    'href'     => '',
                    'children' => $tax
                );
            }

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

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

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

            // Tools
            $maintenance = 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
                );
            }

            $report = array();

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

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

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

            $data['menus'][] = array(
                'id'       => 'menu-report',
                'icon'	   => 'fa-bar-chart-o',
                'name'	   => $this->language->get('text_reports'),
                'href'     => '',
                'children' => $report
            );

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