Code

45ca89db01546d63ebe7750bf5dc6e6aa29e1e38
[gosa.git] / plugins / admin / fai / class_faiPackageNew.inc
1 <?php
3 class faiPackageNew extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary        = "Manage server basic objects";
7   var $cli_description    = "Some longer text\nfor help";
8   var $cli_parameters     = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account     = TRUE;
12   var $attributes         = array();
13   var $objectclasses      = array();
14  
15   var $mirrors            = array(); // The possible mirror,release and section combinations
16   var $servers            = array(); // All available server
17   var $sections           = array(); // All sections
18   var $releases           = array(); // Releases 
20   var $FAIdebianRelease   = "";     // The selected release
21   var $FAIdebianSection   = array();     // selected section
22   var $FAIdebianMirror    = "";     // selected mirror
25   var $obj;
27   function faiPackageNew ($config, $dn= NULL,$mirrors,$servers,$sections,$releases)
28   {
29     plugin::plugin ($config, $dn);
30     $this->mirrors  = $mirrors;
31     $this->servers  = $servers;
32     $this->sections = $sections;
33     $this->releases = $releases;
35     foreach($this->sections as $sec){
36       $this->sections[$sec]  =false;
37     }
38   }
40   function execute()
41   {
42     /* Fill templating stuff */
43     $smarty     = get_smarty();
44     $display = "";
46     // reset grayout options 
47     $disableRelease   = false;
48     $disableMirror    = false;
49     $disableContinue  = false;
50     $disableSection   = false;
52     /* Post handling for Section, Release and Mirror Setup */
53     if(isset($_POST['SetRepository'])){
54       if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
55         $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
56       }
57       if((isset($_POST['FAIdebianMirrorS']))&&(!empty($_POST['FAIdebianMirrorS']))){
58         $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
59       }
61       foreach($this->sections as $sec => $val){
62         if(isset($_POST[$sec])){
63           $this->sections[$sec]=true;
64           $this->FAIdebianSection[$sec]=$sec;
65         }else{
66           $this->sections[$sec]=false;
67         }
68       }
69     
70     }
72     /* Grayout settings */    
73     if(empty($this->FAIdebianRelease)){
74       $disableSection = $disableMirror  = $disableContinue = true;
75     }elseif(empty($this->FAIdebianSection)){
76       $disableRelease = $disableMirror  = $disableContinue = true;
77     }elseif(empty($this->FAIdebianMirror)){
78       $disableRelease = $disableSection = $disableContinue = true;
79     }else{
80       $disableRelease = $disableSection =  true;
81     }
83     /* check servers matching release and section settings */
84     $availableServer = array();
85     foreach($this->mirrors as $mir){
86       if($mir['release'] == $this->FAIdebianRelease){
87         $pass = true;
88         foreach($this->FAIdebianSection as $sec){
89           if($sec != $mir['section']){
90             $pass = false;
91           }
92         if($pass){
93             $availableServer[$mir['mirror']]=$mir['mirror'];
94           }
95         }
96       }
97     }
99     /* If no servers matching the settings, allow setting release and section again */
100     if(($disableMirror==false)&&(count($availableServer)==0)){
101       $this->FAIdebianRelease = $this->FAIdebianMirror = "";
102       $this->FAIdebianSection = array();
103       $disableSection = $disableMirror  = $disableContinue = true;
104       $disableRelease = false;
105     }
107     /* Create checkboxes for the avaliable sections */
108     $strsec = "<table><tr>";
109     foreach($this->sections as $sec => $val){
111       /* Only add this section if it is supported by the selected release */
112       $goon = false;
113       foreach($this->mirrors as $mir){
115         /* Is there a release with this section ? */
116         if((($mir['release'] == $this->FAIdebianRelease )&&($mir['section'] == $sec))){
117           $goon = true; 
118         }
119       }
121       if($goon){
122         if($this->sections[$sec] == true ){
123           $chk = " checked ";
124         }else{
125           $chk = "";
126         }
128         /* Add disabled if needed */
129         if($disableSection){
130           $strsec .= "<td><input type='checkbox' name='".$sec."' disabled ".$chk.">".$sec."</td>";
131         }else{
132           $strsec .= "<td><input type='checkbox' name='".$sec."' ".$chk.">".$sec."</td>";
133         }
134       }
135     }
136     $strsec .= "</table>";
137     
138     /* Add --- to mirror selectbox if it is empty */
139     if(count($availableServer)==0){
140       $availableServer=array("---");
141     }
143     /* Tell smarty the grayout settigs */
144     $smarty->assign("ReleaseACL"  , "");
145     $smarty->assign("MirrorACL"   , "");
146     $smarty->assign("ContinueACL" , "");
147     $smarty->assign("SectionACL"  , "");
149     if($disableContinue){
150       $smarty->assign("ContinueACL"," disabled ");
151     }
152     if($disableRelease){
153       $smarty->assign("ReleaseACL"," disabled ");
154     }
155     if($disableMirror){
156       $smarty->assign("MirrorACL"," disabled ");
157     }
158     if($disableSection){
159       $smarty->assign("SectionACL"," disabled ");
160     }
162     $smarty->assign("mirrors" ,$availableServer);
163     $smarty->assign("mirror"  ,$this->FAIdebianMirror);
164     $smarty->assign("releases",$this->releases);
165     $smarty->assign("release" ,$this->FAIdebianRelease);
166     $smarty->assign("sections",$strsec);
167     $smarty->assign("section" ,$this->FAIdebianSection);
169     $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
170     return($display);
171   }
173   /* Save data to object */
174   function save_object()
175   {
176   }
178   /* Check supplied data */
179   function check()
180   {
181     $message= array();
182     return ($message);
183   }
185   function save()
186   {
187   }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>