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(
'membercard', $defaultControllersPath .
'membercard.controller.class.php',
'MemberCardController');
257 $this->
addControllerDefinition(
'partnershipcard', $defaultControllersPath .
'partnershipcard.controller.class.php',
'PartnershipCardController');
259 $this->
addControllerDefinition(
'documentlist', $defaultControllersPath .
'documentlist.controller.class.php',
'DocumentListController');
261 $this->
addControllerDefinition(
'documentutile', $defaultControllersPath .
'documentutile.controller.class.php',
'DocumentUtileController');
262 $this->
addControllerDefinition(
'viewimage', $defaultControllersPath .
'viewimage.controller.class.php',
'ViewImageController');
265 $hookmanager->initHooks(array(
'webportaldao'));
266 $parameters = array();
267 $reshook = $hookmanager->executeHooks(
'initController', $parameters, $this);
271 if (isset($this->controllers[$this->controller]) && file_exists($this->controllers[$this->controller]->path)) {
272 require_once $this->controllers[$this->controller]->path;
274 if (class_exists($this->controllers[$this->controller]->
class)) {
275 $this->controllerInstance =
new $this->controllers[$this->controller]->class();
281 $this->theme->init();
295 $fileName = basename($path);
296 $needle =
'.controller.class.php';
297 $length = strlen($needle);
298 $isControllerFile = $length > 0 ? substr($fileName, -$length) === $needle :
true;
299 if (!$isControllerFile) {
300 $this->
setError(
'Error: controller definition ' . $fileName);
304 $this->controllers[$controller] =
new stdClass();
305 $this->controllers[$controller]->path = $path;
306 $this->controllers[$controller]->class = $className;
318 $this->controller_found =
true;
331 if (substr($rootUrl, -1) !==
'/') {
350 public function getRootUrl($controller =
'', $moreParams =
'', $addToken =
true)
366 $url = $this->rootUrl;
368 if (empty($controller)) {
375 $Tparams[
'controller'] = $controller;
377 if (!empty($addToken)) {
378 $Tparams[$this->tokenKey] = $this->
newToken();
398 if (empty($controller)) {
403 $Tparams[
'controller'] = $controller;
406 if (!empty($moreParams) && is_array($moreParams)) {
407 if (isset($moreParams[
'controller'])) {
408 unset($moreParams[
'controller']);
410 if (!empty($moreParams)) {
411 foreach ($moreParams as $paramKey => $paramVal) {
412 $Tparams[$paramKey] = $paramVal;
417 if (!empty($Tparams)) {
418 $TCompiledAttr = array();
419 foreach ($Tparams as $key => $value) {
420 $TCompiledAttr[] = $key .
'=' . $value;
422 $url .=
'?' . implode(
"&", $TCompiledAttr);
426 if (!empty($moreParams) && !is_array($moreParams)) {
427 if (empty($Tparams)) {
428 if ($moreParams[0] !==
'?') {
431 if ($moreParams[0] ===
'&') {
432 $moreParams = substr($moreParams, 1);
448 public static function urlOrigin($withRequestUri =
true, $use_forwarded_host =
false)
452 $ssl = (!empty($s[
'HTTPS']) && $s[
'HTTPS'] ==
'on');
453 $sp = strtolower($s[
'SERVER_PROTOCOL']);
454 $protocol = substr($sp, 0, strpos($sp,
'/')) . (($ssl) ?
's' :
'');
455 $port = $s[
'SERVER_PORT'];
456 $port = ((!$ssl && $port ==
'80') || ($ssl && $port ==
'443')) ?
'' :
':' . $port;
457 $host = ($use_forwarded_host && isset($s[
'HTTP_X_FORWARDED_HOST'])) ? $s[
'HTTP_X_FORWARDED_HOST'] : (isset($s[
'HTTP_HOST']) ? $s[
'HTTP_HOST'] :
null);
458 $host = isset($host) ? $host : $s[
'SERVER_NAME'] . $port;
460 $url = $protocol .
'://' . $host;
462 if ($withRequestUri) {
463 $url .= $s[
'REQUEST_URI'];
479 $hookmanager->initHooks(array(
'webportaldao'));
480 $parameters = array();
481 $reshook = $hookmanager->executeHooks(
'userIsLog', $parameters, $this);
483 return !empty($hookmanager->resArray[
'userIsLog']);
486 if (!empty($_SESSION[
"webportal_logged_thirdparty_account_id"])) {
488 } elseif (!empty($_SESSION[
"webportal_logged_member_account_id"])) {
503 return in_array($menuName, $this->menu_active);
514 if (!is_array($errors)) {
515 $errors = array($errors);
517 if (!isset($_SESSION[
'webportal_errors'])) {
518 $_SESSION[
'webportal_errors'] = array();
520 foreach ($errors as $msg) {
521 if (!in_array($msg, $_SESSION[
'webportal_errors'])) {
522 $_SESSION[
'webportal_errors'][] = $msg;
534 if (!empty($_SESSION[
'webportal_errors'])) {
535 $this->errors = array_values($_SESSION[
'webportal_errors']);
536 return count($this->errors);
549 unset($_SESSION[
'webportal_errors']);
550 $this->errors = array();
563 $TAcceptedStyle = array(
'mesgs',
'warnings',
'errors');
565 if (!in_array($style, $TAcceptedStyle)) {
569 if (!is_array($mesgs)) {
570 $mesgs = array($mesgs);
572 if (!isset($_SESSION[
'webportal_events'])) {
573 $_SESSION[
'webportal_events'] = array(
574 'mesgs' => array(),
'warnings' => array(),
'errors' => array()
578 foreach ($mesgs as $msg) {
579 if (!in_array($msg, $_SESSION[
'webportal_events'][$style])) {
580 $_SESSION[
'webportal_events'][$style][] = $msg;
596 if (empty($mesg) && empty($mesgs)) {
597 dol_syslog(__METHOD__ .
' Try to add a message in stack, but value to add is empty message', LOG_WARNING);
599 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
600 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
605 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
620 if (!empty($_SESSION[
'webportal_events'])) {
621 $this->eventMessages = $_SESSION[
'webportal_events'];
635 unset($_SESSION[
'webportal_events']);
636 $this->eventMessages = array();
660 if (!defined(
'NOTOKENRENEWAL') || empty($currentToken)) {
662 if (isset($_SESSION[
'newtoken'])) {
663 $_SESSION[
'token'] = $_SESSION[
'newtoken'];
667 $token =
dol_hash(uniqid((
string) mt_rand(),
true));
668 $_SESSION[
'newtoken'] = $token;
685 return '&' . $this->tokenKey .
'=' . $this->
newToken();
700 return '<input type="hidden" name="' . $this->tokenKey .
'" value="' . $this->
newToken() .
'" />';
717 $sql =
"SELECT sa.rowid as id, sa.pass_crypted";
718 $sql .=
" FROM " . $this->db->prefix() .
"societe_account as sa";
719 $sql .=
" WHERE sa.login = '" . $this->db->escape($login) .
"'";
721 $sql .=
" AND sa.site = 'dolibarr_portal'";
722 $sql .=
" AND sa.status = 1";
723 $sql .=
" AND sa.entity IN (" .
getEntity(
'societe') .
")";
725 dol_syslog(__METHOD__ .
' Try to find the third-party account id for login"' . $login .
'" and site="dolibarr_portal"', LOG_DEBUG);
726 $result = $this->db->query($sql);
728 if ($this->db->num_rows($result) == 1) {
730 $obj = $this->db->fetch_object($result);
732 $passcrypted = $obj->pass_crypted;
743 dol_syslog(__METHOD__ .
' Authentication KO bad password for ' . $login .
', cryptType=auto', LOG_NOTICE);
749 dol_syslog(__METHOD__ .
' Many third-party account found for login"' . $login .
'" and site="dolibarr_portal"', LOG_ERR);
753 $this->error = $this->db->lasterror();
771 $sql =
"SELECT a.rowid as id, a.pass_crypted";
772 $sql .=
" FROM " . $this->db->prefix() .
"adherent as a";
773 $sql .=
" WHERE a.login = '" . $this->db->escape($login) .
"'";
774 $sql .=
" AND a.statut = 1";
775 $sql .=
" AND a.entity IN (" .
getEntity(
'member') .
")";
777 dol_syslog(__METHOD__ .
' Try to find the member account id for login"' . $login .
'"', LOG_DEBUG);
778 $result = $this->db->query($sql);
780 if ($this->db->num_rows($result) == 1) {
782 $obj = $this->db->fetch_object($result);
784 $passcrypted = $obj->pass_crypted;
795 dol_syslog(__METHOD__ .
' Authentication KO bad password for ' . $login .
', cryptType=auto', LOG_NOTICE);
801 dol_syslog(__METHOD__ .
' Many member account found for login"' . $login .
'"', LOG_ERR);
805 $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_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...