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