Html::showToolTip PHP Method

showToolTip() static public method

Show a tooltip on an item
static public showToolTip ( $content, $options = [] ) : nothing
$content string data to put in the tooltip
$options array of possible options: - applyto : string / id of the item to apply tooltip (default empty). If not set display an icon - title : string / title to display (default empty) - contentid : string / id for the content html container (default auto generated) (used for ajax) - link : string / link to put on displayed image if contentid is empty - linkid : string / html id to put to the link link (used for ajax) - linktarget : string / target for the link - popup : string / popup action : link not needed to use it - img : string / url of a specific img to use - display : boolean / display the item : false return the datas - autoclose : boolean / autoclose the item : default true (false permit to scroll)
return nothing (print out an HTML div)
    static function showToolTip($content, $options = array())
    {
        global $CFG_GLPI;
        $param['applyto'] = '';
        $param['title'] = '';
        $param['contentid'] = '';
        $param['link'] = '';
        $param['linkid'] = '';
        $param['linktarget'] = '';
        $param['img'] = $CFG_GLPI["root_doc"] . "/pics/info-small.png";
        $param['popup'] = '';
        $param['ajax'] = '';
        $param['display'] = true;
        $param['autoclose'] = true;
        if (is_array($options) && count($options)) {
            foreach ($options as $key => $val) {
                $param[$key] = $val;
            }
        }
        // No empty content to have a clean display
        if (empty($content)) {
            $content = " ";
        }
        $rand = mt_rand();
        $out = '';
        // Force link for popup
        if (!empty($param['popup'])) {
            $param['link'] = '#';
        }
        if (empty($param['applyto'])) {
            if (!empty($param['link'])) {
                $out .= "<a id='" . (!empty($param['linkid']) ? $param['linkid'] : "tooltiplink{$rand}") . "'";
                if (!empty($param['linktarget'])) {
                    $out .= " target='" . $param['linktarget'] . "' ";
                }
                $out .= " href='" . $param['link'] . "'";
                if (!empty($param['popup'])) {
                    $out .= " onClick=\"" . Html::jsGetElementbyID('tooltippopup' . $rand) . ".dialog('open');\" ";
                }
                $out .= '>';
            }
            $out .= "<img id='tooltip{$rand}' src='" . $param['img'] . "' class='pointer'>";
            if (!empty($param['link'])) {
                $out .= "</a>";
            }
            $param['applyto'] = "tooltip{$rand}";
        }
        if (empty($param['contentid'])) {
            $param['contentid'] = "content" . $param['applyto'];
        }
        $out .= "<div id='" . $param['contentid'] . "' class='invisible'>{$content}</div>";
        if (!empty($param['popup'])) {
            $out .= Ajax::createIframeModalWindow('tooltippopup' . $rand, $param['popup'], array('display' => false, 'width' => 600, 'height' => 300));
        }
        $js = "";
        $js .= Html::jsGetElementbyID($param['applyto']) . ".qtip({\n         position: { viewport: \$(window) },\n         content: {text: " . Html::jsGetElementbyID($param['contentid']);
        if (!$param['autoclose']) {
            $js .= ", title: {text: ' ',button: true}";
        }
        $js .= "}, style: { classes: 'qtip-shadow qtip-bootstrap'}";
        if (!$param['autoclose']) {
            $js .= ",show: {\n                        solo: true, // ...and hide all other tooltips...\n                }, hide: false,";
        }
        $js .= "});";
        $out .= Html::scriptBlock($js);
        if ($param['display']) {
            echo $out;
        } else {
            return $out;
        }
    }

Usage Example

