dolibarr 18.0.6
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// This page return an image of public photos of a category or product.
19// Test to check image can be publically viewed is done inside the viewimage.php wrapper.
20
21//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
22//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
23if (!defined('NOREQUIRESOC')) {
24 define('NOREQUIRESOC', '1');
25}
26//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
27if (!defined('NOTOKENRENEWAL')) {
28 define('NOTOKENRENEWAL', '1');
29}
30if (!defined('NOREQUIREMENU')) {
31 define('NOREQUIREMENU', '1');
32}
33if (!defined('NOREQUIREHTML')) {
34 define('NOREQUIREHTML', '1');
35}
36if (!defined('NOREQUIREAJAX')) {
37 define('NOREQUIREAJAX', '1');
38}
39
40if (!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
49if (!isModEnabled('takepos')) {
50 accessforbidden('Module not enabled');
51}
52
53
54/*
55 * View
56 */
57
58if ($query == "cat") {
59 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
60 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
61
62 $object = new Categorie($db);
63 $result = $object->fetch($id);
64
65 $upload_dir = $conf->categorie->multidir_output[$object->entity];
66 $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
67 $dir = $upload_dir.'/'.$pdir;
68
69 foreach ($object->liste_photos($dir) as $key => $obj) {
70 if ($obj['photo_vignette']) {
71 $filename = $obj['photo_vignette'];
72 } else {
73 $filename = $obj['photo'];
74 }
75 $file = DOL_URL_ROOT.'/viewimage.php?cache=1&publictakepos=1&modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename);
76 header('Location: '.$file);
77 exit;
78 }
79 header('Location: ../../public/theme/common/nophoto.png');
80 exit;
81} elseif ($query == "pro") {
82 require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
83
84 $objProd = new Product($db);
85 $objProd->fetch($id);
86 $image = $objProd->show_photos('product', $conf->product->multidir_output[$objProd->entity], 'small', 1);
87
88 $match = array();
89 preg_match('@src="([^"]+)"@', $image, $match);
90 $file = array_pop($match);
91 if ($file == "") {
92 header('Location: ../../public/theme/common/nophoto.png');
93 exit;
94 } else {
95 if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
96 header('Location: '.$file.'&cache=1');
97 exit;
98 } else {
99 header('Location: '.$file.'&cache=1&publictakepos=1&modulepart=product');
100 exit;
101 }
102 }
103} else {
104 // TODO We don't need this. Size of image must be defined on HTML page, image must NOT be resized when downloaded.
105
106 // The file
107 $filename = $query.".jpg";
108
109 // Dimensions
110 list($width, $height) = getimagesize($filename);
111 $new_width = $w;
112 $new_height = $h;
113
114 // Resample
115 $image_p = imagecreatetruecolor($new_width, $new_height);
116 $image = imagecreatefromjpeg($filename);
117 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
118
119 // Output
120 imagejpeg($image_p, null, 100);
121}
Class to manage categories.
Class to manage products or services.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.