From 49e9326a6d4b81e446b40b2143b47af145b23145 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 24 Sep 2017 19:50:32 +0200 Subject: [PATCH 1/6] Code comment --- htdocs/core/lib/security2.lib.php | 2 +- htdocs/main.inc.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index 3876dc0e2cd..4d79b87122e 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -184,7 +184,7 @@ function dol_loginfunction($langs,$conf,$mysoc) // Set cookie for timeout management $prefix=dol_getprefix(); $sessiontimeout='DOLSESSTIMEOUT_'.$prefix; - if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", '', 0); + if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", null, false, true); if (GETPOST('urlfrom','alpha')) $_SESSION["urlfrom"]=GETPOST('urlfrom','alpha'); else unset($_SESSION["urlfrom"]); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 675c82aa499..27168349f22 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -179,7 +179,9 @@ if (! empty($_SERVER['DOCUMENT_ROOT']) && substr($_SERVER['DOCUMENT_ROOT'], -6) // Include the conf.php and functions.lib.php require_once 'filefunc.inc.php'; -// If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it +// If there is a POST parameter to tell to save automatically some POST parameters into cookies, we do it. +// This is used for example by form of boxes to save personalization of some options. +// DOL_AUTOSET_COOKIE=cookiename:val1,val2 and cookiename_val1=aaa cookiename_val2=bbb will set cookie_name with value json_encode(array('val1'=> , )) if (! empty($_POST["DOL_AUTOSET_COOKIE"])) { $tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2); @@ -194,7 +196,7 @@ if (! empty($_POST["DOL_AUTOSET_COOKIE"])) $cookiename=$tmpautoset[0]; $cookievalue=json_encode($cookiearrayvalue); //var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue); - setcookie($cookiename, empty($cookievalue)?'':$cookievalue, empty($cookievalue)?0:(time()+(86400*354)), '/'); // keep cookie 1 year + setcookie($cookiename, empty($cookievalue)?'':$cookievalue, empty($cookievalue)?0:(time()+(86400*354)), '/', null, false, true); // keep cookie 1 year and add tag httponly if (empty($cookievalue)) unset($_COOKIE[$cookiename]); } @@ -204,7 +206,7 @@ $sessionname='DOLSESSID_'.$prefix; $sessiontimeout='DOLSESSTIMEOUT_'.$prefix; if (! empty($_COOKIE[$sessiontimeout])) ini_set('session.gc_maxlifetime',$_COOKIE[$sessiontimeout]); session_name($sessionname); -session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie +session_set_cookie_params(0, '/', null, false, true); // Add tag httponly on session cookie (same as setting session.cookie_httponly into php.ini). Must be called before the session_start. // This create lock released until session_write_close() or end of page. // We need this lock as long as we read/write $_SESSION ['vars']. We can close released when finished. if (! defined('NOSESSION')) From 4246cf24f3ea4b296647f57267dbd5b417691d57 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 24 Sep 2017 20:36:27 +0200 Subject: [PATCH 2/6] Perf enhancement: Remove one include of js. --- htdocs/core/class/html.form.class.php | 11 +++-- htdocs/core/js/lib_head.js.php | 29 ++++++++++++ htdocs/core/js/select2_locale.js.php | 67 --------------------------- htdocs/core/lib/ajax.lib.php | 5 +- htdocs/main.inc.php | 3 +- 5 files changed, 39 insertions(+), 76 deletions(-) delete mode 100644 htdocs/core/js/select2_locale.js.php diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f2427056fb5..d5ada748c1f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5215,15 +5215,16 @@ class Form */ static function selectArrayAjax($htmlname, $url, $id='', $moreparam='', $moreparamtourl='', $disabled=0, $minimumInputLength=1, $morecss='', $callurlonselect=0, $placeholder='', $acceptdelayedhtml=0) { - global $langs; + global $conf, $langs; global $delayedhtmlcontent; - $tmpplugin='select2'; + // TODO Use an internal dolibarr component instead of select2 + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return ''; $out=''; - // TODO Use an internal dolibarr component instead of select2 - $outdelayed=' + $tmpplugin='select2'; + $outdelayed="\n".' '."\n"; - print ''."\n"; } } @@ -1321,7 +1320,7 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs // Global js function print ''."\n"; - print ''."\n"; + print ''."\n"; // Add datepicker default options /*if (! defined('DISABLE_DATE_PICKER')) From 3482b1293321e134a7b45afdab6ad5a9fae7cf3f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 24 Sep 2017 20:55:48 +0200 Subject: [PATCH 3/6] Comment deprecated js code --- htdocs/core/js/lib_head.js.php | 157 +++++++++++++++++---------------- 1 file changed, 81 insertions(+), 76 deletions(-) diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 46219f1b50e..57a6c4f7005 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -82,6 +82,7 @@ else header('Cache-Control: no-cache'); * SimpleDateFormat a utiliser pour retour * ================================================================== */ + /* function showDP(base,dateFieldID,format,codelang) { // check to see if another box is already showing @@ -165,7 +166,7 @@ function resetDP(base,dateFieldID,format,codelang) function loadMonth(base,month,year,ymd,codelang) { - /* showDP.box.innerHTML="Loading..."; */ + // showDP.box.innerHTML="Loading..."; // alert(codelang); var theURL=base+"datepicker.php?cm=shw&lang="+codelang; theURL+="&m="+encodeURIComponent(month); @@ -192,37 +193,6 @@ function closeDPBox() showDP.datefieldID=null; } -function dpChangeDay(dateFieldID,format) -{ - showDP.datefieldID=dateFieldID; - console.log("Call dpChangeDay, we save date into detailed fields."); - - var thefield=getObjectFromID(showDP.datefieldID); - var thefieldday=getObjectFromID(showDP.datefieldID+"day"); - var thefieldmonth=getObjectFromID(showDP.datefieldID+"month"); - var thefieldyear=getObjectFromID(showDP.datefieldID+"year"); - - var date=getDateFromFormat(thefield.value,format); - if (date) - { - thefieldday.value=date.getDate(); - if(thefieldday.onchange) thefieldday.onchange.call(thefieldday); - thefieldmonth.value=date.getMonth()+1; - if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); - thefieldyear.value=date.getFullYear(); - if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); - } - else - { - thefieldday.value=''; - if(thefieldday.onchange) thefieldday.onchange.call(thefieldday); - thefieldmonth.value=''; - if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); - thefieldyear.value=''; - if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); - } -} - function dpClickDay(year,month,day,format) { var thefield=getObjectFromID(showDP.datefieldID); @@ -250,16 +220,6 @@ function dpHighlightDay(year,month,day,months){ displayinfo.innerHTML=months[month-1]+" "+day+", "+year; } -// Returns an object given an id -function getObjectFromID(id){ - var theObject; - if(document.getElementById) - theObject=document.getElementById(id); - else - theObject=document.all[id]; - return theObject; -} - // This Function returns the top position of an object function getTop(theitem){ var offsetTrail = theitem; @@ -286,6 +246,85 @@ function getLeft(theitem){ return offsetLeft; } +// To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and +// not put popup completely on the front) +// Used only bu popup calendar +function hideSelectBoxes() { + var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); + if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1) + { + for(var i = 0; i < document.all.length; i++) + { + if(document.all[i].tagName) + if(document.all[i].tagName == "SELECT") + document.all[i].style.visibility="hidden"; + } + } +} +// To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and +// not put popup completely on the front) +// Used only bu popup calendar +function displaySelectBoxes() { + var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); + if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1) + { + for(var i = 0; i < document.all.length; i++) + { + if(document.all[i].tagName) + if(document.all[i].tagName == "SELECT") + document.all[i].style.visibility="visible"; + } + } +} + +*/ + + +// Returns an object given an id +function getObjectFromID(id){ + var theObject; + if(document.getElementById) + theObject=document.getElementById(id); + else + theObject=document.all[id]; + return theObject; +} + +// Called after selection of a date to save details into detailed fields +function dpChangeDay(dateFieldID,format) +{ + //showDP.datefieldID=dateFieldID; + console.log("Call dpChangeDay, we save date into detailed fields."); + + var thefield=getObjectFromID(dateFieldID); + var thefieldday=getObjectFromID(dateFieldID+"day"); + var thefieldmonth=getObjectFromID(dateFieldID+"month"); + var thefieldyear=getObjectFromID(dateFieldID+"year"); + + var date=getDateFromFormat(thefield.value,format); + if (date) + { + thefieldday.value=date.getDate(); + if(thefieldday.onchange) thefieldday.onchange.call(thefieldday); + thefieldmonth.value=date.getMonth()+1; + if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); + thefieldyear.value=date.getFullYear(); + if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + } + else + { + thefieldday.value=''; + if(thefieldday.onchange) thefieldday.onchange.call(thefieldday); + thefieldmonth.value=''; + if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth); + thefieldyear.value=''; + if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear); + } +} + + + + // Create XMLHttpRequest object and load url // Used by calendar or other ajax processes @@ -345,40 +384,6 @@ function loadXMLDoc(url,readyStateFunction,async) return req; } -/* To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and - * not put popup completely on the front) - * Used only bu popup calendar - */ -function hideSelectBoxes() { - var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); - if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1) - { - for(var i = 0; i < document.all.length; i++) - { - if(document.all[i].tagName) - if(document.all[i].tagName == "SELECT") - document.all[i].style.visibility="hidden"; - } - } -} -/* To hide/show select Boxes with IE6 (and only IE6 because IE6 has a bug and - * not put popup completely on the front) - * Used only bu popup calendar - */ -function displaySelectBoxes() { - var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10); - if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE 6") > -1) - { - for(var i = 0; i < document.all.length; i++) - { - if(document.all[i].tagName) - if(document.all[i].tagName == "SELECT") - document.all[i].style.visibility="visible"; - } - } -} - - /* * ================================================================= From 2e511badf99f321ecd1a9c86b0dbb05662cb3fd6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 24 Sep 2017 21:02:20 +0200 Subject: [PATCH 4/6] Code comment --- htdocs/core/js/lib_head.js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 57a6c4f7005..7ed49d004d2 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -44,7 +44,7 @@ top_httphead('text/javascript; charset=UTF-8'); if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); else header('Cache-Control: no-cache'); ?> - +// Javascript libraries for Dolibarr ERP CRM (https://www.dolibarr.org) /** From 7a6180858e9d37a2d8442a9a72d9428554b95514 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 24 Sep 2017 21:12:50 +0200 Subject: [PATCH 5/6] Fix phpunit --- test/phpunit/AdherentTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 34ec0a80917..b29f8508a8e 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -196,7 +196,6 @@ class AdherentTest extends PHPUnit_Framework_TestCase $result=$localobject->fetch($id); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); - return $localobject; } @@ -318,14 +317,13 @@ class AdherentTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $template = '%DOL_MAIN_URL_ROOT%,%ID%,%CIVILITY%,%FIRSTNAME%,%LASTNAME%,%FULLNAME%,%COMPANY%,'. - '%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%,%EMAIL%,%BIRTH%,%PHOTO%,%LOGIN%,%PASSWORD%,%PRENOM%,'. - '%NOM%,%SOCIETE%,%ADDRESS%,%ZIP%,%TOWN%,%COUNTRY%'; + $template = '__CIVILITY__,__FIRSTNAME__,__LASTNAME__,__FULLNAME__,__COMPANY__,'. + '__ADDRESS__,__ZIP__,__TOWN__,__COUNTRY__,__EMAIL__,__BIRTH__,__PHOTO__,__LOGIN__'; // If option to store clear password has been set, we get 'dolibspec' into PASSWORD field. - $expected = DOL_MAIN_URL_ROOT.','.$localobject->id.',,New firstname,New name,New firstname New name,'. + $expected = ',New firstname,New name,New firstname New name,'. 'New company,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->birth,'day').',,'. - 'newlogin,dolibspec,New firstname,New name,New company,New address,New zip,New town,Belgium'; + 'newlogin'; $result = $localobject->makeSubstitution($template); print __METHOD__." result=".$result."\n"; From 971e59395c78e2527510d35d76627a50e917eebf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 24 Sep 2017 21:46:14 +0200 Subject: [PATCH 6/6] Fix phpcs --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index d5ada748c1f..b75cde6d9e3 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2991,7 +2991,7 @@ class Form * @param string $htmlname Nom de la zone select * @param int $filtertype Not used * @param int $addempty Add an empty entry - * @param int $noadmininfo 0=Add admin info, 1=Disable admin info + * @param int $noinfoadmin 0=Add admin info, 1=Disable admin info * @param string $morecss Add more CSS on select tag * @return void */