1 use POSIX qw(strftime);
4 use SL::ReportGenerator;
6 require "bin/mozilla/reportgenerator.pl";
11 $main::lxdebug->enter_sub();
15 my $form = $main::form;
19 foreach my $i (1 .. $form->{trans_rowcount}) {
20 next if (!$form->{"trans_id_$i"} || !$form->{"trans_type_$i"});
22 push @{ $dest->{LINKS} }, { map { +"trans_$_" => $form->{"trans_${_}_$i"} } qw(id type info) };
25 $main::lxdebug->leave_sub();
29 $main::lxdebug->enter_sub();
31 my $form = $main::form;
32 my %myconfig = %main::myconfig;
33 my $locale = $main::locale;
35 _collect_links($form);
37 $form->get_employee($form->get_standard_dbh(\%myconfig));
38 $form->{created_for_user} = $form->{employee_id};
42 if (0 < scalar @{ $form->{LINKS} }) {
43 $link_details = FU->link_details(%{ $form->{LINKS}->[0] });
46 if ($link_details && $link_details->{title}) {
47 $form->{title} = $locale->text('Add Follow-Up for #1', $link_details->{title});
49 $form->{title} = $locale->text('Add Follow-Up');
54 $main::lxdebug->leave_sub();
58 $main::lxdebug->enter_sub();
60 my $form = $main::form;
61 my $locale = $main::locale;
63 my $ref = FU->retrieve('id' => $form->{id});
66 $form->error($locale->text("Invalid follow-up ID."));
69 map { $form->{$_} = $ref->{$_} } keys %{ $ref };
71 if (@{ $form->{LINKS} } && $form->{LINKS}->[0]->{title}) {
72 $form->{title} = $locale->text('Edit Follow-Up for #1', $form->{LINKS}->[0]->{title});
74 $form->{title} = $locale->text('Edit Follow-Up');
79 $main::lxdebug->leave_sub();
83 $main::lxdebug->enter_sub();
85 my $form = $main::form;
87 $form->get_lists("employees" => "EMPLOYEES");
90 $params{not_id} = $form->{id} if ($form->{id});
91 $params{trans_id} = $form->{LINKS}->[0]->{trans_id} if (@{ $form->{LINKS} });
92 $form->{FOLLOW_UPS} = FU->follow_ups(%params);
94 $form->{jsscript} = 1;
97 print $form->parse_html_template('fu/add_edit');
99 $main::lxdebug->leave_sub();
103 $main::lxdebug->enter_sub();
105 my $form = $main::form;
106 my $locale = $main::locale;
108 $form->isblank('created_for_user', $locale->text('You must chose a user.'));
109 $form->isblank('follow_up_date', $locale->text('The follow-up date is missing.'));
110 $form->isblank('subject', $locale->text('The subject is missing.'));
112 my %params = (map({ $_ => $form->{$_} } qw(id subject body note_id created_for_user follow_up_date)), 'done' => 0);
114 _collect_links(\%params);
118 if ($form->{POPUP_MODE}) {
120 print $form->parse_html_template('fu/close_window');
124 $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.');
126 if ($form->{callback}) {
130 delete @{$form}{qw(id subject body created_for_user follow_up_date)};
132 map { $form->{$_} = 1 } qw(due_only all_users not_done);
136 $main::lxdebug->leave_sub();
140 $main::lxdebug->enter_sub();
142 my $form = $main::form;
143 my $locale = $main::locale;
146 my $ref = FU->retrieve('id' => $form->{id});
149 $form->error($locale->text("Invalid follow-up ID."));
152 FU->finish('id' => $form->{id});
155 foreach my $i (1..$form->{rowcount}) {
156 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
158 FU->finish('id' => $form->{"follow_up_id_$i"});
162 if ($form->{POPUP_MODE}) {
164 print $form->parse_html_template('fu/close_window');
168 $form->redirect() if ($form->{callback});
172 $main::lxdebug->leave_sub();
176 $main::lxdebug->enter_sub();
178 my $form = $main::form;
179 my $locale = $main::locale;
182 my $ref = FU->retrieve('id' => $form->{id});
185 $form->error($locale->text("Invalid follow-up ID."));
188 FU->delete('id' => $form->{id});
191 foreach my $i (1..$form->{rowcount}) {
192 next unless ($form->{"selected_$i"} && $form->{"follow_up_id_$i"});
194 FU->delete('id' => $form->{"follow_up_id_$i"});
198 if ($form->{POPUP_MODE}) {
200 print $form->parse_html_template('fu/close_window');
204 $form->redirect() if ($form->{callback});
208 $main::lxdebug->leave_sub();
212 $main::lxdebug->enter_sub();
214 my $form = $main::form;
215 my $locale = $main::locale;
217 $form->get_lists("employees" => "EMPLOYEES");
219 $form->{jsscript} = 1;
220 $form->{title} = $locale->text('Follow-Ups');
223 print $form->parse_html_template('fu/search');
225 $main::lxdebug->leave_sub();
229 $main::lxdebug->enter_sub();
231 my $form = $main::form;
232 my %myconfig = %main::myconfig;
233 my $locale = $main::locale;
234 my $cgi = $main::cgi;
236 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);
238 report_generator_set_default_sort('follow_up_date', 1);
240 my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params);
241 $form->{rowcount} = scalar @{ $follow_ups };
243 $form->{title} = $locale->text('Follow-Ups');
246 'selected' => { 'text' => '', },
247 'follow_up_date' => { 'text' => $locale->text('Follow-Up Date'), },
248 'created_on' => { 'text' => $locale->text('Created on'), },
249 'title' => { 'text' => $locale->text('Reference'), },
250 'subject' => { 'text' => $locale->text('Subject'), },
251 'created_by_name' => { 'text' => $locale->text('Created by'), },
252 'created_for_user_name' => { 'text' => $locale->text('Follow-up for'), },
253 'done' => { 'text' => $locale->text('Done'), 'visible' => $form->{done} && $form->{not_done} ? 1 : 0 },
256 my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done);
257 my $href = build_std_url('action=report', grep { $form->{$_} } @report_params);
259 foreach my $name (qw(follow_up_date created_on title subject)) {
260 my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
261 $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
266 if ($form->{created_for}) {
267 $form->get_lists("employees" => "EMPLOYEES");
269 foreach my $employee (@{ $form->{EMPLOYEES} }) {
270 if ($employee->{id} == $form->{created_for}) {
271 push @options, $locale->text('Created for') . " : " . ($employee->{name} ? "$employee->{name} ($employee->{login})" : $employee->{login});
277 push @options, $locale->text('Subject') . " : $form->{subject}" if ($form->{subject});
278 push @options, $locale->text('Body') . " : $form->{body}" if ($form->{body});
279 push @options, $locale->text('Reference') . " : $form->{reference}" if ($form->{reference});
280 push @options, $locale->text('Done') if ($form->{done});
281 push @options, $locale->text('Not done yet') if ($form->{not_done});
282 push @options, $locale->text('Only due follow-ups') if ($form->{due_only});
283 push @options, $locale->text("Other users' follow-ups") if ($form->{all_users});
285 my @hidden_report_params = map { +{ 'key' => $_, 'value' => $form->{$_} } } @report_params;
287 my $report = SL::ReportGenerator->new(\%myconfig, $form, 'std_column_visibility' => 1);
289 $report->set_columns(%column_defs);
290 $report->set_column_order(@columns);
292 $report->set_export_options('report', @report_params, qw(sort sortdir));
294 $report->set_sort_indicator($form->{sort}, $form->{sortdir});
296 $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }),
297 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),
298 'output_format' => 'HTML',
299 'title' => $form->{title},
300 'attachment_basename' => $locale->text('follow_up_list') . strftime('_%Y%m%d', localtime time),
302 $report->set_options_from_form();
303 $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
306 my $callback = build_std_url('action=report', grep { $form->{$_} } @report_params);
307 my $edit_url = build_std_url('action=edit', 'callback=' . E($callback));
309 foreach my $fu (@{ $follow_ups }) {
312 $fu->{done} = $fu->{done} ? $locale->text('Yes') : $locale->text('No');
314 my $row = { map { $_ => { 'data' => $fu->{$_} } } keys %{ $fu } };
317 'raw_data' => $cgi->hidden('-name' => "follow_up_id_${idx}", '-value' => $fu->{id})
318 . $cgi->checkbox('-name' => "selected_${idx}", '-value' => 1, '-label' => ''),
319 'valign' => 'center',
323 if (@{ $fu->{LINKS} }) {
324 my $link = $fu->{LINKS}->[0];
326 $row->{title}->{data} = $link->{title};
327 $row->{title}->{link} = $link->{url};
330 $row->{subject}->{link} = $edit_url . '&id=' . Q($fu->{id});
332 $report->add_data($row);
335 $report->generate_with_headers();
337 $main::lxdebug->leave_sub();
340 sub report_for_todo_list {
341 $main::lxdebug->enter_sub();
343 my $form = $main::form;
345 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);
350 'created_for_login' => $form->{login},
353 my $follow_ups = FU->follow_ups(%params);
356 if (@{ $follow_ups }) {
357 my $callback = build_std_url('action');
358 my $edit_url = build_std_url('script=fu.pl', 'action=edit', 'callback=' . E($callback)) . '&id=';
360 foreach my $fu (@{ $follow_ups }) {
361 if (@{ $fu->{LINKS} }) {
362 my $link = $fu->{LINKS}->[0];
364 $fu->{reference} = $link->{title};
365 $fu->{reference_link} = $link->{url};
369 $content = $form->parse_html_template('fu/report_for_todo_list', { 'FOLLOW_UPS' => $follow_ups,
370 'callback' => $callback,
371 'edit_url' => $edit_url, });
374 $main::lxdebug->leave_sub();
379 sub edit_access_rights {
380 $main::lxdebug->enter_sub();
382 my $form = $main::form;
383 my $locale = $main::locale;
385 my $access = FU->retrieve_access_rights();
387 $form->get_lists("employees" => "EMPLOYEES");
389 map { $_->{access} = $access->{$_->{id}} } @{ $form->{EMPLOYEES} };
391 $form->{title} = $locale->text('Edit Access Rights for Follow-Ups');
394 print $form->parse_html_template('fu/edit_access_rights');
396 $main::lxdebug->leave_sub();
399 sub save_access_rights {
400 $main::lxdebug->enter_sub();
402 my $form = $main::form;
403 my $locale = $main::locale;
407 foreach my $i (1 .. $form->{rowcount}) {
408 my $id = $form->{"employee_id_$i"};
410 $access{$id} = 1 if ($id && $form->{"access_$id"});
413 FU->save_access_rights('access' => \%access);
415 $form->{SAVED_MESSAGE} = $locale->text('The access rights have been saved.');
416 edit_access_rights();
418 $main::lxdebug->leave_sub();
422 call_sub($main::form->{nextsub});
426 call_sub($main::form->{nextsub});
430 if ($main::form->{save_nextsub}) {
431 call_sub($main::form->{save_nextsub});
438 $main::lxdebug->enter_sub();
440 my $form = $main::form;
441 my $locale = $main::locale;
443 foreach my $action (qw(finish save delete)) {
444 if ($form->{"action_${action}"}) {
450 call_sub($form->{default_action}) if ($form->{default_action});
452 $form->error($locale->text('No action defined.'));