/**
  * Create SMTP headers (mode = 'mail')
  *
  * @return	smtp headers
  */
 function write_smtpheaders()
 {
     global $conf;
     $out = "";
     $host = dol_getprefix();
     // Sender
     //$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2;
     $out .= "From: " . $this->getValidAddress($this->addr_from, 3, 1) . $this->eol2;
     if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) {
         $out .= "To: " . $this->getValidAddress($this->addr_to, 0, 1) . $this->eol2;
     }
     $out .= "Return-Path: " . $this->getValidAddress($this->addr_from, 0, 1) . $this->eol2;
     if (isset($this->reply_to) && $this->reply_to) {
         $out .= "Reply-To: " . $this->getValidAddress($this->reply_to, 2) . $this->eol2;
     }
     if (isset($this->errors_to) && $this->errors_to) {
         $out .= "Errors-To: " . $this->getValidAddress($this->errors_to, 2) . $this->eol2;
     }
     // Receiver
     if (isset($this->addr_cc) && $this->addr_cc) {
         $out .= "Cc: " . $this->getValidAddress($this->addr_cc, 2) . $this->eol2;
     }
     if (isset($this->addr_bcc) && $this->addr_bcc) {
         $out .= "Bcc: " . $this->getValidAddress($this->addr_bcc, 2) . $this->eol2;
     }
     // Delivery receipt
     if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) {
         $out .= "Disposition-Notification-To: " . $this->getValidAddress($this->addr_from, 2) . $this->eol2;
     }
     //$out.= "X-Priority: 3".$this->eol2;
     $out .= 'Date: ' . date("r") . $this->eol2;
     $out .= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
     $out .= "X-Mailer: Dolibarr version " . DOL_VERSION . " (using php mail)" . $this->eol2;
     $out .= "Mime-Version: 1.0" . $this->eol2;
     //$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
     $out .= "Content-Type: multipart/mixed; boundary=\"" . $this->mixed_boundary . "\"" . $this->eol2;
     $out .= "Content-Transfer-Encoding: 8bit" . $this->eol2;
     dol_syslog("CMailFile::write_smtpheaders smtp_header=\n" . $out);
     return $out;
 }
Пример #2
0
/**
 * Show Dolibarr default login page.
 * Part of this code is also duplicated into main.inc.php::top_htmlhead
 *
 * @param		Translate	$langs		Lang object (must be initialized by a new).
 * @param		Conf		$conf		Conf object
 * @param		Societe		$mysoc		Company object
 * @return		void
 */
