diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 853deb55731..25a86943a43 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -334,8 +334,8 @@ if ($resql) { $resql_supplier_price = $object->db->query($sql_supplier_price); if ($resql_supplier_price) { $obj = $object->db->fetch_object($resql_supplier_price); - if(!empty($obj->qty) && !empty($sub_bom_line->qty) && !empty($line->qty)) $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty; - else $line_cost = $obj->min_price; + if (!empty($obj->qty) && !empty($sub_bom_line->qty) && !empty($line->qty)) $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty; + else $line_cost = $obj->min_price; print ''.price2num($line_cost, 'MT').''; $total_cost+= $line_cost; diff --git a/htdocs/compta/facture/invoicetemplate_list.php b/htdocs/compta/facture/invoicetemplate_list.php index 56ef08d1f1e..c2955777e4b 100644 --- a/htdocs/compta/facture/invoicetemplate_list.php +++ b/htdocs/compta/facture/invoicetemplate_list.php @@ -626,13 +626,13 @@ if (!empty($arrayfields['f.total_ttc']['checked'])) { } if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) { // Payment term - print ''; + print ''; print $form->getSelectConditionsPaiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100'); print ""; } if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) { // Payment mode - print ''; + print ''; print $form->select_types_paiements($search_payment_mode, 'search_payment_mode', '', 0, 1, 1, 0, 1, 'maxwidth100', 1); print ''; } diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index ad9a09d5013..7e85071e453 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -448,6 +448,7 @@ abstract class CommonDocGenerator // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value + * Note that vars into substitutions array are formatted. * * @param Object $object Main object to use as data source * @param Translate $outputlangs Lang object to use for output @@ -498,14 +499,15 @@ abstract class CommonDocGenerator $array_key.'_hour'=>dol_print_date($date, 'hour'), $array_key.'_date'=>dol_print_date($date, 'day'), $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'), - $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ?dol_print_date($object->date_lim_reglement, 'day') : ''), - $array_key.'_date_end'=>(!empty($object->fin_validite) ?dol_print_date($object->fin_validite, 'day') : ''), + $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'day') : ''), + $array_key.'_date_limit_rfc'=>(!empty($object->date_lim_reglement) ? dol_print_date($object->date_lim_reglement, 'dayrfc') : ''), + $array_key.'_date_end'=>(!empty($object->fin_validite) ? dol_print_date($object->fin_validite, 'day') : ''), $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'), - $array_key.'_date_modification'=>(!empty($object->date_modification) ?dol_print_date($object->date_modification, 'day') : ''), - $array_key.'_date_validation'=>(!empty($object->date_validation) ?dol_print_date($object->date_validation, 'dayhour') : ''), - $array_key.'_date_approve'=>(!empty($object->date_approve) ?dol_print_date($object->date_approve, 'day') : ''), - $array_key.'_date_delivery_planed'=>(!empty($object->delivery_date) ?dol_print_date($object->delivery_date, 'day') : ''), - $array_key.'_date_close'=>(!empty($object->date_cloture) ?dol_print_date($object->date_cloture, 'dayhour') : ''), + $array_key.'_date_modification'=>(!empty($object->date_modification) ? dol_print_date($object->date_modification, 'day') : ''), + $array_key.'_date_validation'=>(!empty($object->date_validation) ? dol_print_date($object->date_validation, 'dayhour') : ''), + $array_key.'_date_approve'=>(!empty($object->date_approve) ? dol_print_date($object->date_approve, 'day') : ''), + $array_key.'_date_delivery_planed'=>(!empty($object->delivery_date) ? dol_print_date($object->delivery_date, 'day') : ''), + $array_key.'_date_close'=>(!empty($object->date_cloture) ? dol_print_date($object->date_cloture, 'dayhour') : ''), $array_key.'_payment_mode_code'=>$object->mode_reglement_code, $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code) != 'PaymentType'.$object->mode_reglement_code ? $outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code) : $object->mode_reglement), @@ -641,6 +643,7 @@ abstract class CommonDocGenerator // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value + * Note that vars into substitutions array are formatted. * * @param Object $line Object line * @param Translate $outputlangs Lang object to use for output @@ -650,8 +653,6 @@ abstract class CommonDocGenerator public function get_substitutionarray_lines($line, $outputlangs, $linenumber = 0) { // phpcs:enable - global $conf; - $resarray = array( 'line_pos' => $linenumber, 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs), @@ -765,6 +766,7 @@ abstract class CommonDocGenerator // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value + * Note that vars into substitutions array are formatted. * * @param Expedition $object Main object to use as data source * @param Translate $outputlangs Lang object to use for output @@ -831,6 +833,7 @@ abstract class CommonDocGenerator // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define array with couple substitution key => substitution value + * Note that vars into substitutions array are formatted. * * @param ExpeditionLigne $line Object line * @param Translate $outputlangs Lang object to use for output @@ -839,7 +842,6 @@ abstract class CommonDocGenerator public function get_substitutionarray_shipment_lines($line, $outputlangs) { // phpcs:enable - global $conf; dol_include_once('/core/lib/product.lib.php'); $resarray = array( @@ -930,6 +932,7 @@ abstract class CommonDocGenerator // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fill array with couple extrafield key => extrafield value + * Note that vars into substitutions array are formatted. * * @param Object $object Object with extrafields (must have $object->array_options filled) * @param array $array_to_fill Substitution array @@ -945,49 +948,51 @@ abstract class CommonDocGenerator if (is_array($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $label) { + $formatedarrayoption = $object->array_options; + if ($extrafields->attributes[$object->table_element]['type'][$key] == 'price') { - $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]); - $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency); + $formatedarrayoption['options_'.$key] = price2num($formatedarrayoption['options_'.$key]); + $formatedarrayoption['options_'.$key.'_currency'] = price($formatedarrayoption['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency); //Add value to store price with currency - $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $formatedarrayoption['options_'.$key.'_currency'])); } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'select') { - $valueofselectkey = $object->array_options['options_'.$key]; + $valueofselectkey = $formatedarrayoption['options_'.$key]; if (array_key_exists($valueofselectkey, $extrafields->attributes[$object->table_element]['param'][$key]['options'])) { - $object->array_options['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey]; + $formatedarrayoption['options_'.$key] = $extrafields->attributes[$object->table_element]['param'][$key]['options'][$valueofselectkey]; } else { - $object->array_options['options_'.$key] = ''; + $formatedarrayoption['options_'.$key] = ''; } } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'checkbox') { - $valArray = explode(',', $object->array_options['options_'.$key]); + $valArray = explode(',', $formatedarrayoption['options_'.$key]); $output = array(); foreach ($extrafields->attributes[$object->table_element]['param'][$key]['options'] as $keyopt => $valopt) { if (in_array($keyopt, $valArray)) { $output[] = $valopt; } } - $object->array_options['options_'.$key] = implode(', ', $output); + $formatedarrayoption['options_'.$key] = implode(', ', $output); } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'date') { - if (strlen($object->array_options['options_'.$key]) > 0) { - $date = $object->array_options['options_'.$key]; - $object->array_options['options_'.$key] = dol_print_date($date, 'day'); // using company output language - $object->array_options['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format - $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format + if (strlen($formatedarrayoption['options_'.$key]) > 0) { + $date = $formatedarrayoption['options_'.$key]; + $formatedarrayoption['options_'.$key] = dol_print_date($date, 'day'); // using company output language + $formatedarrayoption['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format + $formatedarrayoption['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format } else { - $object->array_options['options_'.$key] = ''; - $object->array_options['options_'.$key.'_locale'] = ''; - $object->array_options['options_'.$key.'_rfc'] = ''; + $formatedarrayoption['options_'.$key] = ''; + $formatedarrayoption['options_'.$key.'_locale'] = ''; + $formatedarrayoption['options_'.$key.'_rfc'] = ''; } - $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); - $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale'])); + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc'])); } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'datetime') { - $datetime = $object->array_options['options_'.$key]; - $object->array_options['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhour') : ''); // using company output language - $object->array_options['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format - $object->array_options['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhourrfc') : ''); // international format - $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); - $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); + $datetime = $formatedarrayoption['options_'.$key]; + $formatedarrayoption['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour') : ''); // using company output language + $formatedarrayoption['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format + $formatedarrayoption['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ? dol_print_date($datetime, 'dayhourrfc') : ''); // international format + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $formatedarrayoption['options_'.$key.'_locale'])); + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $formatedarrayoption['options_'.$key.'_rfc'])); } elseif ($extrafields->attributes[$object->table_element]['type'][$key] == 'link') { - $id = $object->array_options['options_'.$key]; + $id = $formatedarrayoption['options_'.$key]; if ($id != "") { $param = $extrafields->attributes[$object->table_element]['param'][$key]; $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' @@ -1000,14 +1005,14 @@ abstract class CommonDocGenerator $tmpobject = new $classname($this->db); $tmpobject->fetch($id); // completely replace the id with the linked object name - $object->array_options['options_'.$key] = $tmpobject->name; + $formatedarrayoption['options_'.$key] = $tmpobject->name; } } } } - if (array_key_exists('options_'.$key, $object->array_options)) { - $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); + if (array_key_exists('options_'.$key, $formatedarrayoption)) { + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $formatedarrayoption['options_'.$key])); } else { $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => '')); } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 75f2a76e7c2..00b0e682636 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9140,12 +9140,13 @@ abstract class CommonObject * Sets all object fields to null. Useful for example in lists, when printing multiple lines and a different object os fetched for each line. * @return void */ - public function emtpyObjectVars() { + public function emtpyObjectVars() + { foreach ($this->fields as $field => $arr) { $this->$field = null; } } - + /** * Function to concat keys of fields * diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 821700059b4..9603eb27b7e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1591,9 +1591,9 @@ class Form if (empty($outputmode)) { if (in_array($obj->rowid, $selected)) { - $out .= ''; + $out .= ''; } else { - $out .= ''; + $out .= ''; } } else { array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label, 'labelhtml' => $labelhtml)); @@ -8614,9 +8614,10 @@ class Form $out .= ' selected'; } if (!empty($tmplabelhtml)) { - $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml) . '"'; + $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"'; } else { - $out .= ' data-html="' . dol_escape_htmltag(($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth" style="color: #' . $tmpcolor . '"') : '') . $newval) . '"'; + $tmplabelhtml = ($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth" style="color: #' . $tmpcolor . '"') : '') . $newval; + $out .= ' data-html="' . dol_escape_htmltag($tmplabelhtml, 0, 0, '', 0, 1) . '"'; } $out .= '>'; $out .= dol_htmlentitiesbr($newval); @@ -8633,7 +8634,9 @@ class Form if ($addjscombo == 1) { $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ? constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT; $out .= 'function formatResult(record, container) {' . "\n"; - $out .= ' if ($(record.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(record.element).attr("data-html")); // If property html set, we decode html entities and use this' . "\n"; + // If property html set, we decode html entities and use this. + // Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, '', 0, 1) when building the select option. + $out .= ' if ($(record.element).attr("data-html") != undefined) { return htmlEntityDecodeJs($(record.element).attr("data-html")); }'."\n"; $out .= ' return record.text;'; $out .= '}' . "\n"; $out .= 'function formatSelection(record) {' . "\n"; diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 1c29ffc2597..37c0bfc6744 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -464,7 +464,7 @@ function urlencode(s) { /* * ================================================================= - * Purpose: Clean string to have it url encoded + * Purpose: Clean string to get a HTML coded string. * Input: s * Author: Laurent Destailleur * Licence: GPL diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 3a95809e6d4..34ca110dd1e 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -506,11 +506,15 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete = templateResult: function (data, container) { /* Format visible output into combo list */ /* Code to add class of origin OPTION propagated to the new select2
  • tag */ if (data.element) { $(container).addClass($(data.element).attr("class")); } - //console.log($(data.element).attr("data-html")); + //console.log("data html is "+$(data.element).attr("data-html")); if (data.id == '.((int) $idforemptyvalue).' && $(data.element).attr("data-html") == undefined) { return \' \'; } - if ($(data.element).attr("data-html") != undefined) return htmlEntityDecodeJs($(data.element).attr("data-html")); // If property html set, we decode html entities and use this + if ($(data.element).attr("data-html") != undefined) { + /* If property html set, we decode html entities and use this. */ + /* Note that HTML content must have been sanitized from js with dol_escape_htmltag(xxx, 0, 0, \'\', 0, 1) when building the select option. */ + return htmlEntityDecodeJs($(data.element).attr("data-html")); + } return data.text; }, templateSelection: function (selection) { /* Format visible output of selected value */ diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e273f17b154..5b47c3d31b6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1594,14 +1594,18 @@ function dol_escape_json($stringtoescape) * @param int $keepn 1=Preserve \r\n strings (otherwise, replace them with escaped value). Set to 1 when escaping for a