1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class DaemonEvent_notify extends DaemonEvent
24 {
25 var $visible_for = USER_EVENT;
27 var $user = array();
28 var $group= array();
30 var $message = "";
31 var $subject = "";
32 var $from = "";
34 var $attributes = array("from","user","group","message","subject","timestamp");
36 public function __construct($config,$data = array())
37 {
38 DaemonEvent::__construct($config,$data);
40 $ui = get_userinfo();
41 $this->from = $ui->cn;
43 $this->message = base64_decode($this->message);
44 $this->subject = base64_decode($this->subject);
46 $this->s_Menu_Name = _("Send message");
47 $this->s_Event_Name = _("Send message");
49 $this->s_Schedule_Action = "job_send_user_msg";
50 $this->s_Trigger_Action= "gosa_send_user_msg";
51 $this->s_Queued_Action= "trigger_action_notify";
52 $this->s_Menu_Image = "plugins/goto/images/notify.png";
53 $this->s_List_Image = "plugins/goto/images/notify.png";
54 $this->a_targets = array("GOSA"); // Required to get the event send. Maybe this is a wrong value.
55 }
57 public function execute()
58 {
59 DaemonEvent::execute();
61 /* Check if target add dialog is open */
62 if($this->is_target_list_open() && $this->is_new){
63 return($this->get_target_add_list());
64 }
67 $display = $this->get_header();
68 $tmp = $this->data;
69 $smarty = get_smarty();
70 $smarty->assign("data" , $this->data);
71 $smarty->assign("is_new" , $this->is_new);
72 $smarty->assign("timestamp" , $this->get_time_select());
74 $smarty->assign("user" , $this->user);
75 $smarty->assign("group" , $this->group);
77 $smarty->assign("add_str", msgPool::addButton(_("Target")));
78 $smarty->assign("del_str", msgPool::delButton(_("Target")));
80 $smarty->assign("from", xmlentities($this->from));
81 $smarty->assign("subject", xmlentities($this->subject));
82 $smarty->assign("message", xmlentities($this->message));
84 $display.= $smarty->fetch(get_template_path('DaemonEvent_notify.tpl', TRUE, dirname(__FILE__)));
85 $display.= $this->get_footer();
86 return($display);
87 }
90 public function check()
91 {
92 $msgs = DaemonEvent::check();
93 if(empty($this->subject)){
94 $msgs[] = msgPool::required(_("Subject"));
95 }
96 if(empty($this->message)){
97 $msgs[] = msgPool::required(_("Message"));
98 }
99 if(empty($this->from)){
100 $msgs[] = msgPool::required(_("From"));
101 }
102 if(!count($this->group) && !count($this->user)){
103 $msgs[] = msgPool::required(_("Target"));
104 }
105 return($msgs);
106 }
109 public function save_object()
110 {
111 DaemonEvent::save_object();
113 if(isset($_POST['del_any_target']) && isset($_POST['group'])){
114 foreach($_POST['group'] as $id){
115 if(isset($this->group[$id])){
116 unset($this->group[$id]);
117 }
118 }
119 }
120 if(isset($_POST['del_any_target']) && isset($_POST['user'])){
121 foreach($_POST['user'] as $id){
122 if(isset($this->user[$id])){
123 unset($this->user[$id]);
124 }
125 }
126 }
128 if(isset($_POST['subject'])){
129 $this->subject = get_post('subject');
130 }
131 if(isset($_POST['message'])){
132 $this->message = get_post('message');
133 }
134 if(isset($_POST['from'])){
135 $this->from = get_post('from');
136 }
137 }
139 public function add_users($targets)
140 {
141 $add = $targets;
142 if(!is_array($add)){
143 $add = array($add);
144 }
145 foreach($add as $target){
146 if(!in_array($target,$this->user)){
147 $this->user[] = $target;
148 }
149 }
150 }
153 public function add_groups($targets)
154 {
155 $add = $targets;
156 if(!is_array($add)){
157 $add = array($add);
158 }
159 foreach($add as $target){
160 if(!in_array($target,$this->group)){
161 $this->group[] = $target;
162 }
163 }
164 }
167 /*! \brief Returns HTML content, displaying a dialog which allows to add new targets.
168 @return String HTML content. (EventTargetAddList)
169 */
170 public function get_target_add_list()
171 {
172 $this->target_add_list_used = TRUE;
174 if($this->target_divlist == NULL){
175 $this->target_divlist = new EventTargetAddUserList($this->config,$this);
176 }
177 $this->target_divlist->execute();
179 $smarty = get_smarty();
180 $smarty->assign("divlist",$this->target_divlist->Draw());
181 return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__))));
182 }
185 /*! \brief Add a target MAC address
186 @param Array A List of all target that should be added.
187 */
188 public function add_targets($targets)
189 {
190 if(isset($targets['USERS'])){
191 $this->add_users($targets['USERS']);
192 }
193 if(isset($targets['GROUPS'])){
194 $this->add_groups($targets['GROUPS']);
195 }
196 }
199 public function save()
200 {
201 $ret = DaemonEvent::save();
202 $ret['delivery_time'] = $ret['timestamp'];
203 $ret['user'] = array_values( $ret['user']);
204 $ret['group'] = array_values( $ret['group']);
205 $ret['subject'] = base64_encode($ret['subject']);
206 $ret['message'] = base64_encode($ret['message']);
207 return($ret);
208 }
209 }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>