From 796325ba62044683f0707e30c463d9a286830980 Mon Sep 17 00:00:00 2001 From: Kilian Saffran Date: Sun, 23 Jun 2019 11:21:18 +0200 Subject: [PATCH] upload 23.06 --- .gitignore | 3 +- .htaccess | 2 +- backoffice/api/lib/dksapp.pm | 41 + backoffice/api/lib/dksdb.pm | 47 +- backoffice/api/lib/dksinvoice.pm | 207 ++ .../api/lib/{report.pm => dksreport.pm} | 60 +- backoffice/api/lib/sendemail.pm | 45 +- backoffice/api/lib/session.pm | 130 +- backoffice/api/process.cgi | 102 +- backoffice/api/sql.log | 96 - backoffice/index.cgi | 98 +- backoffice/js/backoffice.js | 18 + backoffice/js/off-canvas.js | 16 +- backoffice/js/template.js | 14 +- backoffice/tmpl/block/javascript.tt | 1 + backoffice/tmpl/block/sidebar.tt | 5 +- backoffice/tmpl/block/topbar.tt | 19 +- backoffice/tmpl/module/annuaire/index.tt | 25 +- backoffice/tmpl/module/applications/index.js | 18 +- backoffice/tmpl/module/applications/index.tt | 14 +- backoffice/tmpl/module/js/modules_global.js | 4 +- backoffice/tmpl/module/newsletter/css.tt | 0 backoffice/tmpl/module/newsletter/index.js | 0 backoffice/tmpl/module/newsletter/index.tt | 0 .../tmpl/module/newsletter/javascript.tt | 0 backoffice/tmpl/module/payements/css.tt | 0 backoffice/tmpl/module/payements/index.js | 0 backoffice/tmpl/module/payements/index.tt | 0 .../tmpl/module/payements/javascript.tt | 0 backoffice/tmpl/module/profile/index.js | 14 +- backoffice/tmpl/module/users/css.tt | 0 backoffice/tmpl/module/users/index.js | 0 backoffice/tmpl/module/users/index.tt | 0 backoffice/tmpl/module/users/javascript.tt | 0 backoffice/tmpl/module/vouchers/css.tt | 0 backoffice/tmpl/module/vouchers/index.js | 0 backoffice/tmpl/module/vouchers/index.tt | 0 backoffice/tmpl/module/vouchers/javascript.tt | 0 backoffice/tmpl/skeleton/login.tt | 38 +- css/style.css | 7 +- dev/db/juridiglu_db.pg.data.sql | 1083 ++++++--- dev/db/juridiglu_db.pg.full.sql | 1983 +++++++---------- dev/db/juridiglu_db.pg.schema.sql | 886 +------- dev/db/minimum.pg.data.sql | 0 dev/db/tmp_function.sql | 60 + {backoffice/api => dev/lib.old}/download.cgi | 0 {backoffice/api => dev/lib.old}/image.cgi | 0 {backoffice/api => dev/lib.old}/prefs.cgi | 0 {backoffice/api => dev/lib.old}/test.jpeg | Bin {backoffice/api => dev/lib.old}/test.png | Bin .../api => dev/lib.old}/testfiledata.pl | 0 {backoffice/api => dev/lib.old}/upload.cgi | 0 index.cgi | 6 +- index.html | 21 + js/annuaire.js | 17 +- tmpl/block/avocatlist.1.tt | 29 - tmpl/block/avocatlist.tt | 51 +- tmpl/block/domaines.tt | 2 +- tmpl/block/javascript.tt | 1 + tmpl/block/locations.tt | 2 +- tmpl/page/avocat/index.tt | 30 +- tmpl/page/lieu/index.tt | 4 +- vendor/qrcode/qrcode.min.js | 1 + 63 files changed, 2530 insertions(+), 2670 deletions(-) create mode 100644 backoffice/api/lib/dksapp.pm create mode 100644 backoffice/api/lib/dksinvoice.pm rename backoffice/api/lib/{report.pm => dksreport.pm} (82%) delete mode 100644 backoffice/api/sql.log create mode 100644 backoffice/tmpl/module/newsletter/css.tt create mode 100644 backoffice/tmpl/module/newsletter/index.js create mode 100644 backoffice/tmpl/module/newsletter/index.tt create mode 100644 backoffice/tmpl/module/newsletter/javascript.tt create mode 100644 backoffice/tmpl/module/payements/css.tt create mode 100644 backoffice/tmpl/module/payements/index.js create mode 100644 backoffice/tmpl/module/payements/index.tt create mode 100644 backoffice/tmpl/module/payements/javascript.tt create mode 100644 backoffice/tmpl/module/users/css.tt create mode 100644 backoffice/tmpl/module/users/index.js create mode 100644 backoffice/tmpl/module/users/index.tt create mode 100644 backoffice/tmpl/module/users/javascript.tt create mode 100644 backoffice/tmpl/module/vouchers/css.tt create mode 100644 backoffice/tmpl/module/vouchers/index.js create mode 100644 backoffice/tmpl/module/vouchers/index.tt create mode 100644 backoffice/tmpl/module/vouchers/javascript.tt create mode 100644 dev/db/minimum.pg.data.sql create mode 100644 dev/db/tmp_function.sql rename {backoffice/api => dev/lib.old}/download.cgi (100%) rename {backoffice/api => dev/lib.old}/image.cgi (100%) rename {backoffice/api => dev/lib.old}/prefs.cgi (100%) rename {backoffice/api => dev/lib.old}/test.jpeg (100%) rename {backoffice/api => dev/lib.old}/test.png (100%) rename {backoffice/api => dev/lib.old}/testfiledata.pl (100%) rename {backoffice/api => dev/lib.old}/upload.cgi (100%) create mode 100644 index.html delete mode 100644 tmpl/block/avocatlist.1.tt create mode 100644 vendor/qrcode/qrcode.min.js diff --git a/.gitignore b/.gitignore index f01ead1..8f8c470 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ backoffice/api/reports/* -backoffice/api/tmp/* \ No newline at end of file +backoffice/api/tmp/* +backoffice/tmp/* \ No newline at end of file diff --git a/.htaccess b/.htaccess index e7f459c..07c817f 100644 --- a/.htaccess +++ b/.htaccess @@ -4,7 +4,7 @@ #AddType application/octet-stream .pdf RewriteEngine on #dev-mode begin -DirectoryIndex index.cgi index.html +DirectoryIndex index.cgi index.html AddHandler cgi-script .cgi #devmode end #RewriteBase / diff --git a/backoffice/api/lib/dksapp.pm b/backoffice/api/lib/dksapp.pm new file mode 100644 index 0000000..4a691e6 --- /dev/null +++ b/backoffice/api/lib/dksapp.pm @@ -0,0 +1,41 @@ +package dksapp; + +use strict; + +use lib ('.'); +use lib ('./lib'); +use File::Basename; +use Getopt::Long; +use dksdb; + +sub new { + my $class = shift; + my $self = bless {}, $class; + $self->{db} = dksdb->new(); + return $self; +} + +sub activate_app(){ + my $self = shift; + my $idapp = shift; + my $iduser = shift; + my $duration = shift; + my $statusdate = shift; + my $apacc = $self->{db}->dbquery("select ac.id,ac.expiration,ap.app,app.inittables from appaccess ac join apps ap on (ac.id_app=ap.id) where ac.id_user=".$iduser." and id_app=".$idapp.";"); + my $res; + if ($apacc){ + $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.");"); + } + } + } + return $res; +} + + +1; \ No newline at end of file diff --git a/backoffice/api/lib/dksdb.pm b/backoffice/api/lib/dksdb.pm index e3c8673..52d5dbb 100644 --- a/backoffice/api/lib/dksdb.pm +++ b/backoffice/api/lib/dksdb.pm @@ -8,8 +8,9 @@ use Digest::SHA::PurePerl qw(sha256_hex); use DBD::PgPP; use URI::Encode qw(uri_encode uri_decode); use Encode; -use utf8; use dksconfig qw($sitecfg); +use Text::Unidecode; + sub new { my $class = shift; @@ -26,6 +27,32 @@ sub securetext(){ } sub dbquery(){ + my $self = shift; + my $stat = shift; + # my $vw_info = shift; + my $retdata = undef; + my $dbh = DBI->connect($sitecfg->{dsn},$sitecfg->{dbuser},$sitecfg->{dbpassword},{PrintError=>0,RaiseError=>0,AutoCommit=>1}) or return $retdata->{error} = "dbquery Connection Error!".$!; + $stat = encode("utf8", $stat); + # open FILE,">>tmp/sql.log"; + # print FILE "$stat\n"; + # close FILE; + my $sth = $dbh->prepare($stat) or return $retdata->{error} = "dbquery".$dbh->errstr. "- SQL: ".$stat;; + + + $sth->execute() or return $retdata->{error} = "dbquery: ".$sth->errstr; + + my $data = $sth->fetchrow_hashref(); + foreach my $k (keys %{$data}){ + $retdata->{$k} = $data->{$k}; + } + + $sth->finish(); + $dbh->disconnect(); + + return $retdata; +} + +sub dbquerybykey(){ my $self = shift; my $key = shift; my $stat = shift; @@ -37,7 +64,7 @@ sub dbquery(){ # open FILE,">>sql.log"; # print FILE "$stat\n"; # close FILE; - my $sth = $dbh->prepare($stat); + my $sth = $dbh->prepare($stat) or return $retdata->{error} = "dbquery: ".$stat; $sth->execute() or return $retdata->{error} = "dbquery: ".$stat; while(my $data = $sth->fetchrow_hashref()) { @@ -65,10 +92,10 @@ sub dbquerysorted(){ my $retdata; my $dbh = DBI->connect($sitecfg->{dsn},$sitecfg->{dbuser},$sitecfg->{dbpassword},{PrintError=>0,RaiseError=>0,AutoCommit=>1}) or return $retdata->{error} = "dbquery Connection Error!".$!; # $stat = encode("utf8", $stat); - # open FILE,">>sql.log"; + # open FILE,">>tmp/sql.log"; # print FILE "\n==\n$stat\n==\n"; # close FILE; - my $sth = $dbh->prepare($stat); + my $sth = $dbh->prepare($stat) or return $retdata->{error} = "dbquerysorted ".$dbh->errstr. "- SQL: ".$stat;; $sth->execute() or return $retdata->{error} = "dbquerysorted: ".$sth->errstr; @@ -104,10 +131,10 @@ sub dbexec(){ my $retdata; my $dbh = DBI->connect($sitecfg->{dsn},$sitecfg->{dbuser},$sitecfg->{dbpassword},{PrintError=>0,RaiseError=>0,AutoCommit=>1}) or return $retdata->{error} = "dbquery Connection Error!".$!; # $stat = decode("UTF-8", $stat); - # open FILE,">>sql.log"; + # open FILE,">>tmp/sql.log"; # print FILE "\n==\n$stat\n==\n"; # close FILE; - my $sth = $dbh->prepare($stat); + my $sth = $dbh->prepare($stat) or return $retdata->{error} = "dbexec ".$dbh->errstr. "- SQL: ".$stat;; $retdata->{success} = $dbh->do($stat) or return $retdata->{error} = "dbexec ".$dbh->errstr. "- SQL: ".$stat; $dbh->disconnect(); return $retdata; @@ -325,4 +352,12 @@ sub create_ddl_delete(){ return @ddl; } +sub textunidecode(){ + my $self = shift; + my $text = shift; + $text = lc(unidecode(decode("utf-8",$text))); + $text =~ s/^[a-z0-9]//g; + return $text; +} + 1; diff --git a/backoffice/api/lib/dksinvoice.pm b/backoffice/api/lib/dksinvoice.pm new file mode 100644 index 0000000..4367235 --- /dev/null +++ b/backoffice/api/lib/dksinvoice.pm @@ -0,0 +1,207 @@ +package dksinvoice; + +use strict; +use POSIX qw(strftime); +use File::Basename; +use lib ('./'); +use lib ('./lib'); +use dksdb; +use dksreport; +use dksapp; + +sub new { + my $class = shift; + my $self = bless {}, $class; + $self->{db} = dksdb->new(); + return $self; +} + +sub cleanpaypaldata(){ + my $self = shift; + my $pp = shift; + if ($pp->{purchase_units}){ + my $ppd = @{$pp->{purchase_units}}[0]; + my @keys = ("description","reference_id","amount","payee","shipping"); + foreach my $k (@keys){ + if (exists($ppd->{$k})){ + $pp->{$k} = $ppd->{$k}; + } + } + delete $pp->{purchase_units}; + delete $pp->{links}; + } + return $pp; +} + +sub activate_app_byinvoiceid(){ + my $self = shift; + my $idinv = shift; + my $app = dksapp->new(); + my $inv = $self->{db}->dbquery("select iv.id_app,iv.id_user,iv.statusdate,ie.quantity from invoices iv left join invoiceelements ie on (iv.id=ie.id_invoice) where iv.id=".$idinv." and iv.status='PAYED';"); + my $ret = $app->activate_app($inv->{id_app},$inv->{id_user},$inv->{quantity},$inv->{statusdate}); + return $ret; +} + +sub newinvoice(){ + my $self = shift; + my $iduser = shift; + my $data = shift; + my $prdinfo = shift; + my $clnum = $self->getclientnumber($iduser); + my $inv; my $prd; + + if (exists($data->{paypal})){ + ($inv,$prd) = $self->getpaypaldetails($data); + $inv->{invoices_payementmethod} = 'paypal'; + $inv->{invoices_tranactiondata} = JSON::PP::encode_json($data); + } else { + $inv->{invoices_email} = $data->{email}; + $inv->{invoices_recipient} = $data->{recipient}; + $inv->{invoices_address} = $data->{address}; + $inv->{invoices_zip} = $data->{zip}; + $inv->{invoices_city} = $data->{city}; + $inv->{invoices_countryshort} = $data->{countryshort}; + $inv->{invoices_payementmethod} = 'invoice'; + } + $inv->{invoices_clientnumber} = $clnum; + $inv->{invoices_id_user} = $iduser; + $inv->{invoices_id_app} = $prdinfo->{id_app}; + my $invnum = $self->{db}->dbquery("select count(*)+1 as cnt from invoices where invoicedate = CURRENT_DATE;"); + $inv->{invoices_reference} = strftime("%Y%m%d",localtime()).'-'.sprintf( "%04d", $invnum->{cnt}); + $inv->{invoices_invoicedate} = strftime("%Y-%m-%d",localtime()); + if ($inv->{status} ne "PAYED") { + $inv->{invoices_reminderdate} = strftime("%Y-%m-%d",localtime(time()+30*86400)); + } + my $apprice = $self->{db}->dbquery("select id,duration,price,vatpercent from prices where id_app=".$prdinfo->{id_app}." and package='".$prdinfo->{package}."';"); + if ($apprice){ + $prd->{invoiceelements_description} = $data->{description}; + $prd->{invoiceelements_quantity} = $apprice->{duration}; + $prd->{invoiceelements_unit} = "mois"; + $prd->{invoiceelements_vatpercent} = $apprice->{vatpercent}; + $prd->{invoiceelements_id_price} = $apprice->{id}; + $inv->{invoices_vatpercent} = $apprice->{vatpercent}; + + $prd->{invoiceelements_unitamount} = $apprice->{price}; + $inv->{invoices_sumnetamount} = $apprice->{duration} * $apprice->{price}; + $inv->{invoices_sumvatamount} = $inv->{invoices_sumnetamount} * $apprice->{vatpercent}; + $inv->{invoices_sumgrossamount} = $inv->{invoices_sumnetamount} + $inv->{invoices_sumvatamount}; + + if ($prdinfo->{voucher} ne ""){ + my $vouch = $self->{db}->dbquery("select id,percentdiscount from vouchers where voucher='".$prdinfo->{voucher}."';"); + + if ($vouch){ + $self->{db}->dbquery("update vouchers set used=true where voucher='".$prdinfo->{voucher}."';"); + $prd->{invoiceelements_id_voucher} = $vouch->{id}; + + $prd->{invoiceelements_unitamount} = $apprice->{price} - ($apprice->{price} - ($vouch->{discountpercent} * 100)); + $inv->{invoices_sumnetamount} = $apprice->{duration} * $prd->{invoiceelements_unitamount}; + $inv->{invoices_sumvatamount} = $inv->{invoices_sumnetamount} * $apprice->{vatpercent}; + $inv->{invoices_sumgrossamount} = $inv->{invoices_sumnetamount} + $inv->{invoices_sumvatamount}; + } + } + + if (($inv->{status} ne "PAYED") && (exists($data->{paypal}))) { + $inv->{invoices_payementnote} = "Payé avec PAYPAL le ".strftime("%d.%m.%Y",localtime()); + + } elsif ($inv->{invoices_sumgrossamount} > 0){ + $inv->{invoices_payementnote} = "Nous vous prions de virer le montant à payerau compte courrant: LU25 0020 1100 2783 8700 (BILLLULL)"; + } + if (($inv->{status} ne "PAYED") || ($inv->{invoices_sumgrossamount} == 0)){ + $inv->{invoices_status} = "PAYED"; + $inv->{invoices_statusdate} = strftime("%Y-%m-%d",localtime()); + $inv->{invoices_payedamount} = $inv->{invoices_sumgrossamount} + } + + } + my @insql = $self->{db}->create_ddl_insert($inv); + + my $newinvid = $self->{db}->dbquery($insql[0]); + $prd->{invoiceelements_id_invoice} = $newinvid->{id}; + @insql = $self->{db}->create_ddl_insert($prd); + $self->{db}->dbexec($insql[0]); + return ($newinvid->{id},$inv->{invoices_status},$inv->{invoices_sumgrossamount},$inv->{invoices_email}); +} + +sub getpaypaldetails(){ + my $self = shift; + my $ppa = shift; + my $adrdata->{invoices_email} = $ppa->{payer}->{email_address}; + $adrdata->{invoices_recepient} = $ppa->{payer}->{name}->{givenname}." ".$ppa->{payer}->{name}->{surname}; + $adrdata->{invoices_address} = $ppa->{shipping}->{address}->{address_line_1}; + $adrdata->{invoices_zip} = $ppa->{shipping}->{address}->{postal_code}; + $adrdata->{invoices_city} = $ppa->{shipping}->{address}->{admin_area_2}; + $adrdata->{invoices_countryshort} = $ppa->{shipping}->{address}->{country_code}; + $adrdata->{invoices_sumgrossamount} = $ppa->{amount}->{value}; + + + if ($ppa->{status} eq "COMPLETED"){ + $adrdata->{invoices_status} = "PAYED"; + } + my $prdata->{invoiceelements_description} = $ppa->{invoice}->{description}; + return ($adrdata,$prdata); +} + +sub createpdf(){ + my $self = shift; + my $idinv = shift; + my $outpath = shift; + my $pdffile; + my $inv = $self->{db}->dbquery("select * from invoices where id=".$idinv.";"); + if ($inv){ + my $repdata->{currency} = "€"; + $repdata->{recipient} = $inv->{recipient}; + $repdata->{address} = $inv->{address}; + $repdata->{countryshort} = $inv->{countryshort}; + $repdata->{zip} = $inv->{zip}; + $repdata->{city} = $inv->{city}; + $repdata->{reference} = $inv->{reference}; + $repdata->{invoicedate} = $inv->{invoicedate}; + $repdata->{reminderdate} = $inv->{reminderdate}; + $repdata->{clientnumber} = $inv->{clientnumber}; + $repdata->{sumnetamount} = sprintf( "%.2f",$inv->{sumnetamount}); + $repdata->{vatpercent} = sprintf( "%.2f",$inv->{vatpercent} *100); + $repdata->{sumvatamount} = sprintf( "%.2f",$inv->{sumvatamount}); + $repdata->{sumgrossamount} = sprintf( "%.2f",$inv->{sumgrossamount}); + $repdata->{payementnote} = (($inv->{payementnote})?$inv->{payementnote}:''); + my $prods = $self->{db}->dbquerysorted("select * from invoiceelements where id_invoice=".$idinv.";"); + my @prdlist; + foreach my $p (%{$prods}){ + if ($prods->{$p}->{description}){ + my $prd->{currency} = "€"; + $prd->{product} = $prods->{$p}->{description}; + $prd->{quantity} = $prods->{$p}->{quantity}; + $prd->{quantity} =~ s/\./,/g; + $prd->{unit} = $prods->{$p}->{unit}; + $prd->{unitamount} = sprintf( "%.2f",$prods->{$p}->{unitamount}); + $prd->{netamount} = sprintf( "%.2f", $prods->{$p}->{quantity} * $prods->{$p}->{unitamount}); + push(@prdlist,$prd); + } + } + $repdata->{productlist} = \@prdlist; + my $rep = dksreport->new(); + my $pdfname = 'DKS_'.$repdata->{reference}.'.pdf'; + if ($inv->{pdffile}){ + $pdfname = $inv->{pdffile} + } + $pdffile = $rep->generatepdf($repdata,'invoice_dks','fr',dirname($ENV{"SCRIPT_FILENAME"}).'/reports/DKS_'.$repdata->{reference}.'.pdf'); + if ($pdffile){ + $pdffile = basename($pdffile); + $self->{db}->dbexec("UPDATE invoices set pdfname='".$pdffile."' where id=".$idinv.";"); + } + } + return $pdffile; +} + +sub getclientnumber(){ + my $self = shift; + my $id_user = shift; + my $clnum = ""; + my $tclnum = $self->{db}->dbquery("select clientnumber from invoices where id_user=".$id_user); + if ((exists($tclnum->{clientnumber}) && $tclnum->{clientnumber} ne "")){ + $clnum = $tclnum->{clientnumber}; + } else { + $clnum = "JD".strftime('%y%m',localtime()).sprintf( "%05d", $id_user ); + } + return $clnum; +} +1; diff --git a/backoffice/api/lib/report.pm b/backoffice/api/lib/dksreport.pm similarity index 82% rename from backoffice/api/lib/report.pm rename to backoffice/api/lib/dksreport.pm index e761150..9394ae5 100644 --- a/backoffice/api/lib/report.pm +++ b/backoffice/api/lib/dksreport.pm @@ -1,11 +1,14 @@ -package report; +package dksreport; use strict; +use lib ('.'); +use lib ('./lib'); use File::Basename; use Getopt::Long; -use utf8; - +use Data::Dumper; use Image::Size; + +use dksdb; # use DKS::dksdb; use PDF::API2; use PDF::Table; @@ -22,36 +25,40 @@ sub new { sub generatepdf(){ my $self = shift; - my $dataid = shift; - my $datatable = shift; - my $datafield =shift; - my $pdfnamefield = shift; + my $filldata = shift; + # my $dataid = shift; + # my $datatable = shift; + # my $datafield =shift; + # my $pdfnamefield = shift; my $report = shift; my $lang = shift; - my $outpath= shift; + my $pdfout= shift; my $strpdfdata =""; my $db = dksdb->new(); - my $templatedata = $db->dbquerysorted("select report,structure,data_".$lang." from reporttemplates where report='".$report."';"); - if (keys(%{$templatedata}) > 0){ - $templatedata = $templatedata->{0}; - } - my $filldata = $db->dbquerysorted("select ".$datafield.",".$pdfnamefield." from ".$datatable." where id='".$dataid."';"); - if (keys(%{$filldata}) > 0){ - $filldata = $filldata->{0}; - } + my $templatedata = $db->dbquery("select report,structure,data_".$lang." from reporttemplates where report='".$report."';"); + # if (keys(%{$templatedata}) > 0){ + # $templatedata = $templatedata->{0}; + # } + # my $filldata = $db->dbquerysorted("select ".$datafield.",".$pdfnamefield." from ".$datatable." where id='".$dataid."';"); + # if (keys(%{$filldata}) > 0){ + # $filldata = $filldata->{0}; + # } my $xindata = ""; - my $pdfout = $outpath.'/'.$filldata->{$pdfnamefield}; + #my $pdfout = $outpath.'/'.$filldata->{$pdfnamefield}; $self->{endpoints} = (); if (-e $pdfout){ unlink($pdfout); } # print "Test get Template!\n"; - - my $pdfdata->{section} = decode_json($templatedata->{structure}); - $filldata->{$datafield} = encode("utf-8",$filldata->{$datafield}); - $filldata->{$datafield} =~ s/"(\d+)\.(\d+)"/"$1,$2"/g; - $pdfdata->{data} = $self->mergedata($templatedata->{"data_".$lang},decode_json($filldata->{$datafield})); + # open (JS,">tmp/mergereport.txt"); + # print JS Dumper($filldata),"\n====\n"; + # close(JS); + my $pdfdata->{section} = JSON::PP->new->decode($templatedata->{structure}); + my $strfilldata = decode("utf-8",JSON::PP->new->encode($filldata)); + # my $strfilldata = JSON::PP::encode_json(encode("utf-8",$filldata)); + $strfilldata =~ s/"(\d+)\.(\d+)"/"$1,$2"/g; + $pdfdata->{data} = $self->mergedata(decode("utf-8",$templatedata->{"data_".$lang}),JSON::PP->new->decode($strfilldata)); my $pdf = PDF::API2->new(); $pdf->preferences({-fitwindow => 1}); @@ -87,7 +94,7 @@ sub mergedata($$){ my $self = shift; my $strdtmpl = shift; my $dvalues = shift; - #my $dvalues = JSON::PP::decode_json($strdvalues); + foreach my $k (keys(%{$dvalues})){ @@ -119,8 +126,11 @@ sub mergedata($$){ $strdtmpl =~ s/$search/$replace/g; } } - print ($strdtmpl); - my $dtmpl = decode_json($strdtmpl); + # print ($strdtmpl); + # open (JS,">tmp/mergereport.txt"); + # print JS $strdtmpl,"\n====\n"; + #close(JS); + my $dtmpl = JSON::PP->new->decode($strdtmpl); return $dtmpl; } diff --git a/backoffice/api/lib/sendemail.pm b/backoffice/api/lib/sendemail.pm index 1b46a26..004f5c0 100644 --- a/backoffice/api/lib/sendemail.pm +++ b/backoffice/api/lib/sendemail.pm @@ -13,6 +13,7 @@ sub new { $self->{port} = "587"; $self->{user} = 'ksaffran@dks.lu'; $self->{password} = "FB1ia1ka"; + $self->{from} = 'support@dks.lu'; return $self; } @@ -32,8 +33,9 @@ sub sendemail(){ if (keys(%{$tmpl}) > 0){ $tmpl = $tmpl->{0}; } - # open (LOG,">>sendmail.log"); - # print LOG "SEND EMAIL:".Dumper($tmpl)."\n"; + # open (LOG,">>tmp/sendmail.log"); + # print LOG $ENV{SCRIPT_FILENAME}; + # print LOG "SEND EMAIL:".Dumper($data)."\n"; # close(LOG); my $datasql = $tmpl->{'emaildatasql'}; $data->{id} = $iduser; @@ -42,7 +44,7 @@ sub sendemail(){ my $repl = $data->{$key}; $datasql =~ s/$srch/$repl/g; } - # open (LOG,">>sendmail.log"); + # open (LOG,">>tmp/sendmail.log"); # print LOG "TEMPLATE DATA:".$datasql."\n"; # close(LOG); $maildata = $db->dbquerysorted($datasql); @@ -66,14 +68,20 @@ sub sendemail(){ #$bodytmpl =~ s/"/\\\"/g; #PROD REPLACE all not replaced DATA #$bodytmpl =~ s/%%\w+%%//g; - $sendto = 'ksaffran@dks.lu'; - if (($bodytmpl ne "") && ($subject ne "") && (exists($data->{email}))){ - my $f = dirname($ENV{'SCRIPT_FILENAME'}).'/api/tmp/mailbody_'.$data->{email}.'.txt'; + #$sendto = 'ksaffran@dks.lu'; + # open (LOG,">>tmp/sendmail.log"); + # print LOG "SUBJECT:".$subject."\n"; + # print LOG "BODY TEXT:".$bodytmpl."\n"; + # close(LOG); + if (($bodytmpl ne "") && ($subject ne "") && ($sendto =~ /.+\@.+\..+/)){ + + my $f = dirname($ENV{SCRIPT_FILENAME}).'/api/tmp/mailbody_'.$sendto.'.txt'; $f =~ s/\@/_/g; + # open (LOG,">>tmp/sendmail.log"); + # print LOG "FILE:".$f."\n"; + # # print LOG "BODY TEXT:".$bodytmpl."\n"; + # close(LOG); - open(EML,">".$f); - print EML $bodytmpl; - close(EML); my $cmd= 'perl "'.dirname($ENV{'SCRIPT_FILENAME'}).'/api/sendEmail" -f '.$tmpl->{mailfrom}.' '; $cmd .= ' -s "'.$self->{server}.':'.$self->{port}.'" -xu "'.$self->{user}.'" -xp "'.$self->{password}.'" -q '; $cmd .= '-o tls=auto '; @@ -82,6 +90,13 @@ sub sendemail(){ $cmd .= '-o message-file='.$f.' '; $cmd .= '-t "'.$sendto.'" '; $cmd .= '-u "'.$subject.'" '; + # open (LOG,">>tmp/sendmail.log"); + # print LOG "SUBJECT:".$subject."\n"; + # print LOG "BODY TEXT:".$bodytmpl."\n"; + # close(LOG); + open(EML,">".$f); + print EML $bodytmpl; + close(EML); # $cmd .= '-m "'.$bodytmpl.'" '; if ($attach != undef){ $cmd .= " -a"; @@ -90,14 +105,14 @@ sub sendemail(){ $cmd .= " ".$a." "; } } - open (LOG,">>sendmail.log"); - print LOG "SEND EMAIL CMD:".$cmd."\n"; - close(LOG); + # open (LOG,">>tmp/sendmail.log"); + # print LOG "SEND EMAIL CMD:".$cmd."\n"; + # close(LOG); # $cmd =~ s/'/''/g; $send = system($cmd); - open (LOG,">>sendmail.log"); - print LOG "CMD RETURN NUM:".$send."\n"; - close(LOG); + # open (LOG,">>tmp/sendmail.log"); + # print LOG "CMD RETURN NUM:".$send."\n"; + # close(LOG); unlink($f); } return $send; diff --git a/backoffice/api/lib/session.pm b/backoffice/api/lib/session.pm index ed1586b..a708940 100644 --- a/backoffice/api/lib/session.pm +++ b/backoffice/api/lib/session.pm @@ -22,53 +22,80 @@ sub checklogin(){ my $login = shift; my $password = shift; my $pwd = sha256_hex($password); - - my $sql = "select * from check_login('".$self->{db}->securetext($login)."','".$pwd."','".$ENV{REMOTE_ADDR}."','".$ENV{HTTP_USER_AGENT}."');"; - my $res = $self->{db}->dbquerysorted($sql); - if(keys(%{$res}) == 1){ - return $res->{0}->{check_login}; + my $ret->{messagetype} ='danger'; + # my $newsid = undef; + $ret->{message} = "Mot de passe ou nom d'utilisateur inconnue!"; + $ret->{messagetype} = "danger"; + $ret->{sid} = undef; + my $user = $self->{db}->dbquerysorted("select id from users where username= '".$self->{db}->securetext($login)."' and userpassword = '".$pwd."' and \"blocked\" is null;"); + if (keys(%{$user}) > 0){ + $ret->{sid} = $self->randomstring(40); + $self->{db}->dbexec("DELETE FROM sessions where id_user=".$user->{0}->{id}." and remote_addr='".$ENV{REMOTE_ADDR}."' and user_agent='".$ENV{HTTP_USER_AGENT}."';"); + my $r = $self->{db}->dbexec("INSERT INTO sessions (id_user,idsession,remote_addr,user_agent) VALUES (".$user->{0}->{id}.", '".$ret->{sid}."', '".$ENV{REMOTE_ADDR}."', '".$ENV{HTTP_USER_AGENT}."');"); } - return undef; + return $ret; } sub passwordforgotten(){ my $self = shift; my $email = shift; - my $newpwd = $self->randompassword(); - my $pwd = sha256_hex($newpwd); - my $sql = "select * from reset_password('".$self->{db}->securetext($email)."','".$pwd."');"; + my $ret->{messagetype} ='danger'; + $ret->{message} = "Email inconnue!"; + my $sql = "select id,userpassword from users where username='".$self->{db}->securetext($email)."';"; my $ex = $self->{db}->dbquerysorted($sql); - if (keys(%{$ex}) == 0){ - return 0; + if (keys(%{$ex}) > 0){ + my $newpwd = $self->randomstring(12); + my $pwd = sha256_hex($newpwd); + $self->{db}->dbexec("UPDATE users SET userpassword = '".$pwd."' WHERE id=".$ex->{0}->{id}.";"); + my $data->{newpassword} = $newpwd; + my $eml = sendemail->new(); + my $mret = $eml->sendemail('user_forgotpasswd',$ex->{0}->{id},$email,$data,undef); + if ($mret != 0){ + $ret->{messagetype} ='danger'; + $ret->{message} = "Erreur! pour l'instant il n'est pas possible recevoir un nouveau mot de passe, contactez le support!"; + return $ret; + } + $ret->{message} = "Nous vous avons envoyé un e-mail, avec les coordonnées de connection nécessaires!"; + $ret->{messagetype} = "success"; } - if ($ex->{reset_password}->{0} eq "0"){ - return 0; - } - my $data->{newpassword} = $newpwd; - my $eml = sendemail->new(); - my $ret = $eml->sendemail('user_forgotpasswd',$ex->{0}->{id},$email,$data,undef); return $ret; } sub registeruser(){ my $self = shift; my $data = shift; + my $ret->{messagetype} ='danger'; + $ret->{message} = "Une Erreur c'est produite, essayer plus tard encore une fois!"; if (!exists($data->{prename}) || !exists($data->{surname}) || !exists($data->{email}) || !exists($data->{terms})){ - return -1; + $ret->{message} = "Tous les champs sont requis!"; + return $ret; } foreach my $d (%{$data}){ $data->{$d} = $self->{db}->securetext($data->{$d}); } - my $usergroup = 'user'; - if ($data->{email} =~ /\@barreau.lu$/) { - $usergroup = 'avocat'; + # my $usergroup = 'user'; + # # if ($data->{email} =~ /\@barreau.lu$/) { + # $usergroup = 'avocat'; + # # } + + my $user = $self->{db}->dbquerysorted("select id from users where username='".$data->{email}."';"); + if (keys(%{$user}) > 0){ + $ret->{message} = "Un utilisateur avec la même addresse e-mail existe déjà!"; + return $ret; } - my $newpwd = $self->randompassword(); + my $newpwd = $self->randomstring(12); my $pwd = sha256_hex($newpwd); - my $ex = $self->{db}->dbquerysorted("select * from add_profile('".$data->{surname}."', '".$data->{prename}."', '".$data->{email}."','".$usergroup."','".$pwd."');"); + my $usergroup = $self->{db}->dbquerysorted("select id from usergroups where usergroup ='avocat';"); + my $newuserid = $self->{db}->dbquerysorted("INSERT INTO users (surname, prename, id_usergroup, username,userpassword) values ('".$data->{surname}."', '".$data->{prename}."','".$usergroup->{0}->{id}."','".$data->{email}."','".$pwd."') returning id;"); + $self->{db}->dbexec("insert into appaccess (id_user) values (".$newuserid->{0}->{id}.");"); + my $maildata->{password} = $newpwd; my $eml = sendemail->new(); - my $ret = $eml->sendemail('user_registration',$ex->{0}->{add_profile},$data->{email},$maildata,undef); + my $mret = $eml->sendemail('user_registration',$newuserid->{0}->{id},$data->{email},$maildata,undef); + if ($mret == 0){ + $ret->{message} = "Merci pour votre régistration,
nous vous avons envoyé un e-mail, avec les coordonnées de connection nécessaires!"; + $ret->{messagetype} = "success"; + } return $ret; } @@ -77,7 +104,13 @@ sub registeruser(){ sub getsession($){ my $self = shift; my $sid = shift; - my $sql = "select * from get_session('".$self->{db}->securetext($sid)."','".$ENV{REMOTE_ADDR}."','".$ENV{HTTP_USER_AGENT}."')"; + my $sql ="select se.idsession,us.id,us.username,us.prename,us.surname,ug.usergroup from sessions se +join users us on (us.id=se.id_user) +join usergroups ug on (us.id_usergroup=ug.id) +left join appaccess ac on (us.id=ac.id_user) +where se.idsession= '".$self->{db}->securetext($sid)."' +and se.remote_addr= '".$ENV{REMOTE_ADDR}."' +and se.user_agent='".$ENV{HTTP_USER_AGENT}."' and us.blocked is null;"; my $res= $self->{db}->dbquerysorted($sql); my $ret = undef; if (keys(%{$res}) > 0){ @@ -89,14 +122,53 @@ sub getsession($){ sub deletesession(){ my $self = shift; my $sid = shift; - $self->{db}->dbexec("select * from delete_session('".$self->{db}->securetext($sid)."');"); + $self->{db}->dbexec("DELETE FROM sessions where idsession='".$self->{db}->securetext($sid)."';"); } -sub randompassword(){ + +sub randomstring(){ my $self = shift; + my $num = shift; my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9); - my $randpassword = join '', map $alphanumeric[rand @alphanumeric], 0..12; - return $randpassword; + my $randstring = join '', map $alphanumeric[rand @alphanumeric], 0..$num; + return $randstring; +} + +sub deleteprofile(){ + my $self = shift; + my $data = shift; + my $ret->{message} = "mot de passe ou profile inconnue!"; + $ret->{messagetype} = "danger"; + if ($data->{id_user} eq ''){ + $ret->{sid} = undef; + return $ret; + } + #"select kcu.table_schema || '.' ||kcu.table_name as foreign_table, rel_tco.table_schema || '.' || rel_tco.table_name as primary_table, kcu.column_name as fk_column, kcu.constraint_name from information_schema.table_constraints tco join information_schema.key_column_usage kcu on tco.constraint_schema = kcu.constraint_schema and tco.constraint_name = kcu.constraint_name join information_schema.referential_constraints rco on tco.constraint_schema = rco.constraint_schema and tco.constraint_name = rco.constraint_name join information_schema.table_constraints rel_tco on rco.unique_constraint_schema = rel_tco.constraint_schema and rco.unique_constraint_name = rel_tco.constraint_name where tco.constraint_type = 'FOREIGN KEY' and rel_tco.table_name='users' group by kcu.table_schema, kcu.table_name, kcu.column_name, rel_tco.table_name, rel_tco.table_schema, kcu.constraint_name;" + my $pwd = sha256_hex($data->{password}); + my $user = $self->{db}->dbquerysorted("select id from users where id= '".$data->{id_user}."' and userpassword = '".$pwd."';"); + if (keys(%{$user}) > 0){ + my @dl = ("DELETE FROM public.timesheets WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.userclients WHERE id_client=".$data->{id_user}.";", +"DELETE FROM public.userclients WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.appaccess WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.rendezvous WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.invoices WHERE id_user=".$data->{id_user}.";", +"DELETE from public.lawyercategories where id_catalog in (select id from lawyercatalog where id_user=".$data->{id_user}.");", +"DELETE FROM public.lawyercatalog WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.modulepreferences WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.clients WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.exceptions WHERE id_user=".$data->{id_user}.";", +"DELETE FROM public.sessions WHERE id_user=".$data->{id_user}.";", +"delete from users where id=".$data->{id_user}.";"); +foreach my $s (@dl){ + $self->{db}->dbexec($s); + } + my $ret->{'message'} = "Votre profile a été supprimé!"; + $ret->{'messagetype'} = "info"; + $ret->{sid} = undef; + } + return $ret; + } 1; \ No newline at end of file diff --git a/backoffice/api/process.cgi b/backoffice/api/process.cgi index b9148c4..9288ced 100644 --- a/backoffice/api/process.cgi +++ b/backoffice/api/process.cgi @@ -15,6 +15,9 @@ use dksdb; use session; use sendemail; use dkssavefile; +use dksinvoice; +use dksapp; +use utf8; my $cgi = new CGI(); my $scriptpath = $cgi->url(-absolute => 1); my $p = (); @@ -56,27 +59,36 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ } } elsif ($p->{fn} eq "activateapp"){ - $html->{result}->{params} =$p; - my $eml = sendemail->new(); - my $sql = "select * from create_invoice('".$sess->{id}."','invoice','".JSON::PP::encode_json($p->{appinfo})."','".JSON::PP::encode_json($p->{invoice})."');"; - my $res = $db->dbquerysorted($sql); - if (keys(%{$res})> 0){ - my $invid = $res->{0}; - my $rep = report->new(); - my $pdffile = $rep->generatepdf($invid,'invoices','invoicedata','pdfname','invoice_dks','fr',dirname($ENV{"SCRIPT_FILENAME"}).'/reports'); - + $html->{result} = undef; + + my $inv = dksinvoice->new(); + my $appinfo = JSON::PP::decode_json($p->{appinfo}); + my $invdata = JSON::PP::decode_json($p->{invoice}); + my ($invid,$invstatus,$invamount,$invemail) = $inv->newinvoice($appinfo->{id_user},$invdata,$appinfo); + if ($invid){ + $html->{result}= $invid; + my $pdf = $inv->createpdf($invid,'invoice_dks','fr',dirname($ENV{"SCRIPT_FILENAME"}).'/reports'); + if (-e dirname($ENV{"SCRIPT_FILENAME"}).'/reports/'.$pdf){ + if (($invstatus eq "PAYED") && ($invamount > 0)){ + my $eml = sendemail->new(); + $eml->sendemail('user_invoice',$sess->{id},$invemail,{},dirname($ENV{"SCRIPT_FILENAME"}).'/reports/'.$pdf); + } + } else { + # open (LOG,">>tmp/app.log"); + # print LOG "FILE: ".dirname($ENV{"SCRIPT_FILENAME"}).'/reports/'.$pdf." does not exist!\n"; + # close(LOG); + } + } + if (($invstatus ) && ($invstatus eq "PAYED")){ + my $app = dksapp->new(); + $inv->activate_app_byinvoiceid($invid); } - # my $sql = "select * from create_invoice('".JSON::PP::encode_json($p)."');"; - #send invoice to email - # my $res = $db->dbquerysorted($sql); - # if (keys(%{$res})> 0){ - # $html->{result} = $res->{0}; - # } } elsif ($p->{fn} eq "savefield"){ # $html->{p} = $p; my $sf = dkssavefile->new(); + $html->{result}->{ident} = $p->{ident}; delete $p->{ident}; delete $p->{fn}; @@ -84,9 +96,12 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ my $retid=undef; my $type = "upd"; foreach my $px (keys(%{$p})){ - + if ($px eq "lawyercatalog_city"){ + $p->{lawyercatalog_location_link} = $db->textunidecode($p->{$px}); + } #$p->{$px} = $db->securetext($p->{$px}); + if (($px =~ /\_id$/) && ($p->{$px} eq "")){ $type = "ins"; } @@ -140,7 +155,6 @@ 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"; - } } my @sql = (); @@ -159,42 +173,34 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ #} } - $html->{result}->{id} = $retid->{0}; + $html->{result}->{id} = $retid->{0}; #$p->{table},#$p->{field},$p->{value},$p->{id},$p->{type} } elsif ($p->{fn} eq "paypal_payement"){ # open (FF,">>paypalpayement.txt"); # print FF Dumper($p); # close(FF); + my $inv = dksinvoice->new(); my $paypaldata = JSON::PP::decode_json($p->{paypal}); - if ($paypaldata->{purchase_units}){ - my $ppd = @{$paypaldata->{purchase_units}}[0]; - my @keys = ("description","reference_id","amount","payee","shipping"); - foreach my $k (@keys){ - if (exists($ppd->{$k})){ - $paypaldata->{$k} = $ppd->{$k}; + $paypaldata = $inv->cleanpaypaldata($paypaldata); + my $appinfo = JSON::PP::decode_json($p->{appinfo}); + $paypaldata->{paypal} = 1; + my ($invid,$invstatus,$invamount,$invemail) = $inv->newinvoice($appinfo->{id_user},$paypaldata,$appinfo); + + if ($invid){ + my $pdf = $inv->createpdf($invid,'invoice_dks','fr',dirname($ENV{"SCRIPT_FILENAME"}).'/reports'); + if (-e dirname($ENV{"SCRIPT_FILENAME"}).'/reports/'.$pdf){ + if (($invstatus eq "PAYED") && ($invamount > 0)){ + my $eml = sendemail->new(); + $eml->sendemail('user_invoice_paypal',$sess->{id},$sess->{username},{},dirname($ENV{"SCRIPT_FILENAME"}).'/reports/'.$pdf); } } - delete $paypaldata->{purchase_units}; - delete $paypaldata->{links}; } - my $appinfo = JSON::PP::decode_json($p->{appinfo}); - my $sql = "select * from create_invoice('".$appinfo->{id_user}."','paypal','".JSON::PP::encode_json($appinfo)."','".JSON::PP::encode_json($paypaldata)."');"; - my $eml = sendemail->new(); - #set corrrect data to invoicedata - #set correct data to paypal_data - #send invoice to email - my $res = $db->dbquerysorted($sql); - if (keys(%{$res})> 0){ - my $invid = $res->{0}; - my $rep = report->new(); - my $pdffile = $rep->generatepdf($invid,'invoices','invoicedata','pdfname','invoice_dks','fr',dirname($ENV{"SCRIPT_FILENAME"}).'/reports'); - if ($pdffile != undef){ - - $eml->sendemail('user_invoice_paypal',$sess->{id},$sess->{username},{},dirname($ENV{"SCRIPT_FILENAME"}).'/reports/'.$pdffile); - #TODO->send invocie to email - } + if ($invstatus == "PAYED"){ + my $app = dksapp->new(); + $app->activateapp($invid); } + $html->{result} ="OK"; } # elsif ($p->{fn} eq "testinvoice"){ # my $invid = $p->{inv}; @@ -207,19 +213,7 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ $html->{result}->{sql} = $sql; $html->{result}->{events} = $res; } - elsif($p->{fn} eq "deleteprofile"){ - $html->{result} = ""; - if (($p->{id_user} eq $sess->{id}) || ($sess->{usergroup} eq 'admin')){ - my $sql = "select * from delete_profile(".$p->{id_user}.");"; - $db->dbexec($sql); - $html->{result} = "OK"; - } - - } } } print JSON::PP::encode_json($html); -# for my $e ( keys %ENV ) { -# print "$e: $ENV{$e}
"; -# } \ No newline at end of file diff --git a/backoffice/api/sql.log b/backoffice/api/sql.log deleted file mode 100644 index 9f8e00c..0000000 --- a/backoffice/api/sql.log +++ /dev/null @@ -1,96 +0,0 @@ - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET council='["Luxembourg","Diekirch"]' WHERE ; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET council='["Luxembourg","Diekirch"]' WHERE ; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET company='DKSA' WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET phone=null WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET phone=null WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET title='Avocat à la Cour' WHERE ; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET company='DKSA' WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET council='["Luxembourg","Diekirch"]' WHERE id_user='4' AND id='102'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET council='[]' WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET council='["Luxembourg"]' WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET title='Avocat exerçant sous son titre professionnel d''origine' WHERE id='102' AND id_user='4'; -== - -== -select * from get_session('$UhZ$6nSuRzqT83GXGMrrua?jeTiu2YsW6ITC@v;','::1','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36') -== - -== -UPDATE lawyercatalog SET council='["Luxembourg","Diekirch"]' WHERE id_user='4' AND id='102'; -== diff --git a/backoffice/index.cgi b/backoffice/index.cgi index e3f7461..4497c41 100644 --- a/backoffice/index.cgi +++ b/backoffice/index.cgi @@ -21,17 +21,14 @@ my $p=(); my $cookie; my $vars = $sitecfg; -my $page = "index.tt"; - $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 ""){ - $page = $vars->{filepath}; - $page =~ s/html$/tt/; + $vars->{page} = $vars->{filepath}; + $vars->{page} =~ s/html$/tt/; } $vars->{abspath} = ""; -#SESSION - Begin my $sess = (); my $se = session->new(); @@ -50,49 +47,36 @@ if ($cgi->request_method() eq "POST"){ foreach my $pp (@params){ $p->{$pp} = $cgi->param($pp); } + $vars->{hasposts} = $p; if (exists($p->{btnlogin})){ - - $p->{sid} = $se->checklogin($p->{login},$p->{password}); - if ($p->{sid} ne ""){ + my $ret = $se->checklogin($p->{login},$p->{password}); + if ($ret->{sid} ne ""){ + $p->{sid} = $ret->{sid}; $cookie = CGI::Cookie->new(-name=>$vars->{cookiename},-value=>$p->{sid},-httponly => 1); + }else { + $vars->{message} = $ret->{message}; + $vars->{messagetype} = $ret->{messagetype}; + $vars->{page} = "message.tt"; } } if (exists($p->{btnregister})){ my $ret = $se->registeruser($p); - if ($ret == -2){ - $vars->{message} = "Un utilisateur avec la même addresse e-mail existe déjà!"; - $vars->{messagetype} = "danger"; - $page = "message.tt"; - } - elsif ($ret == -1){ - $vars->{message} = "Tous les champs sont requis!"; - $vars->{messagetype} = "danger"; - $page = "message.tt"; - } - elsif ($ret == 0){ - $vars->{message} = "Nous vous avons envoyé un e-mail, avec les coordonnées de connection nécessaires!"; - $vars->{messagetype} = "success"; - $page = "message.tt"; - }else { - $vars->{message} = "Une Erreur c'est produite, essayer plus tard encore une fois!"; - $vars->{messagetype} = "danger"; - } - $page = "message.tt"; + $vars->{message} = $ret->{message}; + $vars->{messagetype} = $ret->{messagetype}; + $vars->{page} = "message.tt"; + } + if (exists($p->{btndeleteprofile})){ + my $ret = $se->deleteprofile($p); + $vars->{message} = $ret->{message}; + $vars->{messagetype} = $ret->{messagetype}; + $vars->{page} = "message.tt"; } if (exists($p->{btnforgotpassword})){ - my $ret = $se->passwordforgotten($p->{email}); - $p->{valreturned} = $ret; - if ($ret == 0){ - $vars->{message} = "Nous vous avons envoyé un e-mail, avec les coordonnées de connection nécessaires!"; - $vars->{messagetype} = "success"; - $page = "message.tt"; - }else { - $vars->{message} = "Une Erreur c'est produite, essayer plus tard encore une fois!"; - $vars->{messagetype} = "danger"; - } - $page = "message.tt"; + $vars->{message} = $ret->{message}; + $vars->{messagetype} = $ret->{messagetype}; + $vars->{page} = "message.tt"; } if (exists($p->{logout})){ @@ -100,22 +84,32 @@ if ($cgi->request_method() eq "POST"){ $p->{sid} = ""; $cookie = CGI::Cookie->new(-name=>$vars->{cookiename},-value=>"",-httponly => 1); } + if (exists($p->{btndeleteprofile})){ + my $ret = $se->deleteprofile($p->{deleteprofile}); + $vars->{message} = $ret->{message}; + $vars->{messagetype} = $ret->{messagetype}; + $vars->{page} = "message.tt"; + if (exists($ret->{sid})){ + $p->{sid} = ""; + } + $cookie = CGI::Cookie->new(-name=>$vars->{cookiename},-value=>"",-httponly => 1); + } } + if ($p->{sid} ne ""){ $sess = $se->getsession($p->{sid}); } +$vars->{beforex} = $vars->{page}; if (!exists($sess->{id}) || (!exists($p->{sid})) || $p->{sid} eq ""){ $skl = "skeleton/login.tt"; } +if ($vars->{page} eq "deleteprofile.tt") { + $skl = "skeleton/login.tt"; +} # my ($appname) = $ENV{REQUEST_URI} =~ /.*\/module\/(\w+)\/.*/; if ($p->{sid} ne ""){ - # $vars->{appname} = $appname; - # if (exists($sess->{$appname})){ - # $vars->{$appname} = JSON::PP::decode_json($sess->{$appname}); - # delete $sess->{$appname}; - # } $vars->{session} = $sess; } #SESSION - End @@ -136,19 +130,20 @@ for (my $i=0;$i<$absnum;$i++){ $vars->{abspath} .= "../"; } -$vars->{page} = $page; -if ($page =~ /^module/){ - $vars->{module} = basename(dirname($page)); +# $vars->{page} = $vars->{page}; +if ($vars->{page} =~ /^module/){ + $vars->{module} = basename(dirname($vars->{page})); } -$vars->{pagename} = basename($page); +$vars->{pagename} = basename($vars->{page}); $vars->{pagename} =~ s/\.tt$//; # my ($appname) = $ENV{REQUEST_URI} =~ /.*\/apps\/(\w+)\/.*/; #$vars->{requri} = $ENV{REQUEST_URI}; #BEGIN - iFrame - Modules -if ($skl ne "skeleton/login.tt" && $page =~ /^module/){ + +if ($skl ne "skeleton/login.tt" && $vars->{page} =~ /^module/){ $skl = "skeleton/module.tt"; - if ($page !~ /\.tt$/) { + if ($vars->{page} !~ /\.tt$/) { $skl = "skeleton/module_file.tt"; } } @@ -162,10 +157,11 @@ $template->process($skl,$vars) || die "Template process failed: ", $template->er # for my $e ( keys %ENV ) { # print "$e: $ENV{$e}
"; # } -# print Dumper($skl); + # print Dumper($vars); print "/*"; +# print Dumper($p); print Dumper($vars); -print Dumper($sess); +# print Dumper($sess); print "*/"; diff --git a/backoffice/js/backoffice.js b/backoffice/js/backoffice.js index 0b75107..4c68290 100644 --- a/backoffice/js/backoffice.js +++ b/backoffice/js/backoffice.js @@ -19,5 +19,23 @@ var backoffice = { }, async:true }); + }, + reloadpage(page){ + + alert(page); + $.ajax({ + encoding:"UTF-8", + url: page, + method: "POST", + data: "logout=1", + success: function (data){ + location.href=location.href; + }, + error: function(data){ + + console.log("Error:" + JSON.stringify(data)); + }, + async:true + }); } } \ No newline at end of file diff --git a/backoffice/js/off-canvas.js b/backoffice/js/off-canvas.js index 082f80e..4bda3b1 100644 --- a/backoffice/js/off-canvas.js +++ b/backoffice/js/off-canvas.js @@ -1,8 +1,8 @@ -// (function($) { -// 'use strict'; -// $(function() { -// $('[data-toggle="offcanvas"]').on("click", function() { -// $('.sidebar-offcanvas').toggleClass('active') -// }); -// }); -// })(jQuery); \ No newline at end of file +(function($) { + 'use strict'; + $(function() { + $('[data-toggle="offcanvas"]').on("click", function() { + $('.sidebar-offcanvas').toggleClass('active') + }); + }); +})(jQuery); \ No newline at end of file diff --git a/backoffice/js/template.js b/backoffice/js/template.js index 33f6718..e4cd611 100644 --- a/backoffice/js/template.js +++ b/backoffice/js/template.js @@ -41,17 +41,17 @@ $( document ).ready(function() { //Close other submenu in sidebar on opening any - sidebar.on('show.bs.collapse', '.collapse', function() { - sidebar.find('.collapse.show').collapse('hide'); - }); + // sidebar.on('show.bs.collapse', '.collapse', function() { + // sidebar.find('.collapse.show').collapse('hide'); + // }); //Change sidebar - $('[data-toggle="minimize"]').on("click", function() { - body.toggleClass('sidebar-icon-only'); - }); + // $('[data-toggle="minimize"]').on("click", function() { + // body.toggleClass('sidebar-icon-only'); + // }); //checkbox and radios - $(".form-check label,.form-radio label").append(''); + // $(".form-check label,.form-radio label").append(''); }); diff --git a/backoffice/tmpl/block/javascript.tt b/backoffice/tmpl/block/javascript.tt index cde1fc7..909dbab 100644 --- a/backoffice/tmpl/block/javascript.tt +++ b/backoffice/tmpl/block/javascript.tt @@ -1,5 +1,6 @@ + \ No newline at end of file diff --git a/backoffice/tmpl/block/sidebar.tt b/backoffice/tmpl/block/sidebar.tt index 5d81501..c29694d 100644 --- a/backoffice/tmpl/block/sidebar.tt +++ b/backoffice/tmpl/block/sidebar.tt @@ -1,4 +1,5 @@ -[% viewapps = dksdb.prepare("select * from getactivated_apps2(?) order by name;") %] + +[% viewapps = dksdb.prepare("select ap.id,ap.app,ap.description,ap.name,acc.publicenabled,acc.expiration, to_char(expiration,'dd.mm.yyyy') as dspexpiration from apps ap left join appaccess acc on (ap.id=acc.id_app) where acc.id_user=? and acc.expiration >= CURRENT_DATE;")%]