PageRenderTime 1ms CodeModel.GetById 18ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/commande/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 175 lines | 101 code | 34 blank | 40 comment | 23 complexity | cffb55a022af4b1df35b2b7ee19fbeee MD5 | raw file
  1<?php
  2/* Copyright (C) 2003-2007 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2008 Laurent Destailleur   <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
  5 * Copyright (C) 2005-2012 Regis Houssin         <regis.houssin@capnetworks.com>
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License as published by
  9 * the Free Software Foundation; either version 3 of the License, or
 10 * (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21/**
 22 *	\file       htdocs/commande/document.php
 23 *	\ingroup    order
 24 *	\brief      Page de gestion des documents attachees a une commande
 25 */
 26
 27require '../main.inc.php';
 28require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
 29require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
 32require_once DOL_DOCUMENT_ROOT .'/commande/class/commande.class.php';
 33
 34
 35$langs->load('companies');
 36$langs->load('other');
 37
 38$action		= GETPOST('action');
 39$confirm	= GETPOST('confirm');
 40$id			= GETPOST('id','int');
 41$ref		= GETPOST('ref');
 42
 43// Security check
 44if ($user->societe_id)
 45{
 46	$action='';
 47	$socid = $user->societe_id;
 48}
 49$result=restrictedArea($user,'commande',$id,'');
 50
 51// Get parameters
 52$sortfield = GETPOST("sortfield",'alpha');
 53$sortorder = GETPOST("sortorder",'alpha');
 54$page = GETPOST("page",'int');
 55if ($page == -1) { $page = 0; }
 56$offset = $conf->liste_limit * $page;
 57$pageprev = $page - 1;
 58$pagenext = $page + 1;
 59if (! $sortorder) $sortorder="ASC";
 60if (! $sortfield) $sortfield="name";
 61
 62$object = new Commande($db);
 63
 64
 65/*
 66 * Actions
 67 */
 68
 69// Envoi fichier
 70if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
 71{
 72	if ($object->fetch($id))
 73    {
 74        $object->fetch_thirdparty();
 75	    $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
 76	    dol_add_file_process($upload_dir,0,1,'userfile');
 77    }
 78}
 79
 80// Delete
 81else if ($action == 'confirm_deletefile' && $confirm == 'yes')
 82{
 83	if ($object->fetch($id))
 84    {
 85        $langs->load("other");
 86        $object->fetch_thirdparty();
 87
 88    	$upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref);
 89    	$file = $upload_dir . '/' . GETPOST('urlfile');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
 90    	$ret=dol_delete_file($file,0,0,0,$object);
 91    	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 92    	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 93    	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
 94    	exit;
 95    }
 96}
 97
 98
 99/*
100 * View
101 */
102
103llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
104
105$form = new Form($db);
106
107if ($id > 0 || ! empty($ref))
108{
109	if ($object->fetch($id, $ref))
110    {
111    	$object->fetch_thirdparty();
112
113    	$upload_dir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($object->ref);
114
115		$head = commande_prepare_head($object);
116		dol_fiche_head($head, 'documents', $langs->trans('CustomerOrder'), 0, 'order');
117
118
119		// Construit liste des fichiers
120		$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
121		$totalsize=0;
122		foreach($filearray as $key => $file)
123		{
124			$totalsize+=$file['size'];
125		}
126
127
128		print '<table class="border" width="100%">';
129
130		$linkback = '<a href="'.DOL_URL_ROOT.'/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
131
132		// Ref
133		print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
134		print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
135		print '</td></tr>';
136
137		print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
138		print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
139		print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
140		print "</table>\n";
141		print "</div>\n";
142
143    	/*
144		 * Confirmation suppression fichier
145		 */
146		if ($action == 'delete')
147		{
148			$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
149			if ($ret == 'html') print '<br>';
150		}
151
152		// Affiche formulaire upload
153		$formfile=new FormFile($db);
154		$formfile->form_attach_new_file(DOL_URL_ROOT.'/commande/document.php?id='.$object->id,'',0,0,$user->rights->commande->creer,50,$object);
155
156
157		// List of document
158		$param='&id='.$object->id;
159		$formfile->list_of_documents($filearray,$object,'commande',$param);
160	}
161	else
162	{
163		dol_print_error($db);
164	}
165}
166else
167{
168	header('Location: index.php');
169}
170
171
172llxFooter();
173
174$db->close();
175?>