function dol_loginfunction($langs, $conf, $mysoc)
{
    global $dolibarr_main_demo, $db;
    global $smartphone, $hookmanager;
    // Instantiate hooks of thirdparty module only if not already define
    $hookmanager->initHooks(array('mainloginpage'));
    $langs->load("main");
    $langs->load("other");
    $langs->load("help");
    $langs->load("admin");
    $main_authentication = $conf->file->main_authentication;
    $session_name = session_name();
    $dol_url_root = DOL_URL_ROOT;
    $php_self = $_SERVER['PHP_SELF'];
    $php_self .= $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : '';
    if (!preg_match('/mainmenu=/', $php_self)) {
        $php_self .= (preg_match('/\\?/', $php_self) ? '&' : '?') . 'mainmenu=home';
    }
    // Title
    $title = 'Dolibarr ' . DOL_VERSION;
    if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
        $title = $conf->global->MAIN_APPLICATION_TITLE;
    }
    // Note: $conf->css looks like '/theme/eldy/style.css.php'
    $conf->css = "/theme/" . (GETPOST('theme') ? GETPOST('theme', 'alpha') : $conf->theme) . "/style.css.php";
    //$themepath=dol_buildpath((empty($conf->global->MAIN_FORCETHEMEDIR)?'':$conf->global->MAIN_FORCETHEMEDIR).$conf->css,1);
    $themepath = dol_buildpath($conf->css, 1);
    if (!empty($conf->modules_parts['theme'])) {
        foreach ($conf->modules_parts['theme'] as $reldir) {
            if (file_exists(dol_buildpath($reldir . $conf->css, 0))) {
                $themepath = dol_buildpath($reldir . $conf->css, 1);
                break;
            }
        }
    }
    $conf_css = $themepath . "?lang=" . $langs->defaultlang;
    // Select templates
    if (!empty($conf->modules_parts['tpl'])) {
        $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl/'));
        foreach ($dirtpls as $reldir) {
            $tmp = dol_buildpath($reldir . 'login.tpl.php');
            if (file_exists($tmp)) {
                $template_dir = preg_replace('/login\\.tpl\\.php$/', '', $tmp);
                break;
            }
        }
    } else {
        $template_dir = DOL_DOCUMENT_ROOT . "/core/tpl/";
    }
    // Set cookie for timeout management
    $prefix = dol_getprefix();
    $sessiontimeout = 'DOLSESSTIMEOUT_' . $prefix;
    if (!empty($conf->global->MAIN_SESSION_TIMEOUT)) {
        setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", '', 0);
    }
    if (GETPOST('urlfrom', 'alpha')) {
        $_SESSION["urlfrom"] = GETPOST('urlfrom', 'alpha');
    } else {
        unset($_SESSION["urlfrom"]);
    }
    if (!GETPOST("username")) {
        $focus_element = 'username';
    } else {
        $focus_element = 'password';
    }
    $login_background = DOL_URL_ROOT . '/theme/login_background.png';
    if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/img/login_background.png')) {
        $login_background = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/login_background.png';
    }
    $demologin = '';
    $demopassword = '';
    if (!empty($dolibarr_main_demo)) {
        $tab = explode(',', $dolibarr_main_demo);
        $demologin = $tab[0];
        $demopassword = $tab[1];
    }
    // Execute hook getLoginPageOptions
    // Should be an array with differents options in $hookmanager->resArray
    $parameters = array('entity' => GETPOST('entity', 'int'));
    $hookmanager->executeHooks('getLoginPageOptions', $parameters);
    // Note that $action and $object may have been modified by some hooks
    // Login
    $login = !empty($hookmanager->resArray['username']) ? $hookmanager->resArray['username'] : (GETPOST("username", "alpha") ? GETPOST("username", "alpha") : $demologin);
    $password = $demopassword;
    // Show logo (search in order: small company logo, large company logo, theme logo, common logo)
    $width = 0;
    $urllogo = DOL_URL_ROOT . '/theme/login_logo.png';
    if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
        $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode('thumbs/' . $mysoc->logo_small);
    } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
        $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode($mysoc->logo);
        $width = 128;
    } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/img/dolibarr_logo.png')) {
        $urllogo = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/dolibarr_logo.png';
    } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.png')) {
        $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
    }
    // Security graphical code
    $captcha = 0;
    $captcha_refresh = '';
    if (function_exists("imagecreatefrompng") && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) {
        $captcha = 1;
        $captcha_refresh = img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"');
    }
    // Extra link
    $forgetpasslink = 0;
    $helpcenterlink = 0;
    if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
        if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) {
            $forgetpasslink = 1;
        }
        if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
            $helpcenterlink = 1;
        }
    }
    // Home message
    $main_home = '';
    if (!empty($conf->global->MAIN_HOME)) {
        $i = 0;
        while (preg_match('/__\\(([a-zA-Z|@]+)\\)__/i', $conf->global->MAIN_HOME, $reg) && $i < 100) {
            $tmp = explode('|', $reg[1]);
            if (!empty($tmp[1])) {
                $langs->load($tmp[1]);
            }
            $conf->global->MAIN_HOME = preg_replace('/__\\(' . preg_quote($reg[1]) . '\\)__/i', $langs->trans($tmp[0]), $conf->global->MAIN_HOME);
            $i++;
        }
        $main_home = dol_htmlcleanlastbr($conf->global->MAIN_HOME);
    }
    // Google AD
    $main_google_ad_client = !empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT) ? 1 : 0;
    // Set jquery theme
    $dol_loginmesg = !empty($_SESSION["dol_loginmesg"]) ? $_SESSION["dol_loginmesg"] : '';
    $favicon = dol_buildpath('/theme/' . $conf->theme . '/img/favicon.ico', 1);
    if (!empty($conf->global->MAIN_FAVICON_URL)) {
        $favicon = $conf->global->MAIN_FAVICON_URL;
    }
    $jquerytheme = 'smoothness';
    if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) {
        $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
    }
    // Set dol_hide_topmenu, dol_hide_leftmenu, dol_optimize_smallscreen, dol_nomousehover
    $dol_hide_topmenu = GETPOST('dol_hide_topmenu', 'int');
    $dol_hide_leftmenu = GETPOST('dol_hide_leftmenu', 'int');
    $dol_optimize_smallscreen = GETPOST('dol_optimize_smallscreen', 'int');
    $dol_no_mouse_hover = GETPOST('dol_no_mouse_hover', 'int');
    $dol_use_jmobile = GETPOST('dol_use_jmobile', 'int');
    // Include login page template
    include $template_dir . 'login.tpl.php';
    $_SESSION["dol_loginmesg"] = '';
}
Пример #3
0
 /**
  * Create SMTP headers (mode = 'mail')
  *
  * @return	string headers
  */
 function write_smtpheaders()
 {
     global $conf;
     $out = "";
     $host = dol_getprefix();
     // Sender
     //$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2;
     $out .= "From: " . $this->getValidAddress($this->addr_from, 3, 1) . $this->eol2;
     if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) {
         $out .= "To: " . $this->getValidAddress($this->addr_to, 0, 1) . $this->eol2;
     }
     // Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that.
     $out .= "Return-Path: " . $this->getValidAddress($this->addr_from, 0, 1) . $this->eol2;
     if (isset($this->reply_to) && $this->reply_to) {
         $out .= "Reply-To: " . $this->getValidAddress($this->reply_to, 2) . $this->eol2;
     }
     if (isset($this->errors_to) && $this->errors_to) {
         $out .= "Errors-To: " . $this->getValidAddress($this->errors_to, 2) . $this->eol2;
     }
     // Receiver
     if (isset($this->addr_cc) && $this->addr_cc) {
         $out .= "Cc: " . $this->getValidAddress($this->addr_cc, 2) . $this->eol2;
     }
     if (isset($this->addr_bcc) && $this->addr_bcc) {
         $out .= "Bcc: " . $this->getValidAddress($this->addr_bcc, 2) . $this->eol2;
     }
     // Delivery receipt
     if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) {
         $out .= "Disposition-Notification-To: " . $this->getValidAddress($this->addr_from, 2) . $this->eol2;
     }
     //$out.= "X-Priority: 3".$this->eol2;
     $out .= 'Date: ' . date("r") . $this->eol2;
     $trackid = $this->trackid;
     if ($trackid) {
         // References is kept in response and Message-ID is returned into In-Reply-To:
         $out .= 'Message-ID: <' . time() . '.phpmail-dolibarr-' . $trackid . '@' . $host . ">" . $this->eol2;
         // Uppercase seems replaced by phpmail
         $out .= 'References: <' . time() . '.phpmail-dolibarr-' . $trackid . '@' . $host . ">" . $this->eol2;
         $out .= 'X-Dolibarr-TRACKID: ' . $trackid . $this->eol2;
     } else {
         $out .= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
     }
     $out .= "X-Mailer: Dolibarr version " . DOL_VERSION . " (using php mail)" . $this->eol2;
     $out .= "Mime-Version: 1.0" . $this->eol2;
     //$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
     $out .= "Content-Type: multipart/mixed; boundary=\"" . $this->mixed_boundary . "\"" . $this->eol2;
     $out .= "Content-Transfer-Encoding: 8bit" . $this->eol2;
     dol_syslog("CMailFile::write_smtpheaders smtp_header=\n" . $out);
     return $out;
 }
