Here is how to add a random background image from the popular open source image website unsplash.com
Notes:
- Set [tt]ADD_UNSPLASH_LOGIN_BACKGROUND[/tt] to 1 in [tt]Setup>Other[/tt]
- The background image will be refreshed on every login
- If an already saved background image exists, then this code will override it (but not delete the saved image).
- To return to using a saved background image, set [tt]ADD_UNSPLASH_LOGIN_BACKGROUND[/tt] to 0 in [tt]Setup>Other[/tt]
- This code snippet has been tested on Dolibarr v7 but should work with any version. The actual background image feature on the login page was introduced in v6.
File:
/core/tpl/login.tpl.php[/code]
[b][size=3]Find:[/size][/b] [i](around line 60)[/i]
[code]
<body class="body bodylogin"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND)?'':' style="background-image: url(
[b][size=3]Replace With:[/size][/b]
[code]
<?php if (!empty($conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND)) { ?>
<body class="body bodylogin" style="background-image: url('https://source.unsplash.com/random'); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; background-color: #ffffff;">
<?php }
else { ?>
<body class="body bodylogin"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND)?'':' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; background-image: url('.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).'
[b][size=3]Replace With:[/size][/b]
[!--###kunena-codeblock-2###--])"'; ?>>
[/code]
[b][size=3]Replace With:[/size][/b]
[!--###kunena-codeblock-2###--]'.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).''.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).'
[b][size=3]Replace With:[/size][/b]
[!--###kunena-codeblock-2###--])"'; ?>>
[/code]
[b][size=3]Replace With:[/size][/b]
[!--###kunena-codeblock-2###--])"'; ?>>
<?php } ?>
[/code]'.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).'
[b][size=3]Replace With:[/size][/b]
[code]
<?php if (!empty($conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND)) { ?>
<body class="body bodylogin" style="background-image: url('https://source.unsplash.com/random'); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; background-color: #ffffff;">
<?php }
else { ?>
<body class="body bodylogin"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND)?'':' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; background-image: url()"'; ?>>
[/code]
[b][size=3]Replace With:[/size][/b]
[!--###kunena-codeblock-2###--]'.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).')"'; ?>>
Replace With:
[!–###kunena-codeblock-2###–])"’; ?>>
<?php } ?>
[/code])"’; ?>>
[/code]
Replace With:
<?php if (!empty($conf->global->ADD_UNSPLASH_LOGIN_BACKGROUND)) { ?>
<body class="body bodylogin" style="background-image: url('https://source.unsplash.com/random'); background-repeat: no-repeat; background-position: center center; background-attachment: fixed; background-size: cover; background-color: #ffffff;">
<?php }
else { ?>
<body class="body bodylogin"<?php print empty($conf->global->MAIN_LOGIN_BACKGROUND)?'':' style="background-size: cover; background-position: center center; background-attachment: fixed; background-repeat: no-repeat; background-image: url('.DOL_URL_ROOT.'/viewimage.php?cache=1&noalt=1&modulepart=mycompany&file='.urlencode($conf->global->MAIN_LOGIN_BACKGROUND).')"'; ?>>
<?php } ?>