Code

Fixes deletopm part of lhm revision #13568
[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     $i_entryID ="";
117     $s_entryType= "";
118                 $s_entry        = "";
119     $no_save = FALSE;   // hide Apply / Save buttons
120     
121     /* If an entry was locked, these vars will be stored in a session to allow direct edit */
122     session::set('LOCK_VARS_TO_USE',array("/^edit_freeze_entry$/","/^edit_entry$/","/^id$/","/^entry_edit_/","/^entry_delete_/","/^item_selected/","/^remove_multiple_fai_objects/","/^menu_action/","/^faiGroupHandle_apply$/"));
124     /****************
125       Handle posts 
126      ****************/
128                 /* Check ImageButton posts
129                  * Create new tab ich new_xx is posted
130                  */
131     $posts = array( "/^remove_branch/"                =>"remove_branch",    
132                     "/^branch_branch/"                =>"branch_branch",
133                     "/^freeze_branch/"                =>"freeze_branch",   
134  
135                     "/^create_partition/i"            =>"new_partition",
136                     "/^create_script/i"               =>"new_script",      
137                     "/^create_hook/i"                 =>"new_hook",
138                     "/^create_variable/i"             =>"new_variable",  
139                     "/^create_template/i"             =>"new_template",
140                     "/^create_package/i"              =>"new_package",    
141                     "/^create_profile/i"              =>"new_profile",
143                     "/^edit_continue$/"               => "select_class_name_finished",
145                     "/^group_copy/"                   => "group_copy",
146                     "/^group_cut/"                    => "group_cut",
147                     "/^group_edit/"                   => "group_edit",
148                     "/^group_remove/"                 => "group_remove");
149                 foreach($_POST as $name => $value){
150       foreach($posts as $reg => $act ){
151         if(preg_match($reg,$name)){
152           $s_action = $act;
153           $s_entry = ltrim(preg_replace($reg,"",$name),"_");
154           $s_entry = preg_replace("/_.*$/","",$s_entry);
155           break;
156         }
157       }
158       if(preg_match("/^edit_[0-9]*_.*$/",$name)){
159         $i_entryID  = preg_replace("/^edit_([0-9]*)_.*$/i","\\1",$name);
160         $s_entryType= preg_replace("/^edit_[0-9]*_([^_]*)_.*$/i","\\1",$name);
161         $s_action = "edit";
162       }
163     }
165     if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id'])){
166       if(isset($this->objects[$_GET['id']])){
167         $s_action = "group_edit";
168         $s_entry = $_GET['id'];
169       }
170     }
172     foreach(array("freeze_branch" => "freeze_branch",
173           "branch_branch" => "branch_branch",
174           "remove_branch" => "remove_branch") as $from => $to){
175       if(isset($_GET['act']) && $_GET['act'] == $from){
176         $s_action = $to;
177       }
178     }
179   
180     /* handle C&P from layer menu */
181     if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
182       $s_action = "copy_multiple";
183     }
184     if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
185       $s_action = "cut_multiple";
186     }
187     if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
188       $s_action = "editPaste";
189     }
192     if((isset($_POST['CancelBranchName'])) || (isset($_POST['CloseIFrame']))){
193       $this->dispNewBranch = false;
194       $this->dispNewFreeze = false;
195     }
197     /* Create options */
198     if(isset($_POST['menu_action']) && preg_match("/^Create_/",$_POST['menu_action'])){
199       $s_action = "new_".preg_replace("/^Create_/","",$_POST['menu_action']);;
200       $s_entry  = preg_replace("/^Create_/","",$_POST['menu_action']);
201     }
203     /* handle remove from layers menu */
204     if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
205       $s_action = "del_multiple";
206     }
209     if(!empty($s_action)){
210       $this->no_save = $no_save;
211     }
214     /*******************
215       Opsi extension 
216      *******************/
218     if($this->opsi instanceof opsi && $this->opsi->enabled()){
219       if($s_action == "opsi_edit"){
220         $name = $this->objects[$s_entry]['cn'];
221         $cfg = $this->opsi->get_product_properties($name);
222         $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
223         if(isset($this->dialog->by_object['opsiProperties'])){
224           $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
225           $this->dialog->by_object['opsiProperties']->set_product($name);
226         }else{
227           trigger_error("Unknown tab, please check config.");
228         }
229       }
230       if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
231         $this->dialog = NULL;
232       }
233       if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
234         $this->dialog->save_object();
235         $op    = $this->dialog->by_object['opsiProperties'];
236         $name  = $op->get_product();
237         $cfg   = $op->get_cfg();
238         $this->opsi->set_product_properties($name,$cfg); 
239         if($this->opsi->is_error()){
240           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
241         }else{
242           $this->dialog = NULL;
243         }
244       }
245       if($this->dialog instanceof tabs_opsiProdConfig){
246         $this->dialog->save_object();
247         return($this->dialog->execute());
248       }
249     }
252     /****************
253       Delete a group of FAI objects 
254         (Group = same name & different classes)
255      ****************/
257     if($s_action == "group_remove"){
258       if(isset($this->objects[$s_entry])){
259         $group = $this->objects[$s_entry];
261         /* Do not allow to remove opsi products */
262         foreach(array("opsi_netboot","opsi_local") as $type){
263           if(isset($group[$type])) unset($group[$type]);
264         }
265         if(count($group) == 1){
266           $s_action = "remove";
267           $i_entryID = $s_entry;
268           $s_entryType = key($group);
269         }elseif(count($group)){
270           $this->dialog = new faiGroupHandle($group,"remove");
271         }
272       }
273     }elseif($s_action == "group_edit"){
274       if(isset($this->objects[$s_entry])){
275         $group = $this->objects[$s_entry];
276         if(count($group) == 1){
277           $s_action = "edit";
278           $i_entryID = $s_entry;
279           $s_entryType = key($group);
280         }else{
281           $this->dialog = new faiGroupHandle($group,"edit");
282         }
283       }
284     }elseif($s_action == "group_cut"){
285       if(isset($this->objects[$s_entry])){
286         $group = $this->objects[$s_entry];
287         if(count($group) == 1){
288           $s_action = "cut";
289           $i_entryID = $s_entry;
290           $s_entryType = key($group);
291         }else{
292           $this->dialog = new faiGroupHandle($group,"cut");
293         }
294       }
295     }elseif($s_action == "group_copy"){
296       if(isset($this->objects[$s_entry])){
297         $group = $this->objects[$s_entry];
298         if(count($group) == 1){
299           $s_action = "copy";
300           $i_entryID = $s_entry;
301           $s_entryType = key($group);
302         }else{
303           $this->dialog = new faiGroupHandle($group,"copy");
304         }
305       }
306     }
307     if($this->dialog instanceOf faiGroupHandle){
308       $this->dialog->save_object();
309       if($this->dialog->is_open()){
310         return($this->dialog->execute());
311       }elseif($this->dialog->is_canceled() || isset($_POST['cancel_lock'])){
312         $this->dialog = FALSE;
313       }else{
314         if(!count($this->dialog->get_selected())){
315           $this->dialog = FALSE;
316         }
317       }
318     }
320     /********************
321       Copy & Paste
322      ********************/
324     /* Display the copy & paste dialog, if it is currently open */
325     $ret = $this->copyPasteHandling_from_queue($s_action,$i_entryID,$s_entryType);
326     if($ret){
327       return($ret);
328     }
331     /********************
332       Delete MULTIPLE entries confirmed
333      ********************/
335     /* Confirmation for deletion has been passed. Users should be deleted. */
336     if (isset($_POST['delete_multiple_fai_object_confirm'])){
338       /* Find out more about the object type */
339       $ldap   = $this->config->get_ldap_link();
341       /* Remove user by user and check acls before removeing them */
342       foreach($this->dns as $key => $dn){
343         $ldap->cat($dn, array('objectClass'));
344         $attrs  = $ldap->fetch();
345         $type   = $this->get_type($attrs);
346         $acl  = $this->ui->get_permissions($dn,"fai/".$type[1]);
347         if(preg_match("/d/",$acl)){
348           $this->dialog = new $type[0]($this->config, $this->config->data['TABS'][$type[2]], $dn,"fai");
349           $this->dialog->parent = &$this;
350           $this->dialog->set_acl_base($dn);
351           $this->dialog->by_object[$type[1]]->remove_from_parent ();
352           $this->dialog= FALSE;
353           $to_del = FAI::clean_up_releases($dn);
354           FAI::save_release_changes_now();
355           foreach($to_del as $dn){
356             $ldap->rmdir_recursive($dn);
357           }
358         } else {
360           /* Normally this shouldn't be reached, send some extra
361              logs to notify the administrator */
362           msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
363           new log("security","fai/".get_class($this),$dn,array(),"Tried to trick deletion.");
364         }
365       }
367       /* Remove lock file after successfull deletion */
368       $this->remove_lock();
369       $this->dns = array();
370       $this->dialog = FALSE;
371     }
374     /****************
375       Delete confirme dialog 
376      ****************/
378     if ($s_action=="del_multiple" || $s_action == "remove" ||  
379         $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "remove"){
380  
381       /* Collect objects to delete and check if objects are freezed
382        */ 
383       $dns = array();
384       $errors = "";
385       $this->dns = array();
387       if($s_action == "remove"){
388         $to_delete =array($entry = $this->objects[$i_entryID][$s_entryType]);
389       }elseif($this->dialog instanceOf faiGroupHandle){
390         $to_delete = $this->dialog->get_selected();
391       }else{
392         $ids = $this->list_get_selected_items();
393         $to_delete = array();
394         foreach($ids as $id){
395           foreach($this->objects[$id] as $obj) { 
396             array_push($to_delete, $obj); 
397           } 
398         }
399       } 
401       foreach($to_delete as $obj){
402         if(isset($obj['type']) && in_array($obj['type'],array("opsi_netboot","opsi_local"))){
403           continue;
404         }
405         if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
406           $errors .= $obj['cn'].", ";
407         }else{
408           $this->dns[] = $obj['dn'];
409         }
410       }
412       if($errors != ""){
413         msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
414               "<br><br>".trim($errors,", ")),INFO_DIALOG);
415       }
417       /* Check locking 
418        */
419       if(count($this->dns)){
420         if ($user= get_multiple_locks($this->dns)){
421           return(gen_locked_message($user,$this->dns));
422         }
423         if(count($this->dns)){
424           $dns_names = array();
425           foreach($this->dns as $dn){
426             add_lock ($dn, $this->ui->dn);
427             $dns_names[] = LDAP::fix($dn);
428           }
429                                   $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
430           $smarty->assign("multiple", true);
431           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
432         }
433       }
434     }
438     /********************
439       Delete MULTIPLE entries Canceled
440      ********************/
442     /* Remove lock */
443     if(isset($_POST['delete_multiple_fai_object_cancel'])){
444       $this->remove_lock();
445       $this->dns = array();
446     }
448     /****************
449       Edit entry 
450      ****************/
452                 if($s_action == "edit" || $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "edit"){
454       $entry = array();
455       if($this->dialog instanceOf faiGroupHandle){
456         $entries = $this->dialog->get_selected();
457         $entry = array_pop($entries);
458       }elseif(isset($this->objects[$i_entryID][$s_entryType])){
459         $entry = $this->objects[$i_entryID][$s_entryType];
460       }
462       if(count($entry)){
463         $a_setup  = $this->get_type($entry);
465         /* Special handling for opsi products 
466          */
468         if(in_array($entry['type'],array("opsi_local","opsi_netboot")) && 
469             $this->opsi instanceof opsi && $this->opsi->enabled() ){
471           $name = $entry['cn'];
472           $cfg = $this->opsi->get_product_properties($name);
473           $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
474           if(isset($this->dialog->by_object['opsiProperties'])){
475             $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
476             $this->dialog->by_object['opsiProperties']->set_product($name);
477           }else{
478             trigger_error("Unknown tab, please check config.");
479           }
480         }elseif(count($a_setup)){
482           $this->dn = $entry['dn'];
483           /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
484           if (($user= get_lock($this->dn)) != ""){
485             return(gen_locked_message ($user, $this->dn, TRUE));
486           }
487           add_lock ($this->dn, $this->ui->dn);
489           $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
490           $this->dialog->parent = &$this;
491           $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
492           $this->dialog->set_acl_base($this->dn);
493           $this->is_dialog  = true;
494           set_object_info($this->dn);
495         }
496       }
497     }
500     /*  Branch handling 
501         09.01.2006
502     */
504     /****************
505       Remove branch
506      ****************/
508     /* Remove branch 
509      */
510     if($s_action == "remove_branch"){
511       $base= $this->fai_release;
513       /* Check if we have a post remove method configured
514        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
515        */
516       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
517         /* Load permissions for selected 'dn' and check if
518            we're allowed to remove this 'dn' */
519         if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
520           $smarty->assign("release_hidden",base64_encode($this->fai_release));
521           $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
522           return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
523         } else {
524           msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
525         }
526       }
527     }
529     
530     /****************
531       Remove branch confirmed
532      ****************/
534     if(isset($_POST['delete_branch_confirm'])){
536       /* Check if we have a post remove method configured
537        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
538        */
539       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
541         if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
542           msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
543         }else{
545           $bb =  $this->fai_release;
546           if(!isset($ldap)){
547             $ldap = $this->config->get_ldap_link();
548           }
550           $br = $this->getBranches();
552           if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
553             $name = $br[$bb];
555             $ldap->cd($bb);
556             $ldap->recursive_remove();
557             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
558             $ldap->recursive_remove();
559             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
560             $ldap->recursive_remove();
562             /* Search for all groups with configured application menus.
563               - First search all groups, to ensure that we only remove entries form whithin groups. 
564               - The search für menu configuration for the specified release and collect all those dns.
565               - Remove entries
566              */
567             $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
568             $ldap->cd($this->config->current['BASE']);
569             $ldap->search("(objectClass=posixGroup)",array("dn"));
570           
571             /* Collect all group dns 
572              */
573             $groups = array();
574             while($attrs = $ldap->fetch()){
575               $groups[] = $attrs['dn'];
576             }
578             /* Collect all group menu release dns that match the release we have removed 
579              */
580             $dns = array();
581             foreach($groups as $dn){
582               $ldap->cd($dn);
583               $ldap->search("(objectClass=FAIbranch)",array("dn"));
584               while($attrs = $ldap->fetch()){
585                 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
586                   $dns[] = $attrs['dn'];
587                 }
588               }
589             }
590             
591             /* Finally remove collected release dns 
592              */
593             foreach($dns as $dn){
594               $ldap->cd($dn);
595               $ldap->recursive_remove();
596             }
598             /* Post remove */
599             $this->fai_release = $this->fai_base;
600             $this->lock_name   = $name;
601             $this->lock_dn     = $bb;
602             $this->postremove();
604             $fai_filter = session::get("fai_filter");
605             $fai_filter['fai_release'] = $this->fai_release;
606             session::set("fai_filter",$fai_filter);
608             new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
609           }
610         }
611       }
612     }
615     /****************
616       Create a new branch "insert Name"
617      ****************/
619     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
620       session::set('LASTPOST',$_POST);
622       if($this->dispNewBranch){
623         $type = "branch";
624       }else{
625         $type = "freeze";
626       }
628       /* Check branch name */
629       $name = $_POST['BranchName'];
630       $is_ok = true;
631       $smarty->assign("BranchName",$name);
632       $base= $this->fai_base;
634       /* Check used characters */
635       if(!preg_match("/^[0-9a-z\.]*$/",$name)){
636         msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
637         $is_ok = false;
638       }
640       /* Check if this name is already in use */
641       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
642         msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
643         $is_ok = false;
644       }
646       if($is_ok){
648         if(session::is_set('LASTPOST')){
649           $LASTPOST = session::get('LASTPOST');
650         }else{
651           $LASTPOST = array();
652         }
653         $LASTPOST['base'] = $base;
654         $LASTPOST['type'] = $type;
655         session::set('LASTPOST',$LASTPOST);
656         $smarty->assign("iframe", true);
657         $smarty->assign("plugID", $_GET['plug']);
658         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
659         return($display);
660       }
661     }
664     /****************
665       Create a new branch 
666      ****************/
668     if(isset($_GET['PerformBranch'])){
669     
670       if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
671         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
672       }else{
674         /* In order to see error messages we have to reset the error handler.
675             Due to the exit(); 
676          */
677         restore_error_handler();
679         /* Create it know */
680         $this->dispNewBranch = false;
681         $this->dispNewFreeze = false;
683         $LASTPOST = session::get('LASTPOST');
684         $base = $LASTPOST['base'];
685         $_POST  = session::get('LASTPOST');      
686         $name = $_POST['BranchName'];
688         $type = $LASTPOST['type'];
689         $ldap = $this->config->get_ldap_link();
691         $baseToUse = $base;
692         if($this->fai_release !=  $this->fai_base){
693           $baseToUse = $this->fai_release;
694         }
696         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
698         $CurrentReleases  = $this->getBranches();
699         $NewReleaseName   = $name;
700         if(isset($CurrentReleases[$this->fai_release])) {
701           if($this->fai_release != $this->fai_base){
702             $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
703             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
704           }else{
705             $NewReleaseName   = $name;
706           }
707         }
709         $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse); 
710         $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ; 
712         $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse); 
713         $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ; 
715         /* Check if source depeartments exist */
716         foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
717           $ldap->cd($this->config->current['BASE']);
718           $ldap->cat($dep);
719           if(!$ldap->count()){
720             $ldap->create_missing_trees($dep);
721           }
722         }
724         /* Print header to have styles included */
725         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
726           <html>
727           <head>
728           <title></title>
729           <style type="text/css">@import url("themes/default/style.css");</style>
730           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
731           </head>
732           <body style="background: none;margin:3px;color:black">
733           ';
735         new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
737         /* Duplicate group application releases 
738          */
739         FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
741         /* Duplicate applications 
742          */
743         $ldap->cat($appsrc,array("dn")) ;
744         if($ldap->count()){
745           $ldap->cd ($appdst);
746           $ldap->recursive_remove();
747           FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
748         }
750         /* Duplicate mime types 
751          */
752         $ldap->cat($mimesrc,array("dn")) ;
753         if($ldap->count()){
754           $ldap->cd ($mimedst);
755           $ldap->recursive_remove();
756           FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
757         }
759         $attr = array();
760         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
761         $attr['ou']       = $name;
762         $attr['FAIstate'] = $type;
763         $ldap->cd($this->config->current['BASE']);
764         $ldap->cd("ou=".$name.",".$baseToUse);
765         $ldap->cat("ou=".$name.",".$baseToUse);
766         if($ldap->count()){
767           $ldap->modify($attr);
768         }else{
769           $ldap->add($attr);
770         }
772         /* Duplicate fai objects 
773          */
774         //      $ldap->cd ("ou=".$name.",".$baseToUse);
775         //      $ldap->recursive_remove();
776         //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
778         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
779           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
780           <input type='hidden' name='php_c_check' value='1'>
781           </form></div>";
783         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
785         /* Print footer to have valid html */
786         echo "</body></html>";
788         $this->dispNewFreeze = false; 
790         /* Postcreate */ 
792         /* Assign possible attributes */
793         $this->lock_type  = $type; 
794         $this->lock_name  = $name; 
795         $this->lock_dn    = $baseToUse;
796         $this->postcreate();
799         /* Send daemon event to reload the fai release database 
800          */
801         if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
802           $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
803           if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
804             $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
805             $tmp = new $evt['CLASS_NAME']($this->config);
806             $tmp->set_type(TRIGGERED_EVENT);
807             $tmp->add_targets(array("GOSA"));
808             $o_queue = new gosaSupportDaemon();
809             if(!$o_queue->append($tmp)){
810               msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
811             }
812           }
813         }else{  
814           trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
815           msg_dialog::display(_("Fatal error"),
816               "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
817               FATAL_ERROR_DIALOG);
818         }
819         exit();
820       }
821     }
823     /****************
824       Display dialog to enter new Branch name
825      ****************/
827     /* Check if we have a post create method configured
828      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
829      */
830     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
831       if(($s_action == "branch_branch")||($this->dispNewBranch)){
832         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
833           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
834         }else{
835           $this->dispNewBranch=true;
836           $smarty->assign("iframe",false);
837           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
838           return($display);
839         }
840       } 
841     }
843  
844     /****************
845       Display dialog to enter new Freeze name
846      ****************/
848     /* Check if we have a post create method configured
849      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
850      */
851     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
852       if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
853         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
854           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
855         }else{
856           $this->dispNewFreeze = true;
857           $smarty->assign("iframe",false);
858           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
859           return($display);
860         }
861       }
862     }
865     /****************
866       Create a new object 
867      ****************/
869     $types = array( "new_partition"     =>  "FAIpartitionTable",
870                     "new_script"        =>  "FAIscript",
871                     "new_hook"          =>  "FAIhook",
872                     "new_variable"      =>  "FAIvariable",
873                     "new_template"      =>  "FAItemplate",
874                     "new_package"       =>  "FAIpackageList");
875     $types_i18n = array( "new_partition"     =>  _("partition table"),
876                     "new_script"        =>  _("script"),
877                     "new_hook"          =>  _("hook"),
878                     "new_variable"      =>  _("variable"),
879                     "new_template"      =>  _("template"),
880                     "new_package"       =>  _("package list"));
882     if(isset($types[$s_action])){
884       $type_acl_mapping = array(
885           "FAIpartitionTable"  => "faiPartitionTable", 
886           "FAIpackageList"     => "faiPackage",
887           "FAIscript"          => "faiScript",
888           "FAIvariable"        => "faiVariable",
889           "FAIhook"            => "faiHook",
890           "FAIprofile"         => "faiProfile",
891           "FAItemplate"        => "faiTemplate");
893       $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$s_action]]);
894       if(preg_match("/c/",$acl)){
895         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
896         $this->dialog->parent = &$this;
897       }else{
898         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
899       }
900     }
902     /* New Profile */
903     if($s_action == "new_profile"){
904       $this->dn = "new" ;
906       $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
907       if(preg_match("/c/",$acl)){
908         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
909         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
910         $this->dialog->set_acl_base($this->base);
911         $this->dialog->parent = &$this;
913         $this->is_dialog = false;
914       }else{
915         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
916       }
917     }
920     /****************
921       Get name from ask_class_name dialog 
922      ****************/
924     if($s_action == "select_class_name_finished"){
925       $this->dialog->save_object();
926       if(count($this->dialog->check())!=0){
927         foreach($this->dialog->check() as $msg){
928           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
929         }               
930       }elseif(isset($this->dialog->objectClass)){
931         $this->dn = "new" ;
932         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
933         $name = $this->dialog->save();
935         if(class_exists($a_setup[0])){
936           $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
937           $this->dialog->set_acl_base($this->base);
938           $this->dialog->by_object[$a_setup[1]]->cn = $name;
939           $this->dialog->parent = &$this;
940           $this->is_dialog = true;
941         }
942       }         
943     }   
946     /****************
947      Cancel dialogs 
948      ****************/
950                 if(isset($_POST['edit_cancel'])){
951                         $this->dialog=FALSE;
952                         $this->is_dialog = false;
953                         set_object_info();
954       $this->remove_lock();
955                 }
958     /****************
959      Handle opsi dialogs  
960      ****************/
961       
962     if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
963       $this->dialog = NULL;
964     }
965     if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
966       $this->dialog->save_object();
967       $op    = $this->dialog->by_object['opsiProperties'];
968       $name  = $op->get_product();
969       $cfg   = $op->get_cfg();
970       $this->opsi->set_product_properties($name,$cfg);
971       if($this->opsi->is_error()){
972         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
973       }else{
974         $this->dialog = NULL;
975       }
976     }
977     if($this->dialog instanceof tabs_opsiProdConfig){
978       $this->dialog->save_object();
979       return($this->dialog->execute());
980     }
983     /****************
984       Save sub dialogs 
985      ****************/
987                 /* This check if the given tab could be saved 
988                  * If it was possible to save it, remove dialog object. 
989                  * If it wasn't possible, show errors and keep dialog.
990                  */
991                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
992                         $this->dialog->save_object();
993       $msgs= $this->dialog->check();
994                         if(count($msgs)!=0){
995                                 foreach($msgs as $msg){
996           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
997                                 }
998                         }else{
999                                 $this->dialog->save();
1000         FAI::save_release_changes_now();
1001         if (!isset($_POST['edit_apply'])){
1002           $this->remove_lock();
1003           $this->dialog=FALSE;
1004           $this->is_dialog=false;
1005           set_object_info();
1006         }else{
1008           /* Reinitialize tab */
1009           if($this->dialog instanceof tabs){
1010             $this->dialog->re_init();
1011           }
1012         }
1013                         }
1014                 }
1017     /****************
1018       Display currently open dialog 
1019      ****************/
1021                 /* If dialog is set, but $this->is_dialog==false, then 
1022                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
1023                  * If is_dialog == true, we are currently editing tab objects.
1024                  *  Here we need both, save and cancel
1025                  */ 
1027                 if(is_object($this->dialog)){
1028                         $display .= $this->dialog->execute();
1029                         /* Don't show buttons if tab dialog requests this */
1031       if(isset($this->dialog->current)){
1033         $obj = $this->dialog->by_object[$this->dialog->current];
1035         if(($this->dialog instanceOf tabs || $this->dialog instanceOf plugin) && $this->dialog->read_only == TRUE){
1036           $display.= "<p style=\"text-align:right\">
1037             <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1038             </p>";
1039         }elseif((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
1041           $display.= "<p style=\"text-align:right\">\n";
1042           if(!$this->no_save){
1043             $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1044             $display.= "&nbsp;\n";
1045             if ($this->dn != "new"){
1046               $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1047               $display.= "&nbsp;\n";
1048             }
1049           }
1050           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1051           $display.= "</p>";
1052         }elseif(!isset($this->dialog->current)){
1053           $display.= "<p style=\"text-align:right\">\n";
1054           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1055           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1056           $display.= "</p>";
1057         }
1058       }else{
1059         $display.= "<p style=\"text-align:right\">\n";
1060         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1061         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1062         $display.= "</p>";
1064       }
1065       return($display);
1066                 }
1067                 
1069     /****************
1070       Dialog display
1071      ****************/
1073     /* Check if there is a snapshot dialog open */
1074     $base = $this->fai_base;
1075     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1076       return($str);
1077     }
1079     /* Display dialog with system list */
1080     $this->reload();
1081     $this->DivListFai->parent = &$this;
1082     $this->DivListFai->execute();
1083     $this->DivListFai->setEntries($this->objects);
1084     return($this->DivListFai->Draw());
1085         }
1088   /* Return departments, that will be included within snapshot detection */
1089   function get_used_snapshot_bases()
1090   {
1091     $tmp = array();
1092     $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1093     foreach($types as $type){
1094       $tmp[] = get_ou($type).$this->fai_release;
1095     }
1096     return($tmp);
1097   }
1100   /* Get available branches for current base */
1101   function getBranches($base = false,$prefix = "")
1102   {
1103     $ret = array("/"=>$this->fai_base);
1104     $ldap = $this->config->get_ldap_link();
1105     if(!$base){
1106       $base = $this->fai_base;
1107     }
1108     $tmp = FAI::get_all_releases_from_base($base,true);
1109     foreach($tmp as $dn => $name){
1110       $ret[$name]=$dn;
1111     }
1112     ksort($ret);
1113     $ret = array_flip($ret);
1115     return ($ret);
1116   }
1117   
1119   function list_get_selected_items()
1120   {
1121     $ids = array();
1122     foreach($_POST as $name => $value){
1123       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1124         $id   = preg_replace("/^item_selected_/","",$name);
1125         $ids[$id] = $id;
1126       }
1127     }
1128     return($ids);
1129   }
1132   /* reload list of objects */
1133   function reload()
1134   {
1135     /* Variable initialisation */
1136     $str            = "";
1137     $Regex          = $this->DivListFai->Regex;
1138     $this->objects  = array();
1140     /* Get base */
1141     $base = $this->fai_base;
1142     if($this->fai_release != $this->fai_base){
1143       $br = $this->getBranches();
1144       if(isset($br[$this->fai_release])){
1145         $base = $this->fai_release;
1146       }else{
1147         $base = $this->fai_base;
1148       }
1149     }
1150     $this->base = $base;
1151     $this->set_acl_base($this->acl_base);
1153     $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1155     /* Create a new list of FAI object 
1156      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
1157      */
1158     $ObjectTypes = array(
1159         "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
1160         "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
1161         "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
1162         "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
1163         "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
1164         "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
1165         "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
1167     $filter = "";
1168     foreach($ObjectTypes as $key => $data){
1169       if($this->DivListFai->$data['CHKBOX']){
1170         $filter.= "(objectClass=".$key.")";
1171       }
1172     }
1173     $filter = "(&(|".$filter.")(cn=$Regex))";
1174     
1175     /* Get resolved release dependencies */
1176     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1178     /* Ge listed ldap objects */
1179     $ldap = $this->config->get_ldap_link();
1180     $ldap->cd($this->config->current['BASE']);
1182     foreach($tmp as $entry){
1184       /* Get some more informations about the object */ 
1185       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1186       $object  = $ldap->fetch();
1188       /* Walk through possible types */
1189       foreach($ObjectTypes as $type => $rest){  
1191         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1193         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1195           /* Prepare object */
1196           unset($object['objectClass']['count']);
1197           if(!isset($object['description'][0])){
1198             $object['description'][0]="";
1199           }
1201           /* Clean up object informations */
1202           $obj                  = array();
1203           $obj['cn']                          = $object['cn'][0];
1204           $obj['dn']                          = $object['dn'];
1205           $obj['acl']                       = $acl;
1206           $obj['class']                           = $rest ['ACL'];
1207           $obj['FAIstate']      = $entry['FAIstate'];
1208           $obj['description']   = $object['description'][0];
1209           $obj['objectClass']   = $object['objectClass'];
1211           $this->objects[$obj['cn']][$type] = $obj;
1212           $this->objects[$obj['cn']][$type]['type']=$type;
1213         }
1214                         }
1215                 }
1217     /*  Append opsi objects, if opsi is available and if we are on the fai_base
1218      */
1219     if($this->opsi instanceof opsi && $this->opsi->enabled()){  
1220       $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1221       if(preg_match("/r/",$opsi_acl)){
1222         $err = FALSE;
1223         if(!$err && $this->DivListFai->ShowOpsiNetboot){
1224           $n_pro = $this->opsi->get_netboot_products();
1225           $err |= $this->opsi->is_error();
1226           foreach($n_pro as $name => $data){
1227             $entry = array(
1228                 "cn" => $name,
1229                 "description" => $data['DESC'],
1230                 "type" => "opsi_netboot");
1231             $this->objects[$name]['opsi_netboot'] = $entry;
1232           }  
1233         }
1234         if(!$err && $this->DivListFai->ShowOpsiLocal){
1235           $l_pro = $this->opsi->get_local_products();
1236           $err |= $this->opsi->is_error();
1237           foreach($l_pro as $name => $data){
1238             $entry = array("cn" => $name,
1239                 "description" => $data['DESC'],
1240                 "type" => "opsi_local");
1241             $this->objects[$name]["opsi_local"] = $entry;
1242           }  
1243         }  
1244         if($err){
1245           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1246         }
1247       }
1248     }
1249  
1250     uksort($this->objects, 'strnatcasecmp');
1251                 reset ($this->objects);
1252                 $this->objects = array_values($this->objects);
1253         }
1255         function remove_lock()
1256         {
1257                 if (isset($this->dn) && !empty($this->dn)){
1258                         del_lock ($this->dn);
1259                 }
1260     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1261       del_lock ($this->dns);
1262     }
1263         }
1265         function get_type($array){
1266     if(!isset($array['objectClass'])) return(array());
1267                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1268                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1269                 }
1270                 if(in_array("FAIscript",$array['objectClass'])){
1271                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1272                 }
1273                 if(in_array("FAItemplate",$array['objectClass'])){
1274                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1275                 }
1276                 if(in_array("FAIhook",$array['objectClass'])){
1277                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1278                 }
1279                 if(in_array("FAIvariable",$array['objectClass'])){
1280                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1281                 }
1282                 if(in_array("FAIprofile",$array['objectClass'])){
1283                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1284                 }
1285                 
1286                 if(in_array("FAIpackageList",$array['objectClass'])){
1287                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1288                 }
1289     return(array());
1290         }
1292   function CheckNewBranchName($name,$base)
1293   {
1294     $f = $this->fai_release;
1295     if($name == ""){
1296       return(false);
1297     }elseif(in_array($name,$this->getBranches($f))) {
1298       return(false);
1299     }elseif(tests::is_department_name_reserved($name,$base)){
1300       return(false);
1301     }
1302     return(true);
1303   }
1305   function save_object()
1306   {
1307     $this->DivListFai->save_object();
1309     /* Get posted release */
1310     $r_releases = array_flip($this->getBranches());
1311     if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1313       /* Ensure that we have a valid release selected */
1314       if(!isset($r_releases[get_post('fai_release')])){
1315         msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1316         $_POST = array();
1317         $plug =$_GET['plug'];
1318         $_GET  = array("plug" => $plug);
1319         $this->fai_release = $this->fai_base;
1320       }else{
1321         $this->fai_release = $r_releases[get_post('fai_release')];
1322       }
1324       $fai_filter = session::get("fai_filter");
1325       $fai_filter['fai_release'] = $this->fai_release;
1326       session::set("fai_filter",$fai_filter);
1327     }
1329     if(is_object($this->CopyPasteHandler)){
1330       $this->CopyPasteHandler->save_object();
1331     }
1332   }
1335   function copyPasteHandling_from_queue($s_action,$i_entryID,$s_entryType)
1336   {
1337     /* Check if Copy & Paste is disabled */
1338     if(!is_object($this->CopyPasteHandler)){
1339       return("");
1340     }
1342     $ui = get_userinfo();
1344     // Copy a single entry
1345     if($s_action == "copy"){
1346       $entry = $this->objects[$i_entryID][$s_entryType];
1347       $this->CopyPasteHandler->cleanup_queue();
1348       $a_setup  = $this->get_type($entry);
1349       $dn = $entry['dn'];
1350       if($ui->is_copyable($dn,"fai",$a_setup[1])){
1351         $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");
1352       }
1353     }
1355     // cut a single entry
1356     if($s_action == "cut"){
1357       $entry = $this->objects[$i_entryID][$s_entryType];
1358       $this->CopyPasteHandler->cleanup_queue();
1359       $a_setup  = $this->get_type($entry);
1360       $dn = $entry['dn'];
1361       if($ui->is_copyable($dn,"fai",$a_setup[1])){
1362         $this->CopyPasteHandler->add_to_queue($dn,"cut",$a_setup[0],$a_setup[2],"fai");
1363       }
1364     }
1366     /* Add a entries from the group selection to queue */
1367     if($this->dialog instanceOf faiGroupHandle && !$this->dialog->is_open()){
1369       if(in_array($this->dialog->get_mode(),array("copy"))){      
1371         /* Cleanup object queue */
1372         $this->CopyPasteHandler->cleanup_queue();
1373         $group = $this->dialog->get_selected();
1374         foreach($group as $entry){
1375           $a_setup  = $this->get_type($entry);
1376           $dn = $entry['dn'];
1377           if($ui->is_copyable($dn,"fai",$a_setup[1])){
1378             $this->CopyPasteHandler->add_to_queue($dn,$this->dialog->get_mode(),$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1379           }
1380         }
1381         $this->dialog = FALSE;
1382       }
1383     }
1385     /* Add entries to queue */
1386     if($s_action == "copy_multiple"){
1388       /* Cleanup object queue */
1389       $this->CopyPasteHandler->cleanup_queue();
1391       /* Add new entries to CP queue */
1392       foreach($this->list_get_selected_items() as $id){
1393         $group    = $this->objects[$id];
1394         foreach($group as $entry){
1395           $a_setup  = $this->get_type($entry);
1396           $dn = $entry['dn'];
1398           if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1399             $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1400           }
1401         }
1402       }
1403     }
1405     /* Start pasting entries */
1406     if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1407       $this->start_pasting_copied_objects = TRUE;
1408     }
1410     /* Return C&P dialog */
1411     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1413       /* Get dialog */
1414       $this->CopyPasteHandler->SetVar("parent",$this);
1415       $data = $this->CopyPasteHandler->execute();
1417       FAI::save_release_changes_now();
1419       /* Return dialog data */
1420       if(!empty($data)){
1421         return($data);
1422       }
1423     }
1425     /* Automatically disable status for pasting */
1426     if(!$this->CopyPasteHandler->entries_queued()){
1427       $this->start_pasting_copied_objects = FALSE;
1428     }
1429     return("");
1430   }
1433   /* Check if the given FAI class is used in this release 
1434    */
1435   static function check_class_name($oc,$name,$dn)
1436   {
1437     $base = FAI::get_release_dn($dn);
1439     if($oc == "FAIprofile"){
1440       $f = "";
1441       $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1442       foreach($ocs as $oc){
1443         $f .= "(objectClass=".$oc.")";
1444       } 
1445       $res  = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);    
1446     }else{
1447       $res  = FAI::get_all_objects_for_given_base($base,"(objectClass=".$oc.")",TRUE);
1448     }
1449     $delete = array();
1450     $used   = array();
1451     foreach($res as $object){
1452       $used[$object['cn'][0]]= $object['cn'][0];
1453     }
1454     return($used);
1455   }
1458   /* Return plugin informations for acl handling */ 
1459   static function plInfo()
1460   {
1461     return (array( 
1462           "plShortName"   => _("FAI releases"),
1463           "plDescription" => _("FAI release management"),
1464           "plSelfModify"  => FALSE,
1465           "plDepends"     => array(),
1466           "plPriority"    => 0,
1467           "plSection"     => array("administration"),           
1468           "plCategory"    => array("fai"=> array("description" => _("FAI"),
1469                                                  "objectClass" => "FAIclass")),
1470           "plProvidedAcls"=> array()));
1471   }
1473 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1474 ?>