Пример #4
0
}elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.png'))
	{
    $urllogo=DOL_URL_ROOT.'/theme/dolibarr_logo.png';
}

// Entity combobox
$select_entity='';
if (! empty($conf->multicompany->enabled)  && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX) && ! $disabled)
{
    $rowspan++;
    $lastuser='';
    $lastentity = GETPOST('entity');

    if (! empty($conf->global->MULTICOMPANY_COOKIE_ENABLED))
    {
        $prefix=dol_getprefix();
        $entityCookieName = 'DOLENTITYID_'.$prefix;
        if (isset($_COOKIE[$entityCookieName]))
        {
            include_once(DOL_DOCUMENT_ROOT . "/core/class/cookie.class.php");
            $lastuser = '';	$lastentity = '';
            $entityCookie = new DolCookie($conf->file->cookie_cryptkey);
            $cookieValue = $entityCookie->_getCookie($entityCookieName);
            list($lastuser, $lastentity) = explode('|', $cookieValue);
        }
    }

    $select_entity = $mc->select_entities($lastentity, 'entity', ' tabindex="2"');
}

// Security graphical code
Пример #5
0
/**
 *	Show Dolibarr default login page
 *	@param		langs		Lang object (must be initialized by a new).
 *	@param		conf		Conf object
 *	@param		mysoc		Company object
 */
