Code

2693af1a7f74a09a62e626d2c793a6dbe799bb4f
[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 $strID        = "";  
16   var $buffer       = array();
17   var $categories   = array();
18   var $searchStr    = "*";
19   var $selected     = array();
21   /* Array with available class names */
22   var $FAIAllclasses        = array();
24   function faiPackageEntry ($config, $dn= NULL,$strID=false,$selected=array())
25   {
26     plugin::plugin ($config, $dn);
27     $this->strID = $strID;
29     $this->selected=$selected;
30   }
32   function execute()
33   {
34     /* Fill templating stuff */
35     $smarty     = get_smarty();
36     $display = "";
38     $divlist = new divlist("PackageEntry");
39     $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
40     $divlist->SetEntriesPerPage(20);
41     $divlist->SetHeader(array(array("string"=>"&nbsp;"),
42                               array("string"=>"Name"),
43                               array("string"=>"Version"),
44                               array("string"=>"Description","attach"=>"style='border-right:0px;'")));
46     if(isset($_GET['search'])){
47       $this->searchStr= $_GET['search']."*";
48     }
50     $pkgs = $this->genPkgs();
51     foreach($pkgs as $cat => $entries){
52       if(!isset($this->categories[$cat])){  
53         $this->categories[$cat] = false;
54       }
55       if(isset($_POST['chkchange'])){
56         $this->searchStr = $_POST['searchStr'];
57         if(isset($_POST['CAT'.$cat])){
58           $this->categories[$cat]=true;
59         }else{
60           $this->categories[$cat]=false;
61         }
62       } 
63   
64     }
66     $CHKS = "<table><tr><input type='hidden' value='chkchange' name='chkchange'>";
67     $i = 0; 
68     foreach($this->categories as $cat => $selected){
69       if($i == 3){
70         $CHKS .="</tr><tr>";
71         $i = 0;
72       }
73       $i ++ ;
74       if($selected){
75         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
76       }else{
77         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
78       }
79     }
80     $CHKS .= "<br><input type='submit' name='refresh0' value='"._("refresh")."'> </td></tr></table>";
82     $packages = array();
83     foreach($this->categories as $cat => $use){
84       if($use){
85         $packages = array_merge($packages,$pkgs[$cat]);
86       }
87     }
89     foreach($_POST as $name => $value){
90       if(preg_match("/^wasonpage_/i",$name)){
91         $name = preg_replace("/^wasonpage_/","",$name);
92         $n =base64_decode($name);
93         if(isset($_POST['use_'.$name])){
94           $this->selected[$n] = $n; 
95         }else{
96           if(isset($this->selected[$n])){
97             unset($this->selected[$n]);
98           }
99         }
101       }
102     }
104     foreach($packages as $pkg){
105       if(preg_match("/^".str_replace("*",".*",$this->searchStr)."/i",$pkg[0])){
106       if(in_array($pkg[0],$this->selected)){
107         $check = " checked ";
108       }else{
109         $check = "";
110       }
111       $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check." onclick='document.mainform.submit()'>
112                  <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
113       $divlist->AddEntry(array(array("string"=>$chkbox),
114                                array("string"=>$pkg[0]),
115                                array("string"=>$pkg[1]),
116                                array("string"=>$pkg[3],"attach"=>"style='border-right:0px'")));
117       }
118     }
120     $smarty->assign("CHKS"          , $CHKS);
121     $smarty->assign("searchStr"     , $this->searchStr);
122     $smarty->assign("faihead"       , "");
123     $smarty->assign("failist"       , $divlist->DrawList());
124     $smarty->assign("infoimage"     , get_template_path('images/info.png'));
125     $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
126     $smarty->assign("alphabet"      , generate_alphabet());
127     $smarty->assign("apply"         , apply_filter(TRUE));
128     $smarty->assign("search_image"  , get_template_path('images/search.png'));
130     $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
131     return($display);
132   }
134   /* Save data to object */
135   function save_object()
136   {
137     foreach($_POST as $name => $value){
138       if(preg_match("/^wasonpage_/i",$name)){
139         $name = preg_replace("/^wasonpage_/","",$name);
140         $n =base64_decode($name);
141         if(isset($_POST['use_'.$name])){
142           $this->selected[$n] = $n;
143         }else{
144           if(isset($this->selected[$n])){
145             unset($this->selected[$n]);
146           }
147         }
149       }
150     }
152   }
154   /* Check supplied data */
155   function check()
156   {
157     $message= array();
158     return ($message);
159   }
161   function save()
162   {
163 /*
164     $a_ret= array();
165     $pkgs = $this->genPkgs();
166     foreach($this->selected as $pkg){
167       foreach($pkgs as $cat => $obj){
168         foreach($obj as $package){
169           if($package[0] == $pkg){
170             $a_ret[$package[0]]=$package;
171           }
172         }
173       }
174     }
175     return($a_ret);
176 */
178   return($this->selected);
179   }
181     /* Generate listbox friendly SubObject list
182   */
183   function genPkgs(){
184     /* Generate a list off available packages for this mirror, section and release
185      */
186     $strID = $this->strID;    // This var contains the path to the parsed package file
187     
188     /* Open the packelist */
189     $fp = fopen($strID,"r");  
190     $a_ret = array();
191     /* Only read this file if it wasn't read before */
192     if(!isset($this->buffer[$strID])){
193       $str = "";
194       /* Parse every line and create an array */
195       while(!feof($fp)){
196         $str= fgets($fp,512);
197         $stra= split("\|",$str);
198         if(count($stra)==4){
199           $a_ret[$stra[2]][] = $stra;
200           } 
201         }
202         
203         /* Save our Data, to avoid reading it again */
204       $this->buffer[$strID]=$a_ret;
205       return($a_ret);
206     }else{
207       return $this->buffer[$strID];
208     }
209   }
213 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
214 ?>