2021-12-30 12:05:56 +01:00
|
|
|
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;
|
2022-11-14 21:16:22 +01:00
|
|
|
use CGI::Cookie ();
|
2021-12-30 12:05:56 +01:00
|
|
|
use Apache2::Const -compile => qw(OK );
|
|
|
|
use DBI;
|
|
|
|
use JSON;
|
|
|
|
use Mod::Libenzdb;
|
2022-11-14 21:16:22 +01:00
|
|
|
use Mod::DBtank;
|
|
|
|
use Mod::APIfunc;
|
2021-12-30 12:05:56 +01:00
|
|
|
use Lib::Config;
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
sub handler {
|
|
|
|
my ($r) = @_;
|
|
|
|
my $q = new CGI;
|
|
|
|
$q->import_names('R');
|
|
|
|
my $db = new Libenzdb;
|
2022-11-14 21:16:22 +01:00
|
|
|
my $dbt = new DBtank;
|
|
|
|
my $apif = new APIfunc;
|
2021-12-30 12:05:56 +01:00
|
|
|
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;
|
2022-11-14 21:16:22 +01:00
|
|
|
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'");
|
|
|
|
}
|
2021-12-30 12:05:56 +01:00
|
|
|
|
|
|
|
print $q->header(-type => "application/json", -charset => "utf-8");
|
|
|
|
|
2022-09-20 16:13:45 +02:00
|
|
|
open(FILE,">>/var/log/copri-bike/ajax_json.log") if($debug);
|
2022-11-14 21:16:22 +01:00
|
|
|
print FILE "$now_dt| u_id:$users_dms->{u_id}|$main_id\n" if($debug);
|
2021-12-30 12:05:56 +01:00
|
|
|
|
2022-11-14 21:16:22 +01:00
|
|
|
if($users_dms->{u_id} && $users_dms->{int07} == 2){
|
|
|
|
foreach(@keywords){
|
2021-12-30 12:05:56 +01:00
|
|
|
my @val = $q->param($_);
|
|
|
|
my $valxx = $q->escapeHTML("@val");
|
|
|
|
if($_ eq "c_idadr"){
|
|
|
|
$search = $valxx;
|
|
|
|
}
|
|
|
|
print FILE "$_: $valxx\n" if($debug);
|
2022-11-14 21:16:22 +01:00
|
|
|
}
|
2021-12-30 12:05:56 +01:00
|
|
|
|
|
|
|
|
2022-11-14 21:16:22 +01:00
|
|
|
if($table eq "content"){
|
2021-12-30 12:05:56 +01:00
|
|
|
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);
|
2022-11-14 21:16:22 +01:00
|
|
|
}elsif($table eq "contentadr"){
|
2021-12-30 12:05:56 +01:00
|
|
|
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);
|
2022-11-14 21:16:22 +01:00
|
|
|
}
|
2021-12-30 12:05:56 +01:00
|
|
|
}
|
|
|
|
close(FILE) if($debug);
|
|
|
|
|
|
|
|
return Apache2::Const::OK;
|
|
|
|
}
|
|
|
|
1;
|
|
|
|
|