Code

Updated gophone realtime dependencies
[gosa.git] / plugins / admin / fai / class_faiPackageEntry.inc
1 <?php
3 class faiPackageEntry extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes   = array();
8   var $objectclasses= array();
9   var $pkgs        = array();  
11   var $buffer       = array();
12   var $categories   = array();
13   var $searchStrPKG = "";
14   var $selected     = array();
16   /* Array with available class names */
17   var $FAIAllclasses        = array();
19   function faiPackageEntry ($config, $dn= NULL,$pkgs,$selected=array())
20   {
21     plugin::plugin ($config, $dn);
22     
23     $this->pkgs=$pkgs;
25     if(isset($_SESSION['searchStrPKG'])){
26       $this->searchStrPKG=$_SESSION['searchStrPKG'];
27     }
28     $this->selected=$selected;
30     $this->searchStrPKG= _("Please enter your search string here");
31   }
33   function execute()
34   {
35         /* Call parent execute */
36         plugin::execute();
38     /* Fill templating stuff */
39     $smarty     = get_smarty();
40     $display = "";
42     $divlist = new divlist("PackageEntry");
43     $divlist->SetPluginMode();
44     $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
45     $divlist->SetEntriesPerPage(0);
46     $divlist->SetHeight("650px;");
47     $divlist->SetHeader(array(array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
48                               array("string" => "Name", "attach" => "style='width:180px;'"),
49                               array("string" => "Version", "attach" ),
50                               array("string" => "Description", "attach" => "style='width:240px;border-right:0px;text-align:left;'")));
52     if(isset($_GET['search'])){
53       $this->searchStrPKG= $_GET['search']."*";
54     }
55     
56     $pkgs= $this->pkgs;
58     unset($this->categories);
59     foreach($pkgs as $name => $entry){
60       $cat = $entry[2];
61       if(!empty($cat)){
62         if(!isset($this->categories[$cat])){  
63           $this->categories[$cat] = true;
64         }
65         if(isset($_POST['chkchange'])){
66           $this->searchStrPKG = $_POST['searchStrPKG'];
67           if(isset($_POST['CAT'.$cat])){
68             $this->categories[$cat]=true;
69           }else{
70             $this->categories[$cat]=false;
71           }
72         }
73       } 
74     }
76     $this->searchStrPKG = preg_replace("/^\+/","",$this->searchStrPKG);
77     if(empty($this->searchStrPKG)){
78       $this->searchStrPKG = "*";
79     }
81     @ksort($this->categories);
83 $CHKS = "<input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
84     $i = 0;
85     if(is_array($this->categories)) 
86     foreach($this->categories as $cat => $selected){
87       if($i == 3){
88         $CHKS .="</tr><tr>";
89         $i = 0;
90       }
91       $i ++ ;
92       if($selected){
93         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
94       }else{
95         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
96       }
97     }
98     $CHKS .= "</tr></table>";
101     foreach($_POST as $name => $value){
102       if(preg_match("/^wasonpage_/i",$name)){
103         $name = preg_replace("/^wasonpage_/","",$name);
104         $n =base64_decode($name);
106         if(isset($_POST['use_'.$name])){
107           $this->selected[$n] = $n; 
108         }else{
109           if(isset($this->selected[$n])){
110             unset($this->selected[$n]);
111           }
112         }
114       }
115     }
117     /* Prepare search filter */
118     $search_str = preg_replace("/\\\\\*/",".*",normalizePreg($this->searchStrPKG));
120     $cnt = 0; 
121     foreach($pkgs as $pkg){
122       if($cnt > 200) {
123         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));
124         break;
125       }
126       if((preg_match("/^".$search_str."/i",$pkg[0]))||
127          (preg_match("/^".$search_str."/i",$pkg[3]))){
128         if($this->categories[$pkg[2]]){
129           if(in_array($pkg[0],$this->selected)){
130             $check = " checked ";
131           }else{
132             $check = "";
133           }
134           $cnt ++ ;
135           $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check.">
136                    <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
137           $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
138                                array("string"=>$pkg[0], "attach" => "style='width:180px;'"),
139                                array("string"=>htmlentities($pkg[1])),
140                                array("string"=>htmlentities($pkg[3]), "attach" => "style='width:221px;border-right:0px;text-align:left;'")));
141         }
142       }
143     }
145     $_SESSION['searchStrPKG']       = $this->searchStrPKG;
146     $smarty->assign("CHKS"          , $CHKS);
147     $smarty->assign("searchStrPKG"  , $this->searchStrPKG);
148     $smarty->assign("faihead"       , "");
149     $smarty->assign("failist"       , $divlist->DrawList());
150     $smarty->assign("infoimage"     , get_template_path('images/info.png'));
151     $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
152     $smarty->assign("alphabet"      , generate_alphabet());
153     $smarty->assign("apply"         , apply_filter(TRUE));
154     $smarty->assign("search_image"  , get_template_path('images/search.png'));
156     $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
157     return($display);
158   }
160   /* Save data to object */
161   function save_object()
162   {
163     foreach($_POST as $name => $value){
164       if(preg_match("/^wasonpage_/i",$name)){
165         $name = preg_replace("/^wasonpage_/","",$name);
166         $n =base64_decode($name);
167         if(isset($_POST['use_'.$name])){
168           $this->selected[$n] = $n;
169         }else{
170           if(isset($this->selected[$n])){
171             unset($this->selected[$n]);
172           }
173         }
175       }
176     }
178   }
180   /* Check supplied data */
181   function check()
182   {
183     /* Call common method to give check the hook */
184     $message= plugin::check();
185         
186     return ($message);
187   }
189   function save()
190   {
191     return($this->selected);
192   }
194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
195 ?>