7888d78bc36bd1f9d82ee43d65aa00dc5c0ad31e
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 $package_sections = array();
12 var $searchStrPKG = "*";
13 var $selected = array();
15 /* Array with available class names */
16 var $FAIAllclasses = array();
17 var $FAIdebianRelease ="";
19 function faiPackageEntry (&$config,$release, $used_packages=array())
20 {
21 plugin::plugin ($config, NULL);
23 $this->FAIdebianRelease = $release;
24 $this->selected = $used_packages;
25 $this->initializeSections();
27 /* Get old search filter, if there is one*/
28 $this->searchStrPKG = _("Please enter your search string here");
29 if(session::is_set("searchStrPKG")){
30 $this->searchStrPKG = session::get("searchStrPKG");
31 }
32 }
35 /*! \brief Load all release seactions from GOsa support daemon
36 */
37 function initializeSections()
38 {
39 $this->package_sections = array();
40 $q = new gosaSupportDaemon();
41 $ret = $q->FAI_get_package_sections($this->FAIdebianRelease);
42 if($q->is_error()){
43 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
44 }else{
45 foreach($ret as $entry){
46 $this->package_sections[array_pop($entry)] = TRUE;
47 }
48 }
49 }
52 /*! \brief Create HTML for this plugin.
53 @return String The html code for this plugin.
54 */
55 function execute()
56 {
57 /* Call parent execute */
58 plugin::execute();
60 /* Fill templating stuff */
61 $smarty = get_smarty();
62 $display = "";
65 /* Create section checkboxes
66 */
67 $Section_boxes = "<input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
68 $i = 0;
69 foreach($this->package_sections as $cat => $selected){
70 if($i == 3){
71 $Section_boxes .="</tr><tr>";
72 $i = 0;
73 }
74 if($selected){
75 $Section_boxes .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked ".
76 "onclick='document.mainform.submit()'> ".$cat." </td>";
77 }else{
78 $Section_boxes .="<td><input type='checkbox' value='1' name='CAT".$cat."' ".
79 "onclick='document.mainform.submit()'> ".$cat." </td>";
80 }
81 $i ++ ;
82 }
83 $Section_boxes .= "</tr></table>";
85 /* Create List && fill it with packages
86 */
87 $cnt = 0;
88 $this->reload();
89 $divlist = new divlist("PackageEntry");
90 $divlist->SetPluginMode();
91 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
92 $divlist->SetEntriesPerPage(0);
93 #$divlist->SetHeight("650px;");
94 $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
95 array("string" => "Name", "attach" => "style='width:180px;'"),
96 array("string" => "Version", "attach"=>"style='width:240px;'" ),
97 array("string" => "Description", "attach" => "style='border-right:0px;text-align:left;'")));
99 foreach($this->pkgs as $pkg){
100 if(in_array($pkg['PACKAGE'],$this->selected)){
101 $check = " checked ";
102 }else{
103 $check = "";
104 }
105 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg['PACKAGE'])."' ".$check.">
106 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg['PACKAGE'])."'>";
107 $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
108 array("string"=>$pkg['PACKAGE'], "attach" => "style='width:180px;'"),
109 array("string"=>"<div style='width:238px; overflow:hidden;'>".htmlentities($pkg['VERSION']), "attach" => "style='width:240px'"),
110 array("string"=>htmlentities($pkg['DESCRIPTION']), "attach" => "style='border-right:0px;text-align:left;'")));
111 }
113 $smarty->assign("Section_boxes" , $Section_boxes);
114 $smarty->assign("searchStrPKG" , $this->searchStrPKG);
115 $smarty->assign("faihead" , "");
116 $smarty->assign("failist" , $divlist->DrawList());
117 $smarty->assign("infoimage" , get_template_path('images/info.png'));
118 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
119 $smarty->assign("alphabet" , generate_alphabet());
120 $smarty->assign("apply" , apply_filter(TRUE));
121 $smarty->assign("search_image" , get_template_path('images/search.png'));
123 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
124 return($display);
125 }
128 /*! \brief Save HTML POST data to object
129 */
130 function save_object()
131 {
132 /* Keep sections selected */
133 foreach($_POST as $name => $value){
134 if(preg_match("/^wasonpage_/i",$name)){
135 $name = preg_replace("/^wasonpage_/","",$name);
136 $n =base64_decode($name);
137 if(isset($_POST['use_'.$name])){
138 $this->selected[$n] = $n;
139 }else{
140 if(isset($this->selected[$n])){
141 unset($this->selected[$n]);
142 }
143 }
145 }
146 }
148 /* Get Posted search filter
149 */
150 if(isset($_POST['searchStrPKG'])){
151 $this->searchStrPKG = get_post("searchStrPKG");
152 }
153 if(isset($_GET['search'])){
154 $this->searchStrPKG= $_GET['search']."*";
155 }
156 if(empty($this->searchStrPKG)){
157 $this->searchStrPKG = "*";
158 }
159 session::set('searchStrPKG',$this->searchStrPKG);
160 }
163 /*! \brief Reload list of displayed packages
164 */
165 function reload()
166 {
167 $this->pkgs = array();
168 $q = new gosaSupportDaemon();
169 $filter = preg_replace("/\*/","%",array($this->searchStrPKG));
170 $attrs = array("distribution", "package","version", "section", "description", "timestamp");
171 $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$filter,0,200);
172 if($q->is_error()){
173 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
174 }else{
175 foreach($ret as $attr){
176 $this->pkgs[$attr['PACKAGE']] = $attr;
177 }
178 }
179 }
182 /*! \brief Return all selected packages
183 @return Array All selected package names
184 */
185 function save()
186 {
187 return($this->selected);
188 }
189 }
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>