New: Add option to clean orphelins files into repair page

This commit is contained in:
Laurent Destailleur 2012-02-08 16:41:06 +01:00
parent 7f081ae7ef
commit 186258410e
9 changed files with 196 additions and 66 deletions

View File

@ -134,16 +134,16 @@ class Propal extends CommonObject
$this->duree_validite=$conf->global->PROPALE_VALIDITY_DURATION; $this->duree_validite=$conf->global->PROPALE_VALIDITY_DURATION;
$langs->load("propal"); $langs->load("propal");
$this->labelstatut[0]=($conf->global->PROPAL_STATUS_DRAFT_LABEL ? $conf->global->PROPAL_STATUS_DRAFT_LABEL : $langs->trans("PropalStatusDraft")); $this->labelstatut[0]=(! empty($conf->global->PROPAL_STATUS_DRAFT_LABEL) ? $conf->global->PROPAL_STATUS_DRAFT_LABEL : $langs->trans("PropalStatusDraft"));
$this->labelstatut[1]=($conf->global->PROPAL_STATUS_VALIDATED_LABEL ? $conf->global->PROPAL_STATUS_VALIDATED_LABEL : $langs->trans("PropalStatusValidated")); $this->labelstatut[1]=(! empty($conf->global->PROPAL_STATUS_VALIDATED_LABEL) ? $conf->global->PROPAL_STATUS_VALIDATED_LABEL : $langs->trans("PropalStatusValidated"));
$this->labelstatut[2]=($conf->global->PROPAL_STATUS_SIGNED_LABEL ? $conf->global->PROPAL_STATUS_SIGNED_LABEL : $langs->trans("PropalStatusSigned")); $this->labelstatut[2]=(! empty($conf->global->PROPAL_STATUS_SIGNED_LABEL) ? $conf->global->PROPAL_STATUS_SIGNED_LABEL : $langs->trans("PropalStatusSigned"));
$this->labelstatut[3]=($conf->global->PROPAL_STATUS_NOTSIGNED_LABEL ? $conf->global->PROPAL_STATUS_NOTSIGNED_LABEL : $langs->trans("PropalStatusNotSigned")); $this->labelstatut[3]=(! empty($conf->global->PROPAL_STATUS_NOTSIGNED_LABEL) ? $conf->global->PROPAL_STATUS_NOTSIGNED_LABEL : $langs->trans("PropalStatusNotSigned"));
$this->labelstatut[4]=($conf->global->PROPAL_STATUS_BILLED_LABEL ? $conf->global->PROPAL_STATUS_BILLED_LABEL : $langs->trans("PropalStatusBilled")); $this->labelstatut[4]=(! empty($conf->global->PROPAL_STATUS_BILLED_LABEL) ? $conf->global->PROPAL_STATUS_BILLED_LABEL : $langs->trans("PropalStatusBilled"));
$this->labelstatut_short[0]=($conf->global->PROPAL_STATUS_DRAFTSHORT_LABEL ? $conf->global->PROPAL_STATUS_DRAFTSHORT_LABEL : $langs->trans("PropalStatusDraftShort")); $this->labelstatut_short[0]=(! empty($conf->global->PROPAL_STATUS_DRAFTSHORT_LABEL) ? $conf->global->PROPAL_STATUS_DRAFTSHORT_LABEL : $langs->trans("PropalStatusDraftShort"));
$this->labelstatut_short[1]=($conf->global->PROPAL_STATUS_VALIDATEDSHORT_LABEL ? $conf->global->PROPAL_STATUS_VALIDATEDSHORT_LABEL : $langs->trans("Opened")); $this->labelstatut_short[1]=(! empty($conf->global->PROPAL_STATUS_VALIDATEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_VALIDATEDSHORT_LABEL : $langs->trans("Opened"));
$this->labelstatut_short[2]=($conf->global->PROPAL_STATUS_SIGNEDSHORT_LABEL ? $conf->global->PROPAL_STATUS_SIGNEDSHORT_LABEL : $langs->trans("PropalStatusSignedShort")); $this->labelstatut_short[2]=(! empty($conf->global->PROPAL_STATUS_SIGNEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_SIGNEDSHORT_LABEL : $langs->trans("PropalStatusSignedShort"));
$this->labelstatut_short[3]=($conf->global->PROPAL_STATUS_NOTSIGNEDSHORT_LABEL ? $conf->global->PROPAL_STATUS_NOTSIGNEDSHORT_LABEL : $langs->trans("PropalStatusNotSignedShort")); $this->labelstatut_short[3]=(! empty($conf->global->PROPAL_STATUS_NOTSIGNEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_NOTSIGNEDSHORT_LABEL : $langs->trans("PropalStatusNotSignedShort"));
$this->labelstatut_short[4]=($conf->global->PROPAL_STATUS_BILLEDSHORT_LABEL ? $conf->global->PROPAL_STATUS_BILLEDSHORT_LABEL : $langs->trans("PropalStatusBilledShort")); $this->labelstatut_short[4]=(! empty($conf->global->PROPAL_STATUS_BILLEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_BILLEDSHORT_LABEL : $langs->trans("PropalStatusBilledShort"));
} }
@ -984,7 +984,7 @@ class Propal extends CommonObject
if ($ref) $sql.= " AND p.ref='".$ref."'"; if ($ref) $sql.= " AND p.ref='".$ref."'";
else $sql.= " AND p.rowid=".$rowid; else $sql.= " AND p.rowid=".$rowid;
dol_syslog("Propal::fecth sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
@ -1119,7 +1119,7 @@ class Propal extends CommonObject
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("Propal::Fetch Error ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::fetch Error ".$this->error, LOG_ERR);
return -1; return -1;
} }
@ -1132,7 +1132,7 @@ class Propal extends CommonObject
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog("Propal::Fetch Error ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::fetch Error ".$this->error, LOG_ERR);
return -1; return -1;
} }
} }

