From ab89b0ee541a1f19aa0600e616dc21d89ae873d4 Mon Sep 17 00:00:00 2001 From: Mojtaba Date: Sun, 3 Oct 2021 12:16:09 +0200 Subject: [PATCH] CSRF token has been added generally on all post request with post method. (http, https, and APIs) --- nodcms-core/Libraries/Form.php | 9 ------- nodcms-layout/Views/admin/layout.php | 1 + nodcms-layout/Views/nodcms-clean.php | 1 + nodcms-layout/Views/nodcms-frontend.php | 1 + nodcms-layout/Views/nodcms-membership.php | 1 + nodcms-users/Views/layout.php | 1 + public/assets/nodcms/js/common.js | 30 +++++++++++++++++++++++ public/assets/nodcms/js/common.min.js | 2 +- 8 files changed, 36 insertions(+), 10 deletions(-) diff --git a/nodcms-core/Libraries/Form.php b/nodcms-core/Libraries/Form.php index 91ffd4ab..e90db646 100644 --- a/nodcms-core/Libraries/Form.php +++ b/nodcms-core/Libraries/Form.php @@ -129,15 +129,6 @@ function __construct($CI) function config($inputs, $action = '', $method = 'post', $type = 'ajax', $notes = array()) { - // Add CSRF token on SSL Protocol requests - if(SSL_PROTOCOL) { - $inputs[] = [ - 'field'=>csrf_token(), - 'type'=>"hidden", - 'default'=>csrf_hash(), - 'rules'=>"", - ]; - } $this->data['inputs'] = $inputs; $this->data['action'] = $action; $this->data['back_url'] = $action; diff --git a/nodcms-layout/Views/admin/layout.php b/nodcms-layout/Views/admin/layout.php index ee585e2b..5f74a639 100644 --- a/nodcms-layout/Views/admin/layout.php +++ b/nodcms-layout/Views/admin/layout.php @@ -11,6 +11,7 @@ <?php echo $title; ?> <?php echo isset($sub_title)?$sub_title:""; ?> + settings['add_on_header']; ?> diff --git a/nodcms-layout/Views/nodcms-clean.php b/nodcms-layout/Views/nodcms-clean.php index 9ff04a5e..6f9b96f0 100644 --- a/nodcms-layout/Views/nodcms-clean.php +++ b/nodcms-layout/Views/nodcms-clean.php @@ -11,6 +11,7 @@ <?php echo $title; ?> <?php echo isset($sub_title)?$sub_title:""; ?> + settings['add_on_header']; ?> diff --git a/nodcms-layout/Views/nodcms-frontend.php b/nodcms-layout/Views/nodcms-frontend.php index a10117bf..8756c71d 100644 --- a/nodcms-layout/Views/nodcms-frontend.php +++ b/nodcms-layout/Views/nodcms-frontend.php @@ -13,6 +13,7 @@ "> <?php echo $title; ?> <?php echo isset($sub_title)?$sub_title:""; ?> + settings['add_on_header']; ?> diff --git a/nodcms-layout/Views/nodcms-membership.php b/nodcms-layout/Views/nodcms-membership.php index 41314eed..9b5dbdc5 100644 --- a/nodcms-layout/Views/nodcms-membership.php +++ b/nodcms-layout/Views/nodcms-membership.php @@ -11,6 +11,7 @@ <?php echo $title; ?> <?php echo isset($sub_title)?$sub_title:""; ?> + settings['add_on_header']; ?> diff --git a/nodcms-users/Views/layout.php b/nodcms-users/Views/layout.php index 58ca7e0c..9089c1e5 100644 --- a/nodcms-users/Views/layout.php +++ b/nodcms-users/Views/layout.php @@ -18,6 +18,7 @@ <?php echo $title; ?> + settings['add_on_header']; ?> diff --git a/public/assets/nodcms/js/common.js b/public/assets/nodcms/js/common.js index 26746a97..598aaad8 100644 --- a/public/assets/nodcms/js/common.js +++ b/public/assets/nodcms/js/common.js @@ -16,6 +16,36 @@ function translate(value){ } (function ($) { + + // Save the origin jquery ajax + let $originAjax = $.ajax; + + // Reset jquery ajax function to add csrf token generally + $.ajax = function (url, options) { + + // If url is an object, simulate pre-1.5 signature + if ( typeof url === "object" ) { + options = url; + url = undefined; + } + + // Force options to be an object + options = options || {}; + + if((options.hasOwnProperty('method') && options.method !== null && options.method.toLowerCase() === "post") || + (options.hasOwnProperty('type') && options.type !== null && options.type.toLowerCase() === "post")) { + let m = document.getElementById('csrf_meta'); + if(m !== null) { + if(!options.hasOwnProperty('headers')) options['headers'] = {}; + if(!options.headers.hasOwnProperty(m.getAttribute('name'))) { + options.headers[m.getAttribute('name')] = m.getAttribute('content'); + } + } + } + + return $originAjax(url, options); + }; + $.dataListSearch = function () { var query_string = "?"; $('.data-list-search-input').each(function () { diff --git a/public/assets/nodcms/js/common.min.js b/public/assets/nodcms/js/common.min.js index 7ab625e2..8b8a82e0 100644 --- a/public/assets/nodcms/js/common.min.js +++ b/public/assets/nodcms/js/common.min.js @@ -1 +1 @@ -window.CKEDITOR_BASEPATH=$("body").attr("data-base-url")+"assets/plugins/ckeditor/";function translate(value){if(typeof SITE_TRANSLATE!="undefined"&&typeof SITE_TRANSLATE[value]!="undefined")return SITE_TRANSLATE[value];return value}(function($){$.dataListSearch=function(){var query_string="?";$(".data-list-search-input").each(function(){if($("#language_select").val()!=0&&$("#language_select").val()!=null){query_string+="language="+$("#language_select").val()+"&"}if($("#filters").val()!=0&&$("#filters").val()!=null){query_string+="filters="+$("#filters").val()+"&"}});return query_string};$.showInModal=function(title,content,addButtons,modal_class){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()});myModal.appendTo("body");myModal.find(".modal-body").html(content);var modalFooter=myModal.find(".modal-footer");if(addButtons!=null&&typeof addButtons=="object"&&addButtons.length>0){$.each(addButtons,function(key,val){modalFooter.append(val)})}else if(addButtons!=null){modalFooter.append(addButtons)}myModal.modal("show");return myModal};$.fn.quickCKeditor=function(){$(this).each(function(){var $myTextArea=$(this);CKEDITOR.replace($myTextArea.attr("id"),{on:{instanceReady:function(evt){$($myTextArea.attr("data-loading")).remove()}},toolbar:[{name:"document",items:["Source"]},["Cut","Copy","Paste","PasteText","PasteFromWord","-","Undo","Redo","Underline","Strike"],{name:"basicstyles",items:["Bold","Italic"]},{name:"links",items:["Link"]}]})})};$.fn.checkEditorLoad=function(){if(typeof CKEDITOR!=="undefined"){$(this).find(".ckeditor").each(function(){var $myTextArea=$(this);if(CKEDITOR.instances[$myTextArea.attr("id")]){$($myTextArea.attr("data-loading")).remove();return}CKEDITOR.replace($myTextArea.attr("id"),{on:{instanceReady:function(evt){$($myTextArea.attr("data-loading")).remove()}}})});$(this).find(".ckeditor-quick").quickCKeditor()}else if($(this).find(".ckeditor,.ckeditor-quick").length>0){$(this).find(".ckeditor").each(function(){$(this).removeClass("ckeditor")});$(this).find(".ckeditor-quick").each(function(){$(this).removeClass("ckeditor-quick")});alert("common.js: Load the ckeditor.js file is required to use this form.")}return $(this)};$.loadInModal=function(url,addon_class,success_func){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal("show");$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.title!=="undefined"){myModal.find(".modal-title").html(data.title)}else{myModal.find(".modal-title").remove()}if(typeof data.content!=="undefined"){myModal.find(".modal-body").html($(data.content))}else{myModal.find(".modal-body").remove()}if(typeof data.footer!=="undefined"){myModal.find(".modal-footer").html($(data.footer))}if(typeof data.closeBtnLabel!=="undefined"){myModal.find('.modal-footer button[data-dismiss="modal"]').html(data.closeBtnLabel)}else{myModal.find('.modal-footer button[data-dismiss="modal"]').remove()}if(typeof data.footerLinks!=="undefined"){var default_options={color:"",url:"",caption:"",target:"_self"};$.each(data.footerLinks,function(key,val){val=$.extend(default_options,val);$(''+val.caption+"").prependTo(myModal.find(".modal-footer"))})}if(typeof data.footerButtons!=="undefined"){var default_options={color:"",onclick:"",caption:"",target:"_self"};$.each(data.footerButtons,function(key,val){val=$.extend(default_options,val);$('").prependTo(myModal.find(".modal-footer"))})}myModal.find(".modal-header, .modal-footer").removeClass("hidden");myModal.checkEditorLoad().handleAutomatics();myModal.find(".input-select2").each(function(){$(this).select2({allowClear:true,dropdownParent:myModal,width:null})});if($.fn.makeDropzone){myModal.find(".dropzone").makeDropzone()}if(myModal.find(".next-page").length>0){myModal.modalScrollEnd(function(){myModal.find(".next-page").attr("class","next-page-loading");myModal.find(".next-page-loading").loadBefore(myModal.find(".next-page-loading").attr("data-url"));myModal.find(".next-page-loading").remove()})}if(typeof success_func=="function")success_func(myModal)}else myModal.find(".modal-body").html('

Error

'+data.error+"

")},error:function(xhr,status,error){console.log(xhr.responseText);myModal.find(".modal-body").html('

Error

Ajax failed: '+error+"!

")}});return myModal};$.redirectTo=function(url,message){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal({backdrop:"static",keyboard:false});window.location=url;return myModal};$.redirectProcess=function(url,message){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal({backdrop:"static",keyboard:false});$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){window.location=data.url}else{toastr.error(data.error,translate("error"));myModal.modal("hide")}},error:function(xhr,status,error){console.log(xhr.responseText);toastr.error(error,translate("error"));myModal.modal("hide")}});return myModal};$.loadConfirmModal=function(url,onConfirmSuccess){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal("show");$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.title!=="undefined"){myModal.find(".modal-title").html(data.title)}else{myModal.find(".modal-title").remove()}if(typeof data.content!=="undefined"){myModal.find(".modal-body").html($(data.content))}else{myModal.find(".modal-body").remove()}if(typeof data.noBtnLabel!=="undefined"){myModal.find('.modal-footer button[data-dismiss="modal"]').html(data.noBtnLabel)}else{myModal.find('.modal-footer button[data-dismiss="modal"]').remove()}if(typeof data.yesBtnLabel!=="undefined"){myModal.find('.modal-footer button[data-confirm="1"]').html(data.yesBtnLabel)}myModal.find(".modal-header, .modal-footer").removeClass("hidden");if(myModal.find(".next-page").length>0){myModal.modalScrollEnd(function(){myModal.find(".next-page").attr("class","next-page-loading");myModal.find(".next-page-loading").loadBefore(myModal.find(".next-page-loading").attr("data-url"));myModal.find(".next-page-loading").remove()})}if(typeof data.confirmUrl!=="undefined"){myModal.find('.modal-footer button[data-confirm="1"]').click(function(){var $yesButton=$(this);$.ajax({url:data.confirmUrl,dataType:"json",beforeSend:function(){$yesButton.addClass("disabled").prepend($(' '))},complete:function(){$yesButton.find(".fa.fa-spinner").remove()},success:function(result){if(data.status=="success"){toastr.success(result.msg,translate("Success"));if(typeof onConfirmSuccess!=="undefined"){onConfirmSuccess(result,myModal);return}if(typeof data.redirect!=="undefined"&&data.redirect==1){myModal.find(".modal-body").html('

'+translate("Redirecting...")+"

");window.location=result.url;return}if(typeof result.data!=="undefined"&&typeof result.data.success!=="undefined"){eval(result.data.success)}myModal.modal("hide")}else{toastr.error(result.error,translate("Error"))}},error:function(xhr,status,error){console.log(xhr.responseText);toastr.error(translate("Send form with ajax failed!"),translate("Error"))}})})}}else myModal.find(".modal-body").html('

Error

'+data.error+"

")},error:function(xhr,status,error){console.log(xhr.responseText);myModal.find(".modal-body").html('

Error

Ajax failed: '+error+"!

")}});return myModal};$.fn.modalScrollEnd=function(success_fun){var $modal=$(this);var do_active=function(){var modal_scrollTop=$modal.scrollTop();var modal_scrollHeight=$modal.prop("scrollHeight");var modal_innerHeight=$modal.innerHeight();if(modal_scrollTop+modal_innerHeight>=modal_scrollHeight-100){success_fun()}};do_active();$modal.scroll(function(){do_active()})};$.fn.loadIn=function(url,empty_404){var $this=$(this);$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.content!=="undefined"){$this.html($(data.content));var btn,$form=$this.find("form");if(typeof data.footerLinks!=="undefined"){var default_options={color:"",url:"",caption:"",target:"_self"};$.each(data.footerLinks,function(key,val){val=$.extend(default_options,val);btn=$(''+val.caption+"");if($form.length>0){btn.appendTo($form)}else{btn.appendTo($this)}})}if(typeof data.footerButtons!=="undefined"){var default_options={color:"",onclick:"",caption:"",target:"_self"};$.each(data.footerButtons,function(key,val){val=$.extend(default_options,val);btn=$('");if($form.length>0){btn.appendTo($form)}else{btn.appendTo($this)}})}$this.checkEditorLoad().handleAutomatics();$(".input-select2").each(function(){$(this).select2({allowClear:true,width:null})});$this.find(".plot-statistics").each(function(){$(this).handelPlotStatistic()});$this.find(".plot-pie-statistics").each(function(){$(this).handelPlotPieStatistic()});if($.fn.makeDropzone){$this.find(".dropzone").makeDropzone()}}}else{if(typeof empty_404!="undefined"&&empty_404){console.log(data.error);$this.html("");return}$this.html('

'+translate("Error")+"

"+data.error+"

")}},error:function(xhr,status,error){if(typeof empty_404!="undefined"&&empty_404){alert(error);alert(status);$this.html("");return}$this.html('

Error

Ajax failed: '+error+"!

"+xhr.responseText+"
")}})};$.fn.loadBefore=function(url,success_fun){var $this=$(this);$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.content!=="undefined"){$this.insertBefore($(data.content));$this.checkEditorLoad().handleAutomatics();$(".input-select2").each(function(){$(this).select2({allowClear:true,width:null})})}}else $this.html('

Error

'+data.error+"

")},error:function(xhr,status,error){$this.html('

Error

Ajax failed: '+error+"!

"+xhr.responseText+"
")}})};$.fn.makeSpinnerBtn=function(){$(this).click(function(){$(this).addClass("disabled").append('')})};$.fn.removeAnItemFromList=function(url,type){var the_element=$(this);var removeItem=function(result,myModal){if(typeof type!=="undefined"&&type=="refresh"){location.reload();return}if(typeof the_element.data("parent")!=="undefined"){$(the_element.data("parent")+" .box-item[data-id="+the_element.data("id")+"]").parent().slideUp(500).delay(500).remove();myModal.modal("hide");return}if(typeof the_element.data("target")!=="undefined"){$(the_element.data("target")).slideUp(500).delay(500).remove();myModal.modal("hide");return}toastr.success(result.msg,"Success");myModal.modal("hide")};$.loadConfirmModal(url,removeItem)};$.fn.ajaxToggleActionButton=function(url,btn_lass_1,btn_class_2,success){var the_element=$(this);var btn_caption_default=the_element.html(),btn_caption_1=the_element.data("caption1"),btn_caption_2=the_element.data("caption2");$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.addClass("disabled");the_element.append($(''))},complete:function(){the_element.removeClass("disabled");the_element.find("i.fa-spinner.fa-pulse").remove()},success:function(result){if(result.status=="success"){the_element.toggleClass(btn_class_1+" "+btn_class_2);if(btn_caption_default==btn_caption_1){btn_caption_default=btn_caption_2}else{btn_caption_default=btn_caption_1}the_element.html(btn_caption_default);if(typeof success=="function")success();toastr.success(result.msg,translate("Success"))}else{toastr.error(result.error,translate("Error"))}},error:function(xhr,status,error){alert(xhr.responseText);toastr.error("Send form with ajax failed!","Error")}})};$.fn.ajaxActionButton=function(url,success,success_msg){var the_element=$(this);$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.addClass("disabled");the_element.append($(''))},complete:function(){the_element.removeClass("disabled");the_element.find("i.fa-spinner.fa-pulse").remove()},success:function(result){if(result.status=="success"){if(typeof success_msg!="boolean"||success_msg==true)toastr.success(result.msg,"Success");if(typeof success=="function")success(result)}else{var StrippedString=result.error.replace(/(<([^>]+)>)/gi,"");if(result.error==StrippedString)toastr.error(result.error,translate("Error"));else $.showInModal(translate("Error")+": "+translate("Ajax failed!"),'
'+translate("Error")+"
"+result.error)}},error:function(xhr,status,error){$.showInModal(translate("Error")+": "+translate("Ajax failed!"),'
'+"

"+translate("Error")+"

"+error+"
"+"

"+translate("Result")+"

"+xhr.responseText)}})};$.fn.ajaxRefreshActionButton=function(url,success){var the_element=$(this);$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.addClass("disabled");the_element.find("i.fa-refresh").addClass("fa-pulse")},complete:function(){the_element.removeClass("disabled");the_element.find("i.fa-refresh").removeClass("fa-pulse")},success:function(result){if(result.status=="success"){success(result.data)}else{toastr.error(result.error,"Error")}},error:function(){toastr.error("Send form with ajax failed!","Error")}})};$.fn.ajaxAppendLastRow=function(url){var the_element=$(this);var $loading=$("
");$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.append($loading)},complete:function(){the_element.find(".loading").remove()},success:function(result){if(result.status=="success"){the_element.append(result.data)}else{toastr.error(result.error,"Error")}},error:function(){toastr.error("Send form with ajax failed!","Error")}})};$.fn.insertHTMLAtTexteditor=function(areaId){var html_code=$(this).find("textarea").val();CKEDITOR.instances[areaId].insertHtml(html_code,"html")};$.fn.highlight_selected_menu=function(){var item=$(this);if(item.length==0)return;var myParent=item.parent("ul");if(myParent.hasClass("sub-menu")){item.addClass("active");if(item.find("sub-menu").length>0){$("#"+item.attr("id")+" > a:first-child .arrow").addClass("open")}myParent.parent("li").highlight_selected_menu()}else{item.addClass("active star open");if(item.find("sub-menu").length>0){}$("#"+item.attr("id")+" > a:first-child").append($('')).find(".arrow").addClass("open")}};var currencyFormatSettings={};$.setCurrencyFormatSettings=function(options){var default_settings={before_sign:"",after_sign:"",currency_code:"",number_format:"1,234.56"};currencyFormatSettings=$.extend(default_settings,options)};$.currencyFormat=function(value){var default_settings={before_sign:"",after_sign:"",currency_code:"",number_format:"1,234.56"};var settings=typeof currencyFormatSettings!="undefined"?$.extend(default_settings,currencyFormatSettings):default_settings;function formatMoney(n,c,d,t){var c=isNaN(c=Math.abs(c))?2:c,d=d==undefined?".":d,t=t==undefined?",":t,s=n<0?"-":"",i=String(parseInt(n=Math.abs(Number(n)||0).toFixed(c))),j=(j=i.length)>3?j%3:0;return settings.before_sign+s+(j?i.substr(0,j)+t:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+t)+(c?d+Math.abs(n-i).toFixed(c).slice(2):"")+settings.after_sign}if(settings.number_format="1.234,56"){return formatMoney(value,2,".",",")}else if(settings.number_format="1,234.56"){return formatMoney(value,2,",",".")}else if(value="1.234"){return formatMoney(value,0,".","")}else if(value="1,234"){return formatMoney(value,0,",","")}else{alert("The format of currency is unknown.")}};$.fn.handleAutomatics=function(){var the_parent=$(this);the_parent.find(".input-select2").each(function(){$(this).select2({allowClear:true,width:null})});the_parent.find(".load-ajax-content").each(function(){$(this).loadIn($(this).data("load"))});the_parent.find('div[data-role="auto-load"]').each(function(){var e404=typeof $(this).data("empty")!="undefined"&&$(this).data("empty")==1;$(this).loadIn($(this).data("url"),e404)});the_parent.find(".load-ajax-content-btn").click(function(){$($(this).data("target")).html('

'+' Loading...'+"

");$($(this).data("target")).loadIn($(this).data("load"))});the_parent.find('a[data-role="auto-load-tab"]').click(function(){var $tab_button=$(this),$tab_box=$($tab_button.attr("href"));$tab_box.html(' '+translate("Loading")+"");$tab_box.loadIn($tab_button.data("url"))});the_parent.find('.active > a[data-role="auto-load-tab"]').each(function(){$(this).trigger("click")});the_parent.find('input[type="radio"][data-role="toggle-hidden"]').change(function(){$('input[type="radio"][data-role="toggle-hidden"][name="'+$(this).attr("name")+'"]').not(this).each(function(){$($(this).data("target")).addClass("hidden")});$($('input[type="radio"][data-role="toggle-hidden"][name="'+$(this).attr("name")+'"]:checked').data("target")).removeClass("hidden")});the_parent.find('input[type="radio"][data-role="toggle-disabled"]').change(function(){$('input[type="radio"][data-role="toggle-disabled"][name="'+$(this).attr("name")+'"]').not(this).each(function(){$($(this).data("target")).attr("disabled","disabled")});$($(this).data("target")).removeAttr("disabled")});the_parent.find("select").each(function(){if(typeof $(this).data("default")!="undefined"&&$(this).find('option[value="'+$(this).data("default")+'"]').length>0){$(this).val($(this).data("default"))}});the_parent.find('input[type="checkbox"][data-role="toggle-hidden"]').click(function(){if($(this).is(":checked"))$($(this).data("target")).removeClass("d-none");else $($(this).data("target")).addClass("d-none")})}})(jQuery);$(function(){$("body").checkEditorLoad().handleAutomatics();$("a.btn-spinner").makeSpinnerBtn();var handleGoTop=function(){var offset=300;var duration=500;if(navigator.userAgent.match(/iPhone|iPad|iPod/i)){$(window).bind("touchend touchcancel touchleave",function(e){if($(this).scrollTop()>offset){$(".scroll-to-top").fadeIn(duration)}else{$(".scroll-to-top").fadeOut(duration)}})}else{$(window).scroll(function(){if($(this).scrollTop()>offset){$(".scroll-to-top").fadeIn(duration)}else{$(".scroll-to-top").fadeOut(duration)}})}$(".scroll-to-top").click(function(e){e.preventDefault();$("html, body").animate({scrollTop:0},duration);return false})};handleGoTop()}); \ No newline at end of file +window.CKEDITOR_BASEPATH=$("body").attr("data-base-url")+"assets/plugins/ckeditor/";function translate(value){if(typeof SITE_TRANSLATE!="undefined"&&typeof SITE_TRANSLATE[value]!="undefined")return SITE_TRANSLATE[value];return value}(function($){let $originAjax=$.ajax;$.ajax=function(url,options){if(typeof url==="object"){options=url;url=undefined}options=options||{};if(options.hasOwnProperty("method")&&options.method!==null&&options.method.toLowerCase()==="post"||options.hasOwnProperty("type")&&options.type!==null&&options.type.toLowerCase()==="post"){let m=document.getElementById("csrf_meta");if(m!==null){if(!options.hasOwnProperty("headers"))options["headers"]={};if(!options.headers.hasOwnProperty(m.getAttribute("name"))){options.headers[m.getAttribute("name")]=m.getAttribute("content")}}}return $originAjax(url,options)};$.dataListSearch=function(){var query_string="?";$(".data-list-search-input").each(function(){if($("#language_select").val()!=0&&$("#language_select").val()!=null){query_string+="language="+$("#language_select").val()+"&"}if($("#filters").val()!=0&&$("#filters").val()!=null){query_string+="filters="+$("#filters").val()+"&"}});return query_string};$.showInModal=function(title,content,addButtons,modal_class){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()});myModal.appendTo("body");myModal.find(".modal-body").html(content);var modalFooter=myModal.find(".modal-footer");if(addButtons!=null&&typeof addButtons=="object"&&addButtons.length>0){$.each(addButtons,function(key,val){modalFooter.append(val)})}else if(addButtons!=null){modalFooter.append(addButtons)}myModal.modal("show");return myModal};$.fn.quickCKeditor=function(){$(this).each(function(){var $myTextArea=$(this);CKEDITOR.replace($myTextArea.attr("id"),{on:{instanceReady:function(evt){$($myTextArea.attr("data-loading")).remove()}},toolbar:[{name:"document",items:["Source"]},["Cut","Copy","Paste","PasteText","PasteFromWord","-","Undo","Redo","Underline","Strike"],{name:"basicstyles",items:["Bold","Italic"]},{name:"links",items:["Link"]}]})})};$.fn.checkEditorLoad=function(){if(typeof CKEDITOR!=="undefined"){$(this).find(".ckeditor").each(function(){var $myTextArea=$(this);if(CKEDITOR.instances[$myTextArea.attr("id")]){$($myTextArea.attr("data-loading")).remove();return}CKEDITOR.replace($myTextArea.attr("id"),{on:{instanceReady:function(evt){$($myTextArea.attr("data-loading")).remove()}}})});$(this).find(".ckeditor-quick").quickCKeditor()}else if($(this).find(".ckeditor,.ckeditor-quick").length>0){$(this).find(".ckeditor").each(function(){$(this).removeClass("ckeditor")});$(this).find(".ckeditor-quick").each(function(){$(this).removeClass("ckeditor-quick")});alert("common.js: Load the ckeditor.js file is required to use this form.")}return $(this)};$.loadInModal=function(url,addon_class,success_func){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal("show");$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.title!=="undefined"){myModal.find(".modal-title").html(data.title)}else{myModal.find(".modal-title").remove()}if(typeof data.content!=="undefined"){myModal.find(".modal-body").html($(data.content))}else{myModal.find(".modal-body").remove()}if(typeof data.footer!=="undefined"){myModal.find(".modal-footer").html($(data.footer))}if(typeof data.closeBtnLabel!=="undefined"){myModal.find('.modal-footer button[data-dismiss="modal"]').html(data.closeBtnLabel)}else{myModal.find('.modal-footer button[data-dismiss="modal"]').remove()}if(typeof data.footerLinks!=="undefined"){var default_options={color:"",url:"",caption:"",target:"_self"};$.each(data.footerLinks,function(key,val){val=$.extend(default_options,val);$(''+val.caption+"").prependTo(myModal.find(".modal-footer"))})}if(typeof data.footerButtons!=="undefined"){var default_options={color:"",onclick:"",caption:"",target:"_self"};$.each(data.footerButtons,function(key,val){val=$.extend(default_options,val);$('").prependTo(myModal.find(".modal-footer"))})}myModal.find(".modal-header, .modal-footer").removeClass("hidden");myModal.checkEditorLoad().handleAutomatics();myModal.find(".input-select2").each(function(){$(this).select2({allowClear:true,dropdownParent:myModal,width:null})});if($.fn.makeDropzone){myModal.find(".dropzone").makeDropzone()}if(myModal.find(".next-page").length>0){myModal.modalScrollEnd(function(){myModal.find(".next-page").attr("class","next-page-loading");myModal.find(".next-page-loading").loadBefore(myModal.find(".next-page-loading").attr("data-url"));myModal.find(".next-page-loading").remove()})}if(typeof success_func=="function")success_func(myModal)}else myModal.find(".modal-body").html('

Error

'+data.error+"

")},error:function(xhr,status,error){console.log(xhr.responseText);myModal.find(".modal-body").html('

Error

Ajax failed: '+error+"!

")}});return myModal};$.redirectTo=function(url,message){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal({backdrop:"static",keyboard:false});window.location=url;return myModal};$.redirectProcess=function(url,message){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal({backdrop:"static",keyboard:false});$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){window.location=data.url}else{toastr.error(data.error,translate("error"));myModal.modal("hide")}},error:function(xhr,status,error){console.log(xhr.responseText);toastr.error(error,translate("error"));myModal.modal("hide")}});return myModal};$.loadConfirmModal=function(url,onConfirmSuccess){var myModal=$('").on("hidden.bs.modal",function(e){$(this).remove()}).appendTo("body");myModal.modal("show");$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.title!=="undefined"){myModal.find(".modal-title").html(data.title)}else{myModal.find(".modal-title").remove()}if(typeof data.content!=="undefined"){myModal.find(".modal-body").html($(data.content))}else{myModal.find(".modal-body").remove()}if(typeof data.noBtnLabel!=="undefined"){myModal.find('.modal-footer button[data-dismiss="modal"]').html(data.noBtnLabel)}else{myModal.find('.modal-footer button[data-dismiss="modal"]').remove()}if(typeof data.yesBtnLabel!=="undefined"){myModal.find('.modal-footer button[data-confirm="1"]').html(data.yesBtnLabel)}myModal.find(".modal-header, .modal-footer").removeClass("hidden");if(myModal.find(".next-page").length>0){myModal.modalScrollEnd(function(){myModal.find(".next-page").attr("class","next-page-loading");myModal.find(".next-page-loading").loadBefore(myModal.find(".next-page-loading").attr("data-url"));myModal.find(".next-page-loading").remove()})}if(typeof data.confirmUrl!=="undefined"){myModal.find('.modal-footer button[data-confirm="1"]').click(function(){var $yesButton=$(this);$.ajax({url:data.confirmUrl,dataType:"json",beforeSend:function(){$yesButton.addClass("disabled").prepend($(' '))},complete:function(){$yesButton.find(".fa.fa-spinner").remove()},success:function(result){if(data.status=="success"){toastr.success(result.msg,translate("Success"));if(typeof onConfirmSuccess!=="undefined"){onConfirmSuccess(result,myModal);return}if(typeof data.redirect!=="undefined"&&data.redirect==1){myModal.find(".modal-body").html('

'+translate("Redirecting...")+"

");window.location=result.url;return}if(typeof result.data!=="undefined"&&typeof result.data.success!=="undefined"){eval(result.data.success)}myModal.modal("hide")}else{toastr.error(result.error,translate("Error"))}},error:function(xhr,status,error){console.log(xhr.responseText);toastr.error(translate("Send form with ajax failed!"),translate("Error"))}})})}}else myModal.find(".modal-body").html('

Error

'+data.error+"

")},error:function(xhr,status,error){console.log(xhr.responseText);myModal.find(".modal-body").html('

Error

Ajax failed: '+error+"!

")}});return myModal};$.fn.modalScrollEnd=function(success_fun){var $modal=$(this);var do_active=function(){var modal_scrollTop=$modal.scrollTop();var modal_scrollHeight=$modal.prop("scrollHeight");var modal_innerHeight=$modal.innerHeight();if(modal_scrollTop+modal_innerHeight>=modal_scrollHeight-100){success_fun()}};do_active();$modal.scroll(function(){do_active()})};$.fn.loadIn=function(url,empty_404){var $this=$(this);$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.content!=="undefined"){$this.html($(data.content));var btn,$form=$this.find("form");if(typeof data.footerLinks!=="undefined"){var default_options={color:"",url:"",caption:"",target:"_self"};$.each(data.footerLinks,function(key,val){val=$.extend(default_options,val);btn=$(''+val.caption+"");if($form.length>0){btn.appendTo($form)}else{btn.appendTo($this)}})}if(typeof data.footerButtons!=="undefined"){var default_options={color:"",onclick:"",caption:"",target:"_self"};$.each(data.footerButtons,function(key,val){val=$.extend(default_options,val);btn=$('");if($form.length>0){btn.appendTo($form)}else{btn.appendTo($this)}})}$this.checkEditorLoad().handleAutomatics();$(".input-select2").each(function(){$(this).select2({allowClear:true,width:null})});$this.find(".plot-statistics").each(function(){$(this).handelPlotStatistic()});$this.find(".plot-pie-statistics").each(function(){$(this).handelPlotPieStatistic()});if($.fn.makeDropzone){$this.find(".dropzone").makeDropzone()}}}else{if(typeof empty_404!="undefined"&&empty_404){console.log(data.error);$this.html("");return}$this.html('

'+translate("Error")+"

"+data.error+"

")}},error:function(xhr,status,error){if(typeof empty_404!="undefined"&&empty_404){alert(error);alert(status);$this.html("");return}$this.html('

Error

Ajax failed: '+error+"!

"+xhr.responseText+"
")}})};$.fn.loadBefore=function(url,success_fun){var $this=$(this);$.ajax({url:url,dataType:"json",success:function(data){if(data.status=="success"){if(typeof data.content!=="undefined"){$this.insertBefore($(data.content));$this.checkEditorLoad().handleAutomatics();$(".input-select2").each(function(){$(this).select2({allowClear:true,width:null})})}}else $this.html('

Error

'+data.error+"

")},error:function(xhr,status,error){$this.html('

Error

Ajax failed: '+error+"!

"+xhr.responseText+"
")}})};$.fn.makeSpinnerBtn=function(){$(this).click(function(){$(this).addClass("disabled").append('')})};$.fn.removeAnItemFromList=function(url,type){var the_element=$(this);var removeItem=function(result,myModal){if(typeof type!=="undefined"&&type=="refresh"){location.reload();return}if(typeof the_element.data("parent")!=="undefined"){$(the_element.data("parent")+" .box-item[data-id="+the_element.data("id")+"]").parent().slideUp(500).delay(500).remove();myModal.modal("hide");return}if(typeof the_element.data("target")!=="undefined"){$(the_element.data("target")).slideUp(500).delay(500).remove();myModal.modal("hide");return}toastr.success(result.msg,"Success");myModal.modal("hide")};$.loadConfirmModal(url,removeItem)};$.fn.ajaxToggleActionButton=function(url,btn_lass_1,btn_class_2,success){var the_element=$(this);var btn_caption_default=the_element.html(),btn_caption_1=the_element.data("caption1"),btn_caption_2=the_element.data("caption2");$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.addClass("disabled");the_element.append($(''))},complete:function(){the_element.removeClass("disabled");the_element.find("i.fa-spinner.fa-pulse").remove()},success:function(result){if(result.status=="success"){the_element.toggleClass(btn_class_1+" "+btn_class_2);if(btn_caption_default==btn_caption_1){btn_caption_default=btn_caption_2}else{btn_caption_default=btn_caption_1}the_element.html(btn_caption_default);if(typeof success=="function")success();toastr.success(result.msg,translate("Success"))}else{toastr.error(result.error,translate("Error"))}},error:function(xhr,status,error){alert(xhr.responseText);toastr.error("Send form with ajax failed!","Error")}})};$.fn.ajaxActionButton=function(url,success,success_msg){var the_element=$(this);$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.addClass("disabled");the_element.append($(''))},complete:function(){the_element.removeClass("disabled");the_element.find("i.fa-spinner.fa-pulse").remove()},success:function(result){if(result.status=="success"){if(typeof success_msg!="boolean"||success_msg==true)toastr.success(result.msg,"Success");if(typeof success=="function")success(result)}else{var StrippedString=result.error.replace(/(<([^>]+)>)/gi,"");if(result.error==StrippedString)toastr.error(result.error,translate("Error"));else $.showInModal(translate("Error")+": "+translate("Ajax failed!"),'
'+translate("Error")+"
"+result.error)}},error:function(xhr,status,error){$.showInModal(translate("Error")+": "+translate("Ajax failed!"),'
'+"

"+translate("Error")+"

"+error+"
"+"

"+translate("Result")+"

"+xhr.responseText)}})};$.fn.ajaxRefreshActionButton=function(url,success){var the_element=$(this);$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.addClass("disabled");the_element.find("i.fa-refresh").addClass("fa-pulse")},complete:function(){the_element.removeClass("disabled");the_element.find("i.fa-refresh").removeClass("fa-pulse")},success:function(result){if(result.status=="success"){success(result.data)}else{toastr.error(result.error,"Error")}},error:function(){toastr.error("Send form with ajax failed!","Error")}})};$.fn.ajaxAppendLastRow=function(url){var the_element=$(this);var $loading=$("
");$.ajax({url:url,dataType:"json",beforeSend:function(){the_element.append($loading)},complete:function(){the_element.find(".loading").remove()},success:function(result){if(result.status=="success"){the_element.append(result.data)}else{toastr.error(result.error,"Error")}},error:function(){toastr.error("Send form with ajax failed!","Error")}})};$.fn.insertHTMLAtTexteditor=function(areaId){var html_code=$(this).find("textarea").val();CKEDITOR.instances[areaId].insertHtml(html_code,"html")};$.fn.highlight_selected_menu=function(){var item=$(this);if(item.length==0)return;var myParent=item.parent("ul");if(myParent.hasClass("sub-menu")){item.addClass("active");if(item.find("sub-menu").length>0){$("#"+item.attr("id")+" > a:first-child .arrow").addClass("open")}myParent.parent("li").highlight_selected_menu()}else{item.addClass("active star open");if(item.find("sub-menu").length>0){}$("#"+item.attr("id")+" > a:first-child").append($('')).find(".arrow").addClass("open")}};var currencyFormatSettings={};$.setCurrencyFormatSettings=function(options){var default_settings={before_sign:"",after_sign:"",currency_code:"",number_format:"1,234.56"};currencyFormatSettings=$.extend(default_settings,options)};$.currencyFormat=function(value){var default_settings={before_sign:"",after_sign:"",currency_code:"",number_format:"1,234.56"};var settings=typeof currencyFormatSettings!="undefined"?$.extend(default_settings,currencyFormatSettings):default_settings;function formatMoney(n,c,d,t){var c=isNaN(c=Math.abs(c))?2:c,d=d==undefined?".":d,t=t==undefined?",":t,s=n<0?"-":"",i=String(parseInt(n=Math.abs(Number(n)||0).toFixed(c))),j=(j=i.length)>3?j%3:0;return settings.before_sign+s+(j?i.substr(0,j)+t:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+t)+(c?d+Math.abs(n-i).toFixed(c).slice(2):"")+settings.after_sign}if(settings.number_format="1.234,56"){return formatMoney(value,2,".",",")}else if(settings.number_format="1,234.56"){return formatMoney(value,2,",",".")}else if(value="1.234"){return formatMoney(value,0,".","")}else if(value="1,234"){return formatMoney(value,0,",","")}else{alert("The format of currency is unknown.")}};$.fn.handleAutomatics=function(){var the_parent=$(this);the_parent.find(".input-select2").each(function(){$(this).select2({allowClear:true,width:null})});the_parent.find(".load-ajax-content").each(function(){$(this).loadIn($(this).data("load"))});the_parent.find('div[data-role="auto-load"]').each(function(){var e404=typeof $(this).data("empty")!="undefined"&&$(this).data("empty")==1;$(this).loadIn($(this).data("url"),e404)});the_parent.find(".load-ajax-content-btn").click(function(){$($(this).data("target")).html('

'+' Loading...'+"

");$($(this).data("target")).loadIn($(this).data("load"))});the_parent.find('a[data-role="auto-load-tab"]').click(function(){var $tab_button=$(this),$tab_box=$($tab_button.attr("href"));$tab_box.html(' '+translate("Loading")+"");$tab_box.loadIn($tab_button.data("url"))});the_parent.find('.active > a[data-role="auto-load-tab"]').each(function(){$(this).trigger("click")});the_parent.find('input[type="radio"][data-role="toggle-hidden"]').change(function(){$('input[type="radio"][data-role="toggle-hidden"][name="'+$(this).attr("name")+'"]').not(this).each(function(){$($(this).data("target")).addClass("hidden")});$($('input[type="radio"][data-role="toggle-hidden"][name="'+$(this).attr("name")+'"]:checked').data("target")).removeClass("hidden")});the_parent.find('input[type="radio"][data-role="toggle-disabled"]').change(function(){$('input[type="radio"][data-role="toggle-disabled"][name="'+$(this).attr("name")+'"]').not(this).each(function(){$($(this).data("target")).attr("disabled","disabled")});$($(this).data("target")).removeAttr("disabled")});the_parent.find("select").each(function(){if(typeof $(this).data("default")!="undefined"&&$(this).find('option[value="'+$(this).data("default")+'"]').length>0){$(this).val($(this).data("default"))}});the_parent.find('input[type="checkbox"][data-role="toggle-hidden"]').click(function(){if($(this).is(":checked"))$($(this).data("target")).removeClass("d-none");else $($(this).data("target")).addClass("d-none")})}})(jQuery);$(function(){$("body").checkEditorLoad().handleAutomatics();$("a.btn-spinner").makeSpinnerBtn();var handleGoTop=function(){var offset=300;var duration=500;if(navigator.userAgent.match(/iPhone|iPad|iPod/i)){$(window).bind("touchend touchcancel touchleave",function(e){if($(this).scrollTop()>offset){$(".scroll-to-top").fadeIn(duration)}else{$(".scroll-to-top").fadeOut(duration)}})}else{$(window).scroll(function(){if($(this).scrollTop()>offset){$(".scroll-to-top").fadeIn(duration)}else{$(".scroll-to-top").fadeOut(duration)}})}$(".scroll-to-top").click(function(e){e.preventDefault();$("html, body").animate({scrollTop:0},duration);return false})};handleGoTop()}); \ No newline at end of file