5 use Digest::MD5 qw(md5_hex);
7 use Time::HiRes qw(gettimeofday);
8 use List::MoreUtils qw(uniq);
11 use SL::Auth::Constants qw(:all);
21 $main::lxdebug->enter_sub();
28 $self->{SESSION} = { };
30 $self->_read_auth_config();
32 $main::lxdebug->leave_sub();
38 my ($self, $login) = @_;
39 my %user = $self->read_user($login);
40 my $dbh = DBI->connect(
45 pg_enable_utf8 => $::locale->is_utf8,
48 ) or $::form->dberror;
50 if ($user{dboptions}) {
51 $dbh->do($user{dboptions}) or $::form->dberror($user{dboptions});
60 $self->{dbh}->disconnect() if ($self->{dbh});
63 # form isn't loaded yet, so auth needs it's own error.
65 $::lxdebug->show_backtrace();
67 my ($self, @msg) = @_;
68 if ($ENV{HTTP_USER_AGENT}) {
69 print Form->create_http_response(content_type => 'text/html');
70 print "<pre>", join ('<br>', @msg), "</pre>";
72 print STDERR "Error: @msg\n";
77 sub _read_auth_config {
78 $main::lxdebug->enter_sub();
83 my $in = IO::File->new('config/authentication.pl', 'r');
86 my $locale = Locale->new('en');
87 $self->mini_error($locale->text('The config file "config/authentication.pl" was not found.'));
98 my $locale = Locale->new('en');
99 $self->mini_error($locale->text('The config file "config/authentication.pl" contained invalid Perl code:'), $@);
102 if ($self->{module} eq 'DB') {
103 $self->{authenticator} = SL::Auth::DB->new($self);
105 } elsif ($self->{module} eq 'LDAP') {
106 $self->{authenticator} = SL::Auth::LDAP->new($self);
109 if (!$self->{authenticator}) {
110 my $locale = Locale->new('en');
111 $self->mini_error($locale->text('No or an unknown authenticantion module specified in "config/authentication.pl".'));
114 my $cfg = $self->{DB_config};
117 my $locale = Locale->new('en');
118 $self->mini_error($locale->text('config/authentication.pl: Key "DB_config" is missing.'));
121 if (!$cfg->{host} || !$cfg->{db} || !$cfg->{user}) {
122 my $locale = Locale->new('en');
123 $self->mini_error($locale->text('config/authentication.pl: Missing parameters in "DB_config". Required parameters are "host", "db" and "user".'));
126 $self->{authenticator}->verify_config();
128 $self->{session_timeout} *= 1;
129 $self->{session_timeout} = 8 * 60 if (!$self->{session_timeout});
131 $main::lxdebug->leave_sub();
134 sub authenticate_root {
135 $main::lxdebug->enter_sub();
138 my $password = shift;
139 my $is_crypted = shift;
141 $password = crypt $password, 'ro' if (!$password || !$is_crypted);
142 my $admin_password = crypt "$self->{admin_password}", 'ro';
144 $main::lxdebug->leave_sub();
146 return OK if $password eq $admin_password;
152 $main::lxdebug->enter_sub();
156 $main::lxdebug->leave_sub();
158 my $result = $self->{authenticator}->authenticate(@_);
159 return OK if $result eq OK;
165 $main::lxdebug->enter_sub(2);
168 my $may_fail = shift;
171 $main::lxdebug->leave_sub(2);
175 my $cfg = $self->{DB_config};
176 my $dsn = 'dbi:Pg:dbname=' . $cfg->{db} . ';host=' . $cfg->{host};
179 $dsn .= ';port=' . $cfg->{port};
182 $main::lxdebug->message(LXDebug->DEBUG1, "Auth::dbconnect DSN: $dsn");
184 $self->{dbh} = DBI->connect($dsn, $cfg->{user}, $cfg->{password}, { pg_enable_utf8 => $::locale->is_utf8, AutoCommit => 0 });
186 if (!$may_fail && !$self->{dbh}) {
187 $main::form->error($main::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr);
190 $main::lxdebug->leave_sub(2);
196 $main::lxdebug->enter_sub();
201 $self->{dbh}->disconnect();
205 $main::lxdebug->leave_sub();
209 $main::lxdebug->enter_sub();
213 my $dbh = $self->dbconnect();
214 my $query = qq|SELECT COUNT(*) FROM pg_tables WHERE (schemaname = 'auth') AND (tablename = 'user')|;
216 my ($count) = $dbh->selectrow_array($query);
218 $main::lxdebug->leave_sub();
224 $main::lxdebug->enter_sub();
228 my $dbh = $self->dbconnect(1);
230 $main::lxdebug->leave_sub();
235 sub create_database {
236 $main::lxdebug->enter_sub();
241 my $cfg = $self->{DB_config};
243 if (!$params{superuser}) {
244 $params{superuser} = $cfg->{user};
245 $params{superuser_password} = $cfg->{password};
248 $params{template} ||= 'template0';
249 $params{template} =~ s|[^a-zA-Z0-9_\-]||g;
251 my $dsn = 'dbi:Pg:dbname=template1;host=' . $cfg->{host};
254 $dsn .= ';port=' . $cfg->{port};
257 $main::lxdebug->message(LXDebug->DEBUG1(), "Auth::create_database DSN: $dsn");
259 my $charset = $main::dbcharset;
260 $charset ||= Common::DEFAULT_CHARSET;
261 my $encoding = $Common::charset_to_db_encoding{$charset};
262 $encoding ||= 'UNICODE';
264 my $dbh = DBI->connect($dsn, $params{superuser}, $params{superuser_password}, { pg_enable_utf8 => $charset =~ m/^utf-?8$/i });
267 $main::form->error($main::locale->text('The connection to the template database failed:') . "\n" . $DBI::errstr);
270 my $query = qq|CREATE DATABASE "$cfg->{db}" OWNER "$cfg->{user}" TEMPLATE "$params{template}" ENCODING '$encoding'|;
272 $main::lxdebug->message(LXDebug->DEBUG1(), "Auth::create_database query: $query");
277 my $error = $dbh->errstr();
279 $query = qq|SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'|;
280 my ($cluster_encoding) = $dbh->selectrow_array($query);
282 if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i) && ($encoding !~ m/^(?:UTF-?8|UNICODE)$/i)) {
283 $error = $main::locale->text('Your PostgreSQL installationen uses UTF-8 as its encoding. Therefore you have to configure Lx-Office to use UTF-8 as well.');
288 $main::form->error($main::locale->text('The creation of the authentication database failed:') . "\n" . $error);
293 $main::lxdebug->leave_sub();
297 $main::lxdebug->enter_sub();
300 my $dbh = $self->dbconnect();
302 my $charset = $main::dbcharset;
303 $charset ||= Common::DEFAULT_CHARSET;
306 User->process_query($main::form, $dbh, 'sql/auth_db.sql', undef, $charset);
308 $main::lxdebug->leave_sub();
312 $main::lxdebug->enter_sub();
318 my $form = $main::form;
320 my $dbh = $self->dbconnect();
322 my ($sth, $query, $user_id);
324 $query = qq|SELECT id FROM auth."user" WHERE login = ?|;
325 ($user_id) = selectrow_query($form, $dbh, $query, $login);
328 $query = qq|SELECT nextval('auth.user_id_seq')|;
329 ($user_id) = selectrow_query($form, $dbh, $query);
331 $query = qq|INSERT INTO auth."user" (id, login) VALUES (?, ?)|;
332 do_query($form, $dbh, $query, $user_id, $login);
335 $query = qq|DELETE FROM auth.user_config WHERE (user_id = ?)|;
336 do_query($form, $dbh, $query, $user_id);
338 $query = qq|INSERT INTO auth.user_config (user_id, cfg_key, cfg_value) VALUES (?, ?, ?)|;
339 $sth = prepare_query($form, $dbh, $query);
341 while (my ($cfg_key, $cfg_value) = each %params) {
342 next if ($cfg_key eq 'password');
344 do_statement($form, $sth, $query, $user_id, $cfg_key, $cfg_value);
349 $main::lxdebug->leave_sub();
352 sub can_change_password {
355 return $self->{authenticator}->can_change_password();
358 sub change_password {
359 $main::lxdebug->enter_sub();
362 my $result = $self->{authenticator}->change_password(@_);
364 $main::lxdebug->leave_sub();
370 $main::lxdebug->enter_sub();
374 my $dbh = $self->dbconnect();
375 my $query = qq|SELECT u.id, u.login, cfg.cfg_key, cfg.cfg_value
376 FROM auth.user_config cfg
377 LEFT JOIN auth."user" u ON (cfg.user_id = u.id)|;
378 my $sth = prepare_execute_query($main::form, $dbh, $query);
382 while (my $ref = $sth->fetchrow_hashref()) {
383 $users{$ref->{login}} ||= { 'login' => $ref->{login}, 'id' => $ref->{id} };
384 $users{$ref->{login}}->{$ref->{cfg_key}} = $ref->{cfg_value} if (($ref->{cfg_key} ne 'login') && ($ref->{cfg_key} ne 'id'));
389 $main::lxdebug->leave_sub();
395 $main::lxdebug->enter_sub();
400 my $dbh = $self->dbconnect();
401 my $query = qq|SELECT u.id, u.login, cfg.cfg_key, cfg.cfg_value
402 FROM auth.user_config cfg
403 LEFT JOIN auth."user" u ON (cfg.user_id = u.id)
404 WHERE (u.login = ?)|;
405 my $sth = prepare_execute_query($main::form, $dbh, $query, $login);
409 while (my $ref = $sth->fetchrow_hashref()) {
410 $user_data{$ref->{cfg_key}} = $ref->{cfg_value};
411 @user_data{qw(id login)} = @{$ref}{qw(id login)};
416 $main::lxdebug->leave_sub();
422 $main::lxdebug->enter_sub();
427 my $dbh = $self->dbconnect();
428 my ($id) = selectrow_query($main::form, $dbh, qq|SELECT id FROM auth."user" WHERE login = ?|, $login);
430 $main::lxdebug->leave_sub();
436 $main::lxdebug->enter_sub();
441 my $form = $main::form;
443 my $dbh = $self->dbconnect();
444 my $query = qq|SELECT id FROM auth."user" WHERE login = ?|;
446 my ($id) = selectrow_query($form, $dbh, $query, $login);
448 return $main::lxdebug->leave_sub() if (!$id);
450 do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE user_id = ?|, $id);
451 do_query($form, $dbh, qq|DELETE FROM auth.user_config WHERE user_id = ?|, $id);
455 $main::lxdebug->leave_sub();
458 # --------------------------------------
462 sub restore_session {
463 $main::lxdebug->enter_sub();
467 my $cgi = $main::cgi;
468 $cgi ||= CGI->new('');
470 $session_id = $cgi->cookie($self->get_session_cookie_name());
471 $session_id =~ s|[^0-9a-f]||g;
473 $self->{SESSION} = { };
476 $main::lxdebug->leave_sub();
480 my ($dbh, $query, $sth, $cookie, $ref, $form);
484 $dbh = $self->dbconnect();
485 $query = qq|SELECT *, (mtime < (now() - '$self->{session_timeout}m'::interval)) AS is_expired FROM auth.session WHERE id = ?|;
487 $cookie = selectfirst_hashref_query($form, $dbh, $query, $session_id);
489 if (!$cookie || $cookie->{is_expired} || ($cookie->{ip_address} ne $ENV{REMOTE_ADDR})) {
490 $self->destroy_session();
491 $main::lxdebug->leave_sub();
492 return $cookie ? SESSION_EXPIRED : SESSION_NONE;
495 $query = qq|SELECT sess_key, sess_value FROM auth.session_content WHERE session_id = ?|;
496 $sth = prepare_execute_query($form, $dbh, $query, $session_id);
498 while (my $ref = $sth->fetchrow_hashref()) {
499 $self->{SESSION}->{$ref->{sess_key}} = $ref->{sess_value};
500 $form->{$ref->{sess_key}} = $self->_load_value($ref->{sess_value}) if (!defined $form->{$ref->{sess_key}});
505 $main::lxdebug->leave_sub();
511 return $_[1] if $_[1] !~ m/^---/;
515 $value = YAML::Load($_[1]);
522 sub destroy_session {
523 $main::lxdebug->enter_sub();
528 my $dbh = $self->dbconnect();
530 do_query($main::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
531 do_query($main::form, $dbh, qq|DELETE FROM auth.session WHERE id = ?|, $session_id);
536 $self->{SESSION} = { };
539 $main::lxdebug->leave_sub();
542 sub expire_sessions {
543 $main::lxdebug->enter_sub();
547 my $dbh = $self->dbconnect();
549 qq|DELETE FROM auth.session_content
553 WHERE (mtime < (now() - '$self->{session_timeout}m'::interval)))|;
555 do_query($main::form, $dbh, $query);
558 qq|DELETE FROM auth.session
559 WHERE (mtime < (now() - '$self->{session_timeout}m'::interval))|;
561 do_query($main::form, $dbh, $query);
565 $main::lxdebug->leave_sub();
568 sub _create_session_id {
569 $main::lxdebug->enter_sub();
572 map { push @data, int(rand() * 255); } (1..32);
574 my $id = md5_hex(pack 'C*', @data);
576 $main::lxdebug->leave_sub();
581 sub create_or_refresh_session {
582 $main::lxdebug->enter_sub();
586 $session_id ||= $self->_create_session_id();
588 my ($form, $dbh, $query, $sth, $id);
591 $dbh = $self->dbconnect();
593 $query = qq|SELECT id FROM auth.session WHERE id = ?|;
595 ($id) = selectrow_query($form, $dbh, $query, $session_id);
598 do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id);
601 do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR});
605 $self->save_session($dbh);
609 $main::lxdebug->leave_sub();
614 my $provided_dbh = shift;
616 my $dbh = $provided_dbh || $self->dbconnect();
618 do_query($::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
620 if (%{ $self->{SESSION} }) {
621 my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|;
622 my $sth = prepare_query($::form, $dbh, $query);
624 foreach my $key (sort keys %{ $self->{SESSION} }) {
625 do_statement($::form, $sth, $query, $session_id, $key, $self->{SESSION}->{$key});
631 $dbh->commit() unless $provided_dbh;
634 sub set_session_value {
635 $main::lxdebug->enter_sub();
640 $self->{SESSION} ||= { };
642 while (my ($key, $value) = each %params) {
643 $self->{SESSION}->{ $key } = YAML::Dump($value);
646 $main::lxdebug->leave_sub();
651 sub delete_session_value {
652 $main::lxdebug->enter_sub();
656 $self->{SESSION} ||= { };
657 delete @{ $self->{SESSION} }{ @_ };
659 $main::lxdebug->leave_sub();
664 sub get_session_value {
665 $main::lxdebug->enter_sub();
668 my $value = $self->{SESSION} ? $self->_load_value($self->{SESSION}->{ $_[0] }) : undef;
670 $main::lxdebug->leave_sub();
675 sub set_cookie_environment_variable {
677 $ENV{HTTP_COOKIE} = $self->get_session_cookie_name() . "=${session_id}";
680 sub get_session_cookie_name {
683 return $self->{cookie_name} || 'lx_office_erp_session_id';
690 sub session_tables_present {
691 $main::lxdebug->enter_sub();
694 my $dbh = $self->dbconnect(1);
697 $main::lxdebug->leave_sub();
704 WHERE (schemaname = 'auth')
705 AND (tablename IN ('session', 'session_content'))|;
707 my ($count) = selectrow_query($main::form, $dbh, $query);
709 $main::lxdebug->leave_sub();
714 # --------------------------------------
716 sub all_rights_full {
717 my $locale = $main::locale;
720 ["--crm", $locale->text("CRM optional software")],
721 ["crm_search", $locale->text("CRM search")],
722 ["crm_new", $locale->text("CRM create customers, vendors and contacts")],
723 ["crm_service", $locale->text("CRM services")],
724 ["crm_admin", $locale->text("CRM admin")],
725 ["crm_adminuser", $locale->text("CRM user")],
726 ["crm_adminstatus", $locale->text("CRM status")],
727 ["crm_email", $locale->text("CRM send email")],
728 ["crm_termin", $locale->text("CRM termin")],
729 ["crm_opportunity", $locale->text("CRM opportunity")],
730 ["crm_knowhow", $locale->text("CRM know how")],
731 ["crm_follow", $locale->text("CRM follow up")],
732 ["crm_notices", $locale->text("CRM notices")],
733 ["crm_other", $locale->text("CRM other")],
734 ["--master_data", $locale->text("Master Data")],
735 ["customer_vendor_edit", $locale->text("Create and edit customers and vendors")],
736 ["part_service_assembly_edit", $locale->text("Create and edit parts, services, assemblies")],
737 ["project_edit", $locale->text("Create and edit projects")],
738 ["license_edit", $locale->text("Manage license keys")],
739 ["--ar", $locale->text("AR")],
740 ["sales_quotation_edit", $locale->text("Create and edit sales quotations")],
741 ["sales_order_edit", $locale->text("Create and edit sales orders")],
742 ["sales_delivery_order_edit", $locale->text("Create and edit sales delivery orders")],
743 ["invoice_edit", $locale->text("Create and edit invoices and credit notes")],
744 ["dunning_edit", $locale->text("Create and edit dunnings")],
745 ["sales_all_edit", $locale->text("View/edit all employees sales documents")],
746 ["--ap", $locale->text("AP")],
747 ["request_quotation_edit", $locale->text("Create and edit RFQs")],
748 ["purchase_order_edit", $locale->text("Create and edit purchase orders")],
749 ["purchase_delivery_order_edit", $locale->text("Create and edit purchase delivery orders")],
750 ["vendor_invoice_edit", $locale->text("Create and edit vendor invoices")],
751 ["--warehouse_management", $locale->text("Warehouse management")],
752 ["warehouse_contents", $locale->text("View warehouse content")],
753 ["warehouse_management", $locale->text("Warehouse management")],
754 ["--general_ledger_cash", $locale->text("General ledger and cash")],
755 ["general_ledger", $locale->text("Transactions, AR transactions, AP transactions")],
756 ["datev_export", $locale->text("DATEV Export")],
757 ["cash", $locale->text("Receipt, payment, reconciliation")],
758 ["--reports", $locale->text('Reports')],
759 ["report", $locale->text('All reports')],
760 ["advance_turnover_tax_return", $locale->text('Advance turnover tax return')],
761 ["--batch_printing", $locale->text("Batch Printing")],
762 ["batch_printing", $locale->text("Batch Printing")],
763 ["--others", $locale->text("Others")],
764 ["email_bcc", $locale->text("May set the BCC field when sending emails")],
765 ["config", $locale->text("Change Lx-Office installation settings (all menu entries beneath 'System')")],
772 return grep !/^--/, map { $_->[0] } all_rights_full();
776 $main::lxdebug->enter_sub();
780 my $form = $main::form;
782 my $dbh = $self->dbconnect();
784 my $query = 'SELECT * FROM auth."group"';
785 my $sth = prepare_execute_query($form, $dbh, $query);
789 while ($row = $sth->fetchrow_hashref()) {
790 $groups->{$row->{id}} = $row;
794 $query = 'SELECT * FROM auth.user_group WHERE group_id = ?';
795 $sth = prepare_query($form, $dbh, $query);
797 foreach $group (values %{$groups}) {
800 do_statement($form, $sth, $query, $group->{id});
802 while ($row = $sth->fetchrow_hashref()) {
803 push @members, $row->{user_id};
805 $group->{members} = [ uniq @members ];
809 $query = 'SELECT * FROM auth.group_rights WHERE group_id = ?';
810 $sth = prepare_query($form, $dbh, $query);
812 foreach $group (values %{$groups}) {
813 $group->{rights} = {};
815 do_statement($form, $sth, $query, $group->{id});
817 while ($row = $sth->fetchrow_hashref()) {
818 $group->{rights}->{$row->{right}} |= $row->{granted};
821 map { $group->{rights}->{$_} = 0 if (!defined $group->{rights}->{$_}); } all_rights();
825 $main::lxdebug->leave_sub();
831 $main::lxdebug->enter_sub();
836 my $form = $main::form;
837 my $dbh = $self->dbconnect();
839 my ($query, $sth, $row, $rights);
842 ($group->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('auth.group_id_seq')|);
844 $query = qq|INSERT INTO auth."group" (id, name, description) VALUES (?, '', '')|;
845 do_query($form, $dbh, $query, $group->{id});
848 do_query($form, $dbh, qq|UPDATE auth."group" SET name = ?, description = ? WHERE id = ?|, map { $group->{$_} } qw(name description id));
850 do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE group_id = ?|, $group->{id});
852 $query = qq|INSERT INTO auth.user_group (user_id, group_id) VALUES (?, ?)|;
853 $sth = prepare_query($form, $dbh, $query);
855 foreach my $user_id (uniq @{ $group->{members} }) {
856 do_statement($form, $sth, $query, $user_id, $group->{id});
860 do_query($form, $dbh, qq|DELETE FROM auth.group_rights WHERE group_id = ?|, $group->{id});
862 $query = qq|INSERT INTO auth.group_rights (group_id, "right", granted) VALUES (?, ?, ?)|;
863 $sth = prepare_query($form, $dbh, $query);
865 foreach my $right (keys %{ $group->{rights} }) {
866 do_statement($form, $sth, $query, $group->{id}, $right, $group->{rights}->{$right} ? 't' : 'f');
872 $main::lxdebug->leave_sub();
876 $main::lxdebug->enter_sub();
881 my $form = $main::from;
883 my $dbh = $self->dbconnect();
885 do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE group_id = ?|, $id);
886 do_query($form, $dbh, qq|DELETE FROM auth.group_rights WHERE group_id = ?|, $id);
887 do_query($form, $dbh, qq|DELETE FROM auth."group" WHERE id = ?|, $id);
891 $main::lxdebug->leave_sub();
894 sub evaluate_rights_ary {
895 $main::lxdebug->enter_sub(2);
902 foreach my $el (@{$ary}) {
903 if (ref $el eq "ARRAY") {
904 if ($action eq '|') {
905 $value |= evaluate_rights_ary($el);
907 $value &= evaluate_rights_ary($el);
910 } elsif (($el eq '&') || ($el eq '|')) {
913 } elsif ($action eq '|') {
922 $main::lxdebug->leave_sub(2);
927 sub _parse_rights_string {
928 $main::lxdebug->enter_sub(2);
938 push @stack, $cur_ary;
940 while ($access =~ m/^([a-z_0-9]+|\||\&|\(|\)|\s+)/) {
942 substr($access, 0, length $1) = "";
944 next if ($token =~ /\s/);
947 my $new_cur_ary = [];
948 push @stack, $new_cur_ary;
949 push @{$cur_ary}, $new_cur_ary;
950 $cur_ary = $new_cur_ary;
952 } elsif ($token eq ")") {
956 $main::lxdebug->leave_sub(2);
960 $cur_ary = $stack[-1];
962 } elsif (($token eq "|") || ($token eq "&")) {
963 push @{$cur_ary}, $token;
966 push @{$cur_ary}, $self->{RIGHTS}->{$login}->{$token} * 1;
970 my $result = ($access || (1 < scalar @stack)) ? 0 : evaluate_rights_ary($stack[0]);
972 $main::lxdebug->leave_sub(2);
978 $main::lxdebug->enter_sub(2);
985 $self->{FULL_RIGHTS} ||= { };
986 $self->{FULL_RIGHTS}->{$login} ||= { };
988 if (!defined $self->{FULL_RIGHTS}->{$login}->{$right}) {
989 $self->{RIGHTS} ||= { };
990 $self->{RIGHTS}->{$login} ||= $self->load_rights_for_user($login);
992 $self->{FULL_RIGHTS}->{$login}->{$right} = $self->_parse_rights_string($login, $right);
995 my $granted = $self->{FULL_RIGHTS}->{$login}->{$right};
996 $granted = $default if (!defined $granted);
998 $main::lxdebug->leave_sub(2);
1004 $main::lxdebug->enter_sub(2);
1008 my $dont_abort = shift;
1010 my $form = $main::form;
1012 if ($self->check_right($form->{login}, $right)) {
1013 $main::lxdebug->leave_sub(2);
1018 delete $form->{title};
1019 $form->show_generic_error($main::locale->text("You do not have the permissions to access this function."));
1022 $main::lxdebug->leave_sub(2);
1027 sub load_rights_for_user {
1028 $main::lxdebug->enter_sub();
1033 my $form = $main::form;
1034 my $dbh = $self->dbconnect();
1036 my ($query, $sth, $row, $rights);
1041 qq|SELECT gr."right", gr.granted
1042 FROM auth.group_rights gr
1045 FROM auth.user_group ug
1046 LEFT JOIN auth."user" u ON (ug.user_id = u.id)
1047 WHERE u.login = ?)|;
1049 $sth = prepare_execute_query($form, $dbh, $query, $login);
1051 while ($row = $sth->fetchrow_hashref()) {
1052 $rights->{$row->{right}} |= $row->{granted};
1056 map({ $rights->{$_} = 0 unless (defined $rights->{$_}); } SL::Auth::all_rights());
1058 $main::lxdebug->leave_sub();