X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Fcommon.pl;h=d006c5436e12ef8e36540b56744cebeb9c709315;hb=6ebad56e58db857141565f397c555524cba43109;hp=1c4719aaf82eba1c5a20904f9e607621709cfa51;hpb=bde667c235b2347bdd1322f118b032a2f0d93367;p=kivitendo-erp.git diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index 1c4719aaf..d006c5436 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -10,57 +10,33 @@ ###################################################################### use SL::Form; -use YAML; - use SL::Common; +use SL::MoreCommon; -sub save_form { - $lxdebug->enter_sub(); - - my $yaml = new YAML; - $yaml->Indent(1); - my $old_form = $yaml->dump($form); - $old_form =~ s|!|!!|g; - $old_form =~ s|\n|!n|g; - $old_form =~ s|\r|!r|g; - - $lxdebug->leave_sub(); - - return $old_form; -} - -sub restore_form { +sub build_std_url { $lxdebug->enter_sub(); - my ($old_form, $no_delete) = @_; + my $script = $form->{script}; - map({ delete($form->{$_}); } keys(%{$form})) unless ($no_delete); - $old_form =~ s|!r|\r|g; - $old_form =~ s|!n|\n|g; - $old_form =~ s|!!|!|g; - my $new_form = YAML::Load($old_form); - map({ $form->{$_} = $new_form->{$_}; } keys(%{$new_form})); - - $lxdebug->leave_sub(); -} + my @parts; -sub build_std_url { - $lxdebug->enter_sub(); - - my $url = "$form->{script}?"; - my $first = 1; - foreach my $key ((qw(login password path), @_)) { + foreach my $key ((qw(login password), @_)) { next unless ($key); - $url .= "&" unless ($first); - $first = 0; - if ($key =~ /=/) { - $url .= $key; + if ($key =~ /(.*?)=(.*)/) { + if ($1 eq 'script') { + $script = $2; + } else { + push @parts, $key; + } + } else { - $url .= "${key}=" . E($form->{$key}); + push @parts, "${key}=" . E($form->{$key}); } } + my $url = "${script}?" . join('&', @parts); + $lxdebug->leave_sub(); return $url; @@ -99,7 +75,7 @@ sub select_employee_internal { restore_form($form->{"old_form"}); - &{ $callback_sub }($new_id, $new_name); + call_sub($callback_sub, $new_id, $new_name); $lxdebug->leave_sub(); } @@ -169,7 +145,7 @@ sub select_part_internal { restore_form($form->{"old_form"}); - &{ $callback_sub }($new_item); + call_sub($callback_sub, $new_item); $lxdebug->leave_sub(); } @@ -192,7 +168,7 @@ sub part_selection_internal { my $callback = "$form->{script}?action=part_selection_internal&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form))); + (qw(login password partnumber description input_partnumber input_description input_partsid), grep({ /^[fl]_/ } keys %$form))); my @header_sort = qw(partnumber description); my %header_title = ( "partnumber" => $locale->text("Part Number"), @@ -233,7 +209,7 @@ sub project_selection_internal { my $callback = "$form->{script}?action=project_selection_internal&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password projectnumber description input_projectnumber input_description input_project_id), grep({ /^[fl]_/ } keys %$form))); + (qw(login password projectnumber description input_projectnumber input_description input_project_id), grep({ /^[fl]_/ } keys %$form))); my @header_sort = qw(projectnumber description); my %header_title = ( "projectnumber" => $locale->text("Project Number"), @@ -274,7 +250,7 @@ sub employee_selection_internal { my $callback = "$form->{script}?action=employee_selection_internal&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); my @header_sort = qw(name); my %header_title = ( "name" => $locale->text("Name"), @@ -314,7 +290,7 @@ sub delivery_customer_selection { my $callback = "$form->{script}?action=delivery_customer_selection&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); my @header_sort = qw(name customernumber address); my %header_title = ( "name" => $locale->text("Name"), @@ -356,7 +332,7 @@ sub vendor_selection { my $callback = "$form->{script}?action=vendor_selection&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); my @header_sort = qw(name customernumber address); my %header_title = ( "name" => $locale->text("Name"), @@ -432,7 +408,7 @@ sub set_longdescription { my $callback = "$form->{script}?action=set_longdescription&"; map({ $callback .= "$_=" . $form->escape($form->{$_}) . "&" } - (qw(login path password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); + (qw(login password name input_name input_id), grep({ /^[fl]_/ } keys %$form))); $form->{"title"} = $locale->text("Enter longdescription"); $form->header(); @@ -533,16 +509,86 @@ sub reformat_numbers { sub show_history { $lxdebug->enter_sub(); my $dbh = $form->dbconnect(\%myconfig); - + my ($sort, $sortby) = split(/\-\-/, $form->{order}); + $sort =~ s/.*\.(.*)/$1/; + $form->{title} = $locale->text("History"); $form->header(); print $form->parse_html_template( "common/show_history", { - "DATEN" => $form->get_history($dbh,$form->{input_name}), - "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0") + "DATEN" => $form->get_history($dbh,$form->{input_name},"",$form->{order}), + "SUCCESS" => ($form->get_history($dbh,$form->{input_name}) ne "0"), + uc($sort) => 1, + uc($sort)."BY" => $sortby } ); $dbh->disconnect(); $lxdebug->leave_sub(); } +sub call_sub { + $lxdebug->enter_sub(); + + my $name = shift; + + if (!$name) { + $form->error($locale->text("Trying to call a sub without a name")); + } + + $name =~ s/[^a-zA-Z0-9_]//g; + + if (!defined(&{ $name })) { + $form->error(sprintf($locale->text("Attempt to call an undefined sub named '%s'"), $name)); + } + + &{ $name }(@_); + + $lxdebug->leave_sub(); +} + +sub show_vc_details { + $lxdebug->enter_sub(); + + $form->{vc} = $form->{vc} eq "customer" ? "customer" : "vendor"; + $form->isblank("vc_id", + $form->{vc} eq "customer" ? + $locale->text("No customer has been selected yet.") : + $locale->text("No vendor has been selected yet.")); + + Common->get_vc_details(\%myconfig, $form, $form->{vc}, $form->{vc_id}); + + $form->{title} = $form->{vc} eq "customer" ? + $locale->text("Customer details") : $locale->text("Vendor details"); + $form->header(); + print($form->parse_html_template("common/show_vc_details", + { "is_customer" => $form->{vc} eq "customer" })); + + $lxdebug->leave_sub(); +} + +sub mark_as_paid_common { + $lxdebug->enter_sub(); + use SL::DBUtils; + my ($myconfig, $db_name) = @_; + + if($form->{mark_as_paid}) { + my $dbh ||= $form->get_standard_dbh($myconfig); + my $query = qq|UPDATE $db_name SET paid = amount WHERE id = ?|; + do_query($form, $dbh, $query, $form->{id}); + $dbh->commit(); + $form->redirect($locale->text("Marked as paid")); +} + else { + my $referer = $ENV{HTTP_REFERER}; + $referer =~ s/^(.*)action\=.*\&(.*)$/$1action\=mark_as_paid\&mark_as_paid\=1\&login\=$form->{login}\&password\=$form->{password}\&id\=$form->{id}\&$2/; + $form->header(); + print qq|
|; + print qq||.$locale->text('Mark as paid?').qq|
|; + print qq| |; + print qq||; + print qq|