Merge branch 'after-262'
[kivitendo-erp.git] / bin / mozilla / am.pl
index fe9199e..bcf934e 100644 (file)
 #
 #======================================================================
 
+use utf8;
+
 use SL::Auth;
+use SL::Auth::PasswordPolicy;
 use SL::AM;
 use SL::CA;
 use SL::Form;
@@ -39,6 +42,7 @@ use SL::User;
 use SL::USTVA;
 use SL::Iconv;
 use SL::TODO;
+use SL::Printer;
 use CGI::Ajax;
 use CGI;
 
@@ -212,29 +216,29 @@ sub account_header {
 
   my $select_eur = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
   my %eur = (
-          1  => "Umsatzerlöse",
-          2  => "sonstige Erlöse",
+          1  => "Umsatzerlöse",
+          2  => "sonstige Erlöse",
           3  => "Privatanteile",
-          4  => "Zinserträge",
-          5  => "Ausserordentliche Erträge",
+          4  => "Zinserträge",
+          5  => "Ausserordentliche Erträge",
           6  => "Vereinnahmte Umsatzst.",
           7  => "Umsatzsteuererstattungen",
-          8  => "Wareneingänge",
-          9  => "Löhne und Gehälter",
+          8  => "Wareneingänge",
+          9  => "Löhne und Gehälter",
           10 => "Gesetzl. sozialer Aufw.",
           11 => "Mieten",
           12 => "Gas, Strom, Wasser",
           13 => "Instandhaltung",
-          14 => "Steuern, Versich., Beiträge",
+          14 => "Steuern, Versich., Beiträge",
           15 => "Kfz-Steuern",
           16 => "Kfz-Versicherungen",
           17 => "Sonst. Fahrzeugkosten",
           18 => "Werbe- und Reisekosten",
           19 => "Instandhaltung u. Werkzeuge",
-          20 => "Fachzeitschriften, Bücher",
-          21 => "Miete für Einrichtungen",
+          20 => "Fachzeitschriften, Bücher",
+          21 => "Miete für Einrichtungen",
           22 => "Rechts- und Beratungskosten",
-          23 => "Bürobedarf, Porto, Telefon",
+          23 => "Bürobedarf, Porto, Telefon",
           24 => "Sonstige Aufwendungen",
           25 => "Abschreibungen auf Anlagever.",
           26 => "Abschreibungen auf GWG",
@@ -244,7 +248,7 @@ sub account_header {
           30 => "Ausserordentlicher Aufwand",
           31 => "Betriebliche Steuern");
   foreach my $item (sort({ $a <=> $b } keys(%eur))) {
-    my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $eur{$item}));
+    my $text = H($::locale->{iconv_utf8}->convert($eur{$item}));
     if ($item == $form->{pos_eur}) {
       $select_eur .= qq|<option value=$item selected>|. sprintf("%.2d", $item) .qq|. $text</option>\n|;
     } else {
@@ -256,30 +260,30 @@ sub account_header {
   my $select_bwa = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
 
   my %bwapos = (
-             1  => 'Umsatzerlöse',
+             1  => 'Umsatzerlöse',
              2  => 'Best.Verdg.FE/UE',
              3  => 'Aktiv.Eigenleistung',
              4  => 'Mat./Wareneinkauf',
-             5  => 'So.betr.Erlöse',
+             5  => 'So.betr.Erlöse',
              10 => 'Personalkosten',
              11 => 'Raumkosten',
              12 => 'Betriebl.Steuern',
-             13 => 'Vers./Beiträge',
+             13 => 'Vers./Beiträge',
              14 => 'Kfz.Kosten o.St.',
              15 => 'Werbe-Reisek.',
              16 => 'Kosten Warenabgabe',
              17 => 'Abschreibungen',
              18 => 'Rep./instandhlt.',
-             19 => 'Übrige Steuern',
+             19 => 'Übrige Steuern',
              20 => 'Sonst.Kosten',
              30 => 'Zinsauwand',
              31 => 'Sonst.neutr.Aufw.',
-             32 => 'Zinserträge',
+             32 => 'Zinserträge',
              33 => 'Sonst.neutr.Ertrag',
              34 => 'Verr.kalk.Kosten',
              35 => 'Steuern Eink.u.Ertr.');
   foreach my $item (sort({ $a <=> $b } keys %bwapos)) {
-    my $text = H(SL::Iconv::convert("ISO-8859-15", $main::dbcharset, $bwapos{$item}));
+    my $text = H($::locale->{iconv_utf8}->convert($bwapos{$item}));
     if ($item == $form->{pos_bwa}) {
       $select_bwa .= qq|<option value="$item" selected>|. sprintf("%.2d", $item) .qq|. $text\n|;
     } else {
@@ -288,7 +292,7 @@ sub account_header {
 
   }
 
-# Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
+# Wieder hinzugefügt zu evaluationszwecken (us) 09.03.2007
   my $select_bilanz = q|<option value=""> |. $locale->text('None') .q|</option>\n|;
   foreach my $item ((1, 2, 3, 4)) {
     if ($item == $form->{pos_bilanz}) {
@@ -331,7 +335,7 @@ sub account_header {
 
   my %charttype = (
       'A'  => $locale->text('Account'),
-      'H'  => $locale->text('Header'),
+      'H'  => $locale->text('Heading'),
   );
 
   foreach my $item ( sort({ $a <=> $b } keys %charttype) ) {
@@ -1107,7 +1111,7 @@ sub list_business {
   $form->{title} = $locale->text('Type of Business');
 
   my @column_index = qw(description discount customernumberinit);
-  push @column_index, 'salesman' if $::vertreter;
+  push @column_index, 'salesman' if $::lx_office_conf{system}->{vertreter};
   my %column_header;
   $column_header{description} =
       qq|<th class=listheading width=60%>|
@@ -1220,7 +1224,7 @@ sub business_header {
     $form->format_amount(\%myconfig, $form->{discount} * 100);
 
   my $salesman_code;
-  if ($::vertreter) {
+  if ($::lx_office_conf{system}->{vertreter}) {
     $salesman_code = qq|
   <tr>
     <th align="right">| . $locale->text('Representative') . qq|</th>
@@ -1869,7 +1873,7 @@ sub buchungsgruppe_header {
   }
 
   my $linkaccounts;
-  if (!$main::eur) {
+  if (!$::lx_office_conf{system}->{eur}) {
     $linkaccounts = qq|
                <tr>
                 <th align=right>| . $locale->text('Inventory') . qq|</th>
@@ -2014,234 +2018,6 @@ sub swap_buchungsgruppen {
   $main::lxdebug->leave_sub();
 }
 
-
-sub add_printer {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-
-  $main::auth->assert('config');
-
-  $form->{title} = "Add";
-
-  $form->{callback} = "am.pl?action=add_printer" unless $form->{callback};
-
-  &printer_header;
-  &form_footer;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub edit_printer {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
-
-  $main::auth->assert('config');
-
-  $form->{title} = "Edit";
-
-  AM->get_printer(\%myconfig, \%$form);
-
-  &printer_header;
-
-  $form->{orphaned} = 1;
-  &form_footer;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub list_printer {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
-  my $locale   = $main::locale;
-
-  $main::auth->assert('config');
-
-  AM->printer(\%myconfig, \%$form);
-
-  $form->{callback} = "am.pl?action=list_printer";
-
-  my $callback = $form->escape($form->{callback});
-
-  $form->{title} = $locale->text('Printer');
-
-  my @column_index = qw(printer_description printer_command template_code);
-  my %column_header;
-  $column_header{printer_description} =
-      qq|<th class=listheading width=60%>|
-    . $locale->text('Printer Description')
-    . qq|</th>|;
-  $column_header{printer_command} =
-      qq|<th class=listheading width=10%>|
-    . $locale->text('Printer Command')
-    . qq|</th>|;
-  $column_header{template_code} =
-      qq|<th class=listheading>|
-    . $locale->text('Template Code')
-    . qq|</th>|;
-
-  $form->header;
-
-  print qq|
-<body>
-
-<table width=100%>
-  <tr>
-    <th class=listtop>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
-  <tr>
-    <td>
-      <table width=100%>
-        <tr class=listheading>
-|;
-
-  map { print "$column_header{$_}\n" } @column_index;
-
-  print qq|
-        </tr>
-|;
-
-  my ($i, %column_data);
-  foreach my $ref (@{ $form->{ALL} }) {
-
-    $i++;
-    $i %= 2;
-
-    print qq|
-        <tr valign=top class=listrow$i>
-|;
-
-
-    $column_data{printer_description} = qq|<td><a href="am.pl?action=edit_printer&id=$ref->{id}&callback=$callback">$ref->{printer_description}</td>|;
-    $column_data{printer_command}           = qq|<td align=right>$ref->{printer_command}</td>|;
-    $column_data{template_code} =
-      qq|<td align=right>$ref->{template_code}</td>|;
-
-    map { print "$column_data{$_}\n" } @column_index;
-
-    print qq|
-        </tr>
-|;
-  }
-
-  print qq|
-      </table>
-    </td>
-  </tr>
-  <tr>
-  <td><hr size=3 noshade></td>
-  </tr>
-</table>
-
-<br>
-<form method=post action=am.pl>
-
-<input name=callback type=hidden value="$form->{callback}">
-
-<input type=hidden name=type value=printer>
-
-<input class=submit type=submit name=action value="|
-    . $locale->text('Add') . qq|">
-
-  </form>
-
-  </body>
-  </html>
-|;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub printer_header {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my $locale   = $main::locale;
-
-  $main::auth->assert('config');
-
-  $form->{title}    = $locale->text("$form->{title} Printer");
-
-  # $locale->text('Add Printer')
-  # $locale->text('Edit Printer')
-
-  $form->{printer_description} =~ s/\"/&quot;/g;
-  $form->{template_code} =~ s/\"/&quot;/g;
-  $form->{printer_command} =~ s/\"/&quot;/g;
-
-
-  $form->header;
-
-  print qq|
-<body>
-
-<form method=post action=am.pl>
-
-<input type=hidden name=id value=$form->{id}>
-<input type=hidden name=type value=printer>
-
-<table width=100%>
-  <tr>
-    <th class=listtop colspan=2>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
-  <tr>
-    <th align=right>| . $locale->text('Printer') . qq|</th>
-    <td><input name=printer_description size=30 value="$form->{printer_description}"></td>
-  <tr>
-  <tr>
-    <th align=right>| . $locale->text('Printer Command') . qq|</th>
-    <td><input name=printer_command size=30 value="$form->{printer_command}"></td>
-  </tr>
-  <tr>
-    <th align=right>| . $locale->text('Template Code') . qq|</th>
-    <td><input name=template_code size=5 value="$form->{template_code}"></td>
-  </tr>
-  <td colspan=2><hr size=3 noshade></td>
-  </tr>
-</table>
-|;
-
-  $main::lxdebug->leave_sub();
-}
-
-sub save_printer {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
-  my $locale   = $main::locale;
-
-  $main::auth->assert('config');
-
-  $form->isblank("printer_description", $locale->text('Description missing!'));
-  $form->isblank("printer_command", $locale->text('Printer Command missing!'));
-  AM->save_printer(\%myconfig, \%$form);
-  $form->redirect($locale->text('Printer saved!'));
-
-  $main::lxdebug->leave_sub();
-}
-
-sub delete_printer {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
-  my %myconfig = %main::myconfig;
-  my $locale   = $main::locale;
-
-  $main::auth->assert('config');
-
-  AM->delete_printer(\%myconfig, \%$form);
-  $form->redirect($locale->text('Printer deleted!'));
-
-  $main::lxdebug->leave_sub();
-}
-
 sub add_payment {
   $main::lxdebug->enter_sub();
 
@@ -2531,6 +2307,8 @@ sub payment_header {
                         "with discount")
 . qq|</li>
   <li>| . $locale->text("&lt;%skonto_amount%&gt; -- The deductible amount")
+. qq|</li>
+  <li>| . $locale->text("&lt;%skonto_in_percent%&gt; -- The discount in percent")
 . qq|</li>
   <li>| . $locale->text("&lt;%total%&gt; -- Amount payable")
 . qq|</li>
@@ -2679,20 +2457,21 @@ sub config {
   _build_cfg_options('numberformat', ('1,000.00', '1000.00', '1.000,00', '1000,00'));
 
   my @formats = ();
-  if ($main::opendocument_templates && $main::openofficeorg_writer_bin &&
-      $main::xvfb_bin && (-x $main::openofficeorg_writer_bin) && (-x $main::xvfb_bin)) {
+  if ($::lx_office_conf{print_templates}->{opendocument}
+      && $::lx_office_conf{applications}->{openofficeorg_writer} && (-x $::lx_office_conf{applications}->{openofficeorg_writer})
+      && $::lx_office_conf{applications}->{xvfb}                 && (-x $::lx_office_conf{applications}->{xvfb})) {
     push(@formats, { "name" => $locale->text("PDF (OpenDocument/OASIS)"),
                      "value" => "opendocument_pdf" });
   }
-  if ($main::latex_templates) {
+  if ($::lx_office_conf{print_templates}->{latex}) {
     push(@formats, { "name" => $locale->text("PDF"), "value" => "pdf" });
   }
   push(@formats, { "name" => "HTML", "value" => "html" });
-  if ($main::latex_templates) {
+  if ($::lx_office_conf{print_templates}->{latex}) {
     push(@formats, { "name" => $locale->text("Postscript"),
                      "value" => "postscript" });
   }
-  if ($main::opendocument_templates) {
+  if ($::lx_office_conf{print_templates}->{opendocument}) {
     push(@formats, { "name" => $locale->text("OpenDocument/OASIS"),
                      "value" => "opendocument" });
   }
@@ -2720,10 +2499,8 @@ sub config {
     { 'name' => $locale->text('Queue'),   'value' => 'queue',   'selected' => $selected{queue}, },
     ];
 
-  AM->printer(\%myconfig, $form);
-
   $form->{PRINTERS} = [];
-  foreach my $printer (@{$form->{"ALL"}}) {
+  foreach my $printer (SL::Printer->all_printers(%::myconfig)) {
     push @{ $form->{PRINTERS} }, {
       'name'     => $printer->{printer_description},
       'value'    => $printer->{id},
@@ -2743,7 +2520,7 @@ sub config {
   }
 
   $form->{STYLESHEETS} = [];
-  foreach my $item (qw(lx-office-erp.css Win2000.css)) {
+  foreach my $item (qw(lx-office-erp.css Win2000.css Mobile.css)) {
     push @{ $form->{STYLESHEETS} }, {
       'name'     => $item,
       'value'    => $item,
@@ -2774,7 +2551,27 @@ sub save_preferences {
 
   TODO->save_user_config('login' => $form->{login}, %{ $form->{todo_cfg} || { } });
 
-  $form->redirect($locale->text('Preferences saved!')) if (AM->save_preferences(\%myconfig, \%$form, 0));
+  if (AM->save_preferences(\%myconfig, $form)) {
+    if ($::auth->can_change_password()
+        && defined $form->{new_password}
+        && ($form->{new_password} ne '********')) {
+      my $verifier = SL::Auth::PasswordPolicy->new;
+      my $result   = $verifier->verify($form->{new_password});
+
+      if ($result != SL::Auth::PasswordPolicy->OK()) {
+        $form->error($::locale->text('The settings were saved, but the password was not changed.') . ' ' . join(' ', $verifier->errors($result)));
+      }
+
+      $::auth->change_password($form->{login}, $form->{new_password});
+
+      $form->{password} = $form->{new_password};
+      $::auth->set_session_value('password', $form->{password});
+      $::auth->create_or_refresh_session();
+    }
+
+    $form->redirect($locale->text('Preferences saved!'));
+  }
+
   $form->error($locale->text('Cannot save preferences!'));
 
   $main::lxdebug->leave_sub();
@@ -3091,7 +2888,7 @@ sub show_am_history {
   my %searchNo = ( "Artikelnummer"          => "partnumber",
                    "Kundennummer"           => "customernumber",
                    "Lieferantennummer"      => "vendornumber",
-                   "Projektnummer"          => "projectnummer",
+                   "Projektnummer"          => "projectnumber",
                    "Buchungsnummer"         => "ordnumber",
                    "Eingangsrechnungnummer" => "invnumber",
                    "Ausgangsrechnungnummer" => "invnumber",
@@ -3543,7 +3340,7 @@ sub delete_warehouse {
 
     $form->header();
     print $form->parse_html_template('am/confirm_delete_warehouse');
-    exit 0;
+    ::end_of_request();
   }
 
   if (AM->delete_warehouse(\%myconfig, $form)) {