|
|
@@ -35,7 +35,7 @@ class Route_FixUsersLongLogin extends RouteBase {
|
|
|
<th>Status</th>
|
|
|
<th>Data synch.</th>
|
|
|
<th>Nowy login</th>
|
|
|
- <th>Synch. nowy login</th>
|
|
|
+ <th>Update Login and Sync.</th>
|
|
|
</tr>
|
|
|
<?php $i = 0; foreach ($usersTodoList as $user) : $i++ ?>
|
|
|
<?php
|
|
|
@@ -60,7 +60,9 @@ class Route_FixUsersLongLogin extends RouteBase {
|
|
|
<td><?php echo $user->A_SYNC_LDAP_DATE; ?></td>
|
|
|
<td style="font-family:monospace;color:green;"><?php echo $newLogin; ?></td>
|
|
|
<td><a target="_blank"
|
|
|
- href="https://biuro.biall-net.pl/SE/version-git/index.php?MENU_INIT=SYNC_LDAP_PERMS&syncUsr=<?php echo $newLogin; ?>">synchronizuj do LDAP (<?php echo $newLogin; ?>)</td>
|
|
|
+ class="btn btn-xs btn-primary"
|
|
|
+ title="Aktualizuj Login z <?php echo $user->ADM_ACCOUNT; ?> na <?php echo $newLogin; ?> i uruchom synchronizcję do LDAP"
|
|
|
+ href="index.php?_route=FixUsersLongLogin&_task=updateLoginAndSync¤tLogin=<?php echo $user->ADM_ACCOUNT; ?>&newLogin=<?php echo $newLogin; ?>">Update and sync.</td>
|
|
|
</tr>
|
|
|
<?php endforeach; ?>
|
|
|
</table>
|
|
|
@@ -86,4 +88,94 @@ SQL;
|
|
|
return $usersTodoList;
|
|
|
}
|
|
|
|
|
|
+ public function getUserByLogin($login) {
|
|
|
+ $user = null;
|
|
|
+ $db = DB::getDB();
|
|
|
+ $sqlLogin = $db->_($login);
|
|
|
+ $sql = <<<SQL
|
|
|
+ select `ID`, `ADM_ACCOUNT`, `A_STATUS`
|
|
|
+ , `ADM_ADMIN_LEVEL`
|
|
|
+ , `A_SYNC_LDAP_DATE`
|
|
|
+ from `ADMIN_USERS`
|
|
|
+ where `ADM_ACCOUNT`='{$sqlLogin}'
|
|
|
+SQL;
|
|
|
+ $res = $db->query($sql);
|
|
|
+ if ($r = $db->fetch($res)) {
|
|
|
+ $user = $r;
|
|
|
+ }
|
|
|
+ return $user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updateLoginAndSyncAction() {
|
|
|
+ $currentLogin = V::get('currentLogin', '', $_REQUEST, 'word');
|
|
|
+ $newLogin = V::get('newLogin', '', $_REQUEST, 'word');
|
|
|
+ $user = $this->getUserByLogin($currentLogin);
|
|
|
+
|
|
|
+ SE_Layout::gora();
|
|
|
+ ?>
|
|
|
+<div class="container">
|
|
|
+ <?php if (!$user) : ?>
|
|
|
+ <div class="alert alert-danger">
|
|
|
+ Brak użytkownika z loginem <?php echo $currentLogin; ?>
|
|
|
+ </div>
|
|
|
+ <?php else : ?>
|
|
|
+ <div class="alert alert-info">
|
|
|
+ Zmiana loginu z <?php echo $currentLogin; ?> na <?php echo $newLogin; ?>
|
|
|
+ </div>
|
|
|
+ <?php
|
|
|
+ try {
|
|
|
+ $affected = $this->updateLogin($user, $currentLogin, $newLogin);
|
|
|
+ if ($affected == 2) {
|
|
|
+ echo '<div class="alert alert-success">' . "Login został poprawnie zmieniony na '{$newLogin}'" . '</div>';
|
|
|
+ } else if ($affected == 1) {
|
|
|
+ echo '<div class="alert alert-warning">' . "Nie zapisano hist" . '</div>';
|
|
|
+ } else if ($affected == 0) {
|
|
|
+ echo '<div class="alert alert-info">' . "Nic nie zmieniono" . '</div>';
|
|
|
+ }
|
|
|
+ } catch (Exception $e) { ?>
|
|
|
+ <div class="alert alert-danger">
|
|
|
+ <?php echo $e->getMessage(); ?>
|
|
|
+ </div>
|
|
|
+ <?php } ?>
|
|
|
+ <a class="btn btn-primary"
|
|
|
+ href="index.php?MENU_INIT=SYNC_LDAP_PERMS&syncUsr=<?php echo $newLogin; ?>">Synchronizuj do LDAP (<?php echo $newLogin; ?>)</a>
|
|
|
+ <?php endif; ?>
|
|
|
+</div>
|
|
|
+<?php
|
|
|
+ SE_Layout::dol();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function updateLogin($user, $currentLogin, $newLogin) {
|
|
|
+ $db = DB::getDB();
|
|
|
+
|
|
|
+ if ($currentLogin != $user->ADM_ACCOUNT) {
|
|
|
+ throw new Exception("Error: User ADM_ACCOUNT != '{$currentLogin}'");
|
|
|
+ }
|
|
|
+
|
|
|
+ $sqlObj = new stdClass();
|
|
|
+ $sqlObj->ID = $user->ID;
|
|
|
+ $sqlObj->ADM_ACCOUNT = $newLogin;
|
|
|
+
|
|
|
+ $affected = $db->UPDATE_OBJ('ADMIN_USERS', $sqlObj);
|
|
|
+ if ($affected < 0) {
|
|
|
+ if ($db->has_errors()) {
|
|
|
+ $dsErrors = array();
|
|
|
+ $errorsSql = $db->get_errors();
|
|
|
+ foreach ($errorsSql as $vErr) {
|
|
|
+ if ('SQL QUERY FAILED: ' == substr($vErr, 0, 18)) {
|
|
|
+ $vErr = substr($vErr, 18);
|
|
|
+ }
|
|
|
+ $dsErrors[] = $vErr;
|
|
|
+ }
|
|
|
+ if (!empty($dsErrors)) {
|
|
|
+ Lib::loadClass('StorageException');
|
|
|
+ throw new StorageException($dsErrors);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Exception("Error: nic nie zmieniono");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $affected;
|
|
|
+ }
|
|
|
+
|
|
|
}
|