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();
131 public $menu_active = array();
136 public $eventMessages = array();
141 public $tokenKey =
'token';
152 public $logged_user =
null;
157 public $logged_thirdparty =
null;
162 public $logged_member =
null;
167 public $logged_partnership =
null;
186 $this->tplDir = __DIR__ .
'/../';
192 $this->tplPath = realpath(__DIR__ .
'/../../public/webportal/tpl');
194 $this->controller =
GETPOST(
'controller',
'aZ09');
195 $this->action =
GETPOST(
'action',
'aZ09');
197 if (empty($this->controller)) {
198 $this->controller =
'default';
221 if (is_null(self::$_instance)) {
222 self::$_instance =
new Context();
225 return self::$_instance;
237 $defaultControllersPath = __DIR__ .
'/../controllers/';
240 $this->
addControllerDefinition(
'login', $defaultControllersPath .
'login.controller.class.php',
'LoginController');
241 $this->
addControllerDefinition(
'default', $defaultControllersPath .
'default.controller.class.php',
'DefaultController');
242 $this->
addControllerDefinition(
'document', $defaultControllersPath .
'document.controller.class.php',
'DocumentController');
243 $this->
addControllerDefinition(
'propallist', $defaultControllersPath .
'propallist.controller.class.php',
'PropalListController');
244 $this->
addControllerDefinition(
'orderlist', $defaultControllersPath .
'orderlist.controller.class.php',
'OrderListController');
245 $this->
addControllerDefinition(
'invoicelist', $defaultControllersPath .
'invoicelist.controller.class.php',
'InvoiceListController');
246 $this->
addControllerDefinition(
'membercard', $defaultControllersPath .
'membercard.controller.class.php',
'MemberCardController');
247 $this->
addControllerDefinition(
'partnershipcard', $defaultControllersPath .
'partnershipcard.controller.class.php',
'PartnershipCardController');
256 if (isset($this->controllers[$this->controller]) && file_exists($this->controllers[$this->controller]->path)) {
257 require_once $this->controllers[$this->controller]->path;
259 if (class_exists($this->controllers[$this->controller]->
class)) {
260 $this->controllerInstance =
new $this->controllers[$this->controller]->class();
276 $fileName = basename($path);
277 $needle =
'.controller.class.php';
278 $length = strlen($needle);
279 $isControllerFile = $length > 0 ? substr($fileName, -$length) === $needle :
true;
280 if (!$isControllerFile) {
281 $this->
setError(
'Error: controller definition ' . $fileName);
285 $this->controllers[$controller] =
new stdClass();
286 $this->controllers[$controller]->path = $path;
287 $this->controllers[$controller]->class = $className;
299 $this->controller_found =
true;
314 if (substr($rootUrl, -1) !==
'/') {
333 public function getRootUrl($controller =
'', $moreParams =
'', $addToken =
true)
349 $url = $this->rootUrl;
351 if (empty($controller)) {
358 $Tparams[
'controller'] = $controller;
360 if (!empty($addToken)) {
361 $Tparams[$this->tokenKey] = $this->
newToken();
381 if (empty($controller)) {
386 $Tparams[
'controller'] = $controller;
389 if (!empty($moreParams) && is_array($moreParams)) {
390 if (isset($moreParams[
'controller'])) {
391 unset($moreParams[
'controller']);
393 if (!empty($moreParams)) {
394 foreach ($moreParams as $paramKey => $paramVal) {
395 $Tparams[$paramKey] = $paramVal;
400 if (!empty($Tparams)) {
401 $TCompiledAttr = array();
402 foreach ($Tparams as $key => $value) {
403 $TCompiledAttr[] = $key .
'=' . $value;
405 $url .=
'?' . implode(
"&", $TCompiledAttr);
409 if (!empty($moreParams) && !is_array($moreParams)) {
410 if (empty($Tparams)) {
411 if ($moreParams[0] !==
'?') {
414 if ($moreParams[0] ===
'&') {
415 $moreParams = substr($moreParams, 1);
431 public static function urlOrigin($withRequestUri =
true, $use_forwarded_host =
false)
435 $ssl = (!empty($s[
'HTTPS']) && $s[
'HTTPS'] ==
'on');
436 $sp = strtolower($s[
'SERVER_PROTOCOL']);
437 $protocol = substr($sp, 0, strpos($sp,
'/')) . (($ssl) ?
's' :
'');
438 $port = $s[
'SERVER_PORT'];
439 $port = ((!$ssl && $port ==
'80') || ($ssl && $port ==
'443')) ?
'' :
':' . $port;
440 $host = ($use_forwarded_host && isset($s[
'HTTP_X_FORWARDED_HOST'])) ? $s[
'HTTP_X_FORWARDED_HOST'] : (isset($s[
'HTTP_HOST']) ? $s[
'HTTP_HOST'] :
null);
441 $host = isset($host) ? $host : $s[
'SERVER_NAME'] . $port;
443 $url = $protocol .
'://' . $host;
445 if ($withRequestUri) {
446 $url .= $s[
'REQUEST_URI'];
459 if (!empty($_SESSION[
"webportal_logged_thirdparty_account_id"])) {
474 return in_array($menuName, $this->menu_active);
485 if (!is_array($errors)) {
486 $errors = array($errors);
488 if (!isset($_SESSION[
'webportal_errors'])) {
489 $_SESSION[
'webportal_errors'] = array();
491 foreach ($errors as $msg) {
492 if (!in_array($msg, $_SESSION[
'webportal_errors'])) {
493 $_SESSION[
'webportal_errors'][] = $msg;
505 if (!empty($_SESSION[
'webportal_errors'])) {
506 $this->errors = array_values($_SESSION[
'webportal_errors']);
507 return count($this->errors);
520 unset($_SESSION[
'webportal_errors']);
521 $this->errors = array();
534 $TAcceptedStyle = array(
'mesgs',
'warnings',
'errors');
536 if (!in_array($style, $TAcceptedStyle)) {
540 if (!is_array($mesgs)) {
541 $mesgs = array($mesgs);
543 if (!isset($_SESSION[
'webportal_events'])) {
544 $_SESSION[
'webportal_events'] = array(
545 'mesgs' => array(),
'warnings' => array(),
'errors' => array()
549 foreach ($mesgs as $msg) {
550 if (!in_array($msg, $_SESSION[
'webportal_events'][$style])) {
551 $_SESSION[
'webportal_events'][$style][] = $msg;
567 if (empty($mesg) && empty($mesgs)) {
568 dol_syslog(__METHOD__ .
' Try to add a message in stack, but value to add is empty message', LOG_WARNING);
570 if (!in_array((
string) $style, array(
'mesgs',
'warnings',
'errors'))) {
571 dol_print_error(
null,
'Bad parameter style=' . $style .
' for setEventMessages');
576 if (!empty($mesg) && !in_array($mesg, $mesgs)) {
591 if (!empty($_SESSION[
'webportal_events'])) {
592 $this->eventMessages = $_SESSION[
'webportal_events'];
606 unset($_SESSION[
'webportal_events']);
607 $this->eventMessages = array();
631 if (!defined(
'NOTOKENRENEWAL') || empty($currentToken)) {
633 if (isset($_SESSION[
'newtoken'])) {
634 $_SESSION[
'token'] = $_SESSION[
'newtoken'];
638 $token =
dol_hash(uniqid((
string) mt_rand(),
true));
639 $_SESSION[
'newtoken'] = $token;
656 return '&' . $this->tokenKey .
'=' . $this->
newToken();
671 return '<input type="hidden" name="' . $this->tokenKey .
'" value="' . $this->
newToken() .
'" />';
688 $sql =
"SELECT sa.rowid as id, sa.pass_crypted";
689 $sql .=
" FROM " . $this->db->prefix() .
"societe_account as sa";
690 $sql .=
" WHERE BINARY sa.login = '" . $this->db->escape($login) .
"'";
692 $sql .=
" AND sa.site = 'dolibarr_portal'";
693 $sql .=
" AND sa.status = 1";
694 $sql .=
" AND sa.entity IN (" .
getEntity(
'societe') .
")";
696 dol_syslog(__METHOD__ .
' Try to find the third-party account id for login"' . $login .
'" and site="dolibarr_portal"', LOG_DEBUG);
697 $result = $this->db->query($sql);
699 if ($this->db->num_rows($result) == 1) {
701 $obj = $this->db->fetch_object($result);
703 $passcrypted = $obj->pass_crypted;
712 if (!in_array($cryptType, array(
'auto'))) {
717 if ($cryptType ==
'auto') {
727 dol_syslog(__METHOD__ .
' Authentication KO bad password for ' . $login .
', cryptType=' . $cryptType, LOG_NOTICE);
733 dol_syslog(__METHOD__ .
' Many third-party account found for login"' . $login .
'" and site="dolibarr_portal"', LOG_ERR);
737 $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 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,...
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.