Fix: uniformize code

This commit is contained in:
Regis Houssin 2012-06-11 21:42:19 +02:00
parent fb15ea20c6
commit 548266d607
11 changed files with 240 additions and 98 deletions

View File

@ -1801,11 +1801,11 @@ class Propal extends CommonObject
if (! $error)
{
// We remove directory
$propalref = dol_sanitizeFileName($this->ref);
$ref = dol_sanitizeFileName($this->ref);
if ($conf->propal->dir_output)
{
$dir = $conf->propal->dir_output . "/" . $propalref ;
$file = $conf->propal->dir_output . "/" . $propalref . "/" . $propalref . ".pdf";
$dir = $conf->propal->dir_output . "/" . $ref ;
$file = $dir . "/" . $ref . ".pdf";
if (file_exists($file))
{
dol_delete_preview($this);
@ -1819,7 +1819,7 @@ class Propal extends CommonObject
}
if (file_exists($dir))
{
$res=@dol_delete_dir($dir);
$res=@dol_delete_dir_recursive($dir);
if (! $res)
{
$this->error='ErrorFailToDeleteDir';

View File

@ -2294,7 +2294,7 @@ class Commande extends CommonObject
}
if (file_exists($dir))
{
if (! dol_delete_dir($dir))
if (! dol_delete_dir_recursive($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
$this->db->rollback();

View File

@ -119,7 +119,7 @@ if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
}
// Delete
if ($action == 'confirm_deletefile' && $confirm == 'yes')
else if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->fetch($id))
{
@ -185,7 +185,7 @@ if ($id > 0 || ! empty($ref))
*/
if ($action == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}

View File

@ -59,21 +59,36 @@ class FileUpload
// For compatibility
if ($element == 'propal') {
$pathname = 'comm/propal'; $filename = 'propal';
}
elseif ($element == 'commande') {
$pathname = $filename = 'commande';
$pathname = 'comm/propal';
$dir_output=$conf->$element->dir_output;
}
elseif ($element == 'facture') {
$pathname = 'compta/facture'; $filename = 'facture';
$pathname = 'compta/facture';
$dir_output=$conf->$element->dir_output;
}
elseif ($element == 'project') {
$element = $pathname = 'projet'; $filename = 'project';
$element = $pathname = 'projet';
$dir_output=$conf->$element->dir_output;
}
elseif ($element == 'fichinter') {
$element='ficheinter';
$dir_output=$conf->$element->dir_output;
}
elseif ($element == 'order_supplier') {
$pathname = 'fourn'; $filename='fournisseur.commande';
$dir_output=$conf->fournisseur->commande->dir_output;
} else {
$dir_output=$conf->$element->dir_output;
}
dol_include_once('/'.$pathname.'/class/'.$filename.'.class.php');
$classname = ucfirst($filename);
if ($element == 'order_supplier') {
$classname = 'CommandeFournisseur';
}
$object = new $classname($db);
$object->fetch($fk_element);
@ -81,7 +96,7 @@ class FileUpload
$this->_options = array(
'script_url' => $_SERVER['PHP_SELF'],
'upload_dir' => $conf->$element->dir_output . '/' . $object->ref . '/',
'upload_dir' => $dir_output . '/' . $object->ref . '/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/',
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
@ -115,7 +130,7 @@ class FileUpload
),
*/
'thumbnail' => array(
'upload_dir' => $conf->$element->dir_output . '/' . $object->ref . '/thumbs/',
'upload_dir' => $dir_output . '/' . $object->ref . '/thumbs/',
'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object->ref.'/thumbs/',
'max_width' => 80,
'max_height' => 80

View File

@ -396,7 +396,19 @@ class InterfaceDemo
}
// Interventions
elseif ($action == 'FICHEINTER_VALIDATE')
elseif ($action == 'FICHEINTER_CREATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'FICHEINTER_MODIFY')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'FICHEINTER_VALIDATE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'FICHEINTER_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}

View File

@ -156,6 +156,15 @@ class Fichinter extends CommonObject
$result=$this->db->query($sql);
if ($result)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('FICHEINTER_CREATE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."fichinter");
$this->db->commit();
return $this->id;
@ -193,6 +202,15 @@ class Fichinter extends CommonObject
dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql))
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('FICHEINTER_MODIFY',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
$this->db->commit();
return 1;
}
@ -629,7 +647,7 @@ class Fichinter extends CommonObject
{
dol_delete_preview($this);
if (!dol_delete_file($file))
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
@ -637,13 +655,22 @@ class Fichinter extends CommonObject
}
if (file_exists($dir))
{
if (!dol_delete_dir($dir))
if (! dol_delete_dir_recursive($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
}
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('FICHEINTER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
$this->db->commit();
return 1;

View File

@ -41,6 +41,14 @@ $langs->load("interventions");
$id = GETPOST('id','int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action','alpha');
$confirm = GETPOST('confirm','alpha');
$mesg='';
if (isset($_SESSION['DolMessage']))
{
$mesg=$_SESSION['DolMessage'];
unset($_SESSION['DolMessage']);
}
// Security check
if ($user->societe_id) $socid=$user->societe_id;
@ -110,6 +118,22 @@ if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
}
}
// Delete
else if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->id > 0)
{
$langs->load("other");
$object->fetch_thirdparty();
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
$_SESSION['DolMessage'] = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'</div>';
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
}
/*
* View
@ -124,21 +148,6 @@ if ($object->id)
{
$object->fetch_thirdparty();
$soc = new Societe($db);
$soc->fetch($object->societe->id);
if ( $error_msg )
{
echo '<div class="error">'.$error_msg.'</div><br>';
}
if ($action == 'delete')
{
$file = $upload_dir . '/' . GETPOST('urlfile','alpha'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
$result=dol_delete_file($file);
//if ($result >= 0) $mesg=$langs->trans("FileWasRemoced");
}
$head=fichinter_prepare_head($object, $user);
dol_fiche_head($head, 'documents', $langs->trans("InterventionCard"), 0, 'intervention');
@ -168,7 +177,17 @@ if ($object->id)
print '</table>';
print '</div>';
dol_htmloutput_mesg($mesg,$mesgs);
/*
* Confirmation suppression fichier
*/
if ($action == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}
// Affiche formulaire upload
$formfile=new FormFile($db);
@ -176,7 +195,7 @@ if ($object->id)
// List of document
//$param='&id='.$object->id;
$param='&id='.$object->id;
$formfile->list_of_documents($filearray,$object,'ficheinter',$param);
}

View File

@ -195,6 +195,23 @@ else if ($action == 'builddoc' && $user->rights->ficheinter->creer) // En get ou
}
}
// Remove file in doc form
else if ($action == 'remove_file')
{
if ($object->fetch($id))
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
$object->fetch_thirdparty();
$langs->load("other");
$upload_dir = $conf->ficheinter->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
dol_delete_file($file,0,0,0,$object);
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
}
}
// Set into a project
else if ($action == 'classin' && $user->rights->ficheinter->creer)
{
@ -205,7 +222,8 @@ else if ($action == 'classin' && $user->rights->ficheinter->creer)
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer)
{
$object->fetch($id);
$object->fetch($id);
$object->fetch_thirdparty();
$object->delete($user);
Header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter');

View File

@ -332,6 +332,8 @@ class CommandeFournisseur extends Commande
if (! $error)
{
$this->oldref='';
// Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref))
{
@ -347,6 +349,8 @@ class CommandeFournisseur extends Commande
if (@rename($dirsource, $dirdest))
{
$this->oldref = $oldref;
dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep
dol_delete_file($dirdest.'/'.$oldref.'.*');
@ -1226,6 +1230,7 @@ class CommandeFournisseur extends Commande
function delete($user='')
{
global $langs,$conf;
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
$error = 0;
@ -1251,25 +1256,60 @@ class CommandeFournisseur extends Commande
{
$error++;
}
if ($error == 0)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SUPPLIER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
dol_syslog("CommandeFournisseur::delete : Success");
$this->db->commit();
return 1;
if (! $error)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('ORDER_SUPPLIER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
else
{
$this->db->rollback();
return -1;
if (! $error)
{
// We remove directory
$ref = dol_sanitizeFileName($this->ref);
if ($conf->fournisseur->commande->dir_output)
{
$dir = $conf->fournisseur->commande->dir_output . "/" . $ref ;
$file = $dir . "/" . $ref . ".pdf";
if (file_exists($file))
{
if (! dol_delete_file($file,0,0,0,$this)) // For triggers
{
$this->error='ErrorFailToDeleteFile';
$error++;
}
}
if (file_exists($dir))
{
$res=@dol_delete_dir_recursive($dir);
if (! $res)
{
$this->error='ErrorFailToDeleteDir';
$error++;
}
}
}
}
if (! $error)
{
dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG);
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR);
$this->db->rollback();
return -$error;
}
}
/**

View File

@ -41,6 +41,11 @@ $langs->load('deliveries');
$langs->load('products');
$langs->load('stocks');
$id = GETPOST('id','int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action','alpha');
$confirm = GETPOST('confirm','alpha');
$mesg='';
if (isset($_SESSION['DolMessage']))
{
@ -49,8 +54,6 @@ if (isset($_SESSION['DolMessage']))
}
// Security check
$id=empty($_GET['id']) ? 0 : intVal($_GET['id']);
$action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action'];
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'commande_fournisseur', $id,'');
@ -66,14 +69,15 @@ if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$commande = new CommandeFournisseur($db);
if ($commande->fetch($_GET['id'],$_GET['ref']) < 0)
$object = new CommandeFournisseur($db);
if ($object->fetch($id,$ref) < 0)
{
dol_print_error($db);
exit;
}
$upload_dir = $conf->fournisseur->dir_output.'/commande/'.dol_sanitizeFileName($object->ref);
$object->fetch_thirdparty();
/*
* Actions
@ -82,8 +86,6 @@ if ($commande->fetch($_GET['id'],$_GET['ref']) < 0)
// Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
$upload_dir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($commande->ref);
if (dol_mkdir($upload_dir) >= 0)
{
$resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),0,0,$_FILES['userfile']['error']);
@ -119,16 +121,18 @@ if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
}
}
// Delete
if ($action=='delete')
{
$langs->load("other");
$upload_dir = $conf->fournisseur->dir_output . "/commande/" . dol_sanitizeFileName($commande->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file);
$_SESSION['DolMessage'] = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'</div>';
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
else if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->id > 0)
{
$langs->load("other");
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file,0,0,0,$object);
$_SESSION['DolMessage'] = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('urlfile')).'</div>';
Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
}
@ -138,21 +142,14 @@ if ($action=='delete')
$form = new Form($db);
$id = $_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
if ($object->id > 0)
{
llxHeader();
$upload_dir = $conf->fournisseur->dir_output.'/commande/'.dol_sanitizeFileName($commande->ref);
$soc = new Societe($db);
$soc->fetch($commande->socid);
$author = new User($db);
$author->fetch($commande->user_author_id);
$author->fetch($object->user_author_id);
$head = ordersupplier_prepare_head($commande);
$head = ordersupplier_prepare_head($object);
dol_fiche_head($head, 'documents', $langs->trans('SupplierOrder'), 0, 'order');
@ -171,35 +168,35 @@ if ($id > 0 || ! empty($ref))
// Ref
print '<tr><td width="35%">'.$langs->trans("Ref").'</td>';
print '<td colspan="2">';
print $form->showrefnav($commande,'ref','',1,'ref','ref');
print $form->showrefnav($object,'ref','',1,'ref','ref');
print '</td>';
print '</tr>';
// Fournisseur
print '<tr><td>'.$langs->trans("Supplier")."</td>";
print '<td colspan="2">'.$soc->getNomUrl(1,'supplier').'</td>';
print '<td colspan="2">'.$object->thirdparty->getNomUrl(1,'supplier').'</td>';
print '</tr>';
// Statut
print '<tr>';
print '<td>'.$langs->trans("Status").'</td>';
print '<td colspan="2">';
print $commande->getLibStatut(4);
print $object->getLibStatut(4);
print "</td></tr>";
// Date
if ($commande->methode_commande_id > 0)
if ($object->methode_commande_id > 0)
{
print '<tr><td>'.$langs->trans("Date").'</td><td colspan="2">';
if ($commande->date_commande)
if ($object->date_commande)
{
print dol_print_date($commande->date_commande,"dayhourtext")."\n";
print dol_print_date($object->date_commande,"dayhourtext")."\n";
}
print "</td></tr>";
if ($commande->methode_commande)
if ($object->methode_commande)
{
print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$commande->methode_commande.'</td></tr>';
print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$object->methode_commande.'</td></tr>';
}
}
@ -213,25 +210,33 @@ if ($id > 0 || ! empty($ref))
print "</table>\n";
print "</div>\n";
if ($mesg) { print $mesg."<br>"; }
dol_htmloutput_mesg($mesg,$mesgs);
/*
* Confirmation suppression fichier
*/
if ($action == 'delete')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}
// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/commande/document.php?id='.$commande->id,'',0,0,$user->rights->fournisseur->commande->creer,50,$object);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id,'',0,0,$user->rights->fournisseur->commande->creer,50,$object);
// List of document
$param='&id='.$commande->id;
$formfile->list_of_documents($filearray,$commande,'commande_fournisseur',$param);
$param='&id='.$object->id;
$formfile->list_of_documents($filearray,$object,'commande_fournisseur',$param);
}
else
{
Header('Location: index.php');
}
$db->close();
llxFooter();
$db->close();
?>

View File

@ -356,6 +356,7 @@ else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->r
else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->commande->valider)
{
$object->fetch($id);
$object->fetch_thirdparty();
$object->date_commande=dol_now();
$result = $object->valid($user);
@ -452,6 +453,7 @@ else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fo
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
{
$object->fetch($id);
$object->fetch_thirdparty();
$result=$object->delete($user);
if ($result > 0)
{
@ -547,7 +549,9 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) /
// Build document
// Sauvegarde le dernier module choisi pour generer un document
$object->fetch($_REQUEST['id']);
$object->fetch($id);
$object->fetch_thirdparty();
if ($_REQUEST['model'])
{
$object->setDocModel($user, $_REQUEST['model']);
@ -579,10 +583,12 @@ else if ($action == 'remove_file' && $user->rights->fournisseur->commande->creer
if ($object->fetch($id))
{
$object->fetch_thirdparty();
$langs->load("other");
$upload_dir = $conf->fournisseur->commande->dir_output . "/";
$upload_dir = $conf->fournisseur->commande->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
dol_delete_file($file);
dol_delete_file($file,0,0,0,$object);
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved",GETPOST('file')).'</div>';
}
}