PageRenderTime 363ms CodeModel.GetById 131ms app.highlight 106ms RepoModel.GetById 116ms app.codeStats 1ms

/htdocs/product/document.php

https://bitbucket.org/speedealing/speedealing
PHP | 165 lines | 90 code | 35 blank | 40 comment | 14 complexity | 77c0a084370dc475722448af742466f9 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-2012 Regis Houssin         <regis.houssin@capnetworks.com>
  6 * Copyright (C) 2005      Simon TOSSER          <simon@kornog-computing.com>
  7 *
  8 * This program is free software; you can redistribute it and/or modify
  9 * it under the terms of the GNU General Public License as published by
 10 * the Free Software Foundation; either version 3 of the License, or
 11 * (at your option) any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 20 */
 21
 22/**
 23 *       \file       htdocs/product/document.php
 24 *       \ingroup    product
 25 *       \brief      Page des documents joints sur les produits
 26 */
 27
 28require '../main.inc.php';
 29require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
 30require_once DOL_DOCUMENT_ROOT.'/product/class/product.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/class/html.formfile.class.php';
 34
 35$langs->load("other");
 36$langs->load("products");
 37
 38$id = GETPOST('id', 'int');
 39$ref = GETPOST('ref', 'alpha');
 40$action=GETPOST('action','alpha');
 41$confirm=GETPOST('confirm','alpha');
 42
 43// Security check
 44$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 45$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
 46if ($user->societe_id) $socid=$user->societe_id;
 47$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
 48
 49// Get parameters
 50$sortfield = GETPOST("sortfield",'alpha');
 51$sortorder = GETPOST("sortorder",'alpha');
 52$page = GETPOST("page",'int');
 53if ($page == -1) { $page = 0; }
 54$offset = $conf->liste_limit * $page;
 55$pageprev = $page - 1;
 56$pagenext = $page + 1;
 57if (! $sortorder) $sortorder="ASC";
 58if (! $sortfield) $sortfield="name";
 59
 60
 61$object = new Product($db);
 62if ($id > 0 || ! empty($ref))
 63{
 64    $result = $object->fetch($id, $ref);
 65
 66    if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
 67    elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
 68}
 69$modulepart='produit';
 70
 71/*
 72 * Action envoie fichier
 73 */
 74
 75if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
 76{
 77	dol_add_file_process($upload_dir,0,1,'userfile');
 78}
 79
 80// Delete
 81if ($action=='delete')
 82{
 83	$langs->load("other");
 84	$file = $upload_dir . '/' . GETPOST('urlfile');	// Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
 85	$ret=dol_delete_file($file,0,0,0,$object);
 86	if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 87	else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 88	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
 89	exit;
 90}
 91
 92
 93/*
 94 *	View
 95 */
 96
 97$form = new Form($db);
 98
 99llxHeader("","",$langs->trans("CardProduct".$object->type));
100
101
102if ($object->id)
103{
104	$head=product_prepare_head($object, $user);
105	$titre=$langs->trans("CardProduct".$object->type);
106	$picto=($object->type==1?'service':'product');
107	dol_fiche_head($head, 'documents', $titre, 0, $picto);
108
109
110	// Construit liste des fichiers
111	$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
112	$totalsize=0;
113	foreach($filearray as $key => $file)
114	{
115		$totalsize+=$file['size'];
116	}
117
118
119    print '<table class="border" width="100%">';
120
121    // Ref
122    print '<tr>';
123    print '<td width="30%">'.$langs->trans("Ref").'</td><td colspan="3">';
124	print $form->showrefnav($object,'ref','',1,'ref');
125    print '</td>';
126    print '</tr>';
127
128    // Label
129    print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->libelle.'</td></tr>';
130
131	// Status (to sell)
132	print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
133	print $object->getLibStatut(2,0);
134	print '</td></tr>';
135
136	// Status (to buy)
137	print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
138	print $object->getLibStatut(2,1);
139	print '</td></tr>';
140
141    print '<tr><td>'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
142    print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
143    print '</table>';
144
145    print '</div>';
146
147
148    // Affiche formulaire upload
149   	$formfile=new FormFile($db);
150	$formfile->form_attach_new_file(DOL_URL_ROOT.'/product/document.php?id='.$object->id,'',0,0,($user->rights->produit->creer||$user->rights->service->creer),50,$object);
151
152
153	// List of document
154	$formfile->list_of_documents($filearray,$object,'produit');
155
156}
157else
158{
159	print $langs->trans("UnkownError");
160}
161
162
163llxFooter();
164$db->close();
165?>