Code

Updated in
[gosa.git] / gosa-core / include / class_msg_dialog.inc
index 4293414ca1b3c563a5d6a530714407359271da88..e13389a0399359300a6ab3b1697be670acb1982b 100644 (file)
@@ -1,10 +1,31 @@
 <?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 define("INFO_DIALOG"           , 10001);
 define("WARNING_DIALOG"                , 10002);
 define("ERROR_DIALOG"          , 10003);
 define("CONFIRM_DIALOG"                , 10004);
-define("FATAL_ERROR_DIALOG"    , 10005);
+define("OK_CANCEL_DIALOG"      , 10005);
+define("FATAL_ERROR_DIALOG"    , 10006);
 
 class msg_dialog
 {
@@ -17,22 +38,25 @@ class msg_dialog
        public function __construct($s_title,$s_message,$i_type)
        {
                global $config;
+
+               if(empty($s_message)) return;
        
-               if(!in_array($i_type,array(INFO_DIALOG,WARNING_DIALOG,ERROR_DIALOG,CONFIRM_DIALOG,FATAL_ERROR_DIALOG))){
+               if(!in_array_strict($i_type,array(INFO_DIALOG,WARNING_DIALOG,ERROR_DIALOG,CONFIRM_DIALOG,FATAL_ERROR_DIALOG,OK_CANCEL_DIALOG))){
                        trigger_error("Invalid msg_dialog type.");
                        $i_type = INFO_DIALOG;
                }
 
-               if((!isset($_SESSION['errorsAlreadyPosted'])) || !is_array($_SESSION['errorsAlreadyPosted'])){
+               if((!session::is_set('errorsAlreadyPosted')) || !is_array(session::get('errorsAlreadyPosted'))){
                        session::set('errorsAlreadyPosted',array());
                }
 
-               if(!isset($_SESSION['errorsAlreadyPosted'][$s_title.$s_message])){
-                       $_SESSION['errorsAlreadyPosted'][$s_title.$s_message] = 0;
+               $errorsAlreadyPosted = session::get('errorsAlreadyPosted');
+               if(!isset($errorsAlreadyPosted[$s_title.$s_message])){
+                       $errorsAlreadyPosted[$s_title.$s_message] = 0;
                }
-               $_SESSION['errorsAlreadyPosted'][$s_title.$s_message]++;
+               $errorsAlreadyPosted[$s_title.$s_message]++;
 
-               if($_SESSION['errorsAlreadyPosted'][$s_title.$s_message] <=1  ){
+               if($errorsAlreadyPosted[$s_title.$s_message] <=1  ){
 
                        $this->i_ID      = preg_replace("/[^0-9]*/","",microtime()); 
                        $this->s_Title   = $s_title;
@@ -42,11 +66,10 @@ class msg_dialog
                        /* Append trace information, only if error messages are enabled */
                        if(     isset($config) && 
                                is_object($config) && 
-                               isset($config->data['MAIN']['DISPLAYERRORS']) &&
-                               preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS'])){
+                               $config->get_cfg_value("displayerrors") == "true" ){
                                $this->a_Trace   = debug_backtrace();
                        }
-                       if(!isset($_SESSION['msg_dialogs'])){
+                       if(!session::is_set('msg_dialogs')){
                                session::set('msg_dialogs',array());
                        }
                        if($this->i_Type == FATAL_ERROR_DIALOG){
@@ -54,16 +77,30 @@ class msg_dialog
                                error_reporting(E_ALL);
                                echo $this->execute();
                        }else{
-                               $_SESSION['msg_dialogs'][] = $this;
+                               $msg_dialogs   = session::get('msg_dialogs');
+                               $msg_dialogs[] = $this;
+                               session::set('msg_dialogs',$msg_dialogs);
                        }
                }
+               session::set('errorsAlreadyPosted',$errorsAlreadyPosted);
        }
 
+
        public static function display($s_title,$s_message,$i_type = INFO_DIALOG)
        {
                new msg_dialog($s_title,$s_message,$i_type);    
        }
 
+
+       public static function displayChecks($messages)
+       {
+               /* Assemble the message array to a plain string */
+               foreach ($messages as $error){
+                       msg_dialog::display(_("Error"), $error, ERROR_DIALOG);
+               }
+       }
+
+
        public function get_ID()
        {
                return($this->i_ID);
@@ -82,7 +119,7 @@ class msg_dialog
                                <tr><td style='vertical-align:top;padding:10px'>
                                <img src='images/error.png' alt='{t}Error{/t}'>
                                </td><td style='width:100%'>
-                               <b>Fatal Error - GOsa execution abortet - ".$this->s_Title."</b><br>
+                               <b>".$this->s_Title."</b><br>
                                ".$this->s_Message."<br><br>
                                "._("Please fix the above error and reload the page.")."
                                </td></tr>
@@ -98,7 +135,7 @@ class msg_dialog
                        $smarty->assign("s_Title",$this->s_Title);
                        $smarty->assign("i_ID",$this->i_ID);
                        $smarty->assign("frame",false);
-                       $smarty->assign("JS",$_SESSION['js']);
+                       $smarty->assign("JS",session::global_get('js'));
                        $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
                        return($smarty->fetch(get_template_path('msg_dialog.tpl')));
                }
@@ -125,7 +162,7 @@ class msg_dialog
 #                      $seen = $_POST['closed_msg_dialogs'];
                }
 
-               if(isset($_SESSION['msg_dialogs']) && is_array($_SESSION['msg_dialogs']) && count($_SESSION['msg_dialogs'])){
+               if(session::is_set('msg_dialogs') && is_array(session::get('msg_dialogs')) && count(session::get('msg_dialogs'))){
 
                        /* Get frame one */
                        $smarty = get_smarty();
@@ -133,20 +170,22 @@ class msg_dialog
                        $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
                        $return = $smarty->fetch(get_template_path('msg_dialog.tpl'));
 
-                       if(!$_SESSION['js']){
-                               $dialog = array_pop($_SESSION['msg_dialogs']);
+                       if(!session::global_get('js')){
+                               $dialog = array_pop(session::get('msg_dialogs'));
                                $return.= $dialog->execute();
                        }else{
-                               foreach($_SESSION['msg_dialogs'] as $key => $dialog){
+                               $msg_dialogs = session::get('msg_dialogs');
+                               foreach($msg_dialogs as $key => $dialog){
 
                                        if(preg_match("/".$dialog->get_ID()."/",$seen)){
-                                               unset($_SESSION['msg_dialogs'][$key]);
+                                               unset($msg_dialogs[$key]);
                                        }else{
                                                $return.= $dialog->execute();
                                                $dialog_ids= $dialog->get_ID().",".$dialog_ids;
                                        }
-                                       unset($_SESSION['msg_dialogs'][$key]);
+                                       unset($msg_dialogs[$key]);
                                }
+                               session::set('msg_dialogs',$msg_dialogs);
                        }
                        $dialog_ids = preg_replace("/,$/","",$dialog_ids);
 
@@ -158,5 +197,6 @@ class msg_dialog
                }
                return($return);
        }
+
 }
 ?>