diff --git a/ChangeLog b/ChangeLog index 20a1748af6b..ffb51bd26c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -104,6 +104,7 @@ Following changes may create regressions for some external modules, but were nec by a "_" automatically when a reference (with a custom numbering mask that use it) is generated. * Library jflot (replace with chartjs) and geoip (replaced with geoip2) were removed. * Hidden constant COMMANDE_VALID_AFTER_CLOSE_PROPAL were renamed into ORDER_VALID_AFTER_CLOSE_PROPAL. +* Object field ref_int is deprecated and set to not used, object fetch by only ref_int is not supported anymore. ***** ChangeLog for 11.0.3 compared to 11.0.2 ***** diff --git a/dev/translation/strip_language_file.php b/dev/translation/strip_language_file.php index ce28ca5de63..f2263b1d18b 100755 --- a/dev/translation/strip_language_file.php +++ b/dev/translation/strip_language_file.php @@ -250,11 +250,11 @@ foreach($filesToProcess as $fileToProcess) { if ( ! $oh = fopen($output, 'w') ) { - print "ERROR in writing to file $output\n"; + print "ERROR in writing to file ".$output."\n"; exit; } - print "Read Primary File $lPrimaryFile and write ".$output.":\n"; + print "Read Primary File ".$lPrimaryFile." and write ".$output.":\n"; fwrite($oh, "# Dolibarr language file - Source file is en_US - ".(preg_replace('/\.lang$/', '', $fileToProcess))."\n"); diff --git a/dev/translation/txpull.sh b/dev/translation/txpull.sh index fcccae98221..65d5af3689b 100755 --- a/dev/translation/txpull.sh +++ b/dev/translation/txpull.sh @@ -33,8 +33,16 @@ if [ "x$1" = "xall" ] then if [ "x$2" = "x" ] then - echo "tx pull" - tx pull + echo "tx pull -a" + tx pull -a + + echo "Remove some language directories (not enough translated)" + rm -fr htdocs/langs/ach + rm -fr htdocs/langs/br_FR + rm -fr htdocs/langs/en + rm -fr htdocs/langs/frp + rm -fr htdocs/langs/fy_NL + else for dir in `find htdocs/langs/* -type d` do diff --git a/htdocs/admin/translation.php b/htdocs/admin/translation.php index c17c2bdcee6..e509f96c001 100644 --- a/htdocs/admin/translation.php +++ b/htdocs/admin/translation.php @@ -244,7 +244,6 @@ print ''; print ''; print ''; print ''; -print ''; $head = translation_prepare_head(); @@ -252,7 +251,7 @@ dol_fiche_head($head, $mode, '', -1, ''); if ($mode == 'overwrite') { - //print load_fiche_titre($langs->trans("TranslationOverwriteKey"), '', '')."\n"; + print ''; $disabled = ''; if ($action == 'edit' || empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) $disabled = ' disabled="disabled"'; @@ -456,8 +455,8 @@ if ($mode == 'searchkey') //print 'param='.$param.' $_SERVER["PHP_SELF"]='.$_SERVER["PHP_SELF"].' num='.$num.' page='.$page.' nbtotalofrecords='.$nbtotalofrecords." sortfield=".$sortfield." sortorder=".$sortorder; $title = $langs->trans("TranslationKeySearch"); - if ($nbtotalofrecords > 0) $title .= ' ('.$nbtotalofrecords.' / '.$nbtotalofrecordswithoutfilters.' - '.$nbtotaloffiles.' '.$langs->trans("Files").')'; - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit); + if ($nbtotalofrecords > 0) $title .= ' ('.$nbtotalofrecords.' / '.$nbtotalofrecordswithoutfilters.' - '.$nbtotaloffiles.' '.$langs->trans("Files").')'; + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, -1 * $nbtotalofrecords, '', 0, '', '', $limit, 0, 0, 1); print ''; print ''; diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 48e9c9d965a..c98dee97f51 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -523,7 +523,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $keyforbreak = 'duration'; include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php'; - print ''.$langs->trans("TotalCost").''.price($object->total_cost).''; + print ''.$form->textwithpicto($langs->trans("TotalCost"), $langs->trans("BOMTotalCost")).''.price($object->total_cost).''; print ''.$langs->trans("UnitCost").''.price($object->unit_cost).''; // Other attributes diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 3e522b3c11f..86e0b84b655 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1013,11 +1013,20 @@ class BOM extends CommonObject $this->unit_cost = 0; $this->total_cost = 0; + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + $productFournisseur = new ProductFournisseur($this->db); + foreach ($this->lines as &$line) { $tmpproduct = new Product($this->db); $tmpproduct->fetch($line->fk_product); + $line->unit_cost = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp); + if (empty($line->unit_cost)) { + if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) + { + $line->unit_cost = $productFournisseur->fourn_unitprice; + } + } - $line->unit_cost = (!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp; // TODO : add option to work with cost_price or pmp $line->total_cost = price2num($line->qty * $line->unit_cost, 'MT'); $this->total_cost += $line->total_cost; } diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index dc451855c0a..cf0fa1cd697 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -64,9 +64,7 @@ class Categorie extends CommonObject /** - * @var array ID mapping from type string - * - * @note This array should be removed in future, once previous constants are moved to the string value. Deprecated + * @var array Table of mapping between type string and ID used for field 'type' in table llx_categories */ protected $MAP_ID = array( 'product' => 0, @@ -79,7 +77,8 @@ class Categorie extends CommonObject 'user' => 7, 'bank_line' => 8, 'warehouse' => 9, - 'actioncomm' => 10 + 'actioncomm' => 10, + 'website_page' => 11 ); /** @@ -1113,6 +1112,10 @@ class Categorie extends CommonObject global $conf, $langs; if (!is_numeric($type)) $type = $this->MAP_ID[$type]; + if (is_null($type)) { + $this->error = 'BadValueForParameterType'; + return -1; + } if (is_string($markafterid)) { diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index b36101750f2..db6f5a2eec4 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -54,6 +54,7 @@ $typetext = $type; if ($type == Categorie::TYPE_ACCOUNT) $title = $langs->trans('AccountsCategoriesArea'); elseif ($type == Categorie::TYPE_WAREHOUSE) $title = $langs->trans('StocksCategoriesArea'); elseif ($type == Categorie::TYPE_ACTIONCOMM) $title = $langs->trans('ActionCommCategoriesArea'); +elseif ($type == Categorie::TYPE_WEBSITE_PAGE) $title = $langs->trans('WebsitePagesCategoriesArea'); else $title = $langs->trans(ucfirst($type).'sCategoriesArea'); $arrayofjs = array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); @@ -69,8 +70,6 @@ if (!empty($user->rights->categorie->creer)) { print load_fiche_titre($title, $newcardbutton, 'object_category'); -//print ''; -//print ''; print ''; print ''; -/* -// faire une rech dans une sous categorie uniquement -print ''; -print ''; -*/ - print '
'; print '
'; @@ -88,20 +87,9 @@ print '
'.$langs->trans("Search").'
'; print $langs->trans("Name").':
'; -print $langs->trans("SubCatOf").':'; - -print $form->select_all_categories('','subcatof'); -print '
'; -//print ''; print '
'; @@ -138,7 +126,6 @@ if ($catname || $id > 0) else print ' '; -//print ''; print '
'; print '

'; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index bd5430c440a..28fdc7845d2 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -2596,13 +2596,13 @@ if ($action == 'create') /* * Documents generes */ - $filename = dol_sanitizeFileName($object->ref); + $objref = dol_sanitizeFileName($object->ref); $filedir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref); $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed = $usercanread; $delallowed = $usercancreate; - print $formfile->showdocuments('propal', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object); + print $formfile->showdocuments('propal', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object); // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('propal')); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 4764b53a5c9..21f558219eb 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2688,13 +2688,13 @@ if ($action == 'create' && $usercancreate) print '
'; print ''; // ancre // Documents - $comref = dol_sanitizeFileName($object->ref); - $relativepath = $comref.'/'.$comref.'.pdf'; - $filedir = $conf->commande->multidir_output[$object->entity].'/'.$comref; + $objref = dol_sanitizeFileName($object->ref); + $relativepath = $objref.'/'.$objref.'.pdf'; + $filedir = $conf->commande->multidir_output[$object->entity].'/'.$objref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed = $usercanread; $delallowed = $usercancreate; - print $formfile->showdocuments('commande', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object); + print $formfile->showdocuments('commande', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object); // Show links to link elements diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index c737af4a89e..ee02e6a6e8e 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -179,7 +179,7 @@ $sqlrequestforbankline = $sql; if ($action == 'confirm_editbankreceipt' && !empty($oldbankreceipt) && !empty($newbankreceipt)) { // TODO Add a test to check newbankreceipt does not exists yet - $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX.'bank SET num_releve = "'.$db->escape($newbankreceipt).'" WHERE num_releve = "'.$db->escape($oldbankreceipt).'"'; + $sqlupdate = 'UPDATE '.MAIN_DB_PREFIX.'bank SET num_releve = "'.$db->escape($newbankreceipt).'" WHERE num_releve = "'.$db->escape($oldbankreceipt).'" AND fk_account = '.$id; $result = $db->query($sqlupdate); if ($result < 0) dol_print_error($db); diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index ab2262844bf..522d4471daa 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1025,7 +1025,7 @@ if (empty($reshook)) // Replacement invoice if ($_POST['type'] == Facture::TYPE_REPLACEMENT) { - $dateinvoice = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -1086,7 +1086,7 @@ if (empty($reshook)) $action = 'create'; } - $dateinvoice = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -1269,7 +1269,7 @@ if (empty($reshook)) // Standard invoice or Deposit invoice, created from a Predefined template invoice if (($_POST['type'] == Facture::TYPE_STANDARD || $_POST['type'] == Facture::TYPE_DEPOSIT) && GETPOST('fac_rec', 'int') > 0) { - $dateinvoice = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -1320,7 +1320,7 @@ if (empty($reshook)) $action = 'create'; } - $dateinvoice = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $dateinvoice = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($dateinvoice)) { $error++; @@ -1745,7 +1745,7 @@ if (empty($reshook)) // Situation invoices if (GETPOST('type') == Facture::TYPE_SITUATION && (!empty($_POST['situations']))) { - $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (empty($datefacture)) { $error++; $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")); diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 9e7485d189f..781daacd030 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -358,7 +358,6 @@ if (strlen($search_fax)) $sql .= natural_search('p.fax', $search_fax) if (!empty($conf->socialnetworks->enabled)) { foreach ($socialnetworks as $key => $value) { if ($value['active'] && strlen($search_{$key})) { - //$sql.= natural_search("p.socialnetworks->'$.".$key."'", $search_{$key}); $sql .= ' AND p.socialnetworks LIKE \'%"'.$key.'":"'.$search_{$key}.'%\''; } } diff --git a/htdocs/core/antispamimage.php b/htdocs/core/antispamimage.php index 68e585c3ea0..7d6512a64a9 100644 --- a/htdocs/core/antispamimage.php +++ b/htdocs/core/antispamimage.php @@ -43,7 +43,7 @@ $number = strlen($letters); $string = ''; for ($i = 0; $i < $length; $i++) { - $string .= $letters{mt_rand(0, $number - 1)}; + $string .= $letters[mt_rand(0, $number - 1)]; } //print $string; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 18dd686367b..6e0651568a1 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -43,7 +43,7 @@ class ExtraFields public $db; /** - * @var string type of element (for what object is the extrafield) + * @var array Array with type of element (for what object is the extrafield) * @deprecated */ public $attribute_elementtype; diff --git a/htdocs/core/class/extralanguages.class.php b/htdocs/core/class/extralanguages.class.php index 71a6fa8c1aa..48f2e94936a 100644 --- a/htdocs/core/class/extralanguages.class.php +++ b/htdocs/core/class/extralanguages.class.php @@ -18,7 +18,7 @@ /** * \file htdocs/core/class/extralanguages.class.php * \ingroup core - * \brief File of class to manage extra fields + * \brief File of class to manage extra languages for some fields */ @@ -69,7 +69,8 @@ class ExtraLanguages // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Load array this->attributes with list of fields per object that need an alternate translation. + * Load array this->attributes with list of fields per object that need an alternate translation. The object and field must be managed with + * the widgetForTranslation() method. * You can set variable MAIN_USE_ALTERNATE_TRANSLATION_FOR=elementA:fieldname,fieldname2;elementB:... * Example: MAIN_USE_ALTERNATE_TRANSLATION_FOR=societe:name,town;contact:firstname,lastname * @@ -119,16 +120,16 @@ class ExtraLanguages * * @param string $key Key of attribute * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) + * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data * @param string $moreparam To add more parametes on html input tag * @param string $keysuffix Prefix string to add after name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Suffix string to add before name and id of field (can be used to avoid duplicate names) * @param string $morecss More css (to defined size of field. Old behaviour: may also be a numeric) * @param int $objectid Current object id - * @param string $extrafieldsobjectkey If defined (for example $object->table_element), use the new method to get extrafields data * @param string $mode 1=Used for search filters * @return string */ - public function showInputField($key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $extrafieldsobjectkey = '', $mode = 0) + public function showInputField($key, $value, $extrafieldsobjectkey, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = '', $objectid = 0, $mode = 0) { global $conf, $langs, $form; @@ -145,601 +146,7 @@ class ExtraLanguages $keyprefix = $keyprefix.'options_'; } - if (!empty($extrafieldsobjectkey)) - { - $label = $this->attributes[$extrafieldsobjectkey]['label'][$key]; - $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; - $size = $this->attributes[$extrafieldsobjectkey]['size'][$key]; - $default = $this->attributes[$extrafieldsobjectkey]['default'][$key]; - $computed = $this->attributes[$extrafieldsobjectkey]['computed'][$key]; - $unique = $this->attributes[$extrafieldsobjectkey]['unique'][$key]; - $required = $this->attributes[$extrafieldsobjectkey]['required'][$key]; - $param = $this->attributes[$extrafieldsobjectkey]['param'][$key]; - $perms = dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); - $langfile = $this->attributes[$extrafieldsobjectkey]['langfile'][$key]; - $list = dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); - $totalizable = $this->attributes[$extrafieldsobjectkey]['totalizable'][$key]; - $help = $this->attributes[$extrafieldsobjectkey]['help'][$key]; - $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) - } - else // Old usage - { - $label = $this->attribute_label[$key]; - $type = $this->attribute_type[$key]; - $size = $this->attribute_size[$key]; - $elementtype = $this->attribute_elementtype[$key]; // Seems not used - $default = $this->attribute_default[$key]; - $computed = $this->attribute_computed[$key]; - $unique = $this->attribute_unique[$key]; - $required = $this->attribute_required[$key]; - $param = $this->attribute_param[$key]; - $langfile = $this->attribute_langfile[$key]; - $list = $this->attribute_list[$key]; - $totalizable = $this->attribute_totalizable[$key]; - $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) - } - if ($computed) - { - if (!preg_match('/^search_/', $keyprefix)) return ''.$langs->trans("AutomaticallyCalculated").''; - else return ''; - } - - if (empty($morecss)) - { - if ($type == 'date') - { - $morecss = 'minwidth100imp'; - } - elseif ($type == 'datetime' || $type == 'link') - { - $morecss = 'minwidth200imp'; - } - elseif (in_array($type, array('int', 'integer', 'double', 'price'))) - { - $morecss = 'maxwidth75'; - } - elseif ($type == 'password') - { - $morecss = 'maxwidth100'; - } - elseif ($type == 'url') - { - $morecss = 'minwidth400'; - } - elseif ($type == 'boolean') - { - $morecss = ''; - } - else - { - if (round($size) < 12) - { - $morecss = 'minwidth100'; - } - elseif (round($size) <= 48) - { - $morecss = 'minwidth200'; - } - else - { - $morecss = 'minwidth400'; - } - } - } - - if (in_array($type, array('date', 'datetime'))) - { - $tmp = explode(',', $size); - $newsize = $tmp[0]; - - $showtime = in_array($type, array('datetime')) ? 1 : 0; - - // Do not show current date when field not required (see selectDate() method) - if (!$required && $value == '') $value = '-1'; - - // TODO Must also support $moreparam - $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); - } - elseif (in_array($type, array('int', 'integer'))) - { - $tmp = explode(',', $size); - $newsize = $tmp[0]; - $out = ''; - } - elseif (preg_match('/varchar/', $type)) - { - $out = ''; - } - elseif (in_array($type, array('mail', 'phone', 'url'))) - { - $out = ''; - } - elseif ($type == 'text') - { - if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field - { - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); - $out = $doleditor->Create(1); - } - else - { - $out = ''; - } - } - elseif ($type == 'html') - { - if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field - { - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); - $out = $doleditor->Create(1); - } - else - { - $out = ''; - } - } - elseif ($type == 'boolean') - { - if (empty($mode)) - { - $checked = ''; - if (!empty($value)) { - $checked = ' checked value="1" '; - } else { - $checked = ' value="1" '; - } - $out = ''; - } - else - { - $out .= $form->selectyesno($keyprefix.$key.$keysuffix, $value, 1, false, 1); - } - } - elseif ($type == 'price') - { - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. - $value = price($value); - } - $out = ' '.$langs->getCurrencySymbol($conf->currency); - } - elseif ($type == 'double') - { - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. - $value = price($value); - } - $out = ' '; - } - elseif ($type == 'select') - { - $out = ''; - if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; - $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); - } - - $out .= ''; - } - elseif ($type == 'sellist') - { - $out = ''; - if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; - $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); - } - - $out .= ''; - } - elseif ($type == 'checkbox') - { - $value_arr = explode(',', $value); - $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); - } - elseif ($type == 'radio') - { - $out = ''; - foreach ($param['options'] as $keyopt => $val) - { - $out .= ''.$val.'
'; - } - } - elseif ($type == 'chkbxlst') - { - if (is_array($value)) { - $value_arr = $value; - } - else { - $value_arr = explode(',', $value); - } - - if (is_array($param['options'])) { - $param_list = array_keys($param['options']); - $InfoFieldList = explode(":", $param_list[0]); - $parentName = ''; - $parentField = ''; - // 0 : tableName - // 1 : label field name - // 2 : key fields name (if differ of rowid) - // 3 : key field parent (for dependent lists) - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value - // 5 : id category type - // 6 : ids categories list separated by comma for category root - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); - - if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { - list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); - $keyList .= ', '.$parentField; - } - if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { - if (strpos($InfoFieldList[4], 'extra.') !== false) { - $keyList = 'main.'.$InfoFieldList[2].' as rowid'; - } else { - $keyList = $InfoFieldList[2].' as rowid'; - } - } - - $filter_categorie = false; - if (count($InfoFieldList) > 5) { - if ($InfoFieldList[0] == 'categorie') { - $filter_categorie = true; - } - } - - if ($filter_categorie === false) { - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $keyList .= ', '; - $keyList .= implode(', ', $fields_label); - } - - $sqlwhere = ''; - $sql = 'SELECT '.$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; - if (!empty($InfoFieldList[4])) { - // can use SELECT request - if (strpos($InfoFieldList[4], '$SEL$') !== false) { - $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); - } - - // current object id can be use into filter - if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { - $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); - } elseif (preg_match("#^.*list.php$#", $_SERVER["PHP_SELF"])) { - // Pattern for word=$ID$ - $word = '\b[a-zA-Z0-9-\.-_]+\b=\$ID\$'; - - // Removing space arount =, ( and ) - $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); - - $nbPreg = 1; - // While we have parenthesis - while ($nbPreg != 0) { - // Init des compteurs - $nbPregRepl = $nbPregSel = 0; - // On retire toutes les parenthèses sans = avant - $InfoFieldList[4] = preg_replace('#([^=])(\([^)^(]*('.$word.')[^)^(]*\))#', '$1 $3 ', $InfoFieldList[4], -1, $nbPregRepl); - // On retire les espaces autour des = et parenthèses - $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); - // On retire toutes les parenthèses avec = avant - $InfoFieldList[4] = preg_replace('#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*('.$word.')[^)^(]*\)#', '$1 ', $InfoFieldList[4], -1, $nbPregSel); - // On retire les espaces autour des = et parenthèses - $InfoFieldList[4] = preg_replace('# *(=|\(|\)) *#', '$1', $InfoFieldList[4]); - - // Calcul du compteur général pour la boucle - $nbPreg = $nbPregRepl + $nbPregSel; - } - - // Si l'on a un AND ou un OR, avant ou après - preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#', $InfoFieldList[4], $matchCondition); - while (!empty($matchCondition[0])) { - // If the two sides differ but are not empty - if (!empty($matchCondition[1]) && !empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3]) { - // Nobody sain would do that without parentheses - $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); - } else { - if (!empty($matchCondition[1])) { - $boolCond = (($matchCondition[1] == "AND") ? ' AND TRUE ' : ' OR FALSE '); - $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond.$matchCondition[3], $InfoFieldList[4]); - } elseif (!empty($matchCondition[3])) { - $boolCond = (($matchCondition[3] == "AND") ? ' TRUE AND ' : ' FALSE OR'); - $InfoFieldList[4] = str_replace($matchCondition[0], $boolCond, $InfoFieldList[4]); - } else { - $InfoFieldList[4] = " TRUE "; - } - } - - // Si l'on a un AND ou un OR, avant ou après - preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#', $InfoFieldList[4], $matchCondition); - } - } else { - $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); - } - - // We have to join on extrafield table - if (strpos($InfoFieldList[4], 'extra.') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; - $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; - } else { - $sqlwhere .= ' WHERE '.$InfoFieldList[4]; - } - } else { - $sqlwhere .= ' WHERE 1=1'; - } - // Some tables may have field, some other not. For the moment we disable it. - if (in_array($InfoFieldList[0], array('tablewithentity'))) { - $sqlwhere .= ' AND entity = '.$conf->entity; - } - // $sql.=preg_replace('/^ AND /','',$sqlwhere); - // print $sql; - - $sql .= $sqlwhere; - dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - $i = 0; - - $data = array(); - - while ($i < $num) { - $labeltoshow = ''; - $obj = $this->db->fetch_object($resql); - - $notrans = false; - // Several field into label (eq table:code|libelle:rowid) - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $notrans = true; - foreach ($fields_label as $field_toshow) { - $labeltoshow .= $obj->$field_toshow.' '; - } - } else { - $labeltoshow = $obj->{$InfoFieldList[1]}; - } - $labeltoshow = dol_trunc($labeltoshow, 45); - - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { - foreach ($fields_label as $field_toshow) { - $translabel = $langs->trans($obj->$field_toshow); - if ($translabel != $obj->$field_toshow) { - $labeltoshow = dol_trunc($translabel, 18).' '; - } else { - $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; - } - } - - $data[$obj->rowid] = $labeltoshow; - } else { - if (!$notrans) { - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); - if ($translabel != $obj->{$InfoFieldList[1]}) { - $labeltoshow = dol_trunc($translabel, 18); - } else { - $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); - } - } - if (empty($labeltoshow)) - $labeltoshow = '(not defined)'; - - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { - $data[$obj->rowid] = $labeltoshow; - } - - if (!empty($InfoFieldList[3]) && $parentField) { - $parent = $parentName.':'.$obj->{$parentField}; - } - - $data[$obj->rowid] = $labeltoshow; - } - - $i++; - } - $this->db->free($resql); - - $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); - } else { - print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
'; - } - } else { - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1); - $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); - } - } - } - elseif ($type == 'link') - { - $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' - $showempty = (($required && $default != '') ? 0 : 1); - $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty, '', '', $morecss); - } - elseif ($type == 'password') - { - // If prefix is 'search_', field is used as a filter, we use a common text field. - $out = ''; // Hidden field to reduce impact of evil Google Chrome autopopulate bug. - $out .= ''; - } - if (!empty($hidden)) { - $out = ''; - } - /* Add comments - if ($type == 'date') $out.=' (YYYY-MM-DD)'; - elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; - */ - /*if (! empty($help) && $keyprefix != 'search_options_') { - $out .= $form->textwithpicto('', $help, 1, 'help', '', 0, 3); - }*/ return $out; } @@ -749,601 +156,16 @@ class ExtraLanguages * * @param string $key Key of attribute * @param string $value Value to show - * @param string $moreparam To add more parameters on html input tag (only checkbox use html input for output rendering) * @param string $extrafieldsobjectkey If defined (for example $object->table_element), function uses the new method to get extrafields data + * @param string $moreparam To add more parameters on html input tag (only checkbox use html input for output rendering) * @return string Formated value */ - public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjectkey = '') + public function showOutputField($key, $value, $extrafieldsobjectkey, $moreparam = '') { global $conf, $langs; - if (!empty($extrafieldsobjectkey)) - { - $label = $this->attributes[$extrafieldsobjectkey]['label'][$key]; - $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; - $size = $this->attributes[$extrafieldsobjectkey]['size'][$key]; - $default = $this->attributes[$extrafieldsobjectkey]['default'][$key]; - $computed = $this->attributes[$extrafieldsobjectkey]['computed'][$key]; - $unique = $this->attributes[$extrafieldsobjectkey]['unique'][$key]; - $required = $this->attributes[$extrafieldsobjectkey]['required'][$key]; - $param = $this->attributes[$extrafieldsobjectkey]['param'][$key]; - $perms = dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1); - $langfile = $this->attributes[$extrafieldsobjectkey]['langfile'][$key]; - $list = dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); - $help = $this->attributes[$extrafieldsobjectkey]['help'][$key]; - $hidden = (empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) - } - else // Old usage - { - //dol_syslog("Warning: parameter 'extrafieldsobjectkey' is missing", LOG_WARNING); - $label = $this->attribute_label[$key]; - $type = $this->attribute_type[$key]; - $size = $this->attribute_size[$key]; - $default = $this->attribute_default[$key]; - $computed = $this->attribute_computed[$key]; - $unique = $this->attribute_unique[$key]; - $required = $this->attribute_required[$key]; - $param = $this->attribute_param[$key]; - $perms = dol_eval($this->attribute_perms[$key], 1); - $langfile = $this->attribute_langfile[$key]; - $list = dol_eval($this->attribute_list[$key], 1); - $help = ''; // Not supported with old syntax - $hidden = (empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) - } - - if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. - - //if ($computed) $value = // $value is already calculated into $value before calling this method - - $showsize = 0; - if ($type == 'date') - { - $showsize = 10; - $value = dol_print_date($value, 'day'); - } - elseif ($type == 'datetime') - { - $showsize = 19; - $value = dol_print_date($value, 'dayhour'); - } - elseif ($type == 'int') - { - $showsize = 10; - } - elseif ($type == 'double') - { - if (!empty($value)) { - //$value=price($value); - $sizeparts = explode(",", $size); - $number_decimals = $sizeparts[1]; - $value = price($value, 0, $langs, 0, 0, $number_decimals, ''); - } - } - elseif ($type == 'boolean') - { - $checked = ''; - if (!empty($value)) { - $checked = ' checked '; - } - $value = ''; - } - elseif ($type == 'mail') - { - $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); - } - elseif ($type == 'url') - { - $value = dol_print_url($value, '_blank', 32, 1); - } - elseif ($type == 'phone') - { - $value = dol_print_phone($value, '', 0, 0, '', ' ', 'phone'); - } - elseif ($type == 'price') - { - $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); - } - elseif ($type == 'select') - { - if ($langfile && $param['options'][$value]) $value = $langs->trans($param['options'][$value]); - else $value = $param['options'][$value]; - } - elseif ($type == 'sellist') - { - $param_list = array_keys($param['options']); - $InfoFieldList = explode(":", $param_list[0]); - - $selectkey = "rowid"; - $keyList = 'rowid'; - - if (count($InfoFieldList) >= 3) - { - $selectkey = $InfoFieldList[2]; - $keyList = $InfoFieldList[2].' as rowid'; - } - - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $keyList .= ', '; - $keyList .= implode(', ', $fields_label); - } - - $sql = 'SELECT '.$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; - if (strpos($InfoFieldList[4], 'extra') !== false) - { - $sql .= ' as main'; - } - if ($selectkey == 'rowid' && empty($value)) { - $sql .= " WHERE ".$selectkey."=0"; - } elseif ($selectkey == 'rowid') { - $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); - } else { - $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; - } - - //$sql.= ' AND entity = '.$conf->entity; - - dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $value = ''; // value was used, so now we reste it to use it to build final output - - $obj = $this->db->fetch_object($resql); - - // Several field into label (eq table:code|libelle:rowid) - $fields_label = explode('|', $InfoFieldList[1]); - - if (is_array($fields_label) && count($fields_label) > 1) - { - foreach ($fields_label as $field_toshow) - { - $translabel = ''; - if (!empty($obj->$field_toshow)) { - $translabel = $langs->trans($obj->$field_toshow); - } - if ($translabel != $field_toshow) { - $value .= dol_trunc($translabel, 18).' '; - } else { - $value .= $obj->$field_toshow.' '; - } - } - } - else - { - $translabel = ''; - if (!empty($obj->{$InfoFieldList[1]})) { - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); - } - if ($translabel != $obj->{$InfoFieldList[1]}) { - $value = dol_trunc($translabel, 18); - } else { - $value = $obj->{$InfoFieldList[1]}; - } - } - } - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); - } - elseif ($type == 'radio') - { - $value = $param['options'][$value]; - } - elseif ($type == 'checkbox') - { - $value_arr = explode(',', $value); - $value = ''; - $toprint = array(); - if (is_array($value_arr)) - { - foreach ($value_arr as $keyval=>$valueval) { - $toprint[] = '
  • '.$param['options'][$valueval].'
  • '; - } - } - $value = '
      '.implode(' ', $toprint).'
    '; - } - elseif ($type == 'chkbxlst') - { - $value_arr = explode(',', $value); - - $param_list = array_keys($param['options']); - $InfoFieldList = explode(":", $param_list[0]); - - $selectkey = "rowid"; - $keyList = 'rowid'; - - if (count($InfoFieldList) >= 3) { - $selectkey = $InfoFieldList[2]; - $keyList = $InfoFieldList[2].' as rowid'; - } - - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { - $keyList .= ', '; - $keyList .= implode(', ', $fields_label); - } - - $sql = 'SELECT '.$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; - if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main'; - } - // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; - // $sql.= ' AND entity = '.$conf->entity; - - dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $value = ''; // value was used, so now we reste it to use it to build final output - $toprint = array(); - while ($obj = $this->db->fetch_object($resql)) { - // Several field into label (eq table:code|libelle:rowid) - $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { - if (is_array($fields_label) && count($fields_label) > 1) { - foreach ($fields_label as $field_toshow) { - $translabel = ''; - if (!empty($obj->$field_toshow)) { - $translabel = $langs->trans($obj->$field_toshow); - } - if ($translabel != $field_toshow) { - $toprint[] = '
  • '.dol_trunc($translabel, 18).'
  • '; - } else { - $toprint[] = '
  • '.$obj->$field_toshow.'
  • '; - } - } - } else { - $translabel = ''; - if (!empty($obj->{$InfoFieldList[1]})) { - $translabel = $langs->trans($obj->{$InfoFieldList[1]}); - } - if ($translabel != $obj->{$InfoFieldList[1]}) { - $toprint[] = '
  • '.dol_trunc($translabel, 18).'
  • '; - } else { - $toprint[] = '
  • '.$obj->{$InfoFieldList[1]}.'
  • '; - } - } - } - } - $value = '
      '.implode(' ', $toprint).'
    '; - } else { - dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); - } - } - elseif ($type == 'link') - { - $out = ''; - - // Only if something to display (perf) - if ($value) // If we have -1 here, pb is into insert, not into ouptut (fix insert instead of changing code here to compensate) - { - $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' - - $InfoFieldList = explode(":", $param_list[0]); - $classname = $InfoFieldList[0]; - $classpath = $InfoFieldList[1]; - if (!empty($classpath)) - { - dol_include_once($InfoFieldList[1]); - if ($classname && class_exists($classname)) - { - $object = new $classname($this->db); - $object->fetch($value); - $value = $object->getNomUrl(3); - } - } - else - { - dol_syslog('Error bad setup of extrafield', LOG_WARNING); - return 'Error bad setup of extrafield'; - } - } - } - elseif ($type == 'text') - { - $value = dol_htmlentitiesbr($value); - } - elseif ($type == 'html') - { - $value = dol_htmlentitiesbr($value); - } - elseif ($type == 'password') - { - $value = dol_trunc(preg_replace('/./i', '*', $value), 8, 'right', 'UTF-8', 1); - } - else - { - $showsize = round($size); - if ($showsize > 48) $showsize = 48; - } - - //print $type.'-'.$size; - $out = $value; + $out = $this->attributes[$extrafieldsobjectkey][$key]; return $out; } - - /** - * Return tag to describe alignement to use for this extrafield - * - * @param string $key Key of attribute - * @param string $extrafieldsobjectkey If defined, use the new method to get extrafields data - * @return string Formated value - */ - public function getAlignFlag($key, $extrafieldsobjectkey = '') - { - global $conf, $langs; - - if (!empty($extrafieldsobjectkey)) $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; - else $type = $this->attribute_type[$key]; - - $align = ''; - - if ($type == 'date') - { - $align = "center"; - } - elseif ($type == 'datetime') - { - $align = "center"; - } - elseif ($type == 'int') - { - $align = "right"; - } - elseif ($type == 'price') - { - $align = "right"; - } - elseif ($type == 'double') - { - $align = "right"; - } - elseif ($type == 'boolean') - { - $align = "center"; - } - elseif ($type == 'radio') - { - $align = "center"; - } - elseif ($type == 'checkbox') - { - $align = "center"; - } - elseif ($type == 'price') - { - $align = "right"; - } - - return $align; - } - - /** - * Return HTML string to print separator extrafield - * - * @param string $key Key of attribute - * @param string $object Object - * @param int $colspan Value of colspan to use (it must includes the first column with title) - * @return string HTML code with line for separator - */ - public function showSeparator($key, $object, $colspan = 2) - { - global $langs; - - $out = ''; - $out .= $langs->trans($this->attributes[$object->table_element]['label'][$key]); - $out .= ''; - - $extrafield_param = $this->attributes[$object->table_element]['param'][$key]; - if (!empty($extrafield_param) && is_array($extrafield_param)) { - $extrafield_param_list = array_keys($extrafield_param['options']); - - if (count($extrafield_param_list) > 0) { - $extrafield_collapse_display_value = intval($extrafield_param_list[0]); - if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) { - // Set the collapse_display status to cookie in priority or if ignorecollapsesetup is 1, if cookie and ignorecollapsesetup not defined, use the setup. - $collapse_display = ((isset($_COOKIE['DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key]) || GETPOST('ignorecollapsesetup', 'int')) ? ($_COOKIE['DOLCOLLAPSE_'.$object->table_element.'_extrafields_'.$key] ? true : false) : ($extrafield_collapse_display_value == 2 ? false : true)); - $extrafields_collapse_num = $this->attributes[$object->table_element]['pos'][$key]; - - $out .= ''; - $out .= ''; - } - } - } - - return $out; - } - - /** - * Fill array_options property of object by extrafields value (using for data sent by forms) - * - * @param array $extralabels Deprecated (old $array of extrafields, now set this to null) - * @param object $object Object - * @param string $onlykey Only the following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must set this to avoid to have other extrafields being reset. - * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) - */ - public function setOptionalsFromPost($extralabels, &$object, $onlykey = '') - { - global $_POST, $langs; - - $nofillrequired = 0; // For error when required field left blank - $error_field_required = array(); - - if (is_array($this->attributes[$object->table_element]['label'])) $extralabels = $this->attributes[$object->table_element]['label']; - - if (is_array($extralabels)) - { - // Get extra fields - foreach ($extralabels as $key => $value) - { - if (!empty($onlykey) && $key != $onlykey) continue; - - $key_type = $this->attributes[$object->table_element]['type'][$key]; - if ($key_type == 'separate') continue; - - $enabled = 1; - if (isset($this->attributes[$object->table_element]['list'][$key])) - { - $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); - } - $perms = 1; - if (isset($this->attributes[$object->table_element]['perms'][$key])) - { - $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); - } - if (empty($enabled)) continue; - if (empty($perms)) continue; - - if ($this->attributes[$object->table_element]['required'][$key]) // Value is required - { - // Check if empty without using GETPOST, value can be alpha, int, array, etc... - if ((!is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] != 'select' && $_POST["options_".$key] != '0') - || (!is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $this->attributes[$object->table_element]['type'][$key] == 'select') - || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key]))) - { - //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; - $nofillrequired++; - $error_field_required[] = $langs->transnoentitiesnoconv($value); - } - } - - if (in_array($key_type, array('date'))) - { - // Clean parameters - // TODO GMT date in memory must be GMT so we should add gm=true in parameters - $value_key = dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); - } - elseif (in_array($key_type, array('datetime'))) - { - // Clean parameters - // TODO GMT date in memory must be GMT so we should add gm=true in parameters - $value_key = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); - } - elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) - { - $value_arr = GETPOST("options_".$key, 'array'); // check if an array - if (!empty($value_arr)) { - $value_key = implode($value_arr, ','); - } else { - $value_key = ''; - } - } - elseif (in_array($key_type, array('price', 'double'))) - { - $value_arr = GETPOST("options_".$key, 'alpha'); - $value_key = price2num($value_arr); - } - else - { - $value_key = GETPOST("options_".$key); - if (in_array($key_type, array('link')) && $value_key == '-1') $value_key = ''; - } - - $object->array_options["options_".$key] = $value_key; - } - - if ($nofillrequired) { - $langs->load('errors'); - setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ', $error_field_required), null, 'errors'); - return -1; - } - else { - return 1; - } - } - else { - return 0; - } - } - - /** - * return array_options array of data of extrafields value of object sent by a search form - * - * @param array|string $extrafieldsobjectkey array of extrafields (old usage) or value of object->table_element (new usage) - * @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names) - * @param string $keysuffix Suffix string to add into name and id of field (can be used to avoid duplicate names) - * @return array|int array_options set or 0 if no value - */ - public function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix = '', $keysuffix = '') - { - global $_POST; - - if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey]['label'])) - { - $extralabels = $this->attributes[$extrafieldsobjectkey]['label']; - } - else - { - $extralabels = $extrafieldsobjectkey; - } - - if (is_array($extralabels)) - { - $array_options = array(); - - // Get extra fields - foreach ($extralabels as $key => $value) - { - $key_type = ''; - if (is_string($extrafieldsobjectkey)) - { - $key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; - } - - if (in_array($key_type, array('date', 'datetime'))) - { - if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) continue; // Value was not provided, we should not set it. - // Clean parameters - $value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int')); - } - elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) - { - if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. - $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); - // Make sure we get an array even if there's only one checkbox - $value_arr = (array) $value_arr; - $value_key = implode(',', $value_arr); - } - elseif (in_array($key_type, array('price', 'double', 'int'))) - { - if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. - $value_arr = GETPOST($keysuffix."options_".$key.$keyprefix); - $value_key = price2num($value_arr); - } - else - { - if (!GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it. - $value_key = GETPOST($keysuffix."options_".$key.$keyprefix); - } - - $array_options[$keysuffix."options_".$key] = $value_key; // No keyprefix here. keyprefix is used only for read. - } - - return $array_options; - } - - return 0; - } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index b07e5220384..f2b11938ca2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -368,6 +368,8 @@ class Form $s = picto_from_langcode($langcode, 'class="pictoforlang paddingright"'); $resultforextrlang .= $s; + + // TODO Use the showInputField() method of ExtraLanguages object if ($typeofdata == 'textarea') { $resultforextrlang .= '