26require_once __DIR__ .
'/controller.class.php';
27require_once __DIR__ .
'/webPortalTheme.class.php';
39 private static $_instance =
null;
80 public $controller_found =
false;
85 private $controllers = array();
90 public $controllerInstance;
101 public $errors = array();
136 public $menu_active = array();
141 public $eventMessages = array();
146 public $tokenKey =
'token';
157 public $logged_user =
null;
162 public $logged_thirdparty =
null;
167 public $logged_member =
null;
172 public $logged_partnership =
null;
191 $this->tplDir = __DIR__ .
'/../';
197 $this->tplPath = realpath(__DIR__ .
'/../../public/webportal/tpl');
199 $this->controller =
GETPOST(
'controller',
'aZ09');
200 $this->action =
GETPOST(
'action',
'aZ09');
202 if (empty($this->controller)) {
203 $this->controller =
'default';
218 $this->cdnUrl = rtrim(trim($this->cdnUrl),
'/');
230 if (is_null(self::$_instance)) {
231 self::$_instance =
new Context();
234 return self::$_instance;
247 $defaultControllersPath = __DIR__ .
'/../controllers/';
250 $this->
addControllerDefinition(
'login', $defaultControllersPath .
'login.controller.class.php',
'LoginController');
251 $this->
addControllerDefinition(
'default', $defaultControllersPath .
'default.controller.class.php',
'DefaultController');
252 $this->
addControllerDefinition(
'document', $defaultControllersPath .
'document.controller.class.php',
'DocumentController');
253 $this->
addControllerDefinition(
'propallist', $defaultControllersPath .
'propallist.controller.class.php',
'PropalListController');
254 $this->
addControllerDefinition(
'orderlist', $defaultControllersPath .
'orderlist.controller.class.php',
'OrderListController');
255 $this->
addControllerDefinition(
'invoicelist', $defaultControllersPath .
'invoicelist.controller.class.php',
'InvoiceListController');
256 $this->
addControllerDefinition(
'ficheinterlist', $defaultControllersPath .
'ficheinterlist.controller.class.php',
'FicheinterListController');
257 $this->
addControllerDefinition(
'ticketlist', $defaultControllersPath .
'ticketlist.controller.class.php',
'TicketListController');
258 $this->
addControllerDefinition(
'membercard', $defaultControllersPath .
'membercard.controller.class.php',
'MemberCardController');
259 $this->
addControllerDefinition(
'partnershipcard', $defaultControllersPath .
'partnershipcard.controller.class.php',
'PartnershipCardController');
261 $this->
addControllerDefinition(
'documentlist', $defaultControllersPath .
'documentlist.controller.class.php',
'DocumentListController');
263 $this->
addControllerDefinition(
'documentutile', $defaultControllersPath .
'documentutile.controller.class.php',
'DocumentUtileController');
264 $this->
addControllerDefinition(
'viewimage', $defaultControllersPath .
'viewimage.controller.class.php',
'ViewImageController');
267 $hookmanager->initHooks(array(
'webportaldao'));
268 $parameters = array();
269 $reshook = $hookmanager->executeHooks(
'initController', $parameters, $this);
273 if (isset($this->controllers[$this->controller]) && file_exists($this->controllers[$this->controller]->path)) {
274 require_once $this->controllers[$this->controller]->path;
276 if (class_exists($this->controllers[$this->controller]->
class)) {
277 $this->controllerInstance =
new $this->controllers[$this->controller]->class();
283 $this->theme->init();
297 $fileName = basename($path);
298 $needle =
'.controller.class.php';
299 $length = strlen($needle);
300 $isControllerFile = $length > 0 ? substr($fileName, -$length) === $needle :
true;
301 if (!$isControllerFile) {
302 $this->
setError(
'Error: controller definition ' . $fileName);
306 $this->controllers[$controller] =
new stdClass();
307 $this->controllers[$controller]->path = $path;
308 $this->controllers[$controller]->class = $className;
320 $this->controller_found =
true;
333 if (substr($rootUrl, -1) !==
'/') {
352 public function getRootUrl($controller =
'', $moreParams =
'', $addToken =
true)
368 $url = $this->rootUrl;
370 if (empty($controller)) {
377 $Tparams[
'controller'] = $controller;
379 if (!empty($addToken)) {
380 $Tparams[$this->tokenKey] = $this->
newToken();
400 if (empty($controller)) {
405 $Tparams[
'controller'] = $controller;
408 if (!empty($moreParams) && is_array($moreParams)) {
409 if (isset($moreParams[
'controller'])) {
410 unset($moreParams[
'controller']);
412 if (!empty($moreParams)) {
413 foreach ($moreParams as $paramKey => $paramVal) {
414 $Tparams[$paramKey] = $paramVal;
419 if (!empty($Tparams)) {
420 $TCompiledAttr = array();
421 foreach ($Tparams as $key => $value) {
422 $TCompiledAttr[] = $key .
'=' . $value;
424 $url .=
'?' . implode(
"&", $TCompiledAttr);
428 if (!empty($moreParams) && !is_array($moreParams)) {
429 if (empty($Tparams)) {
430 if ($moreParams[0] !==
'?') {
433 if ($moreParams[0] ===
'&') {
434 $moreParams = substr($moreParams, 1);
450 public static function urlOrigin($withRequestUri =
true, $use_forwarded_host =
false)
454 $ssl = (!empty($s[
'HTTPS']) && $s[
'HTTPS'] ==
'on');
455 $sp = strtolower($s[
'SERVER_PROTOCOL']);
456 $protocol = substr($sp, 0, strpos($sp,
'/')) . (($ssl) ?
's' :
'');
457 $port = $s[
'SERVER_PORT'];
458 $port = ((!$ssl && $port ==
'80') || ($ssl && $port ==
'443')) ?
'' :
':' . $port;
459 $host = ($use_forwarded_host && isset($s[
'HTTP_X_FORWARDED_HOST'])) ? $s[
'HTTP_X_FORWARDED_HOST'] : (isset($s[
'HTTP_HOST']) ? $s[
'HTTP_HOST'] :
null);
460 $host = isset($host) ? $host : $s[
'SERVER_NAME'] . $port;
462 $url = $protocol .
'://' . $host;
464 if ($withRequestUri) {
465 $url .= $s[
'REQUEST_URI'];
481 $hookmanager->initHooks(array(
'webportaldao'));
482 $parameters = array();
483 $reshook = $hookmanager->executeHooks(
'userIsLog', $parameters, $this);
485 return !empty($hookmanager->resArray[
'userIsLog']);
488 if (!empty($_SESSION[
"webportal_logged_thirdparty_account_id"])) {
490 } elseif (!empty($_SESSION[
"webportal_logged_member_account_id"])) {
505 return in_array($menuName, $this->menu_active);
516 if (!is_array($errors)) {
517 $errors = array($errors);
519 if (!isset($_SESSION[
'webportal_errors'])) {
520 $_SESSION[
'webportal_errors'] = array();
522 foreach ($errors as $msg) {
523 if (!in_array($msg, $_SESSION[
'webportal_errors'])) {
524 $_SESSION[
'webportal_errors'][] = $msg;
536 if (!empty($_SESSION[
'webportal_errors'])) {
537 $this->errors = array_values($_SESSION[
'webportal_errors']);
538 return count($this->errors);
551 unset($_SESSION[
'webportal_errors']);
552 $this->errors = array();
565 $TAcceptedStyle = array(
'mesgs',
'warnings',
'errors');
567 if (!in_array($style, $TAcceptedStyle)) {
571 if (!is_array($mesgs)) {
572 $mesgs = array($mesgs);
574 if (!isset($_SESSION[
'webportal_events'])) {
575 $_SESSION[
'webportal_events'] = array(
576 'mesgs' => array(),
'warnings' => array(),
'errors' => array()
580 foreach ($mesgs as $msg) {
581 if (!in_array($msg, $_SESSION[
'webportal_events'][$style])) {
582 $_SESSION[
'webportal_events'][$style][] = $msg;
598 if (empty($mesg) && empty($mesgs)) {
599 dol_syslog(__METHOD__ .
' Try to add a message in stack, but value to add is empty message', LOG_WARNING);
601 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
602 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
607 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
622 if (!empty($_SESSION[
'webportal_events'])) {
623 $this->eventMessages = $_SESSION[
'webportal_events'];
637 unset($_SESSION[
'webportal_events']);
638 $this->eventMessages = array();
662 if (!defined(
'NOTOKENRENEWAL') || empty($currentToken)) {
664 if (isset($_SESSION[
'newtoken'])) {
665 $_SESSION[
'token'] = $_SESSION[
'newtoken'];
670 $token = bin2hex(random_bytes(32));
671 $_SESSION[
'newtoken'] = $token;
688 return '&' . $this->tokenKey .
'=' . $this->
newToken();
703 return '<input type="hidden" name="' . $this->tokenKey .
'" value="' . $this->
newToken() .
'" />';
720 $sql =
"SELECT sa.rowid as id, sa.pass_crypted";
721 $sql .=
" FROM " . $this->db->prefix() .
"societe_account as sa";
722 $sql .=
" WHERE sa.login = '" . $this->db->escape($login) .
"'";
724 $sql .=
" AND sa.site = 'dolibarr_portal'";
725 $sql .=
" AND sa.status = 1";
726 $sql .=
" AND sa.entity IN (" .
getEntity(
'societe') .
")";
728 dol_syslog(__METHOD__ .
' Try to find the third-party account id for login"' . $login .
'" and site="dolibarr_portal"', LOG_DEBUG);
729 $result = $this->db->query($sql);
731 if ($this->db->num_rows($result) == 1) {
733 $obj = $this->db->fetch_object($result);
735 $passcrypted = $obj->pass_crypted;
746 dol_syslog(__METHOD__ .
' Authentication KO bad password for ' . $login .
', cryptType=auto', LOG_NOTICE);
752 dol_syslog(__METHOD__ .
' Many third-party account found for login"' . $login .
'" and site="dolibarr_portal"', LOG_ERR);
756 $this->error = $this->db->lasterror();
774 $sql =
"SELECT a.rowid as id, a.pass_crypted";
775 $sql .=
" FROM " . $this->db->prefix() .
"adherent as a";
776 $sql .=
" WHERE a.login = '" . $this->db->escape($login) .
"'";
777 $sql .=
" AND a.statut = 1";
778 $sql .=
" AND a.entity IN (" .
getEntity(
'member') .
")";
780 dol_syslog(__METHOD__ .
' Try to find the member account id for login"' . $login .
'"', LOG_DEBUG);
781 $result = $this->db->query($sql);
783 if ($this->db->num_rows($result) == 1) {
785 $obj = $this->db->fetch_object($result);
787 $passcrypted = $obj->pass_crypted;
798 dol_syslog(__METHOD__ .
' Authentication KO bad password for ' . $login .
', cryptType=auto', LOG_NOTICE);
804 dol_syslog(__METHOD__ .
' Many member account found for login"' . $login .
'"', LOG_ERR);
808 $this->error = $this->db->lasterror();
$id
Support class for third parties, contacts, members, users or resources.
static urlOrigin($withRequestUri=true, $use_forwarded_host=false)
Url origin.
generateNewToken()
Generate new token.
menuIsActive($menuName)
Is menu enabled ?
static getInstance()
Singleton method to create one instance of this object.
$object
Current object of page.
clearEventMessages()
Clear event messages.
getFormToken()
Get token input for form.
newToken()
Return the value of token currently saved into session with name 'newToken'.
setError($errors)
Set errors.
userIsLog()
Check if user is logged.
getUrlToken()
Get token url.
addControllerDefinition($controller, $path, $className)
Add controller definition.
getRootUrl($controller='', $moreParams='', $addToken=true)
Get root url.
static getPublicControllerUrl($controller='', $moreParams='', $Tparams=array())
Generate public controller URL Used for external link (like email or web page) so remove token and co...
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
getThirdPartyAccountFromLogin($login, $pass)
Try to find the third-party account id from.
setControllerFound()
Set controller found.
getControllerUrl($controller='', $moreParams='', $addToken=true)
Get controller url according to context.
static getRootConfigUrl()
Get WebPortal root url.
initController($init_theme=true)
Init controller.
$appliName
The application name.
setEventMessage($mesgs, $style='mesgs')
Set event messages in dol_events session object.
__construct()
Constructor.
loadEventMessages()
Load event messages.
clearErrors()
Clear errors.
getMemberAccountFromLogin($login, $pass)
Try to find the member account id from.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...