function dol_loginfunction($langs,$conf,$mysoc)
{
	global $dolibarr_main_demo,$db;
	global $smartphone;

	$langcode=(GETPOST('lang')?((is_object($langs)&&$langs->defaultlang)?$langs->defaultlang:'auto'):GETPOST('lang'));
	$langs->setDefaultLang($langcode);

	$langs->load("main");
	$langs->load("other");
	$langs->load("help");
	$langs->load("admin");

	$main_authentication=$conf->file->main_authentication;
	$session_name=session_name();

	$dol_url_root = DOL_URL_ROOT;

	$php_self = $_SERVER['PHP_SELF'];
	$php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:'';

	// Title
	$title='Dolibarr '.DOL_VERSION;
	if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE;

	// Select templates
	if (preg_match('/^smartphone/',$conf->smart_menu) && isset($conf->browser->phone))
	{
		$template_dir = DOL_DOCUMENT_ROOT.'/theme/phones/smartphone/tpl/';
	}
	else
	{
		if (file_exists(DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/tpl/login.tpl.php"))
		{
			$template_dir = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/tpl/";
		}
		else
		{
			$template_dir = DOL_DOCUMENT_ROOT."/core/tpl/";
		}
	}

	$conf->css = "/theme/".$conf->theme."/style.css.php?lang=".$langs->defaultlang;
	$conf_css = DOL_URL_ROOT.$conf->css;

	// Set cookie for timeout management
	$prefix=dol_getprefix();
	$sessiontimeout='DOLSESSTIMEOUT_'.$prefix;
	if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", '', 0);

	if (GETPOST("urlfrom")) $_SESSION["urlfrom"]=GETPOST("urlfrom");
	else unset($_SESSION["urlfrom"]);

	if (! GETPOST("username")) $focus_element='username';
	else $focus_element='password';

	$login_background=DOL_URL_ROOT.'/theme/login_background.png';
	if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/img/login_background.png'))
	{
		$login_background=DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/login_background.png';
	}

	$demologin='';
	$demopassword='';
	if (! empty($dolibarr_main_demo))
	{
		$tab=explode(',',$dolibarr_main_demo);
		$demologin=$tab[0];
		$demopassword=$tab[1];
	}

	// Entity cookie
	if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY))
	{
		$lastuser = '';
		$lastentity = $_POST['entity'];

		if (! empty($conf->global->MAIN_MULTICOMPANY_COOKIE))
		{
			$prefix=dol_getprefix();
			$entityCookieName = 'DOLENTITYID_'.$prefix;
			if (isset($_COOKIE[$entityCookieName]))
			{
				include_once(DOL_DOCUMENT_ROOT . "/core/class/cookie.class.php");

				$cryptkey = (! empty($conf->file->cookie_cryptkey) ? $conf->file->cookie_cryptkey : '' );

				$entityCookie = new DolCookie($cryptkey);
				$cookieValue = $entityCookie->_getCookie($entityCookieName);
				list($lastuser, $lastentity) = explode('|', $cookieValue);
			}
		}
	}

	// Login
	$login = (!empty($lastuser)?$lastuser:(GETPOST("username")?GETPOST("username"):$demologin));
	$password = $demopassword;

	// Show logo (search in order: small company logo, large company logo, theme logo, common logo)
	$width=0;
	$rowspan=2;
	$urllogo=DOL_URL_ROOT.'/theme/login_logo.png';

	if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small))
	{
		$urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode('thumbs/'.$mysoc->logo_small);
	}
	elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo))
	{
		$urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file='.urlencode($mysoc->logo);
		$width=128;
	}
	elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.png'))
	{
		$urllogo=DOL_URL_ROOT.'/theme/dolibarr_logo.png';
	}

	// Entity field
	$select_entity='';
	if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY) && empty($conf->global->MULTICOMPANY_HIDE_LOGIN_COMBOBOX))
	{
		$rowspan++;

		$res=dol_include_once('/multicompany/class/actions_multicompany.class.php');
		if ($res)
		{
			$mc = new ActionsMulticompany($db);

			$select_entity=$mc->select_entities($lastentity, 'tabindex="3"');
		}
	}

	// Security graphical code
	$captcha=0;
	$captcha_refresh='';
	if (function_exists("imagecreatefrompng") && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
	{
		$captcha=1;
		$captcha_refresh=img_refresh();
	}

	// Extra link
	$forgetpasslink=0;
	$helpcenterlink=0;
	if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK))
	{
		if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK))
		{
			$forgetpasslink=1;
		}

		if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK))
		{
			$helpcenterlink=1;
		}
	}

	// Home message
	if (! empty($conf->global->MAIN_HOME))
	{
		$i=0;
		while (preg_match('/__\(([a-zA-Z]+)\)__/i',$conf->global->MAIN_HOME,$reg) && $i < 100)
		{
			$conf->global->MAIN_HOME=preg_replace('/__\('.$reg[1].'\)__/i',$langs->trans($reg[1]),$conf->global->MAIN_HOME);
			$i++;
		}
	}
	$main_home=dol_htmlcleanlastbr($conf->global->MAIN_HOME);

	// Google AD
	$main_google_ad_client = ((! empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && ! empty($conf->global->MAIN_GOOGLE_AD_SLOT))?1:0);

	$dol_loginmesg = $_SESSION["dol_loginmesg"];

	include($template_dir.'login.tpl.php');	// To use native PHP

	$_SESSION["dol_loginmesg"] = '';
}
Пример #6
0
/**
 * Show Dolibarr default login page.
 * Part of this code is also duplicated into main.inc.php::top_htmlhead
 *
 * @param		Translate	$langs		Lang object (must be initialized by a new).
 * @param		Conf		$conf		Conf object
 * @param		Societe		$mysoc		Company object
 * @return		void
 */
