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 departmentManagement extends management
24 {
25 var $plHeadline = "Departments";
26 var $plDescription = "Manage Departments";
27 var $plIcon = "plugins/departments/images/plugin.png";
29 // Tab definition
30 protected $tabClass = "deptabs";
31 protected $tabType = "DEPTABS";
32 protected $aclCategory = "departement";
33 protected $aclPlugin = "generic";
34 protected $objectName = "department";
36 function __construct($config,$ui)
37 {
38 $this->config = $config;
39 $this->ui = $ui;
41 // Build filter
42 if (session::global_is_set(get_class($this)."_filter")){
43 $filter= session::global_get(get_class($this)."_filter");
44 } else {
45 $filter = new filter(get_template_path("dep-filter.xml", true));
46 }
48 // Build headpage
49 $headpage = new listing(get_template_path("dep-list.xml", true));
50 $headpage->registerElementFilter("depLabel", "departmentManagement::filterDepLabel");
51 $headpage->setFilter($filter);
52 $this->setFilter($filter);
54 // Add copy&paste and snapshot handler.
55 if ($this->config->boolValueIsTrue("main", "copyPaste")){
56 $this->cpHandler = new CopyPasteHandler($this->config);
57 }
58 if($this->config->get_cfg_value("enableSnapshots") == "true"){
59 $this->snapHandler = new SnapshotHandler($this->config);
60 }
62 parent::__construct($config, $ui, "departments", $headpage);
64 $this->registerAction("open","openEntry");
65 $this->registerAction("new_domain","newEntry");
66 $this->registerAction("new_country","newEntry");
67 $this->registerAction("new_locality","newEntry");
68 $this->registerAction("new_dcObject","newEntry");
69 $this->registerAction("new_organization","newEntry");
70 $this->registerAction("new_organizationalUnit","newEntry");
71 $this->registerAction("performRecMove","performRecMove");
72 $this->registerAction("tagDepartment","tagDepartment");
73 }
75 // Inject additional actions here.
76 function detectPostActions()
77 {
78 $actions = management::detectPostActions();
79 if(isset($_GET['PerformRecMove'])) $actions['action'] = "performRecMove";
80 if(isset($_GET['TagDepartment'])) $actions['action'] = "tagDepartment";
81 return($actions);
82 }
84 // Action handler which allows department tagging - Creates the iframe contents.
85 function tagDepartment()
86 {
87 $plugname = $this->last_tabObject->base_name;
88 $this->last_tabObject->by_object[$plugname]->tag_objects();
89 exit();
90 }
92 // Overridden new handler - We've different types of departments to create!
93 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
94 {
95 $types= $this->get_support_departments();
96 $type = preg_replace("/^new_/","",$action);
97 return(management::newEntry($action,$target,$all,$this->tabClass,$types[$type]['TAB'],$this->aclCategory));
98 }
100 // Overridden edit handler - We've different types of departments to edit!
101 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
102 {
103 $types= $this->get_support_departments();
104 $headpage = $this->getHeadpage();
105 $type = $headpage->getType($target[0]);
106 return(management::editEntry($action,$target,$all,$this->tabClass,$types[$type]['TAB'],$this->aclCategory));
107 }
111 function removeEntryConfirmed($action="",$target=array(),$all=array(),
112 $altTabClass="",$altTabType="",$altAclCategory="")
113 {
114 $types= $this->get_support_departments();
115 $headpage = $this->getHeadpage();
117 $tabType = $this->tabType;
118 $tabClass = $this->tabClass;
119 $aclCategory = $this->aclCategory;
120 if(!empty($altTabClass)) $tabClass = $altTabClass;
121 if(!empty($altTabType)) $tabType = $altTabType;
122 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
124 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
126 foreach($this->dns as $key => $dn){
128 // Check permissions, are we allowed to remove this object?
129 $type = $headpage->getType($dn);
130 $tabType = $types[$type]['TAB'];
132 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
133 if(preg_match("/d/",$acl)){
135 // Delete the object
136 $this->dn = $dn;
137 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
138 $this->tabObject->set_acl_base($this->dn);
139 $this->tabObject->delete ();
140 $this->tabObject->parent = &$this;
142 // Remove the lock for the current object.
143 del_lock($this->dn);
144 } else {
145 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
146 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
147 }
148 }
150 // Cleanup
151 $this->remove_lock();
152 $this->closeDialogs();
153 }
158 // Overriden save handler - We've to take care about the department tagging here.
159 protected function saveChanges()
160 {
161 management::saveChanges();
163 global $config;
164 $config->get_departments();
165 $config->make_idepartments();
166 $this->config = $config;
167 $headpage = $this->getHeadpage();
168 $headpage->refreshBasesList();
170 $plugname = $this->last_tabObject->base_name;
171 if($this->last_tabObject->by_object[$plugname]->must_be_tagged()){
172 $smarty = get_smarty();
173 $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment&no_output_compression");
174 $smarty->assign("message",_("As soon as the tag operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog."));
175 return($smarty->fetch(get_template_path("dep_iframe.tpl",TRUE)));
176 }
177 }
180 // An action handler which enables to switch into deparmtment by clicking the names.
181 function openEntry($action,$entry)
182 {
183 $headpage = $this->getHeadpage();
184 $headpage->setBase(array_pop($entry));
185 }
188 // Overridden remove request method - Avoid removal of the ldap base.
189 protected function removeEntryRequested($action="",$target=array(),$all=array())
190 {
191 $target = array_remove_entries(array($this->config->current['BASE']),$target);
192 return(management::removeEntryRequested($action,$target,$all));
193 }
196 // A filter which allows to open a department by clicking on the departments name.
197 static function filterDepLabel($row,$dn,$params,$ou,$pid,$base)
198 {
199 $ou = $ou[0];
200 if($dn == $base){
201 $ou =".";
202 }
203 $dn= LDAP::fix(func_get_arg(1));
204 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_open_$row' title='$dn'>$ou</a>");
205 }
208 /*! \brief Returns information about all container types that GOsa con handle.
209 @return Array Informations about departments supported by GOsa.
210 */
211 public static function get_support_departments()
212 {
213 /* Domain
214 */
215 $types = array();
216 $types['domain']['ACL'] = "domain";
217 $types['domain']['CLASS'] = "domain";
218 $types['domain']['ATTR'] = "dc";
219 $types['domain']['TAB'] = "DOMAIN_TABS";
220 $types['domain']['OC'] = "domain";
221 $types['domain']['IMG'] = "plugins/departments/images/domain.png";
222 $types['domain']['IMG_FULL']= "plugins/departments/images/domain.png";
223 $types['domain']['TITLE'] = _("Domain");
224 $types['domain']['TPL'] = "domain.tpl";
226 /* Domain component
227 */
228 $types['dcObject']['ACL'] = "dcObject";
229 $types['dcObject']['CLASS'] = "dcObject";
230 $types['dcObject']['ATTR'] = "dc";
231 $types['dcObject']['TAB'] = "DCOBJECT_TABS";
232 $types['dcObject']['OC'] = "dcObject";
233 $types['dcObject']['IMG'] = "plugins/departments/images/dc.png";
234 $types['dcObject']['IMG_FULL']= "plugins/departments/images/dc.png";
235 $types['dcObject']['TITLE'] = _("Domain Component");
236 $types['dcObject']['TPL'] = "dcObject.tpl";
238 /* Country object
239 */
240 $types['country']['ACL'] = "country";
241 $types['country']['CLASS'] = "country";
242 $types['country']['TAB'] = "COUNTRY_TABS";
243 $types['country']['ATTR'] = "c";
244 $types['country']['OC'] = "country";
245 $types['country']['IMG'] = "plugins/departments/images/country.png";
246 $types['country']['IMG_FULL']= "plugins/departments/images/country.png";
247 $types['country']['TITLE'] = _("Country");
248 $types['country']['TPL'] = "country.tpl";
250 /* Locality object
251 */
252 $types['locality']['ACL'] = "locality";
253 $types['locality']['CLASS'] = "locality";
254 $types['locality']['TAB'] = "LOCALITY_TABS";
255 $types['locality']['ATTR'] = "l";
256 $types['locality']['OC'] = "locality";
257 $types['locality']['IMG'] = "plugins/departments/images/locality.png";
258 $types['locality']['IMG_FULL']= "plugins/departments/images/locality.png";
259 $types['locality']['TITLE'] = _("Locality");
260 $types['locality']['TPL'] = "locality.tpl";
262 /* Organization
263 */
264 $types['organization']['ACL'] = "organization";
265 $types['organization']['CLASS'] = "organization";
266 $types['organization']['TAB'] = "ORGANIZATION_TABS";
267 $types['organization']['ATTR'] = "o";
268 $types['organization']['OC'] = "organization";
269 $types['organization']['IMG'] = "plugins/departments/images/organization.png";
270 $types['organization']['IMG_FULL']= "plugins/departments/images/organization.png";
271 $types['organization']['TITLE'] = _("Organization");
272 $types['organization']['TPL'] = "organization.tpl";
274 /* Department
275 */
276 $types['organizationalUnit']['ACL'] = "department";
277 $types['organizationalUnit']['CLASS'] = "department";
278 $types['organizationalUnit']['TAB'] = "DEPTABS";
279 $types['organizationalUnit']['ATTR'] = "ou";
280 $types['organizationalUnit']['OC'] = "organizationalUnit";
281 $types['organizationalUnit']['IMG'] = "images/lists/folder.png";//plugins/departments/images/department.png";
282 $types['organizationalUnit']['IMG_FULL']= "images/lists/folder-full.png";//:wplugins/departments/images/department.png";
283 $types['organizationalUnit']['TITLE'] = _("Department");
284 $types['organizationalUnit']['TPL'] = "generic.tpl";
285 return($types);
286 }
287 }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
289 ?>