PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fichinter/document.php

https://github.com/zeert/dolibarr
PHP | 171 lines | 89 code | 40 blank | 42 comment | 20 complexity | 1499eab1475ee1b7f9cfeccdf1e3d638 MD5 | raw file
  1<?php
  2/* Copyright (C) 2003-2007 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2010 Laurent Destailleur   <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
  5 * Copyright (C) 2005-2009 Regis Houssin         <regis@dolibarr.fr>
  6 * Copyright (C) 2005      Simon TOSSER          <simon@kornog-computing.com>
  7 * Copyright (C) 2011-2012 Juanjo Menent         <jmenent@2byte.es>
  8 *
  9 * This program is free software; you can redistribute it and/or modify
 10 * it under the terms of the GNU General Public License as published by
 11 * the Free Software Foundation; either version 2 of the License, or
 12 * (at your option) any later version.
 13 *
 14 * This program is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17 * GNU General Public License for more details.
 18 *
 19 * You should have received a copy of the GNU General Public License
 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 21 */
 22
 23/**
 24 *       \file       htdocs/fichinter/document.php
 25 *       \ingroup    fichinter
 26 *       \brief      Page des documents joints sur les contrats
 27 */
 28
 29require("../main.inc.php");
 30require_once(DOL_DOCUMENT_ROOT."/fichinter/class/fichinter.class.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/lib/fichinter.lib.php");
 34require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
 35
 36$langs->load("other");
 37$langs->load("fichinter");
 38$langs->load("companies");
 39$langs->load("interventions");
 40
 41$id = GETPOST('id','int');
 42$ref = GETPOST('ref', 'alpha');
 43$action = GETPOST('action','alpha');
 44$confirm = GETPOST('confirm','alpha');
 45
 46// Security check
 47if ($user->societe_id) $socid=$user->societe_id;
 48$result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
 49
 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
 63$object = new Fichinter($db);
 64$object->fetch($id, $ref);
 65
 66$upload_dir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($object->ref);
 67$modulepart='fichinter';
 68
 69
 70/*
 71 * Actions
 72 */
 73
 74if (GETPOST('sendit','alpha') && ! empty($conf->global->MAIN_UPLOAD_DOC))
 75{
 76	require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 77
 78	dol_add_file_process($upload_dir,0,1,'userfile');
 79}
 80
 81// Delete
 82else if ($action == 'confirm_deletefile' && $confirm == 'yes')
 83{
 84	if ($object->id > 0)
 85	{
 86		$langs->load("other");
 87		$object->fetch_thirdparty();
 88
 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
103$form = new Form($db);
104
105llxHeader("","",$langs->trans("InterventionCard"));
106
107
108if ($object->id)
109{
110	$object->fetch_thirdparty();
111
112	$head=fichinter_prepare_head($object, $user);
113
114	dol_fiche_head($head, 'documents',  $langs->trans("InterventionCard"), 0, 'intervention');
115
116
117	// Construit liste des fichiers
118	$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
119	$totalsize=0;
120	foreach($filearray as $key => $file)
121	{
122		$totalsize+=$file['size'];
123	}
124
125
126    print '<table class="border" width="100%">';
127
128    $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
129
130	// Ref
131	print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
132	print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
133	print '</td></tr>';
134
135	// Societe
136	print "<tr><td>".$langs->trans("Company")."</td><td>".$object->client->getNomUrl(1)."</td></tr>";
137
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>';
141
142    print '</div>';
143
144    /*
145     * Confirmation suppression fichier
146     */
147    if ($action == 'delete')
148    {
149    	$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1);
150    	if ($ret == 'html') print '<br>';
151    }
152
153    // Affiche formulaire upload
154   	$formfile=new FormFile($db);
155	$formfile->form_attach_new_file(DOL_URL_ROOT.'/fichinter/document.php?id='.$object->id,'',0,0,$user->rights->ficheinter->creer,50,$object);
156
157
158	// List of document
159	$param='&id='.$object->id;
160	$formfile->list_of_documents($filearray,$object,'ficheinter',$param);
161
162}
163else
164{
165	print $langs->trans("UnkownError");
166}
167
168llxFooter();
169
170$db->close();
171?>