Code

31c3aec890e89f6d37851207de302ed3c5aef74d
[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 && $this->dialog->get_mode() == "remove"){
361  
362       /* Collect objects to delete and check if objects are freezed
363        */ 
364       $dns = array();
365       $errors = "";
366       $this->dns = array();
367       if($this->dialog instanceOf faiGroupHandle){
368         $to_delete = $this->dialog->get_selected();
369       }else{
370         $ids = $this->list_get_selected_items();
371         $to_delete = array();
372         foreach($ids as $id){
373           foreach($this->objects[$id] as $obj) {
374             array_push($to_delete, $obj);
375           }
376         }
377       } 
379       foreach($to_delete as $obj){
380         if(isset($obj['type']) && in_array($obj['type'],array("opsi_netboot","opsi_local"))){
381           continue;
382         }
383         if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
384           $errors .= $obj['cn'].", ";
385         }else{
386           $this->dns[] = $obj['dn'];
387         }
388       }
390       if($errors != ""){
391         msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
392               "<br><br>".trim($errors,", ")),INFO_DIALOG);
393       }
395       /* Check locking 
396        */
397       if(count($this->dns)){
398         if ($user= get_multiple_locks($this->dns)){
399           return(gen_locked_message($user,$this->dns));
400         }
401         if(count($this->dns)){
402           $dns_names = array();
403           foreach($this->dns as $dn){
404             add_lock ($dn, $this->ui->dn);
405             $dns_names[] = LDAP::fix($dn);
406           }
407                                   $smarty->assign("warning",msgPool::deleteInfo($dns_names,_("FAI object")));
408           $smarty->assign("multiple", true);
409           return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
410         }
411       }
412     }
416     /********************
417       Delete MULTIPLE entries Canceled
418      ********************/
420     /* Remove lock */
421     if(isset($_POST['delete_multiple_fai_object_cancel'])){
422       $this->remove_lock();
423       $this->dns = array();
424     }
426     /****************
427       Edit entry 
428      ****************/
430                 if($s_action == "edit" || $this->dialog instanceOf faiGroupHandle && $this->dialog->get_mode() == "edit"){
432       $entry = array();
433       if($this->dialog instanceOf faiGroupHandle){
434         $entries = $this->dialog->get_selected();
435         $entry = array_pop($entries);
436       }elseif(isset($this->objects[$i_entryID][$s_entryType])){
437         $entry = $this->objects[$i_entryID][$s_entryType];
438       }
440       if(count($entry)){
441         $a_setup  = $this->get_type($entry);
443         /* Special handling for opsi products 
444          */
446         if(in_array($entry['type'],array("opsi_local","opsi_netboot")) && 
447             $this->opsi instanceof opsi && $this->opsi->enabled() ){
449           $name = $entry['cn'];
450           $cfg = $this->opsi->get_product_properties($name);
451           $this->dialog = new tabs_opsiProdConfig($this->config, $this->config->data['TABS']['OPSIPRODCONFIG'],"","opsi");
452           if(isset($this->dialog->by_object['opsiProperties'])){
453             $this->dialog->by_object['opsiProperties']->set_cfg($cfg);
454             $this->dialog->by_object['opsiProperties']->set_product($name);
455           }else{
456             trigger_error("Unknown tab, please check config.");
457           }
458         }elseif(count($a_setup)){
460           $this->dn = $entry['dn'];
461           /* Check locking, save current plugin in 'back_plugin', so the dialog knows where to return. */
462           if (($user= get_lock($this->dn)) != ""){
463             return(gen_locked_message ($user, $this->dn, TRUE));
464           }
465           add_lock ($this->dn, $this->ui->dn);
467           $this->dialog     = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
468           $this->dialog->parent = &$this;
469           $this->dialog->by_object[$a_setup[1]]->FAIstate = $entry['FAIstate'];
470           $this->dialog->set_acl_base($this->dn);
471           $this->is_dialog  = true;
472           set_object_info($this->dn);
473         }
474       }
475     }
478     /*  Branch handling 
479         09.01.2006
480     */
482     /****************
483       Remove branch
484      ****************/
486     /* Remove branch 
487      */
488     if($s_action == "remove_branch"){
489       $base= $this->fai_release;
491       /* Check if we have a post remove method configured
492        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
493        */
494       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
495         /* Load permissions for selected 'dn' and check if
496            we're allowed to remove this 'dn' */
497         if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
498           $smarty->assign("release_hidden",base64_encode($this->fai_release));
499           $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
500           return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
501         } else {
502           msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
503         }
504       }
505     }
507     
508     /****************
509       Remove branch confirmed
510      ****************/
512     if(isset($_POST['delete_branch_confirm'])){
514       /* Check if we have a post remove method configured
515        *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
516        */
517       if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
519         if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
520           msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
521         }else{
523           $bb =  $this->fai_release;
524           if(!isset($ldap)){
525             $ldap = $this->config->get_ldap_link();
526           }
528           $br = $this->getBranches();
530           if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
531             $name = $br[$bb];
533             $ldap->cd($bb);
534             $ldap->recursive_remove();
535             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('applicationRDN'), $bb));
536             $ldap->recursive_remove();
537             $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/', ','.get_ou('mimetypeRDN'), $bb));
538             $ldap->recursive_remove();
540             /* Search for all groups with configured application menus.
541               - First search all groups, to ensure that we only remove entries form whithin groups. 
542               - The search für menu configuration for the specified release and collect all those dns.
543               - Remove entries
544              */
545             $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/","",$bb);
546             $ldap->cd($this->config->current['BASE']);
547             $ldap->search("(objectClass=posixGroup)",array("dn"));
548           
549             /* Collect all group dns 
550              */
551             $groups = array();
552             while($attrs = $ldap->fetch()){
553               $groups[] = $attrs['dn'];
554             }
556             /* Collect all group menu release dns that match the release we have removed 
557              */
558             $dns = array();
559             foreach($groups as $dn){
560               $ldap->cd($dn);
561               $ldap->search("(objectClass=FAIbranch)",array("dn"));
562               while($attrs = $ldap->fetch()){
563                 if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
564                   $dns[] = $attrs['dn'];
565                 }
566               }
567             }
568             
569             /* Finally remove collected release dns 
570              */
571             foreach($dns as $dn){
572               $ldap->cd($dn);
573               $ldap->recursive_remove();
574             }
576             /* Post remove */
577             $this->fai_release = $this->fai_base;
578             $this->lock_name   = $name;
579             $this->lock_dn     = $bb;
580             $this->postremove();
582             $fai_filter = session::get("fai_filter");
583             $fai_filter['fai_release'] = $this->fai_release;
584             session::set("fai_filter",$fai_filter);
586             new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
587           }
588         }
589       }
590     }
593     /****************
594       Create a new branch "insert Name"
595      ****************/
597     if((isset($_POST['UseBranchName']))&&(($this->dispNewBranch)||($this->dispNewFreeze))){
598       session::set('LASTPOST',$_POST);
600       if($this->dispNewBranch){
601         $type = "branch";
602       }else{
603         $type = "freeze";
604       }
606       /* Check branch name */
607       $name = $_POST['BranchName'];
608       $is_ok = true;
609       $smarty->assign("BranchName",$name);
610       $base= $this->fai_base;
612       /* Check used characters */
613       if(!preg_match("/^[0-9a-z\.]*$/",$name)){
614         msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
615         $is_ok = false;
616       }
618       /* Check if this name is already in use */
619       if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
620         msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
621         $is_ok = false;
622       }
624       if($is_ok){
626         if(session::is_set('LASTPOST')){
627           $LASTPOST = session::get('LASTPOST');
628         }else{
629           $LASTPOST = array();
630         }
631         $LASTPOST['base'] = $base;
632         $LASTPOST['type'] = $type;
633         session::set('LASTPOST',$LASTPOST);
634         $smarty->assign("iframe", true);
635         $smarty->assign("plugID", $_GET['plug']);
636         $display        = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
637         return($display);
638       }
639     }
642     /****************
643       Create a new branch 
644      ****************/
646     if(isset($_GET['PerformBranch'])){
647     
648       if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
649         msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
650       }else{
652         /* In order to see error messages we have to reset the error handler.
653             Due to the exit(); 
654          */
655         restore_error_handler();
657         /* Create it know */
658         $this->dispNewBranch = false;
659         $this->dispNewFreeze = false;
661         $LASTPOST = session::get('LASTPOST');
662         $base = $LASTPOST['base'];
663         $_POST  = session::get('LASTPOST');      
664         $name = $_POST['BranchName'];
666         $type = $LASTPOST['type'];
667         $ldap = $this->config->get_ldap_link();
669         $baseToUse = $base;
670         if($this->fai_release !=  $this->fai_base){
671           $baseToUse = $this->fai_release;
672         }
674         /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
676         $CurrentReleases  = $this->getBranches();
677         $NewReleaseName   = $name;
678         if(isset($CurrentReleases[$this->fai_release])) {
679           if($this->fai_release != $this->fai_base){
680             $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
681             $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName); 
682           }else{
683             $NewReleaseName   = $name;
684           }
685         }
687         $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),$baseToUse); 
688         $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ; 
690         $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),$baseToUse); 
691         $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ; 
693         /* Check if source depeartments exist */
694         foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
695           $ldap->cd($this->config->current['BASE']);
696           $ldap->cat($dep);
697           if(!$ldap->count()){
698             $ldap->create_missing_trees($dep);
699           }
700         }
702         /* Print header to have styles included */
703         echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
704           <html>
705           <head>
706           <title></title>
707           <style type="text/css">@import url("themes/default/style.css");</style>
708           <script language="javascript" src="include/focus.js" type="text/javascript"></script>
709           </head>
710           <body style="background: none;margin:3px;color:black">
711           ';
713         new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
715         /* Duplicate group application releases 
716          */
717         FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
719         /* Duplicate applications 
720          */
721         $ldap->cat($appsrc,array("dn")) ;
722         if($ldap->count()){
723           $ldap->cd ($appdst);
724           $ldap->recursive_remove();
725           FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
726         }
728         /* Duplicate mime types 
729          */
730         $ldap->cat($mimesrc,array("dn")) ;
731         if($ldap->count()){
732           $ldap->cd ($mimedst);
733           $ldap->recursive_remove();
734           FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
735         }
737         $attr = array();
738         $attr['objectClass'] = array("organizationalUnit","FAIbranch");
739         $attr['ou']       = $name;
740         $attr['FAIstate'] = $type;
741         $ldap->cd($this->config->current['BASE']);
742         $ldap->cd("ou=".$name.",".$baseToUse);
743         $ldap->cat("ou=".$name.",".$baseToUse);
744         if($ldap->count()){
745           $ldap->modify($attr);
746         }else{
747           $ldap->add($attr);
748         }
750         /* Duplicate fai objects 
751          */
752         //      $ldap->cd ("ou=".$name.",".$baseToUse);
753         //      $ldap->recursive_remove();
754         //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
756         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
757           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
758           <input type='hidden' name='php_c_check' value='1'>
759           </form></div>";
761         echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
763         /* Print footer to have valid html */
764         echo "</body></html>";
766         $this->dispNewFreeze = false; 
768         /* Postcreate */ 
770         /* Assign possible attributes */
771         $this->lock_type  = $type; 
772         $this->lock_name  = $name; 
773         $this->lock_dn    = $baseToUse;
774         $this->postcreate();
777         /* Send daemon event to reload the fai release database 
778          */
779         if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
780           $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
781           if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
782             $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
783             $tmp = new $evt['CLASS_NAME']($this->config);
784             $tmp->set_type(TRIGGERED_EVENT);
785             $tmp->add_targets(array("GOSA"));
786             $o_queue = new gosaSupportDaemon();
787             if(!$o_queue->append($tmp)){
788               msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
789             }
790           }
791         }else{  
792           trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
793           msg_dialog::display(_("Fatal error"),
794               "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
795               FATAL_ERROR_DIALOG);
796         }
797         exit();
798       }
799     }
801     /****************
802       Display dialog to enter new Branch name
803      ****************/
805     /* Check if we have a post create method configured
806      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
807      */
808     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
809       if(($s_action == "branch_branch")||($this->dispNewBranch)){
810         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
811           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
812         }else{
813           $this->dispNewBranch=true;
814           $smarty->assign("iframe",false);
815           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
816           return($display);
817         }
818       } 
819     }
821  
822     /****************
823       Display dialog to enter new Freeze name
824      ****************/
826     /* Check if we have a post create method configured
827      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
828      */
829     if("" != $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'))){
830       if(($s_action == "freeze_branch")||($this->dispNewFreeze)){
831         if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
832           msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
833         }else{
834           $this->dispNewFreeze = true;
835           $smarty->assign("iframe",false);
836           $display      .= $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
837           return($display);
838         }
839       }
840     }
843     /****************
844       Create a new object 
845      ****************/
847     $types = array( "new_partition"     =>  "FAIpartitionTable",
848                     "new_script"        =>  "FAIscript",
849                     "new_hook"          =>  "FAIhook",
850                     "new_variable"      =>  "FAIvariable",
851                     "new_template"      =>  "FAItemplate",
852                     "new_package"       =>  "FAIpackageList");
853     $types_i18n = array( "new_partition"     =>  _("partition table"),
854                     "new_script"        =>  _("script"),
855                     "new_hook"          =>  _("hook"),
856                     "new_variable"      =>  _("variable"),
857                     "new_template"      =>  _("template"),
858                     "new_package"       =>  _("package list"));
860     if(isset($types[$s_action])){
862       $type_acl_mapping = array(
863           "FAIpartitionTable"  => "faiPartitionTable", 
864           "FAIpackageList"     => "faiPackage",
865           "FAIscript"          => "faiScript",
866           "FAIvariable"        => "faiVariable",
867           "FAIhook"            => "faiHook",
868           "FAIprofile"         => "faiProfile",
869           "FAItemplate"        => "faiTemplate");
871       $acl = $this->ui->get_permissions($this->acl_base,"fai/".$type_acl_mapping[$types[$s_action]]);
872       if(preg_match("/c/",$acl)){
873         $this->dialog = new askClassName($this->config,$this->dn,$this->ui,$types[$s_action]);
874         $this->dialog->parent = &$this;
875       }else{
876         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), $types_i18n[$s_action]), ERROR_DIALOG);
877       }
878     }
880     /* New Profile */
881     if($s_action == "new_profile"){
882       $this->dn = "new" ;
884       $acl = $this->ui->get_permissions($this->acl_base,"fai/faiProfile");
885       if(preg_match("/c/",$acl)){
886         $a_setup= $this->get_type(array("objectClass"=>array("FAIprofile")));
887         $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
888         $this->dialog->set_acl_base($this->acl_base);
889         $this->dialog->parent = &$this;
891         $this->is_dialog = false;
892       }else{
893         msg_dialog::display(_("Permission error"), sprintf(_("You have no permission to create a new %s!"), _("profile")), ERROR_DIALOG);
894       }
895     }
898     /****************
899       Get name from ask_class_name dialog 
900      ****************/
902     if($s_action == "select_class_name_finished"){
903       $this->dialog->save_object();
904       if(count($this->dialog->check())!=0){
905         foreach($this->dialog->check() as $msg){
906           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
907         }               
908       }elseif(isset($this->dialog->objectClass)){
909         $this->dn = "new" ;
910         $a_setup= $this->get_type(array("objectClass"=>array($this->dialog->objectClass)));
911         $name = $this->dialog->save();
913         if(class_exists($a_setup[0])){
914           $this->dialog = new $a_setup[0]($this->config,$this->config->data['TABS'][$a_setup[2]],$this->dn,"fai");
915           $this->dialog->set_acl_base($this->acl_base);
916           $this->dialog->by_object[$a_setup[1]]->cn = $name;
917           $this->dialog->parent = &$this;
918           $this->is_dialog = true;
919         }
920       }         
921     }   
924     /****************
925      Cancel dialogs 
926      ****************/
928                 if(isset($_POST['edit_cancel'])){
929                         $this->dialog=FALSE;
930                         $this->is_dialog = false;
931                         set_object_info();
932       $this->remove_lock();
933                 }
936     /****************
937      Handle opsi dialogs  
938      ****************/
939       
940     if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['cancel_properties'])){
941       $this->dialog = NULL;
942     }
943     if($this->dialog instanceof tabs_opsiProdConfig && isset($_POST['save_properties'])){
944       $this->dialog->save_object();
945       $op    = $this->dialog->by_object['opsiProperties'];
946       $name  = $op->get_product();
947       $cfg   = $op->get_cfg();
948       $this->opsi->set_product_properties($name,$cfg);
949       if($this->opsi->is_error()){
950         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
951       }else{
952         $this->dialog = NULL;
953       }
954     }
955     if($this->dialog instanceof tabs_opsiProdConfig){
956       $this->dialog->save_object();
957       return($this->dialog->execute());
958     }
961     /****************
962       Save sub dialogs 
963      ****************/
965                 /* This check if the given tab could be saved 
966                  * If it was possible to save it, remove dialog object. 
967                  * If it wasn't possible, show errors and keep dialog.
968                  */
969                 if((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->dialog->config))){
970                         $this->dialog->save_object();
971       $msgs= $this->dialog->check();
972                         if(count($msgs)!=0){
973                                 foreach($msgs as $msg){
974           msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
975                                 }
976                         }else{
977                                 $this->dialog->save();
978         FAI::save_release_changes_now();
979         $to_del = FAI::clean_up_releases($this->dn, false);
980         $ldap = $this->config->get_ldap_link();
981         $ldap->cd($this->dn);
982         foreach($to_del as $dn){
983           /* Only delete subobjects of the current FAI class */
984           $ldap->cd($this->dn);
985           $ldap->search("(|(objectClass=FAIclass)(objectClass=FAIdebconfInfo))", array('dn'));
986           if ($ldap->count()){
987             while($attrs = $ldap->fetch()){
988               if ($attrs['dn'] == $dn) {
989                 $ldap->rmdir_recursive($dn);
990               }
991             }
992           }
993         }
994         if (!isset($_POST['edit_apply'])){
995           $this->remove_lock();
996           $this->dialog=FALSE;
997           $this->is_dialog=false;
998           set_object_info();
999         }else{
1001           /* Reinitialize tab */
1002           if($this->dialog instanceof tabs){
1003             $this->dialog->re_init();
1004           }
1005         }
1006                         }
1007                 }
1010     /****************
1011       Display currently open dialog 
1012      ****************/
1014                 /* If dialog is set, but $this->is_dialog==false, then 
1015                  *  only the "abort" button is shown, this are dialogs that must not be saved.  
1016                  * If is_dialog == true, we are currently editing tab objects.
1017                  *  Here we need both, save and cancel
1018                  */ 
1020                 if(is_object($this->dialog)){
1021                         $display .= $this->dialog->execute();
1022                         /* Don't show buttons if tab dialog requests this */
1024       if(isset($this->dialog->current)){
1026         $obj = $this->dialog->by_object[$this->dialog->current];
1028         if(($this->dialog instanceOf tabs || $this->dialog instanceOf plugin) && $this->dialog->read_only == TRUE){
1029           $display.= "<p style=\"text-align:right\">
1030             <input type=submit name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">
1031             </p>";
1032         }elseif((isset($obj->is_dialog) && (!$obj->is_dialog)) || (isset($obj->dialog) && (!$obj->dialog))){
1034           $display.= "<p style=\"text-align:right\">\n";
1035           if(!$this->no_save){
1036             $display.= "<input type=\"submit\" name=\"edit_finish\" style=\"width:80px\" value=\"".msgPool::okButton()."\">\n";
1037             $display.= "&nbsp;\n";
1038             if ($this->dn != "new"){
1039               $display.= "<input type=submit name=\"edit_apply\" value=\"".msgPool::applyButton()."\">\n";
1040               $display.= "&nbsp;\n";
1041             }
1042           }
1043           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1044           $display.= "</p>";
1045         }elseif(!isset($this->dialog->current)){
1046           $display.= "<p style=\"text-align:right\">\n";
1047           $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1048           $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1049           $display.= "</p>";
1050         }
1051       }else{
1052         $display.= "<p style=\"text-align:right\">\n";
1053         $display.= "<input type=\"submit\" name=\"edit_continue\" value=\""._("Continue")."\">&nbsp;";
1054         $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\"".msgPool::cancelButton()."\">\n";
1055         $display.= "</p>";
1057       }
1058       return($display);
1059                 }
1060                 
1062     /****************
1063       Dialog display
1064      ****************/
1066     /* Check if there is a snapshot dialog open */
1067     $base = $this->fai_base;
1068     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases(),$this)){
1069       return($str);
1070     }
1072     /* Display dialog with system list */
1073     $this->reload();
1074     $this->DivListFai->parent = &$this;
1075     $this->DivListFai->execute();
1076     $this->DivListFai->setEntries($this->objects);
1077     return($this->DivListFai->Draw());
1078         }
1081   /* Return departments, that will be included within snapshot detection */
1082   function get_used_snapshot_bases()
1083   {
1084     $tmp = array();
1085     $types = array("faiPartitionRDN","faiScriptRDN","faiTemplateRDN","faiHookRDN","faiProfileRDN","faiVariableRDN","faiPackageRDN");
1086     foreach($types as $type){
1087       $tmp[] = get_ou($type).$this->fai_release;
1088     }
1089     return($tmp);
1090   }
1093   /* Get available branches for current base */
1094   function getBranches($base = false,$prefix = "")
1095   {
1096     $ret = array("/"=>$this->fai_base);
1097     $ldap = $this->config->get_ldap_link();
1098     if(!$base){
1099       $base = $this->fai_base;
1100     }
1101     $tmp = FAI::get_all_releases_from_base($base,true);
1102     foreach($tmp as $dn => $name){
1103       $ret[$name]=$dn;
1104     }
1105     ksort($ret);
1106     $ret = array_flip($ret);
1108     return ($ret);
1109   }
1110   
1112   function list_get_selected_items()
1113   {
1114     $ids = array();
1115     foreach($_POST as $name => $value){
1116       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1117         $id   = preg_replace("/^item_selected_/","",$name);
1118         $ids[$id] = $id;
1119       }
1120     }
1121     return($ids);
1122   }
1125   /* reload list of objects */
1126   function reload()
1127   {
1128     /* Variable initialisation */
1129     $str            = "";
1130     $Regex          = $this->DivListFai->Regex;
1131     $this->objects  = array();
1133     /* Get base */
1134     $base = $this->fai_base;
1135     if($this->fai_release != $this->fai_base){
1136       $br = $this->getBranches();
1137       if(isset($br[$this->fai_release])){
1138         $base = $this->fai_release;
1139       }else{
1140         $base = $this->fai_base;
1141       }
1142     }
1143     $this->base = $base;
1144     $this->set_acl_base($this->acl_base);
1146     $this->lock_type = FAI::get_release_tag(FAI::get_release_dn($base));
1148     /* Create a new list of FAI object 
1149      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ... 
1150      */
1151     $ObjectTypes = array(
1152         "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
1153         "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
1154         "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
1155         "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
1156         "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
1157         "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
1158         "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
1160     $filter = "";
1161     foreach($ObjectTypes as $key => $data){
1162       if($this->DivListFai->$data['CHKBOX']){
1163         $filter.= "(objectClass=".$key.")";
1164       }
1165     }
1166     $filter = "(&(|".$filter.")(cn=$Regex))";
1167     
1168     /* Get resolved release dependencies */
1169     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
1171     /* Ge listed ldap objects */
1172     $ldap = $this->config->get_ldap_link();
1173     $ldap->cd($this->config->current['BASE']);
1175     foreach($tmp as $entry){
1177       /* Get some more informations about the object */ 
1178       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
1179       $object  = $ldap->fetch();
1181       /* Walk through possible types */
1182       foreach($ObjectTypes as $type => $rest){  
1184         $acl = $this->ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
1186         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
1188           /* Prepare object */
1189           unset($object['objectClass']['count']);
1190           if(!isset($object['description'][0])){
1191             $object['description'][0]="";
1192           }
1194           /* Clean up object informations */
1195           $obj                  = array();
1196           $obj['cn']                          = $object['cn'][0];
1197           $obj['dn']                          = $object['dn'];
1198           $obj['acl']                       = $acl;
1199           $obj['class']                           = $rest ['ACL'];
1200           $obj['FAIstate']      = $entry['FAIstate'];
1201           $obj['description']   = $object['description'][0];
1202           $obj['objectClass']   = $object['objectClass'];
1204           $this->objects[$obj['cn']][$type] = $obj;
1205           $this->objects[$obj['cn']][$type]['type']=$type;
1206         }
1207                         }
1208                 }
1210     /*  Append opsi objects, if opsi is available and if we are on the fai_base
1211      */
1212     if($this->opsi instanceof opsi && $this->opsi->enabled()){  
1213       $opsi_acl = $this->ui->get_permissions($base,"opsi/opsiProperties");
1214       if(preg_match("/r/",$opsi_acl)){
1215         $err = FALSE;
1216         if(!$err && $this->DivListFai->ShowOpsiNetboot){
1217           $n_pro = $this->opsi->get_netboot_products();
1218           $err |= $this->opsi->is_error();
1219           foreach($n_pro as $name => $data){
1220             $entry = array(
1221                 "cn" => $name,
1222                 "description" => $data['DESC'],
1223                 "type" => "opsi_netboot");
1224             $this->objects[$name]['opsi_netboot'] = $entry;
1225           }  
1226         }
1227         if(!$err && $this->DivListFai->ShowOpsiLocal){
1228           $l_pro = $this->opsi->get_local_products();
1229           $err |= $this->opsi->is_error();
1230           foreach($l_pro as $name => $data){
1231             $entry = array("cn" => $name,
1232                 "description" => $data['DESC'],
1233                 "type" => "opsi_local");
1234             $this->objects[$name]["opsi_local"] = $entry;
1235           }  
1236         }  
1237         if($err){
1238           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
1239         }
1240       }
1241     }
1242  
1243     uksort($this->objects, 'strnatcasecmp');
1244                 reset ($this->objects);
1245                 $this->objects = array_values($this->objects);
1246         }
1248         function remove_lock()
1249         {
1250                 if (isset($this->dn) && !empty($this->dn)){
1251                         del_lock ($this->dn);
1252                 }
1253     if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
1254       del_lock ($this->dns);
1255     }
1256         }
1258         function get_type($array){
1259     if(!isset($array['objectClass'])) return(array());
1260                 if(in_array("FAIpartitionTable",$array['objectClass'])){
1261                         return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
1262                 }
1263                 if(in_array("FAIscript",$array['objectClass'])){
1264                         return(array("tabsScript","faiScript","FAISCRIPTTABS"));
1265                 }
1266                 if(in_array("FAItemplate",$array['objectClass'])){
1267                         return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
1268                 }
1269                 if(in_array("FAIhook",$array['objectClass'])){
1270                         return(array("tabsHook","faiHook","FAIHOOKTABS"));
1271                 }
1272                 if(in_array("FAIvariable",$array['objectClass'])){
1273                         return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
1274                 }
1275                 if(in_array("FAIprofile",$array['objectClass'])){
1276                         return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
1277                 }
1278                 
1279                 if(in_array("FAIpackageList",$array['objectClass'])){
1280                         return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
1281                 }
1282     return(array());
1283         }
1285   function CheckNewBranchName($name,$base)
1286   {
1287     $f = $this->fai_release;
1288     if($name == ""){
1289       return(false);
1290     }elseif(in_array($name,$this->getBranches($f))) {
1291       return(false);
1292     }elseif(tests::is_department_name_reserved($name,$base)){
1293       return(false);
1294     }
1295     return(true);
1296   }
1298   function save_object()
1299   {
1300     $this->DivListFai->save_object();
1302     /* Get posted release */
1303     $r_releases = array_flip($this->getBranches());
1304     if(isset($_POST['fai_release']) && isset($r_releases[get_post('fai_release')])){
1306       /* Ensure that we have a valid release selected */
1307       if(!isset($r_releases[get_post('fai_release')])){
1308         msg_dialog::display(_("Warning"),_("The selected release is not available anymore. All triggered actions are skipped."));
1309         $_POST = array();
1310         $plug =$_GET['plug'];
1311         $_GET  = array("plug" => $plug);
1312         $this->fai_release = $this->fai_base;
1313       }else{
1314         $this->fai_release = $r_releases[get_post('fai_release')];
1315       }
1317       $fai_filter = session::get("fai_filter");
1318       $fai_filter['fai_release'] = $this->fai_release;
1319       session::set("fai_filter",$fai_filter);
1320     }
1322     if(is_object($this->CopyPasteHandler)){
1323       $this->CopyPasteHandler->save_object();
1324     }
1325   }
1328   function copyPasteHandling_from_queue($s_action,$s_entry)
1329   {
1330     /* Check if Copy & Paste is disabled */
1331     if(!is_object($this->CopyPasteHandler)){
1332       return("");
1333     }
1335     $ui = get_userinfo();
1337     /* Add a single entry to queue */
1338     if($this->dialog instanceOf faiGroupHandle && !$this->dialog->is_open()){
1340       if(in_array($this->dialog->get_mode(),array("copy"))){      
1342         /* Cleanup object queue */
1343         $this->CopyPasteHandler->cleanup_queue();
1344         $group = $this->dialog->get_selected();
1345         foreach($group as $entry){
1346           $a_setup  = $this->get_type($entry);
1347           $dn = $entry['dn'];
1348           if($ui->is_copyable($dn,"fai",$a_setup[1])){
1349             $this->CopyPasteHandler->add_to_queue($dn,$this->dialog->get_mode(),$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1350           }
1351         }
1352         $this->dialog = FALSE;
1353       }
1354     }
1356     /* Add entries to queue */
1357     if($s_action == "copy_multiple"){
1359       /* Cleanup object queue */
1360       $this->CopyPasteHandler->cleanup_queue();
1362       /* Add new entries to CP queue */
1363       foreach($this->list_get_selected_items() as $id){
1364         $group    = $this->objects[$id];
1365         foreach($group as $entry){
1366           $a_setup  = $this->get_type($entry);
1367           $dn = $entry['dn'];
1369           if($s_action == "copy_multiple" && $ui->is_copyable($dn,"fai",$a_setup[1])){
1370             $this->CopyPasteHandler->add_to_queue($dn,"copy",$a_setup[0],$a_setup[2],"fai");//$a_setup[1]);
1371           }
1372         }
1373       }
1374     }
1376     /* Start pasting entries */
1377     if($s_action == "editPaste" && !($this->lock_type == "freeze" && !$this->allow_freeze_object_attach)){
1378       $this->start_pasting_copied_objects = TRUE;
1379     }
1381     /* Return C&P dialog */
1382     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1384       /* Get dialog */
1385       $this->CopyPasteHandler->SetVar("parent",$this);
1386       $data = $this->CopyPasteHandler->execute();
1388       FAI::save_release_changes_now();
1390       /* Return dialog data */
1391       if(!empty($data)){
1392         return($data);
1393       }
1394     }
1396     /* Automatically disable status for pasting */
1397     if(!$this->CopyPasteHandler->entries_queued()){
1398       $this->start_pasting_copied_objects = FALSE;
1399     }
1400     return("");
1401   }
1404   /* Check if the given FAI class is used in this release 
1405    */
1406   static function check_class_name($oc,$name,$dn)
1407   {
1408     $base = FAI::get_release_dn($dn);
1410     if($oc == "FAIprofile"){
1411       $f = "";
1412       $ocs = array("FAIprofile","FAItemplate","FAIhook","FAIpartitionTable","FAIpackageList","FAIscript","FAIvariable");
1413       foreach($ocs as $oc){
1414         $f .= "(objectClass=".$oc.")";
1415       } 
1416       $res  = FAI::get_all_objects_for_given_base($base,"(|".$f.")",TRUE);    
1417     }else{
1418       $res  = FAI::get_all_objects_for_given_base($base,"(|(objectClass=FAIprofile)(objectClass=".$oc."))",TRUE);
1419     }
1420     $delete = array();
1421     $used   = array();
1422     foreach($res as $object){
1423       $used[$object['cn'][0]]= $object['cn'][0];
1424     }
1425     return($used);
1426   }
1429   /* Return plugin informations for acl handling */ 
1430   static function plInfo()
1431   {
1432     return (array( 
1433           "plShortName"   => _("FAI releases"),
1434           "plDescription" => _("FAI release management"),
1435           "plSelfModify"  => FALSE,
1436           "plDepends"     => array(),
1437           "plPriority"    => 0,
1438           "plSection"     => array("administration"),           
1439           "plCategory"    => array("fai"=> array("description" => _("FAI"),
1440                                                  "objectClass" => "FAIclass")),
1441           "plProvidedAcls"=> array()));
1442   }
1444 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1445 ?>