dolibarr/htdocs/commande/document.php

196 lines
5.6 KiB
PHP
Raw Normal View History

2007-01-03 17:17:04 +01:00
<?php
/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
2007-01-03 17:17:04 +01:00
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
2007-01-03 17:17:04 +01:00
*
* 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
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2007-01-03 17:17:04 +01:00
*/
/**
2009-08-05 20:11:27 +02:00
* \file htdocs/commande/document.php
* \ingroup order
* \brief Page de gestion des documents attachees a une commande
2009-01-12 17:33:54 +01:00
*/
2007-01-03 17:17:04 +01:00
2010-03-27 03:35:08 +01:00
require("../main.inc.php");
2007-01-03 17:17:04 +01:00
require_once(DOL_DOCUMENT_ROOT.'/lib/order.lib.php');
2008-05-04 15:33:49 +02:00
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
2010-05-03 10:43:33 +02:00
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
2010-04-27 10:13:42 +02:00
require_once(DOL_DOCUMENT_ROOT ."/commande/class/commande.class.php");
2007-01-03 17:17:04 +01:00
$langs->load('companies');
$langs->load('other');
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$id = GETPOST('id');
$ref = GETPOST('ref');
2007-01-03 17:17:04 +01:00
// Security check
if ($user->societe_id)
{
$action='';
$socid = $user->societe_id;
}
$result=restrictedArea($user,'commande',$id,'');
2007-01-03 17:17:04 +01:00
// Get parameters
2010-11-20 14:08:44 +01:00
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
$page = GETPOST("page",'int');
if ($page == -1) { $page = 0; }
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
2010-11-20 14:08:44 +01:00
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="name";
$object = new Commande($db);
2007-01-03 17:17:04 +01:00
2009-01-12 17:33:54 +01:00
2007-01-03 17:17:04 +01:00
/*
* Actions
*/
2009-01-12 17:33:54 +01:00
2007-01-03 17:17:04 +01:00
// Envoi fichier
if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
2007-01-03 17:17:04 +01:00
{
if ($object->fetch($id))
{
$object->fetch_thirdparty();
2011-07-06 22:56:48 +02:00
$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
2011-07-06 22:56:48 +02:00
if (create_exdir($upload_dir) >= 0)
2009-01-12 17:33:54 +01:00
{
$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 = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
}
else
{
$langs->load("errors");
if ($resupload < 0) // Unknown error
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
}
else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload)) // Files infected by a virus
{
$mesg = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
}
else // Known error
{
$mesg = '<div class="error">'.$langs->trans($resupload).'</div>';
}
}
2009-01-12 17:33:54 +01:00
}
}
2007-01-03 17:17:04 +01:00
}
// Delete
if ($action == 'confirm_deletefile' && $confirm == 'yes')
2007-01-03 17:17:04 +01:00
{
if ($object->fetch($id))
{
$object->fetch_thirdparty();
2011-07-06 22:56:48 +02:00
$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . $_GET['urlfile']; // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
2011-07-14 07:21:52 +02:00
dol_delete_file($file,0,0,0,'FILE_DELETE',$object);
$mesg = '<div class="ok">'.$langs->trans("FileWasRemoved").'</div>';
}
2007-01-03 17:17:04 +01:00
}
/*
2009-01-12 17:33:54 +01:00
* View
2007-01-03 17:17:04 +01:00
*/
2009-01-12 17:33:54 +01:00
2009-08-05 20:11:27 +02:00
llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
2009-01-12 17:33:54 +01:00
$html = new Form($db);
if ($id > 0 || ! empty($ref))
2007-01-03 17:17:04 +01:00
{
if ($object->fetch($id, $ref))
{
$object->fetch_thirdparty();
2011-07-06 22:56:48 +02:00
$upload_dir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($object->ref);
$head = commande_prepare_head($object);
dol_fiche_head($head, 'documents', $langs->trans('CustomerOrder'), 0, 'order');
2011-07-06 22:56:48 +02:00
// Construit liste des fichiers
2011-07-06 22:56:48 +02:00
$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
$totalsize=0;
foreach($filearray as $key => $file)
{
$totalsize+=$file['size'];
}
2011-07-06 22:56:48 +02:00
print '<table class="border"width="100%">';
2011-07-06 22:56:48 +02:00
// Ref
print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
print $html->showrefnav($object,'ref','',1,'ref','ref');
print '</td></tr>';
2011-07-06 22:56:48 +02:00
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
2011-09-17 21:49:50 +02:00
print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
print "</table>\n";
print "</div>\n";
2011-07-06 22:56:48 +02:00
dol_htmloutput_mesg($mesg,$mesgs);
2011-07-06 22:56:48 +02:00
/*
* Confirmation suppression fichier
*/
if ($action == 'delete')
{
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id.'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
if ($ret == 'html') print '<br>';
}
2011-07-06 22:56:48 +02:00
// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file(DOL_URL_ROOT.'/commande/document.php?id='.$object->id,'',0,0,$user->rights->commande->creer);
2011-07-06 22:56:48 +02:00
// List of document
$param='&id='.$object->id;
$formfile->list_of_documents($filearray,$object,'commande',$param);
}
else
2007-01-03 17:17:04 +01:00
{
dol_print_error($db);
2007-01-03 17:17:04 +01:00
}
}
else
{
2009-01-12 17:33:54 +01:00
Header('Location: index.php');
2007-01-03 17:17:04 +01:00
}
$db->close();
llxFooter();
2007-01-03 17:17:04 +01:00
?>