Code

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