Code

Moved search images
[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     /* If someone used the apply button, update searchfilter */
101     if(isset($_POST['Sregex'])){
102       foreach($SUBfaifilter as $key => $val){
103         if(!isset($_POST[$key])){
104           $SUBfaifilter[$key] = false;
105         }else{
106           $SUBfaifilter[$key] =$_POST[$key];
107         }
108       }
109       $SUBfaifilter['Sregex']= $_POST['Sregex'];
110       if(!strstr($SUBfaifilter['Sregex'],"*")){
111         $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
112       }
113     }
114   
115     /* Save current searchfilter in session*/
116     session::set('SUBfaifilter',$SUBfaifilter);
118     /* Check if we used a checkboxe from the list, to select dselect an entry */
119     foreach($_POST as $name => $value){
120       foreach($this->FAIAllclasses as $class => $obj){
121         $bclass = base64_encode($class);
122         if(isset($_POST["ON_PAGE_".$bclass])){
123           if(isset($_POST['USE_'.$bclass])){
124             $this->FAIAllclasses[$class]['status']=true;  
125           }else{
126             $this->FAIAllclasses[$class]['status']=false;  
127           }    
128         }
129       }
130     }
132     /* Create different picture for each object type */
133     $objTypes['FAIhook']            = "<img src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>&nbsp;";
134     $objTypes['FAItemplate']        = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''>&nbsp;";
135     $objTypes['FAIscript']          = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''>&nbsp;";
136     $objTypes['FAIvariable']        = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>&nbsp;";
137     $objTypes['FAIpackageList']     = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''>&nbsp;";
138     $objTypes['FAIpartitionTable']  = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>&nbsp;";
140     /* Magic quotes GPC, escapes every ' " \, to solve some security risks
141      * If we post the escaped strings they will be escaped again
142      */
143     foreach($this->attributes as $attrs){
144       if(get_magic_quotes_gpc()){
145         $smarty->assign($attrs,stripslashes($this->$attrs));
146       }else{
147         $smarty->assign($attrs,($this->$attrs));
148       }
149     }
151     /* Assign all filter attributes to smarty */
152     foreach($SUBfaifilter as $key => $val){
153       if(($key != "base")&&($key != "Sregex")){
154         if($val){
155           $smarty->assign($key."CHK", " checked ");
156         }else{
157           $smarty->assign($key."CHK", "");
158         }
159       }else{
160         $smarty->assign($key,$val);
161       }
162     }
163   
164     /* Create a divlist to display all available class names with the depending object types */
165     $divlist = new divlist("ProfileEntry");
166     $divlist->SetPluginMode();
167     $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
168     $divlist->SetEntriesPerPage(0);
169     $divlist->SetHeader(array(array("string"=> _("Class name")),
170                               array("string"=> _("Objects"),"attach"=>"style='border-right:0px;'")));
172     /* Action button allows us to delete an entry */
173     $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
174               <input type='checkbox' name='USE_%KEY%' value='%KEY%' onClick='document.mainform.submit();' %CHECK%>";
176     /* Check every single class name to match the current search filter */
177     foreach($this->FAIAllclasses as $usedClass => $classes){
179       /* Skip those entries that we are not allowed to read. */
180       if(!preg_match("/r/",$classes['acl'])){
181         continue;
182       }
184       $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);  
185  
186       $abort = true;
187       if(!preg_match("/".$fi."/",$usedClass)){
188         $abort = false;
189         continue;
190       }
191       if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
192         $abort = false;
193       }
194       if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
195         $abort = false;
196       }
197       if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
198         $abort = false;
199       }
200       if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
201         $abort = false;
202       }
203       if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
204         $abort = false;
205       }
206       if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
207         $abort = false;
208       }
210       if(!$abort){
211         $str = "";
212         foreach($classes['objects'] as $class => $obj){
213           $str.= $objTypes[$obj];
214         }
216         /* Is this entry selected */ 
217         if($classes['status']==true){
218           $action_check = preg_replace("/%CHECK%/"," checked ",$action);
219         }else{
220           $action_check = preg_replace("/%CHECK%/","",$action);
221         }      
222         
223         /* Append to list */
224         $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
225         $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
226         $divlist->AddEntry(array($field1,$field2));
227       }
228     }
230     $smarty->assign("faihead"       , "");
231     $smarty->assign("failist"       , $divlist->DrawList());
232     $smarty->assign("infoimage"     , get_template_path('images/info_small.png'));
233     $smarty->assign("launchimage"   , get_template_path('images/lists/action.png'));
234     $smarty->assign("alphabet"      , generate_alphabet());
235     $smarty->assign("apply"         , apply_filter(TRUE));
236     $smarty->assign("search_image"  , get_template_path('images/lists/search.png'));
238     $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
239     return($display);
240   }
242   /* Save data to object */
243   function save_object()
244   {
245   }
247   /* Check supplied data */
248   function check()
249   {
250     /* Call common method to give check the hook */
251     $message= plugin::check();
253     return ($message);
254   }
256   function save()
257   {
258     $tmp = array();
259     foreach($this->FAIAllclasses as $class => $obj){
260       if($obj['status']==true){
261         $tmp[$class]=$class;
262       }
263     }
264     return($tmp);
265   }
267 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
268 ?>