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();
114 public $menu_active = array();
116 public $eventMessages = array();
118 public $tokenKey =
'token';
129 public $logged_user =
null;
134 public $logged_thirdparty =
null;
139 public $logged_member =
null;
144 public $logged_partnership =
null;
164 $this->tplDir = __DIR__ .
'/../';
170 $this->tplPath = realpath(__DIR__ .
'/../../public/webportal/tpl');
172 $this->controller =
GETPOST(
'controller',
'aZ09');
173 $this->action =
GETPOST(
'action',
'aZ09');
175 if (empty($this->controller)) {
176 $this->controller =
'default';
199 if (is_null(self::$_instance)) {
200 self::$_instance =
new Context();
203 return self::$_instance;
215 $defaultControllersPath = __DIR__ .
'/../controllers/';
218 $this->
addControllerDefinition(
'login', $defaultControllersPath .
'login.controller.class.php',
'LoginController');
219 $this->
addControllerDefinition(
'default', $defaultControllersPath .
'default.controller.class.php',
'DefaultController');
220 $this->
addControllerDefinition(
'document', $defaultControllersPath .
'document.controller.class.php',
'DocumentController');
221 $this->
addControllerDefinition(
'propallist', $defaultControllersPath .
'propallist.controller.class.php',
'PropalListController');
222 $this->
addControllerDefinition(
'orderlist', $defaultControllersPath .
'orderlist.controller.class.php',
'OrderListController');
223 $this->
addControllerDefinition(
'invoicelist', $defaultControllersPath .
'invoicelist.controller.class.php',
'InvoiceListController');
224 $this->
addControllerDefinition(
'membercard', $defaultControllersPath .
'membercard.controller.class.php',
'MemberCardController');
225 $this->
addControllerDefinition(
'partnershipcard', $defaultControllersPath .
'partnershipcard.controller.class.php',
'PartnershipCardController');
234 if (isset($this->controllers[$this->controller]) && file_exists($this->controllers[$this->controller]->path)) {
235 require_once $this->controllers[$this->controller]->path;
237 if (class_exists($this->controllers[$this->controller]->
class)) {
238 $this->controllerInstance =
new $this->controllers[$this->controller]->class();
254 $fileName = basename($path);
255 $needle =
'.controller.class.php';
256 $length = strlen($needle);
257 $isControllerFile = $length > 0 ? substr($fileName, -$length) === $needle :
true;
258 if (!$isControllerFile) {
259 $this->
setError(
'Error: controller definition ' . $fileName);
263 $this->controllers[$controller] =
new stdClass();
264 $this->controllers[$controller]->path = $path;
265 $this->controllers[$controller]->class = $className;
277 $this->controller_found =
true;
292 if (substr($rootUrl, -1) !==
'/') {
311 public function getRootUrl($controller =
'', $moreParams =
'', $addToken =
true)
327 $url = $this->rootUrl;
329 if (empty($controller)) {
336 $Tparams[
'controller'] = $controller;
338 if (!empty($addToken)) {
339 $Tparams[$this->tokenKey] = $this->
newToken();
359 if (empty($controller)) {
364 $Tparams[
'controller'] = $controller;
367 if (!empty($moreParams) && is_array($moreParams)) {
368 if (isset($moreParams[
'controller'])) {
369 unset($moreParams[
'controller']);
371 if (!empty($moreParams)) {
372 foreach ($moreParams as $paramKey => $paramVal) {
373 $Tparams[$paramKey] = $paramVal;
378 if (!empty($Tparams)) {
379 $TCompiledAttr = array();
380 foreach ($Tparams as $key => $value) {
381 $TCompiledAttr[] = $key .
'=' . $value;
383 $url .=
'?' . implode(
"&", $TCompiledAttr);
387 if (!empty($moreParams) && !is_array($moreParams)) {
388 if (empty($Tparams)) {
389 if ($moreParams[0] !==
'?') {
392 if ($moreParams[0] ===
'&') {
393 $moreParams = substr($moreParams, 1);
409 public static function urlOrigin($withRequestUri =
true, $use_forwarded_host =
false)
413 $ssl = (!empty($s[
'HTTPS']) && $s[
'HTTPS'] ==
'on');
414 $sp = strtolower($s[
'SERVER_PROTOCOL']);
415 $protocol = substr($sp, 0, strpos($sp,
'/')) . (($ssl) ?
's' :
'');
416 $port = $s[
'SERVER_PORT'];
417 $port = ((!$ssl && $port ==
'80') || ($ssl && $port ==
'443')) ?
'' :
':' . $port;
418 $host = ($use_forwarded_host && isset($s[
'HTTP_X_FORWARDED_HOST'])) ? $s[
'HTTP_X_FORWARDED_HOST'] : (isset($s[
'HTTP_HOST']) ? $s[
'HTTP_HOST'] :
null);
419 $host = isset($host) ? $host : $s[
'SERVER_NAME'] . $port;
421 $url = $protocol .
'://' . $host;
423 if ($withRequestUri) {
424 $url .= $s[
'REQUEST_URI'];
437 if (!empty($_SESSION[
"webportal_logged_thirdparty_account_id"])) {
452 return in_array($menuName, $this->menu_active);
463 if (!is_array($errors)) {
464 $errors = array($errors);
466 if (!isset($_SESSION[
'webportal_errors'])) {
467 $_SESSION[
'webportal_errors'] = array();
469 foreach ($errors as $msg) {
470 if (!in_array($msg, $_SESSION[
'webportal_errors'])) {
471 $_SESSION[
'webportal_errors'][] = $msg;
483 if (!empty($_SESSION[
'webportal_errors'])) {
484 $this->errors = array_values($_SESSION[
'webportal_errors']);
485 return count($this->errors);
498 unset($_SESSION[
'webportal_errors']);
499 $this->errors = array();
512 $TAcceptedStyle = array(
'mesgs',
'warnings',
'errors');
514 if (!in_array($style, $TAcceptedStyle)) {
518 if (!is_array($mesgs)) {
519 $mesgs = array($mesgs);
521 if (!isset($_SESSION[
'webportal_events'])) {
522 $_SESSION[
'webportal_events'] = array(
523 'mesgs' => array(),
'warnings' => array(),
'errors' => array()
527 foreach ($mesgs as $msg) {
528 if (!in_array($msg, $_SESSION[
'webportal_events'][$style])) {
529 $_SESSION[
'webportal_events'][$style][] = $msg;
545 if (empty($mesg) && empty($mesgs)) {
546 dol_syslog(__METHOD__ .
' Try to add a message in stack, but value to add is empty message', LOG_WARNING);
548 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
549 dol_print_error(
'',
'Bad parameter style=' . $style .
' for setEventMessages');
554 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
569 if (!empty($_SESSION[
'webportal_events'])) {
570 $this->eventMessages = $_SESSION[
'webportal_events'];
584 unset($_SESSION[
'webportal_events']);
585 $this->eventMessages = array();
609 if (!defined(
'NOTOKENRENEWAL') || empty($currentToken)) {
611 if (isset($_SESSION[
'newtoken'])) {
612 $_SESSION[
'token'] = $_SESSION[
'newtoken'];
616 $token =
dol_hash(uniqid((
string) mt_rand(),
true));
617 $_SESSION[
'newtoken'] = $token;
634 return '&' . $this->tokenKey .
'=' . $this->
newToken();
649 return '<input type="hidden" name="' . $this->tokenKey .
'" value="' . $this->
newToken() .
'" />';
666 $sql =
"SELECT sa.rowid as id, sa.pass_crypted";
667 $sql .=
" FROM " . $this->db->prefix() .
"societe_account as sa";
668 $sql .=
" WHERE BINARY sa.login = '" . $this->db->escape($login) .
"'";
670 $sql .=
" AND sa.site = 'dolibarr_portal'";
671 $sql .=
" AND sa.status = 1";
672 $sql .=
" AND sa.entity IN (" .
getEntity(
'societe') .
")";
674 dol_syslog(__METHOD__ .
' Try to find the third-party account id for login"' . $login .
'" and site="dolibarr_portal"', LOG_DEBUG);
675 $result = $this->db->query($sql);
677 if ($this->db->num_rows($result) == 1) {
679 $obj = $this->db->fetch_object($result);
681 $passcrypted = $obj->pass_crypted;
690 if (!in_array($cryptType, array(
'auto'))) {
695 if ($cryptType ==
'auto') {
705 dol_syslog(__METHOD__ .
' Authentication KO bad password for ' . $login .
', cryptType=' . $cryptType, LOG_NOTICE);
711 dol_syslog(__METHOD__ .
' Many third-party account found for login"' . $login .
'" and site="dolibarr_portal"', LOG_ERR);
715 $this->error = $this->db->lasterror();
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.
initController()
Init controller.
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.
$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.
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 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,...
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.