dolibarr 23.0.3
index.php
1<?php
2/* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
3 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19// This page return an image of public photos of a category or product.
20// Test to check image can be publicly viewed is done inside the viewimage.php wrapper.
21
22//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
23//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
24if (!defined('NOREQUIRESOC')) {
25 define('NOREQUIRESOC', '1');
26}
27//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
28if (!defined('NOTOKENRENEWAL')) {
29 define('NOTOKENRENEWAL', '1');
30}
31if (!defined('NOREQUIREMENU')) {
32 define('NOREQUIREMENU', '1');
33}
34if (!defined('NOREQUIREHTML')) {
35 define('NOREQUIREHTML', '1');
36}
37if (!defined('NOREQUIREAJAX')) {
38 define('NOREQUIREAJAX', '1');
39}
40
41if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
42 require '../../main.inc.php'; // Load $user and permissions
43}
47$id = GETPOSTINT('id');
48$w = GETPOSTINT('w');
49$h = GETPOSTINT('h');
50$query = GETPOST('query', 'alpha');
51
52if (!isModEnabled('takepos')) {
53 accessforbidden('Module not enabled');
54}
55
56
57/*
58 * View
59 */
60
61if ($query == "cat") {
62 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
63 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
64
65 $object = new Categorie($db);
66 $result = $object->fetch($id);
67
68 $upload_dir = $conf->categorie->multidir_output[$object->entity ?? $conf->entity];
69 $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
70 $dir = $upload_dir.'/'.$pdir;
71
72 foreach ($object->liste_photos($dir) as $key => $obj) {
73 if ($obj['photo_vignette']) {
74 $filename = $obj['photo_vignette'];
75 } else {
76 $filename = $obj['photo'];
77 }
78 $file = DOL_URL_ROOT.'/viewimage.php?cache=1&publictakepos=1&modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename);
79 header('Location: '.$file);
80 exit;
81 }
82 header('Location: ../../public/theme/common/nophoto.png');
83 exit;
84} elseif ($query == "pro") {
85 require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
86
87 $objProd = new Product($db);
88 $objProd->fetch($id);
89 $image = $objProd->show_photos('product', $conf->product->multidir_output[$objProd->entity ?? $conf->entity], 'small', 1);
90
91 $match = array();
92 preg_match('@src="([^"]+)"@', $image, $match);
93 $file = array_pop($match);
94 if ($file == "") {
95 header('Location: ../../public/theme/common/nophoto.png');
96 exit;
97 } else {
98 if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
99 header('Location: '.$file.'&cache=1');
100 exit;
101 } else {
102 header('Location: '.$file.'&cache=1&publictakepos=1&modulepart=product');
103 exit;
104 }
105 }
106} else {
107 print 'Invalid param query. Must be "cat" or "pro"';
108}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage categories.
Class to manage products or services.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
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.