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 $pkgs = array();
16 var $buffer = array();
17 var $categories = array();
18 var $searchStrPKG = "";
19 var $selected = array();
21 /* Array with available class names */
22 var $FAIAllclasses = array();
24 function faiPackageEntry ($config, $dn= NULL,$pkgs,$selected=array())
25 {
26 plugin::plugin ($config, $dn);
28 $this->pkgs=$pkgs;
30 if(isset($_SESSION['searchStrPKG'])){
31 $this->searchStrPKG=$_SESSION['searchStrPKG'];
32 }
33 $this->selected=$selected;
35 $this->searchStrPKG= _("Please enter your search string here");
36 }
38 function execute()
39 {
40 /* Call parent execute */
41 plugin::execute();
43 /* Fill templating stuff */
44 $smarty = get_smarty();
45 $display = "";
47 $divlist = new divlist("PackageEntry");
48 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
49 $divlist->SetEntriesPerPage(0);
50 $divlist->SetHeight("650px;");
51 $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
52 array("string" => "Name", "attach" => "style='width:180px;'"),
53 array("string" => "Version", "attach" ),
54 array("string" => "Description", "attach" => "style='width:240px;border-right:0px;text-align:left;'")));
56 if(isset($_GET['search'])){
57 $this->searchStrPKG= $_GET['search']."*";
58 }
60 $pkgs= $this->pkgs;
62 unset($this->categories);
63 foreach($pkgs as $name => $entry){
64 $cat = $entry[2];
65 if(!empty($cat)){
66 if(!isset($this->categories[$cat])){
67 $this->categories[$cat] = true;
68 }
69 if(isset($_POST['chkchange'])){
70 $this->searchStrPKG = $_POST['searchStrPKG'];
71 if(isset($_POST['CAT'.$cat])){
72 $this->categories[$cat]=true;
73 }else{
74 $this->categories[$cat]=false;
75 }
76 }
77 }
78 }
80 $this->searchStrPKG = preg_replace("/^\+/","",$this->searchStrPKG);
81 if(empty($this->searchStrPKG)){
82 $this->searchStrPKG = "*";
83 }
85 @ksort($this->categories);
87 $CHKS = "<input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
88 $i = 0;
89 if(is_array($this->categories))
90 foreach($this->categories as $cat => $selected){
91 if($i == 3){
92 $CHKS .="</tr><tr>";
93 $i = 0;
94 }
95 $i ++ ;
96 if($selected){
97 $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'> ".$cat." </td>";
98 }else{
99 $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'> ".$cat." </td>";
100 }
101 }
102 $CHKS .= "</tr></table>";
105 foreach($_POST as $name => $value){
106 if(preg_match("/^wasonpage_/i",$name)){
107 $name = preg_replace("/^wasonpage_/","",$name);
108 $n =base64_decode($name);
110 if(isset($_POST['use_'.$name])){
111 $this->selected[$n] = $n;
112 }else{
113 if(isset($this->selected[$n])){
114 unset($this->selected[$n]);
115 }
116 }
118 }
119 }
121 /* Prepare search filter */
122 $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($this->searchStrPKG));
124 $cnt = 0;
125 foreach($pkgs as $pkg){
126 if($cnt > 200) {
127 print_red(sprintf(_("Your specified search string '%s' returned too many results. Only the first 200 entries are shown, to keep the memory usage low."),$this->searchStrPKG));
128 break;
129 }
130 if((preg_match("/^".$search_str."/i",$pkg[0]))||
131 (preg_match("/^".$search_str."/i",$pkg[3]))){
132 if($this->categories[$pkg[2]]){
133 if(in_array($pkg[0],$this->selected)){
134 $check = " checked ";
135 }else{
136 $check = "";
137 }
138 $cnt ++ ;
139 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check.">
140 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
141 $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
142 array("string"=>$pkg[0], "attach" => "style='width:180px;'"),
143 array("string"=>htmlentities($pkg[1])),
144 array("string"=>htmlentities($pkg[3]), "attach" => "style='width:221px;border-right:0px;text-align:left;'")));
145 }
146 }
147 }
149 $_SESSION['searchStrPKG'] = $this->searchStrPKG;
150 $smarty->assign("CHKS" , $CHKS);
151 $smarty->assign("searchStrPKG" , $this->searchStrPKG);
152 $smarty->assign("faihead" , "");
153 $smarty->assign("failist" , $divlist->DrawList());
154 $smarty->assign("infoimage" , get_template_path('images/info.png'));
155 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
156 $smarty->assign("alphabet" , generate_alphabet());
157 $smarty->assign("apply" , apply_filter(TRUE));
158 $smarty->assign("search_image" , get_template_path('images/search.png'));
160 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
161 return($display);
162 }
164 /* Save data to object */
165 function save_object()
166 {
167 foreach($_POST as $name => $value){
168 if(preg_match("/^wasonpage_/i",$name)){
169 $name = preg_replace("/^wasonpage_/","",$name);
170 $n =base64_decode($name);
171 if(isset($_POST['use_'.$name])){
172 $this->selected[$n] = $n;
173 }else{
174 if(isset($this->selected[$n])){
175 unset($this->selected[$n]);
176 }
177 }
179 }
180 }
182 }
184 /* Check supplied data */
185 function check()
186 {
187 /* Call common method to give check the hook */
188 $message= plugin::check();
190 return ($message);
191 }
193 function save()
194 {
195 return($this->selected);
196 }
197 }
198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
199 ?>