Code

list base image migration for gosa-plugins
[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     $base = get_ou('faiou').session::get('CurrentMainBase');
20     $faifilter = session::get('faifilter');
21     if($faifilter['branch']!="main"){
22       $base = $faifilter['branch'];
23     }
24   
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     }
120   
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=''>&nbsp;";
140     $objTypes['FAItemplate']        = "<img src='images/fai_template.png' title='"._("Template bundle")."' alt=''>&nbsp;";
141     $objTypes['FAIscript']          = "<img src='images/fai_script.png' title='"._("Script bundle")."' alt=''>&nbsp;";
142     $objTypes['FAIvariable']        = "<img src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>&nbsp;";
143     $objTypes['FAIpackageList']     = "<img src='images/fai_packages.png' title='"._("Package bundle")."' alt=''>&nbsp;";
144     $objTypes['FAIpartitionTable']  = "<img src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>&nbsp;";
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     }
169   
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']);  
191  
192       $abort = true;
193       if(!preg_match("/".$fi."/",$usedClass)){
194         $abort = false;
195         continue;
196       }
197       if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
198         $abort = false;
199       }
200       if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
201         $abort = false;
202       }
203       if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
204         $abort = false;
205       }
206       if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
207         $abort = false;
208       }
209       if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
210         $abort = false;
211       }
212       if((isset($classes['objects']['FAIpackageList']))&&($SUBfaifilter['SShowPackages'])){
213         $abort = false;
214       }
216       if(!$abort){
217         $str = "";
218         foreach($classes['objects'] as $class => $obj){
219           $str.= $objTypes[$obj];
220         }
222         /* Is this entry selected */ 
223         if($classes['status']==true){
224           $action_check = preg_replace("/%CHECK%/"," checked ",$action);
225         }else{
226           $action_check = preg_replace("/%CHECK%/","",$action);
227         }      
228         
229         /* Append to list */
230         $field1 = array("string"=> str_replace("%KEY%",base64_encode($usedClass),$action_check).$usedClass,"attach"=>"");
231         $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
232         $divlist->AddEntry(array($field1,$field2));
233       }
234     }
236     $smarty->assign("faihead"       , "");
237     $smarty->assign("failist"       , $divlist->DrawList());
238     $smarty->assign("infoimage"     , get_template_path('images/info_small.png'));
239     $smarty->assign("launchimage"   , get_template_path('images/lists/action.png'));
240     $smarty->assign("alphabet"      , generate_alphabet());
241     $smarty->assign("apply"         , apply_filter(TRUE));
242     $smarty->assign("search_image"  , get_template_path('images/search.png'));
244     $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
245     return($display);
246   }
248   /* Save data to object */
249   function save_object()
250   {
251   }
253   /* Check supplied data */
254   function check()
255   {
256     /* Call common method to give check the hook */
257     $message= plugin::check();
259     return ($message);
260   }
262   function save()
263   {
264     $tmp = array();
265     foreach($this->FAIAllclasses as $class => $obj){
266       if($obj['status']==true){
267         $tmp[$class]=$class;
268       }
269     }
270     return($tmp);
271   }
273 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
274 ?>