<?php
namespace DynCom\mysyde\common\classes;
/**
 * Class Adminmenu
 * @package DynCom\mysyde\common\classes
 */
class Adminmenu {

    private static $adminMenu = NULL;

    /**
     * Adminmenu constructor.
     */
    private function __construct() {
    }

    /**
     * @param int $_active
     * @return array|null
     */
    public static function get($_active = 0 ) {
        if (self::$adminMenu === NULL) {
            $translation = \DynCom\mysyde\common\classes\Registry::get('translation');

            self::$adminMenu = array(

                'default'     => array(
                    'name'         => $translation->get('top_structure'),
                    'include'      => CMS_PATH . "admin/dashboard_structure.php",
                    'linklistmenu' => FALSE,
                ),

                // kollektionen
                'collections' => array(
                    'name'         => $translation->get('top_collections'),
                    'include'      => MODULE_PATH . "collection/dashboard_collections.php",
                    'linklistmenu' => FALSE
                ),

                // dashboard
                'dashboard' => array(
                    'name'         => $translation->get('top_dashboard'),
                    'include'      => CMS_PATH . "admin/dashboard_startpage.php",
                    'linklistmenu' => FALSE
                ),

                // Struktur
                'structure'   => array(
                    'name'         => $translation->get('top_structure'),
                    'include'      => CMS_PATH . "admin/dashboard_structure.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(

                        'sites'      => array(
                            'name'         => $translation->get('left_sites'),
                            'include'      => CMS_PATH . "admin/edit_page.inc.php",
                            'linklistmenu' => TRUE,
                            'icon'         => 'seiten.png'
                        ),

                        'navigation' => array(
                            'name'         => $translation->get('left_navigation'),
                            'include'      => CMS_PATH . "admin/edit_main_navigation.inc.php",
                            'linklistmenu' => TRUE,
                            'icon'         => 'navigation.png'
                        ),

                        'files'      => array(
                            'name'         => $translation->get('left_files'),
                            'include'      => CMS_PATH . "admin/filegallery.inc.php",
                            'linklistmenu' => TRUE,
                            'icon'         => 'dateien.png'
                        ),
                        'video_uploud'      => array(
                            'name'         => $translation->get('video_uploud'),
                            'include'      => CMS_PATH . "admin/video_uploud/video_uploud.inc.php",
                            'linklistmenu' => TRUE,
                            'icon'         => 'dateien.png'
                        ),
                        'components' => array(
                            'name'         => $translation->get('left_components'),
                            'include'      => CMS_PATH . "admin/edit_component.inc.php",
                            'linklistmenu' => TRUE,
                            'icon'         => 'bausteine.png'
                        ),
                    )
                ),

                // inhalte
                'contents'    => array(
                    'name'         => $translation->get('top_contents'),
                    'include'      => CMS_PATH . "admin/dashboard_contents.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(
                        'textcontent'  => array(
                            'name'                  => $translation->get('left_text'),
                            'include'               => MODULE_PATH . "textcontent/textcontent.php",
                            'admin_start_parameter' => "textcontent_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'slideshow'    => array(
                            'name'                  => $translation->get('left_slideshows'),
                            'include'               => MODULE_PATH . "slideshow/slideshow.php",
                            'admin_start_parameter' => "slideshow_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'multistep_forms'  => array(
                            'name'                  => $translation->get('left_multistep_contactforms'),
                            'include'               => MODULE_PATH . "contactform/contactform.php",
                            'admin_start_parameter' => "multi_contactform_edit",
                            'linklistmenu'          => TRUE 
                        ),

                        'slidecontent' => array(
                            'name'                  => $translation->get('left_slidecontent'),
                            'include'               => MODULE_PATH . "slidecontent/slidecontent.php",
                            'admin_start_parameter' => "slidecontent_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'filegallery'  => array(
                            'name'                  => $translation->get('left_filecontent'),
                            'include'               => MODULE_PATH . "filegallery/filegallery.php",
                            'admin_start_parameter' => "filegallery_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'gallery'      => array(
                            'name'                  => $translation->get('left_imagegallery'),
                            'include'               => MODULE_PATH . "gallery/gallery.php",
                            'admin_start_parameter' => "gallery_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'magicscroll'  => array(
                            'name'                  => $translation->get('left_scrollbars'),
                            'include'               => MODULE_PATH . "magicscroll/magicscroll.php",
                            'admin_start_parameter' => "magicscroll_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'googlemaps'   => array(
                            'name'                  => $translation->get('left_googlemaps'),
                            'include'               => MODULE_PATH . "googlemaps/googlemaps.php",
                            'admin_start_parameter' => "googlemaps_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'facebook'     => array(
                            'name'                  => $translation->get('left_facebook'),
                            'include'               => MODULE_PATH . "facebook/facebook.php",
                            'admin_start_parameter' => "facebook_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'youtube'      => array(
                            'name'                  => $translation->get('left_youtube'),
                            'include'               => MODULE_PATH . "youtube/youtube.php",
                            'admin_start_parameter' => "youtube_edit",
                            'linklistmenu'          => TRUE
                        ),

                        'iframe'       => array(
                            'name'                  => $translation->get('left_extern'),
                            'include'               => MODULE_PATH . "iframe/iframe.php",
                            'admin_start_parameter' => "iframe_edit",
                            'linklistmenu'          => TRUE
                        ),

                    )
                ),

                // Statistik
                'statistics'  => array(
                    'name'         => $translation->get('top_statistic'),
                    'include'      => CMS_PATH . "admin/statistic.inc.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(
                        'mail_stat'   => array(
                            'name'         => $translation->get('left_mail_stat'),
                            'include'      => CMS_PATH . "admin/mail_log.inc.php",
                            'linklistmenu' => TRUE
                        ),

                        'access_stat' => array(
                            'name'         => $translation->get('left_access_stat'),
                            'include'      => CMS_PATH . "admin/statistic_access.inc.php",
                            'linklistmenu' => TRUE
                        )
                    )
                ),

