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   my $follow_ups    = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
 
 209   $form->{rowcount} = scalar @{ $follow_ups };
 
 211   $form->{title}    = $locale->text('Follow-Ups');
 
 214     'selected'              => { 'text' => '', },
 
 215     'follow_up_date'        => { 'text' => $locale->text('Follow-Up Date'), },
 
 216     'created_on'            => { 'text' => $locale->text('Created on'), },
 
 217     'title'                 => { 'text' => $locale->text('Reference'), },
 
 218     'subject'               => { 'text' => $locale->text('Subject'), },
 
 219     'created_by_name'       => { 'text' => $locale->text('Created by'), },
 
 220     'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
 
 221     'done'                  => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
 
 224   my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
 
 228   if ($form->{created_for}) {
 
 229     $form->get_lists("employees" => "EMPLOYEES");
 
 231     foreach my $employee (@{ $form->{EMPLOYEES} }) {
 
 232       if ($employee->{id} == $form->{created_for}) {
 
 233         push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
 
 239   push @options, $locale->text('Subject')                  . " : $form->{subject}"   if ($form->{subject});
 
 240   push @options, $locale->text('Body')                     . " : $form->{body}"      if ($form->{body});
 
 241   push @options, $locale->text('Reference')                . " : $form->{reference}" if ($form->{reference});
 
 242   push @options, $locale->text('Done')                                               if ($form->{done});
 
 243   push @options, $locale->text('Not done yet')                                       if ($form->{not_done});
 
 244   push @options, $locale->text('Only due follow-ups')                                if ($form->{due_only});
 
 245   push @options, $locale->text("Other users' follow-ups")                            if ($form->{all_users});
 
 247   my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
 
 249   my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
 
 251   $report->set_columns(%column_defs);
 
 252   $report->set_column_order(@columns);
 
 254   $report->set_export_options('report', @report_params);
 
 256   $report->set_sort_indicator('follow_up_date', 1);
 
 258   $report->set_options('raw_top_info_text'    => $form->parse_html_template('fu/report_top',    { 'OPTIONS' => \@options }),
 
 259                        'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN'  => \@hidden_report_params }),
 
 260                        'output_format'        => 'HTML',
 
 261                        'title'                => $form->{title},
 
 262                        'attachment_basename'  => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
 
 264   $report->set_options_from_form();
 
 267   my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
 
 268   my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
 
 270   foreach my $fu (@{ $follow_ups }) {
 
 273     $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
 
 275     my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
 
 278       'raw_data' =>   $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
 
 279                     . $cgi->checkbox('-name' => "selected_${idx}",   '-value' => 1, '-label' => ''),
 
 280       'valign'   => 'center',
 
 284     if (@{ $fu->{LINKS} }) {
 
 285       my $link = $fu->{LINKS}->[0];
 
 287       $row->{title}->{data} = $link->{title};
 
 288       $row->{title}->{link} = $link->{url};
 
 291     $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
 
 293     $report->add_data($row);
 
 296   $report->generate_with_headers();
 
 298   $lxdebug->leave_sub();
 
 301 sub report_for_todo_list {
 
 302   $lxdebug->enter_sub();
 
 304   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);
 
 309     'created_for_login' => $form->{login},
 
 312   my $follow_ups = FU->follow_ups(%params);
 
 315   if (@{ $follow_ups }) {
 
 316     my $callback = build_std_url('action');
 
 317     my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
 
 319     foreach my $fu (@{ $follow_ups }) {
 
 320       if (@{ $fu->{LINKS} }) {
 
 321         my $link = $fu->{LINKS}->[0];
 
 323         $fu->{reference}      = $link->{title};
 
 324         $fu->{reference_link} = $link->{url};
 
 328     $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
 
 329                                                                        'callback'   => $callback,
 
 330                                                                        'edit_url'   => $edit_url, });
 
 333   $lxdebug->leave_sub();
 
 338 sub edit_access_rights {
 
 339   $lxdebug->enter_sub();
 
 341   my $access = FU->retrieve_access_rights();
 
 343   $form->get_lists("employees" => "EMPLOYEES");
 
 345   map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
 
 347   $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
 
 350   print $form->parse_html_template('fu/edit_access_rights');
 
 352   $lxdebug->leave_sub();
 
 355 sub save_access_rights {
 
 356   $lxdebug->enter_sub();
 
 360   foreach my $i (1 .. $form->{rowcount}) {
 
 361     my $id = $form->{"employee_id_$i"};
 
 363     $access{$id} = 1 if ($id && $form->{"access_$id"});
 
 366   FU->save_access_rights('access' => \%access);
 
 368   $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
 
 369   edit_access_rights();
 
 371   $lxdebug->leave_sub();
 
 375   call_sub($form->{nextsub});
 
 379   call_sub($form->{nextsub});
 
 383   if ($form->{save_nextsub}) {
 
 384     call_sub($form->{save_nextsub});
 
 391   foreach my $action (qw(finish save delete)) {
 
 392     if ($form->{"action_${action}"}) {
 
 398   call_sub($form->{default_action}) if ($form->{default_action});
 
 400   $form->error($locale->text('No action defined.'));