From a03bb00254b979b9027092b7b0f1585d51efbb16 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Fri, 19 Jul 2019 11:26:21 +0200 Subject: [PATCH 01/15] Fix missing hook --- htdocs/compta/prelevement/card.php | 138 +++++++++++++++-------------- 1 file changed, 73 insertions(+), 65 deletions(-) diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 60e471d712db2..d6c752330fee7 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -63,78 +63,86 @@ // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals +$hookmanager->initHooks(array('directdebitprevcard','globalcard')); /* * Actions */ -if ( $action == 'confirm_delete' ) -{ - $res=$object->delete($user); - if ($res > 0) - { - header("Location: index.php"); - exit; - } -} - -// Seems to no be used and replaced with $action == 'infocredit -if ( $action == 'confirm_credite' && GETPOST('confirm','alpha') == 'yes') -{ - $res=$object->set_credite(); - if ($res >= 0) - { - header("Location: card.php?id=".$id); - exit; - } -} - -if ($action == 'infotrans' && $user->rights->prelevement->bons->send) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int')); - - /* - if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref) - { - $dir = $conf->prelevement->dir_output.'/receipts'; - - if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0) - { - $object->set_infotrans($user, $dt, GETPOST('methode','alpha')); - } - - header("Location: card.php?id=".$id); - exit; - } - else - { - dol_syslog("Fichier invalide",LOG_WARNING); - $mesg='BadFile'; - }*/ - - $error = $object->set_infotrans($user, $dt, GETPOST('methode','alpha')); +$parameters = array('socid' => $socid); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - if ($error) - { - header("Location: card.php?id=".$id."&error=$error"); - exit; - } -} - -// Set direct debit order to credited, create payment and close invoices -if ($action == 'infocredit' && $user->rights->prelevement->bons->credit) +if (empty($reshook)) { - $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int')); - - $error = $object->set_infocredit($user, $dt); - - if ($error) - { - header("Location: card.php?id=".$id."&error=$error"); - exit; - } + if ( $action == 'confirm_delete' ) + { + $res=$object->delete($user); + if ($res > 0) + { + header("Location: index.php"); + exit; + } + } + + // Seems to no be used and replaced with $action == 'infocredit + if ( $action == 'confirm_credite' && GETPOST('confirm','alpha') == 'yes') + { + $res=$object->set_credite(); + if ($res >= 0) + { + header("Location: card.php?id=".$id); + exit; + } + } + + if ($action == 'infotrans' && $user->rights->prelevement->bons->send) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int')); + + /* + if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref) + { + $dir = $conf->prelevement->dir_output.'/receipts'; + + if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0) + { + $object->set_infotrans($user, $dt, GETPOST('methode','alpha')); + } + + header("Location: card.php?id=".$id); + exit; + } + else + { + dol_syslog("Fichier invalide",LOG_WARNING); + $mesg='BadFile'; + }*/ + + $error = $object->set_infotrans($user, $dt, GETPOST('methode','alpha')); + + if ($error) + { + header("Location: card.php?id=".$id."&error=$error"); + exit; + } + } + + // Set direct debit order to credited, create payment and close invoices + if ($action == 'infocredit' && $user->rights->prelevement->bons->credit) + { + $dt = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int')); + + $error = $object->set_infocredit($user, $dt); + + if ($error) + { + header("Location: card.php?id=".$id."&error=$error"); + exit; + } + } } From b100cdb9db97e20eb2b5a9a13951eb9e74c64902 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Fri, 19 Jul 2019 11:58:21 +0200 Subject: [PATCH 02/15] FIX: extrafield loading bug due to assumption that an object is a third party while it may be a contact if MAIN_USE_COMPANY_NAME_OF_CONTACT is set. --- .../expedition/doc/doc_generic_shipment_odt.modules.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php b/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php index 9c45c135ac346..a1be784f249fe 100644 --- a/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php +++ b/htdocs/core/modules/expedition/doc/doc_generic_shipment_odt.modules.php @@ -393,7 +393,11 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede } } // Make substitutions into odt of thirdparty - $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); + if ($socobject->element == 'contact') { + $tmparray = $this->get_substitutionarray_contact($socobject, $outputlangs); + } else { + $tmparray = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); + } foreach($tmparray as $key=>$value) { try { From cd7d3f1a368a4d2c84906c3ba1110961a72cdc3e Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 19 Jul 2019 15:41:44 +0200 Subject: [PATCH 03/15] FIX : search by phone pro --- htdocs/contact/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 5aacbc2f16f46..f786e73d17a6d 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -290,7 +290,7 @@ if ($search_societe) $sql.= natural_search('s.nom', $search_societe); if (strlen($search_poste)) $sql.= natural_search('p.poste', $search_poste); if (strlen($search_phone_perso)) $sql.= natural_search('p.phone_perso', $search_phone_perso); -if (strlen($search_phone_pro)) $sql.= natural_search('p.phone', $search_phone); +if (strlen($search_phone_pro)) $sql.= natural_search('p.phone', $search_phone_pro); if (strlen($search_phone_mobile)) $sql.= natural_search('p.phone_mobile', $search_phone_mobile); if (strlen($search_fax)) $sql.= natural_search('p.fax', $search_fax); if (strlen($search_skype)) $sql.= natural_search('p.skype', $search_skype); From d88fec52bfd8bff0196a1d32a1ffc5f2349afd48 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Sat, 20 Jul 2019 15:07:59 +0200 Subject: [PATCH 04/15] fix warining message --- htdocs/comm/action/peruser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 9e2a7278a279d..65669625398c8 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -1189,8 +1189,8 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & } $ids1='';$ids2=''; - if (count($cases1[$h]) && array_keys($cases1[$h])) $ids1=join(',',array_keys($cases1[$h])); - if (count($cases2[$h]) && array_keys($cases2[$h])) $ids2=join(',',array_keys($cases2[$h])); + if (is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) $ids1=join(',',array_keys($cases1[$h])); + if (is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) $ids2=join(',',array_keys($cases2[$h])); if ($h == $begin_h) echo ''; else echo ''; From d03d79222e9ecfd239a49566dd8695ceac5841c3 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Sat, 20 Jul 2019 15:15:48 +0200 Subject: [PATCH 05/15] fix warning php --- htdocs/comm/action/peruser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 65669625398c8..7dfe197033e83 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -1207,14 +1207,14 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & $color1='222222'; } - if (count($cases2[$h]) == 1) // only 1 event + if (is_array($cases2[$h]) && count($cases2[$h]) == 1) // only 1 event { $output = array_slice($cases2[$h], 0, 1); $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:''); if ($output[0]['string']) $title2.=($title2?' - ':'').$output[0]['string']; if ($output[0]['color']) $color2 = $output[0]['color']; } - else if (count($cases2[$h]) > 1) + else if (is_array($cases2[$h]) && count($cases2[$h]) > 1) { $title2=$langs->trans("Ref").' '.$ids2.($title2?' - '.$title2:''); $color2='222222'; From b046bcc197a0b8d0b800c1153ace0e76de4e988f Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Sat, 20 Jul 2019 15:19:25 +0200 Subject: [PATCH 06/15] fix warning php --- htdocs/comm/action/peruser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 7dfe197033e83..16d9f09947cd0 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -1194,14 +1194,14 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & if ($h == $begin_h) echo ''; else echo ''; - if (count($cases1[$h]) == 1) // only 1 event + if (is_array($cases1[$h]) && count($cases1[$h]) == 1) // only 1 event { $output = array_slice($cases1[$h], 0, 1); $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:''); if ($output[0]['string']) $title1.=($title1?' - ':'').$output[0]['string']; if ($output[0]['color']) $color1 = $output[0]['color']; } - else if (count($cases1[$h]) > 1) + else if (is_array($cases1[$h]) && count($cases1[$h]) > 1) { $title1=$langs->trans("Ref").' '.$ids1.($title1?' - '.$title1:''); $color1='222222'; From 7ec8b48b180a9f7c1bb27bb6ca9c8a4c39e3175d Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sun, 21 Jul 2019 22:21:11 +0200 Subject: [PATCH 07/15] Fix lost filter in action list --- htdocs/comm/action/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index aae2d48e9cf38..10f3048c2f6a7 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -43,7 +43,7 @@ $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'actioncommlist'; // To manage different context of search $resourceid=GETPOST("search_resourceid","int")?GETPOST("search_resourceid","int"):GETPOST("resourceid","int"); $pid=GETPOST("search_projectid",'int',3)?GETPOST("search_projectid",'int',3):GETPOST("projectid",'int',3); -$status=GETPOST("search_status",'alpha')?GETPOST("search_status",'alpha'):GETPOST("status",'alpha'); +$status=(GETPOST("search_status",'alpha') != '')?GETPOST("search_status",'alpha'):GETPOST("status",'alpha'); $type=GETPOST('search_type','alphanohtml')?GETPOST('search_type','alphanohtml'):GETPOST('type','alphanohtml'); $optioncss = GETPOST('optioncss','alpha'); $year=GETPOST("year",'int'); From 6409cc06ae8d3827610497c8bda26b6671482080 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 22 Jul 2019 11:42:25 +0200 Subject: [PATCH 08/15] FIX duplicate on the check (TODO field $onetrtd not used ?) --- htdocs/core/class/commonobject.class.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 7cf3273b818c5..b2826737d0dc8 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6289,7 +6289,7 @@ function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyp * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan) * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) - * @param string $onetrtd All fields in same tr td + * @param string $onetrtd All fields in same tr td (TODO field not used ?) * @return string */ function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) @@ -6386,10 +6386,7 @@ function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $out .= ''; - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) - { - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } - } + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; } if ($action == 'selectlines') { $colspan++; } From 0a1f4b793172dd29bc83256a72198ec1995ac885 Mon Sep 17 00:00:00 2001 From: atm-josselin Date: Tue, 23 Jul 2019 09:45:17 +0200 Subject: [PATCH 09/15] FIX : correct error in files with multiple spaces --- htdocs/core/lib/files.lib.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index fa1a5e50a5067..ed1695731174c 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1540,6 +1540,11 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio $info = pathinfo($destfile); $destfile = dol_sanitizeFileName($info['filename'].'.'.strtolower($info['extension'])); + // We apply dol_string_nohtmltag also to clean file names (this remove duplicate spaces) because + // this function is also applied when we make try to download file (by the GETPOST(filename, 'alphanohtml') call). + $destfile = dol_string_nohtmltag($destfile); + $destfull = dol_string_nohtmltag($destfull); + $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); if (is_numeric($resupload) && $resupload > 0) // $resupload can be 'ErrorFileAlreadyExists' From 2162f2331dfecef69fb344c629d222d0fa73a241 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 24 Jul 2019 06:57:42 +0200 Subject: [PATCH 10/15] Try to fix travis --- htdocs/accountancy/class/bookkeeping.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 21e43b524d75f..0034723ec4c02 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1701,22 +1701,22 @@ public function transformTransaction($direction=0,$piece_num='') if ($next_piecenum < 0) { $error++; } - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.' (doc_date, doc_type,'; + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . ' (doc_date, doc_type,'; $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num, date_creation)'; $sql .= ' SELECT doc_date, doc_type,'; $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; - $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.$next_piecenum.', "'.$this->db->idate($now).'"'; - $sql .= ' FROM '.MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, ' . $next_piecenum . ', "' . $this->db->idate($now) . '"'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $piece_num; $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $piece_num; $resql = $this->db->query($sql); if (! $resql) { $error ++; @@ -1724,14 +1724,14 @@ public function transformTransaction($direction=0,$piece_num='') dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } elseif ($direction==1) { - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $piece_num; $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.'_tmp (doc_date, doc_type,'; + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '_tmp (doc_date, doc_type,'; $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)'; @@ -1739,14 +1739,14 @@ public function transformTransaction($direction=0,$piece_num='') $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num'; - $sql .= ' FROM '.MAIN_DB_PREFIX . $this->table_element.' WHERE piece_num = '.$piece_num; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element.' WHERE piece_num = ' . $piece_num; $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $piece_num; $resql = $this->db->query($sql); if (! $resql) { $error ++; From 65e9d8f239048afcfea1d73a96917363090e245f Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Thu, 25 Jul 2019 11:14:59 +0200 Subject: [PATCH 11/15] FIX: tk9877 - PDF rouget requires product.lib.php (otherwise measuring_units_string() is not defined) --- htdocs/core/modules/expedition/doc/pdf_rouget.modules.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index fc242e47e527a..087b4a373aa7d 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; /** From 6e3fad8f8380e2c722b7c8e73d740f54f2ee7aba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 25 Jul 2019 17:42:44 +0200 Subject: [PATCH 12/15] Fix phpcs --- .../accountancy/class/bookkeeping.class.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 0034723ec4c02..faad238d7e43e 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -324,8 +324,8 @@ public function create(User $user, $notrigger = false) $sql .= ", piece_num"; $sql .= ', entity'; $sql .= ") VALUES ("; - $sql .= "'" . $this->db->idate($this->doc_date) . "'"; - $sql .= ", ".(! isset($this->date_lim_reglement) || dol_strlen($this->date_lim_reglement) == 0 ? 'NULL' : "'" . $this->db->idate($this->date_lim_reglement) . "'"); + $sql .= "'".$this->db->idate($this->doc_date)."'"; + $sql .= ", ".(! isset($this->date_lim_reglement) || dol_strlen($this->date_lim_reglement) == 0 ? 'NULL' : "'".$this->db->idate($this->date_lim_reglement)."'"); $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; $sql .= "," . $this->fk_doc; @@ -341,7 +341,7 @@ public function create(User $user, $notrigger = false) $sql .= "," . $this->montant; $sql .= ",'" . $this->db->escape($this->sens) . "'"; $sql .= ",'" . $this->db->escape($this->fk_user_author) . "'"; - $sql .= ",'" . $this->db->idate($now). "'"; + $sql .= ",'".$this->db->idate($now)."'"; $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; $sql .= ",'" . $this->db->escape($this->journal_label) . "'"; $sql .= "," . $this->db->escape($this->piece_num); @@ -573,7 +573,7 @@ public function createStd(User $user, $notrigger = false, $mode='') $sql .= 'piece_num,'; $sql .= 'entity'; $sql .= ') VALUES ('; - $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; + $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'".$this->db->idate($this->doc_date)."'") . ','; $sql .= ' ' . (! isset($this->date_lim_reglement) || dol_strlen($this->date_lim_reglement) == 0 ? 'NULL' : "'" . $this->db->idate($this->date_lim_reglement) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; @@ -590,7 +590,7 @@ public function createStd(User $user, $notrigger = false, $mode='') $sql .= ' ' . (! isset($this->montant) ? 'NULL' : $this->montant ). ','; $sql .= ' ' . (! isset($this->sens) ? 'NULL' : "'" . $this->db->escape($this->sens) . "'") . ','; $sql .= ' ' . $user->id . ','; - $sql .= ' ' . "'" . $this->db->idate($now) . "',"; + $sql .= ' ' . "'".$this->db->idate($now)."',"; $sql .= ' ' . (empty($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (empty($this->journal_label) ? 'NULL' : "'" . $this->db->escape($this->journal_label) . "'") . ','; $sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->db->escape($this->piece_num)).','; @@ -1163,7 +1163,7 @@ public function update(User $user, $notrigger = false, $mode='') // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . $mode.' SET'; - $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ','; + $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'".$this->db->idate($this->doc_date)."'" : 'null') . ','; $sql .= ' doc_type = ' . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ','; $sql .= ' doc_ref = ' . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ','; $sql .= ' fk_doc = ' . (isset($this->fk_doc) ? $this->fk_doc : "null") . ','; @@ -1687,7 +1687,7 @@ function export_bookkeping($model = 'ebp') * @param string $piece_num Piece num * @return int int <0 if KO, >0 if OK */ - public function transformTransaction($direction=0,$piece_num='') + public function transformTransaction($direction = 0, $piece_num = '') { $error = 0; @@ -1708,15 +1708,15 @@ public function transformTransaction($direction=0,$piece_num='') $sql .= ' SELECT doc_date, doc_type,'; $sql .= ' doc_ref, fk_doc, fk_docdet, entity, thirdparty_code, subledger_account, subledger_label,'; $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; - $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, ' . $next_piecenum . ', "' . $this->db->idate($now) . '"'; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $piece_num; + $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, ' . $next_piecenum . ", '".$this->db->idate($now)."'"; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $this->db->escape($piece_num); $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $piece_num; + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . '_tmp WHERE piece_num = ' . $this->db->escape($piece_num); $resql = $this->db->query($sql); if (! $resql) { $error ++; From e92c6c87a0f20fda7690480d465c968fc469abf0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jul 2019 13:16:49 +0200 Subject: [PATCH 13/15] FIX API return 404 sometimes even if API exists --- htdocs/api/index.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index e55a30304a465..6788b208a2e91 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -88,17 +88,22 @@ // index.php/xxx called by any REST client to run API +$reg=array(); preg_match('/index\.php\/([^\/]+)(.*)$/', $_SERVER["PHP_SELF"], $reg); // .../index.php/categories?sortfield=t.rowid&sortorder=ASC // Set the flag to say to refresh (when we reload the explorer, production must be for API call only) -$refreshcache=false; +/*$refreshcache=false; if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) { $refreshcache=true; -} - +}*/ +// When in production mode, a file api/temp/routes.php is created with the API available of current call. +// But, if we set $refreshcache to false, so it may have only one API in the routes.php file if we make a call for one API without +// using the explorer. And when we make another call for another API, the API is not into the api/temp/routes.php and a 404 is returned. +// So we force refresh to each call. +$refreshcache=true; $api = new DolibarrApi($db, '', $refreshcache); //var_dump($api->r->apiVersionMap); @@ -115,7 +120,7 @@ -// Call Explorer file for all APIs definitions +// Call Explorer file for all APIs definitions (this part is slow) if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) { // Scan all API files to load them @@ -253,5 +258,6 @@ //var_dump($api->r->apiVersionMap); //exit; -// Call API (we suppose we found it) +// Call API (we suppose we found it). +// The handle will use the file api/temp/routes.php to get data to run the API. If the file exists and the entry for API is not found, it will return 404. $api->r->handle(); From 8b81702dd7805d31a46f3a55ac6942de41bc5161 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jul 2019 13:23:42 +0200 Subject: [PATCH 14/15] Fix API 404 errors --- htdocs/api/index.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 6788b208a2e91..38050592a3737 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -93,17 +93,15 @@ // .../index.php/categories?sortfield=t.rowid&sortorder=ASC -// Set the flag to say to refresh (when we reload the explorer, production must be for API call only) -/*$refreshcache=false; +// When in production mode, a file api/temp/routes.php is created with the API available of current call. +// But, if we set $refreshcache to false, so it may have only one API in the routes.php file if we make a call for one API without +// using the explorer. And when we make another call for another API, the API is not into the api/temp/routes.php and a 404 is returned. +// So we force refresh to each call. +$refreshcache=(empty($conf->global->API_PRODUCTION_DO_NOT_ALWAYS_REFRESH_CACHE) ? true : false); if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/swagger.json' || $reg[2] == '/swagger.json/root' || $reg[2] == '/resources.json' || $reg[2] == '/resources.json/root')) { $refreshcache=true; -}*/ -// When in production mode, a file api/temp/routes.php is created with the API available of current call. -// But, if we set $refreshcache to false, so it may have only one API in the routes.php file if we make a call for one API without -// using the explorer. And when we make another call for another API, the API is not into the api/temp/routes.php and a 404 is returned. -// So we force refresh to each call. -$refreshcache=true; +} $api = new DolibarrApi($db, '', $refreshcache); //var_dump($api->r->apiVersionMap); From 471a947e8abe8789fc49da2ed99c679cedd4349d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jul 2019 16:30:16 +0200 Subject: [PATCH 15/15] FIX Attachment was lost when we validate an expense report Conflicts: htdocs/expensereport/class/expensereport.class.php --- htdocs/expensereport/class/expensereport.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index dd2818f28bf86..aec06b7972b39 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1120,11 +1120,10 @@ function setValidate($fuser, $notrigger=0) $resql=$this->db->query($sql); if ($resql) { - if (!$notrigger) + if (! $error && ! $notrigger) { // Call trigger - $result=$this->call_trigger('EXPENSE_REPORT_VALIDATE',$fuser); - + $result=$this->call_trigger('EXPENSE_REPORT_VALIDATE', $fuser); if ($result < 0) { $error++; } @@ -1148,7 +1147,7 @@ function setValidate($fuser, $notrigger=0) $dirdest = $conf->expensereport->dir_output.'/'.$newref; if (file_exists($dirsource)) { - dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); + dol_syslog(get_class($this)."::setValidate() rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) {