Qual: Uniformisation du fonctionnement de l'upload de fichiers
This commit is contained in:
parent
8b5005ba16
commit
eca63d63a4
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
|
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
|
||||||
*
|
*
|
||||||
@ -38,35 +38,64 @@ if (!$user->rights->propale->lire)
|
|||||||
accessforbidden();
|
accessforbidden();
|
||||||
|
|
||||||
$langs->load('compta');
|
$langs->load('compta');
|
||||||
|
$langs->load('other');
|
||||||
llxHeader();
|
|
||||||
|
|
||||||
$propalid=empty($_GET['propalid']) ? 0 : intVal($_GET['propalid']);
|
$propalid=empty($_GET['propalid']) ? 0 : intVal($_GET['propalid']);
|
||||||
$action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action'];
|
$action=empty($_GET['action']) ? (empty($_POST['action']) ? '' : $_POST['action']) : $_GET['action'];
|
||||||
|
|
||||||
|
|
||||||
function do_upload ($upload_dir)
|
|
||||||
{
|
|
||||||
global $local_file, $error_msg, $langs;
|
|
||||||
|
|
||||||
if (! is_dir($upload_dir))
|
/*
|
||||||
{
|
* Actions
|
||||||
create_exdir($upload_dir);
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
if (doliMoveFileUpload($_FILES['userfile']['tmp_name'], $upload_dir . '/' . $_FILES['userfile']['name']))
|
// Envoi fichier
|
||||||
|
if ($_POST["sendit"] && $conf->upload)
|
||||||
{
|
{
|
||||||
echo $langs->trans('FileUploaded');
|
$propal = new Propal($db);
|
||||||
|
|
||||||
|
if ($propal->fetch($propalid))
|
||||||
|
{
|
||||||
|
$upload_dir = $conf->propal->dir_output . "/" . $propal->ref;
|
||||||
|
if (! is_dir($upload_dir)) create_exdir($upload_dir);
|
||||||
|
|
||||||
|
if (is_dir($upload_dir))
|
||||||
|
{
|
||||||
|
if (doliMoveFileUpload($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name']))
|
||||||
|
{
|
||||||
|
$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
|
||||||
|
//print_r($_FILES);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo $langs->trans('FileNotUploaded');
|
// Echec transfert (fichier dépassant la limite ?)
|
||||||
|
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
|
||||||
|
// print_r($_FILES);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
// Delete
|
||||||
/* Actions */
|
if ($action=='delete')
|
||||||
/******************************************************************************/
|
{
|
||||||
|
$propal = new Propal($db);
|
||||||
|
|
||||||
|
if ($propal->fetch($propalid))
|
||||||
|
{
|
||||||
|
$upload_dir = $conf->propal->dir_output . "/" . $propal->ref;
|
||||||
|
$file = $upload_dir . '/' . urldecode($_GET['urlfile']);
|
||||||
|
dol_delete_file($file);
|
||||||
|
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Affichage
|
||||||
|
*/
|
||||||
|
|
||||||
|
llxHeader();
|
||||||
|
|
||||||
if ($propalid > 0)
|
if ($propalid > 0)
|
||||||
{
|
{
|
||||||
@ -77,25 +106,6 @@ if ($propalid > 0)
|
|||||||
$propref = sanitize_string($propal->ref);
|
$propref = sanitize_string($propal->ref);
|
||||||
$upload_dir = $conf->propal->dir_output.'/'.$propref;
|
$upload_dir = $conf->propal->dir_output.'/'.$propref;
|
||||||
|
|
||||||
if ( $error_msg )
|
|
||||||
{
|
|
||||||
echo '<B>'.$error_msg.'</B><BR><BR>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/* Actions */
|
|
||||||
/******************************************************************************/
|
|
||||||
if ($action=='delete')
|
|
||||||
{
|
|
||||||
$file = $upload_dir . '/' . urldecode($_GET['urlfile']);
|
|
||||||
dol_delete_file($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $_POST['sendit'] )
|
|
||||||
{
|
|
||||||
do_upload ($upload_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
$h=0;
|
$h=0;
|
||||||
|
|
||||||
$head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id;
|
$head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id;
|
||||||
@ -126,33 +136,82 @@ if ($propalid > 0)
|
|||||||
$hselected=$h;
|
$hselected=$h;
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref);
|
dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal'));
|
||||||
|
|
||||||
print_titre($langs->trans('AssociatedDocuments').' '.$propal->ref_url);
|
// Construit liste des fichiers
|
||||||
|
clearstatcache();
|
||||||
|
|
||||||
print '<table width="100%" class="noborder">';
|
$totalsize=0;
|
||||||
|
$filearray=array();
|
||||||
|
|
||||||
|
$errorlevel=error_reporting();
|
||||||
|
error_reporting(0);
|
||||||
|
$handle=opendir($upload_dir);
|
||||||
|
error_reporting($errorlevel);
|
||||||
|
if ($handle)
|
||||||
|
{
|
||||||
|
$i=0;
|
||||||
|
while (($file = readdir($handle))!==false)
|
||||||
|
{
|
||||||
|
if (!is_dir($dir.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
|
||||||
|
{
|
||||||
|
$filearray[$i]=$file;
|
||||||
|
$totalsize+=filesize($upload_dir."/".$file);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// print '<div class="error">'.$langs->trans("ErrorCanNotReadDir",$upload_dir).'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print '<table class="border"width="100%">';
|
||||||
|
print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">'.$propal->ref_url.'</td></tr>';
|
||||||
|
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.sizeof($filearray).'</td></tr>';
|
||||||
|
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
|
||||||
|
print '</table>';
|
||||||
|
|
||||||
|
print '</div>';
|
||||||
|
|
||||||
|
if ($mesg) { print "$mesg<br>"; }
|
||||||
|
|
||||||
|
// Affiche formulaire upload
|
||||||
|
if ($conf->global->MAIN_UPLOAD_DOC)
|
||||||
|
{
|
||||||
|
print_titre($langs->trans("AttachANewFile"));
|
||||||
|
|
||||||
print '<form name="userfile" action="document.php?propalid='.$propal->id.'" enctype="multipart/form-data" method="POST">';
|
print '<form name="userfile" action="document.php?propalid='.$propal->id.'" enctype="multipart/form-data" method="POST">';
|
||||||
print '<input type="hidden" name="max_file_size" value="2000000">';
|
|
||||||
print '<input type="file" name="userfile" size="40" maxlength="80" class="flat"><br>';
|
|
||||||
print '<input type="submit" value="'.$langs->trans('Upload').'" name="sendit" class="button"> ';
|
|
||||||
print '<input type="submit" value="'.$langs->trans('Cancel').'" name="cancelit" class="button"><br>';
|
|
||||||
print '</form><br>';
|
|
||||||
|
|
||||||
clearstatcache();
|
print '<table width="100%" class="noborder">';
|
||||||
|
print '<tr><td width="50%" valign="top">';
|
||||||
|
|
||||||
|
print '<input type="hidden" name="max_file_size" value="2000000">';
|
||||||
|
print '<input class="flat" type="file" name="userfile" size="40" maxlength="80">';
|
||||||
|
print ' ';
|
||||||
|
print '<input type="submit" class="button" value="'.$langs->trans("Add").'" name="sendit">';
|
||||||
|
|
||||||
|
print "</td></tr>";
|
||||||
|
print "</table>";
|
||||||
|
|
||||||
|
print '</form>';
|
||||||
|
print '<br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Affiche liste des documents existant
|
||||||
|
print_titre($langs->trans("AttachedFiles"));
|
||||||
|
|
||||||
|
print '<table width="100%" class="noborder">';
|
||||||
|
print '<tr class="liste_titre"><td>'.$langs->trans("Document").'</td><td align="right">'.$langs->trans("Size").'</td><td align="center">'.$langs->trans("Date").'</td><td> </td></tr>';
|
||||||
|
|
||||||
if (is_dir($upload_dir))
|
if (is_dir($upload_dir))
|
||||||
{
|
{
|
||||||
|
|
||||||
$handle=opendir($upload_dir);
|
$handle=opendir($upload_dir);
|
||||||
if ($handle)
|
if ($handle)
|
||||||
{
|
{
|
||||||
print '<tr class="liste_titre">';
|
|
||||||
print '<td>'.$langs->trans('Document').'</td>';
|
|
||||||
print '<td align="right">'.$langs->trans('Size').'</td>';
|
|
||||||
print '<td align="center">'.$langs->trans('Date').'</td>';
|
|
||||||
print '<td> </td>';
|
|
||||||
print '</tr>';
|
|
||||||
$var=true;
|
$var=true;
|
||||||
while (($file = readdir($handle))!==false)
|
while (($file = readdir($handle))!==false)
|
||||||
{
|
{
|
||||||
@ -187,7 +246,6 @@ if ($propalid > 0)
|
|||||||
}
|
}
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|
||||||
print '</div>';
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -30,26 +30,23 @@
|
|||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
|
|
||||||
$langs->load("companies");
|
$langs->load("companies");
|
||||||
|
$langs->load('other');
|
||||||
|
|
||||||
|
|
||||||
llxHeader();
|
|
||||||
|
|
||||||
$mesg = "";
|
$mesg = "";
|
||||||
$socid=$_GET["socid"];
|
$socid=$_GET["socid"];
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creation répertoire si n'existe pas
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Envoie fichier
|
||||||
|
if ( $_POST["sendit"] && $conf->upload)
|
||||||
|
{
|
||||||
$upload_dir = $conf->societe->dir_output . "/" . $socid ;
|
$upload_dir = $conf->societe->dir_output . "/" . $socid ;
|
||||||
if (! is_dir($upload_dir)) create_exdir($upload_dir);
|
if (! is_dir($upload_dir)) create_exdir($upload_dir);
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Action envoie fichier
|
|
||||||
*/
|
|
||||||
if ( $_POST["sendit"] && $conf->upload)
|
|
||||||
{
|
|
||||||
if (is_dir($upload_dir))
|
if (is_dir($upload_dir))
|
||||||
{
|
{
|
||||||
if (doliMoveFileUpload($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name']))
|
if (doliMoveFileUpload($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name']))
|
||||||
@ -66,12 +63,10 @@ if ( $_POST["sendit"] && $conf->upload)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Suppression fichier
|
||||||
/*
|
|
||||||
* Action suppression fichier
|
|
||||||
*/
|
|
||||||
if ($_GET["action"]=='delete')
|
if ($_GET["action"]=='delete')
|
||||||
{
|
{
|
||||||
|
$upload_dir = $conf->societe->dir_output . "/" . $socid ;
|
||||||
$file = $upload_dir . "/" . urldecode($_GET["urlfile"]);
|
$file = $upload_dir . "/" . urldecode($_GET["urlfile"]);
|
||||||
dol_delete_file($file);
|
dol_delete_file($file);
|
||||||
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
|
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
|
||||||
@ -82,6 +77,8 @@ if ($_GET["action"]=='delete')
|
|||||||
* Affichage liste
|
* Affichage liste
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
llxHeader();
|
||||||
|
|
||||||
if ($socid > 0)
|
if ($socid > 0)
|
||||||
{
|
{
|
||||||
$societe = new Societe($db);
|
$societe = new Societe($db);
|
||||||
@ -181,8 +178,8 @@ if ($socid > 0)
|
|||||||
|
|
||||||
if ($mesg) { print "$mesg<br>"; }
|
if ($mesg) { print "$mesg<br>"; }
|
||||||
|
|
||||||
// Affiche forumlaire upload
|
// Affiche formulaire upload
|
||||||
if (defined('MAIN_UPLOAD_DOC') && $conf->upload)
|
if ($conf->global->MAIN_UPLOAD_DOC)
|
||||||
{
|
{
|
||||||
print_titre($langs->trans("AttachANewFile"));
|
print_titre($langs->trans("AttachANewFile"));
|
||||||
echo '<form name="userfile" action="docsoc.php?socid='.$socid.'" enctype="multipart/form-data" METHOD="POST">';
|
echo '<form name="userfile" action="docsoc.php?socid='.$socid.'" enctype="multipart/form-data" METHOD="POST">';
|
||||||
|
|||||||
@ -45,6 +45,7 @@ ModifiedBy=Modified by %s
|
|||||||
ValidatedBy=Validated by %s
|
ValidatedBy=Validated by %s
|
||||||
CanceledBy=Canceled by %s
|
CanceledBy=Canceled by %s
|
||||||
ClosedBy=Closed by %s
|
ClosedBy=Closed by %s
|
||||||
|
FileWasRemoved=File was deleted
|
||||||
##### Webcal #####
|
##### Webcal #####
|
||||||
LoginWebcal=Login for Webcalendar
|
LoginWebcal=Login for Webcalendar
|
||||||
AddCalendarEntry=Add entry in calendar
|
AddCalendarEntry=Add entry in calendar
|
||||||
|
|||||||
@ -45,6 +45,7 @@ ModifiedBy=Modifi
|
|||||||
ValidatedBy=Validé par %s
|
ValidatedBy=Validé par %s
|
||||||
CanceledBy=Annulé par %s
|
CanceledBy=Annulé par %s
|
||||||
ClosedBy=Cloturé par %s
|
ClosedBy=Cloturé par %s
|
||||||
|
FileWasRemoved=Le fichier a été supprimé
|
||||||
##### Webcal #####
|
##### Webcal #####
|
||||||
LoginWebcal=Login Webcalendar
|
LoginWebcal=Login Webcalendar
|
||||||
AddCalendarEntry=Ajouter entrée dans le calendrier
|
AddCalendarEntry=Ajouter entrée dans le calendrier
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user