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 = "Directory structure";
26 var $plDescription = "Manage organizations, organizational units, localities, countries and more";
27 var $plIcon = "plugins/departments/images/plugin.png";
29 // Tab definition
30 protected $tabClass = "deptabs";
31 protected $tabType = "DEPTABS";
32 protected $aclCategory = "department";
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 }
47 $filter->setObjectStorage(array(''));
49 // Build headpage
50 $headpage = new listing(get_template_path("dep-list.xml", true));
51 $headpage->registerElementFilter("depLabel", "departmentManagement::filterDepLabel");
52 $headpage->setFilter($filter);
53 $this->setFilter($filter);
55 // Add copy&paste and snapshot handler.
56 if ($this->config->boolValueIsTrue("main", "copyPaste")){
57 $this->cpHandler = new CopyPasteHandler($this->config);
58 }
59 if($this->config->get_cfg_value("enableSnapshots") == "true"){
60 $this->snapHandler = new SnapshotHandler($this->config);
61 }
63 parent::__construct($config, $ui, "departments", $headpage);
65 $this->registerAction("open","openEntry");
66 $this->registerAction("new_domain","newEntry");
67 $this->registerAction("new_country","newEntry");
68 $this->registerAction("new_locality","newEntry");
69 $this->registerAction("new_dcObject","newEntry");
70 $this->registerAction("new_organization","newEntry");
71 $this->registerAction("new_organizationalUnit","newEntry");
72 $this->registerAction("performRecMove","performRecMove");
73 $this->registerAction("tagDepartment","tagDepartment");
74 }
76 // Inject additional actions here.
77 function detectPostActions()
78 {
79 $actions = management::detectPostActions();
80 if(isset($_GET['PerformRecMove'])) $actions['action'] = "performRecMove";
81 if(isset($_GET['TagDepartment'])) $actions['action'] = "tagDepartment";
82 return($actions);
83 }
85 // Action handler which allows department tagging - Creates the iframe contents.
86 function tagDepartment()
87 {
88 $plugname = $this->last_tabObject->base_name;
89 $this->last_tabObject->by_object[$plugname]->tag_objects();
90 exit();
91 }
93 // Overridden new handler - We've different types of departments to create!
94 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
95 {
96 $types= $this->get_support_departments();
97 $type = preg_replace("/^new_/","",$action);
98 return(management::newEntry($action,$target,$all,$this->tabClass,$types[$type]['TAB'],$this->aclCategory));
99 }
101 // Overridden edit handler - We've different types of departments to edit!
102 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
103 {
104 $types= $this->get_support_departments();
105 $headpage = $this->getHeadpage();
106 $type = $headpage->getType($target[0]);
107 return(management::editEntry($action,$target,$all,$this->tabClass,$types[$type]['TAB'],$this->aclCategory));
108 }
111 // Overriden save handler - We've to take care about the department tagging here.
112 protected function saveChanges()
113 {
114 $str = management::saveChanges();
115 if(!empty($str)) return($str);
117 $this->refreshDeps();
118 $plugname = $this->last_tabObject->base_name;
119 if($this->last_tabObject->by_object[$plugname]->must_be_tagged()){
120 $smarty = get_smarty();
121 $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment&no_output_compression");
122 $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."));
123 return($smarty->fetch(get_template_path("dep_iframe.tpl",TRUE)));
124 }
125 }
128 function refreshDeps()
129 {
130 global $config;
131 $config->get_departments();
132 $config->make_idepartments();
133 $this->config = $config;
134 $headpage = $this->getHeadpage();
135 $headpage->refreshBasesList();
136 }
139 // An action handler which enables to switch into deparmtment by clicking the names.
140 function openEntry($action,$entry)
141 {
142 $headpage = $this->getHeadpage();
143 $headpage->setBase(array_pop($entry));
144 }
147 // Overridden remove request method - Avoid removal of the ldap base.
148 protected function removeEntryRequested($action="",$target=array(),$all=array())
149 {
150 $target = array_remove_entries(array($this->config->current['BASE']),$target);
151 return(management::removeEntryRequested($action,$target,$all));
152 }
155 // A filter which allows to open a department by clicking on the departments name.
156 static function filterDepLabel($row,$dn,$params,$ou,$pid,$base)
157 {
158 $ou = $ou[0];
159 if(LDAP::convert($dn) == $base){
160 $ou =".";
161 }
162 $dn= LDAP::fix(func_get_arg(1));
163 return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_open_$row' title='$dn'>$ou</a>");
164 }
167 // Finally remove departments and update departmnet browsers
168 function removeEntryConfirmed($action="",$target=array(),$all=array(),$altTabClass="",
169 $altTabType="",$altAclCategory="", $aclPlugin="")
170 {
171 management::removeEntryConfirmed($action,$target,$all, $altTabClass,$altTabType,$altAclCategory);
172 $this->refreshDeps();
173 }
175 /*! \brief Returns information about all container types that GOsa con handle.
176 @return Array Informations about departments supported by GOsa.
177 */
178 public static function get_support_departments()
179 {
180 /* Domain
181 */
182 $types = array();
183 $types['domain']['ACL'] = "domain";
184 $types['domain']['CLASS'] = "domain";
185 $types['domain']['ATTR'] = "dc";
186 $types['domain']['TAB'] = "DOMAIN_TABS";
187 $types['domain']['OC'] = "domain";
188 $types['domain']['IMG'] = "plugins/departments/images/domain.png";
189 $types['domain']['IMG_FULL']= "plugins/departments/images/domain.png";
190 $types['domain']['TITLE'] = _("Domain");
191 $types['domain']['TPL'] = "domain.tpl";
193 /* Domain component
194 */
195 $types['dcObject']['ACL'] = "dcObject";
196 $types['dcObject']['CLASS'] = "dcObject";
197 $types['dcObject']['ATTR'] = "dc";
198 $types['dcObject']['TAB'] = "DCOBJECT_TABS";
199 $types['dcObject']['OC'] = "dcObject";
200 $types['dcObject']['IMG'] = "plugins/departments/images/dc.png";
201 $types['dcObject']['IMG_FULL']= "plugins/departments/images/dc.png";
202 $types['dcObject']['TITLE'] = _("Domain Component");
203 $types['dcObject']['TPL'] = "dcObject.tpl";
205 /* Country object
206 */
207 $types['country']['ACL'] = "country";
208 $types['country']['CLASS'] = "country";
209 $types['country']['TAB'] = "COUNTRY_TABS";
210 $types['country']['ATTR'] = "c";
211 $types['country']['OC'] = "country";
212 $types['country']['IMG'] = "plugins/departments/images/country.png";
213 $types['country']['IMG_FULL']= "plugins/departments/images/country.png";
214 $types['country']['TITLE'] = _("Country");
215 $types['country']['TPL'] = "country.tpl";
217 /* Locality object
218 */
219 $types['locality']['ACL'] = "locality";
220 $types['locality']['CLASS'] = "locality";
221 $types['locality']['TAB'] = "LOCALITY_TABS";
222 $types['locality']['ATTR'] = "l";
223 $types['locality']['OC'] = "locality";
224 $types['locality']['IMG'] = "plugins/departments/images/locality.png";
225 $types['locality']['IMG_FULL']= "plugins/departments/images/locality.png";
226 $types['locality']['TITLE'] = _("Locality");
227 $types['locality']['TPL'] = "locality.tpl";
229 /* Organization
230 */
231 $types['organization']['ACL'] = "organization";
232 $types['organization']['CLASS'] = "organization";
233 $types['organization']['TAB'] = "ORGANIZATION_TABS";
234 $types['organization']['ATTR'] = "o";
235 $types['organization']['OC'] = "organization";
236 $types['organization']['IMG'] = "plugins/departments/images/organization.png";
237 $types['organization']['IMG_FULL']= "plugins/departments/images/organization.png";
238 $types['organization']['TITLE'] = _("Organization");
239 $types['organization']['TPL'] = "organization.tpl";
241 /* Department
242 */
243 $types['organizationalUnit']['ACL'] = "department";
244 $types['organizationalUnit']['CLASS'] = "department";
245 $types['organizationalUnit']['TAB'] = "DEPTABS";
246 $types['organizationalUnit']['ATTR'] = "ou";
247 $types['organizationalUnit']['OC'] = "organizationalUnit";
248 $types['organizationalUnit']['IMG'] = "images/lists/folder.png";//plugins/departments/images/department.png";
249 $types['organizationalUnit']['IMG_FULL']= "images/lists/folder-full.png";//:wplugins/departments/images/department.png";
250 $types['organizationalUnit']['TITLE'] = _("Department");
251 $types['organizationalUnit']['TPL'] = "generic.tpl";
252 return($types);
253 }
254 }
255 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
256 ?>