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;
|
2022-11-14 21:16:22 +01:00
|
|
|
use Mod::DBtank;
|
|
|
|
use Mod::APIfunc;
|
2021-12-30 12:05:56 +01:00
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
sub handler {
|
|
|
|
my ($r) = @_;
|
|
|
|
my $q = new CGI;
|
|
|
|
$q->import_names('R');
|
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 $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
|
|
|
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,"");
|
2023-03-05 20:01:47 +01:00
|
|
|
if($users_sharee->{c_id} && $coo && length($coo) > 20){
|
2022-11-14 21:16:22 +01:00
|
|
|
$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);
|
2023-03-05 20:01:47 +01:00
|
|
|
print FILE "$now_dt| u_id:$users_dms->{u_id}|table:$R::table|template_id:$R::template_id\n" if($debug);
|
2021-12-30 12:05:56 +01:00
|
|
|
|
2023-01-11 06:55:55 +01:00
|
|
|
if($users_dms->{u_id} && ($users_dms->{int03} == 2 || $users_dms->{int07} == 2)){
|
2022-11-14 21:16:22 +01:00
|
|
|
foreach(@keywords){
|
2021-12-30 12:05:56 +01:00
|
|
|
my @val = $q->param($_);
|
|
|
|
my $valxx = $q->escapeHTML("@val");
|
|
|
|
print FILE "$_: $valxx\n" if($debug);
|
2022-11-14 21:16:22 +01:00
|
|
|
}
|
2023-03-05 20:01:47 +01:00
|
|
|
if($R::table eq "users" && $R::faksum){
|
2023-01-30 20:59:19 +01:00
|
|
|
my $update_users = {
|
|
|
|
table => "users",
|
|
|
|
u_id => $users_dms->{u_id},
|
|
|
|
change => "no_time",
|
|
|
|
};
|
|
|
|
my $toggle = 1;
|
|
|
|
$toggle = 0 if($users_dms->{faksum});
|
|
|
|
$dbt->update_one($dbh,$update_users,"faksum=$toggle");
|
2023-03-05 20:01:47 +01:00
|
|
|
}elsif($R::table eq "content"){
|
|
|
|
my ($rows,$sth) = $dbt->search_json($dbh,$R::table,$R::term,$R::template_id,$R::c_id,$R::catch_equal);
|
|
|
|
if($rows){
|
|
|
|
while (my $row = $sth->fetchrow_hashref ){
|
2021-12-30 12:05:56 +01:00
|
|
|
push @query_output, $row;
|
|
|
|
}
|
2023-03-05 20:01:47 +01:00
|
|
|
}
|
|
|
|
print FILE Dumper(\@query_output) if($debug);
|
|
|
|
print JSON::to_json(\@query_output);
|
|
|
|
}elsif($R::table eq "contentadr"){
|
|
|
|
my ($rows,$sth) = $dbt->search_json($dbh,$R::table,$R::term,$R::template_id,"",$R::catch_equal);
|
|
|
|
if($rows){
|
|
|
|
while (my $row = $sth->fetchrow_hashref ){
|
2021-12-30 12:05:56 +01:00
|
|
|
push @query_output, $row;
|
|
|
|
}
|
2023-03-05 20:01:47 +01:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
|