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 = "";
33 public function __construct($config,$data = array())
34 {
35 DaemonEvent::__construct($config,$data);
36 $this->s_Menu_Name = _("Send message");
37 $this->s_Event_Name = _("Send message");
38 $this->s_Schedule_Action = "job_trigger_action_notify";
39 $this->s_Trigger_Action= "gosa_trigger_action_notify";
40 $this->s_Queued_Action= "trigger_action_notify";
41 $this->s_Menu_Image = "images/mailto.png";
42 $this->s_List_Image = "images/mailto.png";
43 $this->a_targets = array("GOsa"); // Required to get the event send. Maybe this is a wrong value.
44 }
46 public function execute()
47 {
48 DaemonEvent::execute();
49 if(isset($_POST['add_any_target'])){
50 echo "Not implemented yet";
51 }
52 $display = $this->get_header();
53 $tmp = $this->data;
54 $smarty = get_smarty();
55 $smarty->assign("subject" ,"subject");
56 $smarty->assign("message" ,"message");
57 $smarty->assign("data" , $this->data);
58 $smarty->assign("is_new" , $this->is_new);
59 $smarty->assign("timestamp" , $this->get_time_select());
61 $smarty->assign("users" , $this->users);
62 $smarty->assign("groups" , $this->groups);
64 $smarty->assign("add_str", msgPool::addButton(_("Target")));
65 $smarty->assign("del_str", msgPool::delButton(_("Target")));
67 $smarty->assign("subject", xmlentities($this->subject));
68 $smarty->assign("message", xmlentities($this->message));
70 $display.= $smarty->fetch(get_template_path('DaemonEvent_notify.tpl', TRUE, dirname(__FILE__)));
71 $display.= $this->get_footer();
72 return($display);
73 }
76 public function check()
77 {
78 $msgs = DaemonEvent::check();
79 if(empty($this->subject)){
80 $msgs[] = msgPool::required(_("Subject"));
81 }
82 if(empty($this->message)){
83 $msgs[] = msgPool::required(_("Message"));
84 }
85 if(!count($this->groups) && !count($this->users)){
86 $msgs[] = msgPool::required(_("Target"));
87 }
88 return($msgs);
89 }
92 public function save_object()
93 {
94 DaemonEvent::save_object();
96 if(isset($_POST['del_any_target']) && isset($_POST['groups'])){
97 foreach($_POST['groups'] as $id){
98 if(isset($this->groups[$id])){
99 unset($this->groups[$id]);
100 }
101 }
102 }
103 if(isset($_POST['del_any_target']) && isset($_POST['users'])){
104 foreach($_POST['users'] as $id){
105 if(isset($this->users[$id])){
106 unset($this->users[$id]);
107 }
108 }
109 }
111 if(isset($_POST['subject'])){
112 $this->subject = get_post('subject');
113 }
114 if(isset($_POST['message'])){
115 $this->message = get_post('message');
116 }
117 }
119 public function add_users($targets)
120 {
121 $this->users = $targets;
122 }
124 public function add_groups($targets)
125 {
126 $this->groups = $targets;
127 }
129 public function save()
130 {
131 $ret = DaemonEvent::save();
132 $ret['users'] = array_values($this->users);
133 $ret['groups'] = array_values($this->groups);
134 $ret['subject'] = $this->subject;
135 $ret['message'] = $this->message;
136 return($ret);
137 }
138 }
139 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
140 ?>