Code

Updated check for boolean config values
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentManagement.inc
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;
40    
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("core", "copyPaste")){
57       $this->cpHandler = new CopyPasteHandler($this->config);
58     }
59     if($this->config->get_cfg_value("core","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     $plugname = (isset($this->last_tabObject->base_name))? $this->last_tabObject->base_name : '';
119     $this->refreshDeps(); 
120     if(isset($this->last_tabObject->by_object[$plugname]) &&
121        is_object($this->last_tabObject->by_object[$plugname])      &&
122             $this->last_tabObject->by_object[$plugname]->must_be_tagged()){
123       $smarty = get_smarty();
124       $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment&no_output_compression");
125       $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."));
126       return($smarty->fetch(get_template_path("dep_iframe.tpl",TRUE)));
127     }
128   }
130   
131   function refreshDeps()
132   {
133     global $config; 
134     $config->get_departments();
135     $config->make_idepartments();
136     $this->config = $config;
137     $headpage = $this->getHeadpage();
138     $headpage->refreshBasesList();
139   }
140  
142   // An action handler which enables to switch into deparmtment by clicking the names.
143   function openEntry($action,$entry)
144   {
145     $headpage = $this->getHeadpage();
146     $headpage->setBase(array_pop($entry));
147   }
150   // Overridden remove request method - Avoid removal of the ldap base.
151   protected function removeEntryRequested($action="",$target=array(),$all=array())
152   {
153     $target = array_remove_entries(array($this->config->current['BASE']),$target);
154     return(management::removeEntryRequested($action,$target,$all)); 
155   }
158   // A filter which allows to open a department by clicking on the departments name.
159   static function filterDepLabel($row,$dn,$params,$ou,$pid,$base)
160   {
161     $ou = $ou[0];
162     if(LDAP::convert($dn) == $base){
163       $ou =".";
164     }
165     $dn= LDAP::fix(func_get_arg(1));
166     return("<a href='?plug=".$_GET['plug']."&amp;PID=$pid&amp;act=listing_open_$row' title='$dn'>$ou</a>");
167   }
169   
170   // Finally remove departments and update departmnet browsers
171   function removeEntryConfirmed($action="",$target=array(),$all=array(),$altTabClass="",
172     $altTabType="",$altAclCategory="", $aclPlugin="")
173   {
174     management::removeEntryConfirmed($action,$target,$all, $altTabClass,$altTabType,$altAclCategory);
175     $this->refreshDeps();
176   }
178   /*! \brief  Returns information about all container types that GOsa con handle.
179     @return Array   Informations about departments supported by GOsa.
180    */
181   public static function get_support_departments()
182   {
183     /* Domain 
184      */ 
185     $types = array();
186     $types['domain']['ACL']     = "domain"; 
187     $types['domain']['CLASS']   = "domain"; 
188     $types['domain']['ATTR']    = "dc"; 
189     $types['domain']['TAB']     = "DOMAIN_TABS"; 
190     $types['domain']['OC']      = "domain"; 
191     $types['domain']['IMG']     = "plugins/departments/images/domain.png"; 
192     $types['domain']['IMG_FULL']= "plugins/departments/images/domain.png"; 
193     $types['domain']['TITLE']   = _("Domain"); 
194     $types['domain']['TPL']     = "domain.tpl"; 
196     /* Domain component 
197      */
198     $types['dcObject']['ACL']     = "dcObject";
199     $types['dcObject']['CLASS']   = "dcObject";
200     $types['dcObject']['ATTR']    = "dc";
201     $types['dcObject']['TAB']     = "DCOBJECT_TABS";
202     $types['dcObject']['OC']      = "dcObject";
203     $types['dcObject']['IMG']     = "plugins/departments/images/dc.png";
204     $types['dcObject']['IMG_FULL']= "plugins/departments/images/dc.png";
205     $types['dcObject']['TITLE']   = _("Domain Component");
206     $types['dcObject']['TPL']     = "dcObject.tpl";
208     /* Country object
209      */
210     $types['country']['ACL']     = "country";
211     $types['country']['CLASS']   = "country";
212     $types['country']['TAB']     = "COUNTRY_TABS";
213     $types['country']['ATTR']    = "c";
214     $types['country']['OC']      = "country";
215     $types['country']['IMG']     = "plugins/departments/images/country.png";
216     $types['country']['IMG_FULL']= "plugins/departments/images/country.png";
217     $types['country']['TITLE']   = _("Country");
218     $types['country']['TPL']     = "country.tpl";
220     /* Locality object
221      */
222     $types['locality']['ACL']     = "locality";
223     $types['locality']['CLASS']   = "locality";
224     $types['locality']['TAB']     = "LOCALITY_TABS";
225     $types['locality']['ATTR']    = "l";
226     $types['locality']['OC']      = "locality";
227     $types['locality']['IMG']     = "plugins/departments/images/locality.png";
228     $types['locality']['IMG_FULL']= "plugins/departments/images/locality.png";
229     $types['locality']['TITLE']   = _("Locality");
230     $types['locality']['TPL']     = "locality.tpl";
232     /* Organization
233      */
234     $types['organization']['ACL']     = "organization";
235     $types['organization']['CLASS']   = "organization";
236     $types['organization']['TAB']     = "ORGANIZATION_TABS";
237     $types['organization']['ATTR']    = "o";
238     $types['organization']['OC']      = "organization";
239     $types['organization']['IMG']     = "plugins/departments/images/organization.png";
240     $types['organization']['IMG_FULL']= "plugins/departments/images/organization.png";
241     $types['organization']['TITLE']   = _("Organization");
242     $types['organization']['TPL']     = "organization.tpl";
244     /* Department
245      */
246     $types['organizationalUnit']['ACL']     = "department";
247     $types['organizationalUnit']['CLASS']   = "department";
248     $types['organizationalUnit']['TAB']     = "DEPTABS";
249     $types['organizationalUnit']['ATTR']    = "ou";
250     $types['organizationalUnit']['OC']      = "organizationalUnit";
251     $types['organizationalUnit']['IMG']     = "images/lists/folder.png";//plugins/departments/images/department.png";
252     $types['organizationalUnit']['IMG_FULL']= "images/lists/folder-full.png";//:wplugins/departments/images/department.png";
253     $types['organizationalUnit']['TITLE']   = _("Department");
254     $types['organizationalUnit']['TPL']     = "generic.tpl";
255     return($types);
256   }
257
258 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
259 ?>