Code

Added copy & paste to fai
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiGroupHandle.inc
1 <?php
3 class faiGroupHandle{
6   private $FAI_group;
7   private $mode     = "edit";  
8   private $open     = TRUE;
9   private $canceled = FALSE;
11   public function __construct($FAI_group, $Action)
12   {
13     if(in_array($Action,array("edit","remove","copy","cut"))){
14       $this->mode = $Action;
15     }else{
16       trigger_error("Wrong action type '".$Action."'.");
17       exit();
18     }
20     /* Preset required values */
21     foreach($FAI_group as $type => $data){
22       $FAI_group[$type]['selected'] = FALSE;
23       $FAI_group[$type]['freezed'] = isset($data['FAIstate']) && preg_match("/freeze/",$data['FAIstate']);
24       if(($this->mode == "cut" || $this->mode == "edit") && !$FAI_group[$type]['freezed']){
25         $FAI_group[$type]['selected'] = TRUE;
26       }
27     }
28     $this->FAI_group = $FAI_group;
29   }
31   function execute()
32   {
33     $smarty = get_smarty();
34     $smarty->assign("FAI_group",$this->FAI_group);
35     $smarty->assign("types",$this->get_types());
36     $smarty->assign("mode",$this->mode);
37     return($smarty->fetch(get_template_path("faiGroupHandle.tpl",TRUE,dirname(__FILE__))));
38   }
40   function save_object()
41   {
42     if(isset($_POST['faiGroupHandle'])){
43       if(in_array($this->mode,array("copy","cut","remove"))){
44         foreach($this->FAI_group as $key => $group){
45           if(isset($_POST[$this->mode."_".$key])){
46             $this->FAI_group[$key]['selected'] = TRUE;
47           }else{
48             $this->FAI_group[$key]['selected'] = FALSE;
49           }
50         } 
51       }else{
52         if(isset($_POST['edit_selected']) && isset($this->FAI_group[get_post('edit_selected')])){
53           foreach($this->FAI_group as $key => $obj){
54             $this->FAI_group[$key]['selected'] = FALSE;
55           }
56           $this->FAI_group[get_post('edit_selected')]['selected'] = TRUE;
57         }
58       }
59       if(isset($_POST['faiGroupHandle_apply']) || isset($_POST['faiGroupHandle_cancel'])){
60         $this->open = FALSE;
61       }
62       if(isset($_POST['faiGroupHandle_cancel'])){
63         $this->canceled = TRUE;
64       }
65     }
66   }
68   function is_open()
69   {
70     return($this->open);
71   }
73   function is_canceled()
74   {
75     return($this->canceled);
76   }
77   
78   function get_mode()
79   {
80     return($this->mode);
81   }
82   
83   function get_selected()
84   {
85     $ret= array();
86     foreach($this->FAI_group as $key => $obj){
87       if($obj['selected']){
88         $ret[$key] = $obj;
89       }
90     }
91     return($ret);
92   }
94   function get_types()
95   {
96     $objects = array(
97         "FAIpartitionTable"  => array("IMG"=> "plugins/fai/images/fai_partitionTable.png",
98           "NAME"=>_("Partition table"),"KZL"=> "PT", "VAR"=>"ShowPartitions"),
99         "FAIpackageList"     => array("IMG"=> "plugins/fai/images/fai_packages.png",
100           "NAME"=>_("Package list") ,  "KZL"=> "PL", "VAR"=>"ShowPackages"),
101         "FAIscript"          => array("IMG"=> "plugins/fai/images/fai_script.png",
102           "NAME"=>_("Scripts") ,       "KZL"=> "S",  "VAR"=>"ShowScripts"),
103         "FAIvariable"        => array("IMG"=> "plugins/fai/images/fai_variable.png",
104           "NAME"=>_("Variables") ,     "KZL"=> "V",  "VAR"=>"ShowVariables"),
105         "FAIhook"            => array("IMG"=> "plugins/fai/images/fai_hook.png",
106           "NAME"=>_("Hooks"),          "KZL"=> "H",  "VAR"=>"ShowHooks"),
107         "FAIprofile"         => array("IMG"=> "plugins/fai/images/fai_profile.png",
108           "NAME"=>_("Profile") ,       "KZL"=> "P",  "VAR"=>"ShowProfiles"),
109         "FAItemplate"        => array("IMG"=> "plugins/fai/images/fai_template.png",
110           "NAME"=>_("Templates") ,     "KZL"=> "T",  "VAR"=>"ShowTemplates"),
111         "opsi_netboot"       => array("IMG"=> "plugins/opsi/images/netboot_package.png",
112           "NAME"=>_("OPSI netboot product") ,     "KZL"=> "ON",  "VAR"=>"ShowOpsiNetboot"),
113         "opsi_local"         => array("IMG"=> "plugins/opsi/images/local_package.png",
114           "NAME"=>_("OPSI local product")   ,     "KZL"=> "OL",  "VAR"=>"ShowOpsiLocal"));
115     return($objects);
116   }
124 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
125 ?>