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: class_roleManagement.inc 13520 2009-03-09 14:54:13Z hickert $$
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 roleManagement extends plugin
24 {
25 /* Definitions */
26 var $plHeadline= "Roles";
27 var $plDescription= "Manage roles";
29 // Copy and paste handler
30 var $CopyPasteHandler = NULL;
32 // The headpage list handler.
33 var $DivListRoles = NULL;
35 // A list of currently visible roles
36 var $roles = array();
38 // A list of currently edited/removed/aso roles.
39 var $dns = array();
41 // Permission modules to use.
42 var $acl_module = array("roles");
44 // Internal: Is truw while objects are pasted.
45 var $start_pasting_copied_objects = FALSE;
48 // Construct and initialize the plugin
49 function __construct (&$config, $dn= NULL)
50 {
51 // Include config object
52 $this->config= &$config;
53 $this->ui= get_userinfo();
55 // Copy & Paste enabled ?
56 if ($this->config->get_cfg_value("copyPaste") == "true"){
57 $this->CopyPasteHandler = new CopyPasteHandler($this->config);
58 }
60 // Initialize the corresponding list class.
61 $this->DivListRoles = new divListRole($this->config,$this);
62 }
65 function execute()
66 {
67 // Call parent execute
68 plugin::execute();
70 /* Variables to restore after 'entry locked' warning was displayed */
71 session::set('LOCK_VARS_TO_USE',array('/^role_/'));
73 $smarty = get_smarty();
74 $s_action = "";
75 $s_entry = "";
77 /***************
78 * Handle _POST/_GET variables
79 ***************/
81 // Get entry related posts
82 foreach($_POST as $name => $value){
83 if(preg_match("/^role_edit_/",$name)){
84 $s_action = "edit";
85 $s_entry = preg_replace("/^role_edit_([0-9]*)_.*$/","\\1",$name);
86 break;
87 }
88 if(preg_match("/^role_del_/",$name)){
89 $s_action = "del";
90 $s_entry = preg_replace("/^role_del_([0-9]*)_.*$/","\\1",$name);
91 break;
92 }
93 }
94 if(isset($_GET['act']) && $_GET['act'] == "edit_entry" && isset($_GET['id'])){
95 $id = $_GET['id'];
96 if(isset($this->roles[$id])){
97 $s_action = "edit";
98 $s_entry = $id;
99 }
100 }
102 // Get menu related posts
103 if(isset($_POST['menu_action'])) {
104 if($_POST['menu_action'] == "role_new"){
105 $s_action = "new";
106 }elseif($_POST['menu_action'] == "remove_multiple_roles"){
107 $s_action = "remove_multiple";
108 }
109 }
112 /***************
113 * New handling
114 ***************/
116 if($s_action == "new"){
117 $this->dialog = new roletabs($this->config, $this->config->data['TABS']['ROLETABS'], "new");
118 }
120 /***************
121 * Edit handling
122 ***************/
124 if($s_action == "edit"){
125 if(!isset($this->roles[$s_entry])){
126 trigger_error("Unknown entry!");
127 }else{
128 $entry = $this->roles[$s_entry];
129 print_a($entry);
130 }
131 }
133 /***************
134 * Dialog handling
135 ***************/
137 if (isset($_POST['edit_cancel'])){
138 if(isset($this->grouptab->dn)){
139 $this->remove_lock();
140 }
141 $this->dialog= NULL;
142 set_object_info();
143 }
145 if($this->dialog instanceOf tabs){
146 $this->dialog->save_object();
147 $display= $this->dialog->execute();
149 if($this->dialog->read_only == TRUE){
150 $display.= "<p style=\"text-align:right\">
151 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
152 </p>";
153 }else{
155 $display.= "<p style=\"text-align:right\">\n";
156 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\"
157 value=\"".msgPool::okButton(). "\">\n";
158 $display.= " \n";
159 if ($this->dn != "new"){
160 $display.= "<input type=submit name=\"edit_apply\"
161 value=\"".msgPool::applyButton()."\">\n";
162 $display.= " \n";
163 }
164 $display.= "<input type=submit name=\"edit_cancel\"
165 value=\"".msgPool::cancelButton()."\">\n";
166 $display.= "</p>";
167 }
168 return ($display);
169 }
172 /***************
173 * List handling
174 ***************/
176 // Display dialog with group list
177 $this->DivListRoles->parent = $this;
178 $this->DivListRoles->execute();
180 // Add departments if subsearch is disabled
181 if(!$this->DivListRoles->SubSearch){
182 $this->DivListRoles->AddDepartments($this->DivListRoles->selectedBase,4,1);
183 }
184 $this->reload ();
185 $this->DivListRoles->setEntries($this->roles);
186 return($this->DivListRoles->Draw());
187 }
190 // Refreshes the list of known role objects.
191 function reload()
192 {
194 // Get current ldap base and filter settings.
195 $base = $this->DivListRoles->selectedBase;
196 $Regex = $this->DivListRoles->Regex;
198 // Search and fetch all matching role objects.
199 $this->roles = array();
200 $ldap = $this->config->get_ldap_link();
201 $ldap->search("(objectClass=gosaGroupOfNames)",array("cn","description"));
202 $tmp = array();
203 while($attrs = $ldap->fetch()){
204 $tmp[$attrs['cn'][0].$attrs['dn']] = $attrs;
205 }
207 uksort($tmp, 'strnatcasecmp');
208 $this->roles = array_values($tmp);
209 }
212 /* \brief Returns a list of selected entry ids.
213 * E.g. remove multiple entries.
214 * @return Array A list of entry IDs
215 */
216 function list_get_selected_items()
217 {
218 $ids = array();
219 foreach($_POST as $name => $value){
220 if(preg_match("/^item_selected_[0-9]*$/",$name)){
221 $id = preg_replace("/^item_selected_/","",$name);
222 $ids[$id] = $id;
223 }
224 }
225 return($ids);
226 }
229 function remove_lock()
230 {
231 }
234 /* Return departments, that will be included within snapshot detection
235 */
236 function get_used_snapshot_bases()
237 {
238 return(array(get_ou('roleRDN').$this->DivListRoles->selectedBase));
239 }
242 function save_object()
243 {
244 $this->DivListRoles->save_object();
245 if(is_object($this->CopyPasteHandler)){
246 $this->CopyPasteHandler->save_object();
247 }
248 }
249 }
251 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
252 ?>