From: Kilian Saffran Date: Mon, 24 Jun 2019 19:21:36 +0000 (+0200) Subject: missconfig for subtables X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=a7d0315f9d105e6a055d9363376954e7eb3f2714;p=juridig_lu.git missconfig for subtables --- diff --git a/backoffice/api/lib/dksapp.pm b/backoffice/api/lib/dksapp.pm index ac1e3be..b70a61a 100644 --- a/backoffice/api/lib/dksapp.pm +++ b/backoffice/api/lib/dksapp.pm @@ -28,12 +28,24 @@ sub activate_app(){ $res = $self->{db}->dbexec("update appaccess set expiration=date(case when expiration >= date('".$statusdate."') then expiration + interval '".$duration." month' else date('".$statusdate."') + interval '".$duration." month' end) where id=".$apacc->{id}); } else { $res = $self->{db}->dbexec("INSERT INTO appaccess (id_user, id_app, publicenabled, expiration) VALUES(".$iduser.", ".$idapp.", null, date('".$statusdate."') + interval '".$duration." month');"); - if (($apacc->{inittables}) && ($apacc->{inittables} ne "")){ - my @tbl = split(",",$apacc->{inittables}); - foreach my $t (@tbl){ - $self->{db}->dbexec("INSERT INTO ".$t." (id_user) VALUES (".$iduser.");"); + # if (($apacc->{inittables}) && ($apacc->{inittables} ne "")){ + # my @tbl = split(",",$apacc->{inittables}); + # foreach my $t (@tbl){ + # + # } + # } + if ($idapp eq "2"){ #is annauire + my $ud = $self->{db}->dbquery("SELECT * from users where id=".$iduser.";"); + if (exists($ud->{id})){ + $self->{db}->dbexec("INSERT INTO lawyercatalog (id_user) VALUES (".$iduser.");"); + my $profile_link = lc(substr($ud->{username},0,index($ud->{username},0,'@'))); + my $profexists = $self->{db}->dbquery("SELECT COUNT(*)+1 as cnt from lawyercatalog where profile_link='".$profile_link."';"); + if ($profexists->{cnt} ne "1"){ + $profile_link .= $profexists->{cnt}; + } + $self->{db}->dbexec("UPDATE lawyercatalog SET profilelink='".$profile_link."' WHERE id_user=".$iduser.";"); } - } + } } return $res; } diff --git a/backoffice/api/lib/dksconfig.pm b/backoffice/api/lib/dksconfig.pm index 13cbc67..3f9cb83 100644 --- a/backoffice/api/lib/dksconfig.pm +++ b/backoffice/api/lib/dksconfig.pm @@ -12,8 +12,8 @@ our @EXPORT_OK = qw($sitecfg); our $sitecfg ={ cookiename => 'juridig', dbtype => 'PgPP', - dsn => 'DBI:PgPP:dbname=juridiglu_db;host=sql629.your-server.de', - #dsn => 'DBI:PgPP:dbname=juridiglu_db;host=localhost', + #dsn => 'DBI:PgPP:dbname=juridiglu_db;host=sql629.your-server.de', + dsn => 'DBI:PgPP:dbname=juridiglu_db;host=localhost', dbuser => 'juridiglu_user', dbpassword => 'hfdR2C9pK9rQV4cH', page => 'index.tt', diff --git a/backoffice/api/lib/dksdb.pm b/backoffice/api/lib/dksdb.pm index 5ebf275..d0a6221 100644 --- a/backoffice/api/lib/dksdb.pm +++ b/backoffice/api/lib/dksdb.pm @@ -180,15 +180,24 @@ sub create_ddl_insert(){ my $data = shift; my $fields = (); my @ddl = (); + foreach my $f (keys(%{$data})){ if (($f =~ /\_/) && ($f !~ /^ident_/)){ my $t = substr($f,0,index($f,"_")); my $c = substr($f,length($t)+1); #my ($t,$c) = $f =~ m/(.+)\_(.+)/; $fields->{$t}->{$c} = $data->{$f}; - } + } elsif ($f =~ /^ident_/){ + my $f2 = $f; + $f2 =~ s/^ident_//; + + my $t = substr($f2,0,index($f2,"_")); + my $c = substr($f2,length($t)+1); + $fields->{$t}->{$c} = $data->{$f}; + } + } - + foreach my $tb (keys(%{$fields})){ my @sqlcol = (); my @sqlval = (); @@ -203,7 +212,7 @@ sub create_ddl_insert(){ } push (@sqlval,$v); } - push(@ddl,"INSERT INTO ".$tb." (".join(",",@sqlcol).") VALUES (".join(",",@sqlval).") returning id;"); + push(@ddl,"INSERT INTO public.".$tb." (".join(",",@sqlcol).") VALUES (".join(",",@sqlval).") returning id;"); } return @ddl; } @@ -251,7 +260,7 @@ sub create_ddl_insert_json(){ push (@sqlval,$v); #} } - return "INSERT INTO ".$schema.".\"".$table."\" (".join(",",@sqlcol).") VALUES (".join(",",@sqlval).");"; + return "INSERT INTO public.".$schema.".\"".$table."\" (".join(",",@sqlcol).") VALUES (".join(",",@sqlval).");"; } sub create_ddl_update(){ @@ -310,7 +319,39 @@ sub create_ddl_update(){ } push (@sqlcond,$c."=".$v); } - push(@ddl,"UPDATE ".$tb." SET ".join(",",@sqlupd)." WHERE ".join(" AND ",@sqlcond).";"); + push(@ddl,"UPDATE public.".$tb." SET ".join(",",@sqlupd)." WHERE ".join(" AND ",@sqlcond).";"); + } + + return @ddl; +} + +sub create_cnt_statement(){ + my $self = shift; + my $data = shift; + my $fields = (); + my @ddl = (); + foreach my $f (keys(%{$data})){ + if ($f =~ /^ident_/){ + my $fx = substr($f,6); + my $t = substr($fx,0,index($fx,"_")); + my $c = substr($fx,length($t)+1); + #my ($t,$c) = $f =~ m/^ident_(.+)\_([a-z0-9|\_]+)/; + $fields->{$t}->{cond}->{$c} = $data->{$f}; + } + } + foreach my $tb (keys(%{$fields})){ + my @sqlcond = (); + foreach my $c (keys(%{$fields->{$tb}->{cond}})){ + my $v = $fields->{$tb}->{cond}->{$c}; + $v =~ s/'/''/g; + if ($v eq ''){ + $v = 'null'; + } else { + $v = "'".$v."'"; + } + push (@sqlcond,$c."=".$v); + } + push(@ddl,"SELECT count(*) as cnt from ".$tb." WHERE ".join(" AND ",@sqlcond).";"); } return @ddl; @@ -351,7 +392,7 @@ sub create_ddl_delete(){ $v =~ s/'/''/g; push (@sqlcond,$c."='".$v."'"); } - push(@ddl,"DELETE FROM ".$tb." WHERE ".join(" AND ",@sqlcond).";"); + push(@ddl,"DELETE FROM public.".$tb." WHERE ".join(" AND ",@sqlcond).";"); } return @ddl; } diff --git a/backoffice/api/process.cgi b/backoffice/api/process.cgi index 3a1f0f5..185c5b0 100644 --- a/backoffice/api/process.cgi +++ b/backoffice/api/process.cgi @@ -95,6 +95,7 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ delete $p->{sid}; my $retid=undef; my $type = "upd"; + my $idexists = 0; foreach my $px (keys(%{$p})){ if ($px eq "lawyercatalog_city"){ $p->{lawyercatalog_location_link} = $db->textunidecode($p->{$px}); @@ -103,8 +104,12 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ #$p->{$px} = $db->securetext($p->{$px}); if (($px =~ /\_id$/) && ($p->{$px} eq "")){ + $type = "ins"; } + if ($px =~ /^ident\_.+\_id$/){ + $idexists = 1; + } if ($p->{$px} =~ /^data:.+;base64,/){ # $html->{result}->{isfile} = 1; @@ -122,6 +127,20 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ } } } + if (($idexists == 0) && ($type eq "upd")){ + my @sqlcnt = $db->create_cnt_statement($p); + my $rnums = 0; + + + foreach my $s (@sqlcnt){ + + $rnums= $db->dbquery($s); + } + if ($rnums->{cnt} eq "0"){ + $type = "ins"; + } + + } my @sql = (); if ($type eq "ins"){ @sql = $db->create_ddl_insert($p); diff --git a/backoffice/index.cgi b/backoffice/index.cgi index 2629267..06acaaa 100644 --- a/backoffice/index.cgi +++ b/backoffice/index.cgi @@ -25,6 +25,7 @@ $vars->{filepath} = substr($cgi->url({-absolute=>1}),length($vars->{basepath})+1 $vars->{baseurl} = $cgi->url({-base=>1}).$vars->{basepath}; $vars->{siteurl} = $cgi->url({-base=>1}).dirname($vars->{basepath}); if ($vars->{filepath} ne ""){ + $vars->{suffix} = substr($vars->{filepath},rindex($vars->{filepath},'.')); $vars->{page} = $vars->{filepath}; $vars->{page} =~ s/html$/tt/; } @@ -118,7 +119,13 @@ if ($p->{sid} ne ""){ # $skl = "skeleton/browser.tt"; # } # #END - Browser Blocking -print $cgi->header(-type=>'text/html', -charset=>"utf-8",-cookie => $cookie); +my $ctype = 'text/html'; +if ($vars->{suffix} eq ".js"){ + $ctype= "text/javascript"; +} elsif ($vars->{suffix} eq ".css"){ + $ctype = "text/css"; +} +print $cgi->header(-type=>$ctype, -charset=>"utf-8",-cookie => $cookie); # print dirname($ENV{"SCRIPT_FILENAME"}); my $template = Template->new({INCLUDE_PATH => [dirname($ENV{"SCRIPT_FILENAME"}).'/tmpl']}); @@ -160,9 +167,9 @@ $template->process($skl,$vars) || die "Template process failed: ", $template->er # } # print Dumper($vars); -#print "/*"; +print "/*"; # print Dumper($p); -#§print Dumper($vars); +print Dumper($vars); # print Dumper($sess); -#print "*/"; +print "*/"; diff --git a/backoffice/js/fieldsave.js b/backoffice/js/fieldsave.js index 1b7ad55..c6ff2cf 100644 --- a/backoffice/js/fieldsave.js +++ b/backoffice/js/fieldsave.js @@ -43,7 +43,7 @@ function savefield(objid){ var bident = false; for (var d in $("#" + objid).data()){ //if (typeof $("#" + objid).data(d) == "string"){ - if ((d != "select2Id") && (d != "select2") && (d != "selectpicker")){ + if ( (d != "select2Id") && (d != "select2") && (d != "selectpicker")){ // if (d.startsWith("ident_")){ //console.log(d); @@ -55,7 +55,7 @@ function savefield(objid){ if (bident == false){ var frmid=$("#" + objid)[0].form.id; for (var idv in $("#" + frmid).data()){ - if ((idv != "select2Id") && (idv != "select2") && (idv != "selectpicker")){ + if ( (idv != "select2Id") && (idv != "select2Id") && (idv != "select2") && (idv != "selectpicker")){ field[idv] = $("#" + frmid).data(idv); } } diff --git a/backoffice/tmpl/module/annuaire/index.js b/backoffice/tmpl/module/annuaire/index.js index 42c13dc..7bbc9af 100644 --- a/backoffice/tmpl/module/annuaire/index.js +++ b/backoffice/tmpl/module/annuaire/index.js @@ -42,7 +42,7 @@ $("input,textarea").on('blur',function(event){ //console.log(event.currentTarget.tagName); //console.log(event.currentTarget.type); if (event.currentTarget.type != "file"){ - console.log(savefield); + console.log('savefield'); savefield(event.currentTarget.id); } }); diff --git a/backoffice/tmpl/module/annuaire/index.tt b/backoffice/tmpl/module/annuaire/index.tt index 28e7dd2..fda2005 100644 --- a/backoffice/tmpl/module/annuaire/index.tt +++ b/backoffice/tmpl/module/annuaire/index.tt @@ -1,13 +1,14 @@ [% usercat = dksdb.prepare("select acc.id as access_id, acc.publicenabled, lc.id, lc.id_user, lc.surname, lc.prename, lc.company, lc.email, lc.phone, lc.address, lc.zip, lc.city, lc.description, lc.photo, lc.price, lc.profile_link, lc.court, lc.title, lc.country, lc.languages,lc.council,lc.website,lc.logo from lawyercatalog lc join appaccess acc on (lc.id_user=acc.id_user and id_app in (select id from apps where app='annuaire')) where lc.id_user=? LIMIT 1;") %] -[% lawyerspecs = dksdb.prepare("select lca.id,lca.selection,ca.id as id_category,category from categories ca left join lawyercategories lca on (ca.id=lca.id_category and lca.id_catalog=?) where ca.usertype='avocat' order by category asc;") %] +[% lawyerspecs = dksdb.prepare("select lca.selection,ca.id as id_category,category from public.categories ca +left join public.lawyercategories lca on (ca.id=lca.id_category and lca.id_catalog=?) where ca.usertype='avocat' group by ca.id,lca.selection order by ca.category asc;") %] [% FOREACH cat = usercat.execute(session.id) %]