diff --git a/ChangeLog b/ChangeLog index c5ddefd980e..0de3ed5df3a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -280,6 +280,23 @@ Following changes may create regression for some external modules, but were nece content by doing a print into function, sometimes by returning content into "resprint". This has been fixed to follow hook specifications so you must return output into "resprint". + +***** ChangeLog for 5.0.7 compared to 5.0.6 ***** +FIX: #7000 Dashboard link for late pending payment supplier invoices do not work +FIX: #7148 +FIX: #7325 Default VAT rate when editing template invoices is 0% +FIX: #7366 renaming table with pgsql +FIX: #7391 +FIX: #7510 Bug: extrafield content disappear when generate pdf within intervention +FIX: Agenda events are not exported in the ICAL, VCAL if begin exactly with the same $datestart +FIX: Bad link to unpayed suppliers invoices +FIX: bankentries search conciliated if val 0 +FIX: multicompany better accuracy in rounding and with revenue stamp. +FIX: PDF output was sharing 2 different currencies in same total +FIX: Upgrade missing on field +FIX: wrong key in selectarray +FIX: wrong personnal project time spent + ***** ChangeLog for 5.0.6 compared to 5.0.5 ***** FIX: Removed a bad symbolic link into custom directory. FIX: Renaming a resource ref rename also the directory of attached files. diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 52af47a83a5..04ba162cb9e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3119,7 +3119,6 @@ class Commande extends CommonOrder // End call triggers } - //TODO: Check for error after each action. If one failed we rollback, don't waste time to do action if previous fail if (! $error) { // Delete order details @@ -3129,23 +3128,24 @@ class Commande extends CommonOrder $error++; $this->errors[]=$this->db->lasterror(); } + } - // Delete order - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; - if (! $this->db->query($sql) ) - { - $error++; - $this->errors[]=$this->db->lasterror(); - } - + if (! $error) + { // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) $error++; + } + if (! $error) + { // Delete linked contacts $res = $this->delete_linked_contact(); if ($res < 0) $error++; + } + if (! $error) + { // Remove extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { @@ -3156,8 +3156,22 @@ class Commande extends CommonOrder dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); } } + } - // On efface le repertoire de pdf provisoire + if (! $error) + { + // Delete object + $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande WHERE rowid = ".$this->id; + if (! $this->db->query($sql) ) + { + $error++; + $this->errors[]=$this->db->lasterror(); + } + } + + if (! $error) + { + // Remove directory with files $comref = dol_sanitizeFileName($this->ref); if ($conf->commande->dir_output && !empty($this->ref)) { @@ -3183,8 +3197,6 @@ class Commande extends CommonOrder } } } - - } if (! $error) diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 0fc7657f184..8aafef55fba 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -197,8 +197,15 @@ if ($action == 'update') $object->proprio = trim($_POST["proprio"]); $object->owner_address = trim($_POST["owner_address"]); - $account_number = GETPOST('account_number', 'int'); - if ($account_number <= 0) { $object->account_number = ''; } else { $object->account_number = $account_number; } + $account_number = GETPOST('account_number', 'alpha'); + if (empty($account_number) || $account_number == '-1') + { + $object->account_number = ''; + } + else + { + $object->account_number = $account_number; + } $fk_accountancy_journal = GETPOST('fk_accountancy_journal','int'); if ($fk_accountancy_journal <= 0) { $object->fk_accountancy_journal = ''; } else { $object->fk_accountancy_journal = $fk_accountancy_journal; } @@ -213,7 +220,7 @@ if ($action == 'update') if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($object->account_number)) { - setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'error'); + setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("AccountancyCode")), null, 'errors'); $action='edit'; // Force chargement page en mode creation $error++; } diff --git a/htdocs/compta/bank/transfer.php b/htdocs/compta/bank/transfer.php index 7696427b059..3819e2acccb 100644 --- a/htdocs/compta/bank/transfer.php +++ b/htdocs/compta/bank/transfer.php @@ -82,9 +82,12 @@ if ($action == 'add') $accountto=new Account($db); $accountto->fetch(GETPOST('account_to','int')); - if ($accountto->currency_code == $accountfrom->currency_code) { + if ($accountto->currency_code == $accountfrom->currency_code) + { $amountto=$amount; - } else { + } + else + { if (! $amountto) { $error++; diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 1f47a94f6d2..ea5d6c3db26 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -56,7 +56,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') { if ($object->id) { - $urlfile = GETPOST('urlfile', 'alpha'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). + $urlfile = GETPOST('urlfile', 'alpha', 0, null, null, 1); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). if (GETPOST('section', 'alpha')) $file = $upload_dir . "/" . $urlfile; // For a delete of GED module urlfile contains full path from upload_dir else // For documents pages, upload_dir contains already path to file from module dir, so we clean path into urlfile. { diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index dee63987d45..cf5d02a7b31 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -449,4 +449,78 @@ class Utils return 0; } + + + + /** + * Execute a CLI command. + * + * @param string $command Command line to execute. + * @param string $outputfile Output file (used only when method is 2). For exemple $conf->admin->dir_temp.'/out.tmp'; + * @param int $execmethod 0=Use default method (that is 1 by default), 1=Use the PHP 'exec', 2=Use the 'popen' method + * @return array array('result'=>...,'output'=>...,'error'=>...). result = 0 means OK. + */ + function executeCLI($command, $outputfile, $execmethod=0) + { + global $conf, $langs; + + $result = 0; + $output = ''; + $error = ''; + + $command=escapeshellcmd($command); + $command.=" 2>&1"; + + if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN; + if (empty($execmethod)) $execmethod=1; + //$execmethod=1; + + dol_syslog("Utils::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG); + $output_arr=array(); + + if ($execmethod == 1) + { + exec($command, $output_arr, $retval); + $result = $retval; + if ($retval != 0) + { + $langs->load("errors"); + dol_syslog("Utils::executeCLI retval after exec=".$retval, LOG_ERR); + $error = 'Error '.$retval; + } + } + if ($execmethod == 2) // With this method, there is no way to get the return code, only output + { + $ok=0; + $handle = fopen($outputfile, 'w+b'); + if ($handle) + { + dol_syslog("Utils::executeCLI run command ".$command); + $handlein = popen($command, 'r'); + while (!feof($handlein)) + { + $read = fgets($handlein); + fwrite($handle,$read); + $output_arr[]=$read; + } + pclose($handlein); + fclose($handle); + } + if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); + } + + // Update with result + if (is_array($output_arr) && count($output_arr)>0) + { + foreach($output_arr as $val) + { + $output.=$val.($execmethod == 2 ? '' : "\n"); + } + } + + dol_syslog("Utils::executeCLI result=".$result." output=".$output." error=".$error, LOG_DEBUG); + + return array('result'=>$result, 'output'=>$output, 'error'=>$error); + } + } diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 0c133a85769..6fd7beb86bb 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1052,7 +1052,11 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable $file_name_osencoded=dol_osencode($file_name); // Check if destination dir is writable - // TODO + if (! is_writable(dirname($file_name_osencoded))) + { + dol_syslog("Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded)." is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING); + return 'ErrorDirNotWritable'; + } // Check if destination file already exists if (! $allowoverwrite) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 986d48b37e1..7660b198313 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -270,10 +270,11 @@ function GETPOSTISSET($paramname) * 'custom'= custom filter specify $filter and $options) * @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get, 4 = post then get then cookie) * @param int $filter Filter to apply when $check is set to 'custom'. (See http://php.net/manual/en/filter.filters.php for détails) - * @param mixed $options Options to pass to filter_var when $check is set to 'custom'. + * @param mixed $options Options to pass to filter_var when $check is set to 'custom' + * @param string $noreplace Force disable of replacement of __xxx__ strings. * @return string|string[] Value found (string or array), or '' if check fails */ -function GETPOST($paramname, $check='alpha', $method=0, $filter=NULL, $options=NULL) +function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0) { global $mysoc,$user,$conf; @@ -467,7 +468,7 @@ function GETPOST($paramname, $check='alpha', $method=0, $filter=NULL, $options=N // Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters) // Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ... // We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text. - if (! is_array($out) && empty($_POST[$paramname])) + if (! is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) { $maxloop=20; $loopnb=0; // Protection against infinite loop while (preg_match('/__([A-Z0-9]+_?[A-Z0-9]+)__/i', $out, $reg) && ($loopnb < $maxloop)) // Detect '__ABCDEF__' as key 'ABCDEF' and '__ABC_DEF__' as key 'ABC_DEF'. Detection is also correct when 2 vars are side by side. @@ -3650,7 +3651,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $return.= "\n"; $return.= '
| '.img_picto('',$picto, 'class="valignmiddle" id="pictotitle"', $pictoisfullpath).' | '; + if ($picto) $return.= ''.img_picto('',$picto, 'class="valignmiddle widthpictotitle" id="pictotitle"', $pictoisfullpath).' | '; $return.= '';
$return.= ' '.$titre.' ';
$return.= ' | ';
diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php
index c9d195214db..88494be7e04 100644
--- a/htdocs/cron/class/cronjob.class.php
+++ b/htdocs/cron/class/cronjob.class.php
@@ -1060,7 +1060,14 @@ class Cronjob extends CommonObject
$outputfile=$outputdir.'/cronjob.'.$userlogin.'.out'; // File used with popen method
// Execute a CLI
- $retval = $this->executeCLI($this->command, $outputfile);
+ include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
+ $utils = new Utils($db);
+ $arrayresult = $utils->executeCLI($this->command, $outputfile);
+
+ $retval = $arrayresult['result'];
+ $this->error = $arrayresult['error'];
+ $this->lastoutput = $arrayresult['output'];
+ $this->lastresult = $arrayresult['result'];
}
}
@@ -1082,81 +1089,6 @@ class Cronjob extends CommonObject
}
- /**
- * Execute a CLI command.
- * this->error, this->lastoutput, this->lastresult are also set.
- *
- * @param string $command Command line
- * @param string $outputfile Output file
- * @param int $execmethod 0=Use default method, 1=Use the PHP 'exec', 2=Use the 'popen' method
- * @return int Retval
- */
- function executeCLI($command, $outputfile, $execmethod=0)
- {
- global $conf, $langs;
-
- $retval = 0;
-
- $command=escapeshellcmd($command);
- $command.=" 2>&1";
-
- if (! empty($conf->global->MAIN_EXEC_USE_POPEN)) $execmethod=$conf->global->MAIN_EXEC_USE_POPEN;
- if (empty($execmethod)) $execmethod=1;
- //$execmethod=1;
-
- dol_syslog(get_class($this)."::executeCLI execmethod=".$execmethod." system:".$command, LOG_DEBUG);
- $output_arr=array();
-
- if ($execmethod == 1)
- {
- exec($command, $output_arr, $retval);
- if ($retval != 0)
- {
- $langs->load("errors");
- dol_syslog(get_class($this)."::executeCLI retval after exec=".$retval, LOG_ERR);
- $this->error = 'Error '.$retval;
- $this->lastoutput = ''; // Will be filled later from $output_arr
- $this->lastresult = $retval;
- $retval = $this->lastresult;
- }
- }
- if ($execmethod == 2) // With this method, there is no way to get the return code, only output
- {
- $ok=0;
- $handle = fopen($outputfile, 'w+b');
- if ($handle)
- {
- dol_syslog(get_class($this)."::executeCLI run command ".$command);
- $handlein = popen($command, 'r');
- while (!feof($handlein))
- {
- $read = fgets($handlein);
- fwrite($handle,$read);
- $output_arr[]=$read;
- }
- pclose($handlein);
- fclose($handle);
- }
- if (! empty($conf->global->MAIN_UMASK)) @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
- }
-
- // Update with result
- if (is_array($output_arr) && count($output_arr)>0)
- {
- foreach($output_arr as $val)
- {
- $this->lastoutput.=$val.($execmethod == 2 ? '' : "\n");
- }
- }
-
- $this->lastresult=$retval;
-
- dol_syslog(get_class($this)."::executeCLI output_arr:".var_export($output_arr,true)." lastoutput=".$this->lastoutput." lastresult=".$this->lastresult, LOG_DEBUG);
-
- return $retval;
- }
-
-
/**
* Reprogram a job
*
diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php
index 25cf644db0f..237d09570d1 100644
--- a/htdocs/fichinter/class/fichinter.class.php
+++ b/htdocs/fichinter/class/fichinter.class.php
@@ -840,85 +840,96 @@ class Fichinter extends CommonObject
$this->db->begin();
+ if (! $error && ! $notrigger)
+ {
+ // Call trigger
+ $result=$this->call_trigger('FICHINTER_DELETE',$user);
+ if ($result < 0) { $error++; $this->db->rollback(); return -1; }
+ // End call triggers
+ }
+
// Delete linked object
- $res = $this->deleteObjectLinked();
- if ($res < 0) $error++;
+ if (! $error)
+ {
+ $res = $this->deleteObjectLinked();
+ if ($res < 0) $error++;
+ }
// Delete linked contacts
- $res = $this->delete_linked_contact();
- if ($res < 0)
+ if (! $error)
{
- $this->error='ErrorFailToDeleteLinkedContact';
- $error++;
+ $res = $this->delete_linked_contact();
+ if ($res < 0)
+ {
+ $this->error='ErrorFailToDeleteLinkedContact';
+ $error++;
+ }
}
- if ($error)
+ if (! $error)
{
- $this->db->rollback();
- return -1;
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
+ $sql.= " WHERE fk_fichinter = ".$this->id;
+
+ $resql = $this->db->query($sql);
+ if (! $resql) $error++;
}
- $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet";
- $sql.= " WHERE fk_fichinter = ".$this->id;
-
- dol_syslog("Fichinter::delete", LOG_DEBUG);
- if ( $this->db->query($sql) )
+ if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
+ // Remove extrafields
+ $res = $this->deleteExtraFields();
+ if ($res < 0) $error++;
+ }
+
+ if (! $error)
+ {
+ // Delete object
$sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
dol_syslog("Fichinter::delete", LOG_DEBUG);
- if ( $this->db->query($sql) )
+ $resql = $this->db->query($sql);
+ if (! $resql) $error++;
+ }
+
+ if (! $error)
+ {
+ // Remove directory with files
+ $fichinterref = dol_sanitizeFileName($this->ref);
+ if ($conf->ficheinter->dir_output)
{
-
- // Remove directory with files
- $fichinterref = dol_sanitizeFileName($this->ref);
- if ($conf->ficheinter->dir_output)
+ $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
+ $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
+ if (file_exists($file))
{
- $dir = $conf->ficheinter->dir_output . "/" . $fichinterref ;
- $file = $conf->ficheinter->dir_output . "/" . $fichinterref . "/" . $fichinterref . ".pdf";
- if (file_exists($file))
- {
- dol_delete_preview($this);
+ dol_delete_preview($this);
- if (! dol_delete_file($file,0,0,0,$this)) // For triggers
- {
- $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
- return 0;
- }
- }
- if (file_exists($dir))
+ if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
- if (! dol_delete_dir_recursive($dir))
- {
- $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
- return 0;
- }
+ $this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
+ return 0;
}
}
-
- if (! $notrigger)
+ if (file_exists($dir))
{
- // Call trigger
- $result=$this->call_trigger('FICHINTER_DELETE',$user);
- if ($result < 0) { $error++; $this->db->rollback(); return -1; }
- // End call triggers
+ if (! dol_delete_dir_recursive($dir))
+ {
+ $this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
+ return 0;
+ }
}
+ }
+ }
- $this->db->commit();
- return 1;
- }
- else
- {
- $this->error=$this->db->lasterror();
- $this->db->rollback();
- return -2;
- }
+ if (! $error)
+ {
+ $this->db->commit();
+ return 1;
}
else
{
- $this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
diff --git a/htdocs/product/list.php b/htdocs/product/list.php
index 837f7f291e3..31cf38cfe9a 100644
--- a/htdocs/product/list.php
+++ b/htdocs/product/list.php
@@ -251,7 +251,7 @@ else
if ($search_type != '' && $search_type != '-1')
{
- if ($search_type==1)
+ if ($search_type == 1)
{
$texte = $langs->trans("Services");
}
diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php
index df36ffabd28..d1c39e4358b 100644
--- a/test/phpunit/AllTests.php
+++ b/test/phpunit/AllTests.php
@@ -85,6 +85,8 @@ class AllTests
$suite->addTestSuite('CompanyLibTest');
require_once dirname(__FILE__).'/DateLibTest.php';
$suite->addTestSuite('DateLibTest');
+ require_once dirname(__FILE__).'/UtilsTest.php';
+ $suite->addTestSuite('UtilsTest');
//require_once dirname(__FILE__).'/DateLibTzFranceTest.php';
//$suite->addTestSuite('DateLibTzFranceTest');
require_once dirname(__FILE__).'/MarginsLibTest.php';
diff --git a/test/phpunit/UtilsTest.php b/test/phpunit/UtilsTest.php
new file mode 100644
index 00000000000..b80ce84f624
--- /dev/null
+++ b/test/phpunit/UtilsTest.php
@@ -0,0 +1,152 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see