Und noch ein Bug: renamed columns
[kivitendo-erp.git] / SL / User.pm
index ece1fb8..a49b3b5 100644 (file)
@@ -34,6 +34,8 @@
 
 package User;
 
 
 package User;
 
+#use strict;
+
 use IO::File;
 use Fcntl qw(:seek);
 
 use IO::File;
 use Fcntl qw(:seek);
 
@@ -92,6 +94,7 @@ sub login {
   $main::lxdebug->enter_sub();
 
   my ($self, $form) = @_;
   $main::lxdebug->enter_sub();
 
   my ($self, $form) = @_;
+  our $sid;
 
   local *FH;
 
 
   local *FH;
 
@@ -145,7 +148,12 @@ sub login {
       }
 
       # update the tables
       }
 
       # update the tables
-      open(FH, ">$main::userspath/nologin") or die("$!");
+      if (!open(FH, ">$main::userspath/nologin")) {
+        $form->show_generic_error($main::locale->text('A temporary file could not be created. ' .
+                                                      'Please verify that the directory "#1" is writeable by the webserver.',
+                                                      $main::userspath),
+                                  'back_button' => 1);
+      }
 
       # required for Oracle
       $form->{dbdefault} = $sid;
 
       # required for Oracle
       $form->{dbdefault} = $sid;
@@ -165,6 +173,7 @@ sub login {
       my $menufile =
         $self->{"menustyle"} eq "v3" ? "menuv3.pl" :
         $self->{"menustyle"} eq "neu" ? "menunew.pl" :
       my $menufile =
         $self->{"menustyle"} eq "v3" ? "menuv3.pl" :
         $self->{"menustyle"} eq "neu" ? "menunew.pl" :
+        $self->{"menustyle"} eq "js" ? "menujs.pl" :
         $self->{"menustyle"} eq "xml" ? "menuXML.pl" :
         "menu.pl";
 
         $self->{"menustyle"} eq "xml" ? "menuXML.pl" :
         "menu.pl";
 
@@ -311,6 +320,25 @@ sub dbsources {
   return @dbsources;
 }
 
   return @dbsources;
 }
 
+sub dbclusterencoding {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $form) = @_;
+
+  $form->{dbdefault} ||= $form->{dbuser};
+
+  dbconnect_vars($form, $form->{dbdefault});
+
+  my $dbh                = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) || $form->dberror();
+  my $query              = qq|SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'|;
+  my ($cluster_encoding) = $dbh->selectrow_array($query);
+  $dbh->disconnect();
+
+  $main::lxdebug->leave_sub();
+
+  return $cluster_encoding;
+}
+
 sub dbcreate {
   $main::lxdebug->enter_sub();
 
 sub dbcreate {
   $main::lxdebug->enter_sub();
 
@@ -526,6 +554,12 @@ sub process_query {
         $query .= $char;
       }
     }
         $query .= $char;
       }
     }
