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 groupManagement extends management
24 {
25 var $plHeadline = "Groups";
26 var $plDescription = "Group administration";
27 var $plIcon = "plugins/groups/images/plugin.png";
29 // Tab definition
30 protected $tabClass = "grouptabs";
31 protected $tabType = "GROUPTABS";
32 protected $aclCategory = "groups";
33 protected $aclPlugin = "group";
34 protected $objectName = "group";
36 function __construct($config,$ui)
37 {
38 $this->config = $config;
39 $this->ui = $ui;
41 $this->storagePoints = array(get_ou("groupRDN"));
43 // Build filter
44 if (session::global_is_set(get_class($this)."_filter")){
45 $filter= session::global_get(get_class($this)."_filter");
46 } else {
47 $filter = new filter(get_template_path("group-filter.xml", true));
48 $filter->setObjectStorage($this->storagePoints);
49 }
50 $this->setFilter($filter);
52 // Build headpage
53 $headpage = new listing(get_template_path("group-list.xml", true));
54 $headpage->registerElementFilter("filterProperties", "groupManagement::filterProperties");
55 $headpage->setFilter($filter);
57 // Add copy&paste and snapshot handler.
58 if ($this->config->boolValueIsTrue("main", "copyPaste")){
59 $this->cpHandler = new CopyPasteHandler($this->config);
60 }
61 if($this->config->get_cfg_value("enableSnapshots") == "true"){
62 $this->snapHandler = new SnapshotHandler($this->config);
63 }
64 parent::__construct($config, $ui, "groups", $headpage);
66 $this->registerAction("edit_group","editEntry");
67 $this->registerAction("edit_environment","editEntry");
68 $this->registerAction("edit_appgroup","editEntry");
69 $this->registerAction("edit_mailgroup","editEntry");
71 $this->registerAction("sendMessage", "sendMessage");
72 $this->registerAction("saveEventDialog", "saveEventDialog");
73 $this->registerAction("abortEventDialog", "closeDialogs");
74 }
76 // Inject user actions
77 function detectPostActions()
78 {
79 $action = management::detectPostActions();
80 if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEventDialog";
81 if(isset($_POST['abort_event_dialog'])) $action['action'] = "abortEventDialog";
82 return($action);
83 }
86 /*! \brief Sends a message to a set of users using gosa-si events.
87 */
88 function saveEventDialog()
89 {
90 $this->dialogObject->save_object();
91 $msgs = $this->dialogObject->check();
92 if(count($msgs)){
93 msg_dialog::displayChecks($msgs);
94 }else{
95 $o_queue = new gosaSupportDaemon();
96 $o_queue->append($this->dialogObject);
97 if($o_queue->is_error()){
98 msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
99 }
100 $this->closeDialogs();
101 }
102 }
105 /*! \brief Sends a message to a set of users using gosa-si events.
106 */
107 function sendMessage($action="",$target=array(),$all=array())
108 {
109 $uids = array();
110 $ldap = $this->config->get_ldap_link();
111 $ldap->cd($this->config->current['BASE']);
112 foreach($target as $dn){
113 $ldap->cat($dn,array('cn'));
114 if($ldap->count()){
115 $attrs = $ldap->fetch();
116 $uids[] = $attrs['cn'][0];
117 }
118 }
119 if(count($uids)){
120 $events = DaemonEvent::get_event_types(USER_EVENT);
121 $event = "DaemonEvent_notify";
122 if(isset($events['BY_CLASS'][$event])){
123 $type = $events['BY_CLASS'][$event];
124 $this->dialogObject = new $type['CLASS_NAME']($this->config);
125 $this->dialogObject->add_groups($uids);
126 $this->dialogObject->set_type(SCHEDULED_EVENT);
127 }
128 }
129 }
132 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
133 {
134 $str = management::editEntry($action,$target);
136 if(preg_match("/^edit_/",$action)){
137 $tab = preg_replace("/^edit_/","",$action);
138 if(isset($this->tabObject->by_object[$tab])){
139 $this->tabObject->current = $tab;
140 }else{
141 trigger_error("Unknown tab: ".$tab);
142 }
143 }
144 if(!empty($str)) return($str);
145 }
147 static function filterProperties($row, $classes)
148 {
149 $result= "";
151 $map = array(
152 "posixGroup" =>
153 array(
154 "image" => "plugins/groups/images/groups.png",
155 "plugin" => "group",
156 "alt" => _("Posix"),
157 "title" => _("Edit posix properties")
158 ),
160 "gosaMailAccount" =>
161 array(
162 "image" => "plugins/groups/images/mail.png",
163 "plugin" => "mailgroup",
164 "alt" => _("Mail"),
165 "title" => _("Edit mail properties")
166 ),
168 "sambaGroupMapping" =>
169 array(
170 "image" => "plugins/groups/images/samba.png",
171 "plugin" => "group",
172 "alt" => _("Samba"),
173 "title" => _("Edit samba properties")
174 ),
176 "goFonPickupGroup" =>
177 array(
178 "image" => "plugins/groups/images/asterisk.png",
179 "plugin" => "group",
180 "alt" => _("Phone"),
181 "title" => _("Edit phone properties")
182 ),
184 "gotoMenuGroup" =>
185 array(
186 "image" => "plugins/groups/images/menu.png",
187 "plugin" => "appgroup",
188 "alt" => _("Menu"),
189 "title" => _("Edit start menu properties")
190 ),
192 "gotoEnvironment" =>
193 array(
194 "image" => "plugins/groups/images/environment.png",
195 "plugin" => "environment",
196 "alt" => _("Environment"),
197 "title" => _("Edit environment properties")
198 )
199 );
202 // Walk thru map
203 foreach ($map as $oc => $properties) {
204 if (in_array_ics($oc, $classes)) {
205 $result.="<input class='center' type='image' src='".$properties['image']."' ".
206 "alt='".$properties['alt']."' title='".$properties['title'].
207 "' name='listing_edit_".$properties['plugin']."_$row' style='padding:1px'>";
208 } else {
209 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
210 }
211 }
212 return $result;
213 }
214 }
215 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
216 ?>