Dropdown::showAdvanceDateRestrictionSwitch PHP Method

showAdvanceDateRestrictionSwitch() static public method

Toggle view in LDAP user import/synchro between no restriction and date restriction
static public showAdvanceDateRestrictionSwitch ( $enabled )
$enabled (default 0)
    static function showAdvanceDateRestrictionSwitch($enabled = 0)
    {
        global $CFG_GLPI;
        $rand = mt_rand();
        $url = $CFG_GLPI["root_doc"] . "/ajax/ldapdaterestriction.php";
        echo "<script type='text/javascript' >\n";
        echo "function activateRestriction() {\n";
        $params = array('enabled' => 1);
        Ajax::updateItemJsCode('date_restriction', $url, $params);
        echo "};";
        echo "function deactivateRestriction() {\n";
        $params = array('enabled' => 0);
        Ajax::updateItemJsCode('date_restriction', $url, $params);
        echo "};";
        echo "</script>";
        echo "</table>";
        echo "<span id='date_restriction'>";
        $_POST['enabled'] = $enabled;
        include GLPI_ROOT . "/ajax/ldapdaterestriction.php";
        echo "</span>\n";
        return $rand;
    }

Usage Example

 /**
  * @param $authldap  AuthLDAP object
  **/
 static function showUserImportForm(AuthLDAP $authldap)
 {
     global $DB;
     //Get data related to entity (directory and ldap filter)
     $authldap->getFromDB($_SESSION['ldap_import']['authldaps_id']);
     echo "<div class='center'>";
     echo "<form method='post' action='" . $_SERVER['PHP_SELF'] . "'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr><th colspan='4' class='middle'><div class='relative'>";
     echo "<span>" . ($_SESSION['ldap_import']['mode'] ? __('Synchronizing already imported users') : __('Import new users'));
     // Expert interface allow user to override configuration.
     // If not coming from the ticket form, then give expert/simple link
     if ((Config::canUpdate() || Entity::canUpdate()) && !isset($_SESSION['ldap_import']['no_expert_mode'])) {
         echo "</span>&nbsp;<span class='floatright'><a href='" . $_SERVER['PHP_SELF'] . "?action=" . $_SESSION['ldap_import']['action'] . "&amp;mode=" . $_SESSION['ldap_import']['mode'];
         if ($_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE) {
             echo "&amp;interface=" . self::EXPERT_INTERFACE . "'>" . __('Expert mode') . "</a>";
         } else {
             echo "&amp;interface=" . self::SIMPLE_INTERFACE . "'>" . __('Simple mode') . "</a>";
         }
     } else {
         $_SESSION['ldap_import']['interface'] = self::SIMPLE_INTERFACE;
     }
     echo "</span></div>";
     echo "</th></tr>";
     switch ($_SESSION['ldap_import']['interface']) {
         case self::EXPERT_INTERFACE:
             //If more than one directory configured
             //Display dropdown ldap servers
             if ($_SESSION['ldap_import']['authldaps_id'] != NOT_AVAILABLE && $_SESSION['ldap_import']['authldaps_id'] > 0) {
                 if (self::getNumberOfServers() > 1) {
                     echo "<tr class='tab_bg_2'><td>" . __('LDAP directory choice') . "</td>";
                     echo "<td colspan='3'>";
                     self::dropdown(array('name' => 'authldaps_id', 'value' => $_SESSION['ldap_import']['authldaps_id'], 'condition' => "`is_active` = '1'", 'display_emptychoice' => false));
                     echo "&nbsp;<input class='submit' type='submit' name='change_directory'\n                        value=\"" . _sx('button', 'To change') . "\">";
                     echo "</td></tr>";
                 }
                 echo "<tr class='tab_bg_2'><td>" . __('BaseDN') . "</td><td colspan='3'>";
                 echo "<input type='text' class='form-control' name='basedn' value=\"" . $_SESSION['ldap_import']['basedn'] . "\" size='90' " . (!$_SESSION['ldap_import']['basedn'] ? "disabled" : "") . ">";
                 echo "</td></tr>";
                 echo "<tr class='tab_bg_2'><td>" . __('Search filter for users') . "</td><td colspan='3'>";
                 echo "<input type='text' class='form-control' name='ldap_filter' value=\"" . $_SESSION['ldap_import']['ldap_filter'] . "\" size='90'>";
                 echo "</td></tr>";
             }
             break;
             //case self::SIMPLE_INTERFACE :
         //case self::SIMPLE_INTERFACE :
         default:
             //If multi-entity mode and more than one entity visible
             //else no need to select entity
             if (Session::isMultiEntitiesMode() && count($_SESSION['glpiactiveentities']) > 1) {
                 echo "<tr class='tab_bg_2'><td>" . __('Select the desired entity') . "</td>" . "<td colspan='3'>";
                 Entity::dropdown(array('value' => $_SESSION['ldap_import']['entities_id'], 'entity' => $_SESSION['glpiactiveentities'], 'on_change' => 'submit()'));
                 echo "</td></tr>";
             } else {
                 //Only one entity is active, store it
                 echo "<tr><td><input type='hidden' name='entities_id' value='" . $_SESSION['glpiactive_entity'] . "'></td></tr>";
             }
             if (isset($_SESSION['ldap_import']['begin_date']) && !empty($_SESSION['ldap_import']['begin_date']) || isset($_SESSION['ldap_import']['end_date']) && !empty($_SESSION['ldap_import']['end_date'])) {
                 $enabled = 1;
             } else {
                 $enabled = 0;
             }
             Dropdown::showAdvanceDateRestrictionSwitch($enabled);
             echo "<table class='tab_cadre_fixe'>";
             if ($_SESSION['ldap_import']['authldaps_id'] != NOT_AVAILABLE && $_SESSION['ldap_import']['authldaps_id'] > 0) {
                 $field_counter = 0;
                 $fields = array('login_field' => __('Login'), 'email1_field' => __('Email'), 'email2_field' => sprintf(__('%1$s %2$s'), _n('Email', 'Emails', 1), '2'), 'email3_field' => sprintf(__('%1$s %2$s'), _n('Email', 'Emails', 1), '3'), 'email4_field' => sprintf(__('%1$s %2$s'), _n('Email', 'Emails', 1), '4'), 'realname_field' => __('Surname'), 'firstname_field' => __('First name'), 'phone_field' => __('Phone'), 'phone2_field' => __('Phone 2'), 'mobile_field' => __('Mobile phone'), 'title_field' => _x('person', 'Title'), 'category_field' => __('Category'), 'picture_field' => __('Picture'));
                 $available_fields = array();
                 foreach ($fields as $field => $label) {
                     if (isset($authldap->fields[$field]) && $authldap->fields[$field] != '') {
                         $available_fields[$field] = $label;
                     }
                 }
                 echo "<tr><th colspan='4'>" . __('Search criteria for users') . "</th></tr>";
                 foreach ($available_fields as $field => $label) {
                     if ($field_counter == 0) {
                         echo "<tr class='tab_bg_1'>";
                     }
                     echo "<td>{$label}</td><td>";
                     $field_counter++;
                     echo "<input type='text' class='form-control' name='criterias[{$field}]' value='" . (isset($_SESSION['ldap_import']['criterias'][$field]) ? $_SESSION['ldap_import']['criterias'][$field] : '') . "'>";
                     echo "</td>";
                     if ($field_counter == 2) {
                         echo "</tr>";
                         $field_counter = 0;
                     }
                 }
                 if ($field_counter > 0) {
                     while ($field_counter < 2) {
                         echo "<td colspan='2'></td>";
                         $field_counter++;
                     }
                     $field_counter = 0;
                     echo "</tr>";
                 }
             }
             break;
     }
     if ($_SESSION['ldap_import']['authldaps_id'] != NOT_AVAILABLE && $_SESSION['ldap_import']['authldaps_id'] > 0) {
         if ($_SESSION['ldap_import']['authldaps_id']) {
             echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
             echo "<input class='submit' type='submit' name='search' value=\"" . _sx('button', 'Search') . "\">";
             echo "</td></tr>";
         } else {
             echo "<tr class='tab_bg_2'><" . "td colspan='4' class='center'>" . __('No directory selected') . "</td></tr>";
         }
     } else {
         echo "<tr class='tab_bg_2'><td colspan='4' class='center'>" . __('No directory associated to entity: impossible search') . "</td></tr>";
     }
     echo "</table>";
     Html::closeForm();
     echo "</div>";
 }
All Usage Examples Of Dropdown::showAdvanceDateRestrictionSwitch