+
+    # Insert a space at the end of each line so that queries split
+    # over multiple lines work properly.
+    if ($query ne '') {
+      $query .= @quote_chars ? "\n" : ' ';
+    }
   }
 
   if (ref($version_or_control) eq "HASH") {
   }
 
   if (ref($version_or_control) eq "HASH") {
@@ -656,8 +690,8 @@ sub cmp_script_version {
   $my_a =~ s/.sql$//;
   $my_b =~ s/.*-upgrade-//;
   $my_b =~ s/.sql$//;
   $my_a =~ s/.sql$//;
   $my_b =~ s/.*-upgrade-//;
   $my_b =~ s/.sql$//;
-  ($my_a_from, $my_a_to) = split(/-/, $my_a);
-  ($my_b_from, $my_b_to) = split(/-/, $my_b);
+  my ($my_a_from, $my_a_to) = split(/-/, $my_a);
+  my ($my_b_from, $my_b_to) = split(/-/, $my_b);
 
   $res_a = calc_version($my_a_from);
   $res_b = calc_version($my_b_from);
 
   $res_a = calc_version($my_a_from);
   $res_b = calc_version($my_b_from);
@@ -768,7 +802,7 @@ sub dbupdate {
       last if ($version < $mindb);
 
       # apply upgrade
       last if ($version < $mindb);
 
       # apply upgrade
-      $main::lxdebug->message(DEBUG2, "Applying Update $upgradescript");
+      $main::lxdebug->message(LXDebug::DEBUG2, "Applying Update $upgradescript");
       if ($file_type eq "sql") {
         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
                              "-upgrade/$upgradescript", $str_maxdb, $db_charset);
       if ($file_type eq "sql") {
         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
                              "-upgrade/$upgradescript", $str_maxdb, $db_charset);
@@ -852,7 +886,7 @@ sub dbupdate2 {
       my $file_type = $1;
 
       # apply upgrade
       my $file_type = $1;
 
       # apply upgrade
-      $main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
+      $main::lxdebug->message(LXDebug::DEBUG2, "Applying Update $control->{file}");
       print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
 
       if ($file_type eq "sql") {
       print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
 
       if ($file_type eq "sql") {
@@ -910,6 +944,7 @@ sub save_member {
   $main::lxdebug->enter_sub();
 
   my ($self) = @_;
   $main::lxdebug->enter_sub();
 
   my ($self) = @_;
+  my $form   = \%main::form;
 
   # format dbconnect and dboptions string
   dbconnect_vars($self, $self->{dbname});
 
   # format dbconnect and dboptions string
   dbconnect_vars($self, $self->{dbname});
@@ -920,7 +955,7 @@ sub save_member {
 
   my $dbh = DBI->connect($self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd});
   if ($dbh) {
 
   my $dbh = DBI->connect($self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd});
   if ($dbh) {
-    $self->create_employee_entry($form, $dbh, $self);
+    $self->create_employee_entry($form, $dbh, $self, 1);
     $dbh->disconnect();
   }
 
     $dbh->disconnect();
   }
 
@@ -930,18 +965,28 @@ sub save_member {
 sub create_employee_entry {
   $main::lxdebug->enter_sub();
 
 sub create_employee_entry {
   $main::lxdebug->enter_sub();
 
-  my $self     = shift;
-  my $form     = shift;
-  my $dbh      = shift;
-  my $myconfig = shift;
+  my $self            = shift;
+  my $form            = shift;
+  my $dbh             = shift;
+  my $myconfig        = shift;
+  my $update_existing = shift;
+
+  if (!does_table_exist($dbh, 'employee')) {
+    $main::lxdebug->leave_sub();
+    return;
+  }
 
   # add login to employee table if it does not exist
   # no error check for employee table, ignore if it does not exist
 
   # add login to employee table if it does not exist
   # no error check for employee table, ignore if it does not exist
-  my ($login)  = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $self->{login});
+  my ($id)  = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $self->{login});
 
 
-  if (!$login) {
-    $query = qq|INSERT INTO employee (login, name, workphone, role) VALUES (?, ?, ?, ?)|;
+  if (!$id) {
+    my $query = qq|INSERT INTO employee (login, name, workphone, role) VALUES (?, ?, ?, ?)|;
     do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel}, "user"));
     do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel}, "user"));
+
+  } elsif ($update_existing) {
+    my $query = qq|UPDATE employee SET name = ?, workphone = ?, role = 'user' WHERE id = ?|;
+    do_query($form, $dbh, $query, $myconfig->{name}, $myconfig->{tel}, $id);
   }
 
   $main::lxdebug->leave_sub();
   }
 
   $main::lxdebug->leave_sub();
@@ -950,7 +995,7 @@ sub create_employee_entry {
 sub config_vars {
   $main::lxdebug->enter_sub();
 
 sub config_vars {
   $main::lxdebug->enter_sub();
 
-  my @conf = qw(acs address admin businessnumber company countrycode
+  my @conf = qw(address admin businessnumber company countrycode
     currency dateformat dbconnect dbdriver dbhost dbport dboptions
     dbname dbuser dbpasswd email fax name numberformat password
     printer role sid signature stylesheet tel templates vclimit angebote
     currency dateformat dbconnect dbdriver dbhost dbport dboptions
     dbname dbuser dbpasswd email fax name numberformat password
     printer role sid signature stylesheet tel templates vclimit angebote