]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Admin.pm
Merge branch 'master' of http://wagnertech.de/git/mfinanz
[mfinanz.git] / SL / Controller / Admin.pm
index e6200896cb6704d04b44d93a32d671a32cb2cc89..082b94ff8481987bcb46a742443cbd1473327ad1 100644 (file)
@@ -119,7 +119,7 @@ sub action_new_user {
       countrycode  => $defaults->language('de'),
       numberformat => $defaults->numberformat('1.000,00'),
       dateformat   => $defaults->dateformat('dd.mm.yy'),
-      stylesheet   => "kivitendo.css",
+      stylesheet   => "design40.css",
       menustyle    => "neu",
     },
   ));
@@ -137,6 +137,8 @@ sub action_save_user {
   my $params = delete($::form->{user})          || { };
   my $props  = delete($params->{config_values}) || { };
   my $is_new = !$params->{id};
+  my $check_previously_used = delete($::form->{check_previously_used}) || 0;
+  my $assign_documents = delete($::form->{assign_documents}) || 0;
 
   # Assign empty arrays if the browser doesn't send those controls.
   $params->{clients} ||= [];
@@ -149,9 +151,29 @@ sub action_save_user {
   my @errors = $self->user->validate;
 
   if (@errors) {
-    flash('error', @errors);
-    $self->edit_user_form(title => $is_new ? t8('Create a new user') : t8('Edit User'));
-    return;
+    $self->js->flash('error', $_) foreach @errors;
+    return $self->js->render();
+  }
+
+  # check if given login name was previously used and show a dialog if so
+  if ($is_new && $check_previously_used && $self->check_loginname_previously_used()) {
+    $self->js->run('show_loginname_previously_used_dialog');
+    return $self->js->render();
+  }
+
+  # rename previous usernames in employee table, if not set to assign
+  if ($is_new && !$assign_documents) {
+    my $clients = SL::DB::Manager::AuthClient->get_all_sorted;
+    for my $client (@$clients) {
+      my $now = DateTime->now_local;
+      my $timestamp = $now->format_cldr('yyyyMMddHHmmss');
+
+      my $dbh = $client->dbconnect(AutoCommit => 1);
+      next if !$dbh;
+      $dbh->do(qq|UPDATE employee SET login = ? WHERE login = ?;|,undef,
+               $params->{'login'} . $timestamp, $params->{'login'});
+      $dbh->disconnect;
+    }
   }
 
   $self->user->save;
@@ -505,7 +527,7 @@ sub init_all_groups        { SL::DB::Manager::AuthGroup ->get_all_sorted
 sub init_all_printers      { SL::DB::Manager::Printer   ->get_all_sorted                                                     }
 sub init_all_dateformats   { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd)      ]                                              }
 sub init_all_numberformats { [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ]                                    }
-sub init_all_stylesheets   { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ]                                              }
+sub init_all_stylesheets   { [ qw(lx-office-erp.css Mobile.css kivitendo.css design40.css) ]                                 }
 sub init_all_dbsources             { [ sort User->dbsources($::form)                               ] }
 sub init_all_used_dbsources        { { map { (join(':', $_->dbhost || 'localhost', $_->dbport || 5432, $_->dbname) => $_->name) } @{ $_[0]->all_clients }  } }
 sub init_all_accounting_methods    { [ { id => 'accrual',   name => t8('Accrual accounting')  }, { id => 'cash',     name => t8('Cash accounting')       } ] }
@@ -755,4 +777,22 @@ sub check_database_superuser_privileges {
   return (%result, error => $::locale->text('The database user \'#1\' does not have superuser privileges.', $result{username}));
 }
 
+sub check_loginname_previously_used() {
+  my ($self) = @_;
+
+  my $clients = SL::DB::Manager::AuthClient->get_all_sorted;
+  for my $client (@$clients) {
+    my $dbh = $client->dbconnect();
+    next if !$dbh;
+    my ($result) = $dbh->selectrow_array(qq|SELECT login FROM employee WHERE login = ?;|,undef,
+                                        $self->user->{'login'});
+    $dbh->disconnect;
+
+    if ($result) {
+      return 1;
+    }
+  }
+  return 0;
+}
+
 1;