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->header(no_layout => $::form->{POPUP_MODE});
103 print $form->parse_html_template('fu/add_edit');
105 $main::lxdebug->leave_sub();
109 $main::lxdebug->enter_sub();
111 $main::auth->assert('productivity');
113 my $form = $main::form;
114 my $locale = $main::locale;
116 $form->isblank('created_for_user', $locale->text('You must chose a user.'));
117 $form->isblank('follow_up_date', $locale->text('The follow-up date is missing.'));
118 $form->isblank('subject', $locale->text('The subject is missing.'));
120 my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_user follow_up_date)), 'done' => 0);
122 _collect_links(\%params);
126 if ($form->{POPUP_MODE}) {
128 print $form->parse_html_template('fu/close_window');
132 $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
134 if ($form->{callback}) {
138 delete @{$form}{qw(id subject body created_for_user follow_up_date)};
140 map { $form->{$_} = 1 } qw(due_only all_users not_done);
144 $main::lxdebug->leave_sub();
148 $main::lxdebug->enter_sub();
150 $main::auth->assert('productivity');
152 my $form = $main::form;
153 my $locale = $main::locale;
156 my $ref = FU->retrieve('id' => $form->{id});
159 $form->error($locale->text("Invalid follow-up ID."));
162 FU->finish('id' => $form->{id});
165 foreach my $i (1..$form->{rowcount}) {
166 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
168 FU->finish('id' => $form->{"follow_up_id_$i"});
172 if ($form->{POPUP_MODE}) {
174 print $form->parse_html_template('fu/close_window');
178 $form->redirect() if ($form->{callback});
182 $main::lxdebug->leave_sub();
186 $main::lxdebug->enter_sub();
188 $main::auth->assert('productivity');
190 my $form = $main::form;
191 my $locale = $main::locale;
194 my $ref = FU->retrieve('id' => $form->{id});
197 $form->error($locale->text("Invalid follow-up ID."));
200 FU->delete('id' => $form->{id});
203 foreach my $i (1..$form->{rowcount}) {
204 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
206 FU->delete('id' => $form->{"follow_up_id_$i"});
210 if ($form->{POPUP_MODE}) {
212 print $form->parse_html_template('fu/close_window');
216 $form->redirect() if ($form->{callback});
220 $main::lxdebug->leave_sub();
224 $main::lxdebug->enter_sub();
226 $main::auth->assert('productivity');
228 my $form = $main::form;
229 my $locale = $main::locale;
231 $form->get_lists("employees" => "EMPLOYEES");
233 $form->{title} = $locale->text('Follow-Ups');
236 print $form->parse_html_template('fu/search');
238 $main::lxdebug->leave_sub();
242 $main::lxdebug->enter_sub();
244 $main::auth->assert('productivity');
246 my $form = $main::form;
247 my %myconfig = %main::myconfig;
248 my $locale = $main::locale;
249 my $cgi = $::request->{cgi};
251 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);
253 report_generator_set_default_sort('follow_up_date', 1);
255 my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
256 $form->{rowcount} = scalar @{ $follow_ups };
258 $form->{title} = $locale->text('Follow-Ups');
261 'selected' => { 'text' => '', },
262 'follow_up_date' => { 'text' => $locale->text('Follow-Up Date'), },
263 'created_on' => { 'text' => $locale->text('Created on'), },
264 'title' => { 'text' => $locale->text('Reference'), },
265 'subject' => { 'text' => $locale->text('Subject'), },
266 'created_by_name' => { 'text' => $locale->text('Created by'), },
267 'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
268 'done' => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
271 my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
272 my $href = build_std_url('action=report', grep { $form->{$_} } @report_params);
274 foreach my $name (qw(follow_up_date created_on title subject)) {
275 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
276 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
281 if ($form->{created_for}) {
282 $form->get_lists("employees" => "EMPLOYEES");
284 foreach my $employee (@{ $form->{EMPLOYEES} }) {
285 if ($employee->{id} == $form->{created_for}) {
286 push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
292 push @options, $locale->text('Subject') . " : $form->{subject}" if ($form->{subject});
293 push @options, $locale->text('Body') . " : $form->{body}" if ($form->{body});
294 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
295 push @options, $locale->text('Done') if ($form->{done});
296 push @options, $locale->text('Not done yet') if ($form->{not_done});
297 push @options, $locale->text('Only due follow-ups') if ($form->{due_only});
298 push @options, $locale->text("Other users' follow-ups") if ($form->{all_users});
300 my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
302 my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
304 $report->set_columns(%column_defs);
305 $report->set_column_order(@columns);
307 $report->set_export_options('report', @report_params, qw(sort sortdir));
309 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
311 $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }),
312 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),
313 'output_format' => 'HTML',
314 'title' => $form->{title},
315 'attachment_basename' => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
317 $report->set_options_from_form();
318 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
321 my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
322 my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
324 foreach my $fu (@{ $follow_ups }) {
327 $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
329 my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
332 'raw_data' => $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
333 . $cgi->checkbox('-name' => "selected_${idx}", '-value' => 1, '-label' => ''),
334 'valign' => 'center',
338 if (@{ $fu->{LINKS} }) {
339 my $link = $fu->{LINKS}->[0];
341 $row->{title}->{data} = $link->{title};
342 $row->{title}->{link} = $link->{url};
345 $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
347 $report->add_data($row);
350 $report->generate_with_headers();
352 $main::lxdebug->leave_sub();
355 sub report_for_todo_list {
356 $main::lxdebug->enter_sub();
358 $main::auth->assert('productivity');
360 my $form = $main::form;
362 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);
367 'created_for_login' => $form->{login},
370 my $follow_ups = FU->follow_ups(%params);
373 if (@{ $follow_ups }) {
374 my $callback = build_std_url('action');
375 my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
377 foreach my $fu (@{ $follow_ups }) {
378 if (@{ $fu->{LINKS} }) {
379 my $link = $fu->{LINKS}->[0];
381 $fu->{reference} = $link->{title};
382 $fu->{reference_link} = $link->{url};
386 $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
387 'callback' => $callback,
388 'edit_url' => $edit_url, });
391 $main::lxdebug->leave_sub();
396 sub edit_access_rights {
397 $main::lxdebug->enter_sub();
399 $main::auth->assert('productivity');
401 my $form = $main::form;
402 my $locale = $main::locale;
404 my $access = FU->retrieve_access_rights();
406 $form->{EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
408 map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
410 $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
413 print $form->parse_html_template('fu/edit_access_rights');
415 $main::lxdebug->leave_sub();
418 sub save_access_rights {
419 $main::lxdebug->enter_sub();
421 $main::auth->assert('productivity');
423 my $form = $main::form;
424 my $locale = $main::locale;
428 foreach my $i (1 .. $form->{rowcount}) {
429 my $id = $form->{"employee_id_$i"};
431 $access{$id} = 1 if ($id && $form->{"access_$id"});
434 FU->save_access_rights('access' => \%access);
436 $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
437 edit_access_rights();
439 $main::lxdebug->leave_sub();
443 call_sub($main::form->{nextsub});
447 call_sub($main::form->{nextsub});
451 $main::auth->assert('productivity');
453 if ($main::form->{save_nextsub}) {
454 call_sub($main::form->{save_nextsub});
461 $main::lxdebug->enter_sub();
463 my $form = $main::form;
464 my $locale = $main::locale;
466 foreach my $action (qw(finish save delete)) {
467 if ($form->{"action_${action}"}) {
473 call_sub($form->{default_action}) if ($form->{default_action});
475 $form->error($locale->text('No action defined.'));