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 $users = array();
28 var $groups= array();
30 var $message = "";
31 var $subject = "";
32 var $from = "";
34 public function __construct($config,$data = array())
35 {
36 DaemonEvent::__construct($config,$data);
38 $ui = get_userinfo();
39 $this->from = $ui->cn;
41 $this->message = base64_decode($this->message);
43 $this->s_Menu_Name = _("Send message");
44 $this->s_Event_Name = _("Send message");
46 $this->s_Schedule_Action = "job_send_user_msg";
47 $this->s_Trigger_Action= "gosa_send_user_msg";
48 $this->s_Queued_Action= "trigger_action_notify";
49 $this->s_Menu_Image = "images/mailto.png";
50 $this->s_List_Image = "images/mailto.png";
51 $this->a_targets = array("GOSA"); // Required to get the event send. Maybe this is a wrong value.
52 }
54 public function execute()
55 {
56 DaemonEvent::execute();
58 /* Check if target add dialog is open */
59 if($this->is_target_list_open() && $this->is_new){
60 return($this->get_target_add_list());
61 }
64 $display = $this->get_header();
65 $tmp = $this->data;
66 $smarty = get_smarty();
67 $smarty->assign("data" , $this->data);
68 $smarty->assign("is_new" , $this->is_new);
69 $smarty->assign("timestamp" , $this->get_time_select());
71 $smarty->assign("users" , $this->users);
72 $smarty->assign("groups" , $this->groups);
74 $smarty->assign("add_str", msgPool::addButton(_("Target")));
75 $smarty->assign("del_str", msgPool::delButton(_("Target")));
77 $smarty->assign("from", xmlentities($this->from));
78 $smarty->assign("subject", xmlentities($this->subject));
79 $smarty->assign("message", xmlentities($this->message));
81 $display.= $smarty->fetch(get_template_path('DaemonEvent_notify.tpl', TRUE, dirname(__FILE__)));
82 $display.= $this->get_footer();
83 return($display);
84 }
87 public function check()
88 {
89 $msgs = DaemonEvent::check();
90 if(empty($this->subject)){
91 $msgs[] = msgPool::required(_("Subject"));
92 }
93 if(empty($this->message)){
94 $msgs[] = msgPool::required(_("Message"));
95 }
96 if(empty($this->from)){
97 $msgs[] = msgPool::required(_("From"));
98 }
99 if(!count($this->groups) && !count($this->users)){
100 $msgs[] = msgPool::required(_("Target"));
101 }
102 return($msgs);
103 }
106 public function save_object()
107 {
108 DaemonEvent::save_object();
110 if(isset($_POST['del_any_target']) && isset($_POST['groups'])){
111 foreach($_POST['groups'] as $id){
112 if(isset($this->groups[$id])){
113 unset($this->groups[$id]);
114 }
115 }
116 }
117 if(isset($_POST['del_any_target']) && isset($_POST['users'])){
118 foreach($_POST['users'] as $id){
119 if(isset($this->users[$id])){
120 unset($this->users[$id]);
121 }
122 }
123 }
125 if(isset($_POST['subject'])){
126 $this->subject = get_post('subject');
127 }
128 if(isset($_POST['message'])){
129 $this->message = get_post('message');
130 }
131 if(isset($_POST['from'])){
132 $this->from = get_post('from');
133 }
134 }
136 public function add_users($targets)
137 {
138 $add = $targets;
139 if(!is_array($add)){
140 $add = array($add);
141 }
142 foreach($add as $target){
143 if(!in_array($target,$this->users)){
144 $this->users[] = $target;
145 }
146 }
147 }
150 public function add_groups($targets)
151 {
152 $add = $targets;
153 if(!is_array($add)){
154 $add = array($add);
155 }
156 foreach($add as $target){
157 if(!in_array($target,$this->groups)){
158 $this->groups[] = $target;
159 }
160 }
161 }
164 /*! \brief Returns HTML content, displaying a dialog which allows to add new targets.
165 @return String HTML content. (EventTargetAddList)
166 */
167 public function get_target_add_list()
168 {
169 $this->target_add_list_used = TRUE;
171 if($this->target_divlist == NULL){
172 $this->target_divlist = new EventTargetAddUserList($this->config,$this);
173 }
174 $this->target_divlist->execute();
176 $smarty = get_smarty();
177 $smarty->assign("divlist",$this->target_divlist->Draw());
178 return($smarty->fetch(get_template_path('target_list.tpl', TRUE, dirname(__FILE__))));
179 }
182 /*! \brief Add a target MAC address
183 @param Array A List of all target that should be added.
184 */
185 public function add_targets($targets)
186 {
187 if(isset($targets['USERS'])){
188 $this->add_users($targets['USERS']);
189 }
190 if(isset($targets['GROUPS'])){
191 $this->add_groups($targets['GROUPS']);
192 }
193 }
196 public function save()
197 {
198 $ret = DaemonEvent::save();
199 $ret['users'] = array_values($this->users);
200 $ret['groups'] = array_values($this->groups);
201 $ret['subject'] = $this->subject;
202 $ret['from'] = $this->from;
203 $ret['message'] = base64_encode($this->message);
204 return($ret);
205 }
206 }
207 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
208 ?>