dolibarr  16.0.5
index.php
1 <?php
2 /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
18 //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
19 //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
20 if (!defined('NOREQUIRESOC')) {
21  define('NOREQUIRESOC', '1');
22 }
23 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
24 if (!defined('NOCSRFCHECK')) {
25  define('NOCSRFCHECK', '1');
26 }
27 if (!defined('NOTOKENRENEWAL')) {
28  define('NOTOKENRENEWAL', '1');
29 }
30 if (!defined('NOREQUIREMENU')) {
31  define('NOREQUIREMENU', '1');
32 }
33 if (!defined('NOREQUIREHTML')) {
34  define('NOREQUIREHTML', '1');
35 }
36 if (!defined('NOREQUIREAJAX')) {
37  define('NOREQUIREAJAX', '1');
38 }
39 
40 if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
41  require '../../main.inc.php'; // Load $user and permissions
42 }
43 
44 $id = GETPOST('id', 'int');
45 $w = GETPOST('w', 'int');
46 $h = GETPOST('h', 'int');
47 $query = GETPOST('query', 'alpha');
48 
49 
50 
51 /*
52  * View
53  */
54 
55 if ($query == "cat") {
56  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
57  require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
58 
59  $object = new Categorie($db);
60  $result = $object->fetch($id);
61 
62  $upload_dir = $conf->categorie->multidir_output[$object->entity];
63  $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
64  $dir = $upload_dir.'/'.$pdir;
65 
66  foreach ($object->liste_photos($dir) as $key => $obj) {
67  if ($obj['photo_vignette']) {
68  $filename = $obj['photo_vignette'];
69  } else {
70  $filename = $obj['photo'];
71  }
72  $file = DOL_URL_ROOT.'/viewimage.php?cache=1&publictakepos=1&modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename);
73  header('Location: '.$file);
74  exit;
75  }
76  header('Location: ../../public/theme/common/nophoto.png');
77 } elseif ($query == "pro") {
78  require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
79 
80  $objProd = new Product($db);
81  $objProd->fetch($id);
82  $image = $objProd->show_photos('product', $conf->product->multidir_output[$objProd->entity], 'small', 1);
83 
84  $match = array();
85  preg_match('@src="([^"]+)"@', $image, $match);
86  $file = array_pop($match);
87  if ($file == "") {
88  header('Location: ../../public/theme/common/nophoto.png');
89  } else {
90  if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
91  header('Location: '.$file.'&cache=1');
92  } else {
93  header('Location: '.$file.'&cache=1&publictakepos=1&modulepart=product');
94  }
95  }
96 } else {
97  // TODO We don't need this. Size of image must be defined on HTML page, image must NOT be resize when downloaded.
98 
99  // The file
100  $filename = $query.".jpg";
101 
102  // Dimensions
103  list($width, $height) = getimagesize($filename);
104  $new_width = $w;
105  $new_height = $h;
106 
107  // Resample
108  $image_p = imagecreatetruecolor($new_width, $new_height);
109  $image = imagecreatefromjpeg($filename);
110  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
111 
112  // Output
113  imagejpeg($image_p, null, 100);
114 }
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
Categorie
Class to manage categories.
Definition: categorie.class.php:47
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
Product
Class to manage products or services.
Definition: product.class.php:46