package Mod::ajax_json; # # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) Rainer Gümpelein, TeilRad GmbH # use warnings; use strict; use POSIX; use CGI; use CGI::Cookie (); use Apache2::Const -compile => qw(OK ); use DBI; use JSON; use Mod::Libenzdb; use Mod::DBtank; use Mod::APIfunc; use Lib::Config; use Data::Dumper; sub handler { my ($r) = @_; my $q = new CGI; $q->import_names('R'); my $db = new Libenzdb; my $dbt = new DBtank; my $apif = new APIfunc; my $cf = new Config; my %varenv = $cf->envonline(); my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime; my $lang="de"; my $main_id = $q->param('main_id'); my $table = $q->param('table'); my $search = $q->param('term'); my @keywords = $q->param; my @query_output = (); my $debug=1; my $dbh = ""; my $coo = $q->cookie('domcookie'); my $users_sharee = { c_id => 0 }; my $users_dms = { u_id => 0 }; my $api_return = { authcookie => '' }; ($api_return,$users_sharee) = $apif->auth_verify($q,$coo,""); if($users_sharee->{c_id} && $varenv{orga} eq "dms" && $coo && length($coo) > 20){ $users_dms = $dbt->select_users($dbh,$users_sharee->{c_id},"and cookie='$coo'"); } print $q->header(-type => "application/json", -charset => "utf-8"); open(FILE,">>/var/log/copri-bike/ajax_json.log") if($debug); print FILE "$now_dt| u_id:$users_dms->{u_id}|$main_id\n" if($debug); if($users_dms->{u_id} && $users_dms->{int07} == 2){ foreach(@keywords){ my @val = $q->param($_); my $valxx = $q->escapeHTML("@val"); if($_ eq "c_idadr"){ $search = $valxx; } print FILE "$_: $valxx\n" if($debug); } if($table eq "content"){ my $sth = $db->search_json("$table","$lang","$search","$main_id"); while ( my $row = $sth->fetchrow_hashref ){ push @query_output, $row; } print FILE Dumper(\@query_output) if($debug); print JSON::to_json(\@query_output); }elsif($table eq "contentadr"){ my $sth = $db->search_jsonadr("$table","$lang","$search","$main_id",""); while ( my $row = $sth->fetchrow_hashref ){ push @query_output, $row; } print FILE Dumper(\@query_output) if($debug); print JSON::to_json(\@query_output); } } close(FILE) if($debug); return Apache2::Const::OK; } 1;