From: Kilian Saffran Date: Fri, 16 Aug 2019 05:16:49 +0000 (+0200) Subject: request change no jquery ajax X-Git-Url: http://cloud.dks.lu/git/?a=commitdiff_plain;h=3f485681c010c83c19f6299574f0b83bac9cff2a;p=juridig_lu.git request change no jquery ajax --- diff --git a/backoffice/api/process.cgi b/backoffice/api/process.cgi index 5337dd3..36c2e8c 100644 --- a/backoffice/api/process.cgi +++ b/backoffice/api/process.cgi @@ -49,7 +49,31 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ if (exists($p->{fn})){ my $db = dksdb->new(); - if (($p->{fn} eq "checkvoucher") && (exists($p->{voucher}))) { + if ($p->{fn} eq "setpref"){ + my $sql = "select id from modulepreferences where page='".$p->{page}."' AND id_user=".$sess->{id}.";"; + my $rid = $db->dbquerysorted($sql); + if (defined($rid) && exists($rid->{0}->{id})){ + $sql = "update modulepreferences set preference='".$p->{data}."' where id=".$rid->{0}->{id}.";"; + } else { + $sql = "insert into modulepreferences (id_user,page,preference) VALUES (".$sess->{id}.",'".$p->{page}."','".$p->{data}."');"; + } + open(LOG,">>tmp/sql.log"); + print LOG $sql."\n"; + close(LOG); + $db->dbexec($sql); + $html->{result} = "Preference saved"; + } + elsif ($p->{fn} eq "getpref"){ + my $sql = "select preference from modulepreferences where page='".$p->{page}."' AND id_user=".$sess->{id}.";"; + open(LOG,">>tmp/sql.log"); + print LOG $sql."\n"; + close(LOG); + my $pref = $db->dbquerysorted($sql); + if (defined($pref) && exists($pref->{0}->{preference})){ + $html->{result} = $pref->{0}; + } + } + elsif (($p->{fn} eq "checkvoucher") && (exists($p->{voucher}))) { # $html->{check} = "1"; my $sql = "select vc.percentdiscount,px.id_app as app,px.package from vouchers vc join prices px on (vc.id_price=px.id) where vc.voucher='".$p->{voucher}."' and vc.expiration <= vc.expiration and vc.used != true;"; my $res = $db->dbquerysorted($sql); @@ -318,7 +342,7 @@ if (($cgi->request_method() eq "GET") || ($cgi->request_method() eq "POST")){ # and bt.id_user not in (".$sess->{id}.") # and (bt.invites is null or bt.invites::text like '%\"' || (select senderemail from billjee where id_user=".$sess->{id}.")|| '\"%') # order by bt.eventdate,us.surname,us.prename;"; -my $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,0,5) as starttime,bt.eventmsg as msg ,bt.eventtype,us.prename,us.surname +my $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,1,5) as starttime,bt.eventmsg as msg ,bt.eventtype,us.prename,us.surname from billjeetickets bt join billjee bj on (bj.id_user=bt.id_user) join (select users.id,users.prename,users.surname,appaccess.privateenabled from users join appaccess on (appaccess.id_user=users.id) and appaccess.id_app=7) us on (bt.id_user=us.id) @@ -326,31 +350,31 @@ where bt.eventdate between date('".$p->{startdate}."') and date('".$p->{enddate} and us.privateenabled=true and isdisabled is null ".$olyf." and bt.invites is null order by bt.eventdate,us.surname,us.prename;"; if ($p->{type} eq "private"){ - $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,0,5) as starttime,bt.eventmsg as msg ,bt.eventtype,us.prename,us.surname + $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,1,5) as starttime,bt.eventmsg as msg ,bt.eventtype,us.prename,us.surname from billjeetickets bt join billjee bj on (bj.id_user=bt.id_user) join (select users.id,users.prename,users.surname,appaccess.privateenabled from users join appaccess on (appaccess.id_user=users.id) and appaccess.id_app=7) us on (bt.id_user=us.id) where bt.eventdate between date('".$p->{startdate}."') and date('".$p->{enddate}."') -and us.privateenabled=true and isdisabled is null ".$olyf." -and and bt.invites::text like '%\"' || (select senderemail from billjee where id_user=".$sess->{id}.")|| '\"%') order by bt.eventdate,us.surname,us.prename;"; +and us.privateenabled=true and isdisabled is null ".$olyf." and bt.id_user not in (".$sess->{id}.") +and bt.invites::text like '%\"' || (select senderemail from billjee where id_user=".$sess->{id}.")|| '\"%' order by bt.eventdate,us.surname,us.prename;"; } if ($p->{type} eq "user"){ - $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,0,5) as starttime,bt.eventmsg as msg ,bt.eventtype,bt.eventtype,us.prename,us.surname ,'[' || string_agg(bdata::TEXT,',')|| ']' as bookings + $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,1,5) as starttime,bt.eventmsg as msg ,bt.eventtype,bt.eventtype,us.prename,us.surname ,'[' || string_agg(bdata::TEXT,',')|| ']' as bookings from billjeetickets bt join billjee bj on (bj.id_user=bt.id_user) left join (select bbook.id_user,bbook.id_billjeeticket,row_to_json(bbook) as bdata from ( select us1.prename,us1.surname,bb1.id_billjeeticket,bb1.id_user,to_char(bb1.bookingtime,'DD.MM.YYYY HH:MI') as bookingtime,bt1.senderemail from billjeebooking bb1 join billjee bt1 on (bb1.id_user=bt1.id_user) join users us1 on (bb1.id_user=us1.id) order by bb1.bookingtime ASC) as bbook) bb on (bt.id=bb.id_billjeeticket) join (select users.id,users.prename,users.surname,appaccess.privateenabled from users join appaccess on (appaccess.id_user=users.id) and appaccess.id_app=7) us on (bt.id_user=us.id) -where bt.eventdate between date('".$p->{startdate}."') and date('".$p->{enddate}."') and us.id=".$sess->{id}." group by bt.id,us.prename,us.surname;"; +where bt.eventdate between date('".$p->{startdate}."') and date('".$p->{enddate}."') and bt.id_user=".$sess->{id}." group by bt.id,us.prename,us.surname;"; } if ($p->{type} eq "bookings"){ - $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,0,5) as starttime,bt.eventmsg as msg ,bt.eventtype,bt.eventtype,us.prename,us.surname ,'[' || string_agg(bdata::TEXT,',')|| ']' as bookings + $sql ="select bt.id,bt.id_user,bt.isdisabled,bt.court,bt.room,to_char(bt.eventdate,'DD.MM.YYYY') as dspdate,substr(bt.starttime::TEXT,1,5) as starttime,bt.eventmsg as msg ,bt.eventtype,bt.eventtype,us.prename,us.surname ,'[' || string_agg(bdata::TEXT,',')|| ']' as bookings from billjeetickets bt join billjee bj on (bj.id_user=bt.id_user) left join (select bbook.id_user,bbook.id_billjeeticket,row_to_json(bbook) as bdata from ( select us1.prename,us1.surname,bb1.id_billjeeticket,bb1.id_user,to_char(bb1.bookingtime,'DD.MM.YYYY HH:MI') as bookingtime,bt1.senderemail from billjeebooking bb1 join billjee bt1 on (bb1.id_user=bt1.id_user) join users us1 on (bb1.id_user=us1.id) order by bb1.bookingtime ASC) as bbook) bb on (bt.id=bb.id_billjeeticket) -join (select users.id,users.prename,users.surname,appaccess.privateenabled from users join appaccess on (appaccess.id_user=users.id) and appaccess.id_app=7) us on (bt.id_user=us.id) -where bt.eventdate between date('".$p->{startdate}."') and date('".$p->{enddate}."') and bdata.id_user=".$sess->{id}." group by bt.id,us.prename,us.surname;"; +join (select users.id,users.prename,users.surname,appaccess.privateenabled from users join appaccess on (appaccess.id_user=users.id) and appaccess.id_app=7) us on (bt.id_user=us.id) +where bt.eventdate between date('".$p->{startdate}."') and date('".$p->{enddate}."') and bb.id_user=".$sess->{id}." group by bt.id,us.prename,us.surname;"; } my $res = $db->dbquerysorted($sql); #$html->{result}->{onlyfuture} = $p->{onlyfuture}; diff --git a/backoffice/css/w3pro.css b/backoffice/css/w3pro.css index a0ed743..a4cef47 100644 --- a/backoffice/css/w3pro.css +++ b/backoffice/css/w3pro.css @@ -307,4 +307,5 @@ hr{border:0;border-top:1px solid #eee;margin:20px 0} table-layout: fixed; } -.w3-text-line-through { text-decoration: line-through; } \ No newline at end of file +.w3-text-line-through { text-decoration: line-through; } + diff --git a/backoffice/index.cgi b/backoffice/index.cgi index f0f1e29..c0a53b6 100644 --- a/backoffice/index.cgi +++ b/backoffice/index.cgi @@ -28,6 +28,10 @@ if ($vars->{basepath} eq "/"){ }else { $vars->{siteurl} = $cgi->url({-base=>1}).dirname($vars->{basepath}); } +if ($vars->{siteurl} !~ /\/$/){ + $vars->{siteurl} .= '/'; +} + if ($vars->{filepath} ne ""){ $vars->{suffix} = substr($vars->{filepath},rindex($vars->{filepath},'.')); diff --git a/backoffice/js/backoffice.js b/backoffice/js/backoffice.js index 6b11e15..158023d 100644 --- a/backoffice/js/backoffice.js +++ b/backoffice/js/backoffice.js @@ -1,59 +1,45 @@ + var backoffice = { - loadpage: function(modulepage,modulename = ''){ + loadpage: function(modulepage){ //console.log("Load module:" + modulepage); - $("#modulename").html(modulename); + // $("#modulename").html(modulename); $("#moduleframe").attr('src',modulepage); }, + settitle: function(title){ + $("#modulename").html(title); + }, + setPreference(page,data){ + console.log("set preference!" + page); + var sdata = data; + if (typeof(data) == "object"){ + sdata = JSON.stringify(data); + } + req.reqdata("POST","process.cgi",{"fn":"setpref","page":page,"data":sdata},null); + }, + getPreference(page,callback){ + var data = req.reqdata("POST","process.cgi",{"fn":"getpref","page":page},callback); + }, loadnewwindow: function(url){ //console.log("New Window load URL:" + url); window.open(url); return false; }, logout: function(){ - $.ajax({ - encoding:"UTF-8", - url: location.href, - method: "POST", - data: "logout=1", - success: function (data){ - location.href=location.href; - }, - error: function(data){ - - console.log("Logout Error Deteceted!"); - }, - async:true - }); + req.reqdata("POST",location.href,{"logout":"1"},backoffice.reloadpage); + }, 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("Reload Error detected!"); - }, - async:true - }); + location.href=location.href; + } } -$( document ).ready(function() { +document.addEventListener("DOMContentLoaded", function() { var body = $('body'); - var contentWrapper = $('.content-wrapper'); - var scroller = $('.container-scroller'); + var contentWrapper = document.getElementsByClassName('.content-wrapper'); + var scroller = document.getElementsByClassName('.container-scroller'); // var footer = $('.footer'); - var sidebar = $('.sidebar'); - - //Add active class to nav-link based on url dynamically - //Active class can be hard coded directly in html file also as required + var sidebar = document.getElementsByClassName('.sidebar'); function addActiveClass(element) { if (current === "") { @@ -85,22 +71,6 @@ $( document ).ready(function() { var $this = $(this); addActiveClass($this); }) - - //Close other submenu in sidebar on opening any - - // 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'); - // }); - - //checkbox and radios - // $(".form-check label,.form-radio label").append(''); }); (function($) { diff --git a/backoffice/js/fieldsave.js b/backoffice/js/fieldsave.js index e315340..679d7d9 100644 --- a/backoffice/js/fieldsave.js +++ b/backoffice/js/fieldsave.js @@ -62,7 +62,7 @@ function savefield(objid){ } field["fn"] = "savefield"; //console.log(field); - process_data(field,fieldsaved); + req.reqdata("POST",'process.cgi',field,fieldsaved); return false; } diff --git a/backoffice/js/request.js b/backoffice/js/request.js index cd43031..ca99b5c 100644 --- a/backoffice/js/request.js +++ b/backoffice/js/request.js @@ -1,5 +1,9 @@ -var api = location.origin + location.pathname.substring(0, location.pathname.indexOf('module')) + 'api/'; -//console.log(api); + +var api = location.origin + location.pathname.substring(0,location.pathname.lastIndexOf('/')) + '/api/'; +if (location.pathname.indexOf('module') > 0){ + api = location.origin + location.pathname.substring(0, location.pathname.indexOf('module')) + 'api/'; +} +console.log(api); var req = { reqdata: function(method,url,data,callback=null){ @@ -27,12 +31,16 @@ var req = { }else { rdata = data; } + //console.log("Data to send: " + decodeURIComponent(rdata)); var sendurl = api + url; + if (url.startsWith("http")){ + sendurl = url; + } if (method.toUpperCase() == 'GET'){ sendurl = sendurl + '?' + rdata; } - //console.log("sending URL: " + method + " => " +sendurl); + console.log("sending URL: " + method + " => " +sendurl); request.open(method.toUpperCase(), sendurl, false); request.onload = function(){ if (request.status >= 200 && request.status <= 400){ diff --git a/backoffice/tmpl/block/javascript.tt b/backoffice/tmpl/block/javascript.tt index e2a755a..5643bbf 100644 --- a/backoffice/tmpl/block/javascript.tt +++ b/backoffice/tmpl/block/javascript.tt @@ -1,4 +1,5 @@ - + + \ No newline at end of file diff --git a/backoffice/tmpl/block/sidebar.tt b/backoffice/tmpl/block/sidebar.tt index 9771591..7ee73c2 100644 --- a/backoffice/tmpl/block/sidebar.tt +++ b/backoffice/tmpl/block/sidebar.tt @@ -10,7 +10,7 @@ -->