PageRenderTime 49ms CodeModel.GetById 37ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/facture/document.php

https://github.com/zeert/dolibarr
PHP | 206 lines | 127 code | 37 blank | 42 comment | 24 complexity | 70a33604b7cc779c28f911927bdedad7 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-2011 Regis Houssin         <regis@dolibarr.fr>
  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 2 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/compta/facture/document.php
 23 *	\ingroup    facture
 24 *	\brief      Page for attached files on invoices
 25 */
 26
 27require("../../main.inc.php");
 28require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
 29require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
 30require_once(DOL_DOCUMENT_ROOT."/core/lib/invoice.lib.php");
 31require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 32require_once(DOL_DOCUMENT_ROOT."/core/lib/images.lib.php");
 33require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
 34
 35$langs->load('propal');
 36$langs->load('compta');
 37$langs->load('other');
 38$langs->load("bills");
 39
 40
 41$action		= GETPOST('action');
 42$confirm	= GETPOST('confirm');
 43$id			= GETPOST('facid','int');
 44$ref		= GETPOST('ref');
 45
 46// Security check
 47if ($user->societe_id)
 48{
 49	$action='';
 50	$socid = $user->societe_id;
 51}
 52$result=restrictedArea($user,'facture',$id,'');
 53
 54// Get parameters
 55$sortfield = GETPOST("sortfield",'alpha');
 56$sortorder = GETPOST("sortorder",'alpha');
 57$page = GETPOST("page",'int');
 58if ($page == -1) { $page = 0; }
 59$offset = $conf->liste_limit * $page;
 60$pageprev = $page - 1;
 61$pagenext = $page + 1;
 62if (! $sortorder) $sortorder="ASC";
 63if (! $sortfield) $sortfield="name";
 64
 65$object = new Facture($db);
 66
 67
 68/*
 69 * Actions
 70 */
 71
 72// Envoi fichier
 73if ($_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
 74{
 75	if ($object->fetch($id))
 76	{
 77		$object->fetch_thirdparty();
 78		$upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
 79		dol_add_file_process($upload_dir,0,1,'userfile');
 80	}
 81}
 82
 83// Delete
 84if ($action == 'confirm_deletefile' && $confirm == 'yes')
 85{
 86	if ($object->fetch($id))
 87	{
 88	    $langs->load("other");
 89		$object->fetch_thirdparty();
 90
 91		$upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
 92		$file = $upload_dir . '/' . GETPOST('urlfile');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
 93		$ret=dol_delete_file($file,0,0,0,$object);
 94		if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 95		else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 96    	Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
 97    	exit;
 98	}
 99}
100
101/*
102 * View
103 */
104
105llxHeader();
106
107$form = new Form($db);
108
109$id = $_GET['facid']?$_GET['facid']:$_GET['id'];
110$ref= $_GET['ref'];
111if ($id > 0 || ! empty($ref))
112{
113	if ($object->fetch($id,$ref) > 0)
114	{
115		$object->fetch_thirdparty();
116
117		$upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref);
118
119		$head = facture_prepare_head($object);
120		dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), 0, 'bill');
121
122
123		// Construit liste des fichiers
124		$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
125		$totalsize=0;
126		foreach($filearray as $key => $file)
127		{
128			$totalsize+=$file['size'];
129		}
130
131
132
133		print '<table class="border" width="100%">';
134
135		$linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
136
137		// Ref
138		print '<tr><td width="30%">'.$langs->trans('Ref').'</td>';
139		print '<td colspan="3">';
140		$morehtmlref='';
141		$discount=new DiscountAbsolute($db);
142		$result=$discount->fetch(0,$object->id);
143		if ($result > 0)
144		{
145			$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
146		}
147		if ($result < 0)
148		{
149			dol_print_error('',$discount->error);
150		}
151		print $form->showrefnav($object, 'ref', $linkback, 1, 'facnumber', 'ref', $morehtmlref);
152		print '</td></tr>';
153
154		// Ref customer
155		print '<tr><td width="20%">';
156		print '<table class="nobordernopadding" width="100%"><tr><td>';
157		print $langs->trans('RefCustomer');
158		print '</td>';
159		print '</tr></table>';
160		print '</td>';
161		print '<td colspan="5">';
162		print $object->ref_client;
163		print '</td></tr>';
164
165		// Company
166		print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
167
168		print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
169		print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
170		print "</table>\n";
171		print "</div>\n";
172
173    	/*
174		 * Confirmation suppression fichier
175		 */
176		if ($action == 'delete')
177		{
178			$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?facid='.$id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
179			if ($ret == 'html') print '<br>';
180		}
181
182
183		// Affiche formulaire upload
184		$formfile=new FormFile($db);
185		$formfile->form_attach_new_file(DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id,'',0,0,$user->rights->facture->creer,50,$object);
186
187
188		// List of document
189		$param='&facid='.$object->id;
190		$formfile->list_of_documents($filearray,$object,'facture',$param);
191
192	}
193	else
194	{
195		dol_print_error($db);
196	}
197}
198else
199{
200	print $langs->trans("UnkownError");
201}
202
203$db->close();
204
205llxFooter();
206?>