1 use POSIX qw(strftime);
 
   4 use SL::ReportGenerator;
 
   6 require "bin/mozilla/reportgenerator.pl";
 
  15   foreach my $i (1 .. $form->{trans_rowcount}) {
 
  16     next if (!$form->{"trans_id_$i"} || !$form->{"trans_type_$i"});
 
  18     push @{ $dest->{LINKS} }, { map { +"trans_$_" => $form->{"trans_${_}_$i"} } qw(id type info) };
 
  21   $lxdebug->leave_sub();
 
  25   $lxdebug->enter_sub();
 
  27   _collect_links($form);
 
  29   $form->get_employee($form->get_standard_dbh(\%myconfig));
 
  30   $form->{created_for_user} = $form->{employee_id};
 
  34   if (0 < scalar @{ $form->{LINKS} }) {
 
  35     $link_details = FU->link_details(%{ $form->{LINKS}->[0] });
 
  38   if ($link_details && $link_details->{title}) {
 
  39     $form->{title} = $locale->text('Add Follow-Up for #1', $link_details->{title});
 
  41     $form->{title} = $locale->text('Add Follow-Up');
 
  46   $lxdebug->leave_sub();
 
  50   $lxdebug->enter_sub();
 
  52   my $ref = FU->retrieve('id' => $form->{id});
 
  55     $form->error($locale->text("Invalid follow-up ID."));
 
  58   map { $form->{$_} = $ref->{$_} } keys %{ $ref };
 
  60   if (@{ $form->{LINKS} } && $form->{LINKS}->[0]->{title}) {
 
  61     $form->{title} = $locale->text('Edit Follow-Up for #1', $form->{LINKS}->[0]->{title});
 
  63     $form->{title} = $locale->text('Edit Follow-Up');
 
  68   $lxdebug->leave_sub();
 
  72   $lxdebug->enter_sub();
 
  74   $form->get_lists("employees" => "EMPLOYEES");
 
  77   $params{not_id}     = $form->{id} if ($form->{id});
 
  78   $params{trans_id}   = $form->{LINKS}->[0]->{trans_id} if (@{ $form->{LINKS} });
 
  79   $form->{FOLLOW_UPS} = FU->follow_ups(%params);
 
  81   $form->{jsscript}   = 1;
 
  84   print $form->parse_html_template('fu/add_edit');
 
  86   $lxdebug->leave_sub();
 
  90   $lxdebug->enter_sub();
 
  92   $form->isblank('created_for_user', $locale->text('You must chose a user.'));
 
  93   $form->isblank('follow_up_date',   $locale->text('The follow-up date is missing.'));
 
  94   $form->isblank('subject',          $locale->text('The subject is missing.'));
 
  96   my %params = (map({ $_ => $form->{$_} } qw(id subject body created_for_user follow_up_date)), 'done' => 0);
 
  98   _collect_links(\%params);
 
 102   if ($form->{POPUP_MODE}) {
 
 104     print $form->parse_html_template('fu/close_window');
 
 108   $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
 
 110   if ($form->{callback}) {
 
 114   delete @{$form}{qw(id subject body created_for_user follow_up_date)};
 
 116   map { $form->{$_} = 1 } qw(due_only all_users not_done);
 
 120   $lxdebug->leave_sub();
 
 124   $lxdebug->enter_sub();
 
 127     my $ref = FU->retrieve('id' => $form->{id});
 
 130       $form->error($locale->text("Invalid follow-up ID."));
 
 133     FU->finish('id' => $form->{id});
 
 136     foreach my $i (1..$form->{rowcount}) {
 
 137       next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
 
 139       FU->finish('id' => $form->{"follow_up_id_$i"});
 
 143   if ($form->{POPUP_MODE}) {
 
 145     print $form->parse_html_template('fu/close_window');
 
 149   $form->redirect() if ($form->{callback});
 
 153   $lxdebug->leave_sub();
 
 157   $lxdebug->enter_sub();
 
 160     my $ref = FU->retrieve('id' => $form->{id});
 
 163       $form->error($locale->text("Invalid follow-up ID."));
 
 166     FU->delete('id' => $form->{id});
 
 169     foreach my $i (1..$form->{rowcount}) {
 
 170       next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
 
 172       FU->delete('id' => $form->{"follow_up_id_$i"});
 
 176   if ($form->{POPUP_MODE}) {
 
 178     print $form->parse_html_template('fu/close_window');
 
 182   $form->redirect() if ($form->{callback});
 
 186   $lxdebug->leave_sub();
 
 190   $lxdebug->enter_sub();
 
 192   $form->get_lists("employees" => "EMPLOYEES");
 
 194   $form->{jsscript} = 1;
 
 195   $form->{title}    = $locale->text('Follow-Ups');
 
 198   print $form->parse_html_template('fu/search');
 
 200   $lxdebug->leave_sub();
 
 204   $lxdebug->enter_sub();
 
 206   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);
 
 208   report_generator_set_default_sort('follow_up_date', 1);
 
 210   my $follow_ups    = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
 
 211   $form->{rowcount} = scalar @{ $follow_ups };
 
 213   $form->{title}    = $locale->text('Follow-Ups');
 
 216     'selected'              => { 'text' => '', },
 
 217     'follow_up_date'        => { 'text' => $locale->text('Follow-Up Date'), },
 
 218     'created_on'            => { 'text' => $locale->text('Created on'), },
 
 219     'title'                 => { 'text' => $locale->text('Reference'), },
 
 220     'subject'               => { 'text' => $locale->text('Subject'), },
 
 221     'created_by_name'       => { 'text' => $locale->text('Created by'), },
 
 222     'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
 
 223     'done'                  => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
 
 226   my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
 
 227   my $href    = build_std_url('action=report', grep { $form->{$_} } @report_params);
 
 229   foreach my $name (qw(follow_up_date created_on title subject)) {
 
 230     my $sortdir                 = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
 
 231     $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
 
 236   if ($form->{created_for}) {
 
 237     $form->get_lists("employees" => "EMPLOYEES");
 
 239     foreach my $employee (@{ $form->{EMPLOYEES} }) {
 
 240       if ($employee->{id} == $form->{created_for}) {
 
 241         push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
 
 247   push @options, $locale->text('Subject')                  . " : $form->{subject}"   if ($form->{subject});
 
 248   push @options, $locale->text('Body')                     . " : $form->{body}"      if ($form->{body});
 
 249   push @options, $locale->text('Reference')                . " : $form->{reference}" if ($form->{reference});
 
 250   push @options, $locale->text('Done')                                               if ($form->{done});
 
 251   push @options, $locale->text('Not done yet')                                       if ($form->{not_done});
 
 252   push @options, $locale->text('Only due follow-ups')                                if ($form->{due_only});
 
 253   push @options, $locale->text("Other users' follow-ups")                            if ($form->{all_users});
 
 255   my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
 
 257   my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
 
 259   $report->set_columns(%column_defs);
 
 260   $report->set_column_order(@columns);
 
 262   $report->set_export_options('report', @report_params);
 
 264   $report->set_sort_indicator($form->{sort}, $form->{sortdir});
 
 266   $report->set_options('raw_top_info_text'    => $form->parse_html_template('fu/report_top',    { 'OPTIONS' => \@options }),
 
 267                        'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN'  => \@hidden_report_params }),
 
 268                        'output_format'        => 'HTML',
 
 269                        'title'                => $form->{title},
 
 270                        'attachment_basename'  => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
 
 272   $report->set_options_from_form();
 
 275   my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
 
 276   my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
 
 278   foreach my $fu (@{ $follow_ups }) {
 
 281     $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
 
 283     my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
 
 286       'raw_data' =>   $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
 
 287                     . $cgi->checkbox('-name' => "selected_${idx}",   '-value' => 1, '-label' => ''),
 
 288       'valign'   => 'center',
 
 292     if (@{ $fu->{LINKS} }) {
 
 293       my $link = $fu->{LINKS}->[0];
 
 295       $row->{title}->{data} = $link->{title};
 
 296       $row->{title}->{link} = $link->{url};
 
 299     $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
 
 301     $report->add_data($row);
 
 304   $report->generate_with_headers();
 
 306   $lxdebug->leave_sub();
 
 309 sub report_for_todo_list {
 
 310   $lxdebug->enter_sub();
 
 312   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);
 
 317     'created_for_login' => $form->{login},
 
 320   my $follow_ups = FU->follow_ups(%params);
 
 323   if (@{ $follow_ups }) {
 
 324     my $callback = build_std_url('action');
 
 325     my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
 
 327     foreach my $fu (@{ $follow_ups }) {
 
 328       if (@{ $fu->{LINKS} }) {
 
 329         my $link = $fu->{LINKS}->[0];
 
 331         $fu->{reference}      = $link->{title};
 
 332         $fu->{reference_link} = $link->{url};
 
 336     $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
 
 337                                                                        'callback'   => $callback,
 
 338                                                                        'edit_url'   => $edit_url, });
 
 341   $lxdebug->leave_sub();
 
 346 sub edit_access_rights {
 
 347   $lxdebug->enter_sub();
 
 349   my $access = FU->retrieve_access_rights();
 
 351   $form->get_lists("employees" => "EMPLOYEES");
 
 353   map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
 
 355   $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
 
 358   print $form->parse_html_template('fu/edit_access_rights');
 
 360   $lxdebug->leave_sub();
 
 363 sub save_access_rights {
 
 364   $lxdebug->enter_sub();
 
 368   foreach my $i (1 .. $form->{rowcount}) {
 
 369     my $id = $form->{"employee_id_$i"};
 
 371     $access{$id} = 1 if ($id && $form->{"access_$id"});
 
 374   FU->save_access_rights('access' => \%access);
 
 376   $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
 
 377   edit_access_rights();
 
 379   $lxdebug->leave_sub();
 
 383   call_sub($form->{nextsub});
 
 387   call_sub($form->{nextsub});
 
 391   if ($form->{save_nextsub}) {
 
 392     call_sub($form->{save_nextsub});
 
 399   foreach my $action (qw(finish save delete)) {
 
 400     if ($form->{"action_${action}"}) {
 
 406   call_sub($form->{default_action}) if ($form->{default_action});
 
 408   $form->error($locale->text('No action defined.'));