Code

Added execute methods
[gosa.git] / plugins / 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();
18   function faiProfileEntry ($config, $dn= NULL,$used=array(),$objects=false)
19   {
20     plugin::plugin ($config, $dn);
22     /* Search only in fai tree */
23     $base = "ou=fai,ou=configs,ou=systems,".$_SESSION['faifilter']['base'];
25     /* Create array with categories to be able to sort different types of objects */
26     $categories = array("FAIscript","FAItemplate","FAIhook","FAIvariable","FAIpartitionTable","FAIpackage");
28     /* Read out all objects from fai tree */
29     $ldap= $this->config->get_ldap_link();
30     $ldap->cd($base);
31     $ldap->search("(| (objectClass=FAIscript)(objectClass=FAItemplate)(objectClass=FAIhook)(objectClass=FAIvariable)
32                       (objectClass=FAIpartitionTable)(objectClass=FAIpackage))",array("*"));
33     
34     $sort=array();
35     while($attrs = $ldap->fetch()){
36       
37       /* Only use objects which have cn set */
38       if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
39         foreach($categories as $cat){
40           if(in_array($cat,$attrs['objectClass'])){
41         
42             /* Append different types of objects */
43             $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
45             /* Set selected status to false */
46             $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
48             $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
49           }
50         }
51       }
52     }
53     $tmp = array();
54     ksort($sort);
55     foreach($sort as $name){
56       $tmp[$name] =$this->FAIAllclasses[$name];
57     }
58     $this->FAIAllclasses = array();
59     $this->FAIAllclasses = $tmp;
62     /* If no search filter is set, create one */
63     if (!is_global("SUBfaifilter")){
64       $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$base, "Sregex" => "*");
65       $SUBfaifilter['SShowTemplates'] = true;
66       $SUBfaifilter['SShowScripts']   = true;
67       $SUBfaifilter['SShowHooks']     = true;
68       $SUBfaifilter['SShowVariables'] = true;
69       $SUBfaifilter['SShowPackages']  = true;
70       $SUBfaifilter['SShowPartitions']= true;
71       register_global("SUBfaifilter", $SUBfaifilter);
72     }
73   }
75   function execute()
76   {
77         /* Call parent execute */
78         plugin::execute();
79     /* Fill templating stuff */
80     $smarty     = get_smarty();
81     $display = "";
83     $SUBfaifilter = $_SESSION['SUBfaifilter'];
85     /* If someone used the apply button, update searchfilter */
86     if(isset($_POST['Sregex'])){
87       foreach($SUBfaifilter as $key => $val){
88         if(!isset($_POST[$key])){
89           $SUBfaifilter[$key] = false;
90         }else{
91           $SUBfaifilter[$key] =$_POST[$key];
92         }
93       }
94       $SUBfaifilter['Sregex']= $_POST['Sregex'];
95       if(!strstr($SUBfaifilter['Sregex'],"*")){
96         $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
97       }
98     }
99   
100     /* Save current searchfilter in session*/
101     $_SESSION['SUBfaifilter']= $SUBfaifilter;
103     /* Check if we used a checkboxe from the list, to select dselect an entry */
104     foreach($_POST as $name => $value){
105       foreach($this->FAIAllclasses as $class => $obj){
106         if(isset($_POST["ON_PAGE_".$class])){
107           if(isset($_POST['USE_'.$class])){
108             $this->FAIAllclasses[$class]['status']=true;  
109           }else{
110             $this->FAIAllclasses[$class]['status']=false;  
111           }    
112         }
113       }
114     }
116     /* Create different picture for each object type */
117     $objTypes['FAIhook']            = "<image src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>&nbsp;";
118     $objTypes['FAItemplate']        = "<image src='images/fai_template.png' title='"._("Template bundle")."' alt=''>&nbsp;";
119     $objTypes['FAIscript']          = "<image src='images/fai_script.png' title='"._("Script bundle")."' alt=''>&nbsp;";
120     $objTypes['FAIvariable']        = "<image src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>&nbsp;";
121     $objTypes['FAIpackage']        = "<image src='images/fai_packages.png' title='"._("Package bundle")."' alt=''>&nbsp;";
122     $objTypes['FAIpartitionTable']  = "<image src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>&nbsp;";
124     /* Magic quotes GPC, escapes every ' " \, to solve some security risks
125      * If we post the escaped strings they will be escaped again
126      */
127     foreach($this->attributes as $attrs){
128       if(get_magic_quotes_gpc()){
129         $smarty->assign($attrs,stripslashes($this->$attrs));
130       }else{
131         $smarty->assign($attrs,($this->$attrs));
132       }
133     }
135     /* Assign all filter attributes to smarty */
136     foreach($SUBfaifilter as $key => $val){
137       if(($key != "base")&&($key != "Sregex")){
138         if($val){
139           $smarty->assign($key."CHK", " checked ");
140         }else{
141           $smarty->assign($key."CHK", "");
142         }
143       }else{
144         $smarty->assign($key,$val);
145       }
146     }
147   
148     /* Create a divlist to display all available class names with the depending object types */
149     $divlist = new divlist("ProfileEntry");
150     $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
151     $divlist->SetEntriesPerPage(0);
152     $divlist->SetHeader(array(array("string"=>"Class name"),
153                               array("string"=>"Objects","attach"=>"style='border-right:0px;'")));
155     /* Action button allows us to delete an entry */
156     $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
157               <input type='checkbox' name='USE_%KEY%' value='%KEY%' onChange='document.mainform.submit();' %CHECK%>";
159     /* Check every single class name to match the current search filter */
160     foreach($this->FAIAllclasses as $usedClass => $classes){
162       $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);  
163  
164       $abort = true; 
165       if(!preg_match("/".$fi."/",$usedClass)){
166         $abort = false;
167       }
168       if((isset($classes['objects']['FAIscript']))&&($SUBfaifilter['SShowScripts'])){
169         $abort = false;
170       }
171       if((isset($classes['objects']['FAItemplate']))&&($SUBfaifilter['SShowTemplates'])){
172         $abort = false;
173       }
174       if((isset($classes['objects']['FAIhook']))&&($SUBfaifilter['SShowHooks'])){
175         $abort = false;
176       }
177       if((isset($classes['objects']['FAIvariable']))&&($SUBfaifilter['SShowVariables'])){
178         $abort = false;
179       }
180       if((isset($classes['objects']['FAIpartitionTable']))&&($SUBfaifilter['SShowPartitions'])){
181         $abort = false;
182       }
183       if((isset($classes['objects']['FAIpackage']))&&($SUBfaifilter['SShowPackages'])){
184         $abort = false;
185       }
187       if(!$abort){
188         $str = "";
189         foreach($classes['objects'] as $class => $obj){
190           $str.= $objTypes[$obj];
191         }
193         /* Is this entry selected */ 
194         if($classes['status']==true){
195           $action_check = preg_replace("/%CHECK%/"," checked ",$action);
196         }else{
197           $action_check = preg_replace("/%CHECK%/","",$action);
198         }      
199         
200         /* Append to list */
201         $field1 = array("string"=> preg_replace("/%KEY%/",$usedClass,$action_check).$usedClass,"attach"=>"");
202         $field2 = array("string"=> $str,"attach"=>"style='border-right:0px;'");
203         $divlist->AddEntry(array($field1,$field2));
204       }
205     }
207     $smarty->assign("faihead"       , "");
208     $smarty->assign("failist"       , $divlist->DrawList());
209     $smarty->assign("infoimage"     , get_template_path('images/info.png'));
210     $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
211     $smarty->assign("alphabet"      , generate_alphabet());
212     $smarty->assign("apply"         , apply_filter(TRUE));
213     $smarty->assign("search_image"  , get_template_path('images/search.png'));
215     $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
216     return($display);
217   }
219   /* Save data to object */
220   function save_object()
221   {
222   }
224   /* Check supplied data */
225   function check()
226   {
227     $message= array();
228     return ($message);
229   }
231   function save()
232   {
233     $tmp = array();
234     foreach($this->FAIAllclasses as $class => $obj){
235       if($obj['status']==true){
236         $tmp[$class]=$class;
237       }
238     }
239     return($tmp);
240   }
242 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
243 ?>