inc/error.php
defbfa55
 <?php
 
af8c8976
 require_once("inc/security.php");
 
defbfa55
 function system_failure($reason)
 {
d73051da
 	input_error($reason);
 	show_page();
defbfa55
         die();
 }
 
 
 function input_error($reason)
 {
   global $input_error;
   if (!isset($input_error))
     $input_error = array();
   array_push($input_error, $reason);
 }
 
 function warning($msg)
 {
7cd93137
   if (!isset($_SESSION['warning']))
     $_SESSION['warning'] = array();
   array_push($_SESSION['warning'], $msg);
defbfa55
 }
 
 function success_msg($msg)
 {
7cd93137
   if (!isset($_SESSION['success_msg']))
     $_SESSION['success_msg'] = array();
   array_push($_SESSION['success_msg'], $msg);
defbfa55
 }
 
 
90ff5748
 function we_have_an_error()
 {
   global $input_error;
 
7cd93137
   return ((count($input_error) + count($_SESSION['warning'])) > 0);
90ff5748
 
 }
 
 
d73051da
 function get_messages()
defbfa55
 {
d73051da
   $messages = '';
defbfa55
   global $input_error;
   if (isset($input_error))
   {
d73051da
     $messages .= '<div class="error">
defbfa55
     <h3>Fehler</h3>
     <p>Folgende Fehler wurden festgestellt: </p>
     <ul>
     ';
     foreach ($input_error as $error)
     {
d73051da
       $messages .= '<li>'.nl2br(filter_input_general($error))."</li>\n";
defbfa55
     }
d73051da
     $messages .= '</ul>
defbfa55
     </div>';
   }
7cd93137
   if (isset($_SESSION['warning']))
defbfa55
   {
d73051da
     $messages .= '<div class="error">
defbfa55
     <ul>
     ';
7cd93137
     foreach ($_SESSION['warning'] as $msg)
defbfa55
     {
d73051da
       $messages .= '<li>'.nl2br(filter_input_general($msg))."</li>\n";
defbfa55
     }
d73051da
     $messages .= '</ul>
defbfa55
     </div>';
7cd93137
     unset($_SESSION['warning']);
defbfa55
   }
7cd93137
   if (isset($_SESSION['success_msg']))
defbfa55
   {
d73051da
     $messages .= '<div class="success">
defbfa55
     <ul>
     ';
7cd93137
     foreach ($_SESSION['success_msg'] as $msg)
defbfa55
     {
d73051da
       $messages .= '<li>'.nl2br(filter_input_general($msg))."</li>\n";
defbfa55
     }
d73051da
     $messages .= '</ul>
defbfa55
     </div>';
7cd93137
     unset($_SESSION['success_msg']);
defbfa55
   }
d73051da
   return $messages;
defbfa55
 }
 
d73051da
 function show_messages() 
 {
   echo get_messages();
 }
defbfa55
 
 function require_role($roles)
 {
   if (! is_array($roles))
     $roles = array($roles);
   $allow = false;
   foreach ($roles as $role)
db10e50b
     if ($role & $_SESSION['role'])
defbfa55
       $allow = true;
   if (! $allow)
db10e50b
     if ($_SESSION['role'] == ROLE_ANONYMOUS)
       login_screen("Diese Seite können Sie erst benutzen, wenn Sie sich mit Ihren Zugangsdaten anmelden.");
     else
       login_screen("Diese Seite können Sie mit Ihren aktuellen Zugriffsrechten nicht benutzen, bitte melden Sie sich mit den benötigten Zugriffsrechten an!");
defbfa55
 }
 
 
 function login_screen($why)
 {
d73051da
   require_once('inc/theme.php');
   if ($why) {
     warning($why);
   }
   show_page('login');
   die();
defbfa55
 }
 
 
 ?>