dolibarr 19.0.3
multicompany_page.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 *
4 * This file is a modified version of datepicker.php from phpBSM to fix some
5 * bugs, to add new features and to dramatically increase speed.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
27//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
28//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
29//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
30if (!defined('NOCSRFCHECK')) {
31 define('NOCSRFCHECK', 1);
32}
33if (!defined('NOTOKENRENEWAL')) {
34 define('NOTOKENRENEWAL', 1);
35}
36//if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
37if (!defined('NOREQUIREMENU')) {
38 define('NOREQUIREMENU', 1);
39}
40//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
41
42require_once '../main.inc.php';
43
44$action = GETPOST('action', 'aZ');
45$entityid = GETPOST('entity', 'int');
46$backtourl = GETPOST('backtourl');
47if (empty($backtourl)) {
48 $backtourl = DOL_URL_ROOT;
49}
50
51if (GETPOST('lang', 'aZ09')) {
52 $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
53}
54
55$langs->load("main");
56
57$right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
58$left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
59
60
61
62/*
63 * Actions
64 */
65
66if ($action == 'switchentity') {
67 if (is_object($mc)) {
68 $mc->switchEntity($entityid);
69 }
70
71 header("Location: ".$backtourl);
72 exit(0);
73}
74
75
76
77/*
78 * View
79 */
80
81$title = $langs->trans("Multicompanies");
82
83// URL http://mydolibarr/core/multicompany_page?dol_use_jmobile=1 can be used for tests
84$head = '<!-- Multicompany selection -->'."\n"; // This is used by DoliDroid to know page is a multicompany selection page
85$arrayofjs = array();
86$arrayofcss = array();
87top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
88
89
90print '<body>'."\n";
91print '<div>';
92//print '<br>';
93
94// Define $multicompanyList
95$multicompanyList = '';
96
97if (!isModEnabled('multicompany')) {
98 $langs->load("admin");
99 $multicompanyList .= '<br><span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("MultiCompany")).'</span>';
100 $multicompanyList .= '<br><br>';
101} 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
102 $langs->load("errors");
103 $multicompanyList .= '<br><span class="opacitymedium">'.$langs->trans("ErrorForbidden").'</span>';
104 $multicompanyList .= '<br><br>';
105} else {
106 // Instantiate hooks of thirdparty module
107 $hookmanager->initHooks(array('multicompany'));
108
109 if (is_object($mc)) {
110 $listofentities = $mc->getEntitiesList(true, false, true);
111 }
112
113 $multicompanyList .= '<ul class="ullistonly left" style="list-style: none;">';
114 foreach ($listofentities as $entityid => $entitycursor) {
115 // Check if the user has the right to access the entity
116 if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && !empty($user->entity) && $mc->checkRight($user->id, $entityid) < 0) {
117 continue;
118 }
119 $url = DOL_URL_ROOT.'/core/multicompany_page.php?action=switchentity&token='.newToken().'&entity='.((int) $entityid).($backtourl ? '&backtourl='.urlencode($backtourl) : '');
120 $multicompanyList .= '<li class="lilistonly" style="height: 2.5em; font-size: 1.15em;">';
121 $multicompanyList .= '<a class="dropdown-item multicompany-item" id="multicompany-item-'.$entityid.'" data-id="'.$entityid.'" href="'.dol_escape_htmltag($url).'">';
122 $multicompanyList .= img_picto('', 'entity', 'class="pictofixedwidth"');
123 $multicompanyList .= dol_escape_htmltag($entitycursor);
124 if ($conf->entity == $entityid) {
125 $multicompanyList .= ' <span class="opacitymedium">('.$langs->trans("Currently").')</span>';
126 }
127 $multicompanyList .= '</a>';
128 $multicompanyList .= '</li>';
129 }
130 $multicompanyList .= '</ul>';
131
132 // Execute hook printBookmarks
133 $parameters = array('multicompany'=>$multicompanyList);
134 $reshook = $hookmanager->executeHooks('printMultiCompanyEntities', $parameters); // Note that $action and $object may have been modified by some hooks
135 if (empty($reshook)) {
136 $multicompanyList .= $hookmanager->resPrint;
137 } else {
138 $multicompanyList = $hookmanager->resPrint;
139 }
140}
141
142print "\n";
143print "<!-- Begin Multicompany list -->\n";
144print '<div class="center"><div class="center" style="padding: 6px;">';
145print '<style>.menu_titre { padding-top: 7px; }</style>';
146print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
147print $multicompanyList;
148print '</div>'."\n";
149print '</div></div>';
150print "\n<!-- End Multicompany list -->\n";
151
152print '</div>';
153print '</body></html>'."\n";
154
155$db->close();
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
Ouput html header of a page.