LStemplate : display error page on fatal error

This commit is contained in:
Benjamin Renard 2019-06-28 18:02:44 +02:00
parent f64cc3cc19
commit aa6bb472b7
4 changed files with 93 additions and 0 deletions

View file

@ -333,3 +333,45 @@ input[type='submit'].LSview_search {
margin-bottom: 0; margin-bottom: 0;
margin-left: 1.2em; margin-left: 1.2em;
} }
/*
*********************
* Fatal error
*********************
*/
#fatal_error {
margin: auto;
max-width: 80%;
text-align: center;
}
#fatal_error h1 {
border: none;
}
#fatal_error pre {
color: #111;
text-align: left;
background-color: #eee;
width: 80%;
margin: auto;
margin-top: 3em;
padding: 0.5em;
border-radius: 1em;
border: 1px solid #ccc;
}
#fatal_error pre em {
border-radius: 6px;
background-color: #60B7D4;
font-family: sans-serif;
font-size: 1em;
font-style: normal;
padding: 5px;
margin: 0.2em;
margin-top: -1.5em;
display: block;
max-width: 50%;
border-radius: 1em;
font-weight: bold;
}

View file

@ -159,6 +159,15 @@ class LSlog {
// Logging on this handler // Logging on this handler
call_user_func(array($handler, 'logging'), $level, $message); call_user_func(array($handler, 'logging'), $level, $message);
} }
if ($level == 'FATAL') {
if (php_sapi_name() == "cli")
die($message);
elseif (class_exists('LStemplate'))
LStemplate :: fatal_error($message);
else
die($message);
}
} }
/** /**

View file

@ -320,6 +320,19 @@ class LStemplate {
return self :: $_smarty -> fetch("ls:$template"); return self :: $_smarty -> fetch("ls:$template");
} }
/**
* Handle fatal error
*
* @param[in] $error string|null Error message (optional)
*
* @retval void
**/
public static function fatal_error($error=null) {
self :: $_smarty -> assign('fatal_error', $error);
self :: $_smarty -> display("ls:fatal_error.tpl");
exit();
}
/** /**
* Register a template function * Register a template function
* *

View file

@ -0,0 +1,29 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset={$LSencoding}">
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle|escape:"htmlall"}{/if}</title>
<link rel="icon" type="image/png" href="images/default/favicon.png" />
<link rel="stylesheet" type="text/css" href="{css name='base.css'}" title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" />
{$LSsession_css}
</head>
<body>
{include file='ls:LSdefault.tpl'}
{$LSsession_js}
<div id="fatal_error">
<h1>{tr msg="A fatal error occured. If problem persist, please contact support."}</h1>
{if $fatal_error}
<pre class='details'>
<em>{tr msg="Details"} :</em>
{$fatal_error}</p>
{/if}
</div>
</body>
</html>