27if (!defined(
'WEBPORTAL')) {
28 define(
'WEBPORTAL', 1);
30if (!defined(
'NOLOGIN')) {
33if (!defined(
'NOREQUIREUSER')) {
34 define(
'NOREQUIREUSER', 1);
36if (!defined(
'NOREQUIREMENU')) {
37 define(
'NOREQUIREMENU', 1);
39if (!defined(
'NOREQUIRESOC')) {
40 define(
'NOREQUIRESOC', 1);
42if (!defined(
'EVEN_IF_ONLY_LOGIN_ALLOWED')) {
43 define(
'EVEN_IF_ONLY_LOGIN_ALLOWED', 1);
45if (!defined(
'NOIPCHECK')) {
46 define(
'NOIPCHECK', 1);
50if (!function_exists(
'dol_getprefix')) {
60 function dol_getprefix($mode =
'')
62 global $dolibarr_main_instance_unique_id,
63 $dolibarr_main_cookie_cryptkey;
65 $tmp_instance_unique_id = empty($dolibarr_main_instance_unique_id) ?
66 (empty($dolibarr_main_cookie_cryptkey) ?
'' :
67 $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id;
71 if (!empty($tmp_instance_unique_id)) {
72 return sha1(
'webportal' . $tmp_instance_unique_id);
74 return sha1(
'webportal' . $_SERVER[
'SERVER_NAME'].$_SERVER[
'DOCUMENT_ROOT'].DOL_DOCUMENT_ROOT);
80include
'../../main.inc.php';
82require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
83require_once DOL_DOCUMENT_ROOT .
'/societe/class/societeaccount.class.php';
84require_once DOL_DOCUMENT_ROOT .
'/public/webportal/lib/webportal.lib.php';
85require_once DOL_DOCUMENT_ROOT .
'/webportal/class/context.class.php';
86require_once DOL_DOCUMENT_ROOT .
'/webportal/class/webportalmember.class.php';
87require_once DOL_DOCUMENT_ROOT .
'/webportal/class/webportalpartnership.class.php';
92$prefix = dol_getprefix(
'');
93$sessionname =
'WEBPORTAL_SESSID_' . $prefix;
94$sessiontimeout =
'WEBPORTAL_SESSTIMEOUT_' . $prefix;
95if (!empty($_COOKIE[$sessiontimeout]) && session_status() === PHP_SESSION_NONE) {
96 ini_set(
'session.gc_maxlifetime', $_COOKIE[$sessiontimeout]);
102$hookmanager->initHooks(array(
'main'));
104$logged_user =
new User($db);
105$anti_spam_session_key =
'dol_antispam_value';
107if (!defined(
'NOREQUIREDB') && empty($conf->webportal->enabled)) {
111if (!defined(
'WEBPORTAL_NOREQUIRETRAN') || (!defined(
'WEBPORTAL_NOLOGIN') && !empty($context->controllerInstance->accessNeedLoggedUser))) {
112 if (!is_object($langs)) {
113 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
115 $langcode = (
GETPOST(
'lang',
'aZ09', 1) ?
GETPOST(
'lang',
'aZ09', 1) : (empty($logged_user->
conf->MAIN_LANG_DEFAULT) ? (!
getDolGlobalString(
'MAIN_LANG_DEFAULT') ?
'auto' : $conf->global->MAIN_LANG_DEFAULT) : $logged_user->
conf->MAIN_LANG_DEFAULT));
116 if (defined(
'MAIN_LANG_DEFAULT')) {
117 $langcode = constant(
'MAIN_LANG_DEFAULT');
119 $langs->setDefaultLang($langcode);
121 $langs->loadLangs(array(
'website',
'main'));
127if (!defined(
'WEBPORTAL_NOLOGIN') && !empty($context->controllerInstance->accessNeedLoggedUser)) {
128 $admin_error_messages = array();
129 $webportal_logged_thirdparty_account_id = isset($_SESSION[
"webportal_logged_thirdparty_account_id"]) && $_SESSION[
"webportal_logged_thirdparty_account_id"] > 0 ? $_SESSION[
"webportal_logged_thirdparty_account_id"] : 0;
130 if (empty($webportal_logged_thirdparty_account_id)) {
132 $langs->loadLangs(array(
"other",
"help",
"admin"));
135 $action =
GETPOST(
'action_login',
'alphanohtml');
137 if ($action ==
'login') {
138 $login =
GETPOST(
'login',
'alphanohtml');
139 $password =
GETPOST(
'password',
'password');
143 $context->setEventMessage($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login")),
'errors');
144 $focus_element =
'login';
147 if (empty($password)) {
148 $context->setEventMessage($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Password")),
'errors');
149 if (empty($focus_element)) {
150 $focus_element =
'password';
165 $thirdparty_account_id = $context->getThirdPartyAccountFromLogin($login, $password);
166 if ($thirdparty_account_id <= 0) {
168 dol_syslog($langs->transnoentitiesnoconv(
'WebPortalErrorFetchThirdPartyAccountFromLogin', $login), LOG_WARNING);
169 $context->setEventMessage($langs->transnoentitiesnoconv(
'WebPortalErrorAuthentication'),
'errors');
171 $_SESSION[
"webportal_logged_thirdparty_account_id"] = $thirdparty_account_id;
172 $webportal_logged_thirdparty_account_id = $thirdparty_account_id;
173 $context->controller =
'default';
174 $context->initController();
179 if (empty($webportal_logged_thirdparty_account_id)) {
182 setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0,
"/",
'', !empty($dolibarr_main_force_https),
true);
185 $context->controller =
'login';
186 $context->initController();
190 if ($webportal_logged_thirdparty_account_id > 0) {
195 $result = $websiteaccount->fetch($webportal_logged_thirdparty_account_id);
200 dol_syslog(
"Can't load third-party account (ID: $webportal_logged_thirdparty_account_id) even if session logged.", LOG_WARNING);
202 session_set_cookie_params(0,
'/',
null, !empty($dolibarr_main_force_https),
true);
203 session_name($sessionname);
206 $context->setEventMessage($langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedThirdPartyAccount', $webportal_logged_thirdparty_account_id),
'errors');
211 $result = $logged_user->fetch($user_id);
214 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedUser', $user_id);
216 $context->setEventMessage($error_msg,
'errors');
221 $logged_thirdparty = $websiteaccount->thirdparty;
222 if (!$logged_thirdparty || !($logged_thirdparty->id > 0)) {
223 $result = $websiteaccount->fetch_thirdparty();
225 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedThirdParty', $websiteaccount->fk_soc);
228 $context->setEventMessage($error_msg,
'errors');
234 $logged_thirdparty = $websiteaccount->thirdparty;
238 $result = $logged_member->fetch(0,
'', $websiteaccount->thirdparty->id);
241 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedMember', $websiteaccount->thirdparty->id);
243 $context->setEventMessage($error_msg,
'errors');
250 $result = $logged_partnership->fetch(0,
'', $logged_member->id, $websiteaccount->thirdparty->id);
253 $error_msg = $langs->transnoentitiesnoconv(
'WebPortalErrorFetchLoggedPartnership', $websiteaccount->thirdparty->id, $logged_member->id);
255 $context->setEventMessage($error_msg,
'errors');
260 if ($logged_thirdparty->default_lang != $langs->defaultlang && !defined(
'WEBPORTAL_NOREQUIRETRAN')) {
261 if (!is_object($langs)) {
262 include_once DOL_DOCUMENT_ROOT .
'/core/class/translate.class.php';
264 $langs->setDefaultLang($logged_thirdparty->default_lang);
266 $langs->loadLangs(array(
'website',
'main'));
269 $context->logged_user = $logged_user;
270 $context->logged_thirdparty = $logged_thirdparty;
271 $context->logged_member = $logged_member;
272 $context->logged_partnership = $logged_partnership;
static getInstance()
Singleton method to create one instance of this object.
Class for SocieteAccount.
Class to manage translations.
Class to manage Dolibarr users.
Class for WebPortalMember.
Class for WebPortalPartnership.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.