Code

We are no able again to save and remove entries
[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 removeEntryRequested($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
96   {
97     $headpage = $this->getHeadpage();
98     if(count($target) == 1){
99       $entry = $headpage->getEntry($target[0]);
100       if($entry){
101         $this->dialogObject = new faiGroupHandle($entry['GROUPS'],"remove");
102       }
103     }
104   }
107   function editByGroup()
108   {
109     if($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "edit"){
110       $this->dialogObject->save_object();
111       $entry = $this->dialogObject->get_selected();
112       $this->closeDialogs();
113       $data = array_pop($entry);
114       $type = $this->get_type($data);
115       management::editEntry('editEntry',array($data['dn']),array(),$type[0],$type[2],$type[1]);
116     }elseif($this->dialogObject instanceOf faiGroupHandle && $this->dialogObject->get_mode() == "remove"){
117       $this->dialogObject->save_object();
118       $to_delete = $entry = $this->dialogObject->get_selected();
119       $dns = array();
122       // Check FAIstate to ensure that we do not remove frozen objects
123       //  additionally check ACLs
124       $locked = array();
125       $disallowed = array();
126       foreach($to_delete as $obj){
127         if(isset($obj['FAIstate']) && preg_match('/^freeze/', $obj['FAIstate'])){
128           $locked[] = $obj['dn'];
129         }else{
130           $type = $this->get_type($obj);
131           $acl = $this->ui->get_permissions($obj['dn'], 'acl/'.$type[1]);
132           if(!preg_match("/d/",$acl)){
133             $disallowed[] = $obj['dn']; 
134           }else{
135             $dns[] = $obj['dn'];
136           }
137         }
138       }
140       // Display info dialog about locked and not removeable entries
141       if(count($locked)){
142         msg_dialog::display(_("Branch locked"),sprintf(_("The following entries are locked, you can't remove them %s."),
143             msgPool::buildList($locked)));
144       }
146       // Display info dialog about not removeable entries due to permissions
147       if(count($disallowed)){
148         msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
149       }
151       // There are entries left to be removed
152       if(count($dns)){  
153         $this->closeDialogs();
154         $this->dns = $dns;
156         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$target,"Entry removel requested!");
158         // check locks
159         if ($user= get_multiple_locks($this->dns)){
160           return(gen_locked_message($user,$this->dns));
161         }
163         // Add locks
164         $dns_names = array();
165         foreach($this->dns as $dn){
166           $dns_names[] =LDAP::fix($dn);
167         }
168         add_lock ($this->dns, $this->ui->dn);
170         // Display confirmation dialog.
171         $smarty = get_smarty();
172         $smarty->assign("info", msgPool::deleteInfo($dns_names,_($this->objectName)));
173         $smarty->assign("multiple", true);
174         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
175       }else{
176         $this->closeDialogs();
177       }
178     }
179   }
181   
182  /*! \brief  Object removal was confirmed, now remove the requested entries.
183    *
184    *  @param  String  'action'  The name of the action which was the used as trigger.
185    *  @param  Array   'target'  A list of object dns, which should be affected by this method.
186    *  @param  Array   'all'     A combination of both 'action' and 'target'.
187    */
188   function removeEntryConfirmed($action="",$target=array(),$all=array(),
189       $altTabClass="",$altTabType="",$altAclCategory="")
190   {
191     $ldap = $this->config->get_ldap_link();
192     $ldap->cd($this->config->current['BASE']);  
193     foreach($this->dns as $key => $dn){
194       $ldap->cat($dn);
195       if($ldap->count()){
196         $attrs = $ldap->fetch();
197         $type= $this->get_type($attrs);
198         management::removeEntryConfirmed($action,array($dn),$all,$type[0],$type[2],$type[1]);
200         // Now save changes
201         FAI::save_release_changes_now();
202         $to_del = FAI::clean_up_releases($dn);
203         foreach($to_del as $dn){
204           $ldap->rmdir_recursive($dn);
205         }
206       }
207     }
208   }
210   protected function saveChanges()
211   {
212     management::saveChanges();
214     // Now save changes
215     FAI::save_release_changes_now();
216     $to_del = FAI::clean_up_releases($this->last_dn);
217     foreach($to_del as $dn){
218       $ldap->rmdir_recursive($dn);
219     }
220   }
222   protected function applyChanges()
223   {
224     management::applyChanges();
226     // Now save changes
227     FAI::save_release_changes_now();
228     $to_del = FAI::clean_up_releases($this->last_dn);
229     foreach($to_del as $dn){
230       $ldap->rmdir_recursive($dn);
231     }
232   }
234   function detectPostActions()
235   {
236     $action = management::detectPostActions();
237     if(isset($_POST['faiGroupHandle_cancel'])) $action['action'] = "cancel";
238     if(isset($_POST['faiGroupHandle_apply']))  $action['action'] = "editByGroup";
239     return($action);
240   }
243   function renderList()
244   {
245     $filter = $this->getFilter();
246     $headpage = $this->getHeadpage();
247     $filter->setComboBoxOptions("RELEASE",$this->getReleaseList());
249     if(isset($_POST['RELEASE'])){
250       $this->fai_release = get_post('RELEASE');
251     }
252     $headpage->setBase($this->fai_release);
253     $headpage->update();
254     $display = $headpage->render();
255     return($this->getHeader().$display);
256   }
258   function getReleaseList($base = "", $prefix ="")
259   {
260     $list = array();
261     if(empty($base)){
262       $base = get_ou('faiBaseRDN').$this->config->current['BASE'];
263       $list[$base] = "/";
264     }
266     $ldap = $this->config->get_ldap_link();
267     $ldap->ls("(objectClass=FAIbranch)",$base,array("ou","FAIstate"));
268     $cfg_rel = $this->config->search("faiManagement","DEFAULTFAIRELEASE",array("menu"));
270     while($release = $ldap->fetch()){
271       $list[$release['dn']] = $prefix.$release['ou'][0];
273       // Preset to prefered releaes if necessary  
274       if(empty($this->fai_release) && $cfg_rel == $release['dn']){
275         $this->fai_release = $release['dn'];
276       }
278       $list = array_merge($list,$this->getReleaseList($release['dn'],$prefix."&nbsp; "));
279     }
280     return($list);
281   }
284   static function filterProperties($row, $classes)
285   {
286     $objects = array(
287         "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
288           "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
289         "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",
290           "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
291         "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",
292           "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
293         "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",
294           "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
295         "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",
296           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
297         "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",
298           "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
299         "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",
300           "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
301         "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",
302           "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
303         "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",
304           "NAME"=>_("OPSI localboot product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
306     $icon_list = "";
307     foreach($objects as $type => $type_data){
308       if(in_array($type, $classes)){
309         $icon_list .= "<input type='image' src='".$type_data['IMG']."' title='".$type_data['NAME']."'
310           alt='".$type_data['KZL']."' class='center' name='edit_".$row."_".$type."'>\n";
311       }else{
312         $icon_list .= "<img src='images/empty.png' alt=' ' class='center'>\n";
313       }
314     }
316     return $icon_list;
317   }
320   function get_type($array){
321     if(!isset($array['objectClass'])) return(array());
322     if(in_array("FAIpartitionTable",$array['objectClass'])){
323       return(array("tabsPartition","faiPartitionTable","FAIPARTITIONTABS"));
324     }
325     if(in_array("FAIscript",$array['objectClass'])){
326       return(array("tabsScript","faiScript","FAISCRIPTTABS"));
327     }
328     if(in_array("FAItemplate",$array['objectClass'])){
329       return(array("tabsTemplate","faiTemplate","FAITEMPLATETABS"));
330     }
331     if(in_array("FAIhook",$array['objectClass'])){
332       return(array("tabsHook","faiHook","FAIHOOKTABS"));
333     }
334     if(in_array("FAIvariable",$array['objectClass'])){
335       return(array("tabsVariable","faiVariable","FAIVARIABLETABS"));
336     }
337     if(in_array("FAIprofile",$array['objectClass'])){
338       return(array("tabsProfile","faiProfile","FAIPROFILETABS"));
339     }
340     if(in_array("FAIpackageList",$array['objectClass'])){
341       return(array("tabsPackage","faiPackage","FAIPACKAGETABS"));
342     }
343     return(array());
344   }
345
346 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
347 ?>