1 use POSIX qw(strftime);
4 use SL::Locale::String qw(t8);
5 use SL::ReportGenerator;
7 require "bin/mozilla/reportgenerator.pl";
12 $main::lxdebug->enter_sub();
14 $main::auth->assert('productivity');
18 my $form = $main::form;
22 foreach my $i (1 .. $form->{trans_rowcount}) {
23 next if (!$form->{"trans_id_$i"} || !$form->{"trans_type_$i"});
25 push @{ $dest->{LINKS} }, { map { +"trans_$_" => $form->{"trans_${_}_$i"} } qw(id type info) };
28 $main::lxdebug->leave_sub();
32 $main::lxdebug->enter_sub();
34 $main::auth->assert('productivity');
36 my $form = $main::form;
37 my %myconfig = %main::myconfig;
38 my $locale = $main::locale;
40 _collect_links($form);
42 $form->get_employee($form->get_standard_dbh(\%myconfig));
43 $form->{created_for_user} = $form->{employee_id};
45 $form->{subject} = $form->{trans_subject_1} if $form->{trans_subject_1};
49 if (0 < scalar @{ $form->{LINKS} }) {
50 $link_details = FU->link_details(%{ $form->{LINKS}->[0] });
53 if ($link_details && $link_details->{title}) {
54 $form->{title} = $locale->text('Add Follow-Up for #1', $link_details->{title});
56 $form->{title} = $locale->text('Add Follow-Up');
61 $main::lxdebug->leave_sub();
65 $main::lxdebug->enter_sub();
67 $main::auth->assert('productivity');
69 my $form = $main::form;
70 my $locale = $main::locale;
72 my $ref = FU->retrieve('id' => $form->{id});
75 $form->error($locale->text("Invalid follow-up ID."));
78 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
80 if (@{ $form->{LINKS} } && $form->{LINKS}->[0]->{title}) {
81 $form->{title} = $locale->text('Edit Follow-Up for #1', $form->{LINKS}->[0]->{title});
83 $form->{title} = $locale->text('Edit Follow-Up');
88 $main::lxdebug->leave_sub();
92 $main::lxdebug->enter_sub();
94 $main::auth->assert('productivity');
96 my $form = $main::form;
98 $form->get_lists("employees" => "EMPLOYEES");
101 $params{not_id} = $form->{id} if ($form->{id});
102 $params{trans_id} = $form->{LINKS}->[0]->{trans_id} if (@{ $form->{LINKS} });
103 $form->{FOLLOW_UPS} = FU->follow_ups(%params);
105 setup_fu_display_form_action_bar() unless $::form->{POPUP_MODE};
107 $form->header(no_layout => $::form->{POPUP_MODE});
108 print $form->parse_html_template('fu/add_edit');
110 $main::lxdebug->leave_sub();
114 $main::lxdebug->enter_sub();
116 $main::auth->assert('productivity');
118 my $form = $main::form;
119 my $locale = $main::locale;
121 $form->isblank('created_for_user', $locale->text('You must chose a user.'));
122 $form->isblank('follow_up_date', $locale->text('The follow-up date is missing.'));
123 $form->isblank('subject', $locale->text('The subject is missing.'));
125 my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_user follow_up_date)), 'done' => 0);
127 _collect_links(\%params);
131 if ($form->{POPUP_MODE}) {
133 print $form->parse_html_template('fu/close_window');
134 $::dispatcher->end_request;
137 $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
139 if ($form->{callback}) {
143 delete @{$form}{qw(id subject body created_for_user follow_up_date)};
145 map { $form->{$_} = 1 } qw(due_only all_users not_done);
149 $main::lxdebug->leave_sub();
153 $main::lxdebug->enter_sub();
155 $main::auth->assert('productivity');
157 my $form = $main::form;
158 my $locale = $main::locale;
161 my $ref = FU->retrieve('id' => $form->{id});
164 $form->error($locale->text("Invalid follow-up ID."));
167 FU->finish('id' => $form->{id});
170 foreach my $i (1..$form->{rowcount}) {
171 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
173 FU->finish('id' => $form->{"follow_up_id_$i"});
177 if ($form->{POPUP_MODE}) {
179 print $form->parse_html_template('fu/close_window');
180 $::dispatcher->end_request;
183 $form->redirect() if ($form->{callback});
187 $main::lxdebug->leave_sub();
191 $main::lxdebug->enter_sub();
193 $main::auth->assert('productivity');
195 my $form = $main::form;
196 my $locale = $main::locale;
199 my $ref = FU->retrieve('id' => $form->{id});
202 $form->error($locale->text("Invalid follow-up ID."));
205 FU->delete('id' => $form->{id});
208 foreach my $i (1..$form->{rowcount}) {
209 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
211 FU->delete('id' => $form->{"follow_up_id_$i"});
215 if ($form->{POPUP_MODE}) {
217 print $form->parse_html_template('fu/close_window');
218 $::dispatcher->end_request;
221 $form->redirect() if ($form->{callback});
225 $main::lxdebug->leave_sub();
229 $main::lxdebug->enter_sub();
231 $main::auth->assert('productivity');
233 my $form = $main::form;
234 my $locale = $main::locale;
236 $form->get_lists("employees" => "EMPLOYEES");
238 $form->{title} = $locale->text('Follow-Ups');
240 setup_fu_search_action_bar();
242 print $form->parse_html_template('fu/search');
244 $main::lxdebug->leave_sub();
248 $main::lxdebug->enter_sub();
250 $main::auth->assert('productivity');
252 my $form = $main::form;
253 my %myconfig = %main::myconfig;
254 my $locale = $main::locale;
255 my $cgi = $::request->{cgi};
257 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);
259 report_generator_set_default_sort('follow_up_date', 1);
261 my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
262 $form->{rowcount} = scalar @{ $follow_ups };
264 $form->{title} = $locale->text('Follow-Ups');
267 'selected' => { 'text' => '', },
268 'follow_up_date' => { 'text' => $locale->text('Follow-Up Date'), },
269 'created_on' => { 'text' => $locale->text('Created on'), },
270 'title' => { 'text' => $locale->text('Reference'), },
271 'subject' => { 'text' => $locale->text('Subject'), },
272 'created_by_name' => { 'text' => $locale->text('Created by'), },
273 'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
274 'done' => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
277 my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
278 my $href = build_std_url('action=report', grep { $form->{$_} } @report_params);
280 foreach my $name (qw(follow_up_date created_on title subject)) {
281 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
282 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
287 if ($form->{created_for}) {
288 $form->get_lists("employees" => "EMPLOYEES");
290 foreach my $employee (@{ $form->{EMPLOYEES} }) {
291 if ($employee->{id} == $form->{created_for}) {
292 push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
298 push @options, $locale->text('Subject') . " : $form->{subject}" if ($form->{subject});
299 push @options, $locale->text('Body') . " : $form->{body}" if ($form->{body});
300 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
301 push @options, $locale->text('Done') if ($form->{done});
302 push @options, $locale->text('Not done yet') if ($form->{not_done});
303 push @options, $locale->text('Only due follow-ups') if ($form->{due_only});
304 push @options, $locale->text("Other users' follow-ups") if ($form->{all_users});
306 my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
308 my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
310 $report->set_columns(%column_defs);
311 $report->set_column_order(@columns);
313 $report->set_export_options('report', @report_params, qw(sort sortdir));
315 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
317 $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }),
318 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),
319 'output_format' => 'HTML',
320 'title' => $form->{title},
321 'attachment_basename' => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
323 $report->set_options_from_form();
324 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
327 my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
328 my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
330 foreach my $fu (@{ $follow_ups }) {
333 $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
335 my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
338 'raw_data' => $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
339 . $cgi->checkbox('-name' => "selected_${idx}", '-value' => 1, '-label' => ''),
340 'valign' => 'center',
344 if (@{ $fu->{LINKS} }) {
345 my $link = $fu->{LINKS}->[0];
347 $row->{title}->{data} = $link->{title};
348 $row->{title}->{link} = $link->{url};
351 $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
353 $report->add_data($row);
356 setup_fu_report_action_bar();
357 $report->generate_with_headers();
359 $main::lxdebug->leave_sub();
362 sub report_for_todo_list {
363 $main::lxdebug->enter_sub();
365 $main::auth->assert('productivity');
367 my $form = $main::form;
369 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);
374 'created_for_login' => $::myconfig{login},
377 my $follow_ups = FU->follow_ups(%params);
380 if (@{ $follow_ups }) {
381 my $callback = build_std_url('action');
382 my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
384 foreach my $fu (@{ $follow_ups }) {
385 if (@{ $fu->{LINKS} }) {
386 my $link = $fu->{LINKS}->[0];
388 $fu->{reference} = $link->{title};
389 $fu->{reference_link} = $link->{url};
393 $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
394 'callback' => $callback,
395 'edit_url' => $edit_url, });
398 $main::lxdebug->leave_sub();
403 sub edit_access_rights {
404 $main::lxdebug->enter_sub();
406 $main::auth->assert('productivity');
408 my $form = $main::form;
409 my $locale = $main::locale;
411 my $access = FU->retrieve_access_rights();
413 $form->{EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
415 map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
417 $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
419 setup_fu_edit_access_rights_action_bar();
422 print $form->parse_html_template('fu/edit_access_rights');
424 $main::lxdebug->leave_sub();
427 sub save_access_rights {
428 $main::lxdebug->enter_sub();
430 $main::auth->assert('productivity');
432 my $form = $main::form;
433 my $locale = $main::locale;
437 foreach my $i (1 .. $form->{rowcount}) {
438 my $id = $form->{"employee_id_$i"};
440 $access{$id} = 1 if ($id && $form->{"access_$id"});
443 FU->save_access_rights('access' => \%access);
445 $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
446 edit_access_rights();
448 $main::lxdebug->leave_sub();
452 call_sub($main::form->{nextsub});
456 call_sub($main::form->{nextsub});
460 $main::auth->assert('productivity');
462 if ($main::form->{save_nextsub}) {
463 call_sub($main::form->{save_nextsub});
470 $main::lxdebug->enter_sub();
472 my $form = $main::form;
473 my $locale = $main::locale;
475 foreach my $action (qw(finish save delete)) {
476 if ($form->{"action_${action}"}) {
482 call_sub($form->{default_action}) if ($form->{default_action});
484 $form->error($locale->text('No action defined.'));
487 sub setup_fu_search_action_bar {
490 for my $bar ($::request->layout->get('actionbar')) {
494 submit => [ '#form', { action => "report" } ],
495 accesskey => 'enter',
501 sub setup_fu_display_form_action_bar {
504 for my $bar ($::request->layout->get('actionbar')) {
508 submit => [ '#form', { action => "save" } ],
509 accesskey => 'enter',
513 submit => [ '#form', { action => "finish" } ],
514 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
518 submit => [ '#form', { action => "delete" } ],
519 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
520 confirm => t8('Do you really want to delete this object?'),
526 sub setup_fu_report_action_bar {
529 for my $bar ($::request->layout->get('actionbar')) {
533 submit => [ '#form', { action => "finish" } ],
534 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
538 submit => [ '#form', { action => "delete" } ],
539 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
540 confirm => t8('Do you really want to delete the selected objects?'),
546 sub setup_fu_edit_access_rights_action_bar {
549 for my $bar ($::request->layout->get('actionbar')) {
553 submit => [ '#form', { action => "save_access_rights" } ],
554 accesskey => 'enter',