Code

c0938a4c3300d6c7718ade6d06a0353928da4dce
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiProfileEntry.inc
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(),$base)
15   {
16     plugin::plugin ($config, $dn);
18     /* Search only in fai tree */
19     $this->ui = get_userinfo();
21     $filter = "(|(objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)".
22                 "(objectClass=FAIvariable)(objectClass=FAIpartitionTable)(objectClass=FAIpackageList))";
24     $FAI_objects = FAI::get_all_objects_for_given_base($base,$filter,true);
26     /* Create array with categories to be able to sort different types of objects */
27     $categories = array("FAIscript"         => "faiScript",
28                         "FAItemplate"       => "faiTemplate",
29                         "FAIhook"           => "faiHook",
30                         "FAIvariable"       => "faiVariable",
31                         "FAIpartitionTable" => "faiPartitionTable",
32                         "FAIpackageList"    => "faiPackageList");
34     /* Read out all objects from fai tree */
35     $ldap= $this->config->get_ldap_link();
36     $ldap->cd($base);
37     $sort=array();
38     foreach($FAI_objects as $obj){
40       $ldap->cat($obj['dn']);
41       $attrs = $ldap->fetch();
43       /* Only use objects which have cn set */
44       if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
45         foreach($categories as $cat => $acl){
46           if(in_array($cat,$attrs['objectClass'])){
48             $acl =  $this->ui->get_permissions($attrs['dn'],"fai/".$acl); 
50             /* Append different types of objects */
51             $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
53             if(!isset($this->FAIAllclasses[$attrs['cn'][0]]['acl'])){
54               $this->FAIAllclasses[$attrs['cn'][0]]['acl']="";
55             }
56             $this->FAIAllclasses[$attrs['cn'][0]]['acl'].=$acl;
58             /* Set selected status to false */
59             $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
61             $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
62           }
63         } 
64       }
65     }
68     $tmp = array();
69     ksort($sort);
70     foreach($sort as $name){
71       $tmp[$name] =$this->FAIAllclasses[$name];
72     }
73     $this->FAIAllclasses = array();
74     $this->FAIAllclasses = $tmp;
76     /* If no search filter is set, create one */
77     if (!session::is_set("SUBfaifilter")){
78       $SUBfaifilter= array("base" => get_ou('faiou').session::get('CurrentMainBase'), "Sregex" => "*");
79       $SUBfaifilter['SShowTemplates'] = true;
80       $SUBfaifilter['SShowScripts']   = true;
81       $SUBfaifilter['SShowHooks']     = true;
82       $SUBfaifilter['SShowVariables'] = true;
83       $SUBfaifilter['SShowPackages']  = true;
84       $SUBfaifilter['SShowPartitions']= true;
85       session::set("SUBfaifilter", $SUBfaifilter);
86     }
87   }
89   function execute()
90   {
91     /* Call parent execute */
92     plugin::execute();
94     /* Fill templating stuff */
95     $smarty     = get_smarty();
96     $display = "";
98     $SUBfaifilter  = session::get('SUBfaifilter');
100     /* Get alphabet selection */
101     if(isset($_GET['search'])){
102       $SUBfaifilter['Sregex'] = strtolower($_GET['search'])."*";
103     }
105     /* If someone used the apply button, update searchfilter */
106     if(isset($_POST['Sregex'])){
107       foreach($SUBfaifilter as $key => $val){
108         if(!isset($_POST[$key])){
109           $SUBfaifilter[$key] = false;
110         }else{
111           $SUBfaifilter[$key] =$_POST[$key];
112         }
113       }
114       $SUBfaifilter['Sregex']= $_POST['Sregex'];
115       if(!strstr($SUBfaifilter['Sregex'],"*")){
116         $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
117       }
118     }
119   
120     /* Save current searchfilter in session*/
121     session::set('SUBfaifilter',$SUBfaifilter);
123     /* Check if we used a checkboxe from the list, to select dselect an entry */
124     foreach($_POST as $name => $value){
125       foreach($this->FAIAllclasses as $class => $obj){
126         $bclass = base64_encode($class);
127         if(isset($_POST["ON_PAGE_".$bclass])){
128           if(isset($_POST['USE_'.$bclass])){
129             $this->FAIAllclasses[$class]['status']=true;  
130           }else{
131             $this->FAIAllclasses[$class]['status']=false;  
132           }    
133         }
134       }
135     }
137     /* Create different picture for each object type */
138     $objTypes['FAIhook']            = "<img src='plugins/fai/images/fai_hook.png' title='"._("Hook bundle")."' alt=''>&nbsp;";
139     $objTypes['FAItemplate']        = "<img src='plugins/fai/images/fai_template.png' title='"._("Template bundle")."' alt=''>&nbsp;";
140     $objTypes['FAIscript']          = "<img src='plugins/fai/images/fai_script.png' title='"._("Script bundle")."' alt=''>&nbsp;";
141     $objTypes['FAIvariable']        = "<img src='plugins/fai/images/fai_variable.png' title='"._("Variable bundle")."' alt=''>&nbsp;";
142     $objTypes['FAIpackageList']     = "<img src='plugins/fai/images/fai_packages.png' title='"._("Package bundle")."' alt=''>&nbsp;";
143     $objTypes['FAIpartitionTable']  = "<img src='plugins/fai/images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>&nbsp;";
145     /* Magic quotes GPC, escapes every ' " \, to solve some security risks
146      * If we post the escaped strings they will be escaped again
147      */
148     foreach($this->attributes as $attrs){
149       if(get_magic_quotes_gpc()){
150         $smarty->assign($attrs,stripslashes($this->$attrs));
151       }else{
152         $smarty->assign($attrs,($this->$attrs));
153       }
154     }
156     /* Assign all filter attributes to smarty */
157     foreach($SUBfaifilter as $key => $val){
158       if(($key != "base")&&($key != "Sregex")){
159         if($val){
160           $smarty->assign($key."CHK", " checked ");
161         }else{
162           $smarty->assign($key."CHK", "");
163         }
164       }else{
165         $smarty->assign($key,$val);
166       }
167     }
168   
169     /* Create a divlist to display all available class names with the depending object types */
170     $divlist = new divlist("ProfileEntry");
171     $divlist->SetPluginMode();
172     $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
173     $divlist->SetEntriesPerPage(0);
174     $divlist->SetHeader(array(array("string"=> _("Class name")),
175                               array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
177     /* Action button allows us to delete an entry */
178     $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
179               <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
181     /* Check every single class name to match the current search filter */
182     foreach($this->FAIAllclasses as $usedClass => $classes){
184       /* Skip those entries that we are not allowed to read. */
185       if(!preg_match("/r/",$classes['acl'])){
186         continue;
187       }
189       $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);  
190  
191       $abort = true;
192       if(!preg_match("/^".$fi."/i",$usedClass)){
193         $abort = false;
194         continue;
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         }      
227         
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/lists/action.png'));
239     $smarty->assign("alphabet"      , generate_alphabet());
240     $smarty->assign("apply"         , apply_filter(TRUE));
241     $smarty->assign("search_image"  , get_template_path('images/lists/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   }
272 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
273 ?>