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();
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 foreach($this->sections as $sec => $val){
55 if(isset($_POST[$sec])){
56 $this->sections[$sec]=true;
57 $this->FAIdebianSection[$sec]=$sec;
58 }else{
59 $this->sections[$sec]=false;
60 }
61 }
63 }
65 /* Grayout settings */
66 if(empty($this->FAIdebianRelease)){
67 $disableSection = $disableMirror = $disableContinue = true;
68 }elseif(empty($this->FAIdebianSection)){
69 $disableRelease = $disableMirror = $disableContinue = true;
70 }elseif(empty($this->FAIdebianMirror)){
71 $disableRelease = $disableSection = true;
72 }else{
73 $disableRelease = $disableSection = true;
74 }
76 /* check servers matching release and section settings */
77 $availableServer = array();
78 foreach($this->mirrors as $mir){
80 /* Check if release and section match */
81 if($mir['release'] == $this->FAIdebianRelease){
82 $pass = true;
84 foreach($this->FAIdebianSection as $sec){
86 /* If a mirror match, attach */
87 if($sec != $mir['section']){
88 $pass = false;
89 }
91 /* Save all matching */
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>";
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 }
163 $smarty->assign("DisSection",!empty($this->FAIdebianSection));
164 $smarty->assign("DisRelease",!empty($this->FAIdebianRelease));
166 $smarty->assign("mirrors" ,$availableServer);
167 $smarty->assign("mirror" ,$this->FAIdebianMirror);
168 $smarty->assign("releases",$this->releases);
169 $smarty->assign("release" ,$this->FAIdebianRelease);
170 $smarty->assign("sections",$strsec);
171 $smarty->assign("section" ,$this->FAIdebianSection);
173 $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
174 return($display);
175 }
177 /* Save data to object */
178 function save_object()
179 {
180 if(isset($_POST['SetRepository'])){
181 /* Post handling for Section, Release and Mirror Setup */
182 if((isset($_POST['FAIdebianReleaseS']))&&(!empty($_POST['FAIdebianReleaseS']))){
183 $this->FAIdebianRelease = $_POST['FAIdebianReleaseS'];
184 }
185 if((isset($_POST['FAIdebianMirrorS']))&&(!empty($_POST['FAIdebianMirrorS']))){
186 $this->FAIdebianMirror = $_POST['FAIdebianMirrorS'];
187 }
188 }
189 }
191 /* Check supplied data */
192 function check()
193 {
194 $message= array();
195 return ($message);
196 }
198 function save()
199 {
200 }
201 }
202 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
203 ?>