本文整理汇总了PHP中AuthLDAP::getFromDB方法的典型用法代码示例。如果您正苦于以下问题:PHP AuthLDAP::getFromDB方法的具体用法?PHP AuthLDAP::getFromDB怎么用?PHP AuthLDAP::getFromDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AuthLDAP
的用法示例。
在下文中一共展示了AuthLDAP::getFromDB方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAvailableValues
public function getAvailableValues()
{
if (!empty($this->fields['values'])) {
$ldap_values = json_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();
}
}
示例2: sprintf
Session::addMessageAfterRedirect(__('Test successful'));
} else {
Session::addMessageAfterRedirect(__('Test failed'), false, ERROR);
}
Html::redirect($CFG_GLPI["root_doc"] . "/front/authldap.php?next=extauth_ldap&id=" . $newID);
}
}
Html::back();
} else {
if (isset($_POST["delete"])) {
$config_ldap->delete($_POST);
$_SESSION['glpi_authconfig'] = 1;
$config_ldap->redirectToList();
} else {
if (isset($_POST["test_ldap"])) {
$config_ldap->getFromDB($_POST["id"]);
if (AuthLdap::testLDAPConnection($_POST["id"])) {
//TRANS: %s is the description of the test
$_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test successful: %s'), sprintf(__('Main server %s'), $config_ldap->fields["name"]));
} else {
//TRANS: %s is the description of the test
$_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test failed: %s'), sprintf(__('Main server %s'), $config_ldap->fields["name"]));
}
Html::back();
} else {
if (isset($_POST["test_ldap_replicate"])) {
foreach ($_POST["test_ldap_replicate"] as $replicate_id => $value) {
$replicate = new AuthLdapReplicate();
$replicate->getFromDB($replicate_id);
if (AuthLdap::testLDAPConnection($_POST["id"], $replicate_id)) {
//TRANS: %s is the description of the test
示例3: showLdapDebug
/**
* Display information from LDAP server for user
**/
private function showLdapDebug()
{
if ($this->fields['authtype'] != Auth::LDAP) {
return false;
}
echo "<div class='spaced'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='4'>" . __('LDAP directory') . "</th></tr>";
echo "<tr class='tab_bg_2'><td>" . __('User DN') . "</td>";
echo "<td>" . $this->fields['user_dn'] . "</td></tr>\n";
if ($this->fields['user_dn']) {
echo "<tr class='tab_bg_2'><td>" . __('User information') . "</td><td>";
$config_ldap = new AuthLDAP();
$ds = false;
if ($config_ldap->getFromDB($this->fields['auths_id'])) {
$ds = $config_ldap->connect();
}
if ($ds) {
$info = AuthLdap::getUserByDn($ds, $this->fields['user_dn'], array('*', 'createTimeStamp', 'modifyTimestamp'));
if (is_array($info)) {
Html::printCleanArray($info);
} else {
_e('No item to display');
}
} else {
_e('Connection failed');
}
echo "</td></tr>\n";
}
echo "</table></div>";
}
示例4: showUserImportForm
/**
* @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> <span class='floatright'><a href='" . $_SERVER['PHP_SELF'] . "?action=" . $_SESSION['ldap_import']['action'] . "&mode=" . $_SESSION['ldap_import']['mode'];
if ($_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE) {
echo "&interface=" . self::EXPERT_INTERFACE . "'>" . __('Expert mode') . "</a>";
} else {
echo "&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 " <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;
//.........这里部分代码省略.........
示例5: checkBeforeSave
/**
* Validate form fields before add or update a question
*
* @param Array $input Datas used to add the item
*
* @return Array The modified $input array
*
* @param [type] $input [description]
* @return [type] [description]
*/
private function checkBeforeSave($input)
{
// Control fields values :
// - name is required
if (empty($input['name'])) {
Session::addMessageAfterRedirect(__('The title is required', 'formcreator'), false, ERROR);
return array();
}
// - field type is required
if (empty($input['fieldtype'])) {
Session::addMessageAfterRedirect(__('The field type is required', 'formcreator'), false, ERROR);
return array();
}
// - section is required
if (empty($input['plugin_formcreator_sections_id'])) {
Session::addMessageAfterRedirect(__('The section is required', 'formcreator'), false, ERROR);
return array();
}
// Values are required for GLPI dropdowns, dropdowns, multiple dropdowns, checkboxes, radios, LDAP
$itemtypes = array('select', 'multiselect', 'checkboxes', 'radios', 'ldap');
if (empty($input['values']) && in_array($input['fieldtype'], $itemtypes)) {
Session::addMessageAfterRedirect(__('The field value is required:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
// Fields are differents for dropdown lists, so we need to replace these values into the good ones
if ($input['fieldtype'] == 'dropdown') {
if (empty($input['dropdown_values'])) {
Session::addMessageAfterRedirect(__('The field value is required:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
$input['values'] = $input['dropdown_values'];
$input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : '';
}
// Fields are differents for GLPI object lists, so we need to replace these values into the good ones
if ($input['fieldtype'] == 'glpiselect') {
if (empty($input['glpi_objects'])) {
Session::addMessageAfterRedirect(__('The field value is required:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
$input['values'] = $input['glpi_objects'];
$input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : '';
}
// A description field should have a description
if ($input['fieldtype'] == 'description' && empty($input['description'])) {
Session::addMessageAfterRedirect(__('A description field should have a description:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
// format values for numbers
if ($input['fieldtype'] == 'integer' || $input['fieldtype'] == 'float') {
$input['default_values'] = !empty($input['default_values']) ? (double) str_replace(',', '.', $input['default_values']) : null;
$input['range_min'] = !empty($input['range_min']) ? (double) str_replace(',', '.', $input['range_min']) : null;
$input['range_max'] = !empty($input['range_max']) ? (double) str_replace(',', '.', $input['range_max']) : null;
}
// LDAP fields validation
if ($input['fieldtype'] == 'ldapselect') {
// Fields are differents for dropdown lists, so we need to replace these values into the good ones
if (!empty($input['ldap_auth'])) {
$config_ldap = new AuthLDAP();
$config_ldap->getFromDB($input['ldap_auth']);
$ldap_dropdown = new RuleRightParameter();
$ldap_dropdown->getFromDB($input['ldap_attribute']);
$attribute = array($ldap_dropdown->fields['value']);
// Set specific error handler too catch LDAP errors
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 {
$ds = $config_ldap->connect();
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_control_paged_result($ds, 1);
$sn = ldap_search($ds, $config_ldap->fields['basedn'], $input['ldap_filter'], $attribute);
$entries = ldap_get_entries($ds, $sn);
} catch (Exception $e) {
Session::addMessageAfterRedirect(__('Cannot recover LDAP informations!', 'formcreator'), false, ERROR);
}
restore_error_handler();
$input['values'] = json_encode(array('ldap_auth' => $input['ldap_auth'], 'ldap_filter' => $input['ldap_filter'], 'ldap_attribute' => strtolower($input['ldap_attribute'])));
}
}
// Add leading and trailing regex marker automaticaly
if (!empty($input['regex'])) {
if (substr($input['regex'], 0, 1) != '/') {
if (substr($input['regex'], 0, 1) != '^') {
//.........这里部分代码省略.........
示例6: showUserImportForm
static function showUserImportForm(AuthLDAP $authldap)
{
global $DB, $LANG;
//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'] ? $LANG['ldap'][1] : $LANG['ldap'][2]);
// Expert interface allow user to override configuration.
// If not coming from the ticket form, then give expert/simple link
if ((haveRight('config', 'w') || haveRight('entity', 'w')) && !isset($_SESSION['ldap_import']['no_expert_mode'])) {
echo "</span> <span class='ldap_right'>" . $LANG['common'][65] . " : ";
echo "<a href='" . $_SERVER['PHP_SELF'] . "?action=" . $_SESSION['ldap_import']['action'] . "&mode=" . $_SESSION['ldap_import']['mode'] . "&interface=" . ($_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE ? self::EXPERT_INTERFACE : self::SIMPLE_INTERFACE) . "'>" . ($_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE ? $LANG['ldap'][39] : $LANG['ldap'][40]) . "</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>" . $LANG['ldap'][4] . "</td><td colspan='3'>";
Dropdown::show('AuthLdap', array('name' => 'authldaps_id', 'value' => $_SESSION['ldap_import']['authldaps_id'], 'condition' => "`is_active` = '1'", 'display_emptychoice' => false));
echo " <input class='submit' type='submit' name='change_directory'\n value=\"" . $LANG['ldap'][41] . "\">";
echo "</td></tr>";
}
echo "<tr class='tab_bg_2'><td>Basedn</td><td colspan='3'>";
echo "<input type='text' name='basedn' value=\"" . $_SESSION['ldap_import']['basedn'] . "\" size='90' " . (!$_SESSION['ldap_import']['basedn'] ? "disabled" : "") . ">";
echo "</td></tr>";
echo "<tr class='tab_bg_2'><td>" . $LANG['setup'][263] . "</td><td colspan='3'>";
echo "<input type='text' 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 (isMultiEntitiesMode() && count($_SESSION['glpiactiveentities']) > 1) {
echo "<tr class='tab_bg_2'><td>" . $LANG['entity'][10] . "</td><td colspan='3'>";
Dropdown::show('Entity', array('value' => $_SESSION['ldap_import']['entities_id'], 'entity' => $_SESSION['glpiactiveentities'], 'auto_submit' => 1));
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']['days']) && $_SESSION['ldap_import']['days']) {
$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' => $LANG['login'][6], 'email_field' => $LANG['setup'][14], 'realname_field' => $LANG['common'][48], 'firstname_field' => $LANG['common'][43], 'phone_field' => $LANG['help'][35], 'phone2_field' => $LANG['help'][35] . " 2", 'mobile_field' => $LANG['common'][42], 'title_field' => $LANG['users'][1], 'category_field' => $LANG['users'][2]);
$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'>" . $LANG['ldap'][38] . "</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' 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=\"" . $LANG['buttons'][0] . "\">";
echo "</td></tr>";
} else {
echo "<tr class='tab_bg_2'><td colspan='4' class='center'>" . $LANG['ldap'][42] . "</td></tr>";
//.........这里部分代码省略.........
示例7: AuthLDAP
if (!defined('GLPI_ROOT')) {
include '../inc/includes.php';
}
Session::checkRight("import_externalauth_users", 'w');
// Need REQUEST to manage initial walues and posted ones
AuthLdap::manageValuesInSession($_REQUEST);
if (isset($_SESSION['ldap_import']['popup']) && $_SESSION['ldap_import']['popup']) {
Html::popHeader(__('LDAP directory link'), $_SERVER['PHP_SELF']);
} else {
Html::header(__('LDAP directory link'), $_SERVER['PHP_SELF'], "admin", "user", "ldap");
}
if (isset($_GET['start'])) {
$_SESSION['ldap_import']['start'] = $_GET['start'];
}
if (isset($_GET['order'])) {
$_SESSION['ldap_import']['order'] = $_GET['order'];
}
if ($_SESSION['ldap_import']['action'] == 'show') {
$authldap = new AuthLDAP();
$authldap->getFromDB($_SESSION['ldap_import']['authldaps_id']);
AuthLdap::showUserImportForm($authldap);
if (isset($_SESSION['ldap_import']['authldaps_id']) && $_SESSION['ldap_import']['authldaps_id'] != NOT_AVAILABLE && isset($_SESSION['ldap_import']['criterias']) && !empty($_SESSION['ldap_import']['criterias'])) {
echo "<br />";
AuthLdap::searchUser($authldap);
}
}
if (isset($_SESSION['ldap_import']['popup']) && $_SESSION['ldap_import']['popup']) {
Html::ajaxFooter();
} else {
Html::footer();
}
示例8: update0803to083
/**
* Update from 0.80.3 to 0.83
*
* @return bool for success (will die for most error)
**/
function update0803to083()
{
global $DB, $migration;
$updateresult = true;
$ADDTODISPLAYPREF = array();
//TRANS: %s is the number of new version
$migration->displayTitle(sprintf(__('Update to %s'), '0.83'));
$migration->setVersion('0.83');
$backup_tables = false;
$newtables = array('glpi_entities_knowbaseitems', 'glpi_entities_reminders', 'glpi_groups_problems', 'glpi_groups_knowbaseitems', 'glpi_groups_reminders', 'glpi_knowbaseitems_profiles', 'glpi_knowbaseitems_users', 'glpi_items_problems', 'glpi_problems', 'glpi_problemtasks', 'glpi_problems_ticket', 'glpi_problems_users', 'glpi_profiles_reminders', 'glpi_reminders_users', 'glpi_ticketrecurrents', 'glpi_tickettemplates', 'glpi_tickettemplatehiddenfields', 'glpi_tickettemplatemandatoryfields', 'glpi_tickettemplatepredefinedfields', 'glpi_useremails');
foreach ($newtables as $new_table) {
// rename new tables if exists ?
if (TableExists($new_table)) {
$migration->dropTable("backup_{$new_table}");
$migration->displayWarning("{$new_table} table already exists. " . "A backup have been done to backup_{$new_table}.");
$backup_tables = true;
$query = $migration->renameTable("{$new_table}", "backup_{$new_table}");
}
}
if ($backup_tables) {
$migration->displayWarning("You can delete backup tables if you have no need of them.", true);
}
//TRANS: %s is the table or item implied
$migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'Problems'));
// Clean ticket validations : already done in 0.80
$query = "DELETE\n FROM `glpi_ticketvalidations`\n WHERE `glpi_ticketvalidations`.`tickets_id` NOT IN (SELECT `glpi_tickets`.`id`\n FROM `glpi_tickets`)";
$DB->queryOrDie($query, "0.83 clean glpi_ticketvalidations");
// Problems management
if (!TableExists('glpi_problems')) {
$query = "CREATE TABLE `glpi_problems` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `name` varchar(255) DEFAULT NULL,\n `entities_id` int(11) NOT NULL DEFAULT '0',\n `is_recursive` tinyint(1) NOT NULL DEFAULT '0',\n `is_deleted` tinyint(1) NOT NULL DEFAULT '0',\n `status` varchar(255) DEFAULT NULL,\n `content` longtext DEFAULT NULL,\n `date_mod` DATETIME DEFAULT NULL,\n `date` DATETIME DEFAULT NULL,\n `solvedate` DATETIME DEFAULT NULL,\n `closedate` DATETIME DEFAULT NULL,\n `due_date` DATETIME DEFAULT NULL,\n `users_id_recipient` int(11) NOT NULL DEFAULT '0',\n `users_id_lastupdater` int(11) NOT NULL DEFAULT '0',\n `suppliers_id_assign` int(11) NOT NULL DEFAULT '0',\n `urgency` int(11) NOT NULL DEFAULT '1',\n `impact` int(11) NOT NULL DEFAULT '1',\n `priority` int(11) NOT NULL DEFAULT '1',\n `itilcategories_id` int(11) NOT NULL DEFAULT '0',\n `impactcontent` longtext DEFAULT NULL,\n `causecontent` longtext DEFAULT NULL,\n `symptomcontent` longtext DEFAULT NULL,\n `solutiontypes_id` int(11) NOT NULL DEFAULT '0',\n `solution` text COLLATE utf8_unicode_ci,\n `actiontime` int(11) NOT NULL DEFAULT '0',\n `begin_waiting_date` datetime DEFAULT NULL,\n `waiting_duration` int(11) NOT NULL DEFAULT '0',\n `close_delay_stat` int(11) NOT NULL DEFAULT '0',\n `solve_delay_stat` int(11) NOT NULL DEFAULT '0',\n `notepad` LONGTEXT NULL,\n PRIMARY KEY (`id`),\n KEY `name` (`name`),\n KEY `entities_id` (`entities_id`),\n KEY `is_recursive` (`is_recursive`),\n KEY `is_deleted` (`is_deleted`),\n KEY `date` (`date`),\n KEY `closedate` (`closedate`),\n KEY `status` (`status`(1)),\n KEY `priority` (`priority`),\n KEY `date_mod` (`date_mod`),\n KEY `suppliers_id_assign` (`suppliers_id_assign`),\n KEY `itilcategories_id` (`itilcategories_id`),\n KEY `users_id_recipient` (`users_id_recipient`),\n KEY `solvedate` (`solvedate`),\n KEY `solutiontypes_id` (`solutiontypes_id`),\n KEY `urgency` (`urgency`),\n KEY `impact` (`impact`),\n KEY `due_date` (`due_date`),\n KEY `users_id_lastupdater` (`users_id_lastupdater`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.83 create glpi_problems");
$ADDTODISPLAYPREF['Problem'] = array(21, 12, 19, 15, 3, 7, 18);
}
if (FieldExists('glpi_tickets', 'ticket_waiting_duration', false)) {
$migration->changeField('glpi_tickets', 'ticket_waiting_duration', 'waiting_duration', 'integer');
}
if (!TableExists('glpi_problems_users')) {
$query = "CREATE TABLE `glpi_problems_users` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `problems_id` int(11) NOT NULL DEFAULT '0',\n `users_id` int(11) NOT NULL DEFAULT '0',\n `type` int(11) NOT NULL DEFAULT '1',\n `use_notification` tinyint(1) NOT NULL DEFAULT '0',\n `alternative_email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY `unicity` (`problems_id`,`type`,`users_id`,`alternative_email`),\n KEY `user` (`users_id`,`type`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.83 add table glpi_problems_users");
}
if (!TableExists('glpi_groups_problems')) {
$query = "CREATE TABLE `glpi_groups_problems` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `problems_id` int(11) NOT NULL DEFAULT '0',\n `groups_id` int(11) NOT NULL DEFAULT '0',\n `type` int(11) NOT NULL DEFAULT '1',\n PRIMARY KEY (`id`),\n UNIQUE KEY `unicity` (`problems_id`,`type`,`groups_id`),\n KEY `group` (`groups_id`,`type`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.83 add table glpi_groups_problems");
}
if (!TableExists('glpi_items_problems')) {
$query = "CREATE TABLE `glpi_items_problems` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `problems_id` int(11) NOT NULL DEFAULT '0',\n `itemtype` varchar(100) default NULL,\n `items_id` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n UNIQUE KEY `unicity` (`problems_id`,`itemtype`,`items_id`),\n KEY `item` (`itemtype`,`items_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.83 add table glpi_items_problems");
}
if (!TableExists('glpi_problems_tickets')) {
$query = "CREATE TABLE `glpi_problems_tickets` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `problems_id` int(11) NOT NULL DEFAULT '0',\n `tickets_id` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n UNIQUE KEY `unicity` (`problems_id`,`tickets_id`),\n KEY `tickets_id` (`tickets_id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.83 add table glpi_problems_tickets");
}
if (!TableExists('glpi_problemtasks')) {
$query = "CREATE TABLE `glpi_problemtasks` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `problems_id` int(11) NOT NULL DEFAULT '0',\n `taskcategories_id` int(11) NOT NULL DEFAULT '0',\n `date` datetime DEFAULT NULL,\n `begin` datetime DEFAULT NULL,\n `end` datetime DEFAULT NULL,\n `users_id` int(11) NOT NULL DEFAULT '0',\n `users_id_tech` int(11) NOT NULL DEFAULT '0',\n `content` longtext COLLATE utf8_unicode_ci,\n `actiontime` int(11) NOT NULL DEFAULT '0',\n `state` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n KEY `problems_id` (`problems_id`),\n KEY `users_id` (`users_id`),\n KEY `users_id_tech` (`users_id_tech`),\n KEY `date` (`date`),\n KEY `begin` (`begin`),\n KEY `end` (`end`),\n KEY `state` (`state`),\n KEY `taskcategories_id` (taskcategories_id)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$DB->queryOrDie($query, "0.83 add table glpi_problemtasks");
}
$migration->addField("glpi_profiles", "show_my_problem", "char", array('update' => "1", 'condition' => " WHERE `own_ticket` = 1"));
$migration->addField("glpi_profiles", "show_all_problem", "char", array('update' => "1", 'condition' => " WHERE `show_all_ticket` = 1"));
$migration->addField("glpi_profiles", "edit_all_problem", "char", array('update' => "1", 'condition' => " WHERE `update_ticket` = 1"));
$migration->changeField("glpi_profiles", 'helpdesk_status', 'ticket_status', "text", array('comment' => "json encoded array of from/dest allowed status change"));
$migration->addField('glpi_profiles', 'problem_status', "text", array('comment' => "json encoded array of from/dest allowed status change"));
$migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'Changes'));
$migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'TicketPlanning'));
// Merge tickettasks and ticket planning
if (TableExists('glpi_ticketplannings')) {
$migration->addField("glpi_tickettasks", "begin", "datetime");
$migration->addField("glpi_tickettasks", "end", "datetime");
$migration->addField("glpi_tickettasks", "state", "integer", array('value' => '1'));
$migration->addField("glpi_tickettasks", "users_id_tech", "integer");
$migration->migrationOneTable('glpi_tickettasks');
// migrate DATA
$task = new TicketTask();
foreach ($DB->request('glpi_ticketplannings') as $data) {
if ($task->getFromDB($data['tickettasks_id'])) {
$query = "UPDATE `glpi_tickettasks`\n SET `begin` = " . ($data['begin'] == 'NULL' || is_null($data['begin']) ? 'NULL' : "'" . $data['begin'] . "'") . ",\n `end` = " . ($data['end'] == 'NULL' || is_null($data['end']) ? 'NULL' : "'" . $data['end'] . "'") . ",\n `users_id_tech` = '" . $data['users_id'] . "',\n `state` = '" . $data['state'] . "'\n WHERE `id` = '" . $data['tickettasks_id'] . "'";
$DB->queryOrDie($query, "0.83 migrate planning to glpi_tickettasks");
}
}
$migration->dropTable("glpi_ticketplannings");
$migration->displayMessage(sprintf(__('Change of the database layout - %s'), 'Notification'));
// Migrate templates
$from = array('task.planning.user##', 'task.planning.begin##', 'task.planning.end##', 'task.planning.status##');
$to = array('task.user##', 'task.begin##', 'task.end##', 'task.status##');
$query = "SELECT `glpi_notificationtemplatetranslations`.*\n FROM `glpi_notificationtemplatetranslations`\n INNER JOIN `glpi_notificationtemplates`\n ON (`glpi_notificationtemplates`.`id`\n = `glpi_notificationtemplatetranslations`.`notificationtemplates_id`)\n WHERE `glpi_notificationtemplates`.`itemtype` = 'Ticket'";
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$query = "UPDATE `glpi_notificationtemplatetranslations`\n SET `subject` = '" . addslashes(str_replace($from, $to, $data['subject'])) . "',\n `content_text` = '" . addslashes(str_replace($from, $to, $data['content_text'])) . "',\n `content_html` = '" . addslashes(str_replace($from, $to, $data['content_html'])) . "'\n WHERE `id` = " . $data['id'] . "";
$DB->queryOrDie($query, "0.83 fix tags usage for multi users");
}
}
}
}
$query = "SELECT *\n FROM `glpi_notificationtemplates`\n WHERE `name` = 'Problems'";
if ($result = $DB->query($query)) {
//.........这里部分代码省略.........
示例9: displayValue
public static function displayValue($value, $values)
{
if (!empty($values)) {
$ldap_values = json_decode($values);
$ldap_dropdown = new RuleRightParameter();
$ldap_dropdown->getFromDB($ldap_values->ldap_attribute);
$attribute = array($ldap_dropdown->fields['value']);
$config_ldap = new AuthLDAP();
$config_ldap->getFromDB($ldap_values->ldap_auth);
$ds = $config_ldap->connect();
$sn = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute);
$entries = ldap_get_entries($ds, $sn);
array_shift($entries);
$tab_values = array();
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];
}
}
sort($tab_values);
}
return $value != '' ? $tab_values[$value] : '';
}
示例10: plugin_moreldap_item_add_or_update_user
function plugin_moreldap_item_add_or_update_user($user)
{
//Ignore users without auths_id
if (!isset($user->input["auths_id"])) {
return;
}
// We update LDAP field only if LDAP directory is defined
if (isset($user->input["locations_id"])) {
return;
}
// default : store locations outside of any entity
$entityID = -1;
$pluginAuthLDAP = new PluginMoreldapAuthLDAP();
$authsId = isset($user->input["auths_id"]) ? $user->input["auths_id"] : $user->fields["auths_id"];
if ($authsId > 0 && $pluginAuthLDAP->getFromDBByQuery("WHERE `id`='{$authsId}'")) {
// The target entity for the locations to be created
$entityID = $pluginAuthLDAP->fields['entities_id'];
// find from config all attributes to read from LDAP
$fields = array();
$locationHierarchy = explode('>', $pluginAuthLDAP->fields['location']);
foreach ($locationHierarchy as $locationSubAttribute) {
$locationSubAttribute = trim($locationSubAttribute);
if (strlen($locationSubAttribute) > 0) {
$fields[] = $locationSubAttribute;
}
}
// LDAP query to read the needed attributes for the user
$ldap_connection = 0;
if (!isset($user->input["_ldap_conn"]) || !isset($user->fields["_ldap_conn"])) {
$ldap = new AuthLDAP();
$ldap->getFromDB($authsId);
$ldap_connection = $ldap->connect();
} else {
$ldap_connection = isset($user->input["_ldap_conn"]) ? $user->input["_ldap_conn"] : $user->fields["_ldap_conn"];
}
$userdn = isset($user->input["user_dn"]) ? $user->input["user_dn"] : $user->fields["user_dn"];
$userdn = str_replace('\\\\', '\\', $userdn);
$sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $fields);
if (!is_resource($sr) || ldap_errno($ldap_connection) > 0) {
return;
}
$v = AuthLDAP::get_entries_clean($ldap_connection, $sr);
//Find all locations needed to create the deepest one
$locationPath = array();
$incompleteLocation = false;
foreach ($fields as $locationSubAttribute) {
$locationSubAttribute = strtolower($locationSubAttribute);
if (isset($v[0][$locationSubAttribute][0])) {
$locationPath[] = $v[0][$locationSubAttribute][0];
} else {
// A LDAP attribute is not defined for the user. Cannot build the completename
// Therefore we must giveup importing this location
$incompleteLocation = true;
}
}
// TODO : test if location import is enabled earlier in this function
if ($pluginAuthLDAP->fields['location_enabled'] == 'Y') {
if ($incompleteLocation == false) {
$location = new Location();
$locationAncestor = 0;
$locationCompleteName = array();
$allLocationsExist = true;
// Assume we created or found all locations
// while ($locatinItem = array_shift($locationPath) && $allLocationsExist) {
foreach ($locationPath as $locationItem) {
if ($allLocationsExist) {
$locationCompleteName[] = $locationItem;
$locationItem = Toolbox::addslashes_deep(array('entities_id' => $entityID, 'name' => $locationItem, 'locations_id' => $locationAncestor, 'completename' => implode(' > ', $locationCompleteName), 'is_recursive' => $pluginAuthLDAP->fields['is_recursive'], 'comment' => __("Created by MoreLDAP", "moreldap")));
$locationAncestor = $location->findID($locationItem);
if ($locationAncestor == -1) {
// The location does not exists yet
$locationAncestor = $location->add($locationItem);
}
if ($locationAncestor == false) {
// If a location could not be imported and does not exist
// then give up importing children items
$allLocationsExist = false;
}
}
}
if ($allLocationsExist) {
// All locations exist to match the path described un LDAP
$locations_id = $locationAncestor;
$myuser = new User();
// new var to prevent user->input erasing (object are always passed by "reference")
$myuser->update(array('id' => $user->getID(), 'locations_id' => $locations_id));
}
}
} else {
// If the location retrieval is disabled, enablig this line will erase the location for the user.
// $fields['locations_id'] = 0;
}
}
}
示例11: addMessageAfterRedirect
} else {
addMessageAfterRedirect($LANG['login'][23], false, ERROR);
}
glpi_header($CFG_GLPI["root_doc"] . "/front/authldap.php?next=extauth_ldap&id=" . $newID);
}
}
glpi_header($_SERVER['HTTP_REFERER']);
} else {
if (isset($_POST["delete"])) {
$config_ldap->delete($_POST);
$_SESSION['glpi_authconfig'] = 1;
$config_ldap->redirectToList();
} else {
if (isset($_POST["test_ldap"])) {
$ldap = new AuthLDAP();
$ldap->getFromDB($_POST["id"]);
if (AuthLdap::testLDAPConnection($_POST["id"])) {
$_SESSION["LDAP_TEST_MESSAGE"] = $LANG['login'][22] . " (" . $LANG['ldap'][21] . " : " . $ldap->fields["name"] . ")";
} else {
$_SESSION["LDAP_TEST_MESSAGE"] = $LANG['login'][23] . " (" . $LANG['ldap'][21] . " : " . $ldap->fields["name"] . ")";
}
glpi_header($_SERVER['HTTP_REFERER']);
} else {
if (isset($_POST["test_ldap_replicate"])) {
foreach ($_POST["test_ldap_replicate"] as $replicate_id => $value) {
$replicate = new AuthLdapReplicate();
$replicate->getFromDB($replicate_id);
if (AuthLdap::testLDAPConnection($_POST["id"], $replicate_id)) {
$_SESSION["LDAP_TEST_MESSAGE"] = $LANG['login'][22] . " (" . $LANG['ldap'][19] . " : " . $replicate->fields["name"] . ")";
} else {
$_SESSION["LDAP_TEST_MESSAGE"] = $LANG['login'][23] . " (" . $LANG['ldap'][19] . " : " . $replicate->fields["name"] . ")";
示例12: showLdapDebug
/**
* Display information from LDAP server for user
**/
private function showLdapDebug()
{
global $LANG;
if ($this->fields['authtype'] != Auth::LDAP) {
return false;
}
echo "<div class='spaced'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr><th colspan='4'>" . $LANG['setup'][137] . ' - ' . $LANG['login'][2] . "</th></tr>";
echo "<tr class='tab_bg_2'><td>" . $LANG['ldap'][26] . " :</td>";
echo "<td>" . $this->fields['user_dn'] . "</td></tr>\n";
if ($this->fields['user_dn']) {
echo "<tr class='tab_bg_2'><td>" . $LANG['title'][13] . " :</td><td>";
$config_ldap = new AuthLDAP();
$ds = false;
if ($config_ldap->getFromDB($this->fields['auths_id'])) {
$ds = $config_ldap->connect();
}
if ($ds) {
$info = AuthLdap::getUserByDn($ds, $this->fields['user_dn'], array('*', 'createTimeStamp', 'modifyTimestamp'));
if (is_array($info)) {
printCleanArray($info);
} else {
echo $LANG['stats'][2];
}
} else {
echo $LANG['log'][41];
}
echo "</td></tr>\n";
}
echo "</table></div>";
}