Code

fb7d3091dd8baab2d76d59a738b1aa232bed5aaa
[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   var $fai_release = ""; // The currently selected release while in release management mode!
38   function __construct($config,$ui)
39   {
40     $this->config = $config;
41     $this->ui = $ui;
43     $this->storagePoints = array(
44         get_ou('faiPartitionRDN'),
45         get_ou('faiPackageRDN'),
46         get_ou('faiScriptRDN'),
47         get_ou('faiVariableRDN'),
48         get_ou('faiHookRDN'),
49         get_ou('faiProfileRDN'),get_ou('faiTemplateRDN'));
50  
51     // Build filter
52 #    if (session::global_is_set(get_class($this)."_filter")){
53  #     $filter= session::global_get(get_class($this)."_filter");
54   #  } else {
55       $filter = new filter(get_template_path("fai-filter.xml", true));
56       $filter->setObjectStorage($this->storagePoints);
57    # }
58     $this->setFilter($filter);
60     // Build headpage
61     $headpage = new listing(get_template_path("fai-list.xml", true));
62     $headpage->setFilter($filter);
63     $headpage->registerElementFilter("filterProperties", "faiManagement::filterProperties");
65     // Add copy&paste and snapshot handler.
66     if ($this->config->boolValueIsTrue("main", "copyPaste")){
67       $this->cpHandler = new CopyPasteHandler($this->config);
68     }
69     if($this->config->get_cfg_value("enableSnapshots") == "true"){
70       $this->snapHandler = new SnapshotHandler($this->config);
71     }
72     $this->registerAction("editByGroup","editByGroup");
73     parent::__construct($config, $ui, "roles", $headpage);
74   }
77   function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
78   {
79     $headpage = $this->getHeadpage();
80     if(count($target) == 1){
81       $entry = $headpage->getEntry($target[0]);
82       if($entry){
83         if(count($entry['GROUPS']) == 1){
84           $data = array_pop($entry['GROUPS']);
85           $type = $this->get_type($data);
86           management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
87         }else{
88           $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"edit");
89         }
90       }
91     }
92   }
95   function editByGroup()
96   {
97     if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
98       $this->dialogObject->save_object();
99       $entry = $this->dialogObject->get_selected();
100       $this->closeDialogs();
101       $data = array_pop($entry);
102       $type = $this->get_type($data);
103       management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
104     }
105   }
107   
108   function detectPostActions()
109   {
110     $action = management::detectPostActions();
111     if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
112     if(isset($_POST['faiGroupHandle_apply']))  $action['action'] = "editByGroup";
113     return($action);
114   }
117   function renderList()
118   {
119     $filter = $this->getFilter();
120     $headpage = $this->getHeadpage();
121     $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
123     if(isset($_POST['RELEASE'])){
124       $this->fai_release = get_post('RELEASE');
125     }
126     $headpage->setBase($this->fai_release);
127     $headpage->update();
128     $display = $headpage->render();
129     return($this->getHeader().$display);
130   }
132   function getReleaseList($base = "", $prefix ="")
133   {
134     $list = array();
135     if(empty($base)){
136       $base = get_ou('faiBaseRDN').$this->config->current['BASE'];
137       $list[$base] = "/";
138     }
140     $ldap = $this->config->get_ldap_link();
141     $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
142     $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
144     while($release = $ldap->fetch()){
145       $list[$release['dn']] = $prefix.$release['ou'][0];
147       // Preset to prefered releaes if necessary  
148       if(empty($this->fai_release) && $cfg_rel == $release['dn']){
149         $this->fai_release = $release['dn'];
150       }
152       $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix."&nbsp; "));
153     }
154     return($list);
155   }
158   static function filterProperties($row, $classes)
159   {
160     $objects = array(
161         "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
162           "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
163         "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",
164           "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
165         "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",
166           "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
167         "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",
168           "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
169         "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",
170           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
171         "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",
172           "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
173         "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",
174           "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
175         "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",
176           "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
177         "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",
178           "NAME"=>_("OPSI localboot product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
180     $icon_list = "";
181     foreach($objects as $type => $type_data){
182       if(in_array($type, $classes)){
183         $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
184           alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
185       }else{
186         $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
187       }
188     }
190     return $icon_list;
191   }
194   function get_type($array){
195     if(!isset($array['objectClass'])) return(array());
196     if(in_array("FAIpartitionTable",$array['objectClass'])){
197       return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
198     }
199     if(in_array("FAIscript",$array['objectClass'])){
200       return(array("tabsScript","faiScript","FAISCRIPTTABS"));
201     }
202     if(in_array("FAItemplate",$array['objectClass'])){
203       return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
204     }
205     if(in_array("FAIhook",$array['objectClass'])){
206       return(array("tabsHook","faiHook","FAIHOOKTABS"));
207     }
208     if(in_array("FAIvariable",$array['objectClass'])){
209       return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
210     }
211     if(in_array("FAIprofile",$array['objectClass'])){
212       return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
213     }
214     if(in_array("FAIpackageList",$array['objectClass'])){
215       return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
216     }
217     return(array());
218   }
219
220 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
221 ?>