PageRenderTime 163ms CodeModel.GetById 70ms app.highlight 9ms RepoModel.GetById 82ms app.codeStats 0ms

/htdocs/product/photos.php

https://bitbucket.org/speedealing/speedealing
PHP | 197 lines | 108 code | 39 blank | 50 comment | 36 complexity | 76f286603c90d953b7817c47fb81fcc5 MD5 | raw file
  1<?php
  2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2009 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005      Eric Seigne          <eric.seigne@ryxeo.com>
  5 * Copyright (C) 2005-2012 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/product/photos.php
 23 *	\ingroup    product
 24 *	\brief      Onglet photos de la fiche produit
 25 */
 26
 27require '../main.inc.php';
 28require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
 29require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
 31
 32$langs->load("products");
 33$langs->load("bills");
 34
 35$id = GETPOST('id', 'int');
 36$ref = GETPOST('ref', 'alpha');
 37$action = GETPOST('action', 'alpha');
 38$confirm = GETPOST('confirm', 'alpha');
 39
 40// Security check
 41$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
 42$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
 43if ($user->societe_id) $socid=$user->societe_id;
 44$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype);
 45
 46$mesg = '';
 47
 48$object = new Product($db);
 49if ($id > 0 || ! empty($ref))
 50{
 51	$result = $object->fetch($id, $ref);
 52	$dir = (! empty($conf->product->multidir_output[$object->entity])?$conf->product->multidir_output[$object->entity]:$conf->service->multidir_output[$object->entity]);
 53}
 54
 55
 56/*
 57 * Actions
 58 */
 59
 60if (isset($_FILES['userfile']) && $_FILES['userfile']['size'] > 0 && GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC))
 61{
 62	if ($object->id) $result = $object->add_photo($dir, $_FILES['userfile']);
 63}
 64
 65if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer))
 66{
 67	$object->delete_photo($dir."/".$_GET["file"]);
 68}
 69
 70if ($action == 'addthumb' && $_GET["file"])
 71{
 72	$object->add_thumb($dir."/".$_GET["file"]);
 73}
 74
 75
 76/*
 77 *	View
 78 */
 79
 80$form = new Form($db);
 81
 82if ($object->id)
 83{
 84	llxHeader("","",$langs->trans("CardProduct".$object->type));
 85
 86	/*
 87	 *  En mode visu
 88	*/
 89	$head=product_prepare_head($object, $user);
 90	$titre=$langs->trans("CardProduct".$object->type);
 91	$picto=($object->type==1?'service':'product');
 92	dol_fiche_head($head, 'photos', $titre, 0, $picto);
 93
 94	/*
 95	 * Confirmation de la suppression de photo
 96	*/
 97	if ($action == 'delete')
 98	{
 99		$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
100		if ($ret == 'html') print '<br>';
101	}
102
103	print($mesg);
104
105	print '<table class="border" width="100%">';
106
107	// Reference
108	print '<tr>';
109	print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
110	print $form->showrefnav($object,'ref','',1,'ref');
111	print '</td>';
112	print '</tr>';
113
114	// Libelle
115	print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$object->libelle.'</td>';
116	print '</tr>';
117
118	// Status (to sell)
119	print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Sell").')</td><td>';
120	print $object->getLibStatut(2,0);
121	print '</td></tr>';
122
123	// Status (to buy)
124	print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')</td><td>';
125	print $object->getLibStatut(2,1);
126	print '</td></tr>';
127
128	print "</table>\n";
129
130	print "</div>\n";
131
132
133
134	/* ************************************************************************** */
135	/*                                                                            */
136	/* Barre d'action                                                             */
137	/*                                                                            */
138	/* ************************************************************************** */
139
140	print "\n<div class=\"tabsAction\">\n";
141
142	if ($action != 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer))
143	{
144		if (! empty($conf->global->MAIN_UPLOAD_DOC))
145		{
146			print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=ajout_photo&amp;id='.$object->id.'">';
147			print $langs->trans("AddPhoto").'</a>';
148		}
149		else
150		{
151			print '<a class="butActionRefused" href="#">e';
152			print $langs->trans("AddPhoto").'</a>';
153		}
154	}
155
156	print "\n</div>\n";
157
158	/*
159	 * Add a photo
160	*/
161	if ($action == 'ajout_photo' && ($user->rights->produit->creer || $user->rights->service->creer) && ! empty($conf->global->MAIN_UPLOAD_DOC))
162	{
163		// Affiche formulaire upload
164		$formfile=new FormFile($db);
165		$formfile->form_attach_new_file($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans("AddPhoto"),1);
166	}
167
168	// Affiche photos
169	if ($action != 'ajout_photo')
170	{
171		$nbphoto=0;
172		$nbbyrow=5;
173
174		$maxWidth = 160;
175		$maxHeight = 120;
176
177		print $object->show_photos($dir,1,1000,$nbbyrow,1,1);
178
179		if ($object->nbphoto < 1)
180		{
181			print '<br>';
182			print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';				print '<tr align=center valign=middle border=1><td class="photo">';
183			print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
184			print '</td></tr>';
185			print '</table>';
186		}
187	}
188}
189else
190{
191	print $langs->trans("ErrorUnknown");
192}
193
194
195llxFooter();
196$db->close();
197?>