PageRenderTime 33ms CodeModel.GetById 20ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/comm/propal/document.php

https://github.com/zeert/dolibarr
PHP | 181 lines | 107 code | 32 blank | 42 comment | 21 complexity | be39345ee92c939d3408ee72cd4b4fc8 MD5 | raw file
  1<?php
  2/* Copyright (C) 2003-2004 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2009 Laurent Destailleur   <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
  5 * Copyright (C) 2005-2012 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/comm/propal/document.php
 23 *       \ingroup    propale
 24 *       \brief      Page de gestion des documents attaches a une proposition commerciale
 25 */
 26
 27require("../../main.inc.php");
 28require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
 29require_once(DOL_DOCUMENT_ROOT."/core/lib/propal.lib.php");
 30require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 31require_once(DOL_DOCUMENT_ROOT."/core/lib/images.lib.php");
 32require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
 33
 34$langs->load('compta');
 35$langs->load('other');
 36
 37$action		= GETPOST('action','alpha');
 38$confirm	= GETPOST('confirm','alpha');
 39$id			= GETPOST('id','int');
 40$ref		= GETPOST('ref','alpha');
 41
 42// Security check
 43$socid='';
 44if (! empty($user->societe_id))
 45{
 46	$action='';
 47	$socid = $user->societe_id;
 48}
 49$result = restrictedArea($user, 'propal', $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 Propal($db);
 63$object->fetch($id,$ref);
 64if ($object->id > 0)
 65{
 66	$object->fetch_thirdparty();
 67}
 68
 69/*
 70 * Actions
 71 */
 72
 73// Envoi fichier
 74if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
 75{
 76	if ($object->id > 0)
 77    {
 78    	$upload_dir = $conf->propal->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->id > 0)
 87    {
 88        $langs->load("other");
 89
 90        $upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
 91    	$file = $upload_dir . '/' . GETPOST('urlfile');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
 92    	$ret=dol_delete_file($file,0,0,0,$object);
 93    	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 94    	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 95    	Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
 96    	exit;
 97    }
 98}
 99
100
101/*
102 * View
103 */
104
105llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
106
107$form = new Form($db);
108
109if ($object->id > 0)
110{
111	$upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref);
112
113	$head = propal_prepare_head($object);
114	dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
115
116	// Construit liste des fichiers
117	$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
118	$totalsize=0;
119	foreach($filearray as $key => $file)
120	{
121		$totalsize+=$file['size'];
122	}
123
124
125	print '<table class="border"width="100%">';
126
127	$linkback='<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
128
129	// Ref
130	print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
131	print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
132	print '</td></tr>';
133
134	// Ref client
135	print '<tr><td>';
136	print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
137	print $langs->trans('RefCustomer').'</td><td align="left">';
138	print '</td>';
139	print '</tr></table>';
140	print '</td><td colspan="3">';
141	print $object->ref_client;
142	print '</td>';
143	print '</tr>';
144
145	// Customer
146	print "<tr><td>".$langs->trans("Company")."</td>";
147	print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
148
149	print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
150	print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
151
152	print '</table>';
153
154	print '</div>';
155
156	/*
157	 * Confirmation suppression fichier
158	 */
159	if ($action == 'delete')
160	{
161		$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
162		if ($ret == 'html') print '<br>';
163	}
164
165	// Affiche formulaire upload
166	$formfile=new FormFile($db);
167	$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->propale->creer,50,$object);
168
169
170	// List of document
171	$param='&id='.$object->id;
172	$formfile->list_of_documents($filearray,$object,'propal',$param);
173}
174else
175{
176	print $langs->trans("UnkownError");
177}
178
179llxFooter();
180$db->close();
181?>