1 use POSIX qw(strftime);
 
   4 use SL::ReportGenerator;
 
   6 require "bin/mozilla/reportgenerator.pl";
 
  11   $main::lxdebug->enter_sub();
 
  13   $main::auth->assert('productivity');
 
  17   my $form     = $main::form;
 
  21   foreach my $i (1 .. $form->{trans_rowcount}) {
 
  22     next if (!$form->{"trans_id_$i"} || !$form->{"trans_type_$i"});
 
  24     push @{ $dest->{LINKS} }, { map { +"trans_$_" => $form->{"trans_${_}_$i"} } qw(id type info) };
 
  27   $main::lxdebug->leave_sub();
 
  31   $main::lxdebug->enter_sub();
 
  33   $main::auth->assert('productivity');
 
  35   my $form     = $main::form;
 
  36   my %myconfig = %main::myconfig;
 
  37   my $locale   = $main::locale;
 
  39   _collect_links($form);
 
  41   $form->get_employee($form->get_standard_dbh(\%myconfig));
 
  42   $form->{created_for_user} = $form->{employee_id};
 
  46   if (0 < scalar @{ $form->{LINKS} }) {
 
  47     $link_details = FU->link_details(%{ $form->{LINKS}->[0] });
 
  50   if ($link_details && $link_details->{title}) {
 
  51     $form->{title} = $locale->text('Add Follow-Up for #1', $link_details->{title});
 
  53     $form->{title} = $locale->text('Add Follow-Up');
 
  58   $main::lxdebug->leave_sub();
 
  62   $main::lxdebug->enter_sub();
 
  64   $main::auth->assert('productivity');
 
  66   my $form     = $main::form;
 
  67   my $locale   = $main::locale;
 
  69   my $ref = FU->retrieve('id' => $form->{id});
 
  72     $form->error($locale->text("Invalid follow-up ID."));
 
  75   map { $form->{$_} = $ref->{$_} } keys %{ $ref };
 
  77   if (@{ $form->{LINKS} } && $form->{LINKS}->[0]->{title}) {
 
  78     $form->{title} = $locale->text('Edit Follow-Up for #1', $form->{LINKS}->[0]->{title});
 
  80     $form->{title} = $locale->text('Edit Follow-Up');
 
  85   $main::lxdebug->leave_sub();
 
  89   $main::lxdebug->enter_sub();
 
  91   $main::auth->assert('productivity');
 
  93   my $form     = $main::form;
 
  95   $form->get_lists("employees" => "EMPLOYEES");
 
  98   $params{not_id}     = $form->{id} if ($form->{id});
 
  99   $params{trans_id}   = $form->{LINKS}->[0]->{trans_id} if (@{ $form->{LINKS} });
 
 100   $form->{FOLLOW_UPS} = FU->follow_ups(%params);
 
 102   $form->{jsscript}   = 1;
 
 104   $form->header(no_layout => $::form->{POPUP_MODE});
 
 105   print $form->parse_html_template('fu/add_edit');
 
 107   $main::lxdebug->leave_sub();
 
 111   $main::lxdebug->enter_sub();
 
 113   $main::auth->assert('productivity');
 
 115   my $form     = $main::form;
 
 116   my $locale   = $main::locale;
 
 118   $form->isblank('created_for_user', $locale->text('You must chose a user.'));
 
 119   $form->isblank('follow_up_date',   $locale->text('The follow-up date is missing.'));
 
 120   $form->isblank('subject',          $locale->text('The subject is missing.'));
 
 122   my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_user follow_up_date)), 'done' => 0);
 
 124   _collect_links(\%params);
 
 128   if ($form->{POPUP_MODE}) {
 
 130     print $form->parse_html_template('fu/close_window');
 
 134   $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
 
 136   if ($form->{callback}) {
 
 140   delete @{$form}{qw(id subject body created_for_user follow_up_date)};
 
 142   map { $form->{$_} = 1 } qw(due_only all_users not_done);
 
 146   $main::lxdebug->leave_sub();
 
 150   $main::lxdebug->enter_sub();
 
 152   $main::auth->assert('productivity');
 
 154   my $form     = $main::form;
 
 155   my $locale   = $main::locale;
 
 158     my $ref = FU->retrieve('id' => $form->{id});
 
 161       $form->error($locale->text("Invalid follow-up ID."));
 
 164     FU->finish('id' => $form->{id});
 
 167     foreach my $i (1..$form->{rowcount}) {
 
 168       next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
 
 170       FU->finish('id' => $form->{"follow_up_id_$i"});
 
 174   if ($form->{POPUP_MODE}) {
 
 176     print $form->parse_html_template('fu/close_window');
 
 180   $form->redirect() if ($form->{callback});
 
 184   $main::lxdebug->leave_sub();
 
 188   $main::lxdebug->enter_sub();
 
 190   $main::auth->assert('productivity');
 
 192   my $form     = $main::form;
 
 193   my $locale   = $main::locale;
 
 196     my $ref = FU->retrieve('id' => $form->{id});
 
 199       $form->error($locale->text("Invalid follow-up ID."));
 
 202     FU->delete('id' => $form->{id});
 
 205     foreach my $i (1..$form->{rowcount}) {
 
 206       next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
 
 208       FU->delete('id' => $form->{"follow_up_id_$i"});
 
 212   if ($form->{POPUP_MODE}) {
 
 214     print $form->parse_html_template('fu/close_window');
 
 218   $form->redirect() if ($form->{callback});
 
 222   $main::lxdebug->leave_sub();
 
 226   $main::lxdebug->enter_sub();
 
 228   $main::auth->assert('productivity');
 
 230   my $form     = $main::form;
 
 231   my $locale   = $main::locale;
 
 233   $form->get_lists("employees" => "EMPLOYEES");
 
 235   $form->{jsscript} = 1;
 
 236   $form->{title}    = $locale->text('Follow-Ups');
 
 239   print $form->parse_html_template('fu/search');
 
 241   $main::lxdebug->leave_sub();
 
 245   $main::lxdebug->enter_sub();
 
 247   $main::auth->assert('productivity');
 
 249   my $form     = $main::form;
 
 250   my %myconfig = %main::myconfig;
 
 251   my $locale   = $main::locale;
 
 252   my $cgi      = $::request->{cgi};
 
 254   my @report_params = qw(created_for subject body reference follow_up_date_from follow_up_date_to itime_from itime_to due_only all_users done not_done);
 
 256   report_generator_set_default_sort('follow_up_date', 1);
 
 258   my $follow_ups    = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
 
 259   $form->{rowcount} = scalar @{ $follow_ups };
 
 261   $form->{title}    = $locale->text('Follow-Ups');
 
 264     'selected'              => { 'text' => '', },
 
 265     'follow_up_date'        => { 'text' => $locale->text('Follow-Up Date'), },
 
 266     'created_on'            => { 'text' => $locale->text('Created on'), },
 
 267     'title'                 => { 'text' => $locale->text('Reference'), },
 
 268     'subject'               => { 'text' => $locale->text('Subject'), },
 
 269     'created_by_name'       => { 'text' => $locale->text('Created by'), },
 
 270     'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
 
 271     'done'                  => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
 
 274   my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
 
 275   my $href    = build_std_url('action=report', grep { $form->{$_} } @report_params);
 
 277   foreach my $name (qw(follow_up_date created_on title subject)) {
 
 278     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
 
 279     $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
 
 284   if ($form->{created_for}) {
 
 285     $form->get_lists("employees" => "EMPLOYEES");
 
 287     foreach my $employee (@{ $form->{EMPLOYEES} }) {
 
 288       if ($employee->{id} == $form->{created_for}) {
 
 289         push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
 
 295   push @options, $locale->text('Subject')                  . " : $form->{subject}"   if ($form->{subject});
 
 296   push @options, $locale->text('Body')                     . " : $form->{body}"      if ($form->{body});
 
 297   push @options, $locale->text('Reference')                . " : $form->{reference}" if ($form->{reference});
 
 298   push @options, $locale->text('Done')                                               if ($form->{done});
 
 299   push @options, $locale->text('Not done yet')                                       if ($form->{not_done});
 
 300   push @options, $locale->text('Only due follow-ups')                                if ($form->{due_only});
 
 301   push @options, $locale->text("Other users' follow-ups")                            if ($form->{all_users});
 
 303   my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
 
 305   my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
 
 307   $report->set_columns(%column_defs);
 
 308   $report->set_column_order(@columns);
 
 310   $report->set_export_options('report', @report_params, qw(sort sortdir));
 
 312   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
 314   $report->set_options('raw_top_info_text'    => $form->parse_html_template('fu/report_top',    { 'OPTIONS' => \@options }),
 
 315                        'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN'  => \@hidden_report_params }),
 
 316                        'output_format'        => 'HTML',
 
 317                        'title'                => $form->{title},
 
 318                        'attachment_basename'  => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
 
 320   $report->set_options_from_form();
 
 321   $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
 
 324   my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
 
 325   my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
 
 327   foreach my $fu (@{ $follow_ups }) {
 
 330     $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
 
 332     my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
 
 335       'raw_data' =>   $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
 
 336                     . $cgi->checkbox('-name' => "selected_${idx}",   '-value' => 1, '-label' => ''),
 
 337       'valign'   => 'center',
 
 341     if (@{ $fu->{LINKS} }) {
 
 342       my $link = $fu->{LINKS}->[0];
 
 344       $row->{title}->{data} = $link->{title};
 
 345       $row->{title}->{link} = $link->{url};
 
 348     $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
 
 350     $report->add_data($row);
 
 353   $report->generate_with_headers();
 
 355   $main::lxdebug->leave_sub();
 
 358 sub report_for_todo_list {
 
 359   $main::lxdebug->enter_sub();
 
 361   $main::auth->assert('productivity');
 
 363   my $form     = $main::form;
 
 365   my @report_params = qw(created_for subject body reference follow_up_date_from follow_up_date_to itime_from itime_to due_only all_users done not_done);
 
 370     'created_for_login' => $form->{login},
 
 373   my $follow_ups = FU->follow_ups(%params);
 
 376   if (@{ $follow_ups }) {
 
 377     my $callback = build_std_url('action');
 
 378     my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
 
 380     foreach my $fu (@{ $follow_ups }) {
 
 381       if (@{ $fu->{LINKS} }) {
 
 382         my $link = $fu->{LINKS}->[0];
 
 384         $fu->{reference}      = $link->{title};
 
 385         $fu->{reference_link} = $link->{url};
 
 389     $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
 
 390                                                                        'callback'   => $callback,
 
 391                                                                        'edit_url'   => $edit_url, });
 
 394   $main::lxdebug->leave_sub();
 
 399 sub edit_access_rights {
 
 400   $main::lxdebug->enter_sub();
 
 402   $main::auth->assert('productivity');
 
 404   my $form     = $main::form;
 
 405   my $locale   = $main::locale;
 
 407   my $access = FU->retrieve_access_rights();
 
 409   $form->{EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
 
 411   map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
 
 413   $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
 
 416   print $form->parse_html_template('fu/edit_access_rights');
 
 418   $main::lxdebug->leave_sub();
 
 421 sub save_access_rights {
 
 422   $main::lxdebug->enter_sub();
 
 424   $main::auth->assert('productivity');
 
 426   my $form     = $main::form;
 
 427   my $locale   = $main::locale;
 
 431   foreach my $i (1 .. $form->{rowcount}) {
 
 432     my $id = $form->{"employee_id_$i"};
 
 434     $access{$id} = 1 if ($id && $form->{"access_$id"});
 
 437   FU->save_access_rights('access' => \%access);
 
 439   $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
 
 440   edit_access_rights();
 
 442   $main::lxdebug->leave_sub();
 
 446   call_sub($main::form->{nextsub});
 
 450   call_sub($main::form->{nextsub});
 
 454   $main::auth->assert('productivity');
 
 456   if ($main::form->{save_nextsub}) {
 
 457     call_sub($main::form->{save_nextsub});
 
 464   $main::lxdebug->enter_sub();
 
 466   my $form     = $main::form;
 
 467   my $locale   = $main::locale;
 
 469   foreach my $action (qw(finish save delete)) {
 
 470     if ($form->{"action_${action}"}) {
 
 476   call_sub($form->{default_action}) if ($form->{default_action});
 
 478   $form->error($locale->text('No action defined.'));