inc/error.php
defbfa55
 <?php
c208bd90
 /*
 This file belongs to the Webinterface of schokokeks.org Hosting
 
5effc2bd
 Written 2008-2014 by schokokeks.org Hosting, namely
c208bd90
   Bernd Wurst <bernd@schokokeks.org>
   Hanno Böck <hanno@schokokeks.org>
 
 To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
 
 You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see 
 http://creativecommons.org/publicdomain/zero/1.0/
 
 Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
 */
defbfa55
 
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;
 
8d843ef1
   return (count($input_error) > 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)
 {
73aefd48
   if (have_module('index')) {
     if (isset($_COOKIE['CLIENTCERT_AUTOLOGIN']) && $_COOKIE['CLIENTCERT_AUTOLOGIN'] == '1') {
       require_once('modules/index/include/x509.php');
       do_ajax_cert_login();
     }
   }
d73051da
   require_once('inc/theme.php');
   if ($why) {
     warning($why);
   }
   show_page('login');
   die();
defbfa55
 }
 
 
 ?>