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 management
24 {
25 // Public
26 public $config = null;
27 public $ui = null;
29 // The plugin description
30 public $plugname = "unconfigured";
31 public $plIcon = "unconfigured";
32 public $plDescription = "unconfigured";
33 public $plHeadline = "unconfigured";
35 // The currently used object(s) (e.g. in edit, removal)
36 public $dn = ""; // this is public due to some compatibility problems with class plugin..
37 protected $dns = array();
39 // The last used object(s).
40 protected $last_dn = "";
41 protected $last_dns = array();
43 // The common places the displayed objects are stored in. (e.g. array("ou=groups,",".."))
44 protected $storagePoints = array();
46 // The tab definitions to use for the current object.
47 protected $tabClass = ""; // e.g. usertabs
48 protected $tabType = ""; // e.g. USERTABS
49 protected $aclPlugin = ""; // e.g. generic
50 protected $aclCategory = ""; // e.g. users
51 protected $objectName = ""; // e.g. users
53 // The opened object.
54 protected $tabObject = null;
55 protected $dialogObject = null;
57 // The last opened object.
58 protected $last_tabObject = null;
59 protected $last_dialogObject = null;
61 // Whether to display the apply button or not
62 protected $displayApplyBtn = FALSE;
64 // Whether to display a header or not.
65 protected $skipHeader = false;
67 // Whether to display a footer or not.
68 protected $skipFooter = false;
70 // Copy&Paste handler
71 protected $cpHandler = null;
73 // Indicates that we want to paste objects right now.
74 protected $cpPastingStarted = FALSE;
76 // The Snapshot handler class.
77 protected $snapHandler = null;
79 // The listing handlers
80 private $headpage = null;
81 private $filter = null;
83 // A list of configured actions/events
84 protected $actions = array();
86 // Attributes managed by this plugin, can be used in post events;
87 public $attributes = array();
89 function __construct(&$config,$ui,$plugname, $headpage)
90 {
91 $this->plugname = $plugname;
92 $this->headpage = $headpage;
93 $this->ui = $ui;
94 $this->config = $config;
96 if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
97 if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
99 if(empty($this->plIcon)){
100 $this->plIcon = "plugins/".$plugname."/images/plugin.png";
101 }
103 // Register default actions
104 $this->registerAction("new", "newEntry");
105 $this->registerAction("edit", "editEntry");
106 $this->registerAction("apply", "applyChanges");
107 $this->registerAction("save", "saveChanges");
108 $this->registerAction("cancel", "cancelEdit");
109 $this->registerAction("cancelDelete", "cancelEdit");
110 $this->registerAction("remove", "removeEntryRequested");
111 $this->registerAction("removeConfirmed", "removeEntryConfirmed");
113 $this->registerAction("copy", "copyPasteHandler");
114 $this->registerAction("cut", "copyPasteHandler");
115 $this->registerAction("paste", "copyPasteHandler");
117 $this->registerAction("snapshot", "createSnapshotDialog");
118 $this->registerAction("restore", "restoreSnapshotDialog");
119 $this->registerAction("saveSnapshot","saveSnapshot");
120 $this->registerAction("restoreSnapshot","restoreSnapshot");
121 $this->registerAction("cancelSnapshot","closeDialogs");
123 $this->registerAction("config-filter","editFilter");
124 $this->registerAction("saveFilter","saveFilter");
126 // To temporay disable the filter caching UNcomment this line.
127 #session::global_un_set(get_class($this)."_filter");
128 }
130 /*! \brief Execute this plugin
131 * Handle actions/events, locking, snapshots, dialogs, tabs,...
132 */
133 function execute()
134 {
135 // Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
136 $vars = array('/^act$/','/^listing/','/^PID$/','/^FILTER_PID$/');
137 session::set('LOCK_VARS_TO_USE',$vars);
139 pathNavigator::registerPlugin($this);
141 /* Display the copy & paste dialog, if it is currently open */
142 $ret = $this->copyPasteHandler("",array());
143 if($ret){
144 return($this->getHeader().$ret);
145 }
147 // Update filter
148 if ($this->filter) {
149 $this->filter->update();
150 session::global_set(get_class($this)."_filter", $this->filter);
151 session::set('autocomplete', $this->filter);
152 }
154 // Handle actions (POSTs and GETs)
155 $str = $this->handleActions($this->detectPostActions());
156 if($str) return($this->getHeader().$str);
158 // Open single dialog objects
159 if(is_object($this->dialogObject)){
160 if(method_exists($this->dialogObject,'save_object')) $this->dialogObject->save_object();
161 if(method_exists($this->dialogObject,'execute')){
162 $display = $this->dialogObject->execute();
163 $display.= $this->_getTabFooter();
164 return($this->getHeader().$display);
165 }
166 }
168 // Display tab object.
169 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
170 # $this->tabObject->save_object();
171 $display = $this->tabObject->execute();
172 $display.= $this->_getTabFooter();
173 return($this->getHeader().$display);
174 }
176 // Set current restore base for snapshot handling.
177 if(is_object($this->snapHandler)){
178 $bases = array();
179 foreach($this->storagePoints as $sp){
180 $bases[] = $sp.$this->headpage->getBase();
181 }
183 // No bases specified? Try base
184 if(!count($bases)) $bases[] = $this->headpage->getBase();
186 $this->snapHandler->setSnapshotBases($bases);
187 }
189 // Display list
190 return($this->renderList());
191 }
193 function editFilter()
194 {
195 $this->dialogObject = new userFilter($this->config,$this->getHeadpage());
196 }
198 function renderList()
199 {
200 $this->headpage->update();
201 $display = $this->headpage->render();
202 return($this->getHeader().$display);
203 }
205 function getHeadpage()
206 {
207 return($this->headpage);
208 }
210 function getFilter()
211 {
212 return($this->filter);
213 }
215 /*! \brief Generates the plugin header which is displayed whenever a tab object is
216 * opened.
217 */
218 protected function getHeader()
219 {
220 // We do not display any headers right now.
221 if(1 || $this->skipHeader) return("");
222 }
225 /*! \brief Generates the footer which is used whenever a tab object is
226 * displayed.
227 */
228 protected function _getTabFooter()
229 {
230 // Do not display tab footer for non tab objects
231 if(!($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug)){
232 return("");
233 }
235 // Check if there is a dialog opened - We don't need any buttons in this case.
236 if($this->tabObject->by_object[$this->tabObject->current]){
237 $current = $this->tabObject->by_object[$this->tabObject->current];
238 if(isset($current->dialog) && (is_object($current->dialog) || $current->dialog)){
239 return("");
240 }
241 }
243 // Skip footer if requested;
244 if($this->skipFooter) return("");
246 // In case an of locked entry, we may have opened a read-only tab.
247 $str = "";
248 if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
249 $str.= "
250 <p style=\"text-align:right\">
251 <button type=submit name=\"edit_cancel\">".msgPool::cancelButton()."</button>
252 </p>";
253 return($str);
254 }else{
256 // Display ok, (apply) and cancel buttons
257 $str.= "<p style=\"text-align:right\">\n";
258 $str.= "<button type=\"submit\" name=\"edit_finish\" style=\"width:80px\">".msgPool::okButton()."</button>\n";
259 $str.= " \n";
260 if($this->displayApplyBtn){
261 $str.= "<button type=\"submit\" name=\"edit_apply\">".msgPool::applyButton()."</button>\n";
262 $str.= " \n";
263 }
264 $str.= "<button type=\"submit\" name=\"edit_cancel\">".msgPool::cancelButton()."</button>\n";
265 $str.= "</p>";
266 }
267 return($str);
268 }
271 /*! \brief Initiates the removal for the given entries
272 * and displays a confirmation dialog.
273 *
274 * @param String 'action' The name of the action which was the used as trigger.
275 * @param Array 'target' A list of object dns, which should be affected by this method.
276 * @param Array 'all' A combination of both 'action' and 'target'.
277 */
278 protected function removeEntryRequested($action="",$target=array(),$all=array())
279 {
280 // Close dialogs and remove locks for currently handled dns
281 $this->cancelEdit();
283 $disallowed = array();
284 $this->dns = array();
286 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
288 // Check permissons for each target
289 $h = $this->getHeadpage();
290 $oTypes = $h->objectTypes;
291 foreach($target as $dn){
292 $entry = $h->getEntry($dn);
293 $obj = $h->getObjectType($oTypes, $entry['objectClass']);
294 $acl = $this->ui->get_permissions($dn, $obj['category']."/".$obj['class']);
295 if(preg_match("/d/",$acl)){
296 $this->dns[] = $dn;
297 }else{
298 $disallowed[] = $dn;
299 }
300 }
301 if(count($disallowed)){
302 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
303 }
305 // We've at least one entry to delete.
306 if(count($this->dns)){
308 // check locks
309 if ($user= get_multiple_locks($this->dns)){
310 return(gen_locked_message($user,$this->dns));
311 }
313 // Add locks
314 $dns_names = array();
315 $types = array();
317 // Build list of object -labels
318 foreach($h->objectTypes as $type){
319 $map[$type['objectClass']]= $type['label'];
320 }
322 foreach($this->dns as $dn){
323 $tmp = $h->getType($dn);
324 if(isset($map[$tmp])){
325 $dns_names[LDAP::fix($dn)] = _($map[$tmp]);
326 }else{
327 $dns_names[] =LDAP::fix($dn);
328 }
329 }
330 add_lock ($this->dns, $this->ui->dn);
332 // Display confirmation dialog.
333 $smarty = get_smarty();
334 $smarty->assign("info", msgPool::deleteInfo($dns_names));
335 $smarty->assign("multiple", true);
336 return($smarty->fetch(get_template_path('removeEntries.tpl')));
337 }
338 }
341 /*! \brief Object removal was confirmed, now remove the requested entries.
342 *
343 * @param String 'action' The name of the action which was the used as trigger.
344 * @param Array 'target' A list of object dns, which should be affected by this method.
345 * @param Array 'all' A combination of both 'action' and 'target'.
346 */
347 function removeEntryConfirmed($action="",$target=array(),$all=array(),
348 $altTabClass="",$altTabType="", $altAclCategory="",$altAclPlugin="")
349 {
350 $tabType = $this->tabType;
351 $tabClass = $this->tabClass;
352 $aclCategory = $this->aclCategory;
353 $aclPlugin = $this->aclPlugin;
354 if(!empty($altTabClass)) $tabClass = $altTabClass;
355 if(!empty($altTabType)) $tabType = $altTabType;
356 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
357 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
359 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel confirmed!");
361 // Check permissons for each target
362 $h = $this->getHeadpage();
363 $oTypes = $h->objectTypes;
364 foreach($this->dns as $key => $dn){
365 $entry = $h->getEntry($dn);
366 $obj = $h->getObjectType($oTypes, $entry['objectClass']);
367 $acl = $this->ui->get_permissions($dn, $obj['category']."/".$obj['class']);
369 // Check permissions, are we allowed to remove this object?
370 if(preg_match("/d/",$acl)){
372 // Delete the object
373 $this->dn = $dn;
374 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn,
375 $aclCategory, true, true);
376 $this->tabObject->set_acl_base($this->dn);
377 $this->tabObject->parent = &$this;
378 $this->tabObject->delete ();
380 // Remove the lock for the current object.
381 del_lock($this->dn);
382 } else {
383 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
384 new log("security","groups/".get_class($this),$dn,array(),"Tried to trick deletion.");
385 }
386 }
388 // Cleanup
389 $this->remove_lock();
390 $this->closeDialogs();
391 }
394 /*! \brief Detects actions/events send by the ui
395 * and the corresponding targets.
396 */
397 function detectPostActions()
398 {
399 if(!is_object($this->headpage)){
400 trigger_error("No valid headpage given....!");
401 return(array());
402 }
403 $action= $this->headpage->getAction();
404 if(isset($_POST['edit_apply'])) $action['action'] = "apply";
405 if(isset($_POST['edit_finish'])) $action['action'] = "save";
406 if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";
407 if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";
408 if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";
409 if(isset($_POST['saveFilter'])) $action['action'] = "saveFilter";
410 if(isset($_POST['cancelFilter'])) $action['action'] = "cancelFilter";
412 // Detect Snapshot actions
413 if(isset($_POST['CreateSnapshot'])) $action['action'] = "saveSnapshot";
414 if(isset($_POST['CancelSnapshot'])) $action['action'] = "cancelSnapshot";
415 foreach($_POST as $name => $value){
416 $once =TRUE;
417 if(preg_match("/^RestoreSnapShot_/",$name) && $once){
418 $once = FALSE;
419 $entry = base64_decode(preg_replace("/^RestoreSnapShot_(.*)$/i","\\1",$name));
420 $action['action'] = "restoreSnapshot";
421 $action['targets'] = array($entry);
422 }
423 }
425 return($action);
426 }
429 /*! \brief Calls the registered method for a given action/event.
430 */
431 function handleActions($action)
432 {
433 // Start action
434 if(isset($this->actions[$action['action']])){
435 $func = $this->actions[$action['action']];
436 if(!isset($action['targets']))$action['targets']= array();
437 return($this->$func($action['action'],$action['targets'],$action));
438 }
439 }
442 /*! \brief Opens the snapshot creation dialog for the given target.
443 *
444 * @param String 'action' The name of the action which was the used as trigger.
445 * @param Array 'target' A list of object dns, which should be affected by this method.
446 * @param Array 'all' A combination of both 'action' and 'target'.
447 */
448 function createSnapshotDialog($action="",$target=array(),$all=array())
449 {
450 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Snaptshot creation initiated!");
452 foreach($target as $entry){
453 if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
454 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
455 $this->dialogObject->aclCategories = array($this->aclCategory);
456 $this->dialogObject->parent = &$this;
458 }else{
459 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to create a snapshot for %s."),$entry),
460 ERROR_DIALOG);
461 }
462 }
463 }
466 /*! \brief Creates a snapshot new entry - This method is called when the somebody
467 * clicks 'save' in the "Create snapshot dialog" (see ::createSnapshotDialog).
468 *
469 * @param String 'action' The name of the action which was the used as trigger.
470 * @param Array 'target' A list of object dns, which should be affected by this method.
471 * @param Array 'all' A combination of both 'action' and 'target'.
472 */
473 function saveSnapshot($action="",$target=array(),$all=array())
474 {
475 if(!is_object($this->dialogObject)) return;
476 $this->dialogObject->save_object();
477 $msgs = $this->dialogObject->check();
478 if(count($msgs)){
479 foreach($msgs as $msg){
480 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
481 }
482 }else{
483 $this->dn = $this->dialogObject->dn;
484 $this->snapHandler->create_snapshot( $this->dn,$this->dialogObject->CurrentDescription);
485 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot created!");
486 $this->closeDialogs();
487 }
488 }
491 /*! \brief Restores a snapshot object.
492 * The dn of the snapshot entry has to be given as ['target'] parameter.
493 *
494 * @param String 'action' The name of the action which was the used as trigger.
495 * @param Array 'target' A list of object dns, which should be affected by this method.
496 * @param Array 'all' A combination of both 'action' and 'target'.
497 */
498 function restoreSnapshot($action="",$target=array(),$all=array())
499 {
500 $entry = array_pop($target);
501 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
502 $this->snapHandler->restore_snapshot($entry);
503 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Snaptshot restored!");
504 $this->closeDialogs();
505 }else{
506 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
507 ERROR_DIALOG);
508 }
509 }
512 /*! \brief Displays the "Restore snapshot dialog" for a given target.
513 * If no target is specified, open the restore removed object
514 * dialog.
515 * @param String 'action' The name of the action which was the used as trigger.
516 * @param Array 'target' A list of object dns, which should be affected by this method.
517 * @param Array 'all' A combination of both 'action' and 'target'.
518 */
519 function restoreSnapshotDialog($action="",$target=array(),$all=array())
520 {
521 // Set current restore base for snapshot handling.
522 if(is_object($this->snapHandler)){
523 $bases = array();
524 foreach($this->storagePoints as $sp){
525 $bases[] = $sp.$this->headpage->getBase();
526 }
527 }
529 // No bases specified? Try base
530 if(!count($bases)) $bases[] = $this->headpage->getBase();
532 // No target, open the restore removed object dialog.
533 if(!count($target)){
534 $entry = $this->headpage->getBase();
535 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
536 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
537 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
538 $this->dialogObject->set_snapshot_bases($bases);
539 $this->dialogObject->display_all_removed_objects = true;
540 $this->dialogObject->display_restore_dialog = true;
541 $this->dialogObject->parent = &$this;
542 }else{
543 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
544 ERROR_DIALOG);
545 }
546 }else{
548 // Display the restore points for a given object.
549 $entry = array_pop($target);
550 if(!empty($entry) && $this->ui->allow_snapshot_restore($entry,$this->aclCategory)){
551 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot restoring initiated!");
552 $this->dialogObject = new SnapShotDialog($this->config,$entry,$this);
553 $this->dialogObject->set_snapshot_bases($bases);
554 $this->dialogObject->display_restore_dialog = true;
555 $this->dialogObject->parent = &$this;
556 }else{
557 msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to restore a snapshot for %s."),$entry),
558 ERROR_DIALOG);
559 }
560 }
561 }
564 /*! \brief This method intiates the object creation.
565 *
566 * @param String 'action' The name of the action which was the used as trigger.
567 * @param Array 'target' A list of object dns, which should be affected by this method.
568 * @param Array 'all' A combination of both 'action' and 'target'.
569 */
570 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
571 {
572 /* To handle mutliple object types overload this method.
573 * ...
574 * registerAction('newUser', 'newEntry');
575 * registerAction('newGroup','newEntry');
576 * ...
577 *
578 * function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
579 * {
580 * switch($action){
581 * case 'newUser' : {
582 * mangement::newEntry($action,$target,$all,"usertabs","USERTABS","users");
583 * }
584 * case 'newGroup' : {
585 * mangement::newEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
586 * }
587 * }
588 * }
589 **/
590 $tabType = $this->tabType;
591 $tabClass = $this->tabClass;
592 $aclCategory = $this->aclCategory;
593 if(!empty($altTabClass)) $tabClass = $altTabClass;
594 if(!empty($altTabType)) $tabType = $altTabType;
595 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
597 // Check locking & lock entry if required
598 $this->displayApplyBtn = FALSE;
599 $this->dn = "new";
600 $this->is_new = TRUE;
601 $this->is_single_edit = FALSE;
602 $this->is_multiple_edit = FALSE;
604 set_object_info($this->dn);
606 // Open object.
607 if(empty($tabClass) || empty($tabType)){
608 // No tab type defined
609 }else{
610 if (isset($this->config->data['TABS'][$tabType])) {
611 $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
612 $this->tabObject->set_acl_base($this->headpage->getBase());
613 $this->tabObject->parent = &$this;
614 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
615 } else {
616 msg_dialog::display(_("Error"), sprintf(_("No tab declaration for '%s' found in your configuration file. Cannot create plugin instance!"), $tabType), ERROR_DIALOG);
617 }
618 }
619 }
622 /*! \brief This method opens an existing object or a list of existing objects to be edited.
623 *
624 *
625 * @param String 'action' The name of the action which was the used as trigger.
626 * @param Array 'target' A list of object dns, which should be affected by this method.
627 * @param Array 'all' A combination of both 'action' and 'target'.
628 */
629 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
630 {
631 /* To handle mutliple object types overload this method.
632 * ...
633 * registerAction('editUser', 'editEntry');
634 * registerAction('editGroup','editEntry');
635 * ...
636 *
637 * function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory)
638 * {
639 * switch($action){
640 * case 'editUser' : {
641 * mangement::editEntry($action,$target,$all,"usertabs","USERTABS","users");
642 * }
643 * case 'editGroup' : {
644 * mangement::editEntry($action,$target,$all,"grouptabs","GROUPTABS","groups");
645 * }
646 * }
647 * }
648 **/
650 // Do not create a new tabObject while there is already one opened,
651 // the user may have just pressed F5 to reload the page.
652 if(is_object($this->tabObject)){
653 return;
654 }
656 $tabType = $this->tabType;
657 $tabClass = $this->tabClass;
658 $aclCategory = $this->aclCategory;
659 if(!empty($altTabClass)) $tabClass = $altTabClass;
660 if(!empty($altTabType)) $tabType = $altTabType;
661 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
663 // Single edit - we only got one object dn.
664 if(count($target) == 1){
665 $this->displayApplyBtn = TRUE;
666 $this->is_new = FALSE;
667 $this->is_single_edit = TRUE;
668 $this->is_multiple_edit = FALSE;
670 // Get the dn of the object and creates lock
671 $this->dn = array_pop($target);
672 set_object_info($this->dn);
673 $user = get_lock($this->dn);
674 if ($user != ""){
675 return(gen_locked_message ($user, $this->dn,TRUE));
676 }
677 add_lock ($this->dn, $this->ui->dn);
679 // Open object.
680 if(empty($tabClass) || empty($tabType)){
681 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
682 }else{
683 $tab = $tabClass;
684 $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
685 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
686 $this->tabObject->set_acl_base($this->dn);
687 $this->tabObject->parent = &$this;
688 }
689 }else{
691 // We've multiple entries to edit.
692 $this->is_new = FALSE;
693 $this->is_singel_edit = FALSE;
694 $this->is_multiple_edit = TRUE;
696 // Open multiple edit handler.
697 if(empty($tabClass) || empty($tabType)){
698 trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
699 }else{
700 $this->dns = $target;
701 $tmp = new multi_plug($this->config,$tabClass,$this->config->data['TABS'][$tabType],
702 $this->dns,$this->headpage->getBase(),$aclCategory);
704 // Check for locked entries
705 if ($tmp->entries_locked()){
706 return($tmp->display_lock_message());
707 }
709 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
711 // Now lock entries.
712 if($tmp->multiple_available()){
713 $tmp->lock_entries($this->ui->dn);
714 $this->tabObject = $tmp;
715 set_object_info($this->tabObject->get_object_info());
716 }
717 }
718 }
719 }
722 /*! \brief Close filter dialog
723 */
724 protected function cancelFilter()
725 {
726 if($this->dialogObject instanceOf userFilter){
727 $this->remove_lock();
728 $this->closeDialogs();
729 }
730 }
732 /*! \brief Save filter modifcations.
733 */
734 protected function saveFilter()
735 {
736 if($this->dialogObject instanceOf userFilter){
737 $msgs = $this->dialogObject->check();
738 if(count($msgs)){
739 msg_dialog::displayChecks($msgs);
740 return("");
741 }else{
742 $this->dialogObject->save();
743 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
744 $this->remove_lock();
745 $this->closeDialogs();
747 // Ask filter to reload information
748 $this->filter->reloadFilters();
749 }
750 }
751 }
754 /*! \brief Save object modifications and closes dialogs (returns to object listing).
755 * - Calls '::check' to validate the given input.
756 * - Calls '::save' to save back object modifications (e.g. to ldap).
757 * - Calls '::remove_locks' to remove eventually created locks.
758 * - Calls '::closeDialogs' to return to the object listing.
759 */
760 protected function saveChanges()
761 {
762 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
763 $this->tabObject->save_object();
764 $msgs = $this->tabObject->check();
765 if(count($msgs)){
766 msg_dialog::displayChecks($msgs);
767 return("");
768 }else{
769 $this->tabObject->save();
770 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
771 $this->remove_lock();
772 $this->closeDialogs();
773 }
774 }elseif($this->dialogObject instanceOf plugin){
775 $this->dialogObject->save_object();
776 $msgs = $this->dialogObject->check();
777 if(count($msgs)){
778 msg_dialog::displayChecks($msgs);
779 return("");
780 }else{
781 $this->dialogObject->save();
782 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Entry saved!");
783 $this->remove_lock();
784 $this->closeDialogs();
785 }
786 }
787 }
790 /*! \brief Save object modifications and keep dialogs opened.
791 * - Calls '::check' to validate the given input.
792 * - Calls '::save' to save back object modifications (e.g. to ldap).
793 */
794 protected function applyChanges()
795 {
796 if($this->tabObject instanceOf tabs || $this->tabObject instanceOf multi_plug){
797 $this->tabObject->save_object();
798 $msgs = $this->tabObject->check();
799 if(count($msgs)){
800 msg_dialog::displayChecks($msgs);
801 return("");
802 }else{
803 $this->tabObject->save();
804 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Modifications applied!");
805 $this->tabObject->re_init();
806 }
807 }
808 }
811 /*! \brief This method closes dialogs
812 * and cleans up the cached object info and the ui.
813 */
814 protected function closeDialogs()
815 {
816 $this->last_dn = $this->dn;
817 $this->last_dns = $this->dns;
818 $this->last_tabObject = $this->tabObject;
819 $this->last_dialogObject = $this->dialogObject;
820 $this->dn = "";
821 $this->dns = array();
822 $this->tabObject = null;
823 $this->dialogObject = null;
824 $this->skipFooter = FALSE;
825 set_object_info();
826 }
829 /*! \brief Editing an object was caneled.
830 * Close dialogs/tabs and remove locks.
831 */
832 protected function cancelEdit()
833 {
834 $this->remove_lock();
835 $this->closeDialogs();
836 }
839 /*! \brief Every click in the list user interface sends an event
840 * here can we connect those events to a method.
841 * eg. ::registerEvent('new','createUser')
842 * When the action/event new is send, the method 'createUser'
843 * will be called.
844 */
845 function registerAction($action,$target)
846 {
847 $this->actions[$action] = $target;
848 }
851 /*! \brief Removes ldap object locks created by this class.
852 * Whenever an object is edited, we create locks to avoid
853 * concurrent modifications.
854 * This locks will automatically removed here.
855 */
856 function remove_lock()
857 {
858 if(!empty($this->dn) && $this->dn != "new"){
859 del_lock($this->dn);
860 }
861 if(count($this->dns)){
862 del_lock($this->dns);
863 }
864 }
867 /*! \brief This method is used to queue and process copy&paste actions.
868 * Allows to copy, cut and paste mutliple entries at once.
869 * @param String 'action' The name of the action which was the used as trigger.
870 * @param Array 'target' A list of object dns, which should be affected by this method.
871 * @param Array 'all' A combination of both 'action' and 'target'.
872 */
873 function copyPasteHandler($action="",$target=array(),$all=array(),
874 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
875 {
876 // Return without any actions while copy&paste handler is disabled.
877 if(!is_object($this->cpHandler)) return("");
879 $tabType = $this->tabType;
880 $tabClass = $this->tabClass;
881 $aclCategory = $this->aclCategory;
882 $aclPlugin = $this->aclPlugin;
883 if(!empty($altTabClass)) $tabClass = $altTabClass;
884 if(!empty($altTabType)) $tabType = $altTabType;
885 if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
886 if(!empty($altAclPlugin)) $aclPlugin = $altAclPlugin;
888 // Save user input
889 $this->cpHandler->save_object();
891 // Add entries to queue
892 if($action == "copy" || $action == "cut"){
893 $this->cpHandler->cleanup_queue();
894 foreach($target as $dn){
895 if($action == "copy" && $this->ui->is_copyable($dn,$aclCategory,$aclPlugin)){
896 $this->cpHandler->add_to_queue($dn,"copy",$tabClass,$tabType,$aclCategory,$this);
897 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry copied!");
898 }
899 if($action == "cut" && $this->ui->is_cutable($dn,$aclCategory,$aclPlugin)){
900 $this->cpHandler->add_to_queue($dn,"cut",$tabClass,$tabType,$aclCategory,$this);
901 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$dn,"Entry cutted!");
902 }
903 }
904 }
906 // Initiate pasting
907 if($action == "paste"){
908 $this->cpPastingStarted = TRUE;
909 }
911 // Display any c&p dialogs, eg. object modifications required before pasting.
912 if($this->cpPastingStarted && $this->cpHandler->entries_queued()){
913 $this->cpHandler->SetVar("base",$this->headpage->getBase());
914 $data = $this->cpHandler->execute();
915 if(!empty($data)){
916 return($data);
917 }
918 }
920 // Automatically disable pasting process since there is no entry left to paste.
921 if(!$this->cpHandler->entries_queued()){
922 $this->cpPastingStarted = FALSE;
923 }
924 return("");
925 }
928 function setFilter($str) {
929 $this->filter = $str;
930 }
933 function postcreate() {
934 $this->_handlePostEvent('POSTCREATE');
935 }
936 function postmodify(){
937 $this->_handlePostEvent('POSTMODIFY');
938 }
939 function postremove(){
940 $this->_handlePostEvent('POSTREMOVE');
941 }
943 function _handlePostEvent($type)
944 {
946 /* Find postcreate entries for this class */
947 $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
948 if ($command != ""){
950 /* Walk through attribute list */
951 foreach ($this->attributes as $attr){
952 if (!is_array($this->$attr)){
953 $add_attrs[$attr] = $this->$attr;
954 }
955 }
956 $add_attrs['dn']=$this->dn;
958 $tmp = array();
959 foreach($add_attrs as $name => $value){
960 $tmp[$name] = strlen($name);
961 }
962 arsort($tmp);
964 /* Additional attributes */
965 foreach ($tmp as $name => $len){
966 $value = $add_attrs[$name];
967 $command= str_replace("%$name", "$value", $command);
968 }
970 if (check_command($command)){
971 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
972 $command, "Execute");
973 exec($command,$arr);
974 foreach($arr as $str){
975 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
976 $command, "Result: ".$str);
977 }
978 } else {
979 $message= msgPool::cmdnotfound($type, get_class($this));
980 msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
981 }
982 }
983 }
985 function is_modal_dialog()
986 {
987 return(is_object($this->tabObject) || is_object($this->dialogObject));
988 }
991 /*! \brief Forward command execution request
992 * to the correct method.
993 */
994 function handle_post_events($mode, $addAttrs= array())
995 {
996 if(!in_array($mode, array('add','remove','modify'))){
997 trigger_error(sprintf("Invalid post event type given '%s'! Valid types are [add,modify,remove].", $mode));
998 return;
999 }
1000 switch ($mode){
1001 case "add":
1002 plugin::callHook($this,"POSTCREATE", $addAttrs);
1003 break;
1005 case "modify":
1006 plugin::callHook($this,"POSTMODIFY", $addAttrs);
1007 break;
1009 case "remove":
1010 plugin::callHook($this,"POSTREMOVE", $addAttrs);
1011 break;
1012 }
1013 }
1014 }
1016 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1017 ?>