$form->{rowcount} muß in validate_itmes auf 0 überprüfen, da vorherige Überprüfungen...
[kivitendo-erp.git] / bin / mozilla / am.pl
index e34957f..ca1ee4c 100644 (file)
@@ -40,38 +40,15 @@ use Data::Dumper;
 
 1;
 
-
-
-require "$form->{path}/common.pl";
+require "bin/mozilla/common.pl";
 
 # end of main
 
-sub add    { &{"add_$form->{type}"} }
-sub delete { &{"delete_$form->{type}"} }
-
-sub display {
-  if ($form->{display_nextsub}) {
-    &{ $form->{display_nextsub} }();
-  } else {
-    &{ $form->{nextsub} }();
-  }
-}
-
-sub save {
-  if ($form->{save_nextsub}) {
-    &{ $form->{save_nextsub} }();
-  } else {
-    &{ $form->{nextsub} }();
-  }
-}
-
-sub edit {
-  if ($form->{edit_nextsub}) {
-    &{ $form->{edit_nextsub} }();
-  } else {
-    &{ "edit_$form->{type}" }();
-  }
-}
+sub add      { call_sub("add_$form->{type}"); }
+sub delete   { call_sub("delete_$form->{type}"); }
+sub save     { call_sub("save_$form->{type}"); }
+sub edit     { call_sub("edit_$form->{type}"); }
+sub continue { call_sub($form->{"nextsub"}); }
 
 sub add_account {
   $lxdebug->enter_sub();
@@ -81,7 +58,7 @@ sub add_account {
   AM->get_account(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &account_header;
@@ -508,7 +485,6 @@ sub form_footer {
 
 <input name=callback type=hidden value="$form->{callback}">
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -557,7 +533,7 @@ sub list_account {
 
   # construct callback
   $callback =
-    "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_account&login=$form->{login}&password=$form->{password}";
 
   $form->header;
 
@@ -622,7 +598,7 @@ sub list_account {
 
     $ca->{link_edit_account} = 
         qq|$form->{script}?action=edit_account&id=$ca->{id}|
-       .qq|&path=$form->{path}&login=$form->{login}|
+       .qq|&login=$form->{login}|
        .qq|&password=$form->{password}&callback=$callback|;
   }
   
@@ -667,7 +643,7 @@ sub add_department {
   $form->{role}  = "P";
 
   $form->{callback} =
-    "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_department&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &department_header;
@@ -695,7 +671,7 @@ sub list_department {
   AM->departments(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_department&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_department&login=$form->{login}&password=$form->{password}";
 
   $callback = $form->escape($form->{callback});
 
@@ -751,7 +727,7 @@ sub list_department {
     $profitcenter = ($ref->{role} eq "P") ? "X" : "";
 
     $column_data{description} =
-      qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
+      qq|<td><a href=$form->{script}?action=edit_department&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
     $column_data{cost}   = qq|<td align=center>$costcenter</td>|;
     $column_data{profit} = qq|<td align=center>$profitcenter</td>|;
 
@@ -778,7 +754,6 @@ sub list_department {
 
 <input type=hidden name=type value=department>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -875,7 +850,7 @@ sub add_lead {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add_lead&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_lead&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &lead_header;
@@ -905,7 +880,7 @@ sub list_lead {
   AM->lead(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_lead&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_lead&login=$form->{login}&password=$form->{password}";
 
   $callback = $form->escape($form->{callback});
 
@@ -949,7 +924,7 @@ sub list_lead {
        $lead = $ref->{lead};
        
     $column_data{description} =
-      qq|<td><a href=$form->{script}?action=edit_lead&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{lead}</td>|;
+      qq|<td><a href=$form->{script}?action=edit_lead&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{lead}</td>|;
 
     map { print "$column_data{$_}\n" } @column_index;
 
@@ -971,7 +946,6 @@ sub list_lead {
 
 <input type=hidden name=type value=lead>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1052,7 +1026,7 @@ sub add_business {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_business&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &business_header;
@@ -1082,7 +1056,7 @@ sub list_business {
   AM->business(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_business&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_business&login=$form->{login}&password=$form->{password}";
 
   $callback = $form->escape($form->{callback});
 
@@ -1139,7 +1113,7 @@ sub list_business {
     $description =
       $ref->{description};
     $column_data{description} =
-      qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$description</td>|;
+      qq|<td><a href=$form->{script}?action=edit_business&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$description</td>|;
     $column_data{discount}           = qq|<td align=right>$discount</td>|;
     $column_data{customernumberinit} =
       qq|<td align=right>$ref->{customernumberinit}</td>|;
@@ -1167,7 +1141,6 @@ sub list_business {
 
 <input type=hidden name=type value=business>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1256,7 +1229,7 @@ sub add_language {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_language&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &language_header;
@@ -1286,7 +1259,7 @@ sub list_language {
   AM->language(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_language&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_language&login=$form->{login}&password=$form->{password}";
 
   $callback = $form->escape($form->{callback});
 
@@ -1352,7 +1325,7 @@ sub list_language {
 
 
     $column_data{description} =
-      qq|<td><a href=$form->{script}?action=edit_language&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
+      qq|<td><a href=$form->{script}?action=edit_language&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
     $column_data{template_code}           = qq|<td align=right>$ref->{template_code}</td>|;
     $column_data{article_code} =
       qq|<td align=right>$ref->{article_code}</td>|;
@@ -1394,7 +1367,6 @@ sub list_language {
 
 <input type=hidden name=type value=language>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1528,7 +1500,7 @@ sub add_buchungsgruppe {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add_buchungsgruppe&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_buchungsgruppe&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
   AM->get_buchungsgruppe(\%myconfig, \%$form);
   $form->{"inventory_accno_id"} = $form->{"std_inventory_accno_id"};
@@ -1563,7 +1535,7 @@ sub list_buchungsgruppe {
   AM->buchungsgruppe(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_buchungsgruppe&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_buchungsgruppe&login=$form->{login}&password=$form->{password}";
 
   $callback = $form->escape($form->{callback});
 
@@ -1647,7 +1619,7 @@ sub list_buchungsgruppe {
 
   my $swap_link = qq|$form->{script}?action=swap_buchungsgruppen&|;
   map({ $swap_link .= $_ . "=" . $form->escape($form->{$_}) . "&" }
-      qw(login password path));
+      qw(login password));
 
   my $row = 0;
   foreach $ref (@{ $form->{ALL} }) {
@@ -1682,7 +1654,7 @@ sub list_buchungsgruppe {
     }
 
     $column_data{description} =
-      qq|<td><a href=$form->{script}?action=edit_buchungsgruppe&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
+      qq|<td><a href=$form->{script}?action=edit_buchungsgruppe&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
     $column_data{inventory_accno}           = qq|<td align=right>$ref->{inventory_accno}</td>|;
     $column_data{income_accno_0} =
       qq|<td align=right>$ref->{income_accno_0}</td>|;
@@ -1722,7 +1694,6 @@ sub list_buchungsgruppe {
 
 <input type=hidden name=type value=buchungsgruppe>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -1914,7 +1885,7 @@ sub add_printer {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add_printer&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_printer&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   &printer_header;
@@ -1944,7 +1915,7 @@ sub list_printer {
   AM->printer(\%myconfig, \%$form);
 
   $form->{callback} =
-    "$form->{script}?action=list_printer&path=$form->{path}&login=$form->{login}&password=$form->{password}";
+    "$form->{script}?action=list_printer&login=$form->{login}&password=$form->{password}";
 
   $callback = $form->escape($form->{callback});
 
@@ -1998,7 +1969,7 @@ sub list_printer {
 
 
     $column_data{printer_description} =
-      qq|<td><a href=$form->{script}?action=edit_printer&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{printer_description}</td>|;
+      qq|<td><a href=$form->{script}?action=edit_printer&id=$ref->{id}&login=$form->{login}&password=$form->{password}&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>|;
@@ -2026,7 +1997,6 @@ sub list_printer {
 
 <input type=hidden name=type value=printer>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -2116,7 +2086,7 @@ sub add_payment {
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add_payment&path=$form->{path}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add_payment&login=$form->{login}&password=$form->{password}"
     unless $form->{callback};
 
   $form->{terms_netto} = 0;
@@ -2286,7 +2256,6 @@ sub list_payment {
 
 <input type=hidden name=type value=payment>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -2434,226 +2403,6 @@ sub swap_payment_terms {
   $lxdebug->leave_sub();
 }
 
-sub display_template {
-  $lxdebug->enter_sub();
-
-  $form->{edit} = 0;
-  display_template_form();
-
-  $lxdebug->leave_sub();
-}
-
-sub edit_template {
-  $lxdebug->enter_sub();
-
-  $form->{edit} = 1;
-  display_template_form();
-
-  $lxdebug->leave_sub();
-}
-
-sub save_template {
-  $lxdebug->enter_sub();
-
-  $form->isblank("formname", $locale->text("You're not editing a file.")) unless ($form->{type} eq "stylesheet");
-
-  my ($filename) = AM->prepare_template_filename(\%myconfig, $form);
-  if (my $error = AM->save_template($filename, $form->{content})) {
-    $form->error(sprintf($locale->text("Saving the file '%s' failed. OS error message: %s"), $filename, $error));
-  }
-
-  $form->{edit} = 0;
-  display_template_form();
-
-  $lxdebug->leave_sub();
-}
-
-sub display_template_form {
-  $lxdebug->enter_sub();
-
-  $form->{formname} =~ s|.*/||;
-  my $format = $form->{format} eq "html" ? "html" : "tex";
-
-  my $title = $form->{type} eq "stylesheet" ? $locale->text("Edit the stylesheet") : $locale->text("Edit templates");
-  $form->{title} = $title;
-
-  my $edit_options;
-
-  my @hidden = qw(login path password type format);
-
-  if (($form->{type} ne "stylesheet") && !$form->{edit}) {
-    $edit_options = "<p>";
-
-    my %formname_setup =
-      (
-       "balance_sheet" => { "translation" => $locale->text('Balance Sheet'), "html" => 1 },
-       "bin_list" => $locale->text('Bin List'),
-       "bwa" => { "translation" => $locale->text('BWA'), "html" => 1 },
-       "check" => { "translation" => $locale->text('Check'), "html" => 1 },
-       "credit_note" => $locale->text('Credit Note'),
-       "income_statement" => { "translation" => $locale->text('Income Statement'), "html" => 1 },
-       "invoice" => $locale->text('Invoice'),
-       "packing_list" => $locale->text('Packing List'),
-       "pick_list" => $locale->text('Pick List'),
-       "proforma" => $locale->text('Proforma Invoice'),
-       "purchase_order" => $locale->text('Purchase Order'),
-       "receipt" => { "translation" => $locale->text('Receipt'), "tex" => 1 },
-       "request_quotation" => $locale->text('RFQ'),
-       "sales_order" => $locale->text('Confirmation'),
-       "sales_quotation" => $locale->text('Quotation'),
-       "statement" => $locale->text('Statement'),
-       "storno_invoice" => $locale->text('Storno Invoice'),
-       "storno_packing_list" => $locale->text('Storno Packing List'),
-       "ustva-2004" => { "translation" => $locale->text("USTVA 2004"), "tex" => 1 },
-       "ustva-2005" => { "translation" => $locale->text("USTVA 2005"), "tex" => 1 },
-       "ustva-2006" => { "translation" => $locale->text("USTVA 2006"), "tex" => 1 },
-       "ustva-2007" => { "translation" => $locale->text("USTVA 2007"), "tex" => 1 },
-       "ustva" => $locale->text("USTVA"),
-       "zahlungserinnerung" => $locale->text('Payment Reminder'),
-      );
-
-    my (@values, %labels, $file, $setup);
-
-    while (($file, $setup) = each(%formname_setup)) {
-      next unless (!ref($setup) || $setup->{$format});
-
-      push(@values, $file);
-      $labels{$file} = ref($setup) ? $setup->{translation} : $setup;
-    }
-    @values = sort({ $labels{$a} cmp $labels{$b} } @values);
-
-    $edit_options .=
-      $locale->text("Template") . " " .
-      NTI($cgi->popup_menu("-name" => "formname", "-default" => $form->{formname},
-                           "-values" => \@values, "-labels" => \%labels));
-
-    $form->get_lists("printers" => "ALL_PRINTERS",
-                     "languages" => "ALL_LANGUAGES");
-
-    @values = ("");
-    %labels = ();
-
-    foreach my $item (@{ $form->{ALL_LANGUAGES} }) {
-      next unless ($item->{template_code});
-      my $key = "$item->{id}--$item->{template_code}";
-      push(@values, $key);
-      $labels{$key} = $item->{description};
-    }
-
-    if (1 != scalar(@values)) {
-      $edit_options .=
-        " " . $locale->text("Language") . " " .
-        NTI($cgi->popup_menu("-name" => "language", "-default" => $form->{language},
-                             "-values" => \@values, "-labels" => \%labels));
-    }
-
-    @values = ("");
-    %labels = ();
-
-    foreach my $item (@{ $form->{ALL_PRINTERS} }) {
-      next unless ($item->{template_code});
-      my $key = "$item->{id}--$item->{template_code}";
-      push(@values, $key);
-      $labels{$key} = $item->{printer_description};
-    }
-
-    if (1 != scalar(@values)) {
-      $edit_options .=
-        " " . $locale->text("Printer") . " " .
-        NTI($cgi->popup_menu("-name" => "printer", "-default" => $form->{printer},
-                             "-values" => \@values, "-labels" => \%labels));
-    }
-
-    $edit_options .= qq|
-
-  <input type="hidden" name="display_nextsub" value="display_template">
-
-  <input name="action" type="submit" class="submit" value="|
-    . $locale->text('Display') . qq|">
-
- </p>
-
- <hr>
-|;
-
-  } else {
-    push(@hidden, qw(formname language printer));
-  }
-
-  if ($form->{formname} || ($form->{type} eq "stylesheet")) {
-    my ($filename, $display_filename) = AM->prepare_template_filename(\%myconfig, $form);
-    my ($content, $lines) = AM->load_template($filename);
-
-    $body = qq|
-|;
-
-    if ($form->{edit}) {
-      $form->{fokus} = "Form.content";
-      $body = qq|\n<p><div class="listtop">| . $locale->text('Edit file') . " '" . H($display_filename) . qq|'</div></p>\n<p>|
-        . NTI($cgi->textarea("-name" => "content",
-                             "-id" => "content",
-                             "-default" => $content,
-                             "-columns" => 100,
-                             "-rows" => 25))
-        . qq|</p>
-
- <p>
-  <input type="hidden" name="save_nextsub" value="save_template">
-
-  <input type="submit" name="action" value="| . $locale->text('Save') . qq|">
- </p>
-|;
-
-    } else {
-      $content = "\n\n" unless ($content);
-
-      $body = qq|
-  <p><div class="listtop">| . $locale->text('Display file') . " '" . H($display_filename) . qq|'</div></p>
-
-  <input type="hidden" name="edit_nextsub" value="edit_template">
-
-  <p><input name="action" type="submit" class="submit" value="| . $locale->text('Edit') . qq|"></p>
-
-  <p>
-    <pre class="filecontent">| . H($content) . qq|</pre>
-  </p>
-|;
-
-      if ($lines > 25) {
-        $body .= qq|
-  <input name="action" type="submit" class="submit" value="|
-    . $locale->text('Edit') . qq|">
-|;
-      }
-    }
-  }
-
-  $form->header;
-
-  print qq|
-<body>
-
-<div class="listheading">$title</div>
-
-<form method="post" name="Form" action="am.pl">
-
-|;
-  $form->hide_form(@hidden);
-
-  print qq|
-$edit_options
-
-$body
-
-</form>
-
-</body>
-</html>
-|;
-
-  $lxdebug->leave_sub();
-}
-
 sub config {
   $lxdebug->enter_sub();
 
@@ -3032,7 +2781,6 @@ print qq|      </table>
   </tr>
 </table>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -3083,7 +2831,6 @@ sub audit_control {
 
 <form method=post action=$form->{script}>
 
-<input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
 
@@ -3149,14 +2896,6 @@ sub doclose {
   $lxdebug->leave_sub();
 }
 
-sub continue {
-  $lxdebug->enter_sub();
-
-  &{ $form->{nextsub} };
-
-  $lxdebug->leave_sub();
-}
-
 sub edit_units {
   $lxdebug->enter_sub();
 
@@ -3385,33 +3124,36 @@ sub show_am_history {
                                                );
        
        my $dbh = $form->dbconnect(\%myconfig);
-       
+       my $searchSNumber = $searchNo{$form->{'what2search'}} . qq|_| . $form->{'searchid'};
        $restriction .= ($form->{mitarbeiter} eq "" ? "" 
                                        : ($form->{mitarbeiter} =~ /^[0-9]*$/  
                                                ? " AND employee_id = " . $form->{mitarbeiter} 
                                                : " AND employee_id = " . &get_employee_id($form->{mitarbeiter}, $dbh)));
-       
-       my $query = qq|SELECT id FROM $search{$form->{what2search}} 
-                                  WHERE $searchNo{$form->{'what2search'}} ILIKE '$form->{"searchid"}' 
-                                  |;
-       
-       my $sth = $dbh->prepare($query);
+       my $query = qq|SELECT trans_id AS id FROM history_erp WHERE sNumbers = '$searchSNumber' |;
+
+  my $sth = $dbh->prepare($query);
        
        $sth->execute() || $form->dberror($query);
        
+  if($sth->fetch() <= 0) {
+    $sth->finish();
+    my $query = qq|SELECT id FROM $search{$form->{what2search}} 
+           WHERE $searchNo{$form->{'what2search'}} ILIKE '$form->{"searchid"}' 
+           |;
+  }
+  $sth->execute() || $form->dberror($query);  
        $form->{title} = $locale->text("History Search");
        $form->header();
-       
+       my $daten = "";
        while(my $hash_ref = $sth->fetchrow_hashref()){
-               print $form->parse_html_template("/common/show_history", 
-                       {"DATEN" => $form->get_history($dbh,$hash_ref->{id},$restriction),
-                        "SUCCESS" => ($form->get_history($dbh,$hash_ref->{id},$restriction) != 0),
-                        "NONEWWINDOW" => "1"   
-                       }
-               );
-       }
+    $daten =  $form->get_history($dbh,$hash_ref->{id},$restriction);
+  }
        $dbh->disconnect();
-       
+       print $form->parse_html_template("/common/show_history", 
+    {"DATEN" => $daten,
+     "SUCCESS" => ($daten != 0 ? 1 : 0),
+     "NONEWWINDOW" => 1
+    });
        $lxdebug->leave_sub();
 }