<?php
// +-------------------------------------------------+
// | 2002-2007 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: list_tabs_common_ui.class.php,v 1.1.4.3 2026/06/09 07:29:08 dgoron Exp $

if (stristr($_SERVER['REQUEST_URI'], ".class.php")) die("no access");

class list_tabs_common_ui extends list_tabs_ui {
	
    protected function init_default_applied_group() {
        $this->applied_group = array();
    }
    
    public function get_builded_destination_link($categ, $sub='', $url_extra='') {
        global $charset, $lang, $pmb_opac_url;
        
        switch ($categ) {
            case 'help':
                // remplacement de !!help_link!! par le lien correspondant
                $request_uri  = $_SERVER["REQUEST_URI"];
                $doc_params_explode = explode("?", $request_uri);
                if(isset($doc_params_explode[1])) {
                    $doc_params = $doc_params_explode[1];
                } else {
                    $doc_params = '';
                }
                $pos = strrpos($doc_params_explode[0], "/") + 1;
                $script_name = substr($doc_params_explode[0], $pos);
                // On évite la vulnérabilités xss
                $help_url = sprintf("./doc/index.php?script_name=%s", urlencode($script_name));
                if (!empty($doc_params)) {
                    $help_url = "{$help_url}&" . htmlentities($doc_params, ENT_QUOTES, $charset);
                }
                $help_url .= "&lang={$lang}";
                return $help_url;
            case 'param':
                return './account.php';
            case 'opac':
                return $pmb_opac_url."index.php?database=".LOCATION;
            case 'sauv':
            case 'rtl':
            case 'ltr':
            case 'history':
                return '#';
            case 'quit':
                return './logout.php';
        }
    }
    
    protected function _get_object_property_label($object) {
        switch ($object->get_categ()) {
            case 'param':
                return $object->get_label()." ".SESSlogin;
            case 'quit':
                return $object->get_label()." : ".LOCATION;
            default:
                return $object->get_label();
        }
    }
    
    protected function _get_object_property_event_click($object) {
        switch ($object->get_categ()) {
            case 'history':
                return "document.getElementById('history').style.display=''; document.getElementById('history').src='./history.php'; return false;";
            case 'help':
                return '';
            case 'param':
                return '';
            case 'opac':
                return '';
            case 'sauv':
                return "openPopUp('./admin/sauvegarde/launch.php','sauv_launch',600,500,-2,-2,'menubar=no,scrollbars=yes'); w.focus(); return false;";
            case 'rtl':
                return "setActiveStyleSheet('lefttoright'); window.location.reload(false); return false;";
            case 'ltr':
                return "setActiveStyleSheet('righttoleft'); window.location.reload(false); return false;";
            case 'quit':
                return '';
        }
    }
    
    protected function _get_object_property_icon_name($object) {
        switch ($object->get_categ()) {
            case 'history':
                return 'historique.gif';
            case 'help':
                return 'aide.gif';
            case 'param':
                return 'parametres.gif';
            case 'opac':
                return 'opac2.gif';
            case 'sauv':
                return 'sauv.gif';
            case 'rtl':
                return 'rtl.gif';
            case 'ltr':
                return 'ltr.gif';
            case 'quit':
                return 'close.png';
        }
    }
    
    protected function _get_object_property_link_target($object) {
        switch ($object->get_categ()) {
            case 'help':
                return '_blank';
            case 'opac':
                return '_opac_';
            default:
                return '';
        }
    }
    
    protected function _get_object_property_accesskey($object) {
        global $msg;
        switch ($object->get_categ()) {
            case 'param':
                return $msg[2006];
            case 'opac':
                return $msg[2007];
            case 'quit':
                return $msg[2008];
            default:
                return '';
        }
    }
    
    public function get_display_tab($object) {
        global $charset;
        
        $destination_link = $this->get_builded_destination_link($object->get_categ());
        $onClick = '';
        if ($destination_link == '#') {
            $onClick = $this->_get_object_property_event_click($object);
        }
        $label = $this->_get_object_property_label($object);
        $target = $this->_get_object_property_link_target($object);
        $accesskey = $this->_get_object_property_accesskey($object);
        return "<a class=\"icon_".$object->get_categ()."\" href=\"".$destination_link."\" ".($onClick ? "onClick=\"".$onClick."\"" : "")." 
            ".($target ? "target='".$target."'" : "")." ".($accesskey ? "accesskey='".$accesskey."'" : "")." title=\"".htmlentities($label, ENT_QUOTES, $charset)."\">
            <img src='".get_url_icon($this->_get_object_property_icon_name($object))."' class='align_middle' style='margin:0px 3px' alt='' />
            <span class='visually-hidden'>".htmlentities($label, ENT_QUOTES, $charset)."</span>
        </a>";
    }
    
    public function get_display_database_label() {
        global $_tableau_databases, $_libelle_databases;
        
        $display = '';
        if (!empty($_libelle_databases) && count($_libelle_databases) > 1) {
            foreach ($_tableau_databases as $_key_tableau_database=>$_tableau_database) {
                if ($_tableau_database == LOCATION) {
                    $display .= "<span class='label_database'>".$_libelle_databases[$_key_tableau_database]."</span>";
                }
            }
        }
        return $display;
    }
    
    public function get_display() {
        $display = '';
        if (defined('SESSrights') && SESSrights & CATALOGAGE_AUTH) {
            $display.="<iframe id='history' style='display:none;'></iframe>";
        }
        $display.="
        <div id='extra'>
            <span id=\"keystatus\">&nbsp;</span>&nbsp;&nbsp;&nbsp;";
        $display .= $this->get_display_database_label();
        foreach ($this->objects as $object) {
            $display .= $this->get_display_tab($object);
        }
        $display .= "</div>";
        return $display;
    }
    
	protected function _init_tabs() {
	    global $pmb_show_help;
	    global $pmb_show_rtl;
	    
		if (defined('SESSrights') && SESSrights & CATALOGAGE_AUTH) {
		    $this->add_tab('common', 'history', 'menu_bar_title_histo', '');
		}
		//affichage du lien d'aide, c'est un "?" pour l'instant
		if ($pmb_show_help) {
		    $this->add_tab('common', 'help', '1900', '');
		}
		if (defined('SESSrights') && SESSrights & PREF_AUTH) {
		    $this->add_tab('common', 'param', '934');
		}
		$this->add_tab('common', 'opac', '1027');
		if (defined('SESSrights') && SESSrights & SAUV_AUTH) {
		    $this->add_tab('common', 'sauv', 'sauv_shortcuts_title');
		}
		if ($pmb_show_rtl) {
		    $this->add_tab('common', 'rtl', 'rtl');
		    $this->add_tab('common', 'ltr', 'ltr');
		}
		$this->add_tab('common', 'quit', '747');
		
	}
}