dolibarr 25.0.0-alpha
multicompany_page.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This file is a modified version of datepicker.php from phpBSM to fix some
7 * bugs, to add new features and to dramatically increase speed.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
29//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
30//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
31//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
32if (!defined('NOCSRFCHECK')) {
33 define('NOCSRFCHECK', 1);
34}
35if (!defined('NOTOKENRENEWAL')) {
36 define('NOTOKENRENEWAL', 1);
37}
38if (!defined('NOREQUIREMENU')) {
39 define('NOREQUIREMENU', 1);
40}
41//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
42
43require_once '../main.inc.php';
52$action = GETPOST('action', 'aZ');
53$entityid = GETPOSTINT('entity');
54$backtourl = GETPOST('backtourl');
55if (empty($backtourl)) {
56 $backtourl = DOL_URL_ROOT;
57}
58
59if (GETPOST('lang', 'aZ09')) {
60 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
61}
62
63$langs->load("main");
64
65$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
66$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
67
68if (!isModEnabled('multicompany')) {
69 httponly_accessforbidden('No multicompany module enabled');
70}
71
72
73/*
74 * Actions
75 */
76
77if ($action == 'switchentity') { // Test on permission not required here. Test will be done on the targeted page.
78 if (isset($mc) && is_object($mc)) {
79 $mc->switchEntity($entityid);
80 }
81
82 header("Location: ".$backtourl);
83 exit(0);
84}
85
86
87
88/*
89 * View
90 */
91
92$title = $langs->trans("Multicompanies");
93
94// URL http://mydolibarr/core/multicompany_page?dol_use_jmobile=1 can be used for tests
95$head = '<!-- Multicompany selection -->'."\n"; // This is used by DoliDroid to know page is a multicompany selection page
96$arrayofjs = array();
97$arrayofcss = array();
98top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
99
100
101print '<body>'."\n";
102print '<div>';
103//print '<br>';
104
105// Define $multicompanyList
106$multicompanyList = '';
107
108$bookmarkList = '';
109if (!isModEnabled('multicompany')) {
110 $langs->load("admin");
111 $multicompanyList .= '<br><span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("MultiCompany")).'</span>';
112 $multicompanyList .= '<br><br>';
113} elseif (!empty($user->entity) && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) { // Should not be accessible if the option to centralize users on the main entity is not activated
114 $langs->load("errors");
115 $multicompanyList .= '<br><span class="opacitymedium">'.$langs->trans("ErrorForbidden").'</span>';
116 $multicompanyList .= '<br><br>';
117} else {
118 // Instantiate hooks of thirdparty module
119 $hookmanager->initHooks(array('multicompany'));
120
121 if (isset($mc) && is_object($mc)) {
122 $listofentities = $mc->getEntitiesList(true, false, true);
123 } else {
124 $listofentities = array();
125 }
126
127 $multicompanyList .= '<ul class="ullistonly left" style="list-style: none; padding: 10px; padding-top: 20px;">';
128
129 // Get list of all images for all entities
130 // Logo is inside MAIN_INFO_SOCIETE_LOGO_SQUARRED/_MINI/_SMALL else MAIN_INFO_SOCIETE_LOGO/_MINI/_SMALL
131 $imagesofentities = array();
132 $sql = "SELECT entity, name, value FROM ".MAIN_DB_PREFIX."const";
133 $sql .= " WHERE name in ('MAIN_INFO_SOCIETE_LOGO', 'MAIN_INFO_SOCIETE_LOGO_MINI', 'MAIN_INFO_SOCIETE_LOGO_SQUARRED', 'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI')";
134 $sql .= " GROUP BY entity, name, value";
135 $sql .= " ORDER BY entity, name, value";
136 $resql = $db->query($sql);
137 if ($resql) {
138 while ($obj = $db->fetch_object($resql)) {
139 // The ...LOGO_MINI is after ...LOGO in list and the SQUARRED is after the normal, so the mini squarred is at end
140 // and will overwrite the main image.
141 // We ignore the ...LOGO_SMALL that will overwrite the mini.
142 if ($obj->name == 'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI') {
143 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'mini');
144 } elseif ($obj->name == 'MAIN_INFO_SOCIETE_LOGO_MINI') {
145 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'mini');
146 } elseif ($obj->name == 'MAIN_INFO_SOCIETE_LOGO_SQUARRED') {
147 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'normal');
148 } elseif ($obj->name == 'MAIN_INFO_SOCIETE_LOGO') {
149 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'normal');
150 }
151 }
152 }
153
154 foreach ($listofentities as $entityid => $entitycursor) {
155 // Check if the user has the right to access the entity
156 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && !empty($user->entity) && $mc->checkRight($user->id, (string) $entityid) < 0) {
157 continue;
158 }
159 $url = DOL_URL_ROOT.'/core/multicompany_page.php?action=switchentity&token='.newToken().'&entity='.((int) $entityid).($backtourl ? '&backtourl='.urlencode($backtourl) : '');
160 $multicompanyList .= '<li class="lilistonly" style="height: 4em; font-size: 1.5em;">';
161 $multicompanyList .= '<a class="dropdown-item multicompany-item paddingtopimp paddingbottomimp" id="multicompany-item-'.$entityid.'" data-id="'.$entityid.'" href="'.dol_escape_htmltag($url).'">';
162
163 $urlforimage = DOL_URL_ROOT.'/public/theme/common/company.png';
164 if (!empty($imagesofentities[$entityid])) {
165 if ($imagesofentities[$entityid]['type'] == 'mini') {
166 $urlforimage = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$entityid.'&file='.urlencode('logos/thumbs/'.$imagesofentities[$entityid]['file']);
167 } else {
168 $urlforimage = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$entityid.'&file='.urlencode('logos/'.$imagesofentities[$entityid]['file']);
169 }
170 }
171 $multicompanyList .= '<img class="photocontact photorefnoborder valignmiddle marginrightonly" alt="" src="'.$urlforimage.'">';
172
173 $multicompanyList .= dol_escape_htmltag($entitycursor);
174 if ($conf->entity == $entityid) {
175 $multicompanyList .= ' <span class="opacitymedium">'.img_picto($langs->trans("Currently"), 'tick').'</span>';
176 }
177 $multicompanyList .= '</a>';
178 $multicompanyList .= '</li>';
179 }
180 $multicompanyList .= '</ul>';
181
182 // Execute hook printBookmarks
183 $parameters = array('multicompany' => $multicompanyList);
184 $reshook = $hookmanager->executeHooks('printMultiCompanyEntities', $parameters); // Note that $action and $object may have been modified by some hooks
185 if (empty($reshook)) {
186 $multicompanyList .= $hookmanager->resPrint;
187 } else {
188 $multicompanyList = $hookmanager->resPrint;
189 }
190}
191
192print "\n";
193print "<!-- Begin Multicompany list -->\n";
194print '<div class="center"><div class="center" style="padding: 6px;">';
195print '<style>.menu_titre { padding-top: 7px; }</style>';
196print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
197print $multicompanyList;
198print '</div>'."\n";
199print '</div></div>';
200print "\n<!-- End Multicompany list -->\n";
201
202print '</div>';
203print '</body></html>'."\n";
204
205$db->close();
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.