';
diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php
new file mode 100644
index 00000000000..3132423d614
--- /dev/null
+++ b/htdocs/core/class/utils.class.php
@@ -0,0 +1,129 @@
+
+ *
+ * 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
+ * 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 .
+ */
+
+/**
+ * \file htdocs/core/class/utils.class.php
+ * \ingroup core
+ * \brief File for Utils class
+ */
+
+
+/**
+ * Class to manage utility methods
+ */
+class Utils
+{
+ var $db;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ function __construct($db)
+ {
+ $this->db = $db;
+ }
+
+
+ /**
+ * Purge files into directory of data files.
+ *
+ * @param string $choice Choice of purge mode ('tempfiles', 'tempfilesold' to purge temp older than 24h, 'allfiles', 'logfiles')
+ * @return int Nb of files deleted
+ */
+ function purgeFiles($choice='tempfilesold')
+ {
+ global $conf, $dolibarr_main_data_root;
+
+ dol_syslog("Utils::purgeFiles choice=".$choice, LOG_DEBUG);
+ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
+
+ $filesarray=array();
+ if (empty($choice)) $choice='tempfilesold';
+
+ if ($choice=='tempfiles' || $choice=='tempfilesold')
+ {
+ // Delete temporary files
+ if ($dolibarr_main_data_root)
+ {
+ $filesarray=dol_dir_list($dolibarr_main_data_root,"directories",1,'^temp$','','','',2);
+ if ($choice == 'tempfilesold')
+ {
+ $now = dol_now();
+ foreach($filesarray as $key => $val)
+ {
+ if ($val['date'] > ($now - (24 * 3600))) unset($filesarray[$key]); // Discard files not older than 24h
+ }
+ }
+ }
+ }
+
+ if ($choice=='allfiles')
+ {
+ // Delete all files
+ if ($dolibarr_main_data_root)
+ {
+ $filesarray=dol_dir_list($dolibarr_main_data_root,"all",0,'','install\.lock$');
+ }
+ }
+
+ if ($choice=='logfile')
+ {
+ // Define filelog to discard it from purge
+ $filelog='';
+ if (! empty($conf->syslog->enabled))
+ {
+ $filelog=SYSLOG_FILE;
+ $filelog=preg_replace('/DOL_DATA_ROOT/i',DOL_DATA_ROOT,$filelog);
+ }
+
+ $filesarray[]=array('fullname'=>$filelog,'type'=>'file');
+ }
+
+ $count=0;
+ if (count($filesarray))
+ {
+ foreach($filesarray as $key => $value)
+ {
+ //print "x ".$filesarray[$key]['fullname']." \n";
+ if ($filesarray[$key]['type'] == 'dir')
+ {
+ $count+=dol_delete_dir_recursive($filesarray[$key]['fullname']);
+ }
+ elseif ($filesarray[$key]['type'] == 'file')
+ {
+ // If (file that is not logfile) or (if logfile with option logfile)
+ if ($filesarray[$key]['fullname'] != $filelog || $choice=='logfile')
+ {
+ $count+=(dol_delete_file($filesarray[$key]['fullname'])?1:0);
+ }
+ }
+ }
+
+ // Update cachenbofdoc
+ if (! empty($conf->ecm->enabled) && $choice=='allfiles')
+ {
+ require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmdirectory.class.php';
+ $ecmdirstatic = new EcmDirectory($this->db);
+ $result = $ecmdirstatic->refreshcachenboffile(1);
+ }
+ }
+
+ return $count;
+ }
+}
diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php
index cd128cec817..758301c9171 100644
--- a/htdocs/core/lib/tax.lib.php
+++ b/htdocs/core/lib/tax.lib.php
@@ -110,7 +110,7 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
if ($modetax == 1)
{
// If vat paid on due invoices (non draft)
- $sql = "SELECT s.rowid as socid, s.nom as name, s.siren as tva_intra, s.tva_assuj as assuj,";
+ $sql = "SELECT s.rowid as socid, s.nom as name, s.tva_intra as tva_intra, s.tva_assuj as assuj,";
$sql.= " sum(f.$total_ht) as amount, sum(f.".$total_tva.") as tva,";
$sql.= " sum(f.localtax1) as localtax1,";
$sql.= " sum(f.localtax2) as localtax2";
diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php
index 11d904f58d4..06b3bc89860 100644
--- a/htdocs/core/modules/DolibarrModules.class.php
+++ b/htdocs/core/modules/DolibarrModules.class.php
@@ -936,10 +936,11 @@ class DolibarrModules // Can not be abstract, because we need to insta
if (! $err)
{
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, label, jobtype, classesname, objectname, methodename, command, params, note, frequency, unitfrequency, entity)";
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob (module_name, datec, datestart, label, jobtype, classesname, objectname, methodename, command, params, note, frequency, unitfrequency, entity)";
$sql.= " VALUES (";
$sql.= "'".$this->db->escape($this->rights_class)."', ";
$sql.= "'".$this->db->idate($now)."', ";
+ $sql.= "'".$this->db->idate($now)."', ";
$sql.= "'".$this->db->escape($label)."', ";
$sql.= "'".$this->db->escape($jobtype)."', ";
$sql.= ($class?"'".$this->db->escape($class)."'":"null").",";
diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php
index aefb599a9b7..4981eeb0089 100644
--- a/htdocs/core/modules/modCron.class.php
+++ b/htdocs/core/modules/modCron.class.php
@@ -99,6 +99,12 @@ class modCron extends DolibarrModules
$this->rights_class = 'cron';
$r=0;
+ // Cronjobs
+ $this->cronjobs = array(
+ 0=>array('label'=>'PurgeDeleteTemporaryFilesShort', 'jobtype'=>'method', 'class'=>'core/class/utils.class.php', 'objectname'=>'Utils', 'method'=>'purgeFiles', 'parameters'=>'', 'comment'=>'PurgeDeleteTemporaryFiles', 'frequency'=>1, 'unitfrequency'=>3600 * 24 * 7),
+ // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24)
+ );
+
$this->rights[$r][0] = 23001;
$this->rights[$r][1] = 'Read cron jobs';
$this->rights[$r][3] = 1;
diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php
index e91b359ed98..76781d6645e 100644
--- a/htdocs/cron/card.php
+++ b/htdocs/cron/card.php
@@ -1,7 +1,7 @@
- * Copyright (C) 2013-2015 Laurent Destailleur
+ * Copyright (C) 2013-2016 Laurent Destailleur
*
* 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
@@ -539,7 +539,7 @@ else
print '
';
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 13368cbfc06..55eb22f0aee 100755
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -154,6 +154,7 @@ Purge=Purge
PurgeAreaDesc=This page allows you to delete all files built or stored by Dolibarr (temporary files or all files in %s directory). Using this feature is not necessary. It is provided for users whose Dolibarr is hosted by a provider that does not offer permissions to delete files built by the web server.
PurgeDeleteLogFile=Delete log file %s defined for Syslog module (no risk to loose data)
PurgeDeleteTemporaryFiles=Delete all temporary files (no risk to loose data)
+PurgeDeleteTemporaryFilesShort=Delete temporary files
PurgeDeleteAllFilesInDocumentsDir=Delete all files in directory %s. Temporary files but also database backup dumps, files attached to elements (third parties, invoices, ...) and uploaded into the ECM module will be deleted.
PurgeRunNow=Purge now
PurgeNothingToDelete=No directory or file to delete.
diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php
index 542e2980c45..50b8e80e363 100644
--- a/htdocs/webservices/server_thirdparty.php
+++ b/htdocs/webservices/server_thirdparty.php
@@ -685,9 +685,9 @@ function getListOfThirdParties($authentication,$filterthirdparty)
foreach($filterthirdparty as $key => $val)
{
if ($key == 'name' && $val != '') $sql.=" AND s.name LIKE '%".$db->escape($val)."%'";
- if ($key == 'client' && $val != '') $sql.=" AND s.client = ".$db->escape($val);
- if ($key == 'supplier' && $val != '') $sql.=" AND s.fournisseur = ".$db->escape($val);
- if ($key == 'category' && $val != '') $sql.=" AND s.rowid IN (SELECT fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_categorie=".$db->escape($val).") ";
+ if ($key == 'client' && (int) $val > 0) $sql.=" AND s.client = ".$db->escape($val);
+ if ($key == 'supplier' && (int) $val > 0) $sql.=" AND s.fournisseur = ".$db->escape($val);
+ if ($key == 'category' && (int) $val > 0) $sql.=" AND s.rowid IN (SELECT fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe WHERE fk_categorie=".$db->escape($val).") ";
}
dol_syslog("Function: getListOfThirdParties", LOG_DEBUG);