From 3c0e2331451faa8832758409f6baada459f21a88 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2023 15:24:47 +0200 Subject: [PATCH] NEW Can add an array of several links in date selector --- ChangeLog | 1 + htdocs/compta/ajaxpayment.php | 2 + htdocs/core/class/html.form.class.php | 65 +++++++++++++++------------ htdocs/fourn/facture/paiement.php | 6 ++- htdocs/public/payment/newpayment.php | 1 + 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a529daeb0a..a0d32f49010 100644 --- a/ChangeLog +++ b/ChangeLog @@ -169,6 +169,7 @@ NEW: Use by default the domain $dolibarr_main_url_root for SMTP HELO NEW: use more recent model by default NEW: VAT can be modified during add of line NEW: write all fields and their properties in asciidoc format +NEW: Can add an array of several links in date selector For developers or integrators: ------------------------------ diff --git a/htdocs/compta/ajaxpayment.php b/htdocs/compta/ajaxpayment.php index a0c45ff0ed0..b7298189e08 100644 --- a/htdocs/compta/ajaxpayment.php +++ b/htdocs/compta/ajaxpayment.php @@ -38,6 +38,8 @@ require '../main.inc.php'; $langs->load('compta'); +// No permission check. This is just a formatting data service. + /* * View diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7779c6e16d8..22a2c53e1c2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6626,24 +6626,24 @@ class Form * - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location) * - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1) * - * @param integer|string $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). - * @param string $prefix Prefix for fields name - * @param int $h 1 or 2=Show also hours (2=hours on a new line), -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show hour always empty - * @param int $m 1=Show also minutes, -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show minutes always empty - * @param int $empty 0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only - * @param string $form_name Not used - * @param int $d 1=Show days, month, years - * @param int $addnowlink Add a link "Now", 1 with server time, 2 with local computer time - * @param int $disabled Disable input fields - * @param int $fullday When a checkbox with id #fullday is checked, hours are set with 00:00 (if value if 'fulldaystart') or 23:59 (if value is 'fulldayend') - * @param string $addplusone Add a link "+1 hour". Value must be name of another selectDate field. - * @param datetime|string $adddateof Add a link "Date of ..." using the following date. See also $labeladddateof for the label used. - * @param string $openinghours Specify hour start and hour end for the select ex 8,20 - * @param int $stepminutes Specify step for minutes between 1 and 30 - * @param string $labeladddateof Label to use for the $adddateof parameter. - * @param string $placeholder Placeholder - * @param mixed $gm 'auto' (for backward compatibility, avoid this), 'gmt' or 'tzserver' or 'tzuserrel' - * @return string Html for selectDate + * @param integer|string $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). + * @param string $prefix Prefix for fields name + * @param int $h 1 or 2=Show also hours (2=hours on a new line), -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show hour always empty + * @param int $m 1=Show also minutes, -1 has same effect but hour and minutes are prefilled with 23:59 if date is empty, 3 show minutes always empty + * @param int $empty 0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only + * @param string $form_name Not used + * @param int $d 1=Show days, month, years + * @param int $addnowlink Add a link "Now", 1 with server time, 2 with local computer time + * @param int $disabled Disable input fields + * @param int $fullday When a checkbox with id #fullday is checked, hours are set with 00:00 (if value if 'fulldaystart') or 23:59 (if value is 'fulldayend') + * @param string $addplusone Add a link "+1 hour". Value must be name of another selectDate field. + * @param datetime|string|array $adddateof Add a link "Date of ..." using the following date. Must be array(array('adddateof'=>..., 'labeladddateof'=>...)) + * @param string $openinghours Specify hour start and hour end for the select ex 8,20 + * @param int $stepminutes Specify step for minutes between 1 and 30 + * @param string $labeladddateof Label to use for the $adddateof parameter. Deprecated. Used only when $adddateof is not an array. + * @param string $placeholder Placeholder + * @param mixed $gm 'auto' (for backward compatibility, avoid this), 'gmt' or 'tzserver' or 'tzuserrel' + * @return string Html for selectDate * @see form_date(), select_month(), select_year(), select_dayofweek() */ public function selectDate($set_time = '', $prefix = 're', $h = 0, $m = 0, $empty = 0, $form_name = "", $d = 1, $addnowlink = 0, $disabled = 0, $fullday = '', $addplusone = '', $adddateof = '', $openinghours = '', $stepminutes = 1, $labeladddateof = '', $placeholder = '', $gm = 'auto') @@ -7059,17 +7059,26 @@ class Form } // Add a link to set data - if ($conf->use_javascript_ajax && $adddateof) { - $tmparray = dol_getdate($adddateof); - if (empty($labeladddateof)) { - $labeladddateof = $langs->trans("DateInvoice"); + if ($conf->use_javascript_ajax && !empty($adddateof)) { + if (!is_array($adddateof)) { + $arrayofdateof = array(array('adddateof'=>$adddateof, 'labeladddateof'=>$labeladddateof)); + } else { + $arrayofdateof = $adddateof; + } + foreach ($arrayofdateof as $valuedateof) { + $tmpadddateof = $valuedateof['adddateof']; + $tmplabeladddateof = $valuedateof['labeladddateof']; + $tmparray = dol_getdate($tmpadddateof); + if (empty($tmplabeladddateof)) { + $tmplabeladddateof = $langs->trans("DateInvoice"); + } + $reset_scripts = 'console.log(\'Click on now link\'); '; + $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($tmpadddateof, 'dayinputnoreduce').'\');'; + $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');'; + $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');'; + $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');'; + $retstring .= ' - '; } - $reset_scripts = 'console.log(\'Click on now link\'); '; - $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date($adddateof, 'dayinputnoreduce').'\');'; - $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.$tmparray['mday'].'\');'; - $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.$tmparray['mon'].'\');'; - $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.$tmparray['year'].'\');'; - $retstring .= ' -