Skip to content
Snippets Groups Projects
class_core_tools.php 85.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • SNA's avatar
    SNA committed
    <?php
    /*
    
    *   Copyright 2008-2015 Maarch
    
    SNA's avatar
    SNA committed
    *
    
    *   This file is part of Maarch Framework.
    
    SNA's avatar
    SNA committed
    *
    *   Maarch Framework is free software: you can redistribute it and/or modify
    *   it under the terms of the GNU General Public License as published by
    *   the Free Software Foundation, either version 3 of the License, or
    *   (at your option) any later version.
    *
    *   Maarch Framework is distributed in the hope that it will be useful,
    *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    *   GNU General Public License for more details.
    *
    *   You should have received a copy of the GNU General Public License
    
    *   along with Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
    
    SNA's avatar
    SNA committed
    */
    
    
    /****************************************************************************/
    /*                                                                          */
    /*                                                                          */
    /*               THIS PAGE CAN NOT BE OVERWRITTEN IN A CUSTOM               */
    /*                                                                          */
    /*                                                                          */
    /* **************************************************************************/
    
    
    SNA's avatar
    SNA committed
    /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
     * @defgroup core Framework core
     */
    
    SNA's avatar
    SNA committed
    
    /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
     * @brief   Contains all the functions to load core and modules
     *
     * @file
     *
     * @author  Laurent Giovannoni  <dev@maarch.org>
     * @date $date$
     *
     * @version $Revision$
     * @ingroup core
     */
    
    SNA's avatar
    SNA committed
    
    /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
     * @brief   Contains all the functions to load core and modules
     *
     * <ul>
     * <li>Loads core tables into session</li>
     * <li>Loads modules settings into session</li>
     * <li>Builds the application menu</li>
     *  <li>Management and building the framework</li>
     *  <li>Modules services loading</li>
     *  <li>Execution of the module services </li>
     *</ul>
     *
     * @ingroup core
     */
    
    SNA's avatar
    SNA committed
    class core_tools extends functions
    {
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Load Maarch core configuration into sessions vars from the core/xml/config.xml file.
         */
    
    SNA's avatar
    SNA committed
        public function build_core_config($pathtoxmlcore)
        {
            $xmlconfig = simplexml_load_file($pathtoxmlcore);
    
            // Loads  core tables into session ($_SESSION['tablename'] array)
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            $TABLENAME = $xmlconfig->TABLENAME;
            $_SESSION['tablename']['actions'] = (string) $TABLENAME->actions;
            $_SESSION['tablename']['docservers'] = (string) $TABLENAME->docservers;
            $_SESSION['tablename']['doctypes'] = (string) $TABLENAME->doctypes;
            $_SESSION['tablename']['history'] = (string) $TABLENAME->history;
            $_SESSION['tablename']['security'] = (string) $TABLENAME->security;
            $_SESSION['tablename']['status'] = (string) $TABLENAME->status;
            $_SESSION['tablename']['usergroups'] = (string) $TABLENAME->usergroups;
    
    SNA's avatar
    SNA committed
            $_SESSION['tablename']['usergroup_services'] = (string) $TABLENAME->usergroups_services;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            $_SESSION['tablename']['users'] = (string) $TABLENAME->users;
    
    SNA's avatar
    SNA committed
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Load Maarch modules configuration into sessions vars from modules/module_name/xml/config.xml files.
         *
         * @param $modules array  Enabled modules of the application
         */
        public function load_modules_config($modules, $mode_batch = false)
    
    SNA's avatar
    SNA committed
        {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            require_once 'core/class/class_request.php';
    
    SNA's avatar
    SNA committed
            // Browses enabled modules
    
            for ($i = 0; $i < count($modules); ++$i) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR
                    .$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR
                    .'modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid']
                    .DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR
                    .'config.xml'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $configPath = $_SESSION['config']['corepath'].'custom'
                        .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                        .DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'xml'
                        .DIRECTORY_SEPARATOR.'config.xml';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $configPath = 'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'xml'
                        .DIRECTORY_SEPARATOR.'config.xml';
    
    SNA's avatar
    SNA committed
                }
    
    
                if (file_exists('modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$_SESSION['config']['lang'].'.php')) {
                    include_once 'modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.$_SESSION['config']['lang'].'.php';
                }
    
                if (file_exists($configPath)) {
                    // Reads the config.xml file of the current module
                    $xmlconfig = simplexml_load_file($configPath);
    
                    // Loads into $_SESSION['modules_loaded'] module's informations
                    foreach ($xmlconfig->CONFIG as $CONFIG) {
                        $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['name'] =
                            (string) $CONFIG->name;
                        $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['path'] =
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            'modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid']
                            .DIRECTORY_SEPARATOR;
    
                        $comment = (string) $CONFIG->comment;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        if (!empty($comment) && defined($comment)
                            && constant($comment) != null
    
                        ) {
                            $comment = constant($comment);
                        }
                        $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['comment'] =
                            $comment;
    
    SNA's avatar
    SNA committed
    
    
                        $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['fileprefix'] = (string) $CONFIG->fileprefix;
                        $_SESSION['modules_loaded'][$modules[$i]['moduleid']]['loaded'] = (string) $CONFIG->loaded;
                    }
    
    SNA's avatar
    SNA committed
                }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $_SESSION['config']['corepath'].'custom'
                        .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                        .DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'class'
                        .DIRECTORY_SEPARATOR.'class_modules_tools.php'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $path_module_tools = $_SESSION['config']['corepath'].'custom'
                        .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                        .DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'class'
                        .DIRECTORY_SEPARATOR.'class_modules_tools.php';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $path_module_tools = 'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'class'
                        .DIRECTORY_SEPARATOR.'class_modules_tools.php';
    
                if (file_exists($path_module_tools)) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    require_once $path_module_tools;
                    $modules_tools = new $modules[$i]['moduleid']();
    
    SNA's avatar
    SNA committed
                    //Loads the tables of the module into session
                    $modules_tools->build_modules_tables();
                    //Loads log keywords of the module
                }
    
                foreach ($xmlconfig->KEYWORDS as $keyword) {
    
                    $tmp = (string) $keyword->label;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    if (!empty($tmp) && defined($tmp) && constant($tmp) != null) {
    
                        $tmp = constant($tmp);
    
    SNA's avatar
    SNA committed
                    }
    
    SNA's avatar
    SNA committed
    
    
    SNA's avatar
    SNA committed
                    $id = (string) $keyword->id;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    if (!$this->is_var_in_history_keywords_tab($id)) {
    
                            $_SESSION['history_keywords'],
                            array(
                                'id' => $id,
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                'label' => $tmp,
    
    SNA's avatar
    SNA committed
                    }
                }
            }
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
            if (!$mode_batch) {
    
    SNA's avatar
    SNA committed
                //Loads logs keywords of the actions
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                $db = new Database();
                $stmt = $db->query(
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    'select id, label_action from '
                    .$_SESSION['tablename']['actions']
    
    Giovannoni Laurent's avatar
    Giovannoni Laurent committed
                while ($res = $stmt->fetchObject()) {
    
                        $_SESSION['history_keywords'],
                        array(
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            'id' => 'ACTION#'.$res->id,
                            'label' => $this->show_string($res->label_action),
    
    SNA's avatar
    SNA committed
                }
            }
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Check if the log keyword is known in the apps.
         *
         * @param $id  string Log keyword to check
         *
         * @return bool True if the keyword is found, False otherwise
         */
    
    SNA's avatar
    SNA committed
        public function is_var_in_history_keywords_tab($id)
        {
            $found = false;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            for ($i = 0; $i < count($_SESSION['history_keywords']); ++$i) {
                if ($_SESSION['history_keywords'][$i]['id'] == $id) {
    
    SNA's avatar
    SNA committed
                    $found = $_SESSION['history_keywords'][$i]['label'];
                    break;
                }
            }
    
    SNA's avatar
    SNA committed
            return $found;
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Loads the modules specific vars into session.
         *
         * @param $modules Enabled modules of the application
         */
    
    SNA's avatar
    SNA committed
        public function load_var_session($modules, $userData)
        {
    
            for ($i = 0; $i < count($modules); ++$i) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $_SESSION['config']['corepath'].'custom'
                        .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                        .DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'class'
                        .DIRECTORY_SEPARATOR.'class_modules_tools.php'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $path_module_tools = $_SESSION['config']['corepath'].'custom'
                        .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                        .DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'class'
                        .DIRECTORY_SEPARATOR.'class_modules_tools.php';
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $path_module_tools = 'modules'.DIRECTORY_SEPARATOR
                        .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'class'
                        .DIRECTORY_SEPARATOR.'class_modules_tools.php';
    
    SNA's avatar
    SNA committed
                if (file_exists($path_module_tools)) {
                    require_once $path_module_tools;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $modules_tools = new $modules[$i]['moduleid']();
    
    SNA's avatar
    SNA committed
                    if (method_exists(
                        $modules[$i]['moduleid'], 'load_module_var_session'
                    )
                    ) {
                        $modules_tools->load_module_var_session($userData);
                    }
                }
    
                //$this->show_array($_SESSION['user']['baskets']);
    
    SNA's avatar
    SNA committed
            }
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Loads language variables into session.
         */
    
        public static function load_lang($lang = 'fr', $maarch_directory = '', $maarch_apps = '')
    
    SNA's avatar
    SNA committed
        {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (isset($_SESSION['config']['lang']) && !empty($_SESSION['config']['lang'])) {
    
    SNA's avatar
    SNA committed
                $lang = $_SESSION['config']['lang'];
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (isset($_SESSION['config']['corepath']) && !empty($_SESSION['config']['corepath'])) {
                $maarch_directory = $_SESSION['config']['corepath'];
    
    SNA's avatar
    SNA committed
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (isset($_SESSION['config']['app_id']) && !empty($_SESSION['config']['app_id'])) {
                $maarch_apps = $_SESSION['config']['app_id'];
    
    SNA's avatar
    SNA committed
            }
            //Loading custom lang file if present, this means that language constants are defined in the custom language file before other language files
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (isset($_SESSION['custom_override_id']) && !empty($_SESSION['custom_override_id'])) {
    
    SNA's avatar
    SNA committed
                self::load_lang_custom_override($_SESSION['custom_override_id']);
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
            if (isset($lang) && file_exists($maarch_directory.'apps/maarch_entreprise/lang'.DIRECTORY_SEPARATOR.$lang.'.php')) {
                include $maarch_directory.'apps/maarch_entreprise/lang'.DIRECTORY_SEPARATOR.$lang.'.php';
            } else {
                $_SESSION['error'] = 'Language file missing';
    
    SNA's avatar
    SNA committed
            }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (isset($_SESSION['modules'])) {
    
    SNA's avatar
    SNA committed
                self::load_lang_modules($_SESSION['modules']);
            }
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Loads language variables of each module.
         *
         * @param $modules array Enabled modules of the application
         */
    
        private static function load_lang_modules($modules)
    
    SNA's avatar
    SNA committed
        {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            for ($i = 0; $i < count($modules); ++$i) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                    .DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR
                    .$modules[$i]['moduleid'].DIRECTORY_SEPARATOR
                    .'lang'.DIRECTORY_SEPARATOR
                    .$_SESSION['config']['lang'].'.php';
    
                if (!file_exists($file_path)) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    .DIRECTORY_SEPARATOR.$modules[$i]['moduleid']
                    .DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR
                    .$_SESSION['config']['lang'].'.php';
    
                if (isset($_SESSION['config']['lang']) && file_exists($file_path)) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    include $file_path;
                } elseif ($_SESSION['config']['debug'] === 'true') {
                    $_SESSION['info'] .= 'Language file missing for module : '
                    .$modules[$i]['moduleid'].'<br/>';
    
    SNA's avatar
    SNA committed
                }
            }
        }
    
    
        private static function load_lang_custom_override($custom_id)
    
    SNA's avatar
    SNA committed
        {
            $pathname = $_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$custom_id.DIRECTORY_SEPARATOR.$_SESSION['config']['lang'].'.php';
    
            if (file_exists($pathname)) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                include $pathname;
    
    SNA's avatar
    SNA committed
            }
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Loads application services into session.
         */
    
    SNA's avatar
    SNA committed
        public function load_app_services()
        {
    
    //        $_SESSION['app_services'] = [];
            /*
    
    SNA's avatar
    SNA committed
            // Reads the application config.xml file
            if (file_exists(
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                $_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR
                .$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR.'apps'
                .DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
                .DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'services.xml'
    
    SNA's avatar
    SNA committed
            )
            ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                $path = $_SESSION['config']['corepath'].'custom'
                    .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id']
                    .DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR
                    .$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'xml'
                    .DIRECTORY_SEPARATOR.'services.xml';
    
    SNA's avatar
    SNA committed
            } else {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                $path = 'apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id']
                    .DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR
                    .'services.xml';
    
    SNA's avatar
    SNA committed
            }
            $xmlconfig = simplexml_load_file($path);
            $k = 0;
            $m = 0;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            include_once 'apps/'.$_SESSION['config']['app_id'].'/lang/'.$_SESSION['config']['lang'].'.php';
    
    SNA's avatar
    SNA committed
            // Browses the services in that file and loads $_SESSION['app_services']
            foreach ($xmlconfig->SERVICE as $service) {
                $_SESSION['app_services'][$k] = array();
                $_SESSION['app_services'][$k]['id'] = (string) $service->id;
    
                $name = (string) $service->name;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                if (!empty($name) && defined($name) && constant($name) != null) {
                    $name = constant($name);
    
    SNA's avatar
    SNA committed
                }
    
                $_SESSION['app_services'][$k]['name'] = $name;
                $comment = (string) $service->comment;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                if (!empty($comment) && defined($comment)
                    && constant($comment) != null
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    $comment = constant($comment);
    
    SNA's avatar
    SNA committed
                }
    
                $_SESSION['app_services'][$k]['comment'] = $comment;
    
    SNA's avatar
    SNA committed
                if (isset($service->servicepage)) {
                    $_SESSION['app_services'][$k]['servicepage'] = (string) $service->servicepage;
                    $_SESSION['app_services'][$k]['servicepage'] = preg_replace(
    
                        '/&admin/', '&amp;admin',
    
    SNA's avatar
    SNA committed
                        $_SESSION['app_services'][$k]['servicepage']
                    );
                    $_SESSION['app_services'][$k]['servicepage'] = preg_replace(
    
                        '/&module/', '&amp;module',
    
    SNA's avatar
    SNA committed
                        $_SESSION['app_services'][$k]['servicepage']
                    );
                }
                $_SESSION['app_services'][$k]['servicetype'] = (string) $service->servicetype;
    
                if (isset($service->style)) {
                    $_SESSION['app_services'][$k]['style'] = (string) $service->style;
                }
    
                $systemService = (string) $service->system_service;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                if ($systemService == 'false') {
    
    SNA's avatar
    SNA committed
                    $_SESSION['app_services'][$k]['system_service'] = false;
                } else {
                    $_SESSION['app_services'][$k]['system_service'] = true;
                }
                $_SESSION['app_services'][$k]['enabled'] = (string) $service->enabled;
                $l = 0;
                foreach ($service->WHEREAMIUSED as $whereAmIUsed) {
                    if (isset($whereAmIUsed)) {
                        $_SESSION['app_services'][$k]['whereamiused'][$l]['page'] = (string) $whereAmIUsed->page;
                        $_SESSION['app_services'][$k]['whereamiused'][$l]['nature'] = (string) $whereAmIUsed->nature;
                        if (isset($whereAmIUsed->button_label)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['button_label'] = (string) $whereAmIUsed->button_label;
                        }
                        if (isset($whereAmIUsed->tab_label)) {
    
                            $label = (string) $whereAmIUsed->tab_label;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            if (!empty($label) && defined($label)
                                && constant($label) != null
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                $label = constant($label);
    
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['tab_label'] = $label;
    
    SNA's avatar
    SNA committed
                        }
                        if (isset($whereAmIUsed->tab_order)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['tab_order'] = (string) $whereAmIUsed->tab_order;
                        }
                        if (isset($whereAmIUsed->width)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['width'] = (string) $whereAmIUsed->width;
                        }
                        if (isset($whereAmIUsed->frame_id)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['frame_id'] = (string) $whereAmIUsed->frame_id;
                        }
                        if (isset($whereAmIUsed->height)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['height'] = (string) $whereAmIUsed->height;
                        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        if (isset($whereAmIUsed->scrolling)) {
    
    SNA's avatar
    SNA committed
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['scrolling'] = (string) $whereAmIUsed->scrolling;
                        }
                        if (isset($whereAmIUsed->style)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['style'] = (string) $whereAmIUsed->style;
                        }
                        if (isset($whereAmIUsed->border)) {
                            $_SESSION['app_services'][$k]['whereamiused'][$l]['border'] = (string) $whereAmIUsed->border;
                        }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                        ++$l;
    
    SNA's avatar
    SNA committed
                    }
                }
                $m = 0;
                // Loads preprocess and postprocess
                foreach ($service->PROCESSINBACKGROUND as $processInBackground) {
                    $_SESSION['app_services'][$k]['processinbackground'][$m]['page'] = (string) $processInBackground->page;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    if ((string) $processInBackground->preprocess != '') {
    
    SNA's avatar
    SNA committed
                        $_SESSION['app_services'][$k]['processinbackground'][$m]['preprocess'] = (string) $processInBackground->preprocess;
                    }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    if ((string) $processInBackground->postprocess != '') {
    
    SNA's avatar
    SNA committed
                        $_SESSION['app_services'][$k]['processinbackground'][$m]['postprocess'] = (string) $processInBackground->postprocess;
                    }
                    $_SESSION['app_services'][$k]['processinbackground'][$m]['processorder'] = (string) $processInBackground->processorder;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                    ++$m;
    
    SNA's avatar
    SNA committed
                }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                ++$k;
    
    SNA's avatar
    SNA committed
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Loads the services of each module into session.
         *
         * @param $modules array Enabled modules of the application
         */
    
    SNA's avatar
    SNA committed
        public function load_modules_services($modules)
        {
    
    //        $_SESSION['modules_services'] = [];
            /*
    
    SNA's avatar
    SNA committed
            // Browses the enabled modules array
    
            for ($i = 0; $i < count($modules); ++$i) {
    
    SNA's avatar
    SNA committed
                // Reads the module config.xml file
    
                $path = '';
                $moduleServiceXml = 'modules'.DIRECTORY_SEPARATOR.$modules[$i]['moduleid'].DIRECTORY_SEPARATOR.'xml'.DIRECTORY_SEPARATOR.'services.xml';
    
                    'custom'.DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'].DIRECTORY_SEPARATOR.$moduleServiceXml
    
                    $path = 'custom' .DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR.$moduleServiceXml;
                } elseif (file_exists($moduleServiceXml)) {
                    $path = $moduleServiceXml;
    
    SNA's avatar
    SNA committed
                }
    
                if (!empty($path)) {
                    $xmlconfig = simplexml_load_file($path);
                    $k = 0;
                    $m = 0;
                    foreach ($xmlconfig->SERVICE as $service) {
                        if ((string) $service->enabled == 'true') {
                            $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['id'] = (string) $service->id;
                            $name = (string) $service->name;
                            if (!empty($name) && defined($name)
                                && constant($name) != null
                            ) {
                                $name = constant($name);
    
    SNA's avatar
    SNA committed
                            }
    
                            $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['name'] =
                                $name;
        
                            $comment = (string) $service->comment;
                            if (!empty($comment) && defined($comment)
                                && constant($comment) != null
                            ) {
                                $comment = constant($comment);
    
    SNA's avatar
    SNA committed
                            }
    
                            $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['comment'] =
                                $comment;
        
                            if (isset($service->servicepage)) {
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['servicepage'] = (string) $service->servicepage;
    
    SNA's avatar
    SNA committed
                            }
    
                            $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['servicetype'] = (string) $service->servicetype;
        
                            if (isset($service->style)) {
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['style'] = (string) $service->style;
    
    SNA's avatar
    SNA committed
                            }
    
                            $systemService = (string) $service->system_service;
                            if ($systemService == 'false') {
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['system_service'] = false;
                            } else {
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['system_service'] = true;
    
    SNA's avatar
    SNA committed
                            }
    
                            $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['enabled'] = (string) $service->enabled;
        
                            $l = 0;
                            foreach ($service->WHEREAMIUSED as $whereAmIUsed) {
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['page'] = (string) $whereAmIUsed->page;
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['nature'] = (string) $whereAmIUsed->nature;
                                if (isset($whereAmIUsed->button_label)) {
                                    $label = (string) $whereAmIUsed->button_label;
                                    if (!empty($label) && defined($label)
                                        && constant($label) != null
                                    ) {
                                        $label = constant($label);
                                    }
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['button_label'] =
                                        $label;
                                }
                                if (isset($whereAmIUsed->tab_label)) {
                                    $label = (string) $whereAmIUsed->tab_label;
                                    if (!empty($label) && defined($label)
                                        && constant($label) != null
                                    ) {
                                        $label = constant($label);
                                    }
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['tab_label'] =
                                        $label;
                                }
                                if (isset($whereAmIUsed->tab_order)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['tab_order'] = (string) $whereAmIUsed->tab_order;
                                }
                                if (isset($whereAmIUsed->frame_id)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['frame_id'] = (string) $whereAmIUsed->frame_id;
                                }
                                if (isset($whereAmIUsed->width)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['width'] = (string) $whereAmIUsed->width;
                                }
                                if (isset($whereAmIUsed->height)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['height'] = (string) $whereAmIUsed->height;
                                }
                                if (isset($whereAmIUsed->scrolling)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['scrolling'] = (string) $whereAmIUsed->scrolling;
                                }
                                if (isset($whereAmIUsed->style)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['style'] = (string) $whereAmIUsed->style;
                                }
                                if (isset($whereAmIUsed->border)) {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['whereamiused'][$l]['border'] = (string) $whereAmIUsed->border;
                                }
                                ++$l;
    
    SNA's avatar
    SNA committed
                            }
    
                            $m = 0;
                            foreach ($service->PROCESSINBACKGROUND as $processInBackground) {
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['page'] = (string) $processInBackground->page;
                                if ((string) $processInBackground->preprocess != '') {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['preprocess'] = (string) $processInBackground->preprocess;
                                }
                                if ((string) $processInBackground->postprocess != '') {
                                    $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['postprocess'] = (string) $processInBackground->postprocess;
                                }
                                $_SESSION['modules_services'][$modules[$i]['moduleid']][$k]['processinbackground'][$m]['processorder'] = (string) $processInBackground->processorder;
                                ++$m;
    
    SNA's avatar
    SNA committed
                            }
    
    SNA's avatar
    SNA committed
                        }
                    }
                }
            }
    
    SNA's avatar
    SNA committed
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Executes the module' s services in the page.
         *
         * @param $modules_services  array List of the module's services
         * @param $whereami  string Page where to execute the service
         * @param $servicenature string  Nature of the service (by default, the function takes all the services natures)
         * @param  $id_service string Identifier of one specific service (empty by default)
         * @param  $id_module string Identifier of one specific module (empty by default)
         */
        public function execute_modules_services($modules_services, $whereami, $servicenature = 'all', $id_service = '', $id_module = '')
    
    SNA's avatar
    SNA committed
        {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
            if (!empty($id_service) && !empty($id_module)) {
    
                for ($i = 0; $i < count($modules_services[$id_module]); ++$i) {
    
    SNA's avatar
    SNA committed
                    if ($modules_services[$id_module][$i]['id'] == $id_service
    
                        && isset($modules_services[$id_module][$i]['whereamiused'])
    
    SNA's avatar
    SNA committed
                    ) {
                        for ($k = 0; $k < count(
    
                            $modules_services[$id_module][$i]['whereamiused']
    
    SNA's avatar
    SNA committed
                        ) {
                            $name = $id = $width = $height = $frameborder = $scrolling = $style = '';
                            if ($modules_services[$id_module][$i]['whereamiused'][$k]['page'] == $whereami) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                if ($modules_services[$id_module][$i]['whereamiused'][$k]['nature'] == 'frame'
    
                                    && $_SESSION['user']['services'][$modules_services[$id_module][$i]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    && !in_array(
    
                                        $modules_services[$id_module][$i]['id'],
                                        $executedServices
                                    )
    
    SNA's avatar
    SNA committed
                                ) {
                                    array_push(
    
                                        $executedServices,
                                        $modules_services[$id_module][$i]['id']
    
    SNA's avatar
    SNA committed
                                    );
    
                                    if (isset(
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['frame_id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    ) && !empty(
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['frame_id']
    
    SNA's avatar
    SNA committed
                                    ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                        $name = 'name="'.$modules_services[$id_module][$i]['whereamiused'][$k]['frame_id'].'"';
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['frame_id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    ) && !empty(
    
                                            $modules_services[$id_module][$i]['whereamiused'][$k]['frame_id']
    
    SNA's avatar
    SNA committed
                                    ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                        $id = 'id="'.$modules_services[$id_module][$i]['whereamiused'][$k]['frame_id'].'"';
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['width']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    ) && strlen(
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['width']
    
    SNA's avatar
    SNA committed
                                    ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                        $width = 'width="'.$modules_services[$id_module][$i]['whereamiused'][$k]['width'].'" ';
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['height']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    ) && strlen(
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['height']
    
    SNA's avatar
    SNA committed
                                    ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                        $height = 'height="'.$modules_services[$id_module][$i]['whereamiused'][$k]['height'].'"';
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['border']
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['border']
    
    SNA's avatar
    SNA committed
                                    ) {
    
                                        $frameborder = 'frameborder="'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            .$modules_services[$id_module][$i]['whereamiused'][$k]['border'].'" ';
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['scrolling']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    ) && !empty(
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['scrolling']
    
    SNA's avatar
    SNA committed
                                    ) {
    
                                        $scrolling = 'scrolling="'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            .$modules_services[$id_module][$i]['whereamiused'][$k]['scrolling'].'"';
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['style']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    ) && !empty(
    
                                        $modules_services[$id_module][$i]['whereamiused'][$k]['style']
    
    SNA's avatar
    SNA committed
                                    ) {
    
                                        $style = 'style="'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            .$modules_services[$id_module][$i]['whereamiused'][$k]['style'].'"';
    
    SNA's avatar
    SNA committed
    
    
    SNA's avatar
    SNA committed
                                    $iframeStr = '<iframe src="'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                        .$_SESSION['config']['businessappurl']
                                        .'index.php?display=true&module='
                                        .$id_module.'&page='
                                        .$modules_services[$id_module][$i]['servicepage']
                                        .'" '.$name.' '.$id.' '.$width
                                        .' '.$height.' '.$frameborder.' '
                                        .$scrolling.' '.$style.'></iframe>';
    
    SNA's avatar
    SNA committed
    
    
    SNA's avatar
    SNA committed
                                    //break;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                } elseif ($modules_services[$id_module][$i]['whereamiused'][$k]['nature'] == 'popup'
    
                                    && $_SESSION['user']['services'][$modules_services[$id_module][$i]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    && !in_array(
    
                                        $modules_services[$id_module][$i]['id'], $executedServices
                                    )
    
                                        $executedServices,
                                        $modules_services[$id_module][$i]['id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    echo $modules_services[$id_module][$i]['name']; ?>
    
    SNA's avatar
    SNA committed
                                    <br />
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    <a href='<?php echo $_SESSION['config']['businessappurl'].'index.php?display=true&module='.$id_module.'&page='.$modules_services[$id_module][$i]['servicepage']; ?>' target='_blank'><?php echo _ACCESS_TO_SERVICE; ?></a><br /><br />
    
    SNA's avatar
    SNA committed
                                    <?php
                                    break;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                } elseif ($modules_services[$id_module][$i]['whereamiused'][$k]['nature'] == 'button'
    
                                    && $_SESSION['user']['services'][$modules_services[$id_module][$i]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    && !in_array(
    
                                        $modules_services[$id_module][$i]['id'],
                                        $executedServices
                                    )
    
                                        $executedServices,
                                        $modules_services[$id_module][$i]['id']
    
                                    $tmp = $modules_services[$id_module][$i]['whereamiused'][$k]['button_label'];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    if (!empty($tmp) && defined($tmp)
                                        && constant($tmp) != null
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                        $tmp = constant($tmp);
                                    } ?>
                                    <input type="button" name="<?php functions::xecho($modules_services[$id_module][$i]['id']); ?>" value="<?php functions::xecho($tmp); ?>" onclick="window.open('<?php echo   $_SESSION['config']['businessappurl'].'index.php?display=true&module='.$id_module.'&page='.$modules_services[$id_module][$i]['servicepage']; ?>', '<?php functions::xecho($modules_services[$id_module][$i]['id']); ?>','width=<?php functions::xecho($modules_services[$id_module][$i]['whereamiused'][$k]['width']); ?>,height=<?php functions::xecho($modules_services[$id_module][$i]['whereamiused'][$k]['height']); ?>,scrollbars=yes,resizable=yes' );" class="button" /><br/>
    
    SNA's avatar
    SNA committed
                                    <?php
                                    break;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                } elseif ($modules_services[$id_module][$i]['whereamiused'][$k]['nature'] == 'include'
    
                                    && $_SESSION['user']['services'][$modules_services[$id_module][$i]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    && !in_array(
    
                                        $modules_services[$id_module][$i]['id'],
                                        $executedServices
                                    )
    
                                        $executedServices,
                                        $modules_services[$id_module][$i]['id']
    
    SNA's avatar
    SNA committed
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                    include 'modules'.DIRECTORY_SEPARATOR
                                        .$id_module.DIRECTORY_SEPARATOR
                                        .$modules_services[$id_module][$i]['servicepage'];
    
    SNA's avatar
    SNA committed
                                    break;
                                }
                            }
                        }
                    }
                }
    
    SNA's avatar
    SNA committed
                $tab_view = array();
    
                if (isset($modules_services)) {
                    foreach (array_keys($modules_services) as $value) {
                        if (isset($modules_services[$value])) {
    
                            for ($iService = 0; $iService < count($modules_services[$value]);
    
                                ++$iService
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            ) {
    
                                if (isset($modules_services[$value][$iService])
                                    && isset($modules_services[$value][$iService]['whereamiused'])
                                    && count($modules_services[$value][$iService]['whereamiused']) > 0
    
                                        $modules_services[$value][$iService]['whereamiused']
    
                                            $modules_services[$value][$iService]['whereamiused'][$k]['page']
                                        ) && $modules_services[$value][$iService]['whereamiused'][$k]['page'] == $whereami
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            if ($modules_services[$value][$iService]['whereamiused'][$k]['nature'] == 'frame'
    
                                                && $_SESSION['user']['services'][$modules_services[$value][$iService]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                && ($servicenature == 'all' || $servicenature == 'frame')
                                                && !in_array(
    
                                                    $modules_services[$value][$iService]['id'],
    
                                                    $executedServices,
    
                                                    $modules_services[$value][$iService]['id']
    
    SNA's avatar
    SNA committed
    
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['frame_id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                ) && !empty(
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['frame_id']
    
    SNA's avatar
    SNA committed
                                                ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                        .$modules_services[$value][$iService]['whereamiused'][$k]['frame_id'].'"';
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['frame_id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                ) && !empty(
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['frame_id']
    
    SNA's avatar
    SNA committed
                                                ) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                        .$modules_services[$value][$iService]['whereamiused'][$k]['frame_id'].'"';
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['width']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                ) && strlen(
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['width']
    
    SNA's avatar
    SNA committed
                                                ) {
    
                                                    $width = 'width="'.$modules_services[$value][$iService]['whereamiused'][$k]['width'].'" ';
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['height']
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['height']
    
    SNA's avatar
    SNA committed
                                                ) {
    
                                                    $height = 'height="'.$modules_services[$value][$iService]['whereamiused'][$k]['height'].'"';
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['border']
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['border']
    
    SNA's avatar
    SNA committed
                                                ) {
    
                                                    $frameborder = 'frameborder="'.$modules_services[$value][$iService]['whereamiused'][$k]['border'].'" ';
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['scrolling']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                ) && !empty(
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['scrolling']
    
    SNA's avatar
    SNA committed
                                                ) {
    
                                                    $scrolling = 'scrolling="'.$modules_services[$value][$iService]['whereamiused'][$k]['scrolling'].'"';
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['style']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                ) && !empty(
    
                                                    $modules_services[$value][$iService]['whereamiused'][$k]['style']
    
    SNA's avatar
    SNA committed
                                                ) {
    
                                                    $style = 'style="'.$modules_services[$value][$iService]['whereamiused'][$k]['style'].'"';
    
                                                $iServiceframeStr = '<iframe src="'
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                    .$_SESSION['config']['businessappurl']
                                                    .'index.php?display=true&module='
                                                    .$value.'&page='
                                                    .$modules_services[$value][$iService]['servicepage']
                                                    .'" '.$name.' '.$iServiced.' '
                                                    .$width.' '.$height.' '
                                                    .$frameborder.' '.$scrolling
                                                    .' '.$style.'></iframe>';
    
                                                return $iServiceframeStr;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            } elseif ($modules_services[$value][$iService]['whereamiused'][$k]['nature'] == 'tab'
    
                                                && $_SESSION['user']['services'][$modules_services[$value][$iService]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                && ($servicenature == 'tab')
                                                && !in_array(
    
                                                    $modules_services[$value][$iService]['id'],
    
                                                    $executedServices,
    
                                                    $modules_services[$value][$iService]['id']
    
                                                $arrLabel = $modules_services[$value][$iService]['whereamiused'][$k]['tab_label'];
    
    SNA's avatar
    SNA committed
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                if (!empty($arrLabel)
    
                                                    && defined($arrLabel)
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                    && constant($arrLabel) != null
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                    $arrLabel = constant($arrLabel);
    
                                                $arrOrder = $modules_services[$value][$iService]['whereamiused'][$k]['tab_order'];
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                $frameSrc = $_SESSION['config']['businessappurl'].'index.php?display=true&module='.$value.'&page='.$modules_services[$value][$iService]['servicepage'];
    
                                                $tab_view[$arrOrder]['tab_label'] = $arrLabel;
                                                $tab_view[$arrOrder]['frame_src'] = $frameSrc;
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            } elseif ($modules_services[$value][$iService]['whereamiused'][$k]['nature'] == 'popup'
    
                                                && $_SESSION['user']['services'][$modules_services[$value][$iService]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                && ($servicenature == 'all' || $servicenature == 'popup')
                                                && !in_array(
    
                                                    $modules_services[$value][$iService]['id'],
    
                                                    $executedServices,
    
                                                    $modules_services[$value][$iService]['id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                echo $modules_services[$value][$iService]['name']; ?>
    
    SNA's avatar
    SNA committed
                                                <br />
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                <a href='<?php echo $_SESSION['config']['businessappurl'].'index.php?display=true&module='.$value.'&page='.$modules_services[$value][$iService]['servicepage']; ?>' target='_blank'><?php echo _ACCESS_TO_SERVICE; ?></a><br /><br />
    
    SNA's avatar
    SNA committed
                                                <?php
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            } elseif ($modules_services[$value][$iService]['whereamiused'][$k]['nature'] == 'button'
    
                                                && $_SESSION['user']['services'][$modules_services[$value][$iService]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                && ($servicenature == 'all' || $servicenature == 'button')
                                                && !in_array(
    
                                                    $modules_services[$value][$iService]['id'],
    
                                                    $executedServices,
    
                                                    $modules_services[$value][$iService]['id']
    
                                                $tmp = $modules_services[$value][$iService]['whereamiused'][$k]['button_label'];
    
    SNA's avatar
    SNA committed
    
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                if (!empty($tmp) && defined($tmp)
                                                    && constant($tmp) != null
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                    $tmp = constant($tmp);
                                                } ?>
                                                <input type="button" name="<?php functions::xecho($modules_services[$value][$iService]['id']); ?>" value="<?php functions::xecho($tmp); ?>" onclick="window.open('<?php echo  $_SESSION['config']['businessappurl'].'index.php?display=true&module='.$iServiced_module.'&page='.$modules_services[$iServiced_module][$iService]['servicepage']; ?>', '<?php functions::xecho($modules_services[$value][$iService]['id']); ?>','width=<?php functions::xecho($modules_services[$value][$iService]['whereamiused'][$k]['width']); ?>,height=<?php functions::xecho($modules_services[$value][$iService]['whereamiused'][$k]['height']); ?>,scrollbars=yes,resizable=yes' );" class="button" /><br/>
    
    SNA's avatar
    SNA committed
                                                <?php
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                            } elseif (isset($_SESSION['user']['services'][$modules_services[$value][$iService]['id']])
                                                && $modules_services[$value][$iService]['whereamiused'][$k]['nature'] == 'include'
    
                                                && $_SESSION['user']['services'][$modules_services[$value][$iService]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                && ($servicenature == 'all' || $servicenature == 'include')
                                                && !in_array(
    
                                                    $modules_services[$value][$iService]['id'],
    
                                                    $executedServices,
    
                                                    $modules_services[$value][$iService]['id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                                include 'modules'.DIRECTORY_SEPARATOR
                                                    .$value.DIRECTORY_SEPARATOR
                                                    .$modules_services[$value][$iService]['servicepage'];
    
    SNA's avatar
    SNA committed
                                            }
                                        }
                                    }
                                }
                            }
    
    SNA's avatar
    SNA committed
                    }
                }
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                if ($servicenature == 'tab') {
                    for ($u = 1; $u <= count($tab_view); ++$u) {
    
    SNA's avatar
    SNA committed
                            ?>
                            <td  class="indexingtab">
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                <a href="javascript://" onclick="opentab('myframe', '<?php functions::xecho($tab_view[$u]['frame_src']); ?>');">
                                    <?php functions::xecho($tab_view[$u]['tab_label']); ?>
    
    SNA's avatar
    SNA committed
                                </a>
                                <?php
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                $_SESSION['first_tab_to_open'] = $tab_view[$u]['frame_src']; ?>
    
    SNA's avatar
    SNA committed
                            </td>
                            <?php
    
    SNA's avatar
    SNA committed
                            ?>
                            <td  class="indexingtab">
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                <a href="javascript://" onclick="opentab('myframe', '<?php functions::xecho($tab_view[$u]['frame_src']); ?>');">
                                    <?php functions::xecho($tab_view[$u]['tab_label']); ?>
    
    SNA's avatar
    SNA committed
                                </a>
                            </td>
                            <?php
                        }
                    }
                }
            }
        }
    
        /**
    
    Alex ORLUC's avatar
    Alex ORLUC committed
         * Executes the apps services in the page.
         *
         * @param  $apps_services array  List of the application services
         * @param  $whereami string Page where to execute the service
         * @param  $servicenature string Nature of the service (by default, the function takes all the services natures)
         */
        public function execute_app_services($appServices, $whereami, $servicenature = 'all')
    
    SNA's avatar
    SNA committed
        {
    
            for ($i = 0; $i < count($appServices); ++$i) {
    
                if (isset($appServices[$i]['whereamiused'])) {
    
                    for ($k = 0; $k < count($appServices[$i]['whereamiused']); ++$k) {
    
                        if ($appServices[$i]['whereamiused'][$k]['page'] == $whereami) {
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            if ($appServices[$i]['whereamiused'][$k]['nature'] == 'frame'
    
                                && $_SESSION['user']['services'][$appServices[$i]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                && ($servicenature == 'all' || $servicenature == 'frame')
                                && !in_array(
    
                                    $appServices[$i]['id'],
                                    $executedServices
                                )
    
                                    $executedServices,
                                    $appServices[$i]['id']
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                ); ?>
                                   <iframe src='<?php echo  $_SESSION['config']['businessappurl'].'index.php?display=true&page='.$appServices[$i]['servicepage']; ?>' name="<?php  $appServices[$i]['id']; ?>" id="<?php  $appServices[$i]['id']; ?>" width='<?php functions::xecho($appServices[$i]['whereamiused'][$k]['width']); ?>' height='<?php functions::xecho($appServices[$i]['whereamiused'][$k]['height']); ?>' frameborder='<?php functions::xecho($appServices[$i]['whereamiused'][$k]['border']); ?>' scrolling='<?php functions::xecho($appServices[$i]['whereamiused'][$k]['scrolling']); ?>'></iframe>
    
    SNA's avatar
    SNA committed
                                   <?php
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                            } elseif ($appServices[$i]['whereamiused'][$k]['nature'] == 'popup'
    
                                && $_SESSION['user']['services'][$appServices[$i]['id']]
    
    Alex ORLUC's avatar
    Alex ORLUC committed
                                && ($servicenature == 'all' || $servicenature == 'popup')
                                && !in_array(
    
                                    $appServices[$i]['id'],
                                    $executedServices
                                )
    
                                    $executedServices,
                                    $appServices[$i]['id']