Code

Added simple js handling to popup js dialogs, not finished yet
[gosa.git] / include / class_msg_dialog.inc
1 <?php
3 define("INFO_DIALOG"    , 10001);
4 define("WARNING_DIALOG" , 10002);
5 define("ERROR_DIALOG"   , 10003);
6 define("CONFIRM_DIALOG" , 10004);
8 class msg_dialog
9 {
10         private $s_Title        = "Undefined";
11         private $s_Message      = "Undefined";
12         private $i_Type         = INFO_DIALOG ;
13         private $i_ID           = 0;
15         public function __construct($s_title,$s_message,$i_type)
16         {
17                 $this->i_ID      = preg_replace("/[^0-9]*/","",microtime()); 
18                 $this->s_Title   = $s_title;
19                 $this->s_Message = $s_message;
20                 $this->i_Type    = $i_type;
21                 if(!isset($_SESSION['msg_dialogs'])){
22                         $_SESSION['msg_dialogs'] = array();
23                 }
24                 $_SESSION['msg_dialogs'][] = $this;
25         }
27         public static function display($s_title,$s_message,$i_type = INFO_DIALOG)
28         {
29                 $box = new msg_dialog($s_title,$s_message,$i_type);     
30         }
32         public function is_confirmed()
33         {
34                 if($this->i_Type == CONFIRM_DIALOG && isset($_POST['MSG_OK'])){
35                         return(TRUE);
36                 }
37         }
39         public function get_ID()
40         {
41                 return($this->i_ID);
42         }
44         public function execute()
45         {
46                 $smarty = get_smarty();
47                 $smarty->assign("i_Type",$this->i_Type);
48                 $smarty->assign("s_Message",$this->s_Message);
49                 $smarty->assign("s_Title",$this->s_Title);
50                 $smarty->assign("i_ID",$this->i_ID);
51                 $smarty->assign("IE",preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT']));
52                 return($smarty->fetch(get_template_path('msg_dialog.tpl')));
53         }
54         
56         public static function get_dialogs()
57         {
58                 $return  ="";
59                 $dialog_ids= "";        
60                 if(isset($_SESSION['msg_dialogs']) && is_array($_SESSION['msg_dialogs'])){
61                         foreach($_SESSION['msg_dialogs'] as $key => $dialog){
62                                 $return.= $dialog->execute();
63                                 $dialog_ids= $dialog->get_ID().",".$dialog_ids;
64                         }
65                 }
66                 unset($_SESSION['msg_dialogs']);
67                 $dialog_ids = preg_replace("/,$/","",$dialog_ids);
68                 
69                 $return .="<input type='text' style='width:400px;' name='pending_msg_dialogs' id='pending_msg_dialogs' value='".$dialog_ids."'>";
70                 $return .="<input type='text' style='width:400px;' name='current_msg_dialogs' id='current_msg_dialogs' value=''>";
71                 return($return);
72         }
73 }
74 ?>