Code

Fixed new window for script / hook downlaod
[gosa.git] / plugins / admin / fai / class_faiPackageEntry.inc
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);
27     
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" => "&nbsp;", "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     }
59     
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()'>&nbsp;".$cat."&nbsp;</td>";
98       }else{
99         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</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     $cnt = 0; 
122     foreach($pkgs as $pkg){
123       if($cnt > 200) {
124         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));
125         break;
126       }
127       if((preg_match("/^".str_replace("*",".*",$this->searchStrPKG)."/i",$pkg[0]))||
128          (preg_match("/^".str_replace("*",".*",$this->searchStrPKG)."/i",$pkg[3]))){
129         if($this->categories[$pkg[2]]){
130           if(in_array($pkg[0],$this->selected)){
131             $check = " checked ";
132           }else{
133             $check = "";
134           }
135           $cnt ++ ;
136           $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check.">
137                    <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
138           $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
139                                array("string"=>$pkg[0], "attach" => "style='width:180px;'"),
140                                array("string"=>htmlentities($pkg[1])),
141                                array("string"=>htmlentities($pkg[3]), "attach" => "style='width:221px;border-right:0px;text-align:left;'")));
142         }
143       }
144     }
146     $_SESSION['searchStrPKG']       = $this->searchStrPKG;
147     $smarty->assign("CHKS"          , $CHKS);
148     $smarty->assign("searchStrPKG"  , $this->searchStrPKG);
149     $smarty->assign("faihead"       , "");
150     $smarty->assign("failist"       , $divlist->DrawList());
151     $smarty->assign("infoimage"     , get_template_path('images/info.png'));
152     $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
153     $smarty->assign("alphabet"      , generate_alphabet());
154     $smarty->assign("apply"         , apply_filter(TRUE));
155     $smarty->assign("search_image"  , get_template_path('images/search.png'));
157     $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
158     return($display);
159   }
161   /* Save data to object */
162   function save_object()
163   {
164     foreach($_POST as $name => $value){
165       if(preg_match("/^wasonpage_/i",$name)){
166         $name = preg_replace("/^wasonpage_/","",$name);
167         $n =base64_decode($name);
168         if(isset($_POST['use_'.$name])){
169           $this->selected[$n] = $n;
170         }else{
171           if(isset($this->selected[$n])){
172             unset($this->selected[$n]);
173           }
174         }
176       }
177     }
179   }
181   /* Check supplied data */
182   function check()
183   {
184     /* Call common method to give check the hook */
185     $message= plugin::check();
186         
187     return ($message);
188   }
190   function save()
191   {
192     return($this->selected);
193   }
195 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
196 ?>