From 1ecff0a608ee91b34406156a04e1d75c03e57644 Mon Sep 17 00:00:00 2001 From: jpb Date: Fri, 23 Oct 2020 11:14:18 +0200 Subject: [PATCH 1/5] add list and crud --- htdocs/core/class/html.form.class.php | 7 +- htdocs/core/lib/multicurrency.lib.php | 4 + htdocs/langs/en_US/multicurrency.lang | 16 + .../class/multicurrency.class.php | 6 +- htdocs/multicurrency/multicurrency_rate.php | 548 ++++++++++++++++++ 5 files changed, 578 insertions(+), 3 deletions(-) create mode 100644 htdocs/multicurrency/multicurrency_rate.php diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 14251ce2912..0ce9c883d5e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5023,9 +5023,11 @@ class Form * @param string $selected preselected currency code * @param string $htmlname name of HTML select list * @param integer $useempty 1=Add empty line + * @param string $filter Optional filters criteras (example: 'code <> x', ' in (1,3)') + * @param bool $excludeConfCurrency false = If company current currency not in table, we add it into list. Should always be available. true = we are in currency_rate update , we don't want to see conf->currency in select * @return string */ - public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0) + public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0, $filter= '',$excludeConfCurrency = false) { global $db, $conf, $langs, $user; @@ -5035,6 +5037,7 @@ class Form $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency'; $sql .= " WHERE entity IN ('".getEntity('mutlicurrency')."')"; + if ($filter) $sql .= " AND ".$filter; $resql = $db->query($sql); if ($resql) { @@ -5045,7 +5048,7 @@ class Form $out .= ''; + + print ' ' . $langs->trans('Codemulticurrency') . ''; + print '' . $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 0, " code != '".$conf->currency."'", true) . ''; + + print ' ' . $langs->trans('rate') . ''; + print ' '; + + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; +} + +if ($action == "updateRate"){ + $current_rate = new CurrencyRate($db); + $current_rate->fetch(intval($id_rate_selected)); + + if ($current_rate) { + $curr = new MultiCurrency($db); + $resultcurrentCurrency = $curr->fetch($current_rate->fk_multicurrency); + + if ($resultcurrentCurrency){ + $currency_code = $curr->code; + }else{ + $currency_code = ''; + } + + print ''; + print ''; + print '' . "\n"; + print '
' . $langs->trans("FormUpdateRate") . '
'; + + $form = new Form($db); + print '
'; + print ''; + print ' '; + print ''; + + print ''; + print ''; + + print ''; + print ''; + + print ''; + print '
' . $langs->trans('date') . '' . $langs->trans('Codemulticurrency') . '' . $form->selectMultiCurrency($currency_code, 'multicurrency_code', 0, " code != '".$conf->currency."'", true) . '' . $langs->trans('rate') . ''; + print ''; + print ''; + print ''; + print '' .$langs->trans('CancelUpdate') . ''; + + print '
'; + print '
'; + }else{ + dol_syslog("currency_rate:list:update", LOG_WARNING); + } +} + + +$sql = 'SELECT cr.rowid, cr.date_sync, cr.rate, cr.entity, m.code, m.name '; + +// Add fields from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +$sql.= ' FROM '.MAIN_DB_PREFIX.'multicurrency_rate as cr '; +$sql .=" INNER JOIN ".MAIN_DB_PREFIX."multicurrency AS m ON cr.fk_multicurrency = m.rowid"; + + +if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); + +if ($search_date_sync) $sql .= natural_search('cr.date_sync', $search_date_sync); +if ($search_rate) $sql .= natural_search('cr.rate', $search_rate); +if ($search_code) $sql .= natural_search('m.code', $search_code); + +$sql.= ' WHERE m.code != \''.$conf->currency. '\''; + +// Add where from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; +$sql.= " GROUP BY cr.rowid, cr.date_sync, cr.rate, m.code, cr.entity "; + +// Add fields from hooks +$parameters=array(); +$reshook=$hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook +$sql.=$hookmanager->resPrint; + +$sql.= $db->order($sortfield, $sortorder); + + +$nbtotalofrecords = ''; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) +{ + $result = $db->query($sql); + + if ($result){ + $nbtotalofrecords = $db->num_rows($result); + if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 + { + $page = 0; + $offset = 0; + } + }else{ + setEventMessage($langs->trans('No_record_on_multicurrency_rate'), 'warnings'); + } +} + +$sql.= $db->plimit($limit + 1, $offset); + +$resql = $db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $arrayofselected=is_array($toselect)?$toselect:array(); + + $param=''; + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($sall) $param.="&sall=".urlencode($sall); + + if ($search_date_sync) $param="&search_date_sync=".urlencode($search_date_sync); + if ($search_rate) $param="&search_rate=".urlencode($search_rate); + if ($search_code != '') $param.="&search_code=".urlencode($search_code); + + // Add $param from extra fields + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + + + if ($user->admin) $arrayofmassactions['predelete']=$langs->trans("Delete"); + if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); + + print '
'; + if ($optioncss != '') print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_currency.png', 0, $newcardbutton, '', $limit); + + include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + + if ($sall) + { + foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + print '
'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'
'; + } + + // Filter on categories + $moreforfilter=''; + + + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook + if (empty($reshook)) $moreforfilter.=$hookmanager->resPrint; + else $moreforfilter=$hookmanager->resPrint; + + if ($moreforfilter) + { + print '
'; + print $moreforfilter; + print '
'; + } + + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; + $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); + + print '
'; + print ''."\n"; + + // Lines with input filters + print ''; + + // date + if (! empty($arrayfields['cr.date_sync']['checked'])) + { + print ''; + } + // code + if (! empty($arrayfields['m.code']['checked'])) + { + print ''; + } + // rate + if (! empty($arrayfields['cr.rate']['checked'])) + { + print ''; + } + + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields); + $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print ''; + + print ''; + + print ''; + if (! empty($arrayfields['cr.date_sync']['checked'])) print_liste_field_titre($arrayfields['cr.date_sync']['label'], $_SERVER["PHP_SELF"], "cr.date_sync", "", $param, "", $sortfield, $sortorder); + if (! empty($arrayfields['m.code']['checked'])) print_liste_field_titre($arrayfields['m.code']['label'], $_SERVER["PHP_SELF"], "m.code", "", $param, "", $sortfield, $sortorder); + if (! empty($arrayfields['cr.rate']['checked'])) print_liste_field_titre($arrayfields['cr.rate']['label'], $_SERVER["PHP_SELF"], "cr.rate", "", $param, "", $sortfield, $sortorder); + + // Hook fields + $parameters=array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); + $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch '); + print "\n"; + + $i = 0; + $totalarray=array(); + while ($i < min($num, $limit)) + { + $obj = $db->fetch_object($resql); + + print ''; + + // date_sync + if (! empty($arrayfields['cr.date_sync']['checked'])) + { + print '\n"; + if (! $i) $totalarray['nbfield']++; + } + + // code + if (! empty($arrayfields['m.code']['checked'])) + { + print '\n"; + + if (! $i) $totalarray['nbfield']++; + } + + // rate + if (! empty($arrayfields['cr.rate']['checked'])) + { + print '\n"; + if (! $i) $totalarray['nbfield']++; + } + + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + + // Action + print ''; + if (! $i) $totalarray['nbfield']++; + + print "\n"; + $i++; + } + + $db->free($resql); + + print "
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print '
'; + print $obj->date_sync; + print "'; + print $obj->code ." ". $obj->name; + print "'; + print $obj->rate; + print "'; + if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + { + $selected=0; + if (in_array($obj->rowid, $arrayofselected)) $selected=1; + print 'rowid.'" class="like-link " style="margin-right:15px;important">' . img_picto('edit', 'edit') . ''; + print 'rowid.'" class="like-link" style="margin-right:45px;important">' . img_picto('delete', 'delete') . ''; + print ''; + } + print '
"; + print "
"; + + print '
'; +} +else +{ + dol_print_error($db); +} + + +llxFooter(); +$db->close(); From 47351c3cb310603773500ab363ed67580996baae Mon Sep 17 00:00:00 2001 From: jpb Date: Fri, 23 Oct 2020 13:55:55 +0200 Subject: [PATCH 2/5] Fix : stickler-ci --- htdocs/core/class/html.form.class.php | 2 +- htdocs/multicurrency/multicurrency_rate.php | 25 ++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 295fb3dc46b..11aefda225b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5053,7 +5053,7 @@ class Form * @param bool $excludeConfCurrency false = If company current currency not in table, we add it into list. Should always be available. true = we are in currency_rate update , we don't want to see conf->currency in select * @return string */ - public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0, $filter= '',$excludeConfCurrency = false) + public function selectMultiCurrency($selected = '', $htmlname = 'multicurrency_code', $useempty = 0, $filter = '', $excludeConfCurrency = false) { global $db, $conf, $langs, $user; diff --git a/htdocs/multicurrency/multicurrency_rate.php b/htdocs/multicurrency/multicurrency_rate.php index 68ff8fb3be5..64f426b93b2 100644 --- a/htdocs/multicurrency/multicurrency_rate.php +++ b/htdocs/multicurrency/multicurrency_rate.php @@ -116,7 +116,7 @@ if ($action == "create"){ dol_syslog("currencyRate:createRate", LOG_WARNING); setEventMessage($langs->trans('successRateCreate')); } - }else{ + } else { setEventMessage($langs->trans('NoEmptyRate'), "errors"); } } @@ -133,10 +133,10 @@ if ($action == 'update'){ $res = $currencyRate->update(); if ($res){ setEventMessage($langs->trans('successUpdateRate')); - }else{ + }else { setEventMessage($langs->trans('errorUpdateRate'), "errors"); } - }else{ + }else { setEventMessage($langs->trans(''), "warnings"); } } @@ -158,10 +158,10 @@ if ($action == "deleteRate"){ 0, 1 ); - }else{ + }else { dol_syslog("Multicurrency::fetch", LOG_WARNING); } - }else{ + }else { setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings"); } } @@ -173,10 +173,10 @@ if ($action == "confirm_delete"){ $result = $current_rate->delete(); if ($result){ setEventMessage($langs->trans('successRateDelete')); - }else{ + }else { setEventMessage($langs->trans('errorRateDelete')); } - }else{ + }else { setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings"); dol_syslog($langs->trans('NoCurrencyRateSelected'), LOG_WARNING); } @@ -270,7 +270,7 @@ if ($action == "updateRate"){ if ($resultcurrentCurrency){ $currency_code = $curr->code; - }else{ + }else { $currency_code = ''; } @@ -300,7 +300,7 @@ if ($action == "updateRate"){ print ''; print ''; print ''; - }else{ + }else { dol_syslog("currency_rate:list:update", LOG_WARNING); } } @@ -350,7 +350,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $page = 0; $offset = 0; } - }else{ + }else { setEventMessage($langs->trans('No_record_on_multicurrency_rate'), 'warnings'); } } @@ -396,7 +396,7 @@ if ($resql) if ($sall) { - foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); + foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); print '
'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'
'; } @@ -538,8 +538,7 @@ if ($resql) print ''; } -else -{ +else { dol_print_error($db); } From 26e3637e22e4594ef50275c6403d1975797f1c36 Mon Sep 17 00:00:00 2001 From: jpb Date: Tue, 27 Oct 2020 09:58:32 +0100 Subject: [PATCH 3/5] remove ['newtoken'] to newtoken() function --- htdocs/multicurrency/multicurrency_rate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/multicurrency/multicurrency_rate.php b/htdocs/multicurrency/multicurrency_rate.php index 64f426b93b2..4a76c721128 100644 --- a/htdocs/multicurrency/multicurrency_rate.php +++ b/htdocs/multicurrency/multicurrency_rate.php @@ -382,7 +382,7 @@ if ($resql) print '
'; if ($optioncss != '') print ''; - print ''; + print ''; print ''; print ''; print ''; From f0baa0f788505266c4befea63955ea4671b370c8 Mon Sep 17 00:00:00 2001 From: jpb Date: Wed, 28 Oct 2020 12:12:29 +0100 Subject: [PATCH 4/5] fix : input type number , getpost type , hook --- htdocs/multicurrency/multicurrency_rate.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htdocs/multicurrency/multicurrency_rate.php b/htdocs/multicurrency/multicurrency_rate.php index 4a76c721128..2340df84ce5 100644 --- a/htdocs/multicurrency/multicurrency_rate.php +++ b/htdocs/multicurrency/multicurrency_rate.php @@ -73,6 +73,8 @@ $object=new CurrencyRate($db); $extrafields = new ExtraFields($db); $form=new Form($db); +$hookmanager->initHooks(array('EditorRatelist', 'globallist')); + if (empty($action)) $action='list'; // List of fields to search into when doing a "search in all" @@ -127,9 +129,9 @@ if ($action == 'update'){ if ( $result > 0){ $currency_static = new MultiCurrency($db); $fk_currency = $currency_static->getIdFromCode($db, $multicurrency_code); - $currencyRate->date_sync = $db->escape(GETPOST('dateinput')); + $currencyRate->date_sync = $db->escape(GETPOST('dateinput', 'alpha')); $currencyRate->fk_multicurrency = $fk_currency; - $currencyRate->rate = $db->escape(GETPOST('rateinput')); + $currencyRate->rate = $db->escape(GETPOST('rateinput', 'int')); $res = $currencyRate->update(); if ($res){ setEventMessage($langs->trans('successUpdateRate')); @@ -174,7 +176,7 @@ if ($action == "confirm_delete"){ if ($result){ setEventMessage($langs->trans('successRateDelete')); }else { - setEventMessage($langs->trans('errorRateDelete')); + setEventMessage($langs->trans('errorRateDelete'), 'errors'); } }else { setEventMessage($langs->trans('NoCurrencyRateSelected'), "warnings"); @@ -249,7 +251,7 @@ if ($action!= "updateRate" && $action!= "deleteRate" ) { print '' . $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ? GETPOST('multicurrency_code', 'alpha') : $multicurrency_code), 'multicurrency_code', 0, " code != '".$conf->currency."'", true) . ''; print ' ' . $langs->trans('rate') . ''; - print ' '; + print ' '; print ''; print ''; From 24df254e927265003ce80284d5305e7cbb306d56 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 31 Oct 2020 13:54:23 +0100 Subject: [PATCH 5/5] Update multicurrency.class.php --- htdocs/multicurrency/class/multicurrency.class.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index a09607ef1c4..2c2691f1ab8 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -866,11 +866,9 @@ class CurrencyRate extends CommonObjectLine // Update request $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; $sql .= ' rate='.$this->rate; - if (!empty($this->date_sync)) - $sql .= ', date_sync=\''.$this->date_sync.'\''; - if (!empty($this->fk_multicurrency)) - $sql .= ', fk_multicurrency='.$this->fk_multicurrency; - $sql .= ' WHERE rowid=' . $this->id; + if (!empty($this->date_sync)) $sql .= ", date_sync='".$this->db->idate($this->date_sync)."'"; + if (!empty($this->fk_multicurrency)) $sql .= ', fk_multicurrency='.$this->fk_multicurrency; + $sql .= ' WHERE rowid='.$this->id; $this->db->begin();