public function getAvailableValues()
 {
     if (!empty($this->fields['values'])) {
         $ldap_values = json_decode(plugin_formcreator_decode($this->fields['values']));
         $ldap_dropdown = new RuleRightParameter();
         if (!$ldap_dropdown->getFromDB($ldap_values->ldap_attribute)) {
             return array();
         }
         $attribute = array($ldap_dropdown->fields['value']);
         $config_ldap = new AuthLDAP();
         if (!$config_ldap->getFromDB($ldap_values->ldap_auth)) {
             return array();
         }
         if (!function_exists('warning_handler')) {
             function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext)
             {
                 if (0 === error_reporting()) {
                     return false;
                 }
                 throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
             }
         }
         set_error_handler("warning_handler", E_WARNING);
         try {
             $tab_values = array();
             $ds = $config_ldap->connect();
             ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
             $cookie = '';
             do {
                 if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) {
                     ldap_control_paged_result($ds, $config_ldap->fields['pagesize'], true, $cookie);
                 }
                 $result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute);
                 $entries = ldap_get_entries($ds, $result);
                 array_shift($entries);
                 foreach ($entries as $id => $attr) {
                     if (isset($attr[$attribute[0]]) && !in_array($attr[$attribute[0]][0], $tab_values)) {
                         $tab_values[$id] = $attr[$attribute[0]][0];
                     }
                 }
                 if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) {
                     ldap_control_paged_result_response($ds, $result, $cookie);
                 }
             } while ($cookie !== null && $cookie != '');
             if ($this->fields['show_empty']) {
                 $tab_values = array('' => '-----') + $tab_values;
             }
             asort($tab_values);
             return $tab_values;
         } catch (Exception $e) {
             return array();
         }
         restore_error_handler();
     } else {
         return array();
     }
 }
 public function displayField($canEdit = true)
 {
     if ($canEdit) {
         $required = $this->fields['required'] ? ' required' : '';
         echo '<textarea class="form-control"
               rows="5"
               name="formcreator_field_' . $this->fields['id'] . '"
               id="formcreator_field_' . $this->fields['id'] . '"
               onchange="formcreatorChangeValueOf(' . $this->fields['id'] . ', this.value);">' . str_replace('\\r\\n', PHP_EOL, $this->getValue()) . '</textarea>';
         if ($GLOBALS['CFG_GLPI']["use_rich_text"]) {
             Html::initEditorSystem('formcreator_field_' . $this->fields['id']);
         }
     } else {
         if ($GLOBALS['CFG_GLPI']["use_rich_text"]) {
             echo plugin_formcreator_decode($this->getAnswer());
         } else {
             echo nl2br($this->getAnswer());
         }
     }
 }
Beispiel #3
0
               <?php 
$optgroup = Dropdown::getStandardDropdownItemTypes();
array_unshift($optgroup, '---');
Dropdown::showFromArray('dropdown_values', $optgroup, array('value' => $question->fields['values'], 'rand' => $rand, 'on_change' => 'change_dropdown();'));
?>
            </div>
            <div id="glpi_objects_field">
               <?php 
$optgroup = array(__("Assets") => array('Computer' => _n("Computer", "Computers", 2), 'Monitor' => _n("Monitor", "Monitors", 2), 'Software' => _n("Software", "Software", 2), 'Networkequipment' => _n("Network", "Networks", 2), 'Peripheral' => _n("Device", "Devices", 2), 'Printer' => _n("Printer", "Printers", 2), 'Cartridgeitem' => _n("Cartridge", "Cartridges", 2), 'Consumableitem' => _n("Consumable", "Consumables", 2), 'Phone' => _n("Phone", "Phones", 2)), __("Assistance") => array('Ticket' => _n("Ticket", "Tickets", 2), 'Problem' => _n("Problem", "Problems", 2), 'TicketRecurrent' => __("Recurrent tickets")), __("Management") => array('Budget' => _n("Budget", "Budgets", 2), 'Supplier' => _n("Supplier", "Suppliers", 2), 'Contact' => _n("Contact", "Contacts", 2), 'Contract' => _n("Contract", "Contracts", 2), 'Document' => _n("Document", "Documents", 2)), __("Tools") => array('Notes' => __("Notes"), 'RSSFeed' => __("RSS feed")), __("Administration") => array('User' => _n("User", "Users", 2), 'Group' => _n("Group", "Groups", 2), 'Entity' => _n("Entity", "Entities", 2), 'Profile' => _n("Profile", "Profiles", 2)));
array_unshift($optgroup, '---');
Dropdown::showFromArray('glpi_objects', $optgroup, array('value' => $question->fields['values'], 'rand' => $rand, 'on_change' => 'change_glpi_objects();'));
?>
            </div>
            <div id="glpi_ldap_field">
            <?php 
$ldap_values = json_decode(plugin_formcreator_decode($question->fields['values']));
Dropdown::show('AuthLDAP', array('name' => 'ldap_auth', 'rand' => $rand, 'value' => isset($ldap_values->ldap_auth) ? $ldap_values->ldap_auth : '', 'on_change' => 'change_LDAP(this)'));
?>
            </div>
         </td>
      </tr>

      <tr class="line0" id="required_tr">
         <td>
            <label for="dropdown_required<?php 
echo $rand;
?>
" id="label_required">
               <?php 
echo __('Required', 'formcreator');
?>