Unnötiger Code
[kivitendo-erp.git] / bin / mozilla / projects.pl
index a658742..b7614ff 100644 (file)
@@ -39,23 +39,31 @@ use SL::ReportGenerator;
 require "bin/mozilla/common.pl";
 require "bin/mozilla/reportgenerator.pl";
 
+use strict;
+
 sub add {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   # construct callback
   $form->{callback} = build_std_url('action') unless $form->{callback};
 
   display_project_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub edit {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   # show history button
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
@@ -66,13 +74,16 @@ sub edit {
 
   display_project_form();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub search {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('project_edit');
+  $main::auth->assert('project_edit');
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{title} = $locale->text('Projects');
 
@@ -81,17 +92,22 @@ sub search {
    $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables'      => $form->{CUSTOM_VARIABLES},
                                                                            'include_prefix' => 'l_',
                                                                            'include_value'  => 'Y');
+  $::request->{layout}->focus('#projectnumber');
 
   $form->header();
   print $form->parse_html_template('projects/search');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub project_report {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->{sort} ||= 'projectnumber';
   my $filter      = $form->{filter} || { };
@@ -103,8 +119,6 @@ sub project_report {
   my $report       = SL::ReportGenerator->new(\%myconfig, $form);
 
   my @columns      = qw(projectnumber description active);
-  my @hidden_vars  = ('filter');
-  my $href         = build_std_url('action=project_report', @hidden_vars);
 
   my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
   my %column_defs_cvars            = ();
@@ -117,6 +131,11 @@ sub project_report {
 
   push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
 
+
+  my @hidden_vars  = ('filter', map { ('cvar_'. $_->{name} , 'l_cvar_'. $_->{name}) } @includeable_custom_variables);
+  my $href         = build_std_url('action=project_report', @hidden_vars);
+
+
   my %column_defs  = (
     'projectnumber'            => { 'text' => $locale->text('Number'), },
     'description'              => { 'text' => $locale->text('Description'), },
@@ -132,7 +151,14 @@ sub project_report {
   $report->set_columns(%column_defs);
   $report->set_column_order(@columns);
 
-  $report->set_export_options('project_report', @hidden_vars);
+  $report->set_export_options('project_report', @hidden_vars, 'sort');
+
+  CVar->add_custom_variables_to_report('module'         => 'Project',
+                                       'trans_id_field' => 'id',
+                                       'configs'        => $cvar_configs,
+                                       'column_defs'    => \%column_defs,
+                                       'data'           => $form->{project_list},
+                                       );
 
   $report->set_sort_indicator($form->{sort}, 1);
 
@@ -153,6 +179,7 @@ sub project_report {
                        'attachment_basename' => $locale->text('project_list') . strftime('_%Y%m%d', localtime time),
     );
   $report->set_options_from_form();
+  $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
   CVar->add_custom_variables_to_report('module'         => 'Projects',
                                        'trans_id_field' => 'id',
@@ -163,7 +190,7 @@ sub project_report {
   my $edit_url = build_std_url('action=edit&type=project');
   my $callback = $form->escape($href) . '&sort=' . E($form->{sort});
 
-  foreach $project (@{ $form->{project_list} }) {
+  foreach my $project (@{ $form->{project_list} }) {
     $project->{active} = $project->{active} ? $locale->text('Yes')  : $locale->text('No');
 
     my $row = { map { $_ => { 'data' => $project->{$_} } } keys %{ $project } };
@@ -175,32 +202,39 @@ sub project_report {
 
   $report->generate_with_headers();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub display_project_form {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
 
-  $auth->assert('project_edit');
+  $main::auth->assert('project_edit');
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   $form->{project} ||= { };
 
   $form->{title}     = $form->{project}->{id} ? $locale->text("Edit Project") : $locale->text("Add Project");
 
   $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'Projects', 'trans_id' => $form->{project}->{id});
-  $main::lxdebug->dump(0, "cv", $form->{CUSTOM_VARIABLES});
+#  $main::lxdebug->dump(0, "cv", $form->{CUSTOM_VARIABLES});
   CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} });
 
   $form->header();
   print $form->parse_html_template('projects/project_form');
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   $form->isblank("project.projectnumber", $locale->text('Project Number missing!'));
 
@@ -212,8 +246,8 @@ sub save {
   if(!exists $form->{addition} && $project->{id} ne "") {
     $form->{id}       = $project->{id};
     $form->{snumbers} = qq|projectnumber_| . $project->{projectnumber};
-       $form->{addition} = "SAVED";
-       $form->save_history($form->dbconnect(\%myconfig));
+    $form->{addition} = "SAVED";
+    $form->save_history;
   }
   # /saving the history
 
@@ -225,22 +259,29 @@ sub save {
 
   $form->redirect($locale->text('Project saved!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub save_as_new {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  my $form     = $main::form;
+  my $locale   = $main::locale;
 
   delete $form->{project}->{id} if ($form->{project});
   save();
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub delete {
-  $lxdebug->enter_sub();
+  $main::lxdebug->enter_sub();
+
+  $main::auth->assert('project_edit');
 
-  $auth->assert('project_edit');
+  my $form     = $main::form;
+  my %myconfig = %main::myconfig;
+  my $locale   = $main::locale;
 
   my $project = $form->{project} || { };
   Projects->delete_project('id' => $project->{id});
@@ -248,16 +289,16 @@ sub delete {
   # saving the history
   if(!exists $form->{addition}) {
     $form->{snumbers} = qq|projectnumber_| . $project->{projectnumber};
-       $form->{addition} = "DELETED";
-       $form->save_history($form->dbconnect(\%myconfig));
+    $form->{addition} = "DELETED";
+    $form->save_history;
   }
   # /saving the history
 
   $form->redirect($locale->text('Project deleted!'));
 
-  $lxdebug->leave_sub();
+  $main::lxdebug->leave_sub();
 }
 
 sub continue {
-  call_sub($form->{nextsub});
+  call_sub($main::form->{nextsub});
 }