Entity::isEntityDirectoryConfigured PHP Method

isEntityDirectoryConfigured() static public method

static public isEntityDirectoryConfigured ( $entities_id )
$entities_id
    static function isEntityDirectoryConfigured($entities_id)
    {
        $entity = new self();
        if ($entity->getFromDB($entities_id) && $entity->getField('authldaps_id') > 0) {
            return true;
        }
        //If there's a directory marked as default
        if (AuthLdap::getDefault()) {
            return true;
        }
        return false;
    }

Usage Example

示例#1
0
 /**
  * Make a select box with all glpi users where select key = name
  *
  * @param $options array of possible options:
  *    - name         : string / name of the select (default is users_id)
  *    - value
  *    - right        : string / limit user who have specific right :
  *                         id -> only current user (default case);
  *                         interface -> central ;
  *                         all -> all users ;
  *                         specific right like show_all_ticket, create_ticket.... (is array passed one of all passed right is needed)
  *    - comments     : boolean / is the comments displayed near the dropdown (default true)
  *    - entity       : integer or array / restrict to a defined entity or array of entities
  *                      (default -1 : no restriction)
  *    - entity_sons  : boolean / if entity restrict specified auto select its sons
  *                      only available if entity is a single value not an array(default false)
  *    - all          : Nobody or All display for none selected
  *                         all=0 (default) -> Nobody
  *                         all=1 -> All
  *                         all=-1-> nothing
  *    - rand         : integer / already computed rand value
  *    - toupdate     : array / Update a specific item on select change on dropdown
  *                      (need value_fieldname, to_update, url
  *                      (see Ajax::updateItemOnSelectEvent for information)
  *                      and may have moreparams)
  *    - used         : array / Already used items ID: not to display in dropdown (default empty)
  *    - ldap_import
  *    - on_change    : string / value to transmit to "onChange"
  *    - display      : boolean / display or get string (default true)
  *
  * @return rand value if displayed / string if not
  **/
 static function dropdown($options = array())
 {
     global $DB, $CFG_GLPI;
     // Default values
     $p['name'] = 'users_id';
     $p['value'] = '';
     $p['right'] = 'id';
     $p['all'] = 0;
     $p['on_change'] = '';
     $p['comments'] = 1;
     $p['entity'] = -1;
     $p['entity_sons'] = false;
     $p['used'] = array();
     $p['ldap_import'] = false;
     $p['toupdate'] = '';
     $p['rand'] = mt_rand();
     $p['display'] = true;
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $val) {
             $p[$key] = $val;
         }
     }
     $output = '';
     if (!($p['entity'] < 0) && $p['entity_sons']) {
         if (is_array($p['entity'])) {
             $output .= "entity_sons options is not available with array of entity";
         } else {
             $p['entity'] = getSonsOf('glpi_entities', $p['entity']);
         }
     }
     // Make a select box with all glpi users
     $use_ajax = false;
     if ($CFG_GLPI["use_ajax"]) {
         $res = self::getSqlSearchResult(true, $p['right'], $p['entity'], $p['value'], $p['used']);
         $nb = $res ? $DB->result($res, 0, "CPT") : 0;
         if ($nb > $CFG_GLPI["ajax_limit_count"]) {
             $use_ajax = true;
         }
     }
     $user = getUserName($p['value'], 2);
     $default_display = "<select id='dropdown_" . $p['name'] . $p['rand'] . "' name='" . $p['name'] . "'>";
     $default_display .= "<option value='" . $p['value'] . "'>";
     $default_display .= Toolbox::substr($user["name"], 0, $_SESSION["glpidropdown_chars_limit"]);
     $default_display .= "</option></select>";
     $view_users = Session::haveRight("user", "r");
     $params = array('searchText' => '__VALUE__', 'value' => $p['value'], 'myname' => $p['name'], 'all' => $p['all'], 'right' => $p['right'], 'comment' => $p['comments'], 'rand' => $p['rand'], 'on_change' => $p['on_change'], 'entity_restrict' => $p['entity'], 'used' => $p['used'], 'update_item' => $p['toupdate']);
     if ($view_users) {
         $params['update_link'] = $view_users;
     }
     $default = "";
     if (!empty($p['value']) && $p['value'] > 0) {
         $default = $default_display;
     } else {
         $default = "<select name='" . $p['name'] . "' id='dropdown_" . $p['name'] . $p['rand'] . "'>";
         if ($p['all']) {
             $default .= "<option value='0'>--" . __('All') . "--</option></select>";
         } else {
             $default .= "<option value='0'>" . Dropdown::EMPTY_VALUE . "</option></select>\n";
         }
     }
     $output .= Ajax::dropdown($use_ajax, "/ajax/dropdownUsers.php", $params, $default, $p['rand'], false);
     // Display comment
     if ($p['comments']) {
         if (!$view_users) {
             $user["link"] = '';
         } else {
             if (empty($user["link"])) {
                 $user["link"] = $CFG_GLPI['root_doc'] . "/front/user.php";
             }
         }
         $output .= Html::showToolTip($user["comment"], array('contentid' => "comment_" . $p['name'] . $p['rand'], 'display' => false, 'link' => $user["link"], 'linkid' => "comment_link_" . $p["name"] . $p['rand']));
     }
     if (Session::haveRight('import_externalauth_users', 'w') && $p['ldap_import'] && Entity::isEntityDirectoryConfigured($_SESSION['glpiactive_entity'])) {
         $output .= "<img alt='' title=\"" . __s('Import a user') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png' style='cursor:pointer; margin-left:2px;'\n                      onClick=\"var w = window.open('" . $CFG_GLPI['root_doc'] . "/front/popup.php?popup=add_ldapuser&amp;rand=" . $p['rand'] . "&amp;entity=" . $_SESSION['glpiactive_entity'] . "' ,'glpipopup', 'height=400, " . "width=1000, top=100, left=100, scrollbars=yes' );w.focus();\">";
     }
     if ($p['display']) {
         echo $output;
         return $p['rand'];
     }
     return $output;
 }
All Usage Examples Of Entity::isEntityDirectoryConfigured