1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
22 class faiManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Software deployment";
26 var $plDescription = "Manage software packages and deployment reciepes";
27 var $plIcon = "plugins/fai/images/plugin.png";
29 /* Headpage attributes */
30 var $lock_type = ""; // should be branch/freeze
31 var $lock_name = "";
32 var $lock_dn = "";
34 /* attribute list for save action */
35 var $attributes = array("lock_type","lock_name","lock_dn"); // Attributes Managed by this plugin
36 var $objectclasses= array(); // ObjectClasses which the attributes are related to
37 var $dialog = array(); // This object contains every dialog we have currently opened
39 var $objects = array(); // This array contains all available objects shown in divlist
40 var $is_dialog = false;
42 var $dispNewBranch= false;
43 var $dispNewFreeze= false;
45 var $DivListFai;
46 var $start_pasting_copied_objects = FALSE;
47 var $CopyPasteHandler = FALSE;
49 /* Allow inserting of new elements if freezed releases
50 */
51 var $allow_freeze_object_attach = TRUE;
52 var $no_save;
53 var $acl_base ="";
54 var $fai_base ="";
55 var $fai_release ="";
56 var $acl_module = array("fai");
57 var $opsi = NULL;
59 /* construction/reconstruction
60 */
61 function faiManagement (&$config, $ui)
62 {
63 /* Set defaults */
64 $this->dn = "";
65 $this->config = $config;
66 $this->ui = $ui;
68 /* Check if the opsi plugin is installed.
69 */
70 if(class_available("opsi")){
71 $this->opsi = new opsi($this->config);;
72 }
74 /* Creat dialog object */
75 $this->DivListFai = new divListFai($this->config,$this);
77 /* Copy & Paste handler */
78 if ($this->config->boolValueIsTrue("main", "copyPaste")){
79 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
80 }
82 /* Set default release
83 */
84 $this->acl_base = $this->config->current['BASE'];
85 $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
87 if(!session::is_set("fai_filter")){
89 /* Set intial release */
90 $rel = $config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
91 $rels = array_flip($this->getBranches());
92 if(isset($rels[$rel])){
93 $rel = $rels[$rel];
94 }else{
95 $rel = $this->fai_base;
96 }
98 session::set("fai_filter",array("fai_release" => $rel));
99 }
101 $fai_filter = session::get("fai_filter");
102 $this->fai_release = $fai_filter['fai_release'];
103 }
105 function execute()
106 {
107 /* Call parent execute */
108 plugin::execute();
110 /* Initialise vars and smarty */
111 $smarty = get_smarty();
112 $smarty->assign("BranchName","");
114 $display = "";
115 $s_action = "";
116 $i_entryID ="";
117 $s_entryType= "";
118 $s_entry = "";
119 $no_save = FALSE; // hide Apply / Save buttons
121 /* If an entry was locked, these vars will be stored in a session to allow direct edit */
122 session::set('LOCK_VARS_TO_USE',array("/^edit_freeze_entry$/","/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/","/^faiGroupHandle_apply$/"));
124 /****************
125 Handle posts
126 ****************/
128 /* Check ImageButton posts
129 * Create new tab ich new_xx is posted
130 */
131 $posts = array( "/^remove_branch/" =>"remove_branch",
132 "/^branch_branch/" =>"branch_branch",
133 "/^freeze_branch/" =>"freeze_branch",
135 "/^create_partition/i" =>"new_partition",
136 "/^create_script/i" =>"new_script",
137 "/^create_hook/i" =>"new_hook",
138 "/^create_variable/i" =>"new_variable",
139 "/^create_template/i" =>"new_template",
140 "/^create_package/i" =>"new_package",
141 "/^create_profile/i" =>"new_profile",
143 "/^edit_continue$/" => "select_class_name_finished",
145 "/^group_copy/" => "group_copy",
146 "/^group_cut/" => "group_cut",
147 "/^group_edit/" => "group_edit",
148 "/^group_remove/" => "group_remove");
149 foreach($_POST as $name => $value){
150 foreach($posts as $reg => $act ){
151 if(preg_match($reg,$name)){
152 $s_action = $act;
153 $s_entry = ltrim(preg_replace($reg,"",$name),"_");
154 $s_entry = preg_replace("/_.*$/","",$s_entry);
155 break;
156 }
157 }
158 if(preg_match("/^edit_[0-9]*_.*$/",$name)){
159 $i_entryID = preg_replace("/^edit_([0-9]*)_.*$/i","\\1",$name);
160 $s_entryType= preg_replace("/^edit_[0-9]*_([^_]*)_.*$/i","\\1",$name);
161 $s_action = "edit";
162 }
163 }
165 if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
166 if(isset($this->objects[$_GET['id']])){
167 $s_action = "group_edit";
168 $s_entry = $_GET['id'];
169 }
170 }
172 foreach(array("freeze_branch" => "freeze_branch",
173 "branch_branch" => "branch_branch",
174 "remove_branch" => "remove_branch") as $from => $to){
175 if(isset($_GET['act']) && $_GET['act'] == $from){
176 $s_action = $to;
177 }
178 }
180 /* handle C&P from layer menu */
181 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
182 $s_action = "copy_multiple";
183 }
184 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
185 $s_action = "cut_multiple";
186 }
187 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
188 $s_action = "editPaste";
189 }
192 if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
193 $this->dispNewBranch = false;
194 $this->dispNewFreeze = false;
195 }
197 /* Create options */
198 if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
199 $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
200 $s_entry = preg_replace("/^Create_/","",$_POST['menu_action']);
201 }
203 /* handle remove from layers menu */
204 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
205 $s_action = "del_multiple";
206 }
209 if(!empty($s_action)){
210 $this->no_save = $no_save;
211 }
214 /*******************
215 Opsi extension
216 *******************/
218 if($this->opsi instanceof opsi && $this->opsi->enabled()){
219 if($s_action == "opsi_edit"){
220 $name = $this->objects[$s_entry]['cn'];
221 $cfg = $this->opsi->get_product_properties($name);
222 $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
223 if(isset($this->dialog->by_object['opsiProperties'])){
224 $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
225 $this->dialog->by_object['opsiProperties']->set_product($name);
226 }else{
227 trigger_error("Unknown tab, please check config.");
228 }
229 }
230 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
231 $this->dialog = NULL;
232 }
233 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
234 $this->dialog->save_object();
235 $op = $this->dialog->by_object['opsiProperties'];
236 $name = $op->get_product();
237 $cfg = $op->get_cfg();
238 $this->opsi->set_product_properties($name,$cfg);
239 if($this->opsi->is_error()){
240 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
241 }else{
242 $this->dialog = NULL;
243 }
244 }
245 if($this->dialog instanceof tabs_opsiProdConfig){
246 $this->dialog->save_object();
247 return($this->dialog->execute());
248 }
249 }
252 /****************
253 Delete a group of FAI objects
254 (Group = same name & different classes)
255 ****************/
257 if($s_action == "group_remove"){
258 if(isset($this->objects[$s_entry])){
259 $group = $this->objects[$s_entry];
261 /* Do not allow to remove opsi products */
262 foreach(array("opsi_netboot","opsi_local") as $type){
263 if(isset($group[$type])) unset($group[$type]);
264 }
265 if(count($group) == 1){
266 $s_action = "remove";
267 $i_entryID = $s_entry;
268 $s_entryType = key($group);
269 }elseif(count($group)){
270 $this->dialog = new faiGroupHandle($group,"remove");
271 }
272 }
273 }elseif($s_action == "group_edit"){
274 if(isset($this->objects[$s_entry])){
275 $group = $this->objects[$s_entry];
276 if(count($group) == 1){
277 $s_action = "edit";
278 $i_entryID = $s_entry;
279 $s_entryType = key($group);
280 }else{
281 $this->dialog = new faiGroupHandle($group,"edit");
282 }
283 }
284 }elseif($s_action == "group_cut"){
285 if(isset($this->objects[$s_entry])){
286 $group = $this->objects[$s_entry];
287 if(count($group) == 1){
288 $s_action = "cut";
289 $i_entryID = $s_entry;
290 $s_entryType = key($group);
291 }else{
292 $this->dialog = new faiGroupHandle($group,"cut");
293 }
294 }
295 }elseif($s_action == "group_copy"){
296 if(isset($this->objects[$s_entry])){
297 $group = $this->objects[$s_entry];
298 if(count($group) == 1){
299 $s_action = "copy";
300 $i_entryID = $s_entry;
301 $s_entryType = key($group);
302 }else{
303 $this->dialog = new faiGroupHandle($group,"copy");
304 }
305 }
306 }
307 if($this->dialog instanceOf faiGroupHandle){
308 $this->dialog->save_object();
309 if($this->dialog->is_open()){
310 return($this->dialog->execute());
311 }elseif($this->dialog->is_canceled() || isset($_POST['cancel_lock'])){
312 $this->dialog = FALSE;
313 }else{
314 if(!count($this->dialog->get_selected())){
315 $this->dialog = FALSE;
316 }
317 }
318 }
320 /********************
321 Copy & Paste
322 ********************/
324 /* Display the copy & paste dialog, if it is currently open */
325 $ret = $this->copyPasteHandling_from_queue($s_action,$i_entryID,$s_entryType);
326 if($ret){
327 return($ret);
328 }
331 /********************
332 Delete MULTIPLE entries confirmed
333 ********************/
335 /* Confirmation for deletion has been passed. Users should be deleted. */
336 if (isset($_POST['delete_multiple_fai_object_confirm'])){
338 /* Find out more about the object type */
339 $ldap = $this->config->get_ldap_link();
341 /* Remove user by user and check acls before removeing them */
342 foreach($this->dns as $key => $dn){
343 $ldap->cat($dn, array('objectClass'));
344 $attrs = $ldap->fetch();
345 $type = $this->get_type($attrs);
346 $acl = $this->ui->get_permissions($dn,"fai/".$type[1]);
347 if(preg_match("/d/",$acl)){
348 $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
349 $this->dialog->parent = &$this;
350 $this->dialog->set_acl_base($dn);
351 $this->dialog->by_object[$type[1]]->remove_from_parent ();
352 $this->dialog= FALSE;
353 $to_del = FAI::clean_up_releases($dn);
354 FAI::save_release_changes_now();
355 foreach($to_del as $dn){
356 $ldap->rmdir_recursive($dn);
357 }
358 } else {
360 /* Normally this shouldn't be reached, send some extra
361 logs to notify the administrator */
362 msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
363 new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
364 }
365 }
367 /* Remove lock file after successfull deletion */
368 $this->remove_lock();
369 $this->dns = array();
370 $this->dialog = FALSE;
371 }
374 /****************
375 Delete confirme dialog
376 ****************/
378 if ($s_action=="del_multiple" || $s_action == "remove" ||
379 $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "remove"){
381 /* Collect objects to delete and check if objects are freezed
382 */
383 $dns = array();
384 $errors = "";
385 $this->dns = array();
387 if($s_action == "remove"){
388 $to_delete =array($entry = $this->objects[$i_entryID][$s_entryType]);
389 }elseif($this->dialog instanceOf faiGroupHandle){
390 $to_delete = $this->dialog->get_selected();
391 }else{
392 $ids = $this->list_get_selected_items();
393 $to_delete = array();
394 foreach($ids as $id){
395 $to_delete = array_merge($to_delete,$this->objects[$id]);
396 }
397 }
399 foreach($to_delete as $obj){
400 if(isset($obj['type']) && in_array($obj['type'],array("opsi_netboot","opsi_local"))){
401 continue;
402 }
403 if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
404 $errors .= $obj['cn'].", ";
405 }else{
406 $this->dns[] = $obj['dn'];
407 }
408 }
410 if($errors != ""){
411 msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
412 "<br><br>".trim($errors,", ")),INFO_DIALOG);
413 }
415 /* Check locking
416 */
417 if(count($this->dns)){
418 if ($user= get_multiple_locks($this->dns)){
419 return(gen_locked_message($user,$this->dns));
420 }
421 if(count($this->dns)){
422 $dns_names = array();
423 foreach($this->dns as $dn){
424 add_lock ($dn, $this->ui->dn);
425 $dns_names[] = LDAP::fix($dn);
426 }
427 $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
428 $smarty->assign("multiple", true);
429 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
430 }
431 }
432 }
436 /********************
437 Delete MULTIPLE entries Canceled
438 ********************/
440 /* Remove lock */
441 if(isset($_POST['delete_multiple_fai_object_cancel'])){
442 $this->remove_lock();
443 $this->dns = array();
444 }
446 /****************
447 Edit entry
448 ****************/
450 if($s_action == "edit" || $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "edit"){
452 $entry = array();
453 if($this->dialog instanceOf faiGroupHandle){
454 $entries = $this->dialog->get_selected();
455 $entry = array_pop($entries);
456 }elseif(isset($this->objects[$i_entryID][$s_entryType])){
457 $entry = $this->objects[$i_entryID][$s_entryType];
458 }
460 if(count($entry)){
461 $a_setup = $this->get_type($entry);
463 /* Special handling for opsi products
464 */
466 if(in_array($entry['type'],array("opsi_local","opsi_netboot")) &&
467 $this->opsi instanceof opsi && $this->opsi->enabled() ){
469 $name = $entry['cn'];
470 $cfg = $this->opsi->get_product_properties($name);
471 $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
472 if(isset($this->dialog->by_object['opsiProperties'])){
473 $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
474 $this->dialog->by_object['opsiProperties']->set_product($name);
475 }else{
476 trigger_error("Unknown tab, please check config.");
477 }
478 }elseif(count($a_setup)){
480 $this->dn = $entry['dn'];
481 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
482 if (($user= get_lock($this->dn)) != ""){
483 return(gen_locked_message ($user, $this->dn, TRUE));
484 }
485 add_lock ($this->dn, $this->ui->dn);
487 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
488 $this->dialog->parent = &$this;
489 $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
490 $this->dialog->set_acl_base($this->dn);
491 $this->is_dialog = true;
492 set_object_info($this->dn);
493 }
494 }
495 }
498 /* Branch handling
499 09.01.2006
500 */
502 /****************
503 Remove branch
504 ****************/
506 /* Remove branch
507 */
508 if($s_action == "remove_branch"){
509 $base= $this->fai_release;
511 /* Check if we have a post remove method configured
512 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
513 */
514 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
515 /* Load permissions for selected 'dn' and check if
516 we're allowed to remove this 'dn' */
517 if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
518 $smarty->assign("release_hidden",base64_encode($this->fai_release));
519 $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
520 return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
521 } else {
522 msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
523 }
524 }
525 }
528 /****************
529 Remove branch confirmed
530 ****************/
532 if(isset($_POST['delete_branch_confirm'])){
534 /* Check if we have a post remove method configured
535 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
536 */
537 if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
539 if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
540 msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
541 }else{
543 $bb = $this->fai_release;
544 if(!isset($ldap)){
545 $ldap = $this->config->get_ldap_link();
546 }
548 $br = $this->getBranches();
550 if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
551 $name = $br[$bb];
553 $ldap->cd($bb);
554 $ldap->recursive_remove();
555 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
556 $ldap->recursive_remove();
557 $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
558 $ldap->recursive_remove();
560 /* Search for all groups with configured application menus.
561 - First search all groups, to ensure that we only remove entries form whithin groups.
562 - The search für menu configuration for the specified release and collect all those dns.
563 - Remove entries
564 */
565 $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
566 $ldap->cd($this->config->current['BASE']);
567 $ldap->search("(objectClass=posixGroup)",array("dn"));
569 /* Collect all group dns
570 */
571 $groups = array();
572 while($attrs = $ldap->fetch()){
573 $groups[] = $attrs['dn'];
574 }
576 /* Collect all group menu release dns that match the release we have removed
577 */
578 $dns = array();
579 foreach($groups as $dn){
580 $ldap->cd($dn);
581 $ldap->search("(objectClass=FAIbranch)",array("dn"));
582 while($attrs = $ldap->fetch()){
583 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
584 $dns[] = $attrs['dn'];
585 }
586 }
587 }
589 /* Finally remove collected release dns
590 */
591 foreach($dns as $dn){
592 $ldap->cd($dn);
593 $ldap->recursive_remove();
594 }
596 /* Post remove */
597 $this->fai_release = $this->fai_base;
598 $this->lock_name = $name;
599 $this->lock_dn = $bb;
600 $this->postremove();
602 $fai_filter = session::get("fai_filter");
603 $fai_filter['fai_release'] = $this->fai_release;
604 session::set("fai_filter",$fai_filter);
606 new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
607 }
608 }
609 }
610 }
613 /****************
614 Create a new branch "insert Name"
615 ****************/
617 if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
618 session::set('LASTPOST',$_POST);
620 if($this->dispNewBranch){
621 $type = "branch";
622 }else{
623 $type = "freeze";
624 }
626 /* Check branch name */
627 $name = $_POST['BranchName'];
628 $is_ok = true;
629 $smarty->assign("BranchName",$name);
630 $base= $this->fai_base;
632 /* Check used characters */
633 if(!preg_match("/^[0-9a-z\.]*$/",$name)){
634 msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
635 $is_ok = false;
636 }
638 /* Check if this name is already in use */
639 if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
640 msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
641 $is_ok = false;
642 }
644 if($is_ok){
646 if(session::is_set('LASTPOST')){
647 $LASTPOST = session::get('LASTPOST');
648 }else{
649 $LASTPOST = array();
650 }
651 $LASTPOST['base'] = $base;
652 $LASTPOST['type'] = $type;
653 session::set('LASTPOST',$LASTPOST);
654 $smarty->assign("iframe", true);
655 $smarty->assign("plugID", $_GET['plug']);
656 $display = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
657 return($display);
658 }
659 }
662 /****************
663 Create a new branch
664 ****************/
666 if(isset($_GET['PerformBranch'])){
668 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
669 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
670 }else{
672 /* In order to see error messages we have to reset the error handler.
673 Due to the exit();
674 */
675 restore_error_handler();
677 /* Create it know */
678 $this->dispNewBranch = false;
679 $this->dispNewFreeze = false;
681 $LASTPOST = session::get('LASTPOST');
682 $base = $LASTPOST['base'];
683 $_POST = session::get('LASTPOST');
684 $name = $_POST['BranchName'];
686 $type = $LASTPOST['type'];
687 $ldap = $this->config->get_ldap_link();
689 $baseToUse = $base;
690 if($this->fai_release != $this->fai_base){
691 $baseToUse = $this->fai_release;
692 }
694 /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
696 $CurrentReleases = $this->getBranches();
697 $NewReleaseName = $name;
698 if(isset($CurrentReleases[$this->fai_release])) {
699 if($this->fai_release != $this->fai_base){
700 $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
701 $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
702 }else{
703 $NewReleaseName = $name;
704 }
705 }
707 $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse);
708 $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
710 $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse);
711 $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
713 /* Check if source depeartments exist */
714 foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
715 $ldap->cd($this->config->current['BASE']);
716 $ldap->cat($dep);
717 if(!$ldap->count()){
718 $ldap->create_missing_trees($dep);
719 }
720 }
722 /* Print header to have styles included */
723 echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
724 <html>
725 <head>
726 <title></title>
727 <style type="text/css">@import url("themes/default/style.css");</style>
728 <script language="javascript" src="include/focus.js" type="text/javascript"></script>
729 </head>
730 <body style="background: none;margin:3px;color:black">
731 ';
733 new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
735 /* Duplicate group application releases
736 */
737 FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
739 /* Duplicate applications
740 */
741 $ldap->cat($appsrc,array("dn")) ;
742 if($ldap->count()){
743 $ldap->cd ($appdst);
744 $ldap->recursive_remove();
745 FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
746 }
748 /* Duplicate mime types
749 */
750 $ldap->cat($mimesrc,array("dn")) ;
751 if($ldap->count()){
752 $ldap->cd ($mimedst);
753 $ldap->recursive_remove();
754 FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
755 }
757 $attr = array();
758 $attr['objectClass'] = array("organizationalUnit","FAIbranch");
759 $attr['ou'] = $name;
760 $attr['FAIstate'] = $type;
761 $ldap->cd($this->config->current['BASE']);
762 $ldap->cd("ou=".$name.",".$baseToUse);
763 $ldap->cat("ou=".$name.",".$baseToUse);
764 if($ldap->count()){
765 $ldap->modify($attr);
766 }else{
767 $ldap->add($attr);
768 }
770 /* Duplicate fai objects
771 */
772 // $ldap->cd ("ou=".$name.",".$baseToUse);
773 // $ldap->recursive_remove();
774 // FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
776 echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
777 <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
778 <input type='hidden' name='php_c_check' value='1'>
779 </form></div>";
781 echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
783 /* Print footer to have valid html */
784 echo "</body></html>";
786 $this->dispNewFreeze = false;
788 /* Postcreate */
790 /* Assign possible attributes */
791 $this->lock_type = $type;
792 $this->lock_name = $name;
793 $this->lock_dn = $baseToUse;
794 $this->postcreate();
797 /* Send daemon event to reload the fai release database
798 */
799 if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
800 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
801 if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
802 $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
803 $tmp = new $evt['CLASS_NAME']($this->config);
804 $tmp->set_type(TRIGGERED_EVENT);
805 $tmp->add_targets(array("GOSA"));
806 $o_queue = new gosaSupportDaemon();
807 if(!$o_queue->append($tmp)){
808 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
809 }
810 }
811 }else{
812 trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
813 msg_dialog::display(_("Fatal error"),
814 "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
815 FATAL_ERROR_DIALOG);
816 }
817 exit();
818 }
819 }
821 /****************
822 Display dialog to enter new Branch name
823 ****************/
825 /* Check if we have a post create method configured
826 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
827 */
828 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
829 if(($s_action == "branch_branch")||($this->dispNewBranch)){
830 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
831 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
832 }else{
833 $this->dispNewBranch=true;
834 $smarty->assign("iframe",false);
835 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
836 return($display);
837 }
838 }
839 }
842 /****************
843 Display dialog to enter new Freeze name
844 ****************/
846 /* Check if we have a post create method configured
847 * else skip this operation. (Skip:Button in the ui should be disabled in this case too)
848 */
849 if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
850 if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
851 if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
852 msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
853 }else{
854 $this->dispNewFreeze = true;
855 $smarty->assign("iframe",false);
856 $display .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
857 return($display);
858 }
859 }
860 }
863 /****************
864 Create a new object
865 ****************/
867 $types = array( "new_partition" => "FAIpartitionTable",
868 "new_script" => "FAIscript",
869 "new_hook" => "FAIhook",
870 "new_variable" => "FAIvariable",
871 "new_template" => "FAItemplate",
872 "new_package" => "FAIpackageList");
873 $types_i18n = array( "new_partition" => _("partition table"),
874 "new_script" => _("script"),
875 "new_hook" => _("hook"),
876 "new_variable" => _("variable"),
877 "new_template" => _("template"),
878 "new_package" => _("package list"));
880 if(isset($types[$s_action])){
882 $type_acl_mapping = array(
883 "FAIpartitionTable" => "faiPartitionTable",
884 "FAIpackageList" => "faiPackage",
885 "FAIscript" => "faiScript",
886 "FAIvariable" => "faiVariable",
887 "FAIhook" => "faiHook",
888 "FAIprofile" => "faiProfile",
889 "FAItemplate" => "faiTemplate");
891 $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$s_action]]);
892 if(preg_match("/c/",$acl)){
893 $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
894 $this->dialog->parent = &$this;
895 }else{
896 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
897 }
898 }
900 /* New Profile */
901 if($s_action == "new_profile"){
902 $this->dn = "new" ;
904 $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
905 if(preg_match("/c/",$acl)){
906 $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
907 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
908 $this->dialog->set_acl_base($this->base);
909 $this->dialog->parent = &$this;
911 $this->is_dialog = false;
912 }else{
913 msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
914 }
915 }
918 /****************
919 Get name from ask_class_name dialog
920 ****************/
922 if($s_action == "select_class_name_finished"){
923 $this->dialog->save_object();
924 if(count($this->dialog->check())!=0){
925 foreach($this->dialog->check() as $msg){
926 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
927 }
928 }elseif(isset($this->dialog->objectClass)){
929 $this->dn = "new" ;
930 $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
931 $name = $this->dialog->save();
933 if(class_exists($a_setup[0])){
934 $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
935 $this->dialog->set_acl_base($this->base);
936 $this->dialog->by_object[$a_setup[1]]->cn = $name;
937 $this->dialog->parent = &$this;
938 $this->is_dialog = true;
939 }
940 }
941 }
944 /****************
945 Cancel dialogs
946 ****************/
948 if(isset($_POST['edit_cancel'])){
949 $this->dialog=FALSE;
950 $this->is_dialog = false;
951 set_object_info();
952 $this->remove_lock();
953 }
956 /****************
957 Handle opsi dialogs
958 ****************/
960 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
961 $this->dialog = NULL;
962 }
963 if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
964 $this->dialog->save_object();
965 $op = $this->dialog->by_object['opsiProperties'];
966 $name = $op->get_product();
967 $cfg = $op->get_cfg();
968 $this->opsi->set_product_properties($name,$cfg);
969 if($this->opsi->is_error()){
970 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
971 }else{
972 $this->dialog = NULL;
973 }
974 }
975 if($this->dialog instanceof tabs_opsiProdConfig){
976 $this->dialog->save_object();
977 return($this->dialog->execute());
978 }
981 /****************
982 Save sub dialogs
983 ****************/
985 /* This check if the given tab could be saved
986 * If it was possible to save it, remove dialog object.
987 * If it wasn't possible, show errors and keep dialog.
988 */
989 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
990 $this->dialog->save_object();
991 $msgs= $this->dialog->check();
992 if(count($msgs)!=0){
993 foreach($msgs as $msg){
994 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
995 }
996 }else{
997 $this->dialog->save();
998 FAI::save_release_changes_now();
999 if (!isset($_POST['edit_apply'])){
1000 $this->remove_lock();
1001 $this->dialog=FALSE;
1002 $this->is_dialog=false;
1003 set_object_info();
1004 }else{
1006 /* Reinitialize tab */
1007 if($this->dialog instanceof tabs){
1008 $this->dialog->re_init();
1009 }
1010 }
1011 }
1012 }
1015 /****************
1016 Display currently open dialog
1017 ****************/
1019 /* If dialog is set, but $this->is_dialog==false, then
1020 * only the "abort" button is shown, this are dialogs that must not be saved.
1021 * If is_dialog == true, we are currently editing tab objects.
1022 * Here we need both, save and cancel
1023 */
1025 if(is_object($this->dialog)){
1026 $display .= $this->dialog->execute();
1027 /* Don't show buttons if tab dialog requests this */
1029 if(isset($this->dialog->current)){
1031 $obj = $this->dialog->by_object[$this->dialog->current];
1033 if(($this->dialog instanceOf tabs || $this->dialog instanceOf plugin) && $this->dialog->read_only == TRUE){
1034 $display.= "<p style=\"text-align:right\">
1035 <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1036 </p>";
1037 }elseif((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
1039 $display.= "<p style=\"text-align:right\">\n";
1040 if(!$this->no_save){
1041 $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1042 $display.= " \n";
1043 if ($this->dn != "new"){
1044 $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1045 $display.= " \n";
1046 }
1047 }
1048 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1049 $display.= "</p>";
1050 }elseif(!isset($this->dialog->current)){
1051 $display.= "<p style=\"text-align:right\">\n";
1052 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
1053 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1054 $display.= "</p>";
1055 }
1056 }else{
1057 $display.= "<p style=\"text-align:right\">\n";
1058 $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\"> ";
1059 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1060 $display.= "</p>";
1062 }
1063 return($display);
1064 }
1067 /****************
1068 Dialog display
1069 ****************/
1071 /* Check if there is a snapshot dialog open */
1072 $base = $this->fai_base;
1073 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1074 return($str);
1075 }
1077 /* Display dialog with system list */
1078 $this->reload();
1079 $this->DivListFai->parent = &$this;
1080 $this->DivListFai->execute();
1081 $this->DivListFai->setEntries($this->objects);
1082 return($this->DivListFai->Draw());
1083 }
1086 /* Return departments, that will be included within snapshot detection */
1087 function get_used_snapshot_bases()
1088 {
1089 $tmp = array();
1090 $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1091 foreach($types as $type){
1092 $tmp[] = get_ou($type).$this->fai_release;
1093 }
1094 return($tmp);
1095 }
1098 /* Get available branches for current base */
1099 function getBranches($base = false,$prefix = "")
1100 {
1101 $ret = array("/"=>$this->fai_base);
1102 $ldap = $this->config->get_ldap_link();
1103 if(!$base){
1104 $base = $this->fai_base;
1105 }
1106 $tmp = FAI::get_all_releases_from_base($base,true);
1107 foreach($tmp as $dn => $name){
1108 $ret[$name]=$dn;
1109 }
1110 ksort($ret);
1111 $ret = array_flip($ret);
1113 return ($ret);
1114 }
1117 function list_get_selected_items()
1118 {
1119 $ids = array();
1120 foreach($_POST as $name => $value){
1121 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1122 $id = preg_replace("/^item_selected_/","",$name);
1123 $ids[$id] = $id;
1124 }
1125 }
1126 return($ids);
1127 }
1130 /* reload list of objects */
1131 function reload()
1132 {
1133 /* Variable initialisation */
1134 $str = "";
1135 $Regex = $this->DivListFai->Regex;
1136 $this->objects = array();
1138 /* Get base */
1139 $base = $this->fai_base;
1140 if($this->fai_release != $this->fai_base){
1141 $br = $this->getBranches();
1142 if(isset($br[$this->fai_release])){
1143 $base = $this->fai_release;
1144 }else{
1145 $base = $this->fai_base;
1146 }
1147 }
1148 $this->base = $base;
1149 $this->set_acl_base($this->acl_base);
1151 $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1153 /* Create a new list of FAI object
1154 * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
1155 */
1156 $ObjectTypes = array(
1157 "FAIpartitionTable" => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions" ,"ACL" => "faiPartitionTable"),
1158 "FAIpackageList" => array("OU"=> get_ou('faiPackageRDN') , "CHKBOX"=>"ShowPackages" ,"ACL" => "faiPackage"),
1159 "FAIscript" => array("OU"=> get_ou('faiScriptRDN') , "CHKBOX"=>"ShowScripts" ,"ACL" => "faiScript"),
1160 "FAIvariable" => array("OU"=> get_ou('faiVariableRDN') , "CHKBOX"=>"ShowVariables" ,"ACL" => "faiVariable"),
1161 "FAIhook" => array("OU"=> get_ou('faiHookRDN') , "CHKBOX"=>"ShowHooks" ,"ACL" => "faiHook"),
1162 "FAIprofile" => array("OU"=> get_ou('faiProfileRDN') , "CHKBOX"=>"ShowProfiles" ,"ACL" => "faiProfile"),
1163 "FAItemplate" => array("OU"=> get_ou('faiTemplateRDN') , "CHKBOX"=>"ShowTemplates" ,"ACL" => "faiTemplate"));
1165 $filter = "";
1166 foreach($ObjectTypes as $key => $data){
1167 if($this->DivListFai->$data['CHKBOX']){
1168 $filter.= "(objectClass=".$key.")";
1169 }
1170 }
1171 $filter = "(&(|".$filter.")(cn=$Regex))";
1173 /* Get resolved release dependencies */
1174 $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1176 /* Ge listed ldap objects */
1177 $ldap = $this->config->get_ldap_link();
1178 $ldap->cd($this->config->current['BASE']);
1180 foreach($tmp as $entry){
1182 /* Get some more informations about the object */
1183 $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1184 $object = $ldap->fetch();
1186 /* Walk through possible types */
1187 foreach($ObjectTypes as $type => $rest){
1189 $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1191 if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1193 /* Prepare object */
1194 unset($object['objectClass']['count']);
1195 if(!isset($object['description'][0])){
1196 $object['description'][0]="";
1197 }
1199 /* Clean up object informations */
1200 $obj = array();
1201 $obj['cn'] = $object['cn'][0];
1202 $obj['dn'] = $object['dn'];
1203 $obj['acl'] = $acl;
1204 $obj['class'] = $rest ['ACL'];
1205 $obj['FAIstate'] = $entry['FAIstate'];
1206 $obj['description'] = $object['description'][0];
1207 $obj['objectClass'] = $object['objectClass'];
1209 $this->objects[$obj['cn']][$type] = $obj;
1210 $this->objects[$obj['cn']][$type]['type']=$type;
1211 }
1212 }
1213 }
1215 /* Append opsi objects, if opsi is available and if we are on the fai_base
1216 */
1217 if($this->opsi instanceof opsi && $this->opsi->enabled()){
1218 $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1219 if(preg_match("/r/",$opsi_acl)){
1220 $err = FALSE;
1221 if(!$err && $this->DivListFai->ShowOpsiNetboot){
1222 $n_pro = $this->opsi->get_netboot_products();
1223 $err |= $this->opsi->is_error();
1224 foreach($n_pro as $name => $data){
1225 $entry = array(
1226 "cn" => $name,
1227 "description" => $data['DESC'],
1228 "type" => "opsi_netboot");
1229 $this->objects[$name]['opsi_netboot'] = $entry;
1230 }
1231 }
1232 if(!$err && $this->DivListFai->ShowOpsiLocal){
1233 $l_pro = $this->opsi->get_local_products();
1234 $err |= $this->opsi->is_error();
1235 foreach($l_pro as $name => $data){
1236 $entry = array("cn" => $name,
1237 "description" => $data['DESC'],
1238 "type" => "opsi_local");
1239 $this->objects[$name]["opsi_local"] = $entry;
1240 }
1241 }
1242 if($err){
1243 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1244 }
1245 }
1246 }
1248 uksort($this->objects, 'strnatcasecmp');
1249 reset ($this->objects);
1250 $this->objects = array_values($this->objects);
1251 }
1253 function remove_lock()
1254 {
1255 if (isset($this->dn) && !empty($this->dn)){
1256 del_lock ($this->dn);
1257 }
1258 if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1259 del_lock ($this->dns);
1260 }
1261 }
1263 function get_type($array){
1264 if(!isset($array['objectClass'])) return(array());
1265 if(in_array("FAIpartitionTable",$array['objectClass'])){
1266 return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1267 }
1268 if(in_array("FAIscript",$array['objectClass'])){
1269 return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1270 }
1271 if(in_array("FAItemplate",$array['objectClass'])){
1272 return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1273 }
1274 if(in_array("FAIhook",$array['objectClass'])){
1275 return(array("tabsHook","faiHook","FAIHOOKTABS"));
1276 }
1277 if(in_array("FAIvariable",$array['objectClass'])){
1278 return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1279 }
1280 if(in_array("FAIprofile",$array['objectClass'])){
1281 return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1282 }
1284 if(in_array("FAIpackageList",$array['objectClass'])){
1285 return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1286 }
1287 return(array());
1288 }
1290 function CheckNewBranchName($name,$base)
1291 {
1292 $f = $this->fai_release;
1293 if($name == ""){
1294 return(false);
1295 }elseif(in_array($name,$this->getBranches($f))) {
1296 return(false);
1297 }elseif(tests::is_department_name_reserved($name,$base)){
1298 return(false);
1299 }
1300 return(true);
1301 }
1303 function save_object()
1304 {
1305 $this->DivListFai->save_object();
1307 /* Get posted release */
1308 $r_releases = array_flip($this->getBranches());
1309 if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1311 /* Ensure that we have a valid release selected */
1312 if(!isset($r_releases[get_post('fai_release')])){
1313 msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1314 $_POST = array();
1315 $plug =$_GET['plug'];
1316 $_GET = array("plug" => $plug);
1317 $this->fai_release = $this->fai_base;
1318 }else{
1319 $this->fai_release = $r_releases[get_post('fai_release')];
1320 }
1322 $fai_filter = session::get("fai_filter");
1323 $fai_filter['fai_release'] = $this->fai_release;
1324 session::set("fai_filter",$fai_filter);
1325 }
1327 if(is_object($this->CopyPasteHandler)){
1328 $this->CopyPasteHandler->save_object();
1329 }
1330 }
1333 function copyPasteHandling_from_queue($s_action,$i_entryID,$s_entryType)
1334 {
1335 /* Check if Copy & Paste is disabled */
1336 if(!is_object($this->CopyPasteHandler)){
1337 return("");
1338 }
1340 $ui = get_userinfo();
1342 // Copy a single entry
1343 if($s_action == "copy"){
1344 $entry = $this->objects[$i_entryID][$s_entryType];
1345 $this->CopyPasteHandler->cleanup_queue();
1346 $a_setup = $this->get_type($entry);
1347 $dn = $entry['dn'];
1348 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1349 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");
1350 }
1351 }
1353 // cut a single entry
1354 if($s_action == "cut"){
1355 $entry = $this->objects[$i_entryID][$s_entryType];
1356 $this->CopyPasteHandler->cleanup_queue();
1357 $a_setup = $this->get_type($entry);
1358 $dn = $entry['dn'];
1359 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1360 $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");
1361 }
1362 }
1364 /* Add a entries from the group selection to queue */
1365 if($this->dialog instanceOf faiGroupHandle && !$this->dialog->is_open()){
1367 if(in_array($this->dialog->get_mode(),array("copy"))){
1369 /* Cleanup object queue */
1370 $this->CopyPasteHandler->cleanup_queue();
1371 $group = $this->dialog->get_selected();
1372 foreach($group as $entry){
1373 $a_setup = $this->get_type($entry);
1374 $dn = $entry['dn'];
1375 if($ui->is_copyable($dn,"fai",$a_setup[1])){
1376 $this->CopyPasteHandler->add_to_queue($dn,$this->dialog->get_mode(),$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1377 }
1378 }
1379 $this->dialog = FALSE;
1380 }
1381 }
1383 /* Add entries to queue */
1384 if($s_action == "copy_multiple"){
1386 /* Cleanup object queue */
1387 $this->CopyPasteHandler->cleanup_queue();
1389 /* Add new entries to CP queue */
1390 foreach($this->list_get_selected_items() as $id){
1391 $group = $this->objects[$id];
1392 foreach($group as $entry){
1393 $a_setup = $this->get_type($entry);
1394 $dn = $entry['dn'];
1396 if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1397 $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1398 }
1399 }
1400 }
1401 }
1403 /* Start pasting entries */
1404 if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1405 $this->start_pasting_copied_objects = TRUE;
1406 }
1408 /* Return C&P dialog */
1409 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1411 /* Get dialog */
1412 $this->CopyPasteHandler->SetVar("parent",$this);
1413 $data = $this->CopyPasteHandler->execute();
1415 FAI::save_release_changes_now();
1417 /* Return dialog data */
1418 if(!empty($data)){
1419 return($data);
1420 }
1421 }
1423 /* Automatically disable status for pasting */
1424 if(!$this->CopyPasteHandler->entries_queued()){
1425 $this->start_pasting_copied_objects = FALSE;
1426 }
1427 return("");
1428 }
1431 /* Check if the given FAI class is used in this release
1432 */
1433 static function check_class_name($oc,$name,$dn)
1434 {
1435 $base = FAI::get_release_dn($dn);
1437 if($oc == "FAIprofile"){
1438 $f = "";
1439 $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1440 foreach($ocs as $oc){
1441 $f .= "(objectClass=".$oc.")";
1442 }
1443 $res = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);
1444 }else{
1445 $res = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1446 }
1447 $delete = array();
1448 $used = array();
1449 foreach($res as $object){
1450 $used[$object['cn'][0]]= $object['cn'][0];
1451 }
1452 return($used);
1453 }
1456 /* Return plugin informations for acl handling */
1457 static function plInfo()
1458 {
1459 return (array(
1460 "plShortName" => _("FAI releases"),
1461 "plDescription" => _("FAI release management"),
1462 "plSelfModify" => FALSE,
1463 "plDepends" => array(),
1464 "plPriority" => 0,
1465 "plSection" => array("administration"),
1466 "plCategory" => array("fai"=> array("description" => _("FAI"),
1467 "objectClass" => "FAIclass")),
1468 "plProvidedAcls"=> array()));
1469 }
1470 }
1471 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1472 ?>