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};
47 if (0 < scalar @{ $form->{LINKS} }) {
48 $link_details = FU->link_details(%{ $form->{LINKS}->[0] });
51 if ($link_details && $link_details->{title}) {
52 $form->{title} = $locale->text('Add Follow-Up for #1', $link_details->{title});
54 $form->{title} = $locale->text('Add Follow-Up');
59 $main::lxdebug->leave_sub();
63 $main::lxdebug->enter_sub();
65 $main::auth->assert('productivity');
67 my $form = $main::form;
68 my $locale = $main::locale;
70 my $ref = FU->retrieve('id' => $form->{id});
73 $form->error($locale->text("Invalid follow-up ID."));
76 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
78 if (@{ $form->{LINKS} } && $form->{LINKS}->[0]->{title}) {
79 $form->{title} = $locale->text('Edit Follow-Up for #1', $form->{LINKS}->[0]->{title});
81 $form->{title} = $locale->text('Edit Follow-Up');
86 $main::lxdebug->leave_sub();
90 $main::lxdebug->enter_sub();
92 $main::auth->assert('productivity');
94 my $form = $main::form;
96 $form->get_lists("employees" => "EMPLOYEES");
99 $params{not_id} = $form->{id} if ($form->{id});
100 $params{trans_id} = $form->{LINKS}->[0]->{trans_id} if (@{ $form->{LINKS} });
101 $form->{FOLLOW_UPS} = FU->follow_ups(%params);
103 setup_fu_display_form_action_bar() unless $::form->{POPUP_MODE};
105 $form->header(no_layout => $::form->{POPUP_MODE});
106 print $form->parse_html_template('fu/add_edit');
108 $main::lxdebug->leave_sub();
112 $main::lxdebug->enter_sub();
114 $main::auth->assert('productivity');
116 my $form = $main::form;
117 my $locale = $main::locale;
119 $form->isblank('created_for_user', $locale->text('You must chose a user.'));
120 $form->isblank('follow_up_date', $locale->text('The follow-up date is missing.'));
121 $form->isblank('subject', $locale->text('The subject is missing.'));
123 my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_user follow_up_date)), 'done' => 0);
125 _collect_links(\%params);
129 if ($form->{POPUP_MODE}) {
131 print $form->parse_html_template('fu/close_window');
132 $::dispatcher->end_request;
135 $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
137 if ($form->{callback}) {
141 delete @{$form}{qw(id subject body created_for_user follow_up_date)};
143 map { $form->{$_} = 1 } qw(due_only all_users not_done);
147 $main::lxdebug->leave_sub();
151 $main::lxdebug->enter_sub();
153 $main::auth->assert('productivity');
155 my $form = $main::form;
156 my $locale = $main::locale;
159 my $ref = FU->retrieve('id' => $form->{id});
162 $form->error($locale->text("Invalid follow-up ID."));
165 FU->finish('id' => $form->{id});
168 foreach my $i (1..$form->{rowcount}) {
169 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
171 FU->finish('id' => $form->{"follow_up_id_$i"});
175 if ($form->{POPUP_MODE}) {
177 print $form->parse_html_template('fu/close_window');
178 $::dispatcher->end_request;
181 $form->redirect() if ($form->{callback});
185 $main::lxdebug->leave_sub();
189 $main::lxdebug->enter_sub();
191 $main::auth->assert('productivity');
193 my $form = $main::form;
194 my $locale = $main::locale;
197 my $ref = FU->retrieve('id' => $form->{id});
200 $form->error($locale->text("Invalid follow-up ID."));
203 FU->delete('id' => $form->{id});
206 foreach my $i (1..$form->{rowcount}) {
207 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
209 FU->delete('id' => $form->{"follow_up_id_$i"});
213 if ($form->{POPUP_MODE}) {
215 print $form->parse_html_template('fu/close_window');
216 $::dispatcher->end_request;
219 $form->redirect() if ($form->{callback});
223 $main::lxdebug->leave_sub();
227 $main::lxdebug->enter_sub();
229 $main::auth->assert('productivity');
231 my $form = $main::form;
232 my $locale = $main::locale;
234 $form->get_lists("employees" => "EMPLOYEES");
236 $form->{title} = $locale->text('Follow-Ups');
238 setup_fu_search_action_bar();
240 print $form->parse_html_template('fu/search');
242 $main::lxdebug->leave_sub();
246 $main::lxdebug->enter_sub();
248 $main::auth->assert('productivity');
250 my $form = $main::form;
251 my %myconfig = %main::myconfig;
252 my $locale = $main::locale;
253 my $cgi = $::request->{cgi};
255 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);
257 report_generator_set_default_sort('follow_up_date', 1);
259 my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
260 $form->{rowcount} = scalar @{ $follow_ups };
262 $form->{title} = $locale->text('Follow-Ups');
265 'selected' => { 'text' => '', },
266 'follow_up_date' => { 'text' => $locale->text('Follow-Up Date'), },
267 'created_on' => { 'text' => $locale->text('Created on'), },
268 'title' => { 'text' => $locale->text('Reference'), },
269 'subject' => { 'text' => $locale->text('Subject'), },
270 'created_by_name' => { 'text' => $locale->text('Created by'), },
271 'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
272 'done' => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
275 my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
276 my $href = build_std_url('action=report', grep { $form->{$_} } @report_params);
278 foreach my $name (qw(follow_up_date created_on title subject)) {
279 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
280 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
285 if ($form->{created_for}) {
286 $form->get_lists("employees" => "EMPLOYEES");
288 foreach my $employee (@{ $form->{EMPLOYEES} }) {
289 if ($employee->{id} == $form->{created_for}) {
290 push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
296 push @options, $locale->text('Subject') . " : $form->{subject}" if ($form->{subject});
297 push @options, $locale->text('Body') . " : $form->{body}" if ($form->{body});
298 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
299 push @options, $locale->text('Done') if ($form->{done});
300 push @options, $locale->text('Not done yet') if ($form->{not_done});
301 push @options, $locale->text('Only due follow-ups') if ($form->{due_only});
302 push @options, $locale->text("Other users' follow-ups") if ($form->{all_users});
304 my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
306 my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
308 $report->set_columns(%column_defs);
309 $report->set_column_order(@columns);
311 $report->set_export_options('report', @report_params, qw(sort sortdir));
313 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
315 $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }),
316 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),
317 'output_format' => 'HTML',
318 'title' => $form->{title},
319 'attachment_basename' => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
321 $report->set_options_from_form();
322 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
325 my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
326 my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
328 foreach my $fu (@{ $follow_ups }) {
331 $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
333 my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
336 'raw_data' => $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
337 . $cgi->checkbox('-name' => "selected_${idx}", '-value' => 1, '-label' => ''),
338 'valign' => 'center',
342 if (@{ $fu->{LINKS} }) {
343 my $link = $fu->{LINKS}->[0];
345 $row->{title}->{data} = $link->{title};
346 $row->{title}->{link} = $link->{url};
349 $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
351 $report->add_data($row);
354 setup_fu_report_action_bar();
355 $report->generate_with_headers();
357 $main::lxdebug->leave_sub();
360 sub report_for_todo_list {
361 $main::lxdebug->enter_sub();
363 $main::auth->assert('productivity');
365 my $form = $main::form;
367 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);
372 'created_for_login' => $::myconfig{login},
375 my $follow_ups = FU->follow_ups(%params);
378 if (@{ $follow_ups }) {
379 my $callback = build_std_url('action');
380 my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
382 foreach my $fu (@{ $follow_ups }) {
383 if (@{ $fu->{LINKS} }) {
384 my $link = $fu->{LINKS}->[0];
386 $fu->{reference} = $link->{title};
387 $fu->{reference_link} = $link->{url};
391 $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
392 'callback' => $callback,
393 'edit_url' => $edit_url, });
396 $main::lxdebug->leave_sub();
401 sub edit_access_rights {
402 $main::lxdebug->enter_sub();
404 $main::auth->assert('productivity');
406 my $form = $main::form;
407 my $locale = $main::locale;
409 my $access = FU->retrieve_access_rights();
411 $form->{EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
413 map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
415 $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
417 setup_fu_edit_access_rights_action_bar();
420 print $form->parse_html_template('fu/edit_access_rights');
422 $main::lxdebug->leave_sub();
425 sub save_access_rights {
426 $main::lxdebug->enter_sub();
428 $main::auth->assert('productivity');
430 my $form = $main::form;
431 my $locale = $main::locale;
435 foreach my $i (1 .. $form->{rowcount}) {
436 my $id = $form->{"employee_id_$i"};
438 $access{$id} = 1 if ($id && $form->{"access_$id"});
441 FU->save_access_rights('access' => \%access);
443 $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
444 edit_access_rights();
446 $main::lxdebug->leave_sub();
450 call_sub($main::form->{nextsub});
454 call_sub($main::form->{nextsub});
458 $main::auth->assert('productivity');
460 if ($main::form->{save_nextsub}) {
461 call_sub($main::form->{save_nextsub});
468 $main::lxdebug->enter_sub();
470 my $form = $main::form;
471 my $locale = $main::locale;
473 foreach my $action (qw(finish save delete)) {
474 if ($form->{"action_${action}"}) {
480 call_sub($form->{default_action}) if ($form->{default_action});
482 $form->error($locale->text('No action defined.'));
485 sub setup_fu_search_action_bar {
488 for my $bar ($::request->layout->get('actionbar')) {
492 submit => [ '#form', { action => "report" } ],
493 accesskey => 'enter',
499 sub setup_fu_display_form_action_bar {
502 for my $bar ($::request->layout->get('actionbar')) {
506 submit => [ '#form', { action => "save" } ],
507 accesskey => 'enter',
511 submit => [ '#form', { action => "finish" } ],
512 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
516 submit => [ '#form', { action => "delete" } ],
517 disabled => !$::form->{id} ? t8('The object has not been saved yet.') : undef,
518 confirm => t8('Do you really want to delete this object?'),
524 sub setup_fu_report_action_bar {
527 for my $bar ($::request->layout->get('actionbar')) {
531 submit => [ '#form', { action => "finish" } ],
532 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
536 submit => [ '#form', { action => "delete" } ],
537 checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ],
538 confirm => t8('Do you really want to delete the selected objects?'),
544 sub setup_fu_edit_access_rights_action_bar {
547 for my $bar ($::request->layout->get('actionbar')) {
551 submit => [ '#form', { action => "save_access_rights" } ],
552 accesskey => 'enter',