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->SetPluginMode();
49 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
50 $divlist->SetEntriesPerPage(0);
51 $divlist->SetHeight("650px;");
52 $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
53 array("string" => "Name", "attach" => "style='width:180px;'"),
54 array("string" => "Version", "attach" ),
55 array("string" => "Description", "attach" => "style='width:240px;border-right:0px;text-align:left;'")));
57 if(isset($_GET['search'])){
58 $this->searchStrPKG= $_GET['search']."*";
59 }
61 $pkgs= $this->pkgs;
63 unset($this->categories);
64 foreach($pkgs as $name => $entry){
65 $cat = $entry[2];
66 if(!empty($cat)){
67 if(!isset($this->categories[$cat])){
68 $this->categories[$cat] = true;
69 }
70 if(isset($_POST['chkchange'])){
71 $this->searchStrPKG = $_POST['searchStrPKG'];
72 if(isset($_POST['CAT'.$cat])){
73 $this->categories[$cat]=true;
74 }else{
75 $this->categories[$cat]=false;
76 }
77 }
78 }
79 }
81 $this->searchStrPKG = preg_replace("/^\+/","",$this->searchStrPKG);
82 if(empty($this->searchStrPKG)){
83 $this->searchStrPKG = "*";
84 }
86 @ksort($this->categories);
88 $CHKS = "<input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
89 $i = 0;
90 if(is_array($this->categories))
91 foreach($this->categories as $cat => $selected){
92 if($i == 3){
93 $CHKS .="</tr><tr>";
94 $i = 0;
95 }
96 $i ++ ;
97 if($selected){
98 $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'> ".$cat." </td>";
99 }else{
100 $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'> ".$cat." </td>";
101 }
102 }
103 $CHKS .= "</tr></table>";
106 foreach($_POST as $name => $value){
107 if(preg_match("/^wasonpage_/i",$name)){
108 $name = preg_replace("/^wasonpage_/","",$name);
109 $n =base64_decode($name);
111 if(isset($_POST['use_'.$name])){
112 $this->selected[$n] = $n;
113 }else{
114 if(isset($this->selected[$n])){
115 unset($this->selected[$n]);
116 }
117 }
119 }
120 }
122 /* Prepare search filter */
123 $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($this->searchStrPKG));
125 $cnt = 0;
126 foreach($pkgs as $pkg){
127 if($cnt > 200) {
128 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));
129 break;
130 }
131 if((preg_match("/^".$search_str."/i",$pkg[0]))||
132 (preg_match("/^".$search_str."/i",$pkg[3]))){
133 if($this->categories[$pkg[2]]){
134 if(in_array($pkg[0],$this->selected)){
135 $check = " checked ";
136 }else{
137 $check = "";
138 }
139 $cnt ++ ;
140 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check.">
141 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
142 $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
143 array("string"=>$pkg[0], "attach" => "style='width:180px;'"),
144 array("string"=>htmlentities($pkg[1])),
145 array("string"=>htmlentities($pkg[3]), "attach" => "style='width:221px;border-right:0px;text-align:left;'")));
146 }
147 }
148 }
150 $_SESSION['searchStrPKG'] = $this->searchStrPKG;
151 $smarty->assign("CHKS" , $CHKS);
152 $smarty->assign("searchStrPKG" , $this->searchStrPKG);
153 $smarty->assign("faihead" , "");
154 $smarty->assign("failist" , $divlist->DrawList());
155 $smarty->assign("infoimage" , get_template_path('images/info.png'));
156 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
157 $smarty->assign("alphabet" , generate_alphabet());
158 $smarty->assign("apply" , apply_filter(TRUE));
159 $smarty->assign("search_image" , get_template_path('images/search.png'));
161 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
162 return($display);
163 }
165 /* Save data to object */
166 function save_object()
167 {
168 foreach($_POST as $name => $value){
169 if(preg_match("/^wasonpage_/i",$name)){
170 $name = preg_replace("/^wasonpage_/","",$name);
171 $n =base64_decode($name);
172 if(isset($_POST['use_'.$name])){
173 $this->selected[$n] = $n;
174 }else{
175 if(isset($this->selected[$n])){
176 unset($this->selected[$n]);
177 }
178 }
180 }
181 }
183 }
185 /* Check supplied data */
186 function check()
187 {
188 /* Call common method to give check the hook */
189 $message= plugin::check();
191 return ($message);
192 }
194 function save()
195 {
196 return($this->selected);
197 }
198 }
199 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
200 ?>