$form->{rowcount} muß in validate_itmes auf 0 überprüfen, da vorherige Überprüfungen...
[kivitendo-erp.git] / bin / mozilla / am.pl
index 6ff9997..ca1ee4c 100644 (file)
@@ -40,16 +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 edit   { &{"edit_$form->{type}"} }
-sub save   { &{"save_$form->{type}"} }
-sub delete { &{"delete_$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();
@@ -59,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;
@@ -96,13 +95,16 @@ sub account_header {
   $form->{description} =~ s/\"/"/g;
 
   if (@{ $form->{TAXKEY} }) {
-    foreach $item (@{ $form->{TAXKEY} }) {
+    foreach my $item (@{ $form->{TAXKEY} }) {
+
+      $item->{rate} = $item->{rate} * 100 . '%';
+
       if ($item->{tax} == $form->{tax}) {
         $form->{selecttaxkey} .=
-          "<option value=$item->{tax} selected>$item->{taxdescription}\n";
+          "<option value=$item->{tax} selected>$item->{taxdescription} ($item->{rate})\n";
       } else {
         $form->{selecttaxkey} .=
-          "<option value=$item->{tax}>$item->{taxdescription}\n";
+          "<option value=$item->{tax}>$item->{taxdescription} ($item->{rate})\n";
       }
 
     }
@@ -483,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}>
 
@@ -532,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;
 
@@ -597,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|;
   }
   
@@ -642,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;
@@ -670,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});
 
@@ -726,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>|;
 
@@ -753,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}>
 
@@ -850,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;
@@ -880,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});
 
@@ -924,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;
 
@@ -946,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}>
 
@@ -1027,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;
@@ -1057,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});
 
@@ -1112,11 +1111,9 @@ sub list_business {
     $discount =
       $form->format_amount(\%myconfig, $ref->{discount} * 100);
     $description =
-      ($ref->{salesman})
-      ? "<b>$ref->{description}</b>"
-      : "$ref->{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>|;
@@ -1144,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}>
 
@@ -1164,7 +1160,6 @@ sub business_header {
   $lxdebug->enter_sub();
 
   $form->{title}    = $locale->text("$form->{title} Business");
-  $form->{salesman} = "checked" if $form->{salesman};
 
   # $locale->text('Add Business')
   # $locale->text('Edit Business')
@@ -1200,10 +1195,6 @@ sub business_header {
     <th align=right>| . $locale->text('Customernumberinit') . qq|</th>
     <td><input name=customernumberinit size=10 value=$form->{customernumberinit}></td>
   </tr>
-  <tr>
-    <td align=right>| . $locale->text('Salesman') . qq|</td>
-    <td><input name=salesman class=checkbox type=checkbox value=1 $form->{salesman}></td>
-  </tr>
   <td colspan=2><hr size=3 noshade></td>
   </tr>
 </table>
@@ -1238,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;
@@ -1268,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});
 
@@ -1334,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>|;
@@ -1376,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}>
 
@@ -1510,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"};
@@ -1545,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});
 
@@ -1629,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} }) {
@@ -1664,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>|;
@@ -1704,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}>
 
@@ -1896,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;
@@ -1926,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});
 
@@ -1980,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>|;
@@ -2008,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}>
 
@@ -2098,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;
@@ -2268,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}>
 
@@ -2416,114 +2403,6 @@ sub swap_payment_terms {
   $lxdebug->leave_sub();
 }
 
-sub display_stylesheet {
-  $lxdebug->enter_sub();
-
-  $form->{file} = "css/$myconfig{stylesheet}";
-  &display_form;
-
-  $lxdebug->leave_sub();
-}
-
-sub display_form {
-  $lxdebug->enter_sub();
-
-  $form->{file} =~ s/^(.:)*?\/|\.\.\///g;
-  $form->{file} =~ s/^\/*//g;
-  $form->{file} =~ s/$userspath//;
-
-  $form->error("$!: $form->{file}") unless -f $form->{file};
-
-  AM->load_template(\%$form);
-
-  $form->{title} = $form->{file};
-
-  # if it is anything but html
-  if ($form->{file} !~ /\.html$/) {
-    $form->{body} = "<pre>\n$form->{body}\n</pre>";
-  }
-
-  $form->header;
-
-  print qq|
-<body>
-
-$form->{body}
-
-<form method=post action=$form->{script}>
-
-<input name=file type=hidden value=$form->{file}>
-<input name=type type=hidden value=template>
-
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
-<input name=action type=submit class=submit value="|
-    . $locale->text('Edit') . qq|">
-
-  </form>
-
-</body>
-</html>
-|;
-
-  $lxdebug->leave_sub();
-}
-
-sub edit_template {
-  $lxdebug->enter_sub();
-
-  AM->load_template(\%$form);
-
-  $form->{title} = $locale->text('Edit Template');
-
-  # convert &nbsp to &amp;nbsp;
-  $form->{body} =~ s/&nbsp;/&amp;nbsp;/gi;
-
-  $form->header;
-
-  print qq|
-<body>
-
-<form method=post action=$form->{script}>
-
-<input name=file type=hidden value=$form->{file}>
-<input name=type type=hidden value=template>
-
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
-<input name=callback type=hidden value="$form->{script}?action=display_form&file=$form->{file}&path=$form->{path}&login=$form->{login}&password=$form->{password}">
-
-<textarea name=body rows=25 cols=70>
-$form->{body}
-</textarea>
-
-<br>
-<input type=submit class=submit name=action value="|
-    . $locale->text('Save') . qq|">
-
-  </form>
-
-
-</body>
-</html>
-|;
-
-  $lxdebug->leave_sub();
-}
-
-sub save_template {
-  $lxdebug->enter_sub();
-
-  AM->save_template(\%$form);
-  $form->redirect($locale->text('Template saved!'));
-
-  $lxdebug->leave_sub();
-}
-
 sub config {
   $lxdebug->enter_sub();
 
@@ -2902,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}>
 
@@ -2953,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}>
 
@@ -3019,14 +2896,6 @@ sub doclose {
   $lxdebug->leave_sub();
 }
 
-sub continue {
-  $lxdebug->enter_sub();
-
-  &{ $form->{nextsub} };
-
-  $lxdebug->leave_sub();
-}
-
 sub edit_units {
   $lxdebug->enter_sub();
 
@@ -3255,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();
 }