dolibarr/htdocs/comm/propal/document.php

180 lines
5.4 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
2012-12-30 15:13:49 +01:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
2003-08-28 17:29:13 +02: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 3 of the License, or
2003-08-28 17:29:13 +02:00
* (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-03 02:45:22 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2003-08-28 17:29:13 +02:00
*/
/**
* \file htdocs/comm/propal/document.php
* \ingroup propale
2010-03-27 03:35:08 +01:00
* \brief Page de gestion des documents attaches a une proposition commerciale
*/
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
2003-08-28 17:33:50 +02:00
2005-09-11 13:49:43 +02:00
$langs->load('compta');
$langs->load('other');
2003-08-28 17:29:13 +02:00
$action = GETPOST('action','alpha');
$confirm = GETPOST('confirm','alpha');
2012-02-27 22:26:22 +01:00
$id = GETPOST('id','int');
$ref = GETPOST('ref','alpha');
2008-02-24 14:18:40 +01:00
// Security check
$socid='';
if (! empty($user->societe_id))
{
$action='';
$socid = $user->societe_id;
}
$result = restrictedArea($user, 'propal', $id);
2005-06-29 03:35:00 +02: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 Propal($db);
$object->fetch($id,$ref);
2012-07-02 19:30:37 +02:00
if ($object->id > 0)
{
$object->fetch_thirdparty();
}
/*
* Actions
*/
// Envoi fichier
if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
2003-08-28 17:29:13 +02:00
{
if ($object->id > 0)
{
2012-03-22 08:33:44 +01:00
$upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
2012-07-29 16:44:19 +02:00
dol_add_file_process($upload_dir,0,1,'userfile');
}
}
2003-08-28 17:29:13 +02:00
// Delete
if ($action == 'confirm_deletefile' && $confirm == 'yes')
{
if ($object->id > 0)
{
$langs->load("other");
2011-07-06 22:56:48 +02:00
2012-03-22 08:33:44 +01:00
$upload_dir = $conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref);
$file = $upload_dir . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
2012-07-29 15:47:24 +02:00
$ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
2012-08-31 05:58:38 +02:00
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
exit;
}
2003-08-28 17:29:13 +02:00
}
/*
* View
*/
2012-07-28 17:34:21 +02:00
llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
2005-01-16 20:05:40 +01:00
$form = new Form($db);
if ($object->id > 0)
2003-08-28 17:29:13 +02:00
{
2012-07-02 19:30:37 +02:00
$upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref);
2012-07-02 19:30:37 +02:00
$head = propal_prepare_head($object);
dol_fiche_head($head, 'document', $langs->trans('Proposal'), 0, 'propal');
2012-07-02 19:30:37 +02:00
// Construit liste des fichiers
$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'];
}
2012-07-02 19:30:37 +02:00
print '<table class="border"width="100%">';
2012-07-28 09:54:47 +02:00
$linkback='<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
2012-07-02 19:30:37 +02:00
// Ref
print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
print '</td></tr>';
2012-07-02 19:30:37 +02:00
// Ref client
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">';
2012-07-02 19:30:37 +02:00
print $langs->trans('RefCustomer').'</td><td align="left">';
print '</td>';
print '</tr></table>';
print '</td><td colspan="3">';
print $object->ref_client;
print '</td>';
print '</tr>';
2012-07-02 19:30:37 +02:00
// Customer
print "<tr><td>".$langs->trans("Company")."</td>";
print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
2012-07-02 19:30:37 +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>';
2012-07-02 19:30:37 +02:00
print '</table>';
2012-07-02 19:30:37 +02:00
print '</div>';
2012-07-02 19:30:37 +02:00
/*
* Confirmation suppression fichier
2012-07-29 15:47:24 +02:00
*/
2012-07-02 19:30:37 +02:00
if ($action == 'delete')
{
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode(GETPOST("urlfile")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
2012-07-02 19:30:37 +02:00
}
2012-07-02 19:30:37 +02:00
// Affiche formulaire upload
$formfile=new FormFile($db);
$formfile->form_attach_new_file($_SERVER['PHP_SELF'].'?id='.$object->id,'',0,0,$user->rights->propal->creer,50,$object);
2012-07-02 19:30:37 +02:00
// List of document
$formfile->list_of_documents($filearray,$object,'propal');
2003-08-28 17:29:13 +02:00
}
else
{
2005-07-01 21:40:06 +02:00
print $langs->trans("UnkownError");
2003-08-28 17:29:13 +02:00
}
llxFooter();
$db->close();
2003-08-28 17:29:13 +02:00
?>