diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 9180774d38f..1de7725e6b6 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -134,16 +134,16 @@ class Propal extends CommonObject $this->duree_validite=$conf->global->PROPALE_VALIDITY_DURATION; $langs->load("propal"); - $this->labelstatut[0]=($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[2]=($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[4]=($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[1]=($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[3]=($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[0]=(! empty($conf->global->PROPAL_STATUS_DRAFT_LABEL) ? $conf->global->PROPAL_STATUS_DRAFT_LABEL : $langs->trans("PropalStatusDraft")); + $this->labelstatut[1]=(! empty($conf->global->PROPAL_STATUS_VALIDATED_LABEL) ? $conf->global->PROPAL_STATUS_VALIDATED_LABEL : $langs->trans("PropalStatusValidated")); + $this->labelstatut[2]=(! empty($conf->global->PROPAL_STATUS_SIGNED_LABEL) ? $conf->global->PROPAL_STATUS_SIGNED_LABEL : $langs->trans("PropalStatusSigned")); + $this->labelstatut[3]=(! empty($conf->global->PROPAL_STATUS_NOTSIGNED_LABEL) ? $conf->global->PROPAL_STATUS_NOTSIGNED_LABEL : $langs->trans("PropalStatusNotSigned")); + $this->labelstatut[4]=(! empty($conf->global->PROPAL_STATUS_BILLED_LABEL) ? $conf->global->PROPAL_STATUS_BILLED_LABEL : $langs->trans("PropalStatusBilled")); + $this->labelstatut_short[0]=(! empty($conf->global->PROPAL_STATUS_DRAFTSHORT_LABEL) ? $conf->global->PROPAL_STATUS_DRAFTSHORT_LABEL : $langs->trans("PropalStatusDraftShort")); + $this->labelstatut_short[1]=(! empty($conf->global->PROPAL_STATUS_VALIDATEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_VALIDATEDSHORT_LABEL : $langs->trans("Opened")); + $this->labelstatut_short[2]=(! empty($conf->global->PROPAL_STATUS_SIGNEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_SIGNEDSHORT_LABEL : $langs->trans("PropalStatusSignedShort")); + $this->labelstatut_short[3]=(! empty($conf->global->PROPAL_STATUS_NOTSIGNEDSHORT_LABEL) ? $conf->global->PROPAL_STATUS_NOTSIGNEDSHORT_LABEL : $langs->trans("PropalStatusNotSignedShort")); + $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."'"; 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); if ($resql) { @@ -1119,7 +1119,7 @@ class Propal extends CommonObject else { $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; } @@ -1132,7 +1132,7 @@ class Propal extends CommonObject else { $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; } } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 169c24cb171..6c0aa45fe3c 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1188,7 +1188,7 @@ class Commande extends CommonObject * @param string $ref Ref of object * @param string $ref_ext External reference of 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='') { @@ -1220,7 +1220,7 @@ class Commande extends CommonObject 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)."'"; - dol_syslog("Commande::fetch sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -1289,7 +1289,7 @@ class Commande extends CommonObject } /* - * Lignes + * Lines */ $result=$this->fetch_lines(); if ($result < 0) @@ -1300,14 +1300,14 @@ class Commande extends CommonObject } else { - dol_syslog('Commande::Fetch Error rowid='.$id.' numrows=0 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 { - 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(); return -1; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 04ece4813c1..ad1bc5ff7a8 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -712,7 +712,7 @@ class Facture extends CommonObject * @param string $ref Reference of invoice * @param string $ref_ext External reference of invoice * @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='') { @@ -808,7 +808,7 @@ class Facture extends CommonObject { $this->error='Bill with id '.$rowid.' or ref '.$ref.' not found sql='.$sql; dol_syslog(get_class($this)."::fetch Error ".$this->error, LOG_ERR); - return -2; + return 0; } } else @@ -1130,7 +1130,7 @@ class Facture extends CommonObject $error=0; $this->db->begin(); - + // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) $error++; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index f93f8d22d88..c7d79e564a6 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -50,8 +50,6 @@ class Contrat extends CommonObject var $product; var $user_author; - var $user_service; - var $user_cloture; var $date_creation; var $date_validation; @@ -79,8 +77,6 @@ class Contrat extends CommonObject $this->db = $db; $this->product = new Product($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->ref = (!isset($result["ref"]) || !$result["ref"]) ? $result["rowid"] : $result["ref"]; $this->statut = $result["statut"]; - $this->factureid = $result["fk_facture"]; - $this->facturedetid = $result["fk_facturedet"]; $this->mise_en_service = $this->db->jdate($result["datemise"]); - $this->date_fin_validite = $result["datefin"]; $this->date_contrat = $this->db->jdate($result["datecontrat"]); $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_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_public = $result["note_public"]; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 9c16ce53a60..153214c76e1 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -715,12 +715,18 @@ class FormFile if ($modulepart == 'contract') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$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]; else { //print 'Fetch '.$idorref.'
'; $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) // Not found but no error + { + // Clean of orphelins directories are done into repair.php + //dol_delete_file($file['fullname'],1,1,1); + } } $var=!$var; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 68aa7d898b3..b5843af4b3f 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -136,13 +136,16 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil closedir($dir); // Obtain a list of columns - $myarray=array(); - foreach ($file_list as $key => $row) + if ($sortcriteria) { - $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; } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index e3b2e3fe89c..5149b1d63b9 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -99,7 +99,7 @@ class CommandeFournisseur extends Commande * * @param int $id Id of order to load * @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='') { @@ -123,12 +123,17 @@ class CommandeFournisseur extends Commande if ($ref) $sql.= " AND c.ref='".$ref."'"; 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); if ($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->ref = $obj->ref; @@ -148,12 +153,12 @@ class CommandeFournisseur extends Commande $this->methode_commande = $obj->methode_commande; $this->source = $obj->source; - $this->facturee = $obj->facture; + //$this->facturee = $obj->facture; $this->fk_project = $obj->fk_project; $this->cond_reglement_id = $obj->fk_cond_reglement; $this->cond_reglement_code = $obj->cond_reglement_code; $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_code = $obj->mode_reglement_code; $this->mode_reglement = $obj->mode_reglement_libelle; @@ -178,7 +183,7 @@ class CommandeFournisseur extends Commande $sql.= " ORDER BY l.rowid"; //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); if ($result) { @@ -227,14 +232,14 @@ class CommandeFournisseur extends Commande else { $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; } } else { $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; } } diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 4e4208e161c..ce3114dc39c 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -248,7 +248,7 @@ class FactureFournisseur extends Facture * * @param int $id Id 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='') { @@ -348,7 +348,7 @@ class FactureFournisseur extends Facture if ($result < 0) { $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; } @@ -356,8 +356,8 @@ class FactureFournisseur extends Facture else { $this->error='Bill with id '.$id.' not found sql='.$sql; - dol_syslog(get_class($this).'::Fetch rowid='.$id.' numrows=0 sql='.$sql); - return -2; + dol_syslog(get_class($this).'::fetch '.$this->error); + return 0; } $this->db->free($resql); diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index 2524d66395f..2051217db9b 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -1,21 +1,21 @@ * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin - * - * 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 2 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 . - */ +* Copyright (C) 2005-2009 Regis Houssin +* +* 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 2 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 . +*/ /** * \file htdocs/install/repair.php @@ -59,7 +59,7 @@ if (! is_object($conf)) dolibarr_install_syslog("repair: conf file not initializ /* * View - */ +*/ pHeader('',"upgrade2",GETPOST('action')); @@ -145,7 +145,7 @@ flush(); /* * Load sql files - */ +*/ if ($ok) { 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 'Clean orphelins files into files '.$upload_dir.''; + + $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.'
'; + $result=$object_instance->fetch($id,$ref); + //print $result.'
'; + if ($result == 0) // Not found but no error + { + // Clean of orphelins directories are done into repair.php + print ''; + print 'Delete orphelins file '.$file['fullname'].'
'; + if (GETPOST('purge') == 2) + { + dol_delete_file($file['fullname'],1,1,1); + dol_delete_dir(dirname($file['fullname']),1); + } + print ""; + } + else if ($result < 0) print 'Error in '.get_class($object_instance).'.fetch of id'.$id.' ref='.$ref.', result='.$result.'
'; + } + } + } + } +} + print ''; + + + if ($db->connected) $db->close();