Skip to content

Commit

Permalink
fix ui of users ldap import
Browse files Browse the repository at this point in the history
  • Loading branch information
orthagh authored and cedric-anne committed Sep 21, 2021
1 parent af3c6ef commit c61868b
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 84 deletions.
15 changes: 5 additions & 10 deletions front/ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* ---------------------------------------------------------------------
*/

use Glpi\Application\View\TemplateRenderer;

include ('../inc/includes.php');

Session::checkRight("user", User::IMPORTEXTAUTHUSERS);
Expand All @@ -41,16 +43,9 @@
}

AuthLDAP::manageValuesInSession([], true);
echo "<div class='center'><table class='tab_cadre'>";
echo "<tr><th>".__('Bulk import users from a LDAP directory')."</th></tr>";

echo "<tr class='tab_bg_1'><td class='center b'>".
"<a href='ldap.import.php?mode=1&action=show'>". __('Synchronizing already imported users').
"</a></td></tr>";

echo "<tr class='tab_bg_1'><td class='center b'>".
"<a href='ldap.import.php?mode=0&action=show'>". __('Import new users')."</a></td> </tr>";

echo "</table></div>";
echo TemplateRenderer::getInstance()->render(
'pages/admin/users_ldap.html.twig'
);

Html::footer();
125 changes: 73 additions & 52 deletions inc/authldap.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,7 @@ static function showLdapUsers() {
$numrows = count($ldap_users);

if ($numrows > 0) {
echo "<div class='card'>";
self::displaySizeLimitWarning($limitexceeded);

Html::printPager($values['start'], $numrows, $_SERVER['PHP_SELF'], '');
Expand All @@ -1586,13 +1587,17 @@ static function showLdapUsers() {
}

Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams = ['num_displayed' => min(count($ldap_users),
$_SESSION['glpilist_limit']),
'container' => 'mass'.__CLASS__.$rand,
'specific_actions' => [$form_action => $textbutton]];
$massiveactionparams = [
'num_displayed' => min(count($ldap_users), $_SESSION['glpilist_limit']),
'container' => 'mass'.__CLASS__.$rand,
'specific_actions' => [$form_action => $textbutton]
];
echo "<div class='ms-2 ps-1 d-flex mb-2'>";
Html::showMassiveActions($massiveactionparams);
echo "</div>";

echo "<table class='tab_cadre_fixe'>";
echo "<table class='table card-table'>";
echo "<thead>";
echo "<tr>";
echo "<th width='10'>";
echo Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
Expand All @@ -1611,9 +1616,10 @@ static function showLdapUsers() {
echo "<th>".__('Last update in GLPI')."</th>";
}
echo "</tr>";
echo "</thead>";

foreach ($ldap_users as $userinfos) {
echo "<tr class='tab_bg_2 center'>";
echo "<tr>";
//Need to use " instead of ' because it doesn't work with names with ' inside !
echo "<td>";
echo Html::getMassiveActionCheckBox(__CLASS__, $userinfos['uid']);
Expand Down Expand Up @@ -1641,6 +1647,7 @@ static function showLdapUsers() {
}
echo "</tr>";
}
echo "<tfoot>";
echo "<tr>";
echo "<th width='10'>";
echo Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
Expand All @@ -1660,13 +1667,19 @@ static function showLdapUsers() {
echo "<th>".__('Last update in GLPI')."</th>";
}
echo "</tr>";
echo "</tfoot>";
echo "</table>";

$massiveactionparams['ontop'] = false;
echo "<div class='ms-2 ps-1 mt-2 d-flex'>";
Html::showMassiveActions($massiveactionparams);
echo "</div>";

Html::closeForm();

Html::printPager($values['start'], $numrows, $_SERVER['PHP_SELF'], '');

echo "</div>";
} else {
echo "<div class='center b'>".
($_SESSION['ldap_import']['mode']?__('No user to be synchronized')
Expand Down Expand Up @@ -3235,14 +3248,10 @@ static function showUserImportForm(AuthLDAP $authldap) {

//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')
echo "<h2 class='center mb-3'>" .($_SESSION['ldap_import']['mode']?__('Synchronizing already imported users')
:__('Import new users'));

// Expert interface allow user to override configuration.
Expand All @@ -3252,7 +3261,7 @@ static function showUserImportForm(AuthLDAP $authldap) {
&& (!isset($_SESSION['ldap_import']['no_expert_mode'])
|| $_SESSION['ldap_import']['no_expert_mode'] != 1)) {

echo "</span>&nbsp;<span class='float-end'><a href='".$_SERVER['PHP_SELF']."?action=".
echo "<a class='float-end btn btn-secondary' href='".$_SERVER['PHP_SELF']."?action=".
$_SESSION['ldap_import']['action']."&amp;mode=".$_SESSION['ldap_import']['mode'];

if ($_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE) {
Expand All @@ -3263,8 +3272,10 @@ static function showUserImportForm(AuthLDAP $authldap) {
} else {
$_SESSION['ldap_import']['interface'] = self::SIMPLE_INTERFACE;
}
echo "</span></div>";
echo "</th></tr>";
echo "</h2>";

echo "<div class='card'>";
echo "<table class='table card-table'>";

switch ($_SESSION['ldap_import']['interface']) {
case self::EXPERT_INTERFACE :
Expand All @@ -3275,26 +3286,26 @@ static function showUserImportForm(AuthLDAP $authldap) {

if (self::getNumberOfServers() > 1) {
$rand = mt_rand();
echo "<tr class='tab_bg_2'><td><label for='dropdown_authldaps_id$rand'>".__('LDAP directory choice')."</label></td>";
echo "<tr><td class='text-end'><label for='dropdown_authldaps_id$rand'>".__('LDAP directory choice')."</label></td>";
echo "<td colspan='3'>";
self::dropdown(['name' => 'authldaps_id',
'value' => $_SESSION['ldap_import']['authldaps_id'],
'condition' => ['is_active' => 1],
'display_emptychoice' => false,
'rand' => $rand]);
echo "&nbsp;<input class='btn btn-primary' type='submit' name='change_directory'
echo "&nbsp;<input class='btn btn-secondary' type='submit' name='change_directory'
value=\""._sx('button', 'Change')."\">";
echo "</td></tr>";
}

echo "<tr class='tab_bg_2'><td><label for='basedn'>".__('BaseDN')."</label></td><td colspan='3'>";
echo "<input type='text' id='basedn' name='basedn' value=\"".$_SESSION['ldap_import']['basedn'].
"\" size='90' ".(!$_SESSION['ldap_import']['basedn']?"disabled":"").">";
echo "<tr><td style='width: 250px' class='text-end'><label for='basedn'>".__('BaseDN')."</label></td><td colspan='3'>";
echo "<input type='text' class='form-control' id='basedn' name='basedn' value=\"".$_SESSION['ldap_import']['basedn'].
"\" ".(!$_SESSION['ldap_import']['basedn']?"disabled":"").">";
echo "</td></tr>";

echo "<tr class='tab_bg_2'><td><label for='ldap_filter'>".__('Search filter for users')."</label></td><td colspan='3'>";
echo "<input type='text' id='ldap_filter' name='ldap_filter' value=\"".
$_SESSION['ldap_import']['ldap_filter']."\" size='90'>";
echo "<tr><td class='text-end'><label for='ldap_filter'>".__('Search filter for users')."</label></td><td colspan='3'>";
echo "<input type='text' class='form-control' id='ldap_filter' name='ldap_filter' value=\"".
$_SESSION['ldap_import']['ldap_filter']."\">";
echo "</td></tr>";
}
break;
Expand All @@ -3303,14 +3314,18 @@ static function showUserImportForm(AuthLDAP $authldap) {
default :
if (self::getNumberOfServers() > 1) {
$rand = mt_rand();
echo "<tr class='tab_bg_2'><td><label for='dropdown_authldaps_id$rand'>".__('LDAP directory choice')."</label></td>";
echo "<td colspan='3'>";
self::dropdown(['name' => 'authldaps_id',
'value' => $_SESSION['ldap_import']['authldaps_id'],
'condition' => ['is_active' => 1],
'display_emptychoice' => false,
'rand' => $rand]);
echo "&nbsp;<input class='btn btn-primary' type='submit' name='change_directory'
echo "<tr><td style='width: 250px' class='text-end'>
<label for='dropdown_authldaps_id$rand'>".__('LDAP directory choice')."</label>
</td>";
echo "<td>";
self::dropdown([
'name' => 'authldaps_id',
'value' => $_SESSION['ldap_import']['authldaps_id'],
'condition' => ['is_active' => 1],
'display_emptychoice' => false,
'rand' => $rand
]);
echo "&nbsp;<input class='btn btn-secondary' type='submit' name='change_directory'
value=\""._sx('button', 'Change')."\">";
echo "</td></tr>";
}
Expand All @@ -3319,11 +3334,13 @@ static function showUserImportForm(AuthLDAP $authldap) {
//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(['value' => $_SESSION['ldap_import']['entities_id'],
'entity' => $_SESSION['glpiactiveentities'],
'on_change' => 'this.form.submit()']);
echo "<tr><td class='text-end'>".__('Select the desired entity')."</td>".
"<td>";
Entity::dropdown([
'value' => $_SESSION['ldap_import']['entities_id'],
'entity' => $_SESSION['glpiactiveentities'],
'on_change' => 'this.form.submit()'
]);
echo "</td></tr>";
} else {
//Only one entity is active, store it
Expand All @@ -3341,7 +3358,7 @@ static function showUserImportForm(AuthLDAP $authldap) {
}
Dropdown::showAdvanceDateRestrictionSwitch($enabled);

echo "<table class='tab_cadre_fixe'>";
echo "<table class='table card-table'>";

if (($_SESSION['ldap_import']['authldaps_id'] != NOT_AVAILABLE)
&& ($_SESSION['ldap_import']['authldaps_id'] > 0)) {
Expand Down Expand Up @@ -3370,18 +3387,18 @@ static function showUserImportForm(AuthLDAP $authldap) {
$available_fields[$field] = $label;
}
}
echo "<tr><th colspan='4'>" . __('Search criteria for users') . "</th></tr>";
echo "<tr><td colspan='4' class='border-bottom-0'><h4>" . __('Search criteria for users') . "</h4></td></tr>";
foreach ($available_fields as $field => $label) {
if ($field_counter == 0) {
echo "<tr class='tab_bg_1'>";
echo "<tr>";
}
echo "<td><label for='criterias$field'>$label</label></td><td>";
echo "<td style='width: 250px' class='text-end'><label for='criterias$field'>$label</label></td><td>";
$field_counter++;
$field_value = '';
if (isset($_SESSION['ldap_import']['criterias'][$field])) {
$field_value = Html::entities_deep(Sanitizer::unsanitize($_SESSION['ldap_import']['criterias'][$field], true));
}
echo "<input type='text' id='criterias$field' name='criterias[$field]' value='$field_value'>";
echo "<input type='text' class='form-control' id='criterias$field' name='criterias[$field]' value='$field_value'>";
echo "</td>";
if ($field_counter == 2) {
echo "</tr>";
Expand Down Expand Up @@ -3418,8 +3435,8 @@ static function showUserImportForm(AuthLDAP $authldap) {
__('No directory associated to entity: impossible search')."</td></tr>";
}
echo "</table>";
Html::closeForm();
echo "</div>";
Html::closeForm();
}

/**
Expand Down Expand Up @@ -3668,32 +3685,36 @@ static function getServersWithImportByEmailActive() {
*/
static function showDateRestrictionForm($options = []) {

echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'>";
echo "<table class='table'>";
echo "<tr>";

$enabled = (isset($options['enabled'])?$options['enabled']:false);
if (!$enabled) {
echo "<td colspan='4' class='center'>";
echo "<a href='#' onClick='activateRestriction()'>".__('Enable filtering by date')."</a>";
echo "<td colspan='4'>";
echo "<a href='#' class='btn btn-outline-secondary' onClick='activateRestriction()'>
<i class='fas fa-toggle-off me-1'></i>
".__('Enable filtering by date')."
</a>";
echo "</td></tr>";
}
if ($enabled) {
echo "<td>".__('View updated users')."</td>";
echo "<td>".__('from')."</td>";
echo "<td>";
echo "<td style='width: 250px' class='text-end border-bottom-0'>".__('View updated users')."</td>";
echo "<td class='border-bottom-0'>".__('from')."";
$begin_date = (isset($_SESSION['ldap_import']['begin_date'])
?$_SESSION['ldap_import']['begin_date'] :'');
Html::showDateTimeField("begin_date", ['value' => $begin_date]);
echo "</td>";
echo "<td>".__('to')."</td>";
echo "<td>";
echo "<td class='border-bottom-0'>".__('to')."";
$end_date = (isset($_SESSION['ldap_import']['end_date'])
?$_SESSION['ldap_import']['end_date']
:date('Y-m-d H:i:s', time()-DAY_TIMESTAMP));
Html::showDateTimeField("end_date", ['value' => $end_date]);
echo "</td></tr>";
echo "<tr class='tab_bg_2'><td colspan='4' class='center'>";
echo "<a href='#' onClick='deactivateRestriction()'>".__('Disable filtering by date')."</a>";
echo "<tr><td colspan='4'>";
echo "<a href='#' class='btn btn-outline-secondary' onClick='deactivateRestriction()'>
<i class='fas fa-toggle-on me-1'></i>
".__('Disable filtering by date')."
</a>";
echo "</td></tr>";
}
echo "</table>";
Expand Down
8 changes: 4 additions & 4 deletions inc/dropdown.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1728,13 +1728,13 @@ static function showAdvanceDateRestrictionSwitch($enabled = 0) {

$rand = mt_rand();
$url = $CFG_GLPI["root_doc"]."/ajax/ldapdaterestriction.php";
echo "<script type='text/javascript' >\n";
echo "function activateRestriction() {\n";
echo "<script type='text/javascript' >";
echo "function activateRestriction() {";
$params = ['enabled'=> 1];
Ajax::updateItemJsCode('date_restriction', $url, $params);
echo "};";

echo "function deactivateRestriction() {\n";
echo "function deactivateRestriction() {";
$params = ['enabled' => 0];
Ajax::updateItemJsCode('date_restriction', $url, $params);
echo "};";
Expand All @@ -1744,7 +1744,7 @@ static function showAdvanceDateRestrictionSwitch($enabled = 0) {
echo "<span id='date_restriction'>";
$_POST['enabled'] = $enabled;
include (GLPI_ROOT."/ajax/ldapdaterestriction.php");
echo "</span>\n";
echo "</span>";
return $rand;
}

Expand Down
37 changes: 19 additions & 18 deletions inc/html.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4049,7 +4049,7 @@ static function printPager($start, $numrows, $target, $parameters, $item_type_ou
}

// Print it
echo "<div><table class='tab_cadre_pager'>";
echo "<div><table class='table align-middle'>";
echo "<tr>";

if (strpos($target, '?') == false) {
Expand All @@ -4060,13 +4060,13 @@ static function printPager($start, $numrows, $target, $parameters, $item_type_ou
// Back and fast backward button
if (!$start == 0) {
echo "<th class='left'>";
echo "<a href='$fulltarget&amp;start=0'>";
echo "
<i class='fa fa-step-backward' title=\"".__s('Start')."\"></i>";
echo "</a></th>";
echo "<th class='left'>";
echo "<a href='$fulltarget&amp;start=$back'>";
echo "<i class='fa fa-chevron-left' title=\"".__s('Previous')."\"></i>";
echo "<a href='$fulltarget&amp;start=0' class='btn btn-sm btn-ghost-secondary me-2'
title=\"".__s('Start')."\" data-bs-toggle='tooltip' data-bs-placement='top'>";
echo "<i class='fa fa-step-backward'></i>";
echo "</a>";
echo "<a href='$fulltarget&amp;start=$back' class='btn btn-sm btn-ghost-secondary me-2'
title=\"".__s('Previous')."\" data-bs-toggle='tooltip' data-bs-placement='top'>";
echo "<i class='fa fa-chevron-left'></i>";
echo "</a></th>";
}

Expand Down Expand Up @@ -4113,22 +4113,23 @@ static function printPager($start, $numrows, $target, $parameters, $item_type_ou
echo "</td>";
}

echo "<td width='20%' class='tab_bg_2 b'>";
echo "<td width='20%' class='b'>";
//TRANS: %1$d, %2$d, %3$d are page numbers
printf(__('From %1$d to %2$d of %3$d'), $current_start, $current_end, $numrows);
echo "</td>\n";
echo "</td>";

// Forward and fast forward button
if ($forward<$numrows) {
echo "<th class='right'>";
echo "<a href='$fulltarget&amp;start=$forward'>
<i class='fa fa-chevron-right' title=\"".__s('Next')."\">";
echo "</a></th>\n";

echo "<th class='right'>";
echo "<a href='$fulltarget&amp;start=$end'>";
echo "<i class='fa fa-step-forward' title=\"".__s('End')."\"></i>";
echo "</a></th>\n";
echo "<a href='$fulltarget&amp;start=$forward' class='btn btn-sm btn-ghost-secondary'
title=\"".__s('Next')."\" data-bs-toggle='tooltip' data-bs-placement='top'>
<i class='fa fa-chevron-right'></i>";
echo "</a>";
echo "<a href='$fulltarget&amp;start=$end' class='btn btn-sm btn-ghost-secondary'
title=\"".__s('End')."\" data-bs-toggle='tooltip' data-bs-placement='top'>";
echo "<i class='fa fa-step-forward'></i>";
echo "</a>";
echo "</th>";
}
// End pager
echo "</tr></table></div>";
Expand Down
Loading

0 comments on commit c61868b

Please sign in to comment.