Code

Added http://servername/ppd/ to gotoPrinterPPD
[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 = "Please enter your search string here";
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;
34   }
36   function execute()
37   {
38         /* Call parent execute */
39         plugin::execute();
41     /* Fill templating stuff */
42     $smarty     = get_smarty();
43     $display = "";
45     $divlist = new divlist("PackageEntry");
46     $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
47     $divlist->SetEntriesPerPage(20);
48     $divlist->SetHeader(array(array("string"=>"&nbsp;"),
49                               array("string"=>"Name"),
50                               array("string"=>"Version"),
51                               array("string"=>"Description","attach"=>"style='border-right:0px;'")));
53     if(isset($_GET['search'])){
54       $this->searchStrPKG= $_GET['search']."*";
55     }
56     
57     $pkgs= $this->pkgs;
59     unset($this->categories);
60     foreach($pkgs as $name => $entry){
61       $cat = $entry[2];
62       if(!empty($cat)){
63         if(!isset($this->categories[$cat])){  
64           $this->categories[$cat] = true;
65         }
66         if(isset($_POST['chkchange'])){
67           $this->searchStrPKG = $_POST['searchStrPKG'];
68           if(isset($_POST['CAT'.$cat])){
69             $this->categories[$cat]=true;
70           }else{
71             $this->categories[$cat]=false;
72           }
73         }
74       } 
75     }
77     ksort($this->categories);
79     $CHKS = "<table><tr><input type='hidden' value='chkchange' name='chkchange'>";
80     $i = 0; 
81     foreach($this->categories as $cat => $selected){
82       if($i == 3){
83         $CHKS .="</tr><tr>";
84         $i = 0;
85       }
86       $i ++ ;
87       if($selected){
88         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
89       }else{
90         $CHKS .="<td><input type='checkbox' value='1' name='CAT".$cat."' onclick='document.mainform.submit()'>&nbsp;".$cat."&nbsp;</td>";
91       }
92     }
93     $CHKS .= "</td></tr></table>";
96     foreach($_POST as $name => $value){
97       if(preg_match("/^wasonpage_/i",$name)){
98         $name = preg_replace("/^wasonpage_/","",$name);
99         $n =base64_decode($name);
101         if(isset($_POST['use_'.$name])){
102           $this->selected[$n] = $n; 
103         }else{
104           if(isset($this->selected[$n])){
105             unset($this->selected[$n]);
106           }
107         }
109       }
110     }
112     $cnt = 0; 
113     foreach($pkgs as $pkg){
114       if((preg_match("/^".str_replace("*",".*",$this->searchStrPKG)."/i",$pkg[0]))||
115          (preg_match("/^".str_replace("*",".*",$this->searchStrPKG)."/i",$pkg[3]))){
116         if($this->categories[$pkg[2]]){
117           if(in_array($pkg[0],$this->selected)){
118             $check = " checked ";
119           }else{
120             $check = "";
121           }
122           $cnt ++ ;
123           $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg[0])."' ".$check." onclick='document.mainform.submit()'>
124                    <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg[0])."'>";
125           $divlist->AddEntry(array(array("string"=>$chkbox),
126                                  array("string"=>$pkg[0]),
127                                array("string"=>$pkg[1]),
128                                array("string"=>$pkg[3],"attach"=>"style='border-right:0px'")));
129         }
130       }
131     }
133     $_SESSION['searchStrPKG']       = $this->searchStrPKG;
134     $smarty->assign("CHKS"          , $CHKS);
135     $smarty->assign("searchStrPKG"  , $this->searchStrPKG);
136     $smarty->assign("faihead"       , "");
137     $smarty->assign("failist"       , $divlist->DrawList());
138     $smarty->assign("infoimage"     , get_template_path('images/info.png'));
139     $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
140     $smarty->assign("alphabet"      , generate_alphabet());
141     $smarty->assign("apply"         , apply_filter(TRUE));
142     $smarty->assign("search_image"  , get_template_path('images/search.png'));
144     $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
145     return($display);
146   }
148   /* Save data to object */
149   function save_object()
150   {
151     foreach($_POST as $name => $value){
152       if(preg_match("/^wasonpage_/i",$name)){
153         $name = preg_replace("/^wasonpage_/","",$name);
154         $n =base64_decode($name);
155         if(isset($_POST['use_'.$name])){
156           $this->selected[$n] = $n;
157         }else{
158           if(isset($this->selected[$n])){
159             unset($this->selected[$n]);
160           }
161         }
163       }
164     }
166   }
168   /* Check supplied data */
169   function check()
170   {
171     $message= array();
172     return ($message);
173   }
175   function save()
176   {
177     return($this->selected);
178   }
180 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
181 ?>