dolibarr 21.0.0-beta
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 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 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}
38//if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
39if (!defined('NOREQUIREMENU')) {
40 define('NOREQUIREMENU', 1);
41}
42//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
43
44require_once '../main.inc.php';
53$action = GETPOST('action', 'aZ');
54$entityid = GETPOSTINT('entity');
55$backtourl = GETPOST('backtourl');
56if (empty($backtourl)) {
57 $backtourl = DOL_URL_ROOT;
58}
59
60if (GETPOST('lang', 'aZ09')) {
61 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
62}
63
64$langs->load("main");
65
66$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
67$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
68
69if (!isModEnabled('multicompany')) {
70 httponly_accessforbidden('No multicompany module enabled');
71}
72
73
74/*
75 * Actions
76 */
77
78if ($action == 'switchentity') { // Test on permission not required here. Test will be done on the targeted page.
79 if (is_object($mc)) {
80 $mc->switchEntity($entityid);
81 }
82
83 header("Location: ".$backtourl);
84 exit(0);
85}
86
87
88
89/*
90 * View
91 */
92
93$title = $langs->trans("Multicompanies");
94
95// URL http://mydolibarr/core/multicompany_page?dol_use_jmobile=1 can be used for tests
96$head = '<!-- Multicompany selection -->'."\n"; // This is used by DoliDroid to know page is a multicompany selection page
97$arrayofjs = array();
98$arrayofcss = array();
99top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
100
101
102print '<body>'."\n";
103print '<div>';
104//print '<br>';
105
106// Define $multicompanyList
107$multicompanyList = '';
108
109$bookmarkList = '';
110if (!isModEnabled('multicompany')) {
111 $langs->load("admin");
112 $multicompanyList .= '<br><span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("MultiCompany")).'</span>';
113 $multicompanyList .= '<br><br>';
114} 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
115 $langs->load("errors");
116 $multicompanyList .= '<br><span class="opacitymedium">'.$langs->trans("ErrorForbidden").'</span>';
117 $multicompanyList .= '<br><br>';
118} else {
119 // Instantiate hooks of thirdparty module
120 $hookmanager->initHooks(array('multicompany'));
121
122 if (is_object($mc)) {
123 $listofentities = $mc->getEntitiesList(true, false, true);
124 } else {
125 $listofentities = array();
126 }
127
128 $multicompanyList .= '<ul class="ullistonly left" style="list-style: none; padding: 10px; padding-top: 20px;">';
129
130 // Get list of all images for all entities
131 // Logo is inside MAIN_INFO_SOCIETE_LOGO_SQUARRED/_MINI/_SMALL else MAIN_INFO_SOCIETE_LOGO/_MINI/_SMALL
132 $imagesofentities = array();
133 $sql = "SELECT entity, name, value FROM ".MAIN_DB_PREFIX."const";
134 $sql .= " WHERE name in ('MAIN_INFO_SOCIETE_LOGO', 'MAIN_INFO_SOCIETE_LOGO_MINI', 'MAIN_INFO_SOCIETE_LOGO_SQUARRED', 'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI')";
135 $sql .= " GROUP BY entity, name, value";
136 $sql .= " ORDER BY entity, name, value";
137 $resql = $db->query($sql);
138 if ($resql) {
139 while ($obj = $db->fetch_object($resql)) {
140 // The ...LOGO_MINI is after ...LOGO in list and the SQUARRED is after the normal, so the mini squarred is at end
141 // and will overwrite the main image.
142 // We ignore the ...LOGO_SMALL that will overwrite the mini.
143 if ($obj->name == 'MAIN_INFO_SOCIETE_LOGO_SQUARRED_MINI') {
144 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'mini');
145 } elseif ($obj->name == 'MAIN_INFO_SOCIETE_LOGO_MINI') {
146 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'mini');
147 } elseif ($obj->name == 'MAIN_INFO_SOCIETE_LOGO_SQUARRED') {
148 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'normal');
149 } elseif ($obj->name == 'MAIN_INFO_SOCIETE_LOGO') {
150 $imagesofentities[$obj->entity] = array('file' => $obj->value, 'type' => 'normal');
151 }
152 }
153 }
154
155 foreach ($listofentities as $entityid => $entitycursor) {
156 // Check if the user has the right to access the entity
157 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && !empty($user->entity) && $mc->checkRight($user->id, $entityid) < 0) {
158 continue;
159 }
160 $url = DOL_URL_ROOT.'/core/multicompany_page.php?action=switchentity&token='.newToken().'&entity='.((int) $entityid).($backtourl ? '&backtourl='.urlencode($backtourl) : '');
161 $multicompanyList .= '<li class="lilistonly" style="height: 4em; font-size: 1.5em;">';
162 $multicompanyList .= '<a class="dropdown-item multicompany-item paddingtopimp paddingbottomimp" id="multicompany-item-'.$entityid.'" data-id="'.$entityid.'" href="'.dol_escape_htmltag($url).'">';
163
164 $urlforimage = DOL_URL_ROOT.'/public/theme/common/company.png';
165 if (!empty($imagesofentities[$entityid])) {
166 if ($imagesofentities[$entityid]['type'] == 'mini') {
167 $urlforimage = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$entityid.'&file='.urlencode('logos/thumbs/'.$imagesofentities[$entityid]['file']);
168 } else {
169 $urlforimage = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&entity='.$entityid.'&file='.urlencode('logos/'.$imagesofentities[$entityid]['file']);
170 }
171 }
172 $multicompanyList .= '<img class="photocontact photorefnoborder valignmiddle marginrightonly" alt="" src="'.$urlforimage.'">';
173
174 $multicompanyList .= dol_escape_htmltag($entitycursor);
175 if ($conf->entity == $entityid) {
176 $multicompanyList .= ' <span class="opacitymedium">'.img_picto($langs->trans("Currently"), 'tick').'</span>';
177 }
178 $multicompanyList .= '</a>';
179 $multicompanyList .= '</li>';
180 }
181 $multicompanyList .= '</ul>';
182
183 // Execute hook printBookmarks
184 $parameters = array('multicompany' => $multicompanyList);
185 $reshook = $hookmanager->executeHooks('printMultiCompanyEntities', $parameters); // Note that $action and $object may have been modified by some hooks
186 if (empty($reshook)) {
187 $multicompanyList .= $hookmanager->resPrint;
188 } else {
189 $multicompanyList = $hookmanager->resPrint;
190 }
191}
192
193print "\n";
194print "<!-- Begin Multicompany list -->\n";
195print '<div class="center"><div class="center" style="padding: 6px;">';
196print '<style>.menu_titre { padding-top: 7px; }</style>';
197print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
198print $multicompanyList;
199print '</div>'."\n";
200print '</div></div>';
201print "\n<!-- End Multicompany list -->\n";
202
203print '</div>';
204print '</body></html>'."\n";
205
206$db->close();
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs=array(), $arrayofcss=array(), $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Output html header of a page.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.