View File

@ -1188,7 +1188,7 @@ class Commande extends CommonObject
* @param string $ref Ref of object * @param string $ref Ref of object
* @param string $ref_ext External reference of object * @param string $ref_ext External reference of object
* @param string $ref_int Internal reference of other object * @param string $ref_int Internal reference of other object
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO, 0 if not found
*/ */
function fetch($id, $ref='', $ref_ext='', $ref_int='') function fetch($id, $ref='', $ref_ext='', $ref_int='')
{ {
@ -1220,7 +1220,7 @@ class Commande extends CommonObject
if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'"; if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND c.ref_int='".$this->db->escape($ref_int)."'"; if ($ref_int) $sql.= " AND c.ref_int='".$this->db->escape($ref_int)."'";
dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -1289,7 +1289,7 @@ class Commande extends CommonObject
} }
/* /*
* Lignes * Lines
*/ */
$result=$this->fetch_lines(); $result=$this->fetch_lines();
if ($result < 0) if ($result < 0)
@ -1300,14 +1300,14 @@ class Commande extends CommonObject
} }
else else
{ {
dol_syslog('Commande::Fetch Error rowid='.$id.' numrows=0 sql='.$sql);
$this->error='Order with id '.$id.' not found sql='.$sql; $this->error='Order with id '.$id.' not found sql='.$sql;
return -2; dol_syslog(get_class($this).'::fetch '.$this->error);
return 0;
} }
} }
else else
{ {
dol_syslog('Commande::Fetch Error rowid='.$id.' Erreur dans fetch de la commande'); dol_syslog(get_class($this).'::fetch Error rowid='.$id, LOG_ERR);
$this->error=$this->db->error(); $this->error=$this->db->error();
return -1; return -1;
} }

View File

@ -712,7 +712,7 @@ class Facture extends CommonObject
* @param string $ref Reference of invoice * @param string $ref Reference of invoice
* @param string $ref_ext External reference of invoice * @param string $ref_ext External reference of invoice
* @param int $ref_int Internal reference of other object * @param int $ref_int Internal reference of other object
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO, 0 if not found
*/ */
function fetch($rowid, $ref='', $ref_ext='', $ref_int='') function fetch($rowid, $ref='', $ref_ext='', $ref_int='')
{ {
@ -808,7 +808,7 @@ class Facture extends CommonObject
{ {
$this->error='Bill with id '.$rowid.' or ref '.$ref.' not found sql='.$sql; $this->error='Bill with id '.$rowid.' or ref '.$ref.' not found sql='.$sql;
dol_syslog(get_class($this)."::fetch Error ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::fetch Error ".$this->error, LOG_ERR);
return -2; return 0;
} }
} }
else else
@ -1130,7 +1130,7 @@ class Facture extends CommonObject
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
// Delete linked object // Delete linked object
$res = $this->deleteObjectLinked(); $res = $this->deleteObjectLinked();
if ($res < 0) $error++; if ($res < 0) $error++;

