1 <?php
3 /*! \brief See contructor
5 */
6 class faiPackageEntry extends plugin
7 {
8 /* attribute list for save action */
9 var $ignore_account= TRUE;
10 var $attributes = array();
11 var $objectclasses= array();
12 var $pkgs = array();
14 var $package_sections = array();
15 var $searchStrPKG = "*";
16 var $selected = array();
18 /* Array with available class names */
19 var $FAIAllclasses = array();
20 var $FAIdebianRelease ="";
23 /*! \brief Allows to select a set of packages for a specific release.
24 The packages are loaded from the GOsa si daemon directly
25 @param Object The GOsa configuration object
26 @param String The release name for which the packages will be loaded
27 @param Array Packages that schould be marked as selected.
28 */
29 function faiPackageEntry (&$config,$release, $used_packages=array())
30 {
31 plugin::plugin ($config, NULL);
33 $this->FAIdebianRelease = $release;
34 $this->selected = $used_packages;
35 $this->initializeSections();
37 /* Get old search filter, if there is one*/
38 $this->searchStrPKG = _("Please enter your search string here");
39 if(session::is_set("searchStrPKG")){
40 $this->searchStrPKG = session::get("searchStrPKG");
41 }
42 }
45 /*! \brief Load all release seactions from GOsa support daemon
46 */
47 function initializeSections()
48 {
49 $this->package_sections = array();
50 $q = new gosaSupportDaemon();
51 $ret = $q->FAI_get_package_sections($this->FAIdebianRelease);
52 if($q->is_error()){
53 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
54 }else{
55 foreach($ret as $entry){
56 $this->package_sections[array_pop($entry)] = TRUE;
57 }
58 }
59 }
62 /*! \brief Create HTML for this plugin.
63 @return String The html code for this plugin.
64 */
65 function execute()
66 {
67 /* Call parent execute */
68 plugin::execute();
70 /* Fill templating stuff */
71 $smarty = get_smarty();
72 $display = "";
75 /* Create section checkboxes
76 */
77 $Section_boxes = "
78 <div style='height:450px; overflow:scroll;'>
79 <input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
80 $i = 0;
81 foreach($this->package_sections as $cat => $selected){
82 $Section_boxes .= "<input type='hidden' value=1 name='CAT$cat'>";
84 if($i == 2){
85 $Section_boxes .="</tr><tr>";
86 $i = 0;
87 }
88 if($selected){
89 $Section_boxes .="<td><input type='checkbox' value='1' name='useCAT".$cat."' checked ".
90 "onclick='document.mainform.submit()'> ".$cat." </td>";
91 }else{
92 $Section_boxes .="<td><input type='checkbox' value='1' name='useCAT".$cat."' ".
93 "onclick='document.mainform.submit()'> ".$cat." </td>";
94 }
95 $i ++ ;
97 }
98 $Section_boxes .= "</tr></table></div>";
100 /* Create List && fill it with packages
101 */
102 $cnt = 0;
103 $this->reload();
104 $divlist = new divlist("PackageEntry");
105 $divlist->SetPluginMode();
106 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
107 $divlist->SetEntriesPerPage(0);
108 $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
109 array("string" => "Name", "attach" => "style='width:180px;'"),
110 array("string" => "Version", "attach"=>"style='width:240px;'" ),
111 array("string" => "Description", "attach" => "style='border-right:0px;text-align:left;'")));
113 foreach($this->pkgs as $pkg){
114 if(in_array($pkg['PACKAGE'],$this->selected)){
115 $check = " checked ";
116 }else{
117 $check = "";
118 }
120 $desc = " ";
121 if(isset($pkg['DESCRIPTION'])){
122 $desc = base64_decode($pkg['DESCRIPTION']);
123 }
125 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg['PACKAGE'])."' ".$check.">
126 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg['PACKAGE'])."'>";
127 $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
128 array("string"=>"<div style='width:178px; overflow:hidden;'>".$pkg['PACKAGE']."</div>",
129 "attach" => "style='width:180px;' title='".$pkg['PACKAGE']." (".$pkg['VERSION'].")'"),
130 array("string"=>"<div style='width:238px; overflow:hidden;'>".htmlentities($pkg['VERSION'])."</div>",
131 "attach" => "style='width:240px' title='".$pkg['PACKAGE']." (".$pkg['VERSION'].")'"),
132 array("string"=>htmlentities($desc),
133 "attach" => "style='border-right:0px;text-align:left;'")));
134 }
135 $smarty->assign("Section_boxes" , $Section_boxes);
136 $smarty->assign("searchStrPKG" , $this->searchStrPKG);
137 $smarty->assign("faihead" , "");
138 $smarty->assign("failist" , $divlist->DrawList());
139 $smarty->assign("infoimage" , get_template_path('images/info.png'));
140 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
141 $smarty->assign("alphabet" , generate_alphabet());
142 $smarty->assign("apply" , apply_filter(TRUE));
143 $smarty->assign("search_image" , get_template_path('images/lists/search.png'));
145 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
146 return($display);
147 }
150 /*! \brief Save HTML POST data to object
151 */
152 function save_object()
153 {
154 /* Keep sections selected */
155 foreach($_POST as $name => $value){
156 if(preg_match("/^wasonpage_/i",$name)){
157 $name = preg_replace("/^wasonpage_/","",$name);
158 $n =base64_decode($name);
159 if(isset($_POST['use_'.$name])){
160 $this->selected[$n] = $n;
161 }else{
162 if(isset($this->selected[$n])){
163 unset($this->selected[$n]);
164 }
165 }
167 }
168 if(preg_match("/^CAT/i", $name)) {
169 $key = "use$name";
170 $section = preg_replace("/^CAT/i", "", $name);
171 if (isset($_POST[$key])) {
172 $this->package_sections[$section] = TRUE;
173 }else {
174 $this->package_sections[$section] = FALSE;
175 }
176 }
177 }
179 /* Get Posted search filter
180 */
181 if(isset($_POST['searchStrPKG'])){
182 $this->searchStrPKG = get_post("searchStrPKG");
183 }
184 if(isset($_GET['search'])){
185 $this->searchStrPKG= $_GET['search']."*";
186 }
187 if(empty($this->searchStrPKG)){
188 $this->searchStrPKG = "*";
189 }
190 session::set('searchStrPKG',$this->searchStrPKG);
191 }
194 /*! \brief Reload list of displayed packages
195 */
196 function reload()
197 {
198 $this->pkgs = array();
199 $q = new gosaSupportDaemon();
200 $filter = preg_replace("/\*/","%",array($this->searchStrPKG));
202 /* Determine filter sections */
203 $cb = create_function('$a', 'return $a != TRUE;');
204 $exclude_sections = array_filter($this->package_sections, $cb);
206 $attrs = array("distribution", "package","version", "section", "description", "timestamp");
207 $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$filter,0,200, $exclude_sections);
208 if($q->is_error()){
209 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
210 }else{
211 foreach($ret as $attr){
212 $this->pkgs[$attr['PACKAGE']] = $attr;
213 }
214 }
215 }
218 /*! \brief Return all selected packages
219 @return Array All selected package names
220 */
221 function save()
222 {
223 return($this->selected);
224 }
225 }
226 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
227 ?>