1 # TODO list helper functions
11 $main::lxdebug->enter_sub();
16 my $myconfig = \%main::myconfig;
17 my $form = $main::form;
19 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
21 $form->error('Need params: id or login') if (!$params{id} && !$params{login});
24 ($params{id}) = selectfirst_array_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $params{login});
27 $main::lxdebug->leave_sub();
32 ($params{login}) = selectfirst_array_query($form, $dbh, qq|SELECT login FROM employee WHERE id = ?|, conv_i($params{id}));
35 my $cfg = selectfirst_hashref_query($form, $dbh, qq|SELECT * FROM todo_user_config WHERE employee_id = ?|, conv_i($params{id}));
38 # Standard configuration: enable all
40 $cfg = { map { $_ => 1 } qw(show_after_login show_follow_ups show_follow_ups_login show_overdue_sales_quotations show_overdue_sales_quotations_login) };
43 if (! $main::auth->check_right($params{login}, 'sales_quotation_edit')) {
44 map { delete $cfg->{$_} } qw(show_overdue_sales_quotations show_overdue_sales_quotations_login);
47 $main::lxdebug->leave_sub();
52 sub save_user_config {
53 $main::lxdebug->enter_sub();
58 Common::check_params(\%params, qw(login));
60 my $myconfig = \%main::myconfig;
61 my $form = $main::form;
63 SL::DB->client->with_transaction(sub {
64 my $dbh = $params{dbh} || SL::DB->client->dbh;
66 my $query = qq|SELECT id FROM employee WHERE login = ?|;
68 my ($id) = selectfirst_array_query($form, $dbh, $query, $params{login});
71 $main::lxdebug->leave_sub();
76 qq|SELECT show_after_login
78 WHERE employee_id = ?|;
80 if (! selectfirst_hashref_query($form, $dbh, $query, $id)) {
81 do_query($form, $dbh, qq|INSERT INTO todo_user_config (employee_id) VALUES (?)|, $id);
85 qq|UPDATE todo_user_config SET
88 show_follow_ups_login = ?,
89 show_overdue_sales_quotations = ?,
90 show_overdue_sales_quotations_login = ?
92 WHERE employee_id = ?|;
94 my @values = map { $params{$_} ? 't' : 'f' } qw(show_after_login show_follow_ups show_follow_ups_login show_overdue_sales_quotations show_overdue_sales_quotations_login);
97 do_query($form, $dbh, $query, @values);
99 }) or do { die SL::DB->client->error };
101 $main::lxdebug->leave_sub();