View File

@ -50,8 +50,6 @@ class Contrat extends CommonObject
var $product; var $product;
var $user_author; var $user_author;
var $user_service;
var $user_cloture;
var $date_creation; var $date_creation;
var $date_validation; var $date_validation;
@ -79,8 +77,6 @@ class Contrat extends CommonObject
$this->db = $db; $this->db = $db;
$this->product = new Product($db); $this->product = new Product($db);
$this->societe = new Societe($db); $this->societe = new Societe($db);
$this->user_service = new User($db);
$this->user_cloture = new User($db);
} }
/** /**
@ -343,10 +339,7 @@ class Contrat extends CommonObject
$this->id = $result["rowid"]; $this->id = $result["rowid"];
$this->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"]; $this->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"];
$this->statut = $result["statut"]; $this->statut = $result["statut"];
$this->factureid = $result["fk_facture"];
$this->facturedetid = $result["fk_facturedet"];
$this->mise_en_service = $this->db->jdate($result["datemise"]); $this->mise_en_service = $this->db->jdate($result["datemise"]);
$this->date_fin_validite = $result["datefin"];
$this->date_contrat = $this->db->jdate($result["datecontrat"]); $this->date_contrat = $this->db->jdate($result["datecontrat"]);
$this->user_author_id = $result["fk_user_author"]; $this->user_author_id = $result["fk_user_author"];
@ -354,9 +347,6 @@ class Contrat extends CommonObject
$this->commercial_signature_id = $result["fk_commercial_signature"]; $this->commercial_signature_id = $result["fk_commercial_signature"];
$this->commercial_suivi_id = $result["fk_commercial_suivi"]; $this->commercial_suivi_id = $result["fk_commercial_suivi"];
$this->user_service->id = $result["fk_user_mise_en_service"];
$this->user_cloture->id = $result["fk_user_cloture"];
$this->note = $result["note"]; $this->note = $result["note"];
$this->note_public = $result["note_public"]; $this->note_public = $result["note_public"];

View File

@ -715,12 +715,18 @@ class FormFile
if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; }
if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; } if ($modulepart == 'tax') { preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; }
$result=0;
if (is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) $object_instance=$this->cache_objects[$modulepart.'_'.$id.'_'.$ref]; if (is_object($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) $object_instance=$this->cache_objects[$modulepart.'_'.$id.'_'.$ref];
else else
{ {
//print 'Fetch '.$idorref.'<br>'; //print 'Fetch '.$idorref.'<br>';
$result=$object_instance->fetch($id,$ref); $result=$object_instance->fetch($id,$ref);
if ($result > 0) $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]=dol_clone($object_instance); // Save object into a cache if ($result > 0) $this->cache_objects[$modulepart.'_'.$id.'_'.$ref]=dol_clone($object_instance); // Save object into a cache
if ($result == 0) // Not found but no error
{
// Clean of orphelins directories are done into repair.php
//dol_delete_file($file['fullname'],1,1,1);
}
} }
$var=!$var; $var=!$var;

View File

@ -136,13 +136,16 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
closedir($dir); closedir($dir);
// Obtain a list of columns // Obtain a list of columns
$myarray=array(); if ($sortcriteria)
foreach ($file_list as $key => $row)
{ {
$myarray[$key] = $row[$sortcriteria]; $myarray=array();
foreach ($file_list as $key => $row)
{
$myarray[$key] = $row[$sortcriteria];
}
// Sort the data
if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
} }
// Sort the data
if ($sortorder) array_multisort($myarray, $sortorder, $file_list);
return $file_list; return $file_list;
} }

View File

@ -99,7 +99,7 @@ class CommandeFournisseur extends Commande
* *
* @param int $id Id of order to load * @param int $id Id of order to load
* @param string $ref Ref of object * @param string $ref Ref of object
* @return int >0 if OK, <0 if KO * @return int >0 if OK, <0 if KO, 0 if not found
*/ */
function fetch($id,$ref='') function fetch($id,$ref='')
{ {
@ -123,12 +123,17 @@ class CommandeFournisseur extends Commande
if ($ref) $sql.= " AND c.ref='".$ref."'"; if ($ref) $sql.= " AND c.ref='".$ref."'";
else $sql.= " AND c.rowid=".$id; else $sql.= " AND c.rowid=".$id;
dol_syslog("CommandeFournisseur::fetch sql=".$sql,LOG_DEBUG); dol_syslog(get_class($this)."::fetch sql=".$sql,LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if (! $obj) return -1; if (! $obj)
{
$this->error='Bill with id '.$id.' not found sql='.$sql;
dol_syslog(get_class($this).'::fetch '.$this->error);
return 0;
}
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ref = $obj->ref; $this->ref = $obj->ref;
@ -148,12 +153,12 @@ class CommandeFournisseur extends Commande
$this->methode_commande = $obj->methode_commande; $this->methode_commande = $obj->methode_commande;
$this->source = $obj->source; $this->source = $obj->source;
$this->facturee = $obj->facture; //$this->facturee = $obj->facture;
$this->fk_project = $obj->fk_project; $this->fk_project = $obj->fk_project;
$this->cond_reglement_id = $obj->fk_cond_reglement; $this->cond_reglement_id = $obj->fk_cond_reglement;
$this->cond_reglement_code = $obj->cond_reglement_code; $this->cond_reglement_code = $obj->cond_reglement_code;
$this->cond_reglement = $obj->cond_reglement_libelle; $this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc; $this->cond_reglement_doc = $obj->cond_reglement_libelle;
$this->mode_reglement_id = $obj->fk_mode_reglement; $this->mode_reglement_id = $obj->fk_mode_reglement;
$this->mode_reglement_code = $obj->mode_reglement_code; $this->mode_reglement_code = $obj->mode_reglement_code;
$this->mode_reglement = $obj->mode_reglement_libelle; $this->mode_reglement = $obj->mode_reglement_libelle;
@ -178,7 +183,7 @@ class CommandeFournisseur extends Commande
$sql.= " ORDER BY l.rowid"; $sql.= " ORDER BY l.rowid";
//print $sql; //print $sql;
dol_syslog("CommandeFournisseur::fetch get lines sql=".$sql,LOG_DEBUG); dol_syslog(get_class($this)."::fetch get lines sql=".$sql,LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -227,14 +232,14 @@ class CommandeFournisseur extends Commande
else else
{ {
$this->error=$this->db->error()." sql=".$sql; $this->error=$this->db->error()." sql=".$sql;
dol_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
return -1; return -1;
} }
} }
else else
{ {
$this->error=$this->db->error()." sql=".$sql; $this->error=$this->db->error()." sql=".$sql;
dol_syslog("CommandeFournisseur::Fetch ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
return -1; return -1;
} }
} }

View File

@ -248,7 +248,7 @@ class FactureFournisseur extends Facture
* *
* @param int $id Id supplier invoice * @param int $id Id supplier invoice
* @param string $ref Ref supplier invoice * @param string $ref Ref supplier invoice
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK, 0 if not found
*/ */
function fetch($id='',$ref='') function fetch($id='',$ref='')
{ {
@ -348,7 +348,7 @@ class FactureFournisseur extends Facture
if ($result < 0) if ($result < 0)
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR); dol_syslog(get_class($this).'::fetch Error '.$this->error, LOG_ERR);
return -3; return -3;
} }
@ -356,8 +356,8 @@ class FactureFournisseur extends Facture
else else
{ {
$this->error='Bill with id '.$id.' not found sql='.$sql; $this->error='Bill with id '.$id.' not found sql='.$sql;
dol_syslog(get_class($this).'::Fetch rowid='.$id.' numrows=0 sql='.$sql); dol_syslog(get_class($this).'::fetch '.$this->error);
return -2; return 0;
} }
$this->db->free($resql); $this->db->free($resql);

