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

/htdocs/facture/document.php

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