Code

removed debug output
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiManagement.inc
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;
53   var $no_save;
54   var $acl_base     ="";
55   var $fai_base     ="";
56   var $fai_release  ="";
58   var $acl_module = array("fai");
60   var $opsi = NULL;
62         /* construction/reconstruction 
63          */
64         function faiManagement (&$config, $ui)
65         {
66                 /* Set defaults */
67                 $this->dn                       = "";
68                 $this->config   = $config;
69                 $this->ui                       = $ui;  
71     /* Check if the opsi plugin is installed.
72      */
73     if(class_available("opsi")){
74       $this->opsi = new opsi($this->config);;
75     }
76     
77     /* Creat dialog object */
78     $this->DivListFai = new divListFai($this->config,$this);
80     /* Copy & Paste handler */
81     if ($this->config->boolValueIsTrue("main", "copyPaste")){
82       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
83     }
85     /* Set default release 
86      */
87     $this->acl_base = $this->config->current['BASE'];
88     $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
90     if(!session::is_set("fai_filter")){
92       /* Set intial release */
93       $rel = $config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
94       $rels = array_flip($this->getBranches());
95       if(isset($rels[$rel])){
96         $rel = $rels[$rel];
97       }else{
98         $rel = $this->fai_base;
99       }
101       session::set("fai_filter",array("fai_release" => $rel));
102     }
104     $fai_filter = session::get("fai_filter");
105     $this->fai_release = $fai_filter['fai_release'];
106         }
108         function execute()
109         {
110     /* Call parent execute */
111     plugin::execute();
114     /* Initialise vars and smarty */
115                 $smarty         = get_smarty();
116                 $smarty->assign("BranchName","");
117     
118                 $display        = "";
119     $s_action   = "";
120                 $s_entry        = "";
121     $no_save = FALSE;   // hide Apply / Save buttons
122     
123     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
124     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/"));
127     /****************
128       Handle posts 
129      ****************/
131                 /* Check ImageButton posts
132                  * Create new tab ich new_xx is posted
133                  */
134     $posts = array( "/remove_branch/"=>"remove_branch",    "/branch_branch/"=>"branch_branch",
135                     "/freeze_branch/"=>"freeze_branch",    "/create_partition/i"=>"new_partition",
136                     "/create_script/i"=>"new_script",      "/create_hook/i"=>"new_hook",
137                     "/create_variable/i"=>"new_variable",  "/create_template/i"=>"new_template",
138                     "/create_package/i"=>"new_package",    "/create_profile/i"=>"new_profile",
139                     "/edit_continue/"=>"select_class_name_finished",
140                     "/^multiple_copy_fai/" => "copy_multiple", 
141                     "/^multiple_cut_fai/" => "cut_multiple", 
142                     "/^copy/" => "copy",
143                     "/^remove_multiple_fai_objects/" => "del_multiple");
145                 foreach($_POST as $name => $value){
146       foreach($posts as $reg => $act ){
147         if(preg_match($reg,$name)){
148           $s_action = $act;
149           $s_entry = ltrim(preg_replace($reg,"",$name),"_");
150           $s_entry = preg_replace("/_.*$/","",$s_entry);
151           break;
152         }
153       }
154                         if(preg_match("/^entry_edit_.*/",$name)){
155                                 $s_entry = preg_replace("/^entry_edit_/","",$name);
156                                 $s_entry = preg_replace("/_.*$/","",$s_entry);
157         $s_action = "edit";
158         break;
159       }elseif(preg_match("/^entry_freeze_edit_.*/",$name)){
160         $s_entry = preg_replace("/^entry_freeze_edit_/","",$name);
161         $s_entry = preg_replace("/_.*$/","",$s_entry);
162         $s_action = "edit";
163         $no_save = TRUE;
164         break;
165       }elseif(preg_match("/^entry_delete_.*/",$name)){
166         $s_entry = preg_replace("/^entry_delete_/","",$name);
167         $s_entry = preg_replace("/_.*$/","",$s_entry);
168         $s_action = "delete";
169         break;
170       }
172       /* Get posts from opsi onjects 
173        */  
174       if($this->opsi instanceof opsi && $this->opsi->enabled()){
175         if(preg_match("/^entry_opsi_edit_/",$name)){
176           $s_entry = preg_replace("/^entry_opsi_edit_([0-9]*).*$/","\\1",$name);
177           $s_action = "opsi_edit";
178           break;
179         }
180       }
181     }
183     /* Get posts from opsi objects 
184      */ 
185                 if($this->opsi instanceof opsi && $this->opsi->enabled() && isset($_GET['edit_opsi_entry'])){
186                         $s_entry = $_GET['edit_opsi_entry'];
187                         $s_action = "opsi_edit";
188                 }
190                 if(isset($_GET['edit_entry'])){
191                         $s_entry = $_GET['edit_entry'];
192                         $s_action = "edit";
193                 }
195                 if(isset($_GET['edit_freeze_entry'])){
196                         $s_entry = $_GET['edit_freeze_entry'];
197                         $s_action = "edit";
198       $no_save = TRUE;
199                 }
201     if(isset($_GET['act']) && $_GET['act'] == "freeze_branch"){
202       $s_action = "freeze_branch";
203     }
204     if(isset($_GET['act']) && $_GET['act'] == "branch_branch"){
205       $s_action = "branch_branch";
206     }
207     if(isset($_GET['act']) && $_GET['act'] == "remove_branch"){
208       $s_action = "remove_branch";
209     }
210     
211     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
212       $this->dispNewBranch = false;
213       $this->dispNewFreeze = false;
214     }
217     $type_acl_mapping = array(
218         "FAIpartitionTable"  => "faiPartitionTable", 
219         "FAIpackageList"     => "faiPackage",
220         "FAIscript"          => "faiScript",
221         "FAIvariable"        => "faiVariable",
222         "FAIhook"            => "faiHook",
223         "FAIprofile"         => "faiProfile",
224         "FAItemplate"        => "faiTemplate");
227     /* handle C&P from layers menu */
228     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
229       $s_action = "copy_multiple";
230     }
231     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
232       $s_action = "cut_multiple";
233     }
234     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
235       $s_action = "editPaste";
236     }
238     /* Create options */
239     if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
240       $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
241       $s_entry  = preg_replace("/^Create_/","",$_POST['menu_action']);
242     }
244     /* handle remove from layers menu */
245     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
246       $s_action = "del_multiple";
247     }
250     if(!empty($s_action)){
251       $this->no_save = $no_save;
252     }
254     /********************
255       Copy & Paste
256      ********************/
258     /* Display the copy & paste dialog, if it is currently open */
259     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
260     if($ret){
261       return($ret);
262     }
265     /*******************
266       Opsi extension 
267      *******************/
269     if($this->opsi instanceof opsi && $this->opsi->enabled()){
270       if($s_action == "opsi_edit"){
271         $name = $this->objects[$s_entry]['cn'];
272         $cfg = $this->opsi->get_product_properties($name);
273         $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
274         if(isset($this->dialog->by_object['opsiProperties'])){
275           $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
276           $this->dialog->by_object['opsiProperties']->set_product($name);
277         }else{
278           trigger_error("Unknown tab, please check config.");
279         }
280       }
281       if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
282         $this->dialog = NULL;
283       }
284       if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
285         $this->dialog->save_object();
286         $op    = $this->dialog->by_object['opsiProperties'];
287         $name  = $op->get_product();
288         $cfg   = $op->get_cfg();
289         $this->opsi->set_product_properties($name,$cfg); 
290         if($this->opsi->is_error()){
291           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
292         }else{
293           $this->dialog = NULL;
294         }
295       }
296       if($this->dialog instanceof tabs_opsiProdConfig){
297         $this->dialog->save_object();
298         return($this->dialog->execute());
299       }
300     }
303     /****************
304       Delete confirme dialog 
305      ****************/
307                 if ($s_action=="delete"){
309       /* Get 'dn' from posted termlinst */
310       $this->dn= $this->objects[$s_entry]['dn'];
312                         /* Load permissions for selected 'dn' and check if
313                            we're allowed to remove this 'dn' */
314       $acl  = $this->ui->get_permissions($this->dn,"fai/".$type_acl_mapping[$this->objects[$s_entry]['type']]);
315       if(preg_match("/d/",$acl)){
317                                 /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
318                                 if (($user= get_lock($this->dn)) != ""){
319                                         return(gen_locked_message ($user, $this->dn));
320                                 }
322                                 /* Lock the current entry, so nobody will edit it during deletion */
323                                 add_lock ($this->dn, $this->ui->dn);
324                                 $smarty->assign("warning",msgPool::deleteInfo(LDAP::fix($this->dn),_("FAI object")));
325         $smarty->assign("multiple", false);
326                                 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
327                         } else {
329                                 /* Obviously the user isn't allowed to delete. Show message and clean session. */
330         msg_dialog::display(_("Permission error"), msgPool::permDelete(),ERROR_DIALOG);
331                         }
332                 }
335     /********************
336       Delete MULTIPLE entries requested, display confirm dialog
337      ********************/
339     if ($s_action=="del_multiple"){
340       $this->dns = array();
341       $ids = $this->list_get_selected_items();
343       if(count($ids)){
345         $errors = "";
346         foreach($ids as $id){
347           $dn = $this->objects[$id]['dn'];
348           $cn = $this->objects[$id]['cn'];
349           if(!preg_match('/^freeze/', $this->objects[$id]['FAIstate'])){
350             $this->dns[$id] = $dn;
351           }else{
352             $errors .= $cn.", ";
353           }
354         }
355         if ($user= get_multiple_locks($this->dns)){
356           return(gen_locked_message($user,$this->dns));
357         }
359         if($errors != ""){
360           msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
361             "<br><br>".trim($errors,", ")),INFO_DIALOG);
362         }
364         if(count($this->dns)){
366           $dns_names = array();
367           foreach($this->dns as $dn){
368             add_lock ($dn, $this->ui->dn);
369             $dns_names[] = LDAP::fix($dn);
370           }
372           /* Lock the current entry, so nobody will edit it during deletion */
373                                   $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
374           $smarty->assign("multiple", true);
375           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
376         }
377       }
378     }
381     /********************
382       Delete MULTIPLE entries confirmed
383      ********************/
385     /* Confirmation for deletion has been passed. Users should be deleted. */
386     if (isset($_POST['delete_multiple_fai_object_confirm'])){
388       /* Find out more about the object type */
389       $ldap   = $this->config->get_ldap_link();
391       /* Remove user by user and check acls before removeing them */
392       foreach($this->dns as $key => $dn){
394         $ldap->cat($dn, array('objectClass'));
395         $attrs  = $ldap->fetch();
396         $type   = $this->get_type($attrs);
398         $acl  = $this->ui->get_permissions($dn,"fai/".$type[1]);
399         if(preg_match("/d/",$acl)){
401           $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
402           $this->dialog->parent = &$this;
403           $this->dialog->set_acl_base($dn);
404           $this->dialog->by_object[$type[1]]->remove_from_parent ();
405           unset ($this->dialog);
406           $this->dialog= FALSE;
407           $to_del = FAI::clean_up_releases($dn);
408           FAI::save_release_changes_now();
410           foreach($to_del as $dn){
411             $ldap->rmdir_recursive($dn);
412           }
414         } else {
416           /* Normally this shouldn't be reached, send some extra
417              logs to notify the administrator */
418           msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
419           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
420         }
421       }
423       /* Remove lock file after successfull deletion */
424       $this->remove_lock();
425       $this->dns = array();
426     }
429     /********************
430       Delete MULTIPLE entries Canceled
431      ********************/
433     /* Remove lock */
434     if(isset($_POST['delete_multiple_fai_object_cancel'])){
435       $this->dns = array();
436       $this->remove_lock();
437     }
440     /****************
441       Delete aborted  
442      ****************/
444                 /* Delete canceled? */
445                 if (isset($_POST['delete_cancel'])){
446       $this->remove_lock();
447                 }
450     /****************
451       Delete confirmed 
452      ****************/
454                 /* Deletion was confirmed, so delete this entry
455      */
456     if (isset($_POST['delete_terminal_confirm'])){
458       /* Some nice guy may send this as POST, so we've to check
459          for the permissions again. */
461       /* Find out more about the object type */
462       $ldap       = $this->config->get_ldap_link();
463       $ldap->cat($this->dn, array('objectClass'));
464       if($ldap->count()){
465         $attrs  = $ldap->fetch();
466         $type     = $this->get_type($attrs);                    
468         $acl  = $this->ui->get_permissions($this->dn,"fai/".$type[1]);
469         if(preg_match("/d/",$acl)){
471           $this->dialog = new $type[0]($this->config,   $this->config->data['TABS'][$type[2]], $this->dn,"fai");
472           $this->dialog->set_acl_base($this->dn);
473           $this->dialog->parent = &$this;
474           $this->dialog->by_object[$type[1]]->remove_from_parent ();
475           unset ($this->dialog);
476           $this->dialog= FALSE;
477           $to_del = FAI::clean_up_releases($this->dn);
478           FAI::save_release_changes_now();
480           foreach($to_del as $dn){
481             $ldap->rmdir_recursive($dn);
482           }
484         } else {
486           /* Normally this shouldn't be reached, send some extra
487              logs to notify the administrator */
488           msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
489           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
490         }
492       }else{
493         msg_dialog::display(_("Error"), sprintf(_("Cannot delete '%s': object does not exist!"), $this->dn) , ERROR_DIALOG);
494       }
496       /* Remove lock file after successfull deletion */
497       $this->remove_lock();
498     }
501     /****************
502       Edit entry 
503      ****************/
505                 if(($s_action == "edit") && (!isset($this->dialog->config))){
506                         $entry    = $this->objects[$s_entry];
507                         $a_setup  = $this->get_type($entry);
508                         $this->dn = $entry['dn'];
510                         /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
511                         if (($user= get_lock($this->dn)) != ""){
512                                 return(gen_locked_message ($user, $this->dn));
513                         }
514                         add_lock ($this->dn, $this->ui->dn);
516                         $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
517       $this->dialog->parent = &$this;
518       $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
519       $this->dialog->set_acl_base($this->dn);
520                         $this->is_dialog  = true;
521                         session::set('objectinfo',$this->dn);
522                 }
525     /*  Branch handling 
526         09.01.2006
527     */
529     /****************
530       Remove branch
531      ****************/
533     /* Remove branch 
534      */
535     if($s_action == "remove_branch"){
536       $base= $this->fai_release;
538       /* Check if we have a post remove method configured
539        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
540        */
541       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
542         /* Load permissions for selected 'dn' and check if
543            we're allowed to remove this 'dn' */
544         if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
545           $smarty->assign("release_hidden",base64_encode($this->fai_release));
546           $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
547           return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
548         } else {
549           msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
550         }
551       }
552     }
554     
555     /****************
556       Remove branch confirmed
557      ****************/
559     if(isset($_POST['delete_branch_confirm'])){
561       /* Check if we have a post remove method configured
562        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
563        */
564       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
566         if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
567           msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
568         }else{
570           $bb =  $this->fai_release;
571           if(!isset($ldap)){
572             $ldap = $this->config->get_ldap_link();
573           }
575           $br = $this->getBranches();
577           if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
578             $name = $br[$bb];
580             $ldap->cd($bb);
581             $ldap->recursive_remove();
582             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
583             $ldap->recursive_remove();
584             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
585             $ldap->recursive_remove();
587             /* Search for all groups with configured application menus.
588               - First search all groups, to ensure that we only remove entries form whithin groups. 
589               - The search für menu configuration for the specified release and collect all those dns.
590               - Remove entries
591              */
592             $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
593             $ldap->cd($this->config->current['BASE']);
594             $ldap->search("(objectClass=posixGroup)",array("dn"));
595           
596             /* Collect all group dns 
597              */
598             $groups = array();
599             while($attrs = $ldap->fetch()){
600               $groups[] = $attrs['dn'];
601             }
603             /* Collect all group menu release dns that match the release we have removed 
604              */
605             $dns = array();
606             foreach($groups as $dn){
607               $ldap->cd($dn);
608               $ldap->search("(objectClass=FAIbranch)",array("dn"));
609               while($attrs = $ldap->fetch()){
610                 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
611                   $dns[] = $attrs['dn'];
612                 }
613               }
614             }
615             
616             /* Finally remove collected release dns 
617              */
618             foreach($dns as $dn){
619               $ldap->cd($dn);
620               $ldap->recursive_remove();
621             }
623             /* Post remove */
624             $this->fai_release = $this->fai_base;
625             $this->lock_name   = $name;
626             $this->lock_dn     = $bb;
627             $this->postremove();
629             $fai_filter = session::get("fai_filter");
630             $fai_filter['fai_release'] = $this->fai_release;
631             session::set("fai_filter",$fai_filter);
633             new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
634           }
635         }
636       }
637     }
640     /****************
641       Create a new branch "insert Name"
642      ****************/
644     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
645       session::set('LASTPOST',$_POST);
647       if($this->dispNewBranch){
648         $type = "branch";
649       }else{
650         $type = "freeze";
651       }
653       /* Check branch name */
654       $name = $_POST['BranchName'];
655       $is_ok = true;
656       $smarty->assign("BranchName",$name);
657       $base= $this->fai_base;
659       /* Check used characters */
660       if(!preg_match("/^[0-9a-z\.]*$/",$name)){
661         msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
662         $is_ok = false;
663       }
665       /* Check if this name is already in use */
666       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
667         msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
668         $is_ok = false;
669       }
671       if($is_ok){
673         if(session::is_set('LASTPOST')){
674           $LASTPOST = session::get('LASTPOST');
675         }else{
676           $LASTPOST = array();
677         }
678         $LASTPOST['base'] = $base;
679         $LASTPOST['type'] = $type;
680         session::set('LASTPOST',$LASTPOST);
681         $smarty->assign("iframe", true);
682         $smarty->assign("plugID", $_GET['plug']);
683         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
684         return($display);
685       }
686     }
689     /****************
690       Create a new branch 
691      ****************/
693     if(isset($_GET['PerformBranch'])){
694     
695       if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
696         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
697       }else{
699         /* In order to see error messages we have to reset the error handler.
700             Due to the exit(); 
701          */
702         restore_error_handler();
704         /* Create it know */
705         $this->dispNewBranch = false;
706         $this->dispNewFreeze = false;
708         $LASTPOST = session::get('LASTPOST');
709         $base = $LASTPOST['base'];
710         $_POST  = session::get('LASTPOST');      
711         $name = $_POST['BranchName'];
713         $type = $LASTPOST['type'];
714         $ldap = $this->config->get_ldap_link();
716         $baseToUse = $base;
717         if($this->fai_release !=  $this->fai_base){
718           $baseToUse = $this->fai_release;
719         }
721         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
723         $CurrentReleases  = $this->getBranches();
724         $NewReleaseName   = $name;
725         if(isset($CurrentReleases[$this->fai_release])) {
726           if($this->fai_release != $this->fai_base){
727             $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
728             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
729           }else{
730             $NewReleaseName   = $name;
731           }
732         }
734         $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse); 
735         $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ; 
737         $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse); 
738         $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ; 
740         /* Check if source depeartments exist */
741         foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
742           $ldap->cd($this->config->current['BASE']);
743           $ldap->cat($dep);
744           if(!$ldap->count()){
745             $ldap->create_missing_trees($dep);
746           }
747         }
749         /* Print header to have styles included */
750         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
751           <html>
752           <head>
753           <title></title>
754           <style type="text/css">@import url("themes/default/style.css");</style>
755           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
756           </head>
757           <body style="background: none;margin:3px;color:black">
758           ';
760         new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
762         /* Duplicate group application releases 
763          */
764         FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
766         /* Duplicate applications 
767          */
768         $ldap->cat($appsrc,array("dn")) ;
769         if($ldap->count()){
770           $ldap->cd ($appdst);
771           $ldap->recursive_remove();
772           FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
773         }
775         /* Duplicate mime types 
776          */
777         $ldap->cat($mimesrc,array("dn")) ;
778         if($ldap->count()){
779           $ldap->cd ($mimedst);
780           $ldap->recursive_remove();
781           FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
782         }
784         $attr = array();
785         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
786         $attr['ou']       = $name;
787         $attr['FAIstate'] = $type;
788         $ldap->cd($this->config->current['BASE']);
789         $ldap->cd("ou=".$name.",".$baseToUse);
790         $ldap->cat("ou=".$name.",".$baseToUse);
791         if($ldap->count()){
792           $ldap->modify($attr);
793         }else{
794           $ldap->add($attr);
795         }
797         /* Duplicate fai objects 
798          */
799         //      $ldap->cd ("ou=".$name.",".$baseToUse);
800         //      $ldap->recursive_remove();
801         //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
803         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
804           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
805           </form></div>";
807         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
809         /* Print footer to have valid html */
810         echo "</body></html>";
812         $this->dispNewFreeze = false; 
814         /* Postcreate */ 
816         /* Assign possible attributes */
817         $this->lock_type  = $type; 
818         $this->lock_name  = $name; 
819         $this->lock_dn    = $baseToUse;
820         $this->postcreate();
823         /* Send daemon event to reload the fai release database 
824          */
825         if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
826           $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
827           if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
828             $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
829             $tmp = new $evt['CLASS_NAME']($this->config);
830             $tmp->set_type(TRIGGERED_EVENT);
831             $tmp->add_targets(array("GOSA"));
832             $o_queue = new gosaSupportDaemon();
833             if(!$o_queue->append($tmp)){
834               msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
835             }
836           }
837         }else{  
838           trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
839           msg_dialog::display(_("Fatal error"),
840               "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
841               FATAL_ERROR_DIALOG);
842         }
843         exit();
844       }
845     }
847     /****************
848       Display dialog to enter new Branch name
849      ****************/
851     /* Check if we have a post create method configured
852      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
853      */
854     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
855       if(($s_action == "branch_branch")||($this->dispNewBranch)){
856         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
857           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
858         }else{
859           $this->dispNewBranch=true;
860           $smarty->assign("iframe",false);
861           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
862           return($display);
863         }
864       } 
865     }
867  
868     /****************
869       Display dialog to enter new Freeze name
870      ****************/
872     /* Check if we have a post create method configured
873      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
874      */
875     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
876       if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
877         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
878           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
879         }else{
880           $this->dispNewFreeze = true;
881           $smarty->assign("iframe",false);
882           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
883           return($display);
884         }
885       }
886     }
889     /****************
890       Create a new object 
891      ****************/
893     $types = array( "new_partition"     =>  "FAIpartitionTable",
894                     "new_script"        =>  "FAIscript",
895                     "new_hook"          =>  "FAIhook",
896                     "new_variable"      =>  "FAIvariable",
897                     "new_template"      =>  "FAItemplate",
898                     "new_package"       =>  "FAIpackageList");
899     $types_i18n = array( "new_partition"     =>  _("partition table"),
900                     "new_script"        =>  _("script"),
901                     "new_hook"          =>  _("hook"),
902                     "new_variable"      =>  _("variable"),
903                     "new_template"      =>  _("template"),
904                     "new_package"       =>  _("package list"));
906     if(isset($types[$s_action])){
907       $acl = $this->ui->get_permissions($this->fai_base,"fai/".$type_acl_mapping[$types[$s_action]]);
908       if(preg_match("/c/",$acl)){
909         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
910         $this->dialog->parent = &$this;
911       }else{
912         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
913       }
914     }
916     /* New Profile */
917     if($s_action == "new_profile"){
918       $this->dn = "new" ;
920       $acl = $this->ui->get_permissions($this->fai_base,"fai/faiProfile");
921       if(preg_match("/c/",$acl)){
922         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
923         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
924         $this->dialog->set_acl_base($this->base);
925         $this->dialog->parent = &$this;
927         $this->is_dialog = false;
928       }else{
929         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
930       }
931     }
934     /****************
935       Get from ask class name dialog 
936      ****************/
938     if($s_action == "select_class_name_finished"){
939       $this->dialog->save_object();
940       if(count($this->dialog->check())!=0){
941         foreach($this->dialog->check() as $msg){
942           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
943         }               
944       }elseif(isset($this->dialog->objectClass)){
945         $this->dn = "new" ;
946         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
947         $name = $this->dialog->save();
949         if(class_exists($a_setup[0])){
950           $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
951           $this->dialog->set_acl_base($this->base);
952           $this->dialog->by_object[$a_setup[1]]->cn = $name;
953           $this->dialog->parent = &$this;
954           $this->is_dialog = true;
955         }
956       }         
957     }   
960     /****************
961      Cancel dialogs 
962      ****************/
964                 if(isset($_POST['edit_cancel'])){
965                         $this->dialog=FALSE;
966                         $this->is_dialog = false;
967                         session::un_set('objectinfo');
968       $this->remove_lock();
969                 }
972     /****************
973       Save sub dialogs 
974      ****************/
976                 /* This check if the given tab could be saved 
977                  * If it was possible to save it, remove dialog object. 
978                  * If it wasn't possible, show errors and keep dialog.
979                  */
980                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
981                         $this->dialog->save_object();
982       $msgs= $this->dialog->check();
983                         if(count($msgs)!=0){
984                                 foreach($msgs as $msg){
985           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
986                                 }
987                         }else{
988                                 $this->dialog->save();
989         FAI::save_release_changes_now();
990         if (!isset($_POST['edit_apply'])){
991           $this->remove_lock();
992           $this->dialog=FALSE;
993           $this->is_dialog=false;
994           session::un_set('objectinfo');
995         }else{
997           /* Reinitialize tab */
998           if($this->dialog instanceof tabs){
999             $this->dialog->re_init();
1000           }
1001         }
1002                         }
1003                 }
1006     /****************
1007       Display currently open dialog 
1008      ****************/
1010                 /* If dialog is set, but $this->is_dialog==false, then 
1011                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
1012                  * If is_dialog == true, we are currently editing tab objects.
1013                  *  Here we need both, save and cancel
1014                  */ 
1016                 if(is_object($this->dialog)){
1017                         $display .= $this->dialog->execute();
1018                         /* Don't show buttons if tab dialog requests this */
1020       if(isset($this->dialog->current)){
1022         $obj = $this->dialog->by_object[$this->dialog->current];
1024         if((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
1026           $display.= "<p style=\"text-align:right\">\n";
1027           if(!$this->no_save){
1028             $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1029             $display.= "&nbsp;\n";
1030             if ($this->dn != "new"){
1031               $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1032               $display.= "&nbsp;\n";
1033             }
1034           }
1035           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1036           $display.= "</p>";
1037         }elseif(!isset($this->dialog->current)){
1038           $display.= "<p style=\"text-align:right\">\n";
1039           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1040           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1041           $display.= "</p>";
1042         }
1043       }else{
1044         $display.= "<p style=\"text-align:right\">\n";
1045         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1046         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1047         $display.= "</p>";
1049       }
1050       return($display);
1051                 }
1052                 
1054     /****************
1055       Dialog display
1056      ****************/
1058     /* Check if there is a snapshot dialog open */
1059     $base = $this->fai_base;
1060     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1061       return($str);
1062     }
1064     /* Display dialog with system list */
1065     $this->reload();
1066     $this->DivListFai->parent = &$this;
1067     $this->DivListFai->execute();
1068     $this->DivListFai->setEntries($this->objects);
1069     return($this->DivListFai->Draw());
1070         }
1073   /* Return departments, that will be included within snapshot detection */
1074   function get_used_snapshot_bases()
1075   {
1076     $tmp = array();
1077     $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1078     foreach($types as $type){
1079       $tmp[] = get_ou($type).$this->fai_release;
1080     }
1081     return($tmp);
1082   }
1085   /* Get available branches for current base */
1086   function getBranches($base = false,$prefix = "")
1087   {
1088     $ret = array("/"=>$this->fai_base);
1089     $ldap = $this->config->get_ldap_link();
1090     if(!$base){
1091       $base = $this->fai_base;
1092     }
1093     $tmp = FAI::get_all_releases_from_base($base,true);
1094     foreach($tmp as $dn => $name){
1095       $ret[$name]=$dn;
1096     }
1097     ksort($ret);
1098     $ret = array_flip($ret);
1100     return ($ret);
1101   }
1102   
1104   function list_get_selected_items()
1105   {
1106     $ids = array();
1107     foreach($_POST as $name => $value){
1108       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1109         $id   = preg_replace("/^item_selected_/","",$name);
1110         $ids[$id] = $id;
1111       }
1112     }
1113     return($ids);
1114   }
1117   /* reload list of objects */
1118   function reload()
1119   {
1120     /* Variable initialisation */
1121     $str            = "";
1122     $Regex          = $this->DivListFai->Regex;
1123     $this->objects  = array();
1125     /* Get base */
1126     $base = $this->fai_base;
1127     if($this->fai_release != $this->fai_base){
1128       $br = $this->getBranches();
1129       if(isset($br[$this->fai_release])){
1130         $base = $this->fai_release;
1131       }else{
1132         $base = $this->fai_base;
1133       }
1134     }
1135     $this->base = $base;
1136     $this->set_acl_base($this->acl_base);
1138     $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1140     /* Create a new list of FAI object 
1141      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
1142      */
1143     $ObjectTypes = array(
1144         "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
1145         "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
1146         "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
1147         "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
1148         "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
1149         "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
1150         "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
1152     $filter = "";
1153     foreach($ObjectTypes as $key => $data){
1154       if($this->DivListFai->$data['CHKBOX']){
1155         $filter.= "(objectClass=".$key.")";
1156       }
1157     }
1158     $filter = "(&(|".$filter.")(cn=$Regex))";
1159     
1160     /* Get resolved release dependencies */
1161     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1163     /* Ge listed ldap objects */
1164     $ldap = $this->config->get_ldap_link();
1165     $ldap->cd($this->config->current['BASE']);
1167     foreach($tmp as $entry){
1169       /* Get some more informations about the object */ 
1170       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1171       $object  = $ldap->fetch();
1173       /* Walk through possible types */
1174       foreach($ObjectTypes as $type => $rest){  
1176         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1178         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1180           /* Prepare object */
1181           unset($object['objectClass']['count']);
1182           if(!isset($object['description'][0])){
1183             $object['description'][0]="";
1184           }
1186           /* Clean up object informations */
1187           $obj                  = array();
1188           $obj['cn']                          = $object['cn'][0];
1189           $obj['dn']                          = $object['dn'];
1190           $obj['acl']                       = $acl;
1191           $obj['class']                           = $rest ['ACL'];
1192           $obj['FAIstate']      = $entry['FAIstate'];
1193           $obj['description']   = $object['description'][0];
1194           $obj['objectClass']   = $object['objectClass'];
1196           $this->objects[strtolower($obj['cn']).$obj['cn'].$type] = $obj;
1197           $this->objects[strtolower($obj['cn']).$obj['cn'].$type]['type']=$type;
1198         }
1199                         }
1200                 }
1202     /*  Append opsi objects, if opsi is available and if we are on the fai_base
1203      */
1204     if($this->opsi instanceof opsi && $this->opsi->enabled()){  
1205       $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1206       if(preg_match("/r/",$opsi_acl)){
1207         $err = FALSE;
1208         if(!$err && $this->DivListFai->ShowOpsiNetboot){
1209           $n_pro = $this->opsi->get_netboot_products();
1210           $err |= $this->opsi->is_error();
1211           foreach($n_pro as $name => $data){
1212             $entry = array("cn" => $name,
1213                 "description" => $data['DESC'],
1214                 "type" => "opsi_netboot");
1215             $this->objects[$name."_opsi_netboot"] = $entry;
1216           }  
1217         }
1218         if(!$err && $this->DivListFai->ShowOpsiLocal){
1219           $l_pro = $this->opsi->get_local_products();
1220           $err |= $this->opsi->is_error();
1221           foreach($l_pro as $name => $data){
1222             $entry = array("cn" => $name,
1223                 "description" => $data['DESC'],
1224                 "type" => "opsi_local");
1225             $this->objects[$name."_opsi_local"] = $entry;
1226           }  
1227         }  
1228         if($err){
1229           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1230         }
1231       }
1232     }
1234                 ksort($this->objects);
1235                 reset ($this->objects);
1236         
1237                 /* use numeric index, thats a bit more secure */        
1238                 $tmp0 = array();
1239                 foreach($this->objects as $obj){
1240                         $tmp0[]= $obj;
1241                 }
1242                 $this->objects = array();
1243                 $this->objects = $tmp0;
1244         }
1246         function remove_lock()
1247         {
1248                 if (isset($this->dn)){
1249                         del_lock ($this->dn);
1250                 }
1251     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1252       del_lock ($this->dns);
1253     }
1254         }
1256         function get_type($array){
1257                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1258                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1259                 }
1260                 if(in_array("FAIscript",$array['objectClass'])){
1261                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1262                 }
1263                 if(in_array("FAItemplate",$array['objectClass'])){
1264                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1265                 }
1266                 if(in_array("FAIhook",$array['objectClass'])){
1267                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1268                 }
1269                 if(in_array("FAIvariable",$array['objectClass'])){
1270                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1271                 }
1272                 if(in_array("FAIprofile",$array['objectClass'])){
1273                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1274                 }
1275                 
1276                 if(in_array("FAIpackageList",$array['objectClass'])){
1277                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1278                 }
1279         }
1281   function CheckNewBranchName($name,$base)
1282   {
1283     $f = $this->fai_release;
1284     if($name == ""){
1285       return(false);
1286     }elseif(in_array($name,$this->getBranches($f))) {
1287       return(false);
1288     }elseif(tests::is_department_name_reserved($name,$base)){
1289       return(false);
1290     }
1291     return(true);
1292   }
1294   function save_object()
1295   {
1296     $this->DivListFai->save_object();
1298     /* Get posted release */
1299     $r_releases = array_flip($this->getBranches());
1300     if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1302       /* Ensure that we have a valid release selected */
1303       if(!isset($r_releases[get_post('fai_release')])){
1304         msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1305         $_POST = array();
1306         $plug =$_GET['plug'];
1307         $_GET  = array("plug" => $plug);
1308         $this->fai_release = $this->fai_base;
1309       }else{
1310         $this->fai_release = $r_releases[get_post('fai_release')];
1311       }
1313       $fai_filter = session::get("fai_filter");
1314       $fai_filter['fai_release'] = $this->fai_release;
1315       session::set("fai_filter",$fai_filter);
1316     }
1318     if(is_object($this->CopyPasteHandler)){
1319       $this->CopyPasteHandler->save_object();
1320     }
1321   }
1324   function copyPasteHandling_from_queue($s_action,$s_entry)
1325   {
1326     /* Check if Copy & Paste is disabled */
1327     if(!is_object($this->CopyPasteHandler)){
1328       return("");
1329     }
1331     $ui = get_userinfo();
1333     /* Add a single entry to queue */
1334     if($s_action == "copy"){
1336       /* Cleanup object queue */
1337       $this->CopyPasteHandler->cleanup_queue();
1338       $entry    = $this->objects[$s_entry];
1339       $a_setup  = $this->get_type($entry);
1340       $dn = $entry['dn'];
1342       if($ui->is_copyable($dn,"fai",$a_setup[1])){
1343         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1344       }
1345     }
1347     /* Add entries to queue */
1348     if($s_action == "copy_multiple"){
1350       /* Cleanup object queue */
1351       $this->CopyPasteHandler->cleanup_queue();
1353       /* Add new entries to CP queue */
1354       foreach($this->list_get_selected_items() as $id){
1356         /* Cleanup object queue */
1357         $entry    = $this->objects[$id];
1358         $a_setup  = $this->get_type($entry);
1359         $dn = $entry['dn'];
1361         if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1362           $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1363         }
1364       }
1365     }
1367     /* Start pasting entries */
1368     if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1369       $this->start_pasting_copied_objects = TRUE;
1370     }
1372     /* Return C&P dialog */
1373     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1375       /* Get dialog */
1376       $this->CopyPasteHandler->SetVar("parent",$this);
1377       $data = $this->CopyPasteHandler->execute();
1379       FAI::save_release_changes_now();
1381       /* Return dialog data */
1382       if(!empty($data)){
1383         return($data);
1384       }
1385     }
1387     /* Automatically disable status for pasting */
1388     if(!$this->CopyPasteHandler->entries_queued()){
1389       $this->start_pasting_copied_objects = FALSE;
1390     }
1391     return("");
1392   }
1395   /* Check if the given FAI class is used in this release 
1396    */
1397   static function check_class_name($oc,$name,$dn)
1398   {
1399     $base = FAI::get_release_dn($dn);
1401     if($oc == "FAIprofile"){
1402       $f = "";
1403       $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1404       foreach($ocs as $oc){
1405         $f .= "(objectClass=".$oc.")";
1406       } 
1407       $res  = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);    
1408     }else{
1409       $res  = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1410     }
1411     $delete = array();
1412     $used   = array();
1413     foreach($res as $object){
1414       $used[$object['cn'][0]]= $object['cn'][0];
1415     }
1416     return($used);
1417   }
1420   /* Return plugin informations for acl handling */ 
1421   static function plInfo()
1422   {
1423     return (array( 
1424           "plShortName"   => _("FAI releases"),
1425           "plDescription" => _("FAI release management"),
1426           "plSelfModify"  => FALSE,
1427           "plDepends"     => array(),
1428           "plPriority"    => 0,
1429           "plSection"     => array("administration"),           
1430           "plCategory"    => array("fai"=> array("description" => _("FAI"),
1431                                                  "objectClass" => "FAIclass")),
1432           "plProvidedAcls"=> array()));
1433   }
1435 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1436 ?>