1 use POSIX qw(strftime);
4 use SL::Locale::String qw(t8);
5 use SL::ReportGenerator;
9 require "bin/mozilla/reportgenerator.pl";
14 $main::lxdebug->enter_sub();
16 $main::auth->assert('productivity');
20 my $form = $main::form;
24 foreach my $i (1 .. $form->{trans_rowcount}) {
25 next if (!$form->{"trans_id_$i"} || !$form->{"trans_type_$i"});
27 push @{ $dest->{LINKS} }, { map { +"trans_$_" => $form->{"trans_${_}_$i"} } qw(id type info) };
30 $main::lxdebug->leave_sub();
34 $main::lxdebug->enter_sub();
36 $main::auth->assert('productivity');
38 my $form = $main::form;
39 my %myconfig = %main::myconfig;
40 my $locale = $main::locale;
42 _collect_links($form);
44 $form->get_employee($form->get_standard_dbh(\%myconfig));
46 push @{$form->{created_for_employees}}, SL::DB::Manager::Employee->current;
48 $form->{subject} = $form->{trans_subject_1} if $form->{trans_subject_1};
52 if (0 < scalar @{ $form->{LINKS} }) {
53 $link_details = FU->link_details(%{ $form->{LINKS}->[0] });
56 if ($link_details && $link_details->{title}) {
57 $form->{title} = $locale->text('Add Follow-Up for #1', $link_details->{title});
59 $form->{title} = $locale->text('Add Follow-Up');
64 $main::lxdebug->leave_sub();
68 $main::lxdebug->enter_sub();
70 $main::auth->assert('productivity');
72 my $form = $main::form;
73 my $locale = $main::locale;
75 my $ref = FU->retrieve('id' => $form->{id});
78 $form->error($locale->text("Invalid follow-up ID."));
81 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
83 if (@{ $form->{LINKS} } && $form->{LINKS}->[0]->{title}) {
84 $form->{title} = $locale->text('Edit Follow-Up for #1', $form->{LINKS}->[0]->{title});
86 $form->{title} = $locale->text('Edit Follow-Up');
89 $form->{created_for_employees} = SL::DB::FollowUp->new(id => $form->{id})->load->created_for_employees;
93 $main::lxdebug->leave_sub();
97 $main::lxdebug->enter_sub();
99 $main::auth->assert('productivity');
101 my $form = $main::form;
103 $form->{all_employees} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
104 $form->{all_auth_groups} = SL::DB::Manager::AuthGroup->get_all_sorted;
107 $params{not_id} = $form->{id} if ($form->{id});
108 $params{trans_id} = $form->{LINKS}->[0]->{trans_id} if (@{ $form->{LINKS} });
110 $form->{sort} = 'follow_up_date';
111 $form->{FOLLOW_UPS_DONE} = FU->follow_ups(%params, done => 1);
112 $form->{FOLLOW_UPS_PENDING} = FU->follow_ups(%params, not_done => 1);
114 setup_fu_display_form_action_bar() unless $::form->{POPUP_MODE};
116 $form->header(no_layout => $::form->{POPUP_MODE},
117 use_javascripts => [ qw(follow_up) ],
119 print $form->parse_html_template('fu/add_edit');
121 $main::lxdebug->leave_sub();
125 $main::lxdebug->enter_sub();
127 $main::auth->assert('productivity');
129 my $form = $main::form;
130 my $locale = $main::locale;
132 $form->error( $locale->text('You must chose a user.')) if !$form->{created_for_employees};
133 $form->isblank('follow_up_date', $locale->text('The follow-up date is missing.'));
134 $form->isblank('subject', $locale->text('The subject is missing.'));
136 my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_employees follow_up_date)), 'done' => 0);
138 _collect_links(\%params);
142 if ($form->{POPUP_MODE}) {
144 print $form->parse_html_template('fu/close_window');
145 $::dispatcher->end_request;
148 $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
150 if ($form->{callback}) {
154 delete @{$form}{qw(id subject body created_for_employees follow_up_date)};
156 map { $form->{$_} = 1 } qw(due_only all_users not_done);
160 $main::lxdebug->leave_sub();
164 $main::lxdebug->enter_sub();
166 $main::auth->assert('productivity');
168 my $form = $main::form;
169 my $locale = $main::locale;
172 my $ref = FU->retrieve('id' => $form->{id});
175 $form->error($locale->text("Invalid follow-up ID."));
178 FU->finish('id' => $form->{id});
181 foreach my $i (1..$form->{rowcount}) {
182 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
184 FU->finish('id' => $form->{"follow_up_id_$i"});
188 if ($form->{POPUP_MODE}) {
190 print $form->parse_html_template('fu/close_window');
191 $::dispatcher->end_request;
194 $form->redirect() if ($form->{callback});
198 $main::lxdebug->leave_sub();
202 $main::lxdebug->enter_sub();
204 $main::auth->assert('productivity');
206 my $form = $main::form;
207 my $locale = $main::locale;
210 my $ref = FU->retrieve('id' => $form->{id});
213 $form->error($locale->text("Invalid follow-up ID."));
216 FU->delete('id' => $form->{id});
219 foreach my $i (1..$form->{rowcount}) {
220 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
222 FU->delete('id' => $form->{"follow_up_id_$i"});
226 if ($form->{POPUP_MODE}) {
228 print $form->parse_html_template('fu/close_window');
229 $::dispatcher->end_request;
232 $form->redirect() if ($form->{callback});
236 $main::lxdebug->leave_sub();
240 $main::lxdebug->enter_sub();
242 $main::auth->assert('productivity');
244 my $form = $main::form;
245 my $locale = $main::locale;
247 $form->get_lists("employees" => "EMPLOYEES");
249 $form->{title} = $locale->text('Follow-Ups');
251 setup_fu_search_action_bar();
253 print $form->parse_html_template('fu/search');
255 $main::lxdebug->leave_sub();
259 $main::lxdebug->enter_sub();
261 $main::auth->assert('productivity');
263 my $form = $main::form;
264 my %myconfig = %main::myconfig;
265 my $locale = $main::locale;
266 my $cgi = $::request->{cgi};
268 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);
270 report_generator_set_default_sort('follow_up_date', 1);
272 my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
273 $form->{rowcount} = scalar @{ $follow_ups };
275 $form->{title} = $locale->text('Follow-Ups');
278 'selected' => { 'text' => '', },
279 'follow_up_date' => { 'text' => $locale->text('Follow-Up Date'), },
280 'created_on' => { 'text' => $locale->text('Created on'), },
281 'title' => { 'text' => $locale->text('Reference'), },
282 'subject' => { 'text' => $locale->text('Subject'), },
283 'created_by_name' => { 'text' => $locale->text('Created by'), },
284 'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
285 'done' => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
288 my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
289 my $href = build_std_url('action=report', grep { $form->{$_} } @report_params);
291 foreach my $name (qw(follow_up_date created_on title subject)) {
292 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
293 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
298 if ($form->{created_for}) {
299 $form->get_lists("employees" => "EMPLOYEES");
301 foreach my $employee (@{ $form->{EMPLOYEES} }) {
302 if ($employee->{id} == $form->{created_for}) {
303 push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
309 push @options, $locale->text('Subject') . " : $form->{subject}" if ($form->{subject});
310 push @options, $locale->text('Body') . " : $form->{body}" if ($form->{body});
311 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
312 push @options, $locale->text('Done') if ($form->{done});
313 push @options, $locale->text('Not done yet') if ($form->{not_done});
314 push @options, $locale->text('Only due follow-ups') if ($form->{due_only});
315 push @options, $locale->text("Other users' follow-ups") if ($form->{all_users});
317 my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
319 my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
321 $report->set_columns(%column_defs);
322 $report->set_column_order(@columns);
324 $report->set_export_options('report', @report_params, qw(sort sortdir));
326 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
328 $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }),
329 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),
330 'output_format' => 'HTML',
331 'title' => $form->{title},
332 'attachment_basename' => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
334 $report->set_options_from_form();
335 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
338 my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
339 my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
341 foreach my $fu (@{ $follow_ups }) {
344 $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
346 my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
349 'raw_data' => $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
350 . $cgi->checkbox('-name' => "selected_${idx}", '-value' => 1, '-label' => ''),
351 'valign' => 'center',
355 if (@{ $fu->{LINKS} }) {
356 my $link = $fu->{LINKS}->[0];
358 $row->{title}->{data} = $link->{title};
359 $row->{title}->{link} = $link->{url};
362 $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
364 $report->add_data($row);
367 setup_fu_report_action_bar();
368 $report->generate_with_headers();
370 $main::lxdebug->leave_sub();
373 sub report_for_todo_list {
374 $main::lxdebug->enter_sub();
376 $main::auth->assert('productivity');
378 my $form = $main::form;
380 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);
385 'created_for_login' => $::myconfig{login},
388 my $follow_ups = FU->follow_ups(%params);
391 if (@{ $follow_ups }) {
392 my $callback = build_std_url('action');
393 my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
395 foreach my $fu (@{ $follow_ups }) {
396 if (@{ $fu->{LINKS} }) {
397 my $link = $fu->{LINKS}->[0];
399 $fu->{reference} = $link->{title};
400 $fu->{reference_link} = $link->{url};
404 $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
405 'callback' => $callback,
406 'edit_url' => $edit_url, });
409 $main::lxdebug->leave_sub();
414 sub edit_access_rights {
415 $main::lxdebug->enter_sub();
417 $main::auth->assert('productivity');
419 my $form = $main::form;
420 my $locale = $main::locale;
422 my $access = FU->retrieve_access_rights();
424 $form->{EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
426 map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
428 $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
430 setup_fu_edit_access_rights_action_bar();
433 print $form->parse_html_template('fu/edit_access_rights');
435 $main::lxdebug->leave_sub();
438 sub save_access_rights {
439 $main::lxdebug->enter_sub();
441 $main::auth->assert('productivity');
443 my $form = $main::form;
444 my $locale = $main::locale;
448 foreach my $i (1 .. $form->{rowcount}) {
449 my $id = $form->{"employee_id_$i"};
451 $access{$id} = 1 if ($id && $form->{"access_$id"});
454 FU->save_access_rights('access' => \%access);
456 $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
457 edit_access_rights();
459 $main::lxdebug->leave_sub();
463 call_sub($main::form->{nextsub});
467 call_sub($main::form->{nextsub});
471 $main::auth->assert('productivity');
473 if ($main::form->{save_nextsub}) {
474 call_sub($main::form->{save_nextsub});
481 $main::lxdebug->enter_sub();
483 my $form = $main::form;
484 my $locale = $main::locale;
486 foreach my $action (qw(finish save delete)) {
487 if ($form->{"action_${action}"}) {
493 call_sub($form->{default_action}) if ($form->{default_action});
495 $form->error($locale->text('No action defined.'));
498 sub setup_fu_search_action_bar {
501 for my $bar ($::request->layout->get('actionbar')) {
505 submit => [ '#form', { action => "report" } ],
506 accesskey => 'enter',
512 sub setup_fu_display_form_action_bar {
515 for my $bar ($::request->layout->get('actionbar')) {
519 submit => [ '#form', { action => "save" } ],
520 accesskey => 'enter',
524 submit => [ '#form', { action => "finish" } ],
525 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
529 submit => [ '#form', { action => "delete" } ],
530 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
531 confirm => t8('Do you really want to delete this object?'),
537 sub setup_fu_report_action_bar {
540 for my $bar ($::request->layout->get('actionbar')) {
544 submit => [ '#form', { action => "finish" } ],
545 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
549 submit => [ '#form', { action => "delete" } ],
550 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
551 confirm => t8('Do you really want to delete the selected objects?'),
557 sub setup_fu_edit_access_rights_action_bar {
560 for my $bar ($::request->layout->get('actionbar')) {
564 submit => [ '#form', { action => "save_access_rights" } ],
565 accesskey => 'enter',