Example #1
0
 /**
  * Permet l'affichage dynamique d'une liste d�roulante imbriquee
  *
  * @static
  * @param array ($itemtype,$options)
  */
 public static function dropdownReferencesByEnterprise($itemtype, $options = array())
 {
     global $DB, $CFG_GLPI;
     $item = getItemForItemtype($itemtype);
     if ($itemtype && !($item = getItemForItemtype($itemtype))) {
         return false;
     }
     $table = $item->getTable();
     $params['comments'] = true;
     $params['condition'] = '';
     $params['entity'] = -1;
     $params['name'] = "reference";
     $params['value'] = 0;
     $params['entity_sons'] = false;
     $params['rand'] = mt_rand();
     $params['used'] = array();
     $params['table'] = $table;
     $params['emptylabel'] = Dropdown::EMPTY_VALUE;
     //specific
     $params['action'] = "";
     $params['itemtype'] = "";
     $params['span'] = "";
     $params['orders_id'] = 0;
     $params['suppliers_id'] = 0;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $params[$key] = $val;
         }
     }
     $name = $params['emptylabel'];
     $comment = "";
     $limit_length = $_SESSION["glpidropdown_chars_limit"];
     if (strlen($params['value']) == 0 || !is_numeric($params['value'])) {
         $params['value'] = 0;
     }
     if ($params['value'] > 0) {
         $tmpname = Dropdown::getDropdownName($table, $params['value'], 1);
         if ($tmpname["name"] != "&nbsp;") {
             $name = $tmpname["name"];
             $comment = $tmpname["comment"];
             if (Toolbox::strlen($name) > $_SESSION["glpidropdown_chars_limit"]) {
                 if ($item instanceof CommonTreeDropdown) {
                     $pos = strrpos($name, ">");
                     $limit_length = max(Toolbox::strlen($name) - $pos, $_SESSION["glpidropdown_chars_limit"]);
                     if (Toolbox::strlen($name) > $limit_length) {
                         $name = "&hellip;" . Toolbox::substr($name, -$limit_length);
                     }
                 } else {
                     $limit_length = Toolbox::strlen($name);
                 }
             } else {
                 $limit_length = $_SESSION["glpidropdown_chars_limit"];
             }
         }
     }
     // Manage entity_sons
     if (!($params['entity'] < 0) && $params['entity_sons']) {
         if (is_array($params['entity'])) {
             echo "entity_sons options is not available with array of entity";
         } else {
             $params['entity'] = getSonsOf('glpi_entities', $params['entity']);
         }
     }
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax_autocompletion"]) {
         $nb = 0;
         $query = "SELECT COUNT(*) AS cpt\n                   FROM `{$table}` as t\n                   LEFT JOIN `glpi_plugin_order_references_suppliers` as s\n                      ON (`t`.`id` = `s`.`plugin_order_references_id`)\n                   WHERE `s`.`suppliers_id` = '{$params['suppliers_id']}'\n                   AND `t`.`itemtype` = '{$params['itemtype']}'";
         if ($item->isEntityAssign()) {
             if (!($params['entity'] < 0)) {
                 $query .= getEntitiesRestrictRequest("AND", 't', '', $params['entity'], true);
             } else {
                 $query .= getEntitiesRestrictRequest("AND", 't', '', '', true);
             }
         }
         $result = $DB->query($query);
         if ($DB->numrows($result) == 1) {
             $nb = $DB->result($result, 0, "cpt");
         }
         $nb -= count($params['used']);
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $param = array('searchText' => '__VALUE__', 'value' => $params['value'], 'itemtype' => $params['itemtype'], 'myname' => $params['name'], 'limit' => $limit_length, 'comment' => $params['comments'], 'rand' => $params['rand'], 'entity_restrict' => $params['entity'], 'used' => $params['used'], 'condition' => $params['condition'], 'table' => $params['table'], 'action' => $params['action'], 'span' => $params['span'], 'orders_id' => $params['orders_id'], 'suppliers_id' => $params['suppliers_id']);
     $default = "<select name='" . $params['name'] . "' id='dropdown_" . $params['name'] . $params['rand'] . "'>";
     $default .= "<option value='" . $params['value'] . "'>{$name}</option></select>";
     Ajax::Dropdown($use_ajax, "/plugins/order/ajax/dropdownValue.php", $param, $default, $params['rand']);
     // Display comment
     if ($params['comments']) {
         $options_tooltip = array('contentid' => "comment_" . $param['myname'] . $params['rand']);
         if ($params['value'] && $item->getFromDB($params['value'])) {
             $options_tooltip['link'] = $item->getLinkURL();
             $options_tooltip['linktarget'] = '_blank';
         }
         Html::showToolTip($comment, $options_tooltip);
         if ($itemtype::canCreate() && !isset($_GET['popup'])) {
             echo "<img alt='' title=\"" . __("Add") . "\" src='" . $CFG_GLPI["root_doc"] . "\n               /pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n               onClick=\"var w = window . open('" . $item->getFormURL() . "?popup=1&amp;rand=" . $params['rand'] . "&amp;itemtype=" . $params['itemtype'] . "&amp;entities_id=" . $params['entity'] . "', " . "'glpipopup', 'height=400,width=1000, top=100, left=100,\n               scrollbars=yes' );w.focus();\">";
         }
     }
     return $params['rand'];
 }
All Usage Examples Of Html::showToolTip
Html