Code

Reenabled release mangement
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiManagement.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id: class_roleManagement.inc 14742 2009-11-04 13:18:33Z hickert $$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class faiManagement extends management
24 {
25   var $plHeadline     = "Software deployment";
26   var $plDescription  = "Manage software packages and deployment reciepes";
27   var $plIcon  = "plugins/fai/images/plugin.png";
29   // Tab definition 
30   protected $tabClass = "roletabs";
31   protected $tabType = "ROLETABS";
32   protected $aclCategory = "roles";
33   protected $aclPlugin   = "role";
34   protected $objectName   = "role";
36   //  Attributes Managed by this plugin can be used in post events
37   protected $attributes   = array("lock_type","lock_name","lock_dn");  
39   var $dispNewBranch=false;
40   var $dispNewFreeze=false;
42   var $fai_release = ""; // The currently selected release while in release management mode!
43   var $fai_base = ""; 
44   var $acl_base = ""; 
46   function __construct($config,$ui)
47   {
48     $this->config = $config;
49     $this->fai_base = get_ou("faiBaseRDN").$this->config->current['BASE'];
50     $this->fai_release = $this->fai_base;
51     $this->acl_base = $this->config->current['BASE'];
52     $this->ui = $ui;
53     $this->storagePoints = array(
54         get_ou('faiPartitionRDN'),
55         get_ou('faiPackageRDN'),
56         get_ou('faiScriptRDN'),
57         get_ou('faiVariableRDN'),
58         get_ou('faiHookRDN'),
59         get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
61 #    // Build filter
62 #    if (session::global_is_set(get_class($this)."_filter")){
63 #      $filter= session::global_get(get_class($this)."_filter");
64 #    } else {
65       $filter = new filter(get_template_path("fai-filter.xml", true));
66       $filter->setObjectStorage($this->storagePoints);
67 #    }
68     $this->setFilter($filter);
70     // Build headpage
71     $headpage = new listing(get_template_path("fai-list.xml", true));
72     $headpage->setFilter($filter);
73     $headpage->setBase($this->fai_release);
74     $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
76     // Add copy&paste and snapshot handler.
77     if ($this->config->boolValueIsTrue("main", "copyPaste")){
78       $this->cpHandler = new CopyPasteHandler($this->config);
79     }
80     if($this->config->get_cfg_value("enableSnapshots") == "true"){
81       $this->snapHandler = new SnapshotHandler($this->config);
82     }
83     $this->registerAction("editByGroup","editByGroup");
84     $this->registerAction("createBranch","createBranch");
85     $this->registerAction("createFreeze","createFreeze");
86     $this->registerAction("removeBranch","removeBranch");
87     $this->registerAction("removeBranchConfirmed","removeBranchConfirmed");
88     $this->registerAction("saveBranch","saveBranch");
89     $this->registerAction("PerformBranch","PerformBranch");
90     parent::__construct($config, $ui, "roles", $headpage);
91   }
94   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
95   {
96     $headpage = $this->getHeadpage();
97     if(count($target) == 1){
98       $entry = $headpage->getEntry($target[0]);
99       if($entry){
100         if(count($entry['GROUPS']) == 1){
101           $data = array_pop($entry['GROUPS']);
102           $type = $this->get_type($data);
103           management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
104         }else{
105           $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
106         }
107       }
108     }
109   }
112   function removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
113   {
114     $headpage = $this->getHeadpage();
115     if(count($target) == 1){
116       $entry = $headpage->getEntry($target[0]);
117       if($entry){
118         $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
119       }
120     }
121   }
123   /*! \brief  Object removal was confirmed, now remove the requested entries.
124    *
125    *  @param  String  'action'  The name of the action which was the used as trigger.
126    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
127    *  @param  Array   'all'     A combination of both 'action' and 'target'.
128    */
129   function removeEntryConfirmed($action="",$target=array(),$all=array(),
130       $altTabClass="",$altTabType="",$altAclCategory="")
131   {
132     $ldap = $this->config->get_ldap_link();
133     $ldap->cd($this->config->current['BASE']);  
134     foreach($this->dns as $key => $dn){
135       $ldap->cat($dn);
136       if($ldap->count()){
137         $attrs = $ldap->fetch();
138         $type= $this->get_type($attrs);
139         management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
141         // Now save changes
142         FAI::save_release_changes_now();
143         $to_del = FAI::clean_up_releases($dn);
144         foreach($to_del as $dn){
145           $ldap->rmdir_recursive($dn);
146         }
147       }
148     }
149   }
152   function editByGroup()
153   {
154     if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
155       $this->dialogObject->save_object();
156       $entry = $this->dialogObject->get_selected();
157       $this->closeDialogs();
158       $data = array_pop($entry);
159       $type = $this->get_type($data);
160       management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
161     }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
162       $this->dialogObject->save_object();
163       $to_delete = $entry = $this->dialogObject->get_selected();
164       $dns = array();
167       // Check FAIstate to ensure that we do not remove frozen objects
168       //  additionally check ACLs
169       $locked = array();
170       $disallowed = array();
171       foreach($to_delete as $obj){
172         if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
173           $locked[] = $obj['dn'];
174         }else{
175           $type = $this->get_type($obj);
176           $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
177           if(!preg_match("/d/",$acl)){
178             $disallowed[] = $obj['dn']; 
179           }else{
180             $dns[] = $obj['dn'];
181           }
182         }
183       }
185       // Display info dialog about locked and not removeable entries
186       if(count($locked)){
187         msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
188             msgPool::buildList($locked)));
189       }
191       // Display info dialog about not removeable entries due to permissions
192       if(count($disallowed)){
193         msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
194       }
196       // There are entries left to be removed
197       if(count($dns)){  
198         $this->closeDialogs();
199         $this->dns = $dns;
201         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
203         // check locks
204         if ($user= get_multiple_locks($this->dns)){
205           return(gen_locked_message($user,$this->dns));
206         }
208         // Add locks
209         $dns_names = array();
210         foreach($this->dns as $dn){
211           $dns_names[] =LDAP::fix($dn);
212         }
213         add_lock ($this->dns, $this->ui->dn);
215         // Display confirmation dialog.
216         $smarty = get_smarty();
217         $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
218         $smarty->assign("multiple", true);
219         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
220       }else{
221         $this->closeDialogs();
222       }
223     }
224   }
226   
227   protected function saveChanges()
228   {
229     management::saveChanges();
231     // Now save changes
232     FAI::save_release_changes_now();
233     $to_del = FAI::clean_up_releases($this->last_dn);
234     foreach($to_del as $dn){
235       $ldap->rmdir_recursive($dn);
236     }
237   }
239   protected function applyChanges()
240   {
241     management::applyChanges();
243     // Now save changes
244     FAI::save_release_changes_now();
245     $to_del = FAI::clean_up_releases($this->last_dn);
246     foreach($to_del as $dn){
247       $ldap->rmdir_recursive($dn);
248     }
249   }
251   function detectPostActions()
252   {
253     $action = management::detectPostActions();
254     if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
255     if(isset($_POST['CancelBranchName'])) $action['action'] = "cancel";
256     if(isset($_POST['delete_branch_confirm'])) $action['action'] = "removeBranchConfirmed";
257     if(isset($_GET['PerformBranch'])) $action['action'] = "PerformBranch";
258     if(isset($_POST['UseBranchName'])) $action['action'] = "saveBranch";
259     if(isset($_POST['faiGroupHandle_apply']))  $action['action'] = "editByGroup";
260     if(isset($_GET['act']) && $_GET['act'] == "branch_branch")  $action['action'] = "createBranch";
261     if(isset($_GET['act']) && $_GET['act'] == "freeze_branch")  $action['action'] = "createFreeze";
262     if(isset($_GET['act']) && $_GET['act'] == "remove_branch")  $action['action'] = "removeBranch";
264     foreach($_POST as $name => $value){
265       if(preg_match("/^edit_([0-9]*)_([a-z]*)_(x|y)/i", $name)){
266         $id = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\1", $name);
267         $tab = preg_replace("/^edit_([0-9]*)_([a-z]*)_(x|y)/i","\\2", $name);
268         $headpage = $this->getHeadpage();
269         if(isset($headpage->entries[$id]['GROUPS'][$tab])){
270           $data =$headpage->entries[$id]['GROUPS'][$tab];
271           $type = $this->get_type($data);
272           management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]); 
273         } 
274         break;
275       }
276     }
277     return($action);
278   }
281   function renderList()
282   {
283     $filter = $this->getFilter();
284     $headpage = $this->getHeadpage();
285     $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
287     if(isset($_POST['RELEASE'])){
288       $this->fai_release = get_post('RELEASE');
289     }
290     $headpage->setBase($this->fai_release);
291     $headpage->update();
292     $smarty = get_smarty();
293     $smarty->assign("fai_release", $this->fai_release);
294     $smarty->assign("fai_base", $this->fai_base);
295     $r = $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'));
296     $c = $this->config->search("faiManagement", "POSTCREATE",array('menu','tabs'));
297     $smarty->assign("allow_create", $c);
298     $smarty->assign("allow_remove", $r);
299     $display = $headpage->render();
300     return($this->getHeader().$display);
301   }
303   function getReleaseList($base = "", $prefix ="")
304   {
305     $list = array();
306     if(empty($base)){
307       $base = $this->fai_base;
308       $list[$base] = "/";
309     }
311     $ldap = $this->config->get_ldap_link();
312     $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
313     $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
315     while($release = $ldap->fetch()){
316       $list[$release['dn']] = $prefix.$release['ou'][0];
318       // Preset to prefered releaes if necessary  
319       if(empty($this->fai_release) && $cfg_rel == $release['dn']){
320         $this->fai_release = $release['dn'];
321       }
323       $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix."&nbsp; "));
324     }
325     return($list);
326   }
329   static function filterProperties($row, $classes)
330   {
331     $objects = array(
332         "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
333           "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
334         "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",
335           "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
336         "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",
337           "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
338         "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",
339           "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
340         "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",
341           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
342         "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",
343           "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
344         "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",
345           "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
346         "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",
347           "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
348         "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",
349           "NAME"=>_("OPSI localboot product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
351     $icon_list = "";
352     foreach($objects as $type => $type_data){
353       if(in_array($type, $classes)){
354         $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
355           alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
356       }else{
357         $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
358       }
359     }
361     return $icon_list;
362   }
367   function removeBranch()
368   {
369     /* Check if we have a post remove method configured
370      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
371      */
372     if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
373       /* Load permissions for selected 'dn' and check if
374          we're allowed to remove this 'dn' */
375       if(preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
376         $smarty=get_smarty();
377         $smarty->assign("release_hidden",base64_encode($this->fai_release));
378         $smarty->assign("info", msgPool::deleteInfo(LDAP::fix($this->fai_release),_("FAI branch/freeze")));
379         return($smarty->fetch(get_template_path('remove_branch.tpl',TRUE)));
380       } else {
381         msg_dialog::display(_("Permission error"), _("You have no permission to delete this release!"), ERROR_DIALOG);
382       }
383     }
384   }
387   function removeBranchConfirmed()
388   {
389     /* Check if we have a post remove method configured
390      *  else skip this operation. (Skip:Button in the ui should be disabled in this case too)
391      */
392     if("" != $this->config->search("faiManagement", "POSTREMOVE",array('menu','tabs'))){
394       if(!isset($_POST['release_hidden']) || base64_decode($_POST['release_hidden']) != $this->fai_release){
395         msg_dialog::display(_("Warning"),_("Release remove aborted because the release name check failed!"));
396       }else{
398         $bb =  $this->fai_release;
399         $ldap = $this->config->get_ldap_link();
401         $br = $this->getBranches();
403         if(isset($br[$bb]) && preg_match("/d/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
404           $name = $br[$bb];
406           $ldap->cd($bb);
407           $ldap->recursive_remove();
408           $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('applicationRDN'), $bb));
409           $ldap->recursive_remove();
410           $ldap->cd(preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'/i', ','.get_ou('mimetypeRDN'), $bb));
411           $ldap->recursive_remove();
413           /* Search for all groups with configured application menus.
414              - First search all groups, to ensure that we only remove entries form whithin groups.
415              - The search für menu configuration for the specified release and collect all those dns.
416              - Remove entries
417            */
418           $release_ou = preg_replace("/".preg_quote(get_ou("faiBaseRDN"), '/').".*$/i","",$bb);
419           $ldap->cd($this->config->current['BASE']);
420           $ldap->search("(objectClass=posixGroup)",array("dn"));
422           /* Collect all group dns
423            */
424           $groups = array();
425           while($attrs = $ldap->fetch()){
426             $groups[] = $attrs['dn'];
427           }
430           /* Collect all group menu release dns that match the release we have removed
431            */
432           $dns = array();
433           foreach($groups as $dn){
434             $ldap->cd($dn);
435             $ldap->search("(objectClass=FAIbranch)",array("dn"));
436             while($attrs = $ldap->fetch()){
437               if(preg_match("/^".preg_quote($release_ou, '/')."/",$attrs['dn'])){
438                 $dns[] = $attrs['dn'];
439               }
440             }
441           }
443           /* Finally remove collected release dns
444            */
445           foreach($dns as $dn){
446             $ldap->cd($dn);
447             $ldap->recursive_remove();
448           }
450           /* Post remove */
451           $this->fai_release = $this->fai_base;
452           $this->lock_name   = $name;
453           $this->lock_dn     = $bb;
454           $this->postremove();
456           $fai_filter = session::get("fai_filter");
457           $fai_filter['fai_release'] = $this->fai_release;
458           session::set("fai_filter",$fai_filter);
460           new log("remove","fai/".get_class($this),$br[$bb],array(),"Release removed");
461         }
462       }
463     }
464   }
467   function createBranch()
468   { 
469     $smarty = get_smarty();
470     $this->dispNewBranch=true;
471     $this->dispNewFreeze=false;
472     $smarty->assign("iframe",false);
473     if(isset($_POST['BranchName'])){
474       $smarty->assign("BranchName", $_POST['BranchName']);
475     }else{
476       $smarty->assign("BranchName","");
477     }
478     return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
479   }
481   function createFreeze()
482   { 
483     $smarty = get_smarty();
484     $this->dispNewFreeze=true;
485     $this->dispNewBranch=false;
486     $smarty->assign("iframe",false);
487     if(isset($_POST['BranchName'])){
488       $smarty->assign("BranchName", $_POST['BranchName']);
489     }else{
490       $smarty->assign("BranchName","");
491     }
492     return($smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__))));
493   }
497   function PerformBranch()
498   {
499     if(!preg_match("/c/",$this->ui->get_permissions($this->acl_base,"fai/faiManagement"))){
500       msg_dialog::display(_("Permission error"), msgPool::permCreate(_("Branch")), ERROR_DIALOG);
501     }else{
503       /* In order to see error messages we have to reset the error handler.
504          Due to the exit();
505        */
506       restore_error_handler();
508       $this->dispNewBranch = false;
509       $this->dispNewFreeze = false;
511       $LASTPOST = session::get('LASTPOST');
512       $base = $LASTPOST['base'];
513       $_POST  = session::get('LASTPOST');
514       $name = $_POST['BranchName'];
516       $type = $LASTPOST['type'];
517       $ldap = $this->config->get_ldap_link();
519       $baseToUse = $base;
520       if($this->fai_release !=  $this->fai_base){
521         $baseToUse = $this->fai_release;
522       }
524       /* Create new Release name to be able to set faidebianRelease for FAIpackageList */
526       $CurrentReleases  = $this->getBranches();
527       $NewReleaseName   = $name;
528       if(isset($CurrentReleases[$this->fai_release])) {
529         if($this->fai_release != $this->fai_base){
530           $NewReleaseName = $CurrentReleases[$this->fai_release]."/".$name;
531           $NewReleaseName = preg_replace("#\/#","/",$NewReleaseName);
532         }else{
533           $NewReleaseName   = $name;
534         }
535       }
536       $appsrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),$baseToUse);
537       $appdst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('applicationRDN'),"ou=".$name.",".$baseToUse) ;
539       $mimesrc = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),$baseToUse);
540       $mimedst = preg_replace("/".preg_quote(get_ou('faiBaseRDN'), '/')."/i",get_ou('mimetypeRDN'),"ou=".$name.",".$baseToUse) ;
542       /* Check if source depeartments exist */
543       foreach(array($baseToUse,$appsrc,$mimesrc) as $dep){
544         $ldap->cd($this->config->current['BASE']);
545         $ldap->cat($dep);
546         if(!$ldap->count()){
547           $ldap->create_missing_trees($dep);
548         }
549       }
551       /* Print header to have styles included */
552       echo '  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
553         <html>
554         <head>
555         <title></title>
556         <style type="text/css">@import url("themes/default/style.css");</style>
557         <script language="javascript" src="include/focus.js" type="text/javascript"></script>
558         </head>
559         <body style="background: none;margin:3px;color:black">
560         ';
562       new log("create","fai/".get_class($this),$NewReleaseName,array(),"New $type created");
564       /* Duplicate group application releases
565        */
566       FAI::copy_FAI_group_releases($CurrentReleases[$this->fai_release],$name,$type);
568       /* Duplicate applications
569        */
570       $ldap->cat($appsrc,array("dn")) ;
571       if($ldap->count()){
572         $ldap->cd ($appdst);
573         $ldap->recursive_remove();
574         FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
575       }
577       /* Duplicate mime types
578        */
579       $ldap->cat($mimesrc,array("dn")) ;
580       if($ldap->count()){
581         $ldap->cd ($mimedst);
582         $ldap->recursive_remove();
583         FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
584       }
586       $attr = array();
587       $attr['objectClass'] = array("organizationalUnit","FAIbranch");
588       $attr['ou']       = $name;
589       $attr['FAIstate'] = $type;
590       $ldap->cd($this->config->current['BASE']);
591       $ldap->cd("ou=".$name.",".$baseToUse);
592       $ldap->cat("ou=".$name.",".$baseToUse);
593       if($ldap->count()){
594         $ldap->modify($attr);
595       }else{
596         $ldap->add($attr);
597       }
599       /* Duplicate fai objects
600        */
601       //      $ldap->cd ("ou=".$name.",".$baseToUse);
602       //      $ldap->recursive_remove();
603       //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
605       echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
606         <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
607         <input type='hidden' name='php_c_check' value='1'>
608         </form></div>";
610       echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
612       /* Print footer to have valid html */
613       echo "</body></html>";
615       $this->dispNewFreeze = false;
617       /* Postcreate */
619       /* Assign possible attributes */
620       $this->lock_type  = $type;
621       $this->lock_name  = $name;
622       $this->lock_dn    = $baseToUse;
623       $this->postcreate();
625       /* Send daemon event to reload the fai release database
626        */
627       if(class_available("DaemonEvent") && class_available("gosaSupportDaemon")){
628         $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
629         if(isset($events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'])){
630           $evt = $events['TRIGGERED']['DaemonEvent_recreate_fai_release_db'];
631           $tmp = new $evt['CLASS_NAME']($this->config);
632           $tmp->set_type(TRIGGERED_EVENT);
633           $tmp->add_targets(array("GOSA"));
634           $o_queue = new gosaSupportDaemon();
635           if(!$o_queue->append($tmp)){
636             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
637           }
638         }
639       }else{
640         trigger_error("Unknown class DaemonEvent / gosaSupportDaemon");
641         msg_dialog::display(_("Fatal error"),
642             "Daemon events called but classes where not accessible, DaemonEvent gosaSupportDaemon",
643             FATAL_ERROR_DIALOG);
644       }
645       exit();
646     }
647   }
652   function saveBranch()
653   {
654     if($this->dispNewBranch){
655       $type = "branch";
656     }else{
657       $type = "freeze";
658     }
660     /* Check branch name */
661     $name = $_POST['BranchName'];
662     $is_ok = true;
663     $smarty = get_smarty();
664     $smarty->assign("BranchName",$name);
665     $base= $this->fai_base;
667     /* Check used characters */
668     if(!preg_match("/^[0-9a-z\.]*$/",$name)){
669       msg_dialog::display(_("Error"), msgPool::invalid(_("Name"),$name,"/[0-9a-z\.]/"), ERROR_DIALOG);
670       $is_ok = false;
671     }
673     // Check if this name is already in use 
674     if(!$this->CheckNewBranchName($_POST['BranchName'],$this->fai_release)){
675       msg_dialog::display(_("Error"), msgPool::duplicated(_("Name")), ERROR_DIALOG);
676       $is_ok = false;
677     }
679     // Handle errors
680     if(!$is_ok && $this->dispNewFreeze){
681       return($this->createFreeze());
682     }elseif(!$is_ok && $this->dispNewBranch){
683       return($this->createBranch());
684     }
686     // Now create new release
688     if(session::is_set('LASTPOST')){
689       $LASTPOST = session::get('LASTPOST');
690     }else{
691       $LASTPOST = array();
692     }
693     $LASTPOST['base'] = $base;
694     $LASTPOST['type'] = $type;
695     $LASTPOST['BranchName'] = $name;
696     session::set('LASTPOST',$LASTPOST);
697     $smarty->assign("iframe", true);
698     $smarty->assign("plugID", $_GET['plug']);
699     $display  = $smarty->fetch(get_template_path('faiNewBranch.tpl', TRUE, dirname(__FILE__)));
700     return($display);
701  
702   }
705   function CheckNewBranchName($name,$base)
706   {
707     $f = $this->fai_release;
708     if($name == ""){
709       return(false);
710     }elseif(in_array($name,$this->getBranches($f))) {
711       return(false);
712     }elseif(tests::is_department_name_reserved($name,$base)){
713       return(false);
714     }
715     return(true);
716   }
719   /* Get available branches for current base */
720   function getBranches($base = false,$prefix = "")
721   {
722     $ret = array("/"=>$this->fai_base);
723     $ldap = $this->config->get_ldap_link();
724     if(!$base){
725       $base = $this->fai_base;
726     }
727     $tmp = FAI::get_all_releases_from_base($base,true);
728     foreach($tmp as $dn => $name){
729       $ret[$name]=$dn;
730     }
731     ksort($ret);
732     $ret = array_flip($ret);
734     return ($ret);
735   }
738   function get_type($array)
739   {
740     if(!isset($array['objectClass'])) return(array());
741     if(in_array("FAIpartitionTable",$array['objectClass'])){
742       return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
743     }
744     if(in_array("FAIscript",$array['objectClass'])){
745       return(array("tabsScript","faiScript","FAISCRIPTTABS"));
746     }
747     if(in_array("FAItemplate",$array['objectClass'])){
748       return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
749     }
750     if(in_array("FAIhook",$array['objectClass'])){
751       return(array("tabsHook","faiHook","FAIHOOKTABS"));
752     }
753     if(in_array("FAIvariable",$array['objectClass'])){
754       return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
755     }
756     if(in_array("FAIprofile",$array['objectClass'])){
757       return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
758     }
759     if(in_array("FAIpackageList",$array['objectClass'])){
760       return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
761     }
762     return(array());
763   }
764
765 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
766 ?>