                // MODULE
                'module'  => array(
                    'name'         => $translation->get('top_module'),
                    'include'      => CMS_PATH . "admin/module.inc.php",
                    'linklistmenu' => FALSE
                ),

                //FAQ
                'faq' => array(
                    'name'         => $translation->get('top_faq'),
                    'include'      => MODULE_PATH . "faq/dashboard_faq.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(
                    
                        'faq_main'      => array(
                            'name'         => $translation->get('left_faq'),
                            'include'               => MODULE_PATH . "faq/faq.php",
                            'admin_start_parameter' => "faq_edit",
                            'linklistmenu' => TRUE
                        ),
                    
                        'config'      => array(
                            'name'         => $translation->get('left_faq_config'),
                            'include'               => MODULE_PATH . "faq/faq.php",
                            'admin_start_parameter' => "faq_edit_setup",
                            'linklistmenu' => TRUE
                        )
                    )
                ),

                // Contactform
                'contactform'  => array(
                    'name'                  => $translation->get('left_contactforms'),
                    'include'               => MODULE_PATH . "contactform/contactform.php",
                    'admin_start_parameter' => "contactform_edit",
                    'linklistmenu'          => TRUE
                ),

                //Photo Approve
                'photo_approve'  => array(
                    'name'                  => $translation->get('photo_approve'),
                    'include'               => MODULE_PATH . "photo_approve/photo_approve.inc.php",
                    'admin_start_parameter' => "photo_approve",
                    'linklistmenu'          => TRUE
                ),

                                // Ticketcenter
                 'ticketcenter'   => array(
                    'name'         => $translation->get('left_tickets'),
                    'include'      => MODULE_PATH . "ticketcenter/ticketcenter.inc.php",
                    'linklistmenu' => TRUE,
                    'subsites'     => array(
                        // 'settings'      => array(
                        //     'name'         => $translation->get('Einstelungen'),
                        //     'include'               => MODULE_PATH . "ticketcenter/views/settings/settings.inc.php",
                        //     'admin_start_parameter' => "",
                        //     'linklistmenu' => TRUE
                        // ),
                        'category'      => array(
                            'name'         => $translation->get('category'),
                            'include'               => MODULE_PATH . "ticketcenter/views/category/category.inc.php",
                            'admin_start_parameter' => "",
                            'linklistmenu' => TRUE
                        ),
                        'process'      => array(
                            'name'         => $translation->get('Process'),
                            'include'               => MODULE_PATH . "ticketcenter/views/process/process.inc.php",
                            'admin_start_parameter' => "",
                            'linklistmenu' => TRUE
                        ),
                        'status'      => array(
                            'name'         => $translation->get('Status'),
                            'include'               => MODULE_PATH . "ticketcenter/views/status/status.inc.php",
                            'admin_start_parameter' => "",
                            'linklistmenu' => TRUE
                        )
                    )
                ),

                // Bewerbermanagement
                'bewerber'  => array(
                    'name'         => $translation->get('top_bewerbermanagement'),
                    'include'      => MODULE_PATH . "bewerber/user/bewerber.php",
                    'linklistmenu' => FALSE,
                    'admin_start_parameter' => "bewerber_edit",
                    'subsites'     => array(
                        'bewerbung'   => array(
                            'name'         => $translation->get('left_bewerbung'),
                            'include'      => MODULE_PATH . "bewerber/user/bewerber.php",
                            'linklistmenu' => TRUE,
                            'admin_start_parameter' => "bewerbung_edit",
                        ),
                        'stufe'   => array(
                            'name'         => $translation->get('left_stufe'),
                            'include'      => MODULE_PATH . "bewerber/stufe.php",
                            'linklistmenu' => TRUE,
                            'admin_start_parameter' => "stufe_edit",
                        ),
                        'process'   => array(
                            'name'         => $translation->get('left_process'),
                            'include'      => MODULE_PATH . "bewerber/process/process.php",
                            'linklistmenu' => TRUE,
                            'admin_start_parameter' => "process_edit",
                        ),
                    )
                ),

                // Knowledgecenter
                'knowledge'  => array(
                    'name'         => $translation->get('top_knowledgecenter'),
                    'include'      => MODULE_PATH . "knowledgecenter/dashboard_knowledge.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(
                        'category'       => array(
                            'name'         => $translation->get('top_knowledge_category'),
                            'include'      => MODULE_PATH . "knowledgecenter/knowledge.inc.php",
                            'linklistmenu' => TRUE
                        )
                    )
                ),

                
                // E-Learning
                'learning'  => array(
                    'name'         => $translation->get('top_learning'),
                    'include'      => MODULE_PATH . "learning/dashboard_learning.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(
                        'category'       => array(
                            'name'         => $translation->get('learning_category'),
                            'include'      => MODULE_PATH . "learning/learning.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'unit'       => array(
                            'name'         => $translation->get('learning_unit'),
                            'include'      => MODULE_PATH . "learning/learning_unit.inc.php",
                            'linklistmenu' => TRUE
                        )
                    )
                ),

                // Zertifikate
                'certificate'  => array(
                    'name'         => $translation->get('top_certificate'),
                    'include'      => MODULE_PATH . "certificate/certificate.inc.php",
                    'linklistmenu' => TRUE
                ),

                // Community Board
                'community_board'  => array(
                    'name'         => $translation->get('top_community_board'),
                    'include'      => MODULE_PATH . "knwoledgecenter/dashboard_knowledge.php",
                    'linklistmenu' => FALSE,
                    'subsites'     => array(
                        'community_board_post'       => array(
                            'name'         => $translation->get('community_board_post'),
                            'include'      => MODULE_PATH . "community_board/community_board_post.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'community_board_category'       => array(
                            'name'         => $translation->get('community_board_category'),
                            'include'      => MODULE_PATH . "community_board/community_board_category.inc.php",
                            'linklistmenu' => TRUE
                        )
                    )
                ),


                // Infoboard
                'infoboard'  => array(
                    'name'         => $translation->get('top_infoboard'),
                    'include'      => MODULE_PATH . "infoboard/infoboard.inc.php",
                    'linklistmenu' => TRUE
                ),

                // Essenslieferung
                'meal_delivery'  => array(
                    'name'         => $translation->get('top_meal_delivery'),
                    'include'      => MODULE_PATH . "intranet/meal_delivery_listform.inc.php",
                    'linklistmenu' => TRUE
                ),

                // Infopoint
                'infopoint'   => array(
                    'name'         => $translation->get('left_infopoint'),
                    'include'      => MODULE_PATH . "infopoint/dashboard_infopoint.php",
                    'linklistmenu' => TRUE,
                    'subsites'     => array(
                        'pages'      => array(
                            'name'         => $translation->get('infopoint_pages'), 
                            'include'               => MODULE_PATH . "infopoint/infopoint.php",
                            'admin_start_parameter' => "infopoint_pages",
                            'linklistmenu' => TRUE
                        ),
                    
                        'screens'      => array(
                            'name'         => $translation->get('infopoint_screens'),
                            'include'               => MODULE_PATH . "infopoint/infopoint.php",
                            'admin_start_parameter' => "infopoint_screens",
                            'linklistmenu' => TRUE
                        ),
                
                        'presets'      => array(
                            'name'         => $translation->get('infopoint_presets'),
                            'include'               => MODULE_PATH . "infopoint/infopoint.php",
                            'admin_start_parameter' => "infopoint_presets",
                            'linklistmenu' => TRUE
                        ),
                    )
                ),

                // Intranet
                'intranet'  => array(
                    'name'         => $translation->get('top_intranet'),
                    'subsites'     => array(
                        'config_contact'       => array(
                            'name'         => $translation->get('top_contact'),
                            'include'      => INTRANET_PATH . "admin/edit_contact.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_mandant'       => array(
                            'name'         => $translation->get('top_mandant'),
                            'include'      => INTRANET_PATH . "admin/edit_mandant.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_department'       => array(
                            'name'         => $translation->get('top_department'),
                            'include'      => INTRANET_PATH . "admin/edit_department.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_space'       => array(
                            'name'         => $translation->get('top_space'),
                            'include'      => INTRANET_PATH . "admin/edit_space.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_role'       => array(
                            'name'         => $translation->get('top_role'),
                            'include'      => INTRANET_PATH . "admin/edit_role.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_facility'       => array(
                            'name'         => $translation->get('top_role'),
                            'include'      => INTRANET_PATH . "admin/edit_facility.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_permission'       => array(
                            'name'         => $translation->get('top_permission'),
                            'include'      => INTRANET_PATH . "admin/edit_permission.inc.php",
                            'linklistmenu' => TRUE
                        )
                    )
                ),

                // Konfiguration
                'config'      => array(
                    'name'     => '<img src="/layout/admin/img/2015/settings.png" />',
                    'subsites' => array(
                        'config_websites'    => array(
                            'name'         => $translation->get('top_websites'),
                            'include'      => CMS_PATH . "admin/edit_site.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_language'    => array(
                            'name'    => $translation->get('top_languages'),
                            'include' => CMS_PATH . "admin/edit_language.inc.php",
                        ),
                        'config_users'       => array(
                            'name'         => $translation->get('top_users'),
                            'include'      => CMS_PATH . "admin/edit_admin_user.inc.php",
                            'linklistmenu' => FALSE
                        ),
                        'config_layouts'     => array(
                            'name'         => $translation->get('top_layouts'),
                            'include'      => CMS_PATH . "admin/edit_layout.inc.php",
                            'linklistmenu' => TRUE
                        ),
                        'log'     => array(
                            'name'         => $translation->get('top_log'),
                            'include'      => CMS_PATH . "admin/mysyde_log.php",
                            'linklistmenu' => TRUE
                        ),
                        'config_collections' => array(
                            'name'                  => $translation->get('top_collections'),
                            'include'               => MODULE_PATH . "collection/collection.php",
                            'admin_start_parameter' => "collection_edit_setup",
                            'linklistmenu'          => TRUE
                        ),
                        'config_geoip' => array(
                            'name'                  => $translation->get('geoip'),
                            'include'               => CMS_PATH . "admin/ip_geo_location.inc.php",
                        ),
                        'config_url_management' => array(
                            'name'                  => $translation->get('url_management'),
                            'include'               => CMS_PATH . "admin/edit_url_management.inc.php",
                        ),
                        'config_google_recaptcha' => array(
                            'name'                  => $translation->get('recaptcha'),
                            'include'               => CMS_PATH . "admin/recaptcha.php",
                        ),
                        'sitemap'  => array(
                            'name'         => $translation->get('sitemap'),
                            'include'      => MODULE_PATH . "sitemap/sitemap.inc.php",
                            'linklistmenu' => FALSE,
                            'admin_start_parameter' => "sitemap_edit",
                            
                        ),
                    )
                ),

                // Hilfe
                'help'        => array(
                    'name'     => '<img src="/layout/admin/img/2015/help.png" />',
                    'subsites' => array(
                        'help_license'    => array(
                            'name'         => $translation->get('top_license'),
                            'include'      => CMS_PATH . "admin/licence.inc.php",
                            'linklistmenu' => FALSE
                        ),

                        'help_systeminfo' => array(
                            'name'         => $translation->get('top_systeminfo'),
                            'include'      => CMS_PATH . "admin/phpinfo.php",
                            'linklistmenu' => FALSE
                        ),

                        'help_help'       => array(
                            'name'         => $translation->get('top_help'),
                            'include'      => CMS_PATH . "admin/help.php",
                            'linklistmenu' => FALSE
                        ),
                    )
                )

            );
        }

        if ($GLOBALS['admin_user']['right_create_user'] == 1 | $GLOBALS['admin_user']['is_super_user'] == 1) {
            self::$adminMenu['config']['subsites']['config_users']['linklistmenu'] = TRUE;
        }

        // kollektionsmenu
        self::create_collections_menu();

        // Shopmenu
        self::create_shop_menu();


        return self::$adminMenu;
    }

    protected static function create_collections_menu() {
        $query  = "SELECT * FROM main_collection_setup WHERE (main_language_id = " . (int)$GLOBALS["language"]['id'] . " OR all_languages = 1)";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 0) {
            return;
        }

        self::$adminMenu['collections']['subsites'] = array();
        while ($row = @mysqli_fetch_array($result)) {
            self::$adminMenu['collections']['subsites'][$row['id']] = array(
                'name'                  => $row['description'],
                'include'               => MODULE_PATH . "collection/collection.php",
                'admin_start_parameter' => "collection_edit",
                'linklistmenu'          => TRUE
            );
        }
        $query  = "SELECT ms.id, ms.main_language_id, ms.code, ms.description, ms.linked, ms.icon, ms.modified_user, ms.modified_date, ms.all_languages, ms.show_filter FROM main_collection_setup as ms INNER JOIN main_collection_setup_websites as mcsw on ms.id = mcsw.main_collection_setup_id WHERE mcsw.main_site_id = ".$GLOBALS['site']['id']." AND ms.is_multidomain = 1";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
  
        while ($row = @mysqli_fetch_array($result)) {
            self::$adminMenu['collections']['subsites'][$row['id']] = array(
                'name'                  => $row['description'],
                'include'               => MODULE_PATH . "collection/collection.php",
                'admin_start_parameter' => "collection_edit",
                'linklistmenu'          => TRUE
            );
        }
    }

    protected static function create_shop_menu() {
        $translation = \DynCom\mysyde\common\classes\Registry::get('translation');

        $query  = "SHOW TABLES LIKE 'shop_shop'";
        $result = @mysqli_query($GLOBALS['mysql_con'], $query);
        if (@mysqli_num_rows($result) == 0) {
            return;                                //---> Shop nicht vorhanden
        }

        self::$adminMenu['statistics']['subsites']["order_stat"] = array(
            'name'         => $translation->get('left_order_stat'),
            'include'      => CMS_PATH . "admin/order_statistic.inc.php",
            'linklistmenu' => TRUE
        );

        self::$adminMenu['statistics']['subsites']["search_stat"] = array(
            'name'         => $translation->get('left_search_stat'),
            'include'      => CMS_PATH . "admin/search_query_statistic.inc.php",
            'linklistmenu' => TRUE
        );
    }
}