View File

@ -1,21 +1,21 @@
<?php <?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** /**
* \file htdocs/install/repair.php * \file htdocs/install/repair.php
@ -59,7 +59,7 @@ if (! is_object($conf)) dolibarr_install_syslog("repair: conf file not initializ
/* /*
* View * View
*/ */
pHeader('',"upgrade2",GETPOST('action')); pHeader('',"upgrade2",GETPOST('action'));
@ -145,7 +145,7 @@ flush();
/* /*
* Load sql files * Load sql files
*/ */
if ($ok) if ($ok)
{ {
if ($choix==1) $dir = "mysql/migration/"; if ($choix==1) $dir = "mysql/migration/";
@ -191,8 +191,134 @@ if ($ok)
} }
} }
if (GETPOST('purge'))
{
$conf->setValues($db);
$listmodulepart=array('company','invoice','invoice_supplier','propal','order','order_supplier','contract','tax');
foreach ($listmodulepart as $modulepart)
{
$filearray=array();
if ($modulepart == 'company') $upload_dir = $conf->societe->dir_output;
if ($modulepart == 'invoice') $upload_dir = $conf->facture->dir_output;
if ($modulepart == 'invoice_supplier') $upload_dir = $conf->fournisseur->facture->dir_output;
if ($modulepart == 'propal') $upload_dir = $conf->propale->dir_output;
if ($modulepart == 'order') $upload_dir = $conf->commande->dir_output;
if ($modulepart == 'order_supplier') $upload_dir = $conf->fournisseur->commande->dir_output;
if ($modulepart == 'contract') $upload_dir = $conf->contrat->dir_output;
if ($modulepart == 'tax') $upload_dir = $conf->tax->dir_output;
if (empty($upload_dir)) break;
print '<tr><td colspan="2">Clean orphelins files into files '.$upload_dir.'</td></tr>';
$filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','\.meta$','^temp$','^payments$','^CVS$','^thumbs$'),'',SORT_DESC,1);
// To show ref or specific information according to view to show (defined by $module)
if ($modulepart == 'invoice')
{
include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
$object_instance=new Facture($db);
}
else if ($modulepart == 'invoice_supplier')
{
include_once(DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php');
$object_instance=new FactureFournisseur($db);
}
else if ($modulepart == 'propal')
{
include_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php');
$object_instance=new Propal($db);
}
else if ($modulepart == 'order')
{
include_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
$object_instance=new Commande($db);
}
else if ($modulepart == 'order_supplier')
{
include_once(DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php');
$object_instance=new CommandeFournisseur($db);
}
else if ($modulepart == 'contract')
{
include_once(DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php');
$object_instance=new Contrat($db);
}
else if ($modulepart == 'tax')
{
include_once(DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php');
$object_instance=new ChargeSociales($db);
}
$var=true;
foreach($filearray as $key => $file)
{
if (!is_dir($file['name'])
&& $file['name'] != '.'
&& $file['name'] != '..'
&& $file['name'] != 'CVS'
)
{
// Define relative path used to store the file
$relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
//var_dump($file);
$id=0; $ref=''; $object_instance->id=0; $object_instance->ref=''; $label='';
// To show ref or specific information according to view to show (defined by $module)
if ($modulepart == 'invoice') {
preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
}
if ($modulepart == 'invoice_supplier') {
preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1];
}
if ($modulepart == 'propal') {
preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
}
if ($modulepart == 'order') {
preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
}
if ($modulepart == 'order_supplier') {
preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
}
if ($modulepart == 'contract') {
preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1];
}
if ($modulepart == 'tax') {
preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1];
}
if ($id || $ref)
{
//print 'Fetch '.$id.' or '.$ref.'<br>';
$result=$object_instance->fetch($id,$ref);
//print $result.'<br>';
if ($result == 0) // Not found but no error
{
// Clean of orphelins directories are done into repair.php
print '<tr><td colspan="2">';
print 'Delete orphelins file '.$file['fullname'].'<br>';
if (GETPOST('purge') == 2)
{
dol_delete_file($file['fullname'],1,1,1);
dol_delete_dir(dirname($file['fullname']),1);
}
print "</td></tr>";
}
else if ($result < 0) print 'Error in '.get_class($object_instance).'.fetch of id'.$id.' ref='.$ref.', result='.$result.'<br>';
}
}
}
}
}
print '</table>'; print '</table>';
if ($db->connected) $db->close(); if ($db->connected) $db->close();