1d162737066919855643b165267a703e79656b06
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 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 }
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){
87 /* Check if release and section match */
88 if($mir['release'] == $this->FAIdebianRelease){
89 $pass = true;
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>";
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 }
170 $smarty->assign("DisSection",!empty($this->FAIdebianSection));
171 $smarty->assign("DisRelease",!empty($this->FAIdebianRelease));
173 $smarty->assign("mirrors" ,$availableServer);
174 $smarty->assign("mirror" ,$this->FAIdebianMirror);
175 $smarty->assign("releases",$this->releases);
176 $smarty->assign("release" ,$this->FAIdebianRelease);
177 $smarty->assign("sections",$strsec);
178 $smarty->assign("section" ,$this->FAIdebianSection);
180 $display.= $smarty->fetch(get_template_path('faiPackageNew.tpl', TRUE));
181 return($display);
182 }
184 /* Save data to object */
185 function save_object()
186 {
187 }
189 /* Check supplied data */
190 function check()
191 {
192 $message= array();
193 return ($message);
194 }
196 function save()
197 {
198 }
199 }
200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
201 ?>