Pflichtenhefte: Fehler beim Anlegen von Versionen richtig abfangen
[kivitendo-erp.git] / SL / Controller / Admin.pm
index bcc9436..c2d9f29 100644 (file)
@@ -15,6 +15,7 @@ use SL::Helper::Flash;
 use SL::Locale::String qw(t8);
 use SL::System::InstallationLock;
 use SL::User;
+use SL::Layout::AdminLogin;
 
 use Rose::Object::MakeMethods::Generic
 (
@@ -166,6 +167,10 @@ sub action_delete_user {
 
   my @clients = @{ $self->user->clients || [] };
 
+  # backup user metadata (email, name, etc)
+  my $user_config_values_ref = $self->user->config_values();
+  my $login =$self->user->login;
+
   if (!$self->user->delete) {
     flash('error', t8('The user could not be deleted.'));
     $self->edit_user_form(title => t8('Edit User'));
@@ -173,9 +178,15 @@ sub action_delete_user {
   }
 
   # Flag corresponding entries in 'employee' as deleted.
+  # and restore the most important user data in employee
+  # TODO try and catch the whole transaction {user->delete; update employee} {exception}
   foreach my $client (@clients) {
     my $dbh = $client->dbconnect(AutoCommit => 1) || next;
-    $dbh->do(qq|UPDATE employee SET deleted = TRUE WHERE login = ?|, undef, $self->user->login);
+    $dbh->do(qq|UPDATE employee SET deleted = TRUE, name = ?, deleted_email = ?,
+                deleted_tel = ?, deleted_fax = ?, deleted_signature = ? WHERE login = ?|,undef,
+              $user_config_values_ref->{name}, $user_config_values_ref->{email},
+              $user_config_values_ref->{tel}, $user_config_values_ref->{fax},
+              $user_config_values_ref->{signature}, $self->user->login);
     $dbh->disconnect;
   }
 
@@ -378,16 +389,13 @@ sub action_delete_printer {
 # actions: database administration
 #
 
-sub action_database_administration {
+sub action_create_dataset_login {
   my ($self) = @_;
 
-  $::form->{dbhost}    ||= $::auth->{DB_config}->{host} || 'localhost';
-  $::form->{dbport}    ||= $::auth->{DB_config}->{port} || 5432;
-  $::form->{dbuser}    ||= $::auth->{DB_config}->{user} || 'kivitendo';
-  $::form->{dbpasswd}  ||= $::auth->{DB_config}->{password};
-  $::form->{dbdefault} ||= 'template1';
-
-  $self->render('admin/dbadmin', title => t8('Database Administration'));
+  $self->database_administration_login_form(
+    title       => t8('Create Dataset'),
+    next_action => 'create_dataset',
+  );
 }
 
 sub action_create_dataset {
@@ -411,7 +419,16 @@ sub action_do_create_dataset {
   User->new->dbcreate($::form);
 
   flash_later('info', t8("The dataset #1 has been created.", $::form->{db}));
-  $self->redirect_to(action => 'database_administration');
+  $self->redirect_to(action => 'show');
+}
+
+sub action_delete_dataset_login {
+  my ($self) = @_;
+
+  $self->database_administration_login_form(
+    title       => t8('Delete Dataset'),
+    next_action => 'delete_dataset',
+  );
 }
 
 sub action_delete_dataset {
@@ -433,13 +450,22 @@ sub action_do_delete_dataset {
   User->new->dbdelete($::form);
 
   flash_later('info', t8("The dataset #1 has been deleted.", $::form->{db}));
-  $self->redirect_to(action => 'database_administration');
+  $self->redirect_to(action => 'show');
 }
 
 #
 # actions: locking, unlocking
 #
 
+sub action_show_lock {
+  my ($self) = @_;
+
+  $self->render(
+    "admin/show_lock",
+    title => "kivitendo " . t8('Administration'),
+  );
+}
+
 sub action_unlock_system {
   my ($self) = @_;
 
@@ -451,7 +477,7 @@ sub action_unlock_system {
 sub action_lock_system {
   my ($self) = @_;
 
-  SL::System::InstallationLock->unlock;
+  SL::System::InstallationLock->lock;
   flash_later('info', t8('Lockfile created!'));
   $self->redirect_to(action => 'show');
 }
@@ -472,7 +498,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'   ]                                              }
-sub init_all_stylesheets   { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ]                                              }
+sub init_all_stylesheets   { [ qw(lx-office-erp.css kivitendo.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')       } ] }
@@ -532,7 +558,6 @@ sub setup_layout {
   my ($self, $action) = @_;
 
   $::request->layout(SL::Layout::Dispatcher->new(style => 'admin'));
-  $::request->layout->use_stylesheet("lx-office-erp.css");
   $::form->{favicon} = "favicon.ico";
   %::myconfig        = (
     countrycode      => 'de',
@@ -544,11 +569,10 @@ sub setup_layout {
 sub setup_client {
   my ($self) = @_;
 
-  $self->client((first { $_->is_default } @{ $self->all_clients }) || $self->all_clients->[0]) if !$self->client;
+  $self->client(SL::DB::Manager::AuthClient->get_default || $self->all_clients->[0]) if !$self->client;
   $::auth->set_client($self->client->id);
 }
 
-
 #
 # displaying forms
 #
@@ -562,6 +586,7 @@ sub use_multiselect_js {
 
 sub login_form {
   my ($self, %params) = @_;
+  $::request->layout(SL::Layout::AdminLogin->new);
   my $version         = $::form->read_version;
   $self->render('admin/adminlogin', title => t8('kivitendo v#1 administration', $version), %params, version => $version);
 }
@@ -586,6 +611,20 @@ sub edit_printer_form {
   $self->render('admin/edit_printer', %params);
 }
 
+sub database_administration_login_form {
+  my ($self, %params) = @_;
+
+  $self->render(
+    'admin/dbadmin',
+    dbhost    => $::form->{dbhost}    || $::auth->{DB_config}->{host} || 'localhost',
+    dbport    => $::form->{dbport}    || $::auth->{DB_config}->{port} || 5432,
+    dbuser    => $::form->{dbuser}    || $::auth->{DB_config}->{user} || 'kivitendo',
+    dbpasswd  => $::form->{dbpasswd}  || $::auth->{DB_config}->{password},
+    dbdefault => $::form->{dbdefault} || 'template1',
+    %params,
+  );
+}
+
 sub create_dataset_form {
   my ($self, %params) = @_;
   $self->render('admin/create_dataset', title => (t8('Database Administration') . " / " . t8('Create Dataset')));