Code

Updated FAI management
[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;
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     }
73     
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","");
113     
114                 $display        = "";
115     $s_action   = "";
116                 $s_entry        = "";
117     $no_save = FALSE;   // hide Apply / Save buttons
118     
119     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
120     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$/"));
122     /****************
123       Handle posts 
124      ****************/
126                 /* Check ImageButton posts
127                  * Create new tab ich new_xx is posted
128                  */
129     $posts = array( "/^remove_branch/"                =>"remove_branch",    
130                     "/^branch_branch/"                =>"branch_branch",
131                     "/^freeze_branch/"                =>"freeze_branch",   
132  
133                     "/^create_partition/i"            =>"new_partition",
134                     "/^create_script/i"               =>"new_script",      
135                     "/^create_hook/i"                 =>"new_hook",
136                     "/^create_variable/i"             =>"new_variable",  
137                     "/^create_template/i"             =>"new_template",
138                     "/^create_package/i"              =>"new_package",    
139                     "/^create_profile/i"              =>"new_profile",
141                     "/^edit_continue$/"               => "select_class_name_finished",
143                     "/^group_edit/"                   => "group_edit",
144                     "/^group_remove/"                 => "group_remove");
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     }
156     if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
157       if(isset($this->objects[$_GET['id']])){
158         $s_action = "group_edit";
159         $s_entry = $_GET['id'];
160       }
161     }
163     foreach(array("freeze_branch" => "freeze_branch",
164           "branch_branch" => "branch_branch",
165           "remove_branch" => "remove_branch") as $from => $to){
166       if(isset($_GET['act']) && $_GET['act'] == $from){
167         $s_action = $to;
168       }
169     }
170   
171     /* handle C&P from layer menu */
172     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
173       $s_action = "copy_multiple";
174     }
175     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
176       $s_action = "cut_multiple";
177     }
178     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
179       $s_action = "editPaste";
180     }
183     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
184       $this->dispNewBranch = false;
185       $this->dispNewFreeze = false;
186     }
188     /* Create options */
189     if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
190       $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
191       $s_entry  = preg_replace("/^Create_/","",$_POST['menu_action']);
192     }
194     /* handle remove from layers menu */
195     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
196       $s_action = "del_multiple";
197     }
200     if(!empty($s_action)){
201       $this->no_save = $no_save;
202     }
204     /********************
205       Copy & Paste
206      ********************/
208     /* Display the copy & paste dialog, if it is currently open */
209     $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
210     if($ret){
211       return($ret);
212     }
215     /*******************
216       Opsi extension 
217      *******************/
219     if($this->opsi instanceof opsi && $this->opsi->enabled()){
220       if($s_action == "opsi_edit"){
221         $name = $this->objects[$s_entry]['cn'];
222         $cfg = $this->opsi->get_product_properties($name);
223         $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
224         if(isset($this->dialog->by_object['opsiProperties'])){
225           $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
226           $this->dialog->by_object['opsiProperties']->set_product($name);
227         }else{
228           trigger_error("Unknown tab, please check config.");
229         }
230       }
231       if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
232         $this->dialog = NULL;
233       }
234       if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
235         $this->dialog->save_object();
236         $op    = $this->dialog->by_object['opsiProperties'];
237         $name  = $op->get_product();
238         $cfg   = $op->get_cfg();
239         $this->opsi->set_product_properties($name,$cfg); 
240         if($this->opsi->is_error()){
241           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
242         }else{
243           $this->dialog = NULL;
244         }
245       }
246       if($this->dialog instanceof tabs_opsiProdConfig){
247         $this->dialog->save_object();
248         return($this->dialog->execute());
249       }
250     }
253     /****************
254       Delete a group of FAI objects 
255         (Group = same name & different classes)
256      ****************/
258     if($s_action == "group_remove"){
259       if(isset($this->objects[$s_entry])){
260         $group = $this->objects[$s_entry];
262         /* Do not allow to remove opsi products */
263         foreach(array("opsi_netboot","opsi_local") as $type){
264           if(isset($group[$type])) unset($group[$type]);
265         }
266         if(count($group)){
267           $this->dialog = new faiGroupHandle($group,"remove");
268         }
269       }
270     }elseif($s_action == "group_edit"){
271       if(isset($this->objects[$s_entry])){
272         $group = $this->objects[$s_entry];
273         $this->dialog = new faiGroupHandle($group,"edit");
274       }
275     }
276     if($this->dialog instanceOf faiGroupHandle){
277       $this->dialog->save_object();
278       if($this->dialog->is_open()){
279         return($this->dialog->execute());
280       }elseif($this->dialog->is_canceled() || isset($_POST['cancel_lock'])){
281         $this->dialog = FALSE;
282       }else{
283         if(!count($this->dialog->get_selected())){
284           $this->dialog = FALSE;
285         }
286       }
287     }
290     /********************
291       Delete MULTIPLE entries confirmed
292      ********************/
294     /* Confirmation for deletion has been passed. Users should be deleted. */
295     if (isset($_POST['delete_multiple_fai_object_confirm'])){
297       /* Find out more about the object type */
298       $ldap   = $this->config->get_ldap_link();
300       /* Remove user by user and check acls before removeing them */
301       foreach($this->dns as $key => $dn){
302         $ldap->cat($dn, array('objectClass'));
303         $attrs  = $ldap->fetch();
304         $type   = $this->get_type($attrs);
305         $acl  = $this->ui->get_permissions($dn,"fai/".$type[1]);
306         if(preg_match("/d/",$acl)){
307           $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
308           $this->dialog->parent = &$this;
309           $this->dialog->set_acl_base($dn);
310           $this->dialog->by_object[$type[1]]->remove_from_parent ();
311           $this->dialog= FALSE;
312           $to_del = FAI::clean_up_releases($dn);
313           FAI::save_release_changes_now();
314           foreach($to_del as $dn){
315             $ldap->rmdir_recursive($dn);
316           }
317         } else {
319           /* Normally this shouldn't be reached, send some extra
320              logs to notify the administrator */
321           msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
322           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
323         }
324       }
326       /* Remove lock file after successfull deletion */
327       $this->remove_lock();
328       $this->dns = array();
329       $this->dialog = FALSE;
330     }
333     /****************
334       Delete confirme dialog 
335      ****************/
337     if ($s_action=="del_multiple" || 
338         $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "remove"){
339  
340       /* Collect objects to delete and check if objects are freezed
341        */ 
342       $dns = array();
343       $errors = "";
344       $this->dns = array();
345       if($this->dialog instanceOf faiGroupHandle){
346         $to_delete = $this->dialog->get_selected();
347       }else{
348         $ids = $this->list_get_selected_items();
349         $to_delete = array();
350         foreach($ids as $id){
351           $to_delete = array_merge($to_delete,$this->objects[$id]);
352         }
353       } 
355       foreach($to_delete as $obj){
356         if(isset($obj['type']) && in_array($obj['type'],array("opsi_netboot","opsi_local"))){
357           continue;
358         }
359         if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
360           $errors .= $obj['cn'].", ";
361         }else{
362           $this->dns[] = $obj['dn'];
363         }
364       }
366       if($errors != ""){
367         msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
368               "<br><br>".trim($errors,", ")),INFO_DIALOG);
369       }
371       /* Check locking 
372        */
373       if(count($this->dns)){
374         if ($user= get_multiple_locks($this->dns)){
375           return(gen_locked_message($user,$this->dns));
376         }
377         if(count($this->dns)){
378           $dns_names = array();
379           foreach($this->dns as $dn){
380             add_lock ($dn, $this->ui->dn);
381             $dns_names[] = LDAP::fix($dn);
382           }
383                                   $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
384           $smarty->assign("multiple", true);
385           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
386         }
387       }
388     }
392     /********************
393       Delete MULTIPLE entries Canceled
394      ********************/
396     /* Remove lock */
397     if(isset($_POST['delete_multiple_fai_object_cancel'])){
398       $this->remove_lock();
399       $this->dns = array();
400     }
403     /****************
404       Edit entry 
405      ****************/
407                 if($this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "edit"){
409       $entry = array();
410       if($this->dialog instanceOf faiGroupHandle){
411         $entries = $this->dialog->get_selected();
412         $entry = array_pop($entries);
413       }elseif(isset($this->objects[$i_entryID][$s_entryType])){
414         $entry = $this->objects[$i_entryID][$s_entryType];
415       }
417       if(count($entry)){
418         $a_setup  = $this->get_type($entry);
420         /* Special handling for opsi products 
421          */
423         if(in_array($entry['type'],array("opsi_local","opsi_netboot")) && 
424             $this->opsi instanceof opsi && $this->opsi->enabled() ){
426           $name = $entry['cn'];
427           $cfg = $this->opsi->get_product_properties($name);
428           $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
429           if(isset($this->dialog->by_object['opsiProperties'])){
430             $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
431             $this->dialog->by_object['opsiProperties']->set_product($name);
432           }else{
433             trigger_error("Unknown tab, please check config.");
434           }
435         }elseif(count($a_setup)){
437           $this->dn = $entry['dn'];
438           /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
439           if (($user= get_lock($this->dn)) != ""){
440             return(gen_locked_message ($user, $this->dn, TRUE));
441           }
442           add_lock ($this->dn, $this->ui->dn);
444           $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
445           $this->dialog->parent = &$this;
446           $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
447           $this->dialog->set_acl_base($this->dn);
448           $this->is_dialog  = true;
449           session::set('objectinfo',$this->dn);
450         }
451       }
452     }
455     /*  Branch handling 
456         09.01.2006
457     */
459     /****************
460       Remove branch
461      ****************/
463     /* Remove branch 
464      */
465     if($s_action == "remove_branch"){
466       $base= $this->fai_release;
468       /* Check if we have a post remove method configured
469        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
470        */
471       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
472         /* Load permissions for selected 'dn' and check if
473            we're allowed to remove this 'dn' */
474         if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
475           $smarty->assign("release_hidden",base64_encode($this->fai_release));
476           $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
477           return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
478         } else {
479           msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
480         }
481       }
482     }
484     
485     /****************
486       Remove branch confirmed
487      ****************/
489     if(isset($_POST['delete_branch_confirm'])){
491       /* Check if we have a post remove method configured
492        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
493        */
494       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
496         if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
497           msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
498         }else{
500           $bb =  $this->fai_release;
501           if(!isset($ldap)){
502             $ldap = $this->config->get_ldap_link();
503           }
505           $br = $this->getBranches();
507           if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
508             $name = $br[$bb];
510             $ldap->cd($bb);
511             $ldap->recursive_remove();
512             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
513             $ldap->recursive_remove();
514             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
515             $ldap->recursive_remove();
517             /* Search for all groups with configured application menus.
518               - First search all groups, to ensure that we only remove entries form whithin groups. 
519               - The search für menu configuration for the specified release and collect all those dns.
520               - Remove entries
521              */
522             $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
523             $ldap->cd($this->config->current['BASE']);
524             $ldap->search("(objectClass=posixGroup)",array("dn"));
525           
526             /* Collect all group dns 
527              */
528             $groups = array();
529             while($attrs = $ldap->fetch()){
530               $groups[] = $attrs['dn'];
531             }
533             /* Collect all group menu release dns that match the release we have removed 
534              */
535             $dns = array();
536             foreach($groups as $dn){
537               $ldap->cd($dn);
538               $ldap->search("(objectClass=FAIbranch)",array("dn"));
539               while($attrs = $ldap->fetch()){
540                 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
541                   $dns[] = $attrs['dn'];
542                 }
543               }
544             }
545             
546             /* Finally remove collected release dns 
547              */
548             foreach($dns as $dn){
549               $ldap->cd($dn);
550               $ldap->recursive_remove();
551             }
553             /* Post remove */
554             $this->fai_release = $this->fai_base;
555             $this->lock_name   = $name;
556             $this->lock_dn     = $bb;
557             $this->postremove();
559             $fai_filter = session::get("fai_filter");
560             $fai_filter['fai_release'] = $this->fai_release;
561             session::set("fai_filter",$fai_filter);
563             new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
564           }
565         }
566       }
567     }
570     /****************
571       Create a new branch "insert Name"
572      ****************/
574     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
575       session::set('LASTPOST',$_POST);
577       if($this->dispNewBranch){
578         $type = "branch";
579       }else{
580         $type = "freeze";
581       }
583       /* Check branch name */
584       $name = $_POST['BranchName'];
585       $is_ok = true;
586       $smarty->assign("BranchName",$name);
587       $base= $this->fai_base;
589       /* Check used characters */
590       if(!preg_match("/^[0-9a-z\.]*$/",$name)){
591         msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
592         $is_ok = false;
593       }
595       /* Check if this name is already in use */
596       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
597         msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
598         $is_ok = false;
599       }
601       if($is_ok){
603         if(session::is_set('LASTPOST')){
604           $LASTPOST = session::get('LASTPOST');
605         }else{
606           $LASTPOST = array();
607         }
608         $LASTPOST['base'] = $base;
609         $LASTPOST['type'] = $type;
610         session::set('LASTPOST',$LASTPOST);
611         $smarty->assign("iframe", true);
612         $smarty->assign("plugID", $_GET['plug']);
613         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
614         return($display);
615       }
616     }
619     /****************
620       Create a new branch 
621      ****************/
623     if(isset($_GET['PerformBranch'])){
624     
625       if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
626         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
627       }else{
629         /* In order to see error messages we have to reset the error handler.
630             Due to the exit(); 
631          */
632         restore_error_handler();
634         /* Create it know */
635         $this->dispNewBranch = false;
636         $this->dispNewFreeze = false;
638         $LASTPOST = session::get('LASTPOST');
639         $base = $LASTPOST['base'];
640         $_POST  = session::get('LASTPOST');      
641         $name = $_POST['BranchName'];
643         $type = $LASTPOST['type'];
644         $ldap = $this->config->get_ldap_link();
646         $baseToUse = $base;
647         if($this->fai_release !=  $this->fai_base){
648           $baseToUse = $this->fai_release;
649         }
651         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
653         $CurrentReleases  = $this->getBranches();
654         $NewReleaseName   = $name;
655         if(isset($CurrentReleases[$this->fai_release])) {
656           if($this->fai_release != $this->fai_base){
657             $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
658             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
659           }else{
660             $NewReleaseName   = $name;
661           }
662         }
664         $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse); 
665         $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ; 
667         $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse); 
668         $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ; 
670         /* Check if source depeartments exist */
671         foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
672           $ldap->cd($this->config->current['BASE']);
673           $ldap->cat($dep);
674           if(!$ldap->count()){
675             $ldap->create_missing_trees($dep);
676           }
677         }
679         /* Print header to have styles included */
680         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
681           <html>
682           <head>
683           <title></title>
684           <style type="text/css">@import url("themes/default/style.css");</style>
685           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
686           </head>
687           <body style="background: none;margin:3px;color:black">
688           ';
690         new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
692         /* Duplicate group application releases 
693          */
694         FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
696         /* Duplicate applications 
697          */
698         $ldap->cat($appsrc,array("dn")) ;
699         if($ldap->count()){
700           $ldap->cd ($appdst);
701           $ldap->recursive_remove();
702           FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
703         }
705         /* Duplicate mime types 
706          */
707         $ldap->cat($mimesrc,array("dn")) ;
708         if($ldap->count()){
709           $ldap->cd ($mimedst);
710           $ldap->recursive_remove();
711           FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
712         }
714         $attr = array();
715         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
716         $attr['ou']       = $name;
717         $attr['FAIstate'] = $type;
718         $ldap->cd($this->config->current['BASE']);
719         $ldap->cd("ou=".$name.",".$baseToUse);
720         $ldap->cat("ou=".$name.",".$baseToUse);
721         if($ldap->count()){
722           $ldap->modify($attr);
723         }else{
724           $ldap->add($attr);
725         }
727         /* Duplicate fai objects 
728          */
729         //      $ldap->cd ("ou=".$name.",".$baseToUse);
730         //      $ldap->recursive_remove();
731         //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
733         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
734           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
735           <input type='hidden' name='php_c_check' value='1'>
736           </form></div>";
738         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
740         /* Print footer to have valid html */
741         echo "</body></html>";
743         $this->dispNewFreeze = false; 
745         /* Postcreate */ 
747         /* Assign possible attributes */
748         $this->lock_type  = $type; 
749         $this->lock_name  = $name; 
750         $this->lock_dn    = $baseToUse;
751         $this->postcreate();
754         /* Send daemon event to reload the fai release database 
755          */
756         if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
757           $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
758           if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
759             $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
760             $tmp = new $evt['CLASS_NAME']($this->config);
761             $tmp->set_type(TRIGGERED_EVENT);
762             $tmp->add_targets(array("GOSA"));
763             $o_queue = new gosaSupportDaemon();
764             if(!$o_queue->append($tmp)){
765               msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
766             }
767           }
768         }else{  
769           trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
770           msg_dialog::display(_("Fatal error"),
771               "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
772               FATAL_ERROR_DIALOG);
773         }
774         exit();
775       }
776     }
778     /****************
779       Display dialog to enter new Branch name
780      ****************/
782     /* Check if we have a post create method configured
783      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
784      */
785     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
786       if(($s_action == "branch_branch")||($this->dispNewBranch)){
787         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
788           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
789         }else{
790           $this->dispNewBranch=true;
791           $smarty->assign("iframe",false);
792           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
793           return($display);
794         }
795       } 
796     }
798  
799     /****************
800       Display dialog to enter new Freeze name
801      ****************/
803     /* Check if we have a post create method configured
804      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
805      */
806     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
807       if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
808         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
809           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
810         }else{
811           $this->dispNewFreeze = true;
812           $smarty->assign("iframe",false);
813           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
814           return($display);
815         }
816       }
817     }
820     /****************
821       Create a new object 
822      ****************/
824     $types = array( "new_partition"     =>  "FAIpartitionTable",
825                     "new_script"        =>  "FAIscript",
826                     "new_hook"          =>  "FAIhook",
827                     "new_variable"      =>  "FAIvariable",
828                     "new_template"      =>  "FAItemplate",
829                     "new_package"       =>  "FAIpackageList");
830     $types_i18n = array( "new_partition"     =>  _("partition table"),
831                     "new_script"        =>  _("script"),
832                     "new_hook"          =>  _("hook"),
833                     "new_variable"      =>  _("variable"),
834                     "new_template"      =>  _("template"),
835                     "new_package"       =>  _("package list"));
837     if(isset($types[$s_action])){
839       $type_acl_mapping = array(
840           "FAIpartitionTable"  => "faiPartitionTable", 
841           "FAIpackageList"     => "faiPackage",
842           "FAIscript"          => "faiScript",
843           "FAIvariable"        => "faiVariable",
844           "FAIhook"            => "faiHook",
845           "FAIprofile"         => "faiProfile",
846           "FAItemplate"        => "faiTemplate");
848       $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$s_action]]);
849       if(preg_match("/c/",$acl)){
850         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
851         $this->dialog->parent = &$this;
852       }else{
853         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
854       }
855     }
857     /* New Profile */
858     if($s_action == "new_profile"){
859       $this->dn = "new" ;
861       $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
862       if(preg_match("/c/",$acl)){
863         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
864         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
865         $this->dialog->set_acl_base($this->base);
866         $this->dialog->parent = &$this;
868         $this->is_dialog = false;
869       }else{
870         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
871       }
872     }
875     /****************
876       Get name from ask_class_name dialog 
877      ****************/
879     if($s_action == "select_class_name_finished"){
880       $this->dialog->save_object();
881       if(count($this->dialog->check())!=0){
882         foreach($this->dialog->check() as $msg){
883           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
884         }               
885       }elseif(isset($this->dialog->objectClass)){
886         $this->dn = "new" ;
887         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
888         $name = $this->dialog->save();
890         if(class_exists($a_setup[0])){
891           $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
892           $this->dialog->set_acl_base($this->base);
893           $this->dialog->by_object[$a_setup[1]]->cn = $name;
894           $this->dialog->parent = &$this;
895           $this->is_dialog = true;
896         }
897       }         
898     }   
901     /****************
902      Cancel dialogs 
903      ****************/
905                 if(isset($_POST['edit_cancel'])){
906                         $this->dialog=FALSE;
907                         $this->is_dialog = false;
908                         session::un_set('objectinfo');
909       $this->remove_lock();
910                 }
913     /****************
914      Handle opsi dialogs  
915      ****************/
916       
917     if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
918       $this->dialog = NULL;
919     }
920     if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
921       $this->dialog->save_object();
922       $op    = $this->dialog->by_object['opsiProperties'];
923       $name  = $op->get_product();
924       $cfg   = $op->get_cfg();
925       $this->opsi->set_product_properties($name,$cfg);
926       if($this->opsi->is_error()){
927         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
928       }else{
929         $this->dialog = NULL;
930       }
931     }
932     if($this->dialog instanceof tabs_opsiProdConfig){
933       $this->dialog->save_object();
934       return($this->dialog->execute());
935     }
938     /****************
939       Save sub dialogs 
940      ****************/
942                 /* This check if the given tab could be saved 
943                  * If it was possible to save it, remove dialog object. 
944                  * If it wasn't possible, show errors and keep dialog.
945                  */
946                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
947                         $this->dialog->save_object();
948       $msgs= $this->dialog->check();
949                         if(count($msgs)!=0){
950                                 foreach($msgs as $msg){
951           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
952                                 }
953                         }else{
954                                 $this->dialog->save();
955         FAI::save_release_changes_now();
956         if (!isset($_POST['edit_apply'])){
957           $this->remove_lock();
958           $this->dialog=FALSE;
959           $this->is_dialog=false;
960           session::un_set('objectinfo');
961         }else{
963           /* Reinitialize tab */
964           if($this->dialog instanceof tabs){
965             $this->dialog->re_init();
966           }
967         }
968                         }
969                 }
972     /****************
973       Display currently open dialog 
974      ****************/
976                 /* If dialog is set, but $this->is_dialog==false, then 
977                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
978                  * If is_dialog == true, we are currently editing tab objects.
979                  *  Here we need both, save and cancel
980                  */ 
982                 if(is_object($this->dialog)){
983                         $display .= $this->dialog->execute();
984                         /* Don't show buttons if tab dialog requests this */
986       if(isset($this->dialog->current)){
988         $obj = $this->dialog->by_object[$this->dialog->current];
990         if(($this->dialog instanceOf tabs || $this->dialog instanceOf plugin) && $this->dialog->read_only == TRUE){
991           $display.= "<p style=\"text-align:right\">
992             <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
993             </p>";
994         }elseif((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
996           $display.= "<p style=\"text-align:right\">\n";
997           if(!$this->no_save){
998             $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
999             $display.= "&nbsp;\n";
1000             if ($this->dn != "new"){
1001               $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1002               $display.= "&nbsp;\n";
1003             }
1004           }
1005           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1006           $display.= "</p>";
1007         }elseif(!isset($this->dialog->current)){
1008           $display.= "<p style=\"text-align:right\">\n";
1009           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1010           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1011           $display.= "</p>";
1012         }
1013       }else{
1014         $display.= "<p style=\"text-align:right\">\n";
1015         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1016         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1017         $display.= "</p>";
1019       }
1020       return($display);
1021                 }
1022                 
1024     /****************
1025       Dialog display
1026      ****************/
1028     /* Check if there is a snapshot dialog open */
1029     $base = $this->fai_base;
1030     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1031       return($str);
1032     }
1034     /* Display dialog with system list */
1035     $this->reload();
1036     $this->DivListFai->parent = &$this;
1037     $this->DivListFai->execute();
1038     $this->DivListFai->setEntries($this->objects);
1039     return($this->DivListFai->Draw());
1040         }
1043   /* Return departments, that will be included within snapshot detection */
1044   function get_used_snapshot_bases()
1045   {
1046     $tmp = array();
1047     $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1048     foreach($types as $type){
1049       $tmp[] = get_ou($type).$this->fai_release;
1050     }
1051     return($tmp);
1052   }
1055   /* Get available branches for current base */
1056   function getBranches($base = false,$prefix = "")
1057   {
1058     $ret = array("/"=>$this->fai_base);
1059     $ldap = $this->config->get_ldap_link();
1060     if(!$base){
1061       $base = $this->fai_base;
1062     }
1063     $tmp = FAI::get_all_releases_from_base($base,true);
1064     foreach($tmp as $dn => $name){
1065       $ret[$name]=$dn;
1066     }
1067     ksort($ret);
1068     $ret = array_flip($ret);
1070     return ($ret);
1071   }
1072   
1074   function list_get_selected_items()
1075   {
1076     $ids = array();
1077     foreach($_POST as $name => $value){
1078       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1079         $id   = preg_replace("/^item_selected_/","",$name);
1080         $ids[$id] = $id;
1081       }
1082     }
1083     return($ids);
1084   }
1087   /* reload list of objects */
1088   function reload()
1089   {
1090     /* Variable initialisation */
1091     $str            = "";
1092     $Regex          = $this->DivListFai->Regex;
1093     $this->objects  = array();
1095     /* Get base */
1096     $base = $this->fai_base;
1097     if($this->fai_release != $this->fai_base){
1098       $br = $this->getBranches();
1099       if(isset($br[$this->fai_release])){
1100         $base = $this->fai_release;
1101       }else{
1102         $base = $this->fai_base;
1103       }
1104     }
1105     $this->base = $base;
1106     $this->set_acl_base($this->acl_base);
1108     $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1110     /* Create a new list of FAI object 
1111      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
1112      */
1113     $ObjectTypes = array(
1114         "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
1115         "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
1116         "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
1117         "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
1118         "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
1119         "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
1120         "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
1122     $filter = "";
1123     foreach($ObjectTypes as $key => $data){
1124       if($this->DivListFai->$data['CHKBOX']){
1125         $filter.= "(objectClass=".$key.")";
1126       }
1127     }
1128     $filter = "(&(|".$filter.")(cn=$Regex))";
1129     
1130     /* Get resolved release dependencies */
1131     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1133     /* Ge listed ldap objects */
1134     $ldap = $this->config->get_ldap_link();
1135     $ldap->cd($this->config->current['BASE']);
1137     foreach($tmp as $entry){
1139       /* Get some more informations about the object */ 
1140       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1141       $object  = $ldap->fetch();
1143       /* Walk through possible types */
1144       foreach($ObjectTypes as $type => $rest){  
1146         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1148         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1150           /* Prepare object */
1151           unset($object['objectClass']['count']);
1152           if(!isset($object['description'][0])){
1153             $object['description'][0]="";
1154           }
1156           /* Clean up object informations */
1157           $obj                  = array();
1158           $obj['cn']                          = $object['cn'][0];
1159           $obj['dn']                          = $object['dn'];
1160           $obj['acl']                       = $acl;
1161           $obj['class']                           = $rest ['ACL'];
1162           $obj['FAIstate']      = $entry['FAIstate'];
1163           $obj['description']   = $object['description'][0];
1164           $obj['objectClass']   = $object['objectClass'];
1166           $this->objects[$obj['cn']][$type] = $obj;
1167           $this->objects[$obj['cn']][$type]['type']=$type;
1168         }
1169                         }
1170                 }
1172     /*  Append opsi objects, if opsi is available and if we are on the fai_base
1173      */
1174     if($this->opsi instanceof opsi && $this->opsi->enabled()){  
1175       $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1176       if(preg_match("/r/",$opsi_acl)){
1177         $err = FALSE;
1178         if(!$err && $this->DivListFai->ShowOpsiNetboot){
1179           $n_pro = $this->opsi->get_netboot_products();
1180           $err |= $this->opsi->is_error();
1181           foreach($n_pro as $name => $data){
1182             $entry = array(
1183                 "cn" => $name,
1184                 "description" => $data['DESC'],
1185                 "type" => "opsi_netboot");
1186             $this->objects[$name]['opsi_netboot'] = $entry;
1187           }  
1188         }
1189         if(!$err && $this->DivListFai->ShowOpsiLocal){
1190           $l_pro = $this->opsi->get_local_products();
1191           $err |= $this->opsi->is_error();
1192           foreach($l_pro as $name => $data){
1193             $entry = array("cn" => $name,
1194                 "description" => $data['DESC'],
1195                 "type" => "opsi_local");
1196             $this->objects[$name]["opsi_local"] = $entry;
1197           }  
1198         }  
1199         if($err){
1200           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1201         }
1202       }
1203     }
1204  
1205     uksort($this->objects, 'strnatcasecmp');
1206                 reset ($this->objects);
1207                 $this->objects = array_values($this->objects);
1208         }
1210         function remove_lock()
1211         {
1212                 if (isset($this->dn)){
1213                         del_lock ($this->dn);
1214                 }
1215     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1216       del_lock ($this->dns);
1217     }
1218         }
1220         function get_type($array){
1221     if(!isset($array['objectClass'])) return(array());
1222                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1223                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1224                 }
1225                 if(in_array("FAIscript",$array['objectClass'])){
1226                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1227                 }
1228                 if(in_array("FAItemplate",$array['objectClass'])){
1229                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1230                 }
1231                 if(in_array("FAIhook",$array['objectClass'])){
1232                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1233                 }
1234                 if(in_array("FAIvariable",$array['objectClass'])){
1235                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1236                 }
1237                 if(in_array("FAIprofile",$array['objectClass'])){
1238                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1239                 }
1240                 
1241                 if(in_array("FAIpackageList",$array['objectClass'])){
1242                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1243                 }
1244     return(array());
1245         }
1247   function CheckNewBranchName($name,$base)
1248   {
1249     $f = $this->fai_release;
1250     if($name == ""){
1251       return(false);
1252     }elseif(in_array($name,$this->getBranches($f))) {
1253       return(false);
1254     }elseif(tests::is_department_name_reserved($name,$base)){
1255       return(false);
1256     }
1257     return(true);
1258   }
1260   function save_object()
1261   {
1262     $this->DivListFai->save_object();
1264     /* Get posted release */
1265     $r_releases = array_flip($this->getBranches());
1266     if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1268       /* Ensure that we have a valid release selected */
1269       if(!isset($r_releases[get_post('fai_release')])){
1270         msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1271         $_POST = array();
1272         $plug =$_GET['plug'];
1273         $_GET  = array("plug" => $plug);
1274         $this->fai_release = $this->fai_base;
1275       }else{
1276         $this->fai_release = $r_releases[get_post('fai_release')];
1277       }
1279       $fai_filter = session::get("fai_filter");
1280       $fai_filter['fai_release'] = $this->fai_release;
1281       session::set("fai_filter",$fai_filter);
1282     }
1284     if(is_object($this->CopyPasteHandler)){
1285       $this->CopyPasteHandler->save_object();
1286     }
1287   }
1290   function copyPasteHandling_from_queue($s_action,$s_entry)
1291   {
1292     /* Check if Copy & Paste is disabled */
1293     if(!is_object($this->CopyPasteHandler)){
1294       return("");
1295     }
1297     $ui = get_userinfo();
1299     /* Add a single entry to queue */
1300     if($s_action == "copy"){
1302       /* Cleanup object queue */
1303       $this->CopyPasteHandler->cleanup_queue();
1304       $entry    = $this->objects[$s_entry];
1305       $a_setup  = $this->get_type($entry);
1306       $dn = $entry['dn'];
1308       if($ui->is_copyable($dn,"fai",$a_setup[1])){
1309         $this->CopyPasteHandler->add_to_queue($dn,$s_action,$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1310       }
1311     }
1313     /* Add entries to queue */
1314     if($s_action == "copy_multiple"){
1316       /* Cleanup object queue */
1317       $this->CopyPasteHandler->cleanup_queue();
1319       /* Add new entries to CP queue */
1320       foreach($this->list_get_selected_items() as $id){
1322         /* Cleanup object queue */
1323         $entry    = $this->objects[$id];
1324         $a_setup  = $this->get_type($entry);
1325         $dn = $entry['dn'];
1327         if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1328           $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1329         }
1330       }
1331     }
1333     /* Start pasting entries */
1334     if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1335       $this->start_pasting_copied_objects = TRUE;
1336     }
1338     /* Return C&P dialog */
1339     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1341       /* Get dialog */
1342       $this->CopyPasteHandler->SetVar("parent",$this);
1343       $data = $this->CopyPasteHandler->execute();
1345       FAI::save_release_changes_now();
1347       /* Return dialog data */
1348       if(!empty($data)){
1349         return($data);
1350       }
1351     }
1353     /* Automatically disable status for pasting */
1354     if(!$this->CopyPasteHandler->entries_queued()){
1355       $this->start_pasting_copied_objects = FALSE;
1356     }
1357     return("");
1358   }
1361   /* Check if the given FAI class is used in this release 
1362    */
1363   static function check_class_name($oc,$name,$dn)
1364   {
1365     $base = FAI::get_release_dn($dn);
1367     if($oc == "FAIprofile"){
1368       $f = "";
1369       $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1370       foreach($ocs as $oc){
1371         $f .= "(objectClass=".$oc.")";
1372       } 
1373       $res  = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);    
1374     }else{
1375       $res  = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1376     }
1377     $delete = array();
1378     $used   = array();
1379     foreach($res as $object){
1380       $used[$object['cn'][0]]= $object['cn'][0];
1381     }
1382     return($used);
1383   }
1386   /* Return plugin informations for acl handling */ 
1387   static function plInfo()
1388   {
1389     return (array( 
1390           "plShortName"   => _("FAI releases"),
1391           "plDescription" => _("FAI release management"),
1392           "plSelfModify"  => FALSE,
1393           "plDepends"     => array(),
1394           "plPriority"    => 0,
1395           "plSection"     => array("administration"),           
1396           "plCategory"    => array("fai"=> array("description" => _("FAI"),
1397                                                  "objectClass" => "FAIclass")),
1398           "plProvidedAcls"=> array()));
1399   }
1401 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1402 ?>