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} });
104 $form->{sort} = 'follow_up_date';
105 $form->{FOLLOW_UPS_DONE} = FU->follow_ups(%params, done => 1);
106 $form->{FOLLOW_UPS_PENDING} = FU->follow_ups(%params, not_done => 1);
108 setup_fu_display_form_action_bar() unless $::form->{POPUP_MODE};
110 $form->header(no_layout => $::form->{POPUP_MODE});
111 print $form->parse_html_template('fu/add_edit');
113 $main::lxdebug->leave_sub();
117 $main::lxdebug->enter_sub();
119 $main::auth->assert('productivity');
121 my $form = $main::form;
122 my $locale = $main::locale;
124 $form->isblank('created_for_user', $locale->text('You must chose a user.'));
125 $form->isblank('follow_up_date', $locale->text('The follow-up date is missing.'));
126 $form->isblank('subject', $locale->text('The subject is missing.'));
128 my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_user follow_up_date)), 'done' => 0);
130 _collect_links(\%params);
134 if ($form->{POPUP_MODE}) {
136 print $form->parse_html_template('fu/close_window');
137 $::dispatcher->end_request;
140 $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
142 if ($form->{callback}) {
146 delete @{$form}{qw(id subject body created_for_user follow_up_date)};
148 map { $form->{$_} = 1 } qw(due_only all_users not_done);
152 $main::lxdebug->leave_sub();
156 $main::lxdebug->enter_sub();
158 $main::auth->assert('productivity');
160 my $form = $main::form;
161 my $locale = $main::locale;
164 my $ref = FU->retrieve('id' => $form->{id});
167 $form->error($locale->text("Invalid follow-up ID."));
170 FU->finish('id' => $form->{id});
173 foreach my $i (1..$form->{rowcount}) {
174 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
176 FU->finish('id' => $form->{"follow_up_id_$i"});
180 if ($form->{POPUP_MODE}) {
182 print $form->parse_html_template('fu/close_window');
183 $::dispatcher->end_request;
186 $form->redirect() if ($form->{callback});
190 $main::lxdebug->leave_sub();
194 $main::lxdebug->enter_sub();
196 $main::auth->assert('productivity');
198 my $form = $main::form;
199 my $locale = $main::locale;
202 my $ref = FU->retrieve('id' => $form->{id});
205 $form->error($locale->text("Invalid follow-up ID."));
208 FU->delete('id' => $form->{id});
211 foreach my $i (1..$form->{rowcount}) {
212 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
214 FU->delete('id' => $form->{"follow_up_id_$i"});
218 if ($form->{POPUP_MODE}) {
220 print $form->parse_html_template('fu/close_window');
221 $::dispatcher->end_request;
224 $form->redirect() if ($form->{callback});
228 $main::lxdebug->leave_sub();
232 $main::lxdebug->enter_sub();
234 $main::auth->assert('productivity');
236 my $form = $main::form;
237 my $locale = $main::locale;
239 $form->get_lists("employees" => "EMPLOYEES");
241 $form->{title} = $locale->text('Follow-Ups');
243 setup_fu_search_action_bar();
245 print $form->parse_html_template('fu/search');
247 $main::lxdebug->leave_sub();
251 $main::lxdebug->enter_sub();
253 $main::auth->assert('productivity');
255 my $form = $main::form;
256 my %myconfig = %main::myconfig;
257 my $locale = $main::locale;
258 my $cgi = $::request->{cgi};
260 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);
262 report_generator_set_default_sort('follow_up_date', 1);
264 my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
265 $form->{rowcount} = scalar @{ $follow_ups };
267 $form->{title} = $locale->text('Follow-Ups');
270 'selected' => { 'text' => '', },
271 'follow_up_date' => { 'text' => $locale->text('Follow-Up Date'), },
272 'created_on' => { 'text' => $locale->text('Created on'), },
273 'title' => { 'text' => $locale->text('Reference'), },
274 'subject' => { 'text' => $locale->text('Subject'), },
275 'created_by_name' => { 'text' => $locale->text('Created by'), },
276 'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
277 'done' => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
280 my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
281 my $href = build_std_url('action=report', grep { $form->{$_} } @report_params);
283 foreach my $name (qw(follow_up_date created_on title subject)) {
284 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
285 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
290 if ($form->{created_for}) {
291 $form->get_lists("employees" => "EMPLOYEES");
293 foreach my $employee (@{ $form->{EMPLOYEES} }) {
294 if ($employee->{id} == $form->{created_for}) {
295 push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
301 push @options, $locale->text('Subject') . " : $form->{subject}" if ($form->{subject});
302 push @options, $locale->text('Body') . " : $form->{body}" if ($form->{body});
303 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
304 push @options, $locale->text('Done') if ($form->{done});
305 push @options, $locale->text('Not done yet') if ($form->{not_done});
306 push @options, $locale->text('Only due follow-ups') if ($form->{due_only});
307 push @options, $locale->text("Other users' follow-ups") if ($form->{all_users});
309 my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
311 my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
313 $report->set_columns(%column_defs);
314 $report->set_column_order(@columns);
316 $report->set_export_options('report', @report_params, qw(sort sortdir));
318 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
320 $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }),
321 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),
322 'output_format' => 'HTML',
323 'title' => $form->{title},
324 'attachment_basename' => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
326 $report->set_options_from_form();
327 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
330 my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
331 my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
333 foreach my $fu (@{ $follow_ups }) {
336 $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
338 my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
341 'raw_data' => $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
342 . $cgi->checkbox('-name' => "selected_${idx}", '-value' => 1, '-label' => ''),
343 'valign' => 'center',
347 if (@{ $fu->{LINKS} }) {
348 my $link = $fu->{LINKS}->[0];
350 $row->{title}->{data} = $link->{title};
351 $row->{title}->{link} = $link->{url};
354 $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
356 $report->add_data($row);
359 setup_fu_report_action_bar();
360 $report->generate_with_headers();
362 $main::lxdebug->leave_sub();
365 sub report_for_todo_list {
366 $main::lxdebug->enter_sub();
368 $main::auth->assert('productivity');
370 my $form = $main::form;
372 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);
377 'created_for_login' => $::myconfig{login},
380 my $follow_ups = FU->follow_ups(%params);
383 if (@{ $follow_ups }) {
384 my $callback = build_std_url('action');
385 my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
387 foreach my $fu (@{ $follow_ups }) {
388 if (@{ $fu->{LINKS} }) {
389 my $link = $fu->{LINKS}->[0];
391 $fu->{reference} = $link->{title};
392 $fu->{reference_link} = $link->{url};
396 $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
397 'callback' => $callback,
398 'edit_url' => $edit_url, });
401 $main::lxdebug->leave_sub();
406 sub edit_access_rights {
407 $main::lxdebug->enter_sub();
409 $main::auth->assert('productivity');
411 my $form = $main::form;
412 my $locale = $main::locale;
414 my $access = FU->retrieve_access_rights();
416 $form->{EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
418 map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
420 $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
422 setup_fu_edit_access_rights_action_bar();
425 print $form->parse_html_template('fu/edit_access_rights');
427 $main::lxdebug->leave_sub();
430 sub save_access_rights {
431 $main::lxdebug->enter_sub();
433 $main::auth->assert('productivity');
435 my $form = $main::form;
436 my $locale = $main::locale;
440 foreach my $i (1 .. $form->{rowcount}) {
441 my $id = $form->{"employee_id_$i"};
443 $access{$id} = 1 if ($id && $form->{"access_$id"});
446 FU->save_access_rights('access' => \%access);
448 $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
449 edit_access_rights();
451 $main::lxdebug->leave_sub();
455 call_sub($main::form->{nextsub});
459 call_sub($main::form->{nextsub});
463 $main::auth->assert('productivity');
465 if ($main::form->{save_nextsub}) {
466 call_sub($main::form->{save_nextsub});
473 $main::lxdebug->enter_sub();
475 my $form = $main::form;
476 my $locale = $main::locale;
478 foreach my $action (qw(finish save delete)) {
479 if ($form->{"action_${action}"}) {
485 call_sub($form->{default_action}) if ($form->{default_action});
487 $form->error($locale->text('No action defined.'));
490 sub setup_fu_search_action_bar {
493 for my $bar ($::request->layout->get('actionbar')) {
497 submit => [ '#form', { action => "report" } ],
498 accesskey => 'enter',
504 sub setup_fu_display_form_action_bar {
507 for my $bar ($::request->layout->get('actionbar')) {
511 submit => [ '#form', { action => "save" } ],
512 accesskey => 'enter',
516 submit => [ '#form', { action => "finish" } ],
517 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
521 submit => [ '#form', { action => "delete" } ],
522 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
523 confirm => t8('Do you really want to delete this object?'),
529 sub setup_fu_report_action_bar {
532 for my $bar ($::request->layout->get('actionbar')) {
536 submit => [ '#form', { action => "finish" } ],
537 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
541 submit => [ '#form', { action => "delete" } ],
542 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
543 confirm => t8('Do you really want to delete the selected objects?'),
549 sub setup_fu_edit_access_rights_action_bar {
552 for my $bar ($::request->layout->get('actionbar')) {
556 submit => [ '#form', { action => "save_access_rights" } ],
557 accesskey => 'enter',