dolibarr 20.0.0
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') {
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: 0">';
121 foreach ($listofentities as $entityid => $entitycursor) {
122 // Check if the user has the right to access the entity
123 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && !empty($user->entity) && $mc->checkRight($user->id, $entityid) < 0) {
124 continue;
125 }
126 $url = DOL_URL_ROOT.'/core/multicompany_page.php?action=switchentity&token='.newToken().'&entity='.((int) $entityid).($backtourl ? '&backtourl='.urlencode($backtourl) : '');
127 $multicompanyList .= '<li class="lilistonly" style="height: 2.5em; font-size: 1.15em;">';
128 $multicompanyList .= '<a class="dropdown-item multicompany-item paddingtopimp paddingbottomimp" id="multicompany-item-'.$entityid.'" data-id="'.$entityid.'" href="'.dol_escape_htmltag($url).'">';
129 $multicompanyList .= img_picto('', 'entity', 'class="pictofixedwidth"');
130 $multicompanyList .= dol_escape_htmltag($entitycursor);
131 if ($conf->entity == $entityid) {
132 $multicompanyList .= ' <span class="opacitymedium">'.img_picto($langs->trans("Currently"), 'tick').'</span>';
133 }
134 $multicompanyList .= '</a>';
135 $multicompanyList .= '</li>';
136 }
137 $multicompanyList .= '</ul>';
138
139 // Execute hook printBookmarks
140 $parameters = array('multicompany' => $multicompanyList);
141 $reshook = $hookmanager->executeHooks('printMultiCompanyEntities', $parameters); // Note that $action and $object may have been modified by some hooks
142 if (empty($reshook)) {
143 $multicompanyList .= $hookmanager->resPrint;
144 } else {
145 $multicompanyList = $hookmanager->resPrint;
146 }
147}
148
149print "\n";
150print "<!-- Begin Multicompany list -->\n";
151print '<div class="center"><div class="center" style="padding: 6px;">';
152print '<style>.menu_titre { padding-top: 7px; }</style>';
153print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
154print $multicompanyList;
155print '</div>'."\n";
156print '</div></div>';
157print "\n<!-- End Multicompany list -->\n";
158
159print '</div>';
160print '</body></html>'."\n";
161
162$db->close();
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.