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