1 <?php
3 class faiProfileEntry extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account= TRUE;
7 var $attributes = array();
8 var $objectclasses= array();
10 /* Array with available class names */
11 var $FAIAllclasses = array();
12 var $ui;
14 function faiProfileEntry (&$config, $dn= NULL,$used=array(),$objects=false)
15 {
16 plugin::plugin ($config, $dn);
18 /* Search only in fai tree */
19 $base = get_ou('faiou').session::get('CurrentMainBase');
20 $faifilter = session::get('faifilter');
21 if($faifilter['branch']!="main"){
22 $base = $faifilter['branch'];
23 }
25 $this->ui = get_userinfo();
27 $filter = "(|(objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)".
28 "(objectClass=FAIvariable)(objectClass=FAIpartitionTable)(objectClass=FAIpackageList))";
30 $FAI_objects = FAI::get_all_objects_for_given_base($base,$filter,true);
32 /* Create array with categories to be able to sort different types of objects */
33 $categories = array("FAIscript" => "faiScript",
34 "FAItemplate" => "faiTemplate",
35 "FAIhook" => "faiHook",
36 "FAIvariable" => "faiVariable",
37 "FAIpartitionTable" => "faiPartitionTable",
38 "FAIpackageList" => "faiPackageList");
40 /* Read out all objects from fai tree */
41 $ldap= $this->config->get_ldap_link();
42 $ldap->cd($base);
43 $sort=array();
44 foreach($FAI_objects as $obj){
46 $ldap->cat($obj['dn']);
47 $attrs = $ldap->fetch();
49 /* Only use objects which have cn set */
50 if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
51 foreach($categories as $cat => $acl){
52 if(in_array($cat,$attrs['objectClass'])){
54 $acl = $this->ui->get_permissions($attrs['dn'],"fai/".$acl);
56 /* Append different types of objects */
57 $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
59 if(!isset($this->FAIAllclasses[$attrs['cn'][0]]['acl'])){
60 $this->FAIAllclasses[$attrs['cn'][0]]['acl']="";
61 }
62 $this->FAIAllclasses[$attrs['cn'][0]]['acl'].=$acl;
64 /* Set selected status to false */
65 $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
67 $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
68 }
69 }
70 }
71 }
74 $tmp = array();
75 ksort($sort);
76 foreach($sort as $name){
77 $tmp[$name] =$this->FAIAllclasses[$name];
78 }
79 $this->FAIAllclasses = array();
80 $this->FAIAllclasses = $tmp;
82 /* If no search filter is set, create one */
83 if (!session::is_set("SUBfaifilter")){
84 $SUBfaifilter= array("base" => get_ou('faiou').session::get('CurrentMainBase'), "Sregex" => "*");
85 $SUBfaifilter['SShowTemplates'] = true;
86 $SUBfaifilter['SShowScripts'] = true;
87 $SUBfaifilter['SShowHooks'] = true;
88 $SUBfaifilter['SShowVariables'] = true;
89 $SUBfaifilter['SShowPackages'] = true;
90 $SUBfaifilter['SShowPartitions']= true;
91 session::set("SUBfaifilter", $SUBfaifilter);
92 }
93 }
95 function execute()
96 {
97 /* Call parent execute */
98 plugin::execute();
100 /* Fill templating stuff */
101 $smarty = get_smarty();
102 $display = "";
104 $SUBfaifilter = session::get('SUBfaifilter');
106 /* If someone used the apply button, update searchfilter */
107 if(isset($_POST['Sregex'])){
108 foreach($SUBfaifilter as $key => $val){
109 if(!isset($_POST[$key])){
110 $SUBfaifilter[$key] = false;
111 }else{
112 $SUBfaifilter[$key] =$_POST[$key];
113 }
114 }
115 $SUBfaifilter['Sregex']= $_POST['Sregex'];
116 if(!strstr($SUBfaifilter['Sregex'],"*")){
117 $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
118 }
119 }
121 /* Save current searchfilter in session*/
122 session::set('SUBfaifilter',$SUBfaifilter);
124 /* Check if we used a checkboxe from the list, to select dselect an entry */
125 foreach($_POST as $name => $value){
126 foreach($this->FAIAllclasses as $class => $obj){
127 $bclass = base64_encode($class);
128 if(isset($_POST["ON_PAGE_".$bclass])){
129 if(isset($_POST['USE_'.$bclass])){
130 $this->FAIAllclasses[$class]['status']=true;
131 }else{
132 $this->FAIAllclasses[$class]['status']=false;
133 }
134 }
135 }
136 }
138 /* Create different picture for each object type */
139 $objTypes['FAIhook'] = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''> ";
140 $objTypes['FAItemplate'] = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''> ";
141 $objTypes['FAIscript'] = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''> ";
142 $objTypes['FAIvariable'] = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''> ";
143 $objTypes['FAIpackageList'] = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''> ";
144 $objTypes['FAIpartitionTable'] = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''> ";
146 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
147 * If we post the escaped strings they will be escaped again
148 */
149 foreach($this->attributes as $attrs){
150 if(get_magic_quotes_gpc()){
151 $smarty->assign($attrs,stripslashes($this->$attrs));
152 }else{
153 $smarty->assign($attrs,($this->$attrs));
154 }
155 }
157 /* Assign all filter attributes to smarty */
158 foreach($SUBfaifilter as $key => $val){
159 if(($key != "base")&&($key != "Sregex")){
160 if($val){
161 $smarty->assign($key."CHK", " checked ");
162 }else{
163 $smarty->assign($key."CHK", "");
164 }
165 }else{
166 $smarty->assign($key,$val);
167 }
168 }
170 /* Create a divlist to display all available class names with the depending object types */
171 $divlist = new divlist("ProfileEntry");
172 $divlist->SetPluginMode();
173 $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
174 $divlist->SetEntriesPerPage(0);
175 $divlist->SetHeader(array(array("string"=> _("Class name")),
176 array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
178 /* Action button allows us to delete an entry */
179 $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
180 <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
182 /* Check every single class name to match the current search filter */
183 foreach($this->FAIAllclasses as $usedClass => $classes){
185 /* Skip those entries that we are not allowed to read. */
186 if(!preg_match("/r/",$classes['acl'])){
187 continue;
188 }
190 $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);
192 $abort = true;
193 if(!preg_match("/".$fi."/",$usedClass)){
194 $abort = false;
195 }
196 if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
197 $abort = false;
198 }
199 if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
200 $abort = false;
201 }
202 if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
203 $abort = false;
204 }
205 if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
206 $abort = false;
207 }
208 if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
209 $abort = false;
210 }
211 if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
212 $abort = false;
213 }
215 if(!$abort){
216 $str = "";
217 foreach($classes['objects'] as $class => $obj){
218 $str.= $objTypes[$obj];
219 }
221 /* Is this entry selected */
222 if($classes['status']==true){
223 $action_check = preg_replace("/%CHECK%/"," checked ",$action);
224 }else{
225 $action_check = preg_replace("/%CHECK%/","",$action);
226 }
228 /* Append to list */
229 $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
230 $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
231 $divlist->AddEntry(array($field1,$field2));
232 }
233 }
235 $smarty->assign("faihead" , "");
236 $smarty->assign("failist" , $divlist->DrawList());
237 $smarty->assign("infoimage" , get_template_path('images/info_small.png'));
238 $smarty->assign("launchimage" , get_template_path('images/small_filter.png'));
239 $smarty->assign("alphabet" , generate_alphabet());
240 $smarty->assign("apply" , apply_filter(TRUE));
241 $smarty->assign("search_image" , get_template_path('images/search.png'));
243 $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
244 return($display);
245 }
247 /* Save data to object */
248 function save_object()
249 {
250 }
252 /* Check supplied data */
253 function check()
254 {
255 /* Call common method to give check the hook */
256 $message= plugin::check();
258 return ($message);
259 }
261 function save()
262 {
263 $tmp = array();
264 foreach($this->FAIAllclasses as $class => $obj){
265 if($obj['status']==true){
266 $tmp[$class]=$class;
267 }
268 }
269 return($tmp);
270 }
271 }
272 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
273 ?>