function dol_loginfunction($langs, $conf, $mysoc)
{
    global $dolibarr_main_demo, $db;
    global $smartphone, $hookmanager;
    // Instantiate hooks of thirdparty module only if not already define
    if (!is_object($hookmanager)) {
        include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
        $hookmanager = new HookManager($db);
    }
    $hookmanager->initHooks(array('mainloginpage'));
    $langcode = GETPOST('lang') ? is_object($langs) && $langs->defaultlang ? $langs->defaultlang : 'auto' : GETPOST('lang');
    $langs->setDefaultLang($langcode);
    $langs->load("main");
    $langs->load("other");
    $langs->load("help");
    $langs->load("admin");
    $main_authentication = $conf->file->main_authentication;
    $session_name = session_name();
    $dol_url_root = DOL_URL_ROOT;
    $php_self = $_SERVER['PHP_SELF'];
    $php_self .= $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : '';
    // Title
    $title = 'Speedealing ' . DOL_VERSION;
    if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
        $title = $conf->global->MAIN_APPLICATION_TITLE;
    }
    // Select templates
    if (file_exists(DOL_DOCUMENT_ROOT . "/theme/" . $conf->theme . "/tpl/login.tpl.php")) {
        $template_dir = DOL_DOCUMENT_ROOT . "/theme/" . $conf->theme . "/tpl/";
    } else {
        $template_dir = DOL_DOCUMENT_ROOT . "/core/tpl/";
    }
    $conf->css = "/theme/" . (GETPOST('theme') ? GETPOST('theme', 'alpha') : $conf->theme) . "/style.css.php?lang=" . $langs->defaultlang;
    $conf_css = DOL_URL_ROOT . $conf->css;
    // Set cookie for timeout management
    $prefix = dol_getprefix();
    $sessiontimeout = 'DOLSESSTIMEOUT_' . $prefix;
    if (!empty($conf->global->MAIN_SESSION_TIMEOUT)) {
        setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", '', 0);
    }
    if (GETPOST('urlfrom', 'alpha')) {
        $_SESSION["urlfrom"] = GETPOST('urlfrom', 'alpha');
    } else {
        unset($_SESSION["urlfrom"]);
    }
    if (!GETPOST("username")) {
        $focus_element = 'username';
    } else {
        $focus_element = 'password';
    }
    $login_background = DOL_URL_ROOT . '/theme/login_background.png';
    if (file_exists(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/img/login_background.png')) {
        $login_background = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/login_background.png';
    }
    $demologin = '';
    $demopassword = '';
    if (!empty($dolibarr_main_demo)) {
        $tab = explode(',', $dolibarr_main_demo);
        $demologin = $tab[0];
        $demopassword = $tab[1];
    }
    // Execute hook getLoginPageOptions
    // Should be an array with differents options in $hookmanager->resArray
    $parameters = array('entity' => $_POST['entity']);
    $hookmanager->executeHooks('getLoginPageOptions', $parameters);
    // Note that $action and $object may have been modified by some hooks
    // Login
    $login = !empty($hookmanager->resArray['username']) ? $hookmanager->resArray['username'] : (GETPOST("username", "alpha", 2) ? GETPOST("username", "alpha", 2) : $demologin);
    $password = $demopassword;
    // Show logo (search in order: small company logo, large company logo, theme logo, common logo)
    $width = 0;
    $urllogo = DOL_URL_ROOT . '/theme/login_logo.png';
    if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) {
        $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode('thumbs/' . $mysoc->logo_small);
    } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) {
        $urllogo = DOL_URL_ROOT . '/viewimage.php?cache=1&amp;modulepart=companylogo&amp;file=' . urlencode($mysoc->logo);
        $width = 128;
    } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/img/dolibarr_logo.png')) {
        $urllogo = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/dolibarr_logo.png';
    } elseif (is_readable(DOL_DOCUMENT_ROOT . '/theme/dolibarr_logo.png')) {
        $urllogo = DOL_URL_ROOT . '/theme/dolibarr_logo.png';
    }
    // Security graphical code
    $captcha = 0;
    $captcha_refresh = '';
    if (function_exists("imagecreatefrompng") && !empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) {
        $captcha = 1;
        $captcha_refresh = img_picto($langs->trans("Refresh"), 'refresh', 'id="captcha_refresh_img"');
    }
    // Extra link
    $forgetpasslink = 0;
    $helpcenterlink = 0;
    if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
        if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) {
            $forgetpasslink = 1;
        }
        if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) {
            $helpcenterlink = 1;
        }
    }
    // Home message
    if (!empty($conf->global->MAIN_HOME)) {
        $i = 0;
        while (preg_match('/__\\(([a-zA-Z]+)\\)__/i', $conf->global->MAIN_HOME, $reg) && $i < 100) {
            $conf->global->MAIN_HOME = preg_replace('/__\\(' . $reg[1] . '\\)__/i', $langs->trans($reg[1]), $conf->global->MAIN_HOME);
            $i++;
        }
    }
    $main_home = dol_htmlcleanlastbr($conf->global->MAIN_HOME);
    // Google AD
    $main_google_ad_client = !empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && !empty($conf->global->MAIN_GOOGLE_AD_SLOT) ? 1 : 0;
    $dol_loginmesg = $_SESSION["dol_loginmesg"];
    $favicon = DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/favicon.ico';
    $jquerytheme = 'smoothness';
    if (!empty($conf->global->MAIN_USE_JQUERY_THEME)) {
        $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME;
    }
    include $template_dir . 'login.tpl.php';
    // To use native PHP
    $_SESSION["dol_loginmesg"] = '';
}