8d6d633347b7cea789f70a363d993329ca047acc
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 $this->i_ID = preg_replace("/[^0-9]*/","",microtime());
25 $this->s_Title = $s_title;
26 $this->s_Message = $s_message;
27 $this->i_Type = $i_type;
28 $this->a_Trace = debug_backtrace();
29 if(!isset($_SESSION['msg_dialogs'])){
30 $_SESSION['msg_dialogs'] = array();
31 }
32 if($this->i_Type == FATAL_ERROR_DIALOG){
33 restore_error_handler();
34 error_reporting(E_ALL);
35 echo $this->execute();
36 }else{
37 $_SESSION['msg_dialogs'][] = $this;
38 }
39 }
41 public static function display($s_title,$s_message,$i_type = INFO_DIALOG)
42 {
43 new msg_dialog($s_title,$s_message,$i_type);
44 }
46 public function get_ID()
47 {
48 return($this->i_ID);
49 }
51 public function execute()
52 {
53 if($this->i_Type == FATAL_ERROR_DIALOG) {
54 $display =
55 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
56 \"http://www.w3.org/TR/html4/transitional.dtd\">
57 <html><head>
58 <title>GOsa startup failed</title>
59 </head><body>
60 <table style='width:100%; border:2px solid red;' summary=''>
61 <tr><td style='vertical-align:top;padding:10px'>
62 <img src='images/error.png' alt='{t}Error{/t}'>
63 </td><td style='width:100%'>
64 <b>Fatal Error - GOsa execution abortet - ".$this->s_Title."</b><br>
65 ".$this->s_Message."<br><br>
66 "._("Please fix the above error and reload the page.")."
67 </td></tr>
68 </table></body></html>";
69 return($display);;
70 }else{
72 $smarty = get_smarty();
73 $smarty->assign("s_Trace",print_a($this->a_Trace,TRUE));
74 $smarty->assign("i_Type",$this->i_Type);
75 $smarty->assign("s_Message",$this->s_Message);
76 $smarty->assign("s_Title",$this->s_Title);
77 $smarty->assign("i_ID",$this->i_ID);
78 $smarty->assign("frame",false);
79 $smarty->assign("JS",$_SESSION['js']);
80 $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
81 return($smarty->fetch(get_template_path('msg_dialog.tpl')));
82 }
83 }
86 public function is_confirmed()
87 {
88 if(isset($_POST['MSG_OK'.$this->i_ID])){
89 return(TRUE);
90 }else{
91 return(FALSE);
92 }
93 }
96 public static function get_dialogs()
97 {
98 $return ="";
99 $dialog_ids= "";
101 $seen = "";
102 if(isset($_POST['closed_msg_dialogs'])){
103 # $seen = $_POST['closed_msg_dialogs'];
104 }
106 if(isset($_SESSION['msg_dialogs']) && is_array($_SESSION['msg_dialogs']) && count($_SESSION['msg_dialogs'])){
108 /* Get frame one */
109 $smarty = get_smarty();
110 $smarty->assign("frame", true);
111 $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
112 $return = $smarty->fetch(get_template_path('msg_dialog.tpl'));
114 if(!$_SESSION['js']){
115 $dialog = array_pop($_SESSION['msg_dialogs']);
116 $return.= $dialog->execute();
117 }else{
118 foreach($_SESSION['msg_dialogs'] as $key => $dialog){
120 if(preg_match("/".$dialog->get_ID()."/",$seen)){
121 unset($_SESSION['msg_dialogs'][$key]);
122 }else{
123 $return.= $dialog->execute();
124 $dialog_ids= $dialog->get_ID().",".$dialog_ids;
125 }
126 unset($_SESSION['msg_dialogs'][$key]);
127 }
128 }
129 $dialog_ids = preg_replace("/,$/","",$dialog_ids);
131 $return .= "</div>";
132 $return .="<input type='hidden' style='width:400px;' name='pending_msg_dialogs' id='pending_msg_dialogs' value='".$dialog_ids."'>";
133 $return .="<input type='hidden' style='width:400px;' name='closed_msg_dialogs' id='closed_msg_dialogs' value=''>";
134 $return .="<input type='hidden' style='width:400px;' name='current_msg_dialogs' id='current_msg_dialogs' value=''>";
135 $return .="<input type='hidden' style='width:700px;' name='js_debug' id='js_debug'>";
136 }
137 return($return);
138 }
139 }
140 ?>