Code

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