954cbd77b28d4fa50ebb4759a48434b5babeb311
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 $searchStr = "*";
20 /* Array with available class names */
21 var $FAIAllclasses = array();
23 function faiPackageEntry ($config, $dn= NULL,$strID=false)
24 {
25 plugin::plugin ($config, $dn);
26 $this->strID = $strID;
28 }
30 function execute()
31 {
32 /* Fill templating stuff */
33 $smarty = get_smarty();
34 $display = "";
36 $divlist = new divlist("PackageEntry");
37 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
38 $divlist->SetEntriesPerPage(20);
39 $divlist->SetHeader(array(array("string"=>" "),
40 array("string"=>"Name"),
41 array("string"=>"Version"),
42 array("string"=>"Description")));
44 if(isset($_GET['search'])){
45 $this->searchStr= $_GET['search']."*";
46 }
48 $pkgs = $this->genPkgs();
49 foreach($pkgs as $cat => $entries){
50 if(!isset($this->categories[$cat])){
51 $this->categories[$cat] = false;
52 }
53 if(isset($_POST['chkchange'])){
54 $this->searchStr = $_POST['searchStr'];
55 if(isset($_POST['CAT'.$cat])){
56 $this->categories[$cat]=true;
57 }else{
58 $this->categories[$cat]=false;
59 }
60 }
62 }
64 $CHKS = "<table><tr><td><input type='hidden' value='chkchange' name='chkchange'>";
65 foreach($this->categories as $cat => $selected){
66 if($selected){
67 $CHKS .="<input type='checkbox' value='1' name='CAT".$cat."' checked> ".$cat." ";
68 }else{
69 $CHKS .="<input type='checkbox' value='1' name='CAT".$cat."'> ".$cat." ";
70 }
71 }
72 $CHKS .= "<br><input type='submit' name='refresh0' value='"._("refresh")."'> </td></tr></table>";
74 $packages = array();
75 foreach($this->categories as $cat => $use){
76 if($use){
77 $packages = array_merge($packages,$pkgs[$cat]);
78 }
79 }
80 /*
81 foreach($_POST as $name => $value){
82 if(preg_match("/^wasonpage_/i",$name)){
83 $name = preg_replace("/^wasonpage_/","",$name);
84 if(isset($_POST['use_'.$name])){
85 print "was checked";
86 }
87 }
89 }
91 */
92 foreach($packages as $pkg){
93 if(preg_match("/^".str_replace("*",".*",$this->searchStr)."/i",$pkg[0])){
94 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."'>
95 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
96 $divlist->AddEntry(array(array("string"=>$chkbox),
97 array("string"=>$pkg[0]),
98 array("string"=>$pkg[1]),
99 array("string"=>$pkg[3])));
100 }
101 }
103 $smarty->assign("CHKS" , $CHKS);
104 $smarty->assign("searchStr" , $this->searchStr);
105 $smarty->assign("faihead" , "");
106 $smarty->assign("failist" , $divlist->DrawList());
107 $smarty->assign("infoimage" , get_template_path('images/info.png'));
108 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
109 $smarty->assign("alphabet" , generate_alphabet());
110 $smarty->assign("apply" , apply_filter(TRUE));
111 $smarty->assign("search_image" , get_template_path('images/search.png'));
113 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
114 return($display);
115 }
117 /* Save data to object */
118 function save_object()
119 {
120 }
122 /* Check supplied data */
123 function check()
124 {
125 $message= array();
126 return ($message);
127 }
129 function save()
130 {
131 $tmp = array();
132 foreach($this->FAIAllclasses as $class => $obj){
133 if($obj['status']==true){
134 $tmp[$class]=$class;
135 }
136 }
137 return($tmp);
138 }
140 /* Generate listbox friendly SubObject list
141 */
142 function genPkgs(){
143 /* Generate a list off available packages for this mirror, section and release
144 */
145 $strID = $this->strID; // This var contains the path to the parsed package file
147 /* Open the packelist */
148 $fp = fopen($strID,"r");
149 $a_ret = array();
150 /* Only read this file if it wasn't read before */
151 if(!isset($this->buffer[$strID])){
152 $str = "";
153 /* Parse every line and create an array */
154 while(!feof($fp)){
155 $str= fgets($fp,512);
156 $stra= split("\|",$str);
157 if(count($stra)==4){
158 $a_ret[$stra[2]][] = $stra;
159 }
160 }
162 /* Save our Data, to avoid reading it again */
163 $this->buffer[$strID]=$a_ret;
164 return($a_ret);
165 }else{
166 return $this->buffer[$strID];
167 }
168 }
171 }
172 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
173 ?>