PageRenderTime 175ms CodeModel.GetById 70ms app.highlight 64ms RepoModel.GetById 37ms app.codeStats 0ms

/htdocs/categories/photos.php

https://github.com/asterix14/dolibarr
PHP | 308 lines | 158 code | 57 blank | 93 comment | 53 complexity | ac20a985d9700416042926149ba7d18d MD5 | raw file
  1<?php
  2/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2010 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005      Eric Seigne          <eric.seigne@ryxeo.com>
  5 * Copyright (C) 2005-2011 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/categories/photos.php
 23 *       \ingroup    category
 24 *       \brief      Gestion des photos d'une categorie
 25 */
 26
 27require("../main.inc.php");
 28require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
 29require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
 30require_once(DOL_DOCUMENT_ROOT."/core/lib/categories.lib.php");
 31
 32$langs->load("categories");
 33$langs->load("bills");
 34
 35
 36$mesg = '';
 37
 38$id=GETPOST('id');
 39$ref=GETPOST('ref');
 40$type=GETPOST('type');
 41$action=GETPOST('action');
 42$confirm=GETPOST('confirm');
 43
 44if ($id == "")
 45{
 46    dol_print_error('','Missing parameter id');
 47    exit();
 48}
 49
 50// Security check
 51$result = restrictedArea($user, 'categorie', $id);
 52
 53$object = new Categorie($db);
 54
 55/*
 56 * Actions
 57 */
 58
 59if ($_FILES['userfile']['size'] > 0 && $_POST["sendit"] && ! empty($conf->global->MAIN_UPLOAD_DOC))
 60{
 61    if ($id)
 62    {
 63        $result = $object->fetch($id);
 64
 65        $result = $object->add_photo($conf->categorie->dir_output, $_FILES['userfile']);
 66    }
 67}
 68
 69if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->rights->categorie->creer)
 70{
 71    $object->delete_photo($conf->categorie->dir_output."/".$_GET["file"]);
 72}
 73
 74if ($action == 'addthumb' && $_GET["file"])
 75{
 76    $object->add_thumb($conf->categorie->dir_output."/".$_GET["file"]);
 77}
 78
 79
 80/*
 81 * View
 82 */
 83
 84llxHeader("","",$langs->trans("Categories"));
 85
 86$form = new Form($db);
 87
 88if (!empty($id) || !empty($ref))
 89{
 90    $result = $object->fetch($id);
 91
 92    if ($result)
 93    {
 94        $title=$langs->trans("ProductsCategoryShort");
 95        if ($type == 0) $title=$langs->trans("ProductsCategoryShort");
 96        elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort");
 97        elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort");
 98        elseif ($type == 3) $title=$langs->trans("MembersCategoryShort");
 99
100        $head = categories_prepare_head($object,$type);
101        dol_fiche_head($head, 'photos', $title, 0, 'category');
102
103        /*
104         * Confirmation de la suppression de photo
105         */
106        if ($action == 'delete')
107        {
108            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&type='.$type.'&file='.$_GET["file"], $langs->trans('DeletePicture'), $langs->trans('ConfirmDeletePicture'), 'confirm_delete', '', 0, 1);
109            if ($ret == 'html') print '<br>';
110        }
111
112        print($mesg);
113
114        print '<table class="border" width="100%">';
115
116        // Path of category
117        print '<tr><td width="20%" class="notopnoleft">';
118        $ways = $object->print_all_ways();
119        print $langs->trans("Ref").'</td><td>';
120        print '<a href="'.DOL_URL_ROOT.'/categories/index.php?leftmenu=cat&type='.$type.'">'.$langs->trans("Root").'</a> >> ';
121        foreach ($ways as $way)
122        {
123            print $way."<br>\n";
124        }
125        print '</td></tr>';
126
127        // Description
128        print '<tr><td width="20%" class="notopnoleft">';
129        print $langs->trans("Description").'</td><td>';
130        print nl2br($object->description);
131        print '</td></tr>';
132
133        // Visibility
134        /*		if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
135        {
136        if ($object->socid)
137        {
138        $soc = new Societe($db);
139        $soc->fetch($object->socid);
140
141        print '<tr><td width="20%" class="notopnoleft">';
142        print $langs->trans("AssignedToTheCustomer").'</td><td>';
143        print $soc->getNomUrl(1);
144        print '</td></tr>';
145
146        $catsMeres = $object->get_meres ();
147
148        if ($catsMeres < 0)
149        {
150        dol_print_error();
151        }
152        else if (count($catsMeres) > 0)
153        {
154        print '<tr><td width="20%" class="notopnoleft">';
155        print $langs->trans("CategoryContents").'</td><td>';
156        print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
157        print '</td></tr>';
158        }
159        }
160        else
161        {
162        print '<tr><td width="20%" class="notopnoleft">';
163        print $langs->trans("CategoryContents").'</td><td>';
164        print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
165        print '</td></tr>';
166        }
167        }
168        else
169        {
170        print '<tr><td width="20%" class="notopnoleft">';
171        print $langs->trans("CategoryContents").'</td><td>';
172        print ($object->visible ? $langs->trans("Visible") : $langs->trans("Invisible"));
173        print '</td></tr>';
174        }
175        */
176
177        print "</table>\n";
178
179        print "</div>\n";
180
181
182
183        /* ************************************************************************** */
184        /*                                                                            */
185        /* Barre d'action                                                             */
186        /*                                                                            */
187        /* ************************************************************************** */
188
189        print "\n<div class=\"tabsAction\">\n";
190
191        if ($action != 'ajout_photo' && $user->rights->produit->creer)
192        {
193            if (! empty($conf->global->MAIN_UPLOAD_DOC))
194            {
195                print '<a class="butAction" href="'.DOL_URL_ROOT.'/categories/photos.php?action=ajout_photo&amp;id='.$object->id.'&amp;type='.$type.'">';
196                print $langs->trans("AddPhoto").'</a>';
197            }
198            else
199            {
200                print '<a class="butActionRefused" href="#">';
201                print $langs->trans("AddPhoto").'</a>';
202            }
203        }
204
205        print "\n</div>\n";
206
207        /*
208         * Ajouter une photo
209         */
210        if ($action == 'ajout_photo' && $user->rights->categorie->creer && ! empty($conf->global->MAIN_UPLOAD_DOC))
211        {
212            // Affiche formulaire upload
213            $formfile=new FormFile($db);
214            $formfile->form_attach_new_file(DOL_URL_ROOT.'/categories/photos.php?id='.$object->id.'&amp;type='.$type,$langs->trans("AddPhoto"),1);
215        }
216
217        // Affiche photos
218        if ($action != 'ajout_photo')
219        {
220            $nbphoto=0;
221            $nbbyrow=5;
222
223            $maxWidth = 160;
224            $maxHeight = 120;
225
226            $pdir = get_exdir($object->id,2) . $object->id ."/photos/";
227            $dir = $conf->categorie->dir_output.'/'.$pdir;
228
229            print '<br>';
230            print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
231
232            foreach ($object->liste_photos($dir) as $key => $obj)
233            {
234                $nbphoto++;
235
236
237                if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>';
238                if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">';
239
240                print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=categorie&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">';
241
242                // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
243                if ($obj['photo_vignette'])
244                {
245                    $filename='thumbs/'.$obj['photo_vignette'];
246                }
247                else
248                {
249                    $filename=$obj['photo'];
250                }
251
252                // Nom affiche
253                $viewfilename=$obj['photo'];
254
255                // Taille de l'image
256                $object->get_image_size($dir.$filename);
257                $imgWidth = ($object->imgWidth < $maxWidth) ? $object->imgWidth : $maxWidth;
258                $imgHeight = ($object->imgHeight < $maxHeight) ? $object->imgHeight : $maxHeight;
259
260                print '<img border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=categorie&file='.urlencode($pdir.$filename).'">';
261
262                print '</a>';
263                print '<br>'.$viewfilename;
264                print '<br>';
265
266                // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
267                if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($object->imgWidth > $maxWidth || $object->imgHeight > $maxHeight))
268                {
269                    print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=addthumb&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').'&nbsp;&nbsp;</a>';
270                }
271                if ($user->rights->categorie->creer)
272                {
273                    print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=delete&amp;type='.$type.'&amp;file='.urlencode($pdir.$viewfilename).'">';
274                    print img_delete().'</a>';
275                }
276                if ($nbbyrow) print '</td>';
277                if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>';
278            }
279
280            // Ferme tableau
281            while ($nbphoto % $nbbyrow)
282            {
283                print '<td width="'.ceil(100/$nbbyrow).'%">&nbsp;</td>';
284                $nbphoto++;
285            }
286
287            if ($nbphoto < 1)
288            {
289                print '<tr align=center valign=middle border=1><td class="photo">';
290                print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
291                print '</td></tr>';
292            }
293
294            print '</table>';
295        }
296    }
297}
298else
299{
300    print $langs->trans("ErrorUnknown");
301}
302
303
304
305$db->close();
306
307llxFooter();
308?>