multicompany_page.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. /**
  21. * \file htdocs/core/multicompany_page.php
  22. * \brief File to return a page with the list of all entities user can switch to
  23. */
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  25. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
  28. if (!defined('NOCSRFCHECK')) {
  29. define('NOCSRFCHECK', 1);
  30. }
  31. if (!defined('NOTOKENRENEWAL')) {
  32. define('NOTOKENRENEWAL', 1);
  33. }
  34. //if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
  35. if (!defined('NOREQUIREMENU')) {
  36. define('NOREQUIREMENU', 1);
  37. }
  38. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
  39. require_once '../main.inc.php';
  40. $action = GETPOST('action', 'aZ');
  41. $entityid = GETPOST('entity', 'int');
  42. $backtourl = GETPOST('backtourl');
  43. if (empty($backtourl)) {
  44. $backtourl = DOL_URL_ROOT;
  45. }
  46. if (GETPOST('lang', 'aZ09')) {
  47. $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
  48. }
  49. $langs->load("main");
  50. $right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
  51. $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
  52. /*
  53. * Actions
  54. */
  55. if ($action == 'switchentity') {
  56. if (is_object($mc)) {
  57. $mc->switchEntity($entityid);
  58. }
  59. header("Location: ".$backtourl);
  60. exit(0);
  61. }
  62. /*
  63. * View
  64. */
  65. $title = $langs->trans("Multicompanies");
  66. // URL http://mydolibarr/core/multicompany_page?dol_use_jmobile=1 can be used for tests
  67. $head = '<!-- Multicompany selection -->'."\n"; // This is used by DoliDroid to know page is a multicompany selection page
  68. $arrayofjs = array();
  69. $arrayofcss = array();
  70. top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
  71. print '<body>'."\n";
  72. print '<div>';
  73. //print '<br>';
  74. if (empty($conf->multicompany->enabled)) {
  75. $langs->load("admin");
  76. $bookmarkList .= '<br><span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("MultiCompany")).'</span>';
  77. $bookmarkList .= '<br><br>';
  78. } else {
  79. // Instantiate hooks of thirdparty module
  80. $hookmanager->initHooks(array('multicompany'));
  81. // Define $bookmarks
  82. $multicompanyList = '';
  83. $searchForm = '';
  84. if (is_object($mc)) {
  85. $listofentities = $mc->getEntitiesList($user->login, false, true);
  86. }
  87. $multicompanyList .= '<ul class="ullistonly left" style="list-style: none;">';
  88. foreach ($listofentities as $entityid => $entitycursor) {
  89. $url = DOL_URL_ROOT.'/core/multicompany_page.php?action=switchentity&token='.newToken().'&entity='.((int) $entityid).($backtourl ? '&backtourl='.urlencode($backtourl) : '');
  90. $multicompanyList .= '<li class="lilistonly" style="height: 2.5em; font-size: 1.15em;">';
  91. $multicompanyList .= '<a class="dropdown-item multicompany-item" id="multicompany-item-'.$entityid.'" data-id="'.$entityid.'" href="'.dol_escape_htmltag($url).'">';
  92. $multicompanyList .= img_picto('', 'entity', 'class="pictofixedwidth"');
  93. $multicompanyList .= dol_escape_htmltag($entitycursor);
  94. if ($conf->entity == $entityid) {
  95. $multicompanyList .= ' <span class="opacitymedium">('.$langs->trans("Currently").')</span>';
  96. }
  97. $multicompanyList .= '</a>';
  98. $multicompanyList .= '</li>';
  99. }
  100. $multicompanyList .= '</ul>';
  101. $searchForm .= '<input name="bookmark" id="top-multicompany-search-input" class="dropdown-search-input" placeholder="'.$langs->trans('Entity').'" autocomplete="off" >';
  102. // Execute hook printBookmarks
  103. $parameters = array('multicompany'=>$multicompanyList);
  104. $reshook = $hookmanager->executeHooks('printMultiCompanyEntities', $parameters); // Note that $action and $object may have been modified by some hooks
  105. if (empty($reshook)) {
  106. $multicompanyList .= $hookmanager->resPrint;
  107. } else {
  108. $multicompanyList = $hookmanager->resPrint;
  109. }
  110. print "\n";
  111. print "<!-- Begin Multicompany list -->\n";
  112. print '<div class="center"><div class="center" style="padding: 6px;">';
  113. print '<style>.menu_titre { padding-top: 7px; }</style>';
  114. print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
  115. print $multicompanyList;
  116. print '</div>'."\n";
  117. print '</div></div>';
  118. print "\n<!-- End SearchForm -->\n";
  119. }
  120. print '</div>';
  121. print '</body></html>'."\n";
  122. $db->close();