1 <?php
3 class faiPackageEntry 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 var $strID = "";
16 var $buffer = array();
17 var $categories = array();
18 var $searchStrPKG = "Please enter your search string here";
19 var $selected = array();
21 /* Array with available class names */
22 var $FAIAllclasses = array();
24 function faiPackageEntry ($config, $dn= NULL,$strID=false,$selected=array())
25 {
26 plugin::plugin ($config, $dn);
27 $this->strID = $strID;
29 if(isset($_SESSION['searchStrPKG'])){
30 $this->searchStrPKG=$_SESSION['searchStrPKG'];
31 }
33 $this->selected=$selected;
34 }
36 function execute()
37 {
38 /* Fill templating stuff */
39 $smarty = get_smarty();
40 $display = "";
42 $divlist = new divlist("PackageEntry");
43 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
44 $divlist->SetEntriesPerPage(20);
45 $divlist->SetHeader(array(array("string"=>" "),
46 array("string"=>"Name"),
47 array("string"=>"Version"),
48 array("string"=>"Description","attach"=>"style='border-right:0px;'")));
50 if(isset($_GET['search'])){
51 $this->searchStrPKG= $_GET['search']."*";
52 }
54 $pkgs = $this->genPkgs();
55 foreach($pkgs as $cat => $entries){
56 if(!isset($this->categories[$cat])){
57 $this->categories[$cat] = true;
58 }
59 if(isset($_POST['chkchange'])){
60 $this->searchStrPKG = $_POST['searchStrPKG'];
61 if(isset($_POST['CAT'.$cat])){
62 $this->categories[$cat]=true;
63 }else{
64 $this->categories[$cat]=false;
65 }
66 }
68 }
70 $CHKS = "<table><tr><input type='hidden' value='chkchange' name='chkchange'>";
71 $i = 0;
72 foreach($this->categories as $cat => $selected){
73 if($i == 3){
74 $CHKS .="</tr><tr>";
75 $i = 0;
76 }
77 $i ++ ;
78 if($selected){
79 $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'> ".$cat." </td>";
80 }else{
81 $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'> ".$cat." </td>";
82 }
83 }
84 $CHKS .= "</td></tr></table>";
86 $packages = array();
87 foreach($this->categories as $cat => $use){
88 if($use){
89 $packages = array_merge($packages,$pkgs[$cat]);
90 }
91 }
93 foreach($_POST as $name => $value){
94 if(preg_match("/^wasonpage_/i",$name)){
95 $name = preg_replace("/^wasonpage_/","",$name);
96 $n =base64_decode($name);
97 if(isset($_POST['use_'.$name])){
98 $this->selected[$n] = $n;
99 }else{
100 if(isset($this->selected[$n])){
101 unset($this->selected[$n]);
102 }
103 }
105 }
106 }
108 foreach($packages as $pkg){
109 if(preg_match("/^".str_replace("*",".*",$this->searchStrPKG)."/i",$pkg[0])){
110 if(in_array($pkg[0],$this->selected)){
111 $check = " checked ";
112 }else{
113 $check = "";
114 }
115 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check." onclick='document.mainform.submit()'>
116 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
117 $divlist->AddEntry(array(array("string"=>$chkbox),
118 array("string"=>$pkg[0]),
119 array("string"=>$pkg[1]),
120 array("string"=>$pkg[3],"attach"=>"style='border-right:0px'")));
121 }
122 }
123 $_SESSION['searchStrPKG'] = $this->searchStrPKG;
124 $smarty->assign("CHKS" , $CHKS);
125 $smarty->assign("searchStrPKG" , $this->searchStrPKG);
126 $smarty->assign("faihead" , "");
127 $smarty->assign("failist" , $divlist->DrawList());
128 $smarty->assign("infoimage" , get_template_path('images/info.png'));
129 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
130 $smarty->assign("alphabet" , generate_alphabet());
131 $smarty->assign("apply" , apply_filter(TRUE));
132 $smarty->assign("search_image" , get_template_path('images/search.png'));
134 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
135 return($display);
136 }
138 /* Save data to object */
139 function save_object()
140 {
141 foreach($_POST as $name => $value){
142 if(preg_match("/^wasonpage_/i",$name)){
143 $name = preg_replace("/^wasonpage_/","",$name);
144 $n =base64_decode($name);
145 if(isset($_POST['use_'.$name])){
146 $this->selected[$n] = $n;
147 }else{
148 if(isset($this->selected[$n])){
149 unset($this->selected[$n]);
150 }
151 }
153 }
154 }
156 }
158 /* Check supplied data */
159 function check()
160 {
161 $message= array();
162 return ($message);
163 }
165 function save()
166 {
167 /*
168 $a_ret= array();
169 $pkgs = $this->genPkgs();
170 foreach($this->selected as $pkg){
171 foreach($pkgs as $cat => $obj){
172 foreach($obj as $package){
173 if($package[0] == $pkg){
174 $a_ret[$package[0]]=$package;
175 }
176 }
177 }
178 }
179 return($a_ret);
180 */
182 return($this->selected);
183 }
185 /* Generate listbox friendly SubObject list
186 */
187 function genPkgs(){
188 /* Generate a list off available packages for this mirror, section and release
189 */
190 $strID = $this->strID; // This var contains the path to the parsed package file
192 /* Open the packelist */
193 $fp = fopen($strID,"r");
194 $a_ret = array();
195 /* Only read this file if it wasn't read before */
196 if(!isset($this->buffer[$strID])){
197 $str = "";
198 /* Parse every line and create an array */
199 while(!feof($fp)){
200 $str= fgets($fp,512);
201 $stra= split("\|",$str);
202 if(count($stra)==4){
203 $a_ret[$stra[2]][] = $stra;
204 }
205 }
207 /* Save our Data, to avoid reading it again */
208 $this->buffer[$strID]=$a_ret;
209 return($a_ret);
210 }else{
211 return $this->buffer[$strID];
212 }
213 }
216 }
217 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
218 ?>