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 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 }
146 static function filterProperties($row, $classes)
147 {
148 $result= "";
150 $map = array(
151 "posixGroup" =>
152 array(
153 "image" => "plugins/groups/images/groups.png",
154 "plugin" => "group",
155 "alt" => _("Posix"),
156 "title" => _("Edit posix properties")
157 ),
159 "gosaMailAccount" =>
160 array(
161 "image" => "plugins/groups/images/mail.png",
162 "plugin" => "mailgroup",
163 "alt" => _("Mail"),
164 "title" => _("Edit mail properties")
165 ),
167 "sambaGroupMapping" =>
168 array(
169 "image" => "plugins/groups/images/samba.png",
170 "plugin" => "group",
171 "alt" => _("Samba"),
172 "title" => _("Edit samba properties")
173 ),
175 "goFonPickupGroup" =>
176 array(
177 "image" => "plugins/groups/images/asterisk.png",
178 "plugin" => "group",
179 "alt" => _("Phone"),
180 "title" => _("Edit phone properties")
181 ),
183 "gotoMenuGroup" =>
184 array(
185 "image" => "plugins/groups/images/menu.png",
186 "plugin" => "appgroup",
187 "alt" => _("Menu"),
188 "title" => _("Edit start menu properties")
189 ),
191 "gotoEnvironment" =>
192 array(
193 "image" => "plugins/groups/images/environment.png",
194 "plugin" => "environment",
195 "alt" => _("Environment"),
196 "title" => _("Edit environment properties")
197 )
198 );
201 // Walk thru map
202 foreach ($map as $oc => $properties) {
203 if (in_array_ics($oc, $classes)) {
204 $result.="<input class='center' type='image' src='".$properties['image']."' ".
205 "alt='".$properties['alt']."' title='".$properties['title'].
206 "' name='listing_edit_".$properties['plugin']."_$row' style='padding:1px'>";
207 } else {
208 $result.="<img src='images/empty.png' alt=' ' class='center' style='padding:1px'>";
209 }
210 }
211 return $result;
212 }
213 }
214 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
215 ?>