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 = "<input type='hidden' value='chkchange' name='chkchange'><table summary=''><tr>";
78 $i = 0;
79 foreach($this->package_sections as $cat => $selected){
80 if($i == 3){
81 $Section_boxes .="</tr><tr>";
82 $i = 0;
83 }
84 if($selected){
85 $Section_boxes .="<td><input type='checkbox' value='1' name='CAT".$cat."' checked ".
86 "onclick='document.mainform.submit()'> ".$cat." </td>";
87 }else{
88 $Section_boxes .="<td><input type='checkbox' value='1' name='CAT".$cat."' ".
89 "onclick='document.mainform.submit()'> ".$cat." </td>";
90 }
91 $i ++ ;
92 }
93 $Section_boxes .= "</tr></table>";
95 /* Create List && fill it with packages
96 */
97 $cnt = 0;
98 $this->reload();
99 $divlist = new divlist("PackageEntry");
100 $divlist->SetPluginMode();
101 $divlist->SetSummary(_("This list displays all assigned package names for this repository settings."));
102 $divlist->SetEntriesPerPage(0);
103 $divlist->SetHeader(array(array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
104 array("string" => "Name", "attach" => "style='width:180px;'"),
105 array("string" => "Version", "attach"=>"style='width:240px;'" ),
106 array("string" => "Description", "attach" => "style='border-right:0px;text-align:left;'")));
108 foreach($this->pkgs as $pkg){
109 if(in_array($pkg['PACKAGE'],$this->selected)){
110 $check = " checked ";
111 }else{
112 $check = "";
113 }
115 if(!isset($pkg['DESCRIPTION'])){
116 $pkg['DESCRIPTION'] = " ";
117 }
119 $chkbox = "<input type='checkbox' value='1' name='use_".base64_encode($pkg['PACKAGE'])."' ".$check.">
120 <input type='hidden' value='1' name='wasonpage_".base64_encode($pkg['PACKAGE'])."'>";
121 $divlist->AddEntry(array(array("string"=>$chkbox, "attach" => "style='text-align:center;width:20px;'"),
122 array("string"=>"<div style='width:178px; overflow:hidden;'>".$pkg['PACKAGE']."</div>",
123 "attach" => "style='width:180px;' title='".$pkg['PACKAGE']." (".$pkg['VERSION'].")'"),
124 array("string"=>"<div style='width:238px; overflow:hidden;'>".htmlentities($pkg['VERSION'])."</div>",
125 "attach" => "style='width:240px' title='".$pkg['PACKAGE']." (".$pkg['VERSION'].")'"),
126 array("string"=>htmlentities($pkg['DESCRIPTION']),
127 "attach" => "style='border-right:0px;text-align:left;'")));
128 }
130 $smarty->assign("Section_boxes" , $Section_boxes);
131 $smarty->assign("searchStrPKG" , $this->searchStrPKG);
132 $smarty->assign("faihead" , "");
133 $smarty->assign("failist" , $divlist->DrawList());
134 $smarty->assign("infoimage" , get_template_path('images/info.png'));
135 $smarty->assign("launchimage" , get_template_path('images/launch.png'));
136 $smarty->assign("alphabet" , generate_alphabet());
137 $smarty->assign("apply" , apply_filter(TRUE));
138 $smarty->assign("search_image" , get_template_path('images/lists/search.png'));
140 $display.= $smarty->fetch(get_template_path('faiPackageEntry.tpl', TRUE));
141 return($display);
142 }
145 /*! \brief Save HTML POST data to object
146 */
147 function save_object()
148 {
149 /* Keep sections selected */
150 foreach($_POST as $name => $value){
151 if(preg_match("/^wasonpage_/i",$name)){
152 $name = preg_replace("/^wasonpage_/","",$name);
153 $n =base64_decode($name);
154 if(isset($_POST['use_'.$name])){
155 $this->selected[$n] = $n;
156 }else{
157 if(isset($this->selected[$n])){
158 unset($this->selected[$n]);
159 }
160 }
162 }
163 }
165 /* Get Posted search filter
166 */
167 if(isset($_POST['searchStrPKG'])){
168 $this->searchStrPKG = get_post("searchStrPKG");
169 }
170 if(isset($_GET['search'])){
171 $this->searchStrPKG= $_GET['search']."*";
172 }
173 if(empty($this->searchStrPKG)){
174 $this->searchStrPKG = "*";
175 }
176 session::set('searchStrPKG',$this->searchStrPKG);
177 }
180 /*! \brief Reload list of displayed packages
181 */
182 function reload()
183 {
184 $this->pkgs = array();
185 $q = new gosaSupportDaemon();
186 $filter = preg_replace("/\*/","%",array($this->searchStrPKG));
187 $attrs = array("distribution", "package","version", "section", "description", "timestamp");
188 $ret = $q->FAI_get_packages($this->FAIdebianRelease,$attrs,$filter,0,200);
189 if($q->is_error()){
190 msg_dialog::display(_("Service infrastructure"),msgPool::siError($q->get_error()),ERROR_DIALOG);
191 }else{
192 foreach($ret as $attr){
193 $this->pkgs[$attr['PACKAGE']] = $attr;
194 }
195 }
196 }
199 /*! \brief Return all selected packages
200 @return Array All selected package names
201 */
202 function save()
203 {
204 return($this->selected);
205 }
206 }
207 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
208 ?>