Code

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