Code

Invalid repository settings fixed.
[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     
87       /* Check if release and section match */
88       if($mir['release'] == $this->FAIdebianRelease){
89         $pass = true;
90     
91         foreach($this->FAIdebianSection as $sec){
93         /* If a mirror match, attach */
94           if($sec != $mir['section']){
95             $pass = false;
96           }
98         /* Save all matching */ 
99         if($pass){
100             $availableServer[$mir['mirror']]=$mir['mirror'];
101           }
102         }
103       }
104     }
106     /* If no servers matching the settings, allow setting release and section again */
107     if(($disableMirror==false)&&(count($availableServer)==0)){
108       $this->FAIdebianRelease = $this->FAIdebianMirror = "";
109       $this->FAIdebianSection = array();
110       $disableSection = $disableMirror  = $disableContinue = true;
111       $disableRelease = false;
112     }
114     /* Create checkboxes for the avaliable sections */
115     $strsec = "<table><tr>";
116     foreach($this->sections as $sec => $val){
118       /* Only add this section if it is supported by the selected release */
119       $goon = false;
120       foreach($this->mirrors as $mir){
122         /* Is there a release with this section ? */
123         if((($mir['release'] == $this->FAIdebianRelease )&&($mir['section'] == $sec))){
124           $goon = true; 
125         }
126       }
128       if($goon){
129         if($this->sections[$sec] == true ){
130           $chk = " checked ";
131         }else{
132           $chk = "";
133         }
135         /* Add disabled if needed */
136         if($disableSection){
137           $strsec .= "<td><input type='checkbox' name='".$sec."' disabled ".$chk.">".$sec."</td>";
138         }else{
139           $strsec .= "<td><input type='checkbox' name='".$sec."' ".$chk.">".$sec."</td>";
140         }
141       }
142     }
143     $strsec .= "</table>";
144     
145     /* Add --- to mirror selectbox if it is empty */
146     if(count($availableServer)==0){
147       $availableServer=array("---");
148     }
150     /* Tell smarty the grayout settigs */
151     $smarty->assign("ReleaseACL"  , "");
152     $smarty->assign("MirrorACL"   , "");
153     $smarty->assign("ContinueACL" , "");
154     $smarty->assign("SectionACL"  , "");
156     if($disableContinue){
157       $smarty->assign("ContinueACL"," disabled ");
158     }
159     if($disableRelease){
160       $smarty->assign("ReleaseACL"," disabled ");
161     }
162     if($disableMirror){
163       $smarty->assign("MirrorACL"," disabled ");
164     }
165     if($disableSection){
166       $smarty->assign("SectionACL"," disabled ");
167     }
169     $smarty->assign("mirrors" ,$availableServer);
170     $smarty->assign("mirror"  ,$this->FAIdebianMirror);
171     $smarty->assign("releases",$this->releases);
172     $smarty->assign("release" ,$this->FAIdebianRelease);
173     $smarty->assign("sections",$strsec);
174     $smarty->assign("section" ,$this->FAIdebianSection);
176     $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
177     return($display);
178   }
180   /* Save data to object */
181   function save_object()
182   {
183   }
185   /* Check supplied data */
186   function check()
187   {
188     $message= array();
189     return ($message);
190   }
192   function save()
193   {
194   }
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>