505d47fc7b412bb77c4a673042f69f364a7e6e75
1 <?php
3 define("INFO_DIALOG" , 10001);
4 define("WARNING_DIALOG" , 10002);
5 define("ERROR_DIALOG" , 10003);
6 define("CONFIRM_DIALOG" , 10004);
7 define("FATAL_ERROR_DIALOG" , 10005);
9 class msg_dialog
10 {
11 private $s_Title = "Undefined";
12 private $s_Message = "Undefined";
13 private $i_Type = INFO_DIALOG ;
14 private $i_ID = 0;
15 private $a_Trace = array();
17 public function __construct($s_title,$s_message,$i_type)
18 {
19 if(!in_array($i_type,array(INFO_DIALOG,WARNING_DIALOG,ERROR_DIALOG,CONFIRM_DIALOG,FATAL_ERROR_DIALOG))){
20 trigger_error("Invalid msg_dialog type.");
21 $i_type = INFO_DIALOG;
22 }
24 if((!isset($_SESSION['errorsAlreadyPosted'])) || !is_array($_SESSION['errorsAlreadyPosted'])){
25 $_SESSION['errorsAlreadyPosted'] = array();
26 }
28 if(!isset($_SESSION['errorsAlreadyPosted'][$s_title.$s_message])){
29 $_SESSION['errorsAlreadyPosted'][$s_title.$s_message] = 0;
30 }
31 $_SESSION['errorsAlreadyPosted'][$s_title.$s_message]++;
33 if($_SESSION['errorsAlreadyPosted'][$s_title.$s_message] <=1 ){
35 $this->i_ID = preg_replace("/[^0-9]*/","",microtime());
36 $this->s_Title = $s_title;
37 $this->s_Message = $s_message;
38 $this->i_Type = $i_type;
39 $this->a_Trace = debug_backtrace();
40 if(!isset($_SESSION['msg_dialogs'])){
41 $_SESSION['msg_dialogs'] = array();
42 }
43 if($this->i_Type == FATAL_ERROR_DIALOG){
44 restore_error_handler();
45 error_reporting(E_ALL);
46 echo $this->execute();
47 }else{
48 $_SESSION['msg_dialogs'][] = $this;
49 }
50 }
51 }
53 public static function display($s_title,$s_message,$i_type = INFO_DIALOG)
54 {
55 new msg_dialog($s_title,$s_message,$i_type);
56 }
58 public function get_ID()
59 {
60 return($this->i_ID);
61 }
63 public function execute()
64 {
65 if($this->i_Type == FATAL_ERROR_DIALOG) {
66 $display =
67 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
68 \"http://www.w3.org/TR/html4/transitional.dtd\">
69 <html><head>
70 <title>GOsa startup failed</title>
71 </head><body>
72 <table style='width:100%; border:2px solid red;' summary=''>
73 <tr><td style='vertical-align:top;padding:10px'>
74 <img src='images/error.png' alt='{t}Error{/t}'>
75 </td><td style='width:100%'>
76 <b>Fatal Error - GOsa execution abortet - ".$this->s_Title."</b><br>
77 ".$this->s_Message."<br><br>
78 "._("Please fix the above error and reload the page.")."
79 </td></tr>
80 </table></body></html>";
81 return($display);;
82 }else{
84 $smarty = get_smarty();
85 $smarty->assign("s_Trace",print_a($this->a_Trace,TRUE));
86 $smarty->assign("i_Type",$this->i_Type);
87 $smarty->assign("s_Message",$this->s_Message);
88 $smarty->assign("s_Title",$this->s_Title);
89 $smarty->assign("i_ID",$this->i_ID);
90 $smarty->assign("frame",false);
91 $smarty->assign("JS",$_SESSION['js']);
92 $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
93 return($smarty->fetch(get_template_path('msg_dialog.tpl')));
94 }
95 }
98 public function is_confirmed()
99 {
100 if(isset($_POST['MSG_OK'.$this->i_ID])){
101 return(TRUE);
102 }else{
103 return(FALSE);
104 }
105 }
108 public static function get_dialogs()
109 {
110 $return ="";
111 $dialog_ids= "";
113 $seen = "";
114 if(isset($_POST['closed_msg_dialogs'])){
115 # $seen = $_POST['closed_msg_dialogs'];
116 }
118 if(isset($_SESSION['msg_dialogs']) && is_array($_SESSION['msg_dialogs']) && count($_SESSION['msg_dialogs'])){
120 /* Get frame one */
121 $smarty = get_smarty();
122 $smarty->assign("frame", true);
123 $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
124 $return = $smarty->fetch(get_template_path('msg_dialog.tpl'));
126 if(!$_SESSION['js']){
127 $dialog = array_pop($_SESSION['msg_dialogs']);
128 $return.= $dialog->execute();
129 }else{
130 foreach($_SESSION['msg_dialogs'] as $key => $dialog){
132 if(preg_match("/".$dialog->get_ID()."/",$seen)){
133 unset($_SESSION['msg_dialogs'][$key]);
134 }else{
135 $return.= $dialog->execute();
136 $dialog_ids= $dialog->get_ID().",".$dialog_ids;
137 }
138 unset($_SESSION['msg_dialogs'][$key]);
139 }
140 }
141 $dialog_ids = preg_replace("/,$/","",$dialog_ids);
143 $return .= "</div>";
144 $return .="<input type='hidden' style='width:400px;' name='pending_msg_dialogs' id='pending_msg_dialogs' value='".$dialog_ids."'>";
145 $return .="<input type='hidden' style='width:400px;' name='closed_msg_dialogs' id='closed_msg_dialogs' value=''>";
146 $return .="<input type='hidden' style='width:400px;' name='current_msg_dialogs' id='current_msg_dialogs' value=''>";
147 $return .="<input type='hidden' style='width:700px;' name='js_debug' id='js_debug'>";
148 }
149 return($return);
150 }
151 }
152 ?>