21bdd4743dcfbda96e8a887735e2ff81f9f8c295
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_plugin.inc 14584 2009-10-12 14:04:22Z 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 management
24 {
25 // Public
26 public $config = null;
27 public $ui = null;
29 public $plIcon = "";
30 public $plDescription = "";
31 public $plHeadline = "";
33 // Protected
34 protected $dn = "";
35 protected $dns = array();
37 protected $tabClass = "";
38 protected $tabType = "";
39 protected $aclCategory = "";
40 protected $objectName = "";
41 protected $tabObject = null;
43 protected $displayApplyBtn = "";
44 protected $cpHandler = null;
45 protected $cpPastingStarted = FALSE;
47 // Private
48 private $plugname = "";
49 private $headpage = null;
50 private $filter = null;
51 private $actions = array();
53 function __construct($config,$ui,$plugname, $headpage)
54 {
55 $this->plugname = $plugname;
56 $this->headpage = $headpage;
57 $this->ui = $ui;
58 $this->config = $config;
60 if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
62 if(empty($this->plIcon)){
63 $this->plIcon = "plugins/".$plugname."/images/plugin.png";
64 }
65 }
67 function execute()
68 {
69 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
70 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
71 session::set('LOCK_VARS_TO_USE',$vars);
73 /* Display the copy & paste dialog, if it is currently open */
74 $ret = $this->copyPasteHandler("",array());
75 if($ret){
76 return($this->getHeader().$ret);
77 }
79 // Handle actions (POSTs and GETs)
80 $str = $this->detectPostActions();
81 if($str) return($this->getHeader().$str);
83 // Display tab object.
84 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
85 $this->tabObject->save_object();
86 $display = $this->tabObject->execute();
87 $display.= $this->_getTabFooter();
88 return($this->getHeader().$display);
89 }
91 $this->headpage->update();
92 $display = $this->headpage->render();
93 return($this->getHeader().$display);
94 }
96 protected function getHeader()
97 {
98 if (get_object_info() != ""){
99 $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
100 "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
101 LDAP::fix(get_object_info()));
102 } else {
103 $display= print_header(get_template_path($this->plIcon),_($this->plDescription));
104 }
105 return($display);
106 }
109 protected function _getTabFooter()
110 {
111 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
112 return("");
113 }
115 if($this->tabObject->by_object[$this->tabObject->current]){
116 $current = $this->tabObject->by_object[$this->tabObject->current];
117 if(is_object($current->dialog)){
118 return("");
119 }
120 }
122 $str = "";
123 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
124 $str.= "<p style=\"text-align:right\">
125 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
126 </p>";
127 return($str);
128 }else{
129 $str.= "<p style=\"text-align:right\">\n";
130 $str.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
131 $str.= " \n";
132 if($this->displayApplyBtn){
133 $str.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
134 $str.= " \n";
135 }
136 $str.= "<input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
137 $str.= "</p>";
138 }
139 return($str);
140 }
143 protected function removeEntryRequested($action,$entry,$all)
144 {
145 $disallowed = array();
146 $this->dns = array();
147 foreach($entry as $dn){
148 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
149 if(preg_match("/d/",$acl)){
150 $this->dns[] = $dn;
151 }else{
152 $disallowed[] = $dn;
153 }
154 }
156 if(count($disallowed)){
157 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
158 }
160 if(count($this->dns)){
162 /* Check locks */
163 if ($user= get_multiple_locks($this->dns)){
164 return(gen_locked_message($user,$this->dns));
165 }
167 $dns_names = array();
168 foreach($this->dns as $dn){
169 $dns_names[] =LDAP::fix($dn);
170 }
171 add_lock ($this->dns, $this->ui->dn);
173 /* Lock the current entry, so nobody will edit it during deletion */
174 $smarty = get_smarty();
175 $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
176 $smarty->assign("multiple", true);
177 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
178 }
179 }
182 protected function removeEntryConfirmed()
183 {
184 foreach($this->dns as $key => $dn){
186 /* Load permissions for selected 'dn' and check if
187 we're allowed to remove this 'dn' */
188 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
189 if(preg_match("/d/",$acl)){
191 /* Delete request is permitted, perform LDAP action */
192 $this->dn = $dn;
193 $tab = $this->tabClass;
194 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory);
195 $this->tabObject->set_acl_base($this->dn);
196 $this->tabObject->delete ();
197 $this->closeDialogs();
198 del_lock($this->dn);
199 } else {
201 /* Normally this shouldn't be reached, send some extra
202 logs to notify the administrator */
203 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
204 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
205 return;
206 }
207 }
209 $this->closeDialogs();
210 $this->remove_lock();
211 }
214 function detectPostActions()
215 {
216 $action= $this->headpage->getAction();
218 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
219 if(isset($_POST['edit_finish'])) $action['action'] = "save";
220 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
221 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
223 // Start action
224 if(isset($this->actions[$action['action']])){
225 $func = $this->actions[$action['action']];
226 if(!isset($action['targets']))$action['targets']= array();
227 return($this->$func($action['action'],$action['targets'],$action));
228 }
229 }
231 function newEntry($action="",$target=array(),$all=array())
232 {
233 // Check locking & lock entry if required
234 $this->displayApplyBtn = FALSE;
235 $this->dn = "new";
236 $this->is_new = TRUE;
237 $this->is_single_edit = FALSE;
238 $this->is_multiple_edit = FALSE;
240 set_object_info($this->dn);
242 // Open object.
243 if(empty($this->tabClass) || empty($this->tabType)){
244 // No tab type defined
245 }else{
246 $tab = $this->tabClass;
247 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn, $this->aclCategory);
248 $this->tabObject->set_acl_base($this->headpage->getBase());
249 }
250 }
252 function editEntry($action,$target,$all)
253 {
254 if(count($target) == 0){
255 //nothing
256 }elseif(count($target) == 1){
258 // Check locking & lock entry if required
259 $this->displayApplyBtn = TRUE;
261 $this->is_new = FALSE;
262 $this->is_single_edit = TRUE;
263 $this->is_multiple_edit = FALSE;
265 $this->dn = array_pop($target);
266 set_object_info($this->dn);
267 $user = get_lock($this->dn);
268 if ($user != ""){
269 return(gen_locked_message ($user, $this->dn,TRUE));
270 }
271 add_lock ($this->dn, $this->ui->dn);
273 // Open object.
274 if(empty($this->tabClass) || empty($this->tabType)){
275 // No tab type defined
276 }else{
277 $tab = $this->tabClass;
278 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$this->tabType], $this->dn,$this->aclCategory);
279 $this->tabObject->set_acl_base($this->dn);
280 }
281 }else{
283 $this->is_new = FALSE;
284 $this->is_singel_edit = FALSE;
285 $this->is_multiple_edit = TRUE;
287 $this->dns = $target;
288 $tmp = new multi_plug($this->config,$this->tabClass,$this->config->data['TABS'][$this->tabType],
289 $this->dns,$this->headpage->getBase(),$this->aclCategory);
290 if ($tmp->entries_locked()){
291 return($tmp->display_lock_message());
292 }
293 $tmp->lock_entries($this->ui->dn);
294 if($tmp->multiple_available()){
295 $this->tabObject = $tmp;
296 set_object_info($this->tabObject->get_object_info());
297 }
299 }
300 }
302 protected function saveChanges()
303 {
304 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
305 $this->tabObject->save_object();
306 $msgs = $this->tabObject->check();
307 if(count($msgs)){
308 msg_dialog::displayChecks($msgs);
309 return("");
310 }else{
311 $this->tabObject->save();
312 $this->closeDialogs();
313 $this->remove_lock();
314 }
315 }
316 }
318 protected function applyChanges()
319 {
320 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
321 $this->tabObject->save_object();
322 $msgs = $this->tabObject->check();
323 if(count($msgs)){
324 msg_dialog::displayChecks($msgs);
325 return("");
326 }else{
327 $this->tabObject->save();
328 $this->tabObject->re_init();
329 }
330 }
331 }
333 protected function closeDialogs()
334 {
335 $this->dn = "";
336 $this->dns = array();
337 $this->tabObject = null;
338 set_object_info();
339 }
341 protected function cancelEdit()
342 {
343 $this->closeDialogs();
344 $this->remove_lock();
345 }
350 function registerAction($action,$target)
351 {
352 $this->actions[$action] = $target;
353 }
355 function remove_lock()
356 {
357 if(!empty($this->dn) && $this->dn != "new"){
358 del_lock($this->dn);
359 }
360 if(count($this->dns)){
361 del_lock($this->dns);
362 }
363 }
365 function copyPasteHandler($s_action,$s_entry)
366 {
368 /* Check if Copy & Paste is disabled */
369 if(!is_object($this->cpHandler)){
370 return("");
371 }
373 $this->cpHandler->save_object();
375 /* Add entries to queue */
376 if($s_action == "copy" || $s_action == "cut"){
378 /* Cleanup object queue */
379 $this->cpHandler->cleanup_queue();
381 /* Add new entries to CP queue */
382 foreach($s_entry as $dn){
383 if($s_action == "copy" && $this->ui->is_copyable($dn,$this->aclCategory,$this->aclPlugin)){
384 $this->cpHandler->add_to_queue($dn,"copy",$this->tabClass,$this->tabType,$this->aclCategory);
385 }
386 if($s_action == "cut" && $this->ui->is_cutable($dn,$this->aclCategory,$this->aclPlugin)){
387 $this->cpHandler->add_to_queue($dn,"cut",$this->tabClass,$this->tabType,$this->aclCategory);
388 }
389 }
390 }
392 /* Start pasting entries */
393 if($s_action == "paste"){
394 $this->cpPastingStarted = TRUE;
395 }
397 /* Return C&P dialog */
398 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
400 /* Get dialog */
401 $this->cpHandler->SetVar("base",$this->headpage->getBase());
402 $data = $this->cpHandler->execute();
404 /* Return dialog data */
405 if(!empty($data)){
406 return($data);
407 }
408 }
410 /* Automatically disable status for pasting */
411 if(!$this->cpHandler->entries_queued()){
412 $this->cpPastingStarted = FALSE;
413 }
414 return("");
415 }
418 function setDescription($str) {
419 $this->plDescription = $str;
420 }
421 function setHeadpage($str) {
422 $this->headpage = $str;
423 }
424 function setFilter($str) {
425 $this->filter = $str;
426 }
427 function setIcon($str) {
428 $this->plIcon = $str;
429 }
430 function setHeadline($str) {
431 $this->plHeadline = $str;
432 }
433 }
435 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
436 ?>