*
* 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
@@ -23,7 +23,7 @@
* \file htdocs/compta/facture/document.php
* \ingroup facture
* \brief Page for attached files on invoices
- * \version $Id$
+ * \version $Id: document.php,v 1.43 2011/07/05 16:10:56 hregis Exp $
*/
require("../../main.inc.php");
@@ -38,19 +38,19 @@ $langs->load('compta');
$langs->load('other');
$langs->load("bills");
-if (!$user->rights->facture->lire)
-accessforbidden();
-$facid=empty($_GET['facid']) ? 0 : intVal($_GET['facid']);
-$action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action'];
+$action = GETPOST('action');
+$confirm = GETPOST('confirm');
+$id = GETPOST('facid');
+$ref = GETPOST('ref');
// Security check
-if ($user->societe_id > 0)
+if ($user->societe_id)
{
- unset($_GET["action"]);
$action='';
$socid = $user->societe_id;
}
+$result=restrictedArea($user,'facture',$id,'');
// Get parameters
$sortfield = GETPOST("sortfield",'alpha');
@@ -63,6 +63,8 @@ $pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
+$object = new Facture($db);
+
/*
* Actions
@@ -71,12 +73,11 @@ if (! $sortfield) $sortfield="name";
// Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
-
- $facture = new Facture($db);
- if ($facture->fetch($facid))
+ if ($object->fetch($id))
{
- $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($facture->ref);
+ $object->fetch_thirdparty();
+
+ $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
if (create_exdir($upload_dir) >= 0)
{
@@ -106,15 +107,13 @@ if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
}
// Delete
-if ($action=='delete')
+if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- $facture = new Facture($db);
-
- $facid=$_GET["id"];
- if ($facture->fetch($facid))
+ if ($object->fetch($id))
{
- $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($facture->ref);
+ $object->fetch_thirdparty();
+
+ $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
dol_delete_file($file);
$mesg = ''.$langs->trans("FileWasRemoved").'
';
@@ -133,15 +132,13 @@ $id = $_GET['facid']?$_GET['facid']:$_GET['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
- $facture = new Facture($db);
- if ($facture->fetch($id,$ref) > 0)
+ if ($object->fetch($id,$ref) > 0)
{
- $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($facture->ref);
+ $object->fetch_thirdparty();
+
+ $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
- $societe = new Societe($db);
- $societe->fetch($facture->socid);
-
- $head = facture_prepare_head($facture);
+ $head = facture_prepare_head($object);
dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), 0, 'bill');
@@ -162,7 +159,7 @@ if ($id > 0 || ! empty($ref))
print '';
$morehtmlref='';
$discount=new DiscountAbsolute($db);
- $result=$discount->fetch(0,$facture->id);
+ $result=$discount->fetch(0,$object->id);
if ($result > 0)
{
$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
@@ -171,28 +168,37 @@ if ($id > 0 || ! empty($ref))
{
dol_print_error('',$discount->error);
}
- print $html->showrefnav($facture,'ref','',1,'facnumber','ref',$morehtmlref);
+ print $html->showrefnav($object,'ref','',1,'facnumber','ref',$morehtmlref);
print ' | ';
// Company
- print '| '.$langs->trans('Company').' | '.$societe->getNomUrl(1).' |
';
+ print '| '.$langs->trans('Company').' | '.$object->thirdparty->getNomUrl(1).' |
';
print '| '.$langs->trans("NbOfAttachedFiles").' | '.sizeof($filearray).' |
';
print '| '.$langs->trans("TotalSizeOfAttachedFiles").' | '.$totalsize.' '.$langs->trans("bytes").' |
';
print "\n";
print "\n";
- if ($mesg) { print $mesg."
"; }
+ dol_htmloutput_mesg($mesg,$mesgs);
+
+ /*
+ * Confirmation suppression fichier
+ */
+ if ($action == 'delete')
+ {
+ $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$id.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
+ if ($ret == 'html') print '
';
+ }
// Affiche formulaire upload
$formfile=new FormFile($db);
- $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$facture->id,'',0,0,$user->rights->facture->creer);
+ $formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id,'',0,0,$user->rights->facture->creer);
// List of document
- $param='&facid='.$facture->id;
- $formfile->list_of_documents($filearray,$facture,'facture',$param);
+ $param='&facid='.$object->id;
+ $formfile->list_of_documents($filearray,$object,'facture',$param);
}
else
@@ -207,5 +213,5 @@ else
$db->close();
-llxFooter('$Date$ - $Revision$');
+llxFooter('$Date: 2011/07/05 16:10:56 $ - $Revision: 1.43 $');
?>
diff --git a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN
index d4deae9b132..eb30cc0726b 100644
--- a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN
+++ b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN
@@ -28,7 +28,7 @@
* - Le nom de la classe doit etre InterfaceMytrigger
* - Le nom de la methode constructeur doit etre InterfaceMytrigger
* - Le nom de la propriete name doit etre Mytrigger
- * \version $Id: interface_all_Demo.class.php-NORUN,v 1.26 2011/07/04 10:35:49 hregis Exp $
+ * \version $Id: interface_all_Demo.class.php-NORUN,v 1.27 2011/07/05 16:10:56 hregis Exp $
*/
@@ -502,6 +502,16 @@ class InterfaceDemo
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SHIPPINGL_DELETE')
+ {
+ dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+ }
+
+ // File
+ elseif ($action == 'FILE_UPLOAD')
+ {
+ dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
+ }
+ elseif ($action == 'FILE_DELETE')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php
index 3eb6a794d45..35ce31d0bc8 100644
--- a/htdocs/lib/files.lib.php
+++ b/htdocs/lib/files.lib.php
@@ -20,7 +20,7 @@
/**
* \file htdocs/lib/files.lib.php
* \brief Library for file managing functions
- * \version $Id$
+ * \version $Id: files.lib.php,v 1.64 2011/07/05 16:10:57 hregis Exp $
*/
/**
@@ -454,11 +454,13 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
* @param allowoverwrite 1=Overwrite target file if it already exists
* @param disablevirusscan 1=Disable virus scan
* @param uploaderrorcode Value of upload error code ($_FILES['field']['error'])
+ * @param notrigger Disable all triggers
* @return int >0 if OK, <0 or string if KO
*/
-function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0)
+function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $notrigger=0)
{
- global $conf;
+ global $conf, $user, $langs;
+ global $object;
$file_name = $dest_file;
// If an upload error has been reported
@@ -552,6 +554,19 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
{
if (! empty($conf->global->MAIN_UMASK)) @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
dol_syslog("Functions.lib::dol_move_uploaded_file Success to move ".$src_file." to ".$file_name." - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
+
+ if (! $notrigger)
+ {
+ $object->src_file=$dest_file;
+
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('FILE_UPLOAD',$object,$user,$langs,$conf);
+ if ($result < 0) { $error++; $errors=$interface->errors; }
+ // Fin appel triggers
+ }
+
return 1; // Success
}
else
@@ -568,10 +583,14 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable
* @param file File to delete or mask of file to delete
* @param disableglob Disable usage of glob like *
* @param nophperrors Disable all PHP output errors
+ * @param notrigger Disable all triggers
* @return boolean True if file is deleted, False if error
*/
-function dol_delete_file($file,$disableglob=0,$nophperrors=0)
+function dol_delete_file($file,$disableglob=0,$nophperrors=0,$notrigger=0)
{
+ global $conf, $user, $langs;
+ global $object;
+
//print "x".$file." ".$disableglob;
$ok=true;
$file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset
@@ -581,7 +600,21 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0)
{
if ($nophperrors) $ok=@unlink($filename); // The unlink encapsulated by dolibarr
else $ok=unlink($filename); // The unlink encapsulated by dolibarr
- if ($ok) dol_syslog("Removed file ".$filename,LOG_DEBUG);
+ if ($ok)
+ {
+ dol_syslog("Removed file ".$filename,LOG_DEBUG);
+ if (! $notrigger)
+ {
+ $object->src_file=$file;
+
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('FILE_DELETE',$object,$user,$langs,$conf);
+ if ($result < 0) { $error++; $errors=$interface->errors; }
+ // Fin appel triggers
+ }
+ }
else dol_syslog("Failed to remove file ".$filename,LOG_WARNING);
}
}
diff --git a/htdocs/societe/document.php b/htdocs/societe/document.php
index e496d064662..01edf6fc420 100644
--- a/htdocs/societe/document.php
+++ b/htdocs/societe/document.php
@@ -23,7 +23,7 @@
* \file htdocs/societe/document.php
* \brief Tab for documents linked to third party
* \ingroup societe
- * \version $Id: document.php,v 1.31 2011/07/03 13:16:46 hregis Exp $
+ * \version $Id: document.php,v 1.32 2011/07/05 16:10:56 hregis Exp $
*/
require("../main.inc.php");
@@ -35,10 +35,13 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
$langs->load("companies");
$langs->load('other');
-$mesg = "";
+$mesg='';
+
+$action = GETPOST('action');
+$confirm = GETPOST('confirm');
+$socid = (GETPOST('socid') ? GETPOST('socid') : GETPOST('id'));
// Security check
-$socid = (GETPOST('socid') ? GETPOST('socid') : GETPOST('id'));
if ($user->societe_id > 0)
{
unset($_GET["action"]);
@@ -70,48 +73,54 @@ $object = new Societe($db);
// Envoie fichier
if ( $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
{
- if (create_exdir($upload_dir) >= 0)
+ if ($object->fetch($socid))
{
- $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
- if (is_numeric($resupload) && $resupload > 0)
+ if (create_exdir($upload_dir) >= 0)
{
- if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
- {
- // Create small thumbs for company (Ratio is near 16/9)
- // Used on logon for example
- $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
-
- // Create mini thumbs for company (Ratio is near 16/9)
- // Used on menu or for setup page for example
- $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
- }
- $mesg = ''.$langs->trans("FileTransferComplete").'
';
- }
- else
- {
- $langs->load("errors");
- if (is_numeric($resupload) && $resupload < 0) // Unknown error
+ $resupload=dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0,0,$_FILES['userfile']['error']);
+ if (is_numeric($resupload) && $resupload > 0)
{
- $mesg = ''.$langs->trans("ErrorFileNotUploaded").'
';
+ if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
+ {
+ // Create small thumbs for company (Ratio is near 16/9)
+ // Used on logon for example
+ $imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthsmall, $maxheightsmall, '_small', $quality, "thumbs");
+
+ // Create mini thumbs for company (Ratio is near 16/9)
+ // Used on menu or for setup page for example
+ $imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'], $maxwidthmini, $maxheightmini, '_mini', $quality, "thumbs");
+ }
+ $mesg = ''.$langs->trans("FileTransferComplete").'
';
}
- else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
+ else
{
- $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus").'
';
- }
- else // Known error
- {
- $mesg = ''.$langs->trans($resupload).'
';
+ $langs->load("errors");
+ if (is_numeric($resupload) && $resupload < 0) // Unknown error
+ {
+ $mesg = ''.$langs->trans("ErrorFileNotUploaded").'
';
+ }
+ else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
+ {
+ $mesg = ''.$langs->trans("ErrorFileIsInfectedWithAVirus").'
';
+ }
+ else // Known error
+ {
+ $mesg = ''.$langs->trans($resupload).'
';
+ }
}
}
}
}
// Suppression fichier
-if ($_REQUEST['action'] == 'confirm_deletefile' && $_REQUEST['confirm'] == 'yes')
+if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
- $file = $upload_dir . "/" . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
- dol_delete_file($file);
- $mesg = ''.$langs->trans("FileWasRemoved").'
';
+ if ($object->fetch($socid))
+ {
+ $file = $upload_dir . "/" . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
+ dol_delete_file($file);
+ $mesg = ''.$langs->trans("FileWasRemoved").'
';
+ }
}
@@ -195,15 +204,15 @@ if ($socid > 0)
/*
* Confirmation suppression fichier
*/
- if ($_GET['action'] == 'delete')
+ if ($action == 'delete')
{
- $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?socid='.$_GET["id"].'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
+ $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?socid='.$socid.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '
';
}
$formfile=new FormFile($db);
- if ($conf->global->MAIN_USE_JQUERY_FILEUPLOAD)
+ if (1==2 && $conf->global->MAIN_USE_JQUERY_FILEUPLOAD)
{
$formfile->form_ajaxfileupload($object);
}
@@ -280,6 +289,6 @@ else
$db->close();
-llxFooter('$Date: 2011/07/03 13:16:46 $ - $Revision: 1.31 $');
+llxFooter('$Date: 2011/07/05 16:10:56 $ - $Revision: 1.32 $');
?>