Code

Added execute methods
[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         /* Call parent execute */
43         plugin::execute();
44     /* Fill templating stuff */
45     $smarty     = get_smarty();
46     $display = "";
48     // reset grayout options 
49     $disableRelease   = false;
50     $disableMirror    = false;
51     $disableContinue  = false;
52     $disableSection   = false;
54     /* Post handling for Section, Release and Mirror Setup */
55     if(isset($_POST['SetRepository'])){
56       foreach($this->sections as $sec => $val){
57         if(isset($_POST[$sec])){
58           $this->sections[$sec]=true;
59           $this->FAIdebianSection[$sec]=$sec;
60         }else{
61           $this->sections[$sec]=false;
62         }
63       }
64     
65     }
67     /* Grayout settings */    
68     if(empty($this->FAIdebianRelease)){
69       $disableSection = $disableMirror  = $disableContinue = true;
70     }elseif(empty($this->FAIdebianSection)){
71       $disableRelease = $disableMirror  = $disableContinue = true;
72     }elseif(empty($this->FAIdebianMirror)){
73       $disableRelease = $disableSection =  true;
74     }else{
75       $disableRelease = $disableSection =  true;
76     }
78     /* check servers matching release and section settings */
79     $availableServer = array();
80     foreach($this->mirrors as $mir){
81     
82       /* Check if release and section match */
83       if($mir['release'] == $this->FAIdebianRelease){
84         $pass = true;
85     
86         foreach($this->FAIdebianSection as $sec){
88         /* If a mirror match, attach */
89           if($sec != $mir['section']){
90             $pass = false;
91           }
93         /* Save all matching */ 
94         if($pass){
95             $availableServer[$mir['mirror']]=$mir['mirror'];
96           }
97         }
98       }
99     }
101     /* If no servers matching the settings, allow setting release and section again */
102     if(($disableMirror==false)&&(count($availableServer)==0)){
103       $this->FAIdebianRelease = $this->FAIdebianMirror = "";
104       $this->FAIdebianSection = array();
105       $disableSection = $disableMirror  = $disableContinue = true;
106       $disableRelease = false;
107     }
109     /* Create checkboxes for the avaliable sections */
110     $strsec = "<table><tr>";
111     foreach($this->sections as $sec => $val){
113       /* Only add this section if it is supported by the selected release */
114       $goon = false;
115       foreach($this->mirrors as $mir){
117         /* Is there a release with this section ? */
118         if((($mir['release'] == $this->FAIdebianRelease )&&($mir['section'] == $sec))){
119           $goon = true; 
120         }
121       }
123       if($goon){
124         if($this->sections[$sec] == true ){
125           $chk = " checked ";
126         }else{
127           $chk = "";
128         }
130         /* Add disabled if needed */
131         if($disableSection){
132           $strsec .= "<td><input type='checkbox' name='".$sec."' disabled ".$chk.">".$sec."</td>";
133         }else{
134           $strsec .= "<td><input type='checkbox' name='".$sec."' ".$chk.">".$sec."</td>";
135         }
136       }
137     }
138     $strsec .= "</table>";
139     
140     /* Add --- to mirror selectbox if it is empty */
141     if(count($availableServer)==0){
142       $availableServer=array("---");
143     }
145     /* Tell smarty the grayout settigs */
146     $smarty->assign("ReleaseACL"  , "");
147     $smarty->assign("MirrorACL"   , "");
148     $smarty->assign("ContinueACL" , "");
149     $smarty->assign("SectionACL"  , "");
151     if($disableContinue){
152       $smarty->assign("ContinueACL"," disabled ");
153     }
154     if($disableRelease){
155       $smarty->assign("ReleaseACL"," disabled ");
156     }
157     if($disableMirror){
158       $smarty->assign("MirrorACL"," disabled ");
159     }
160     if($disableSection){
161       $smarty->assign("SectionACL"," disabled ");
162     }
165     $smarty->assign("DisSection",!empty($this->FAIdebianSection));
166     $smarty->assign("DisRelease",!empty($this->FAIdebianRelease));
168     $smarty->assign("mirrors" ,$availableServer);
169     $smarty->assign("mirror"  ,$this->FAIdebianMirror);
170     $smarty->assign("releases",$this->releases);
171     $smarty->assign("release" ,$this->FAIdebianRelease);
172     $smarty->assign("sections",$strsec);
173     $smarty->assign("section" ,$this->FAIdebianSection);
175     $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
176     return($display);
177   }
179   /* Save data to object */
180   function save_object()
181   {
182     if(isset($_POST['SetRepository'])){
183       /* Post handling for Section, Release and Mirror Setup */
184       if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
185         $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
186       }
187       if((isset($_POST['FAIdebianMirrorS']))&&(!empty($_POST['FAIdebianMirrorS']))){
188         $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
189       }
190     }
191   }
193   /* Check supplied data */
194   function check()
195   {
196     $message= array();
197     return ($message);
198   }
200   function save()
201   {
202   }
204 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
205 ?>