Code

Adapted path and image
[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 = $_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     while($attrs = $ldap->fetch()){
34       
35       /* Only use objects which have cn set */
36       if((isset($attrs['cn'][0]))&&(!in_array($attrs['cn'][0],$used))){
37         foreach($categories as $cat){
38           if(in_array($cat,$attrs['objectClass'])){
39         
40             /* Append different types of objects */
41             $this->FAIAllclasses[$attrs['cn'][0]]['objects'][$cat]=$cat;
43             /* Set selected status to false */
44             $this->FAIAllclasses[$attrs['cn'][0]]['status']=false;
46             $sort[strtolower($attrs['cn'][0])] = $attrs['cn'][0];
47           }
48         }
49       }
50     }
52     ksort($sort);
53     foreach($sort as $name){
54       $tmp[$name] =$this->FAIAllclasses[$name];
55     }
56     $this->FAIAllclasses = array();
57     $this->FAIAllclasses = $tmp;
60     /* If no search filter is set, create one */
61     if (!is_global("SUBfaifilter")){
62       $SUBfaifilter= array("base" => "ou=fai,ou=configs,ou=systems,".$base, "Sregex" => "*");
63       $SUBfaifilter['SShowTemplates'] = false;
64       $SUBfaifilter['SShowScripts']   = false;
65       $SUBfaifilter['SShowHooks']     = false;
66       $SUBfaifilter['SShowVariables'] = false;
67       $SUBfaifilter['SShowPackages']  = false;
68       $SUBfaifilter['SShowPartitions']= false;
69       register_global("SUBfaifilter", $SUBfaifilter);
70     }
71   }
73   function execute()
74   {
75     /* Fill templating stuff */
76     $smarty     = get_smarty();
77     $display = "";
79     $SUBfaifilter = $_SESSION['SUBfaifilter'];
81     /* If someone used the apply button, update searchfilter */
82     if(isset($_POST['Sregex'])){
83       foreach($SUBfaifilter as $key => $val){
84         if(!isset($_POST[$key])){
85           $SUBfaifilter[$key] = false;
86         }else{
87           $SUBfaifilter[$key] =$_POST[$key];
88         }
89       }
90       $SUBfaifilter['Sregex']= $_POST['Sregex'];
91       if(!strstr($SUBfaifilter['Sregex'],"*")){
92         $SUBfaifilter['Sregex'] = $SUBfaifilter['Sregex']."*";
93       }
94     }
95   
96     /* Save current searchfilter in session*/
97     $_SESSION['SUBfaifilter']= $SUBfaifilter;
99     /* Check if we used a checkboxe from the list, to select dselect an entry */
100     foreach($_POST as $name => $value){
101       foreach($this->FAIAllclasses as $class => $obj){
102         if(isset($_POST["ON_PAGE_".$class])){
103           if(isset($_POST['USE_'.$class])){
104             $this->FAIAllclasses[$class]['status']=true;  
105           }else{
106             $this->FAIAllclasses[$class]['status']=false;  
107           }    
108         }
109       }
110     }
112     /* Create different picture for each object type */
113     $objTypes['FAIhook']            = "<image src='images/fai_hook.png' title='"._("Hook bundle")."' alt=''>&nbsp;";
114     $objTypes['FAItemplate']        = "<image src='images/fai_template.png' title='"._("Template bundle")."' alt=''>&nbsp;";
115     $objTypes['FAIscript']          = "<image src='images/fai_script.png' title='"._("Script bundle")."' alt=''>&nbsp;";
116     $objTypes['FAIvariable']        = "<image src='images/fai_variable.png' title='"._("Variable bundle")."' alt=''>&nbsp;";
117     $objTypes['FAIpackages']        = "<image src='images/fai_packages.png' title='"._("Package bundle")."' alt=''>&nbsp;";
118     $objTypes['FAIpartitionTable']  = "<image src='images/fai_partitionTable.png' title='"._("Partition table")."' alt=''>&nbsp;";
120     /* assign basic attributes */
121     foreach($this->attributes as $attrs){
122       $smarty->assign($attrs,stripslashes($this->$attrs));
123     }
125     /* Assign all filter attributes to smarty */
126     foreach($SUBfaifilter as $key => $val){
127       if(($key != "base")&&($key != "Sregex")){
128         if($val){
129           $smarty->assign($key."CHK", " checked ");
130         }else{
131           $smarty->assign($key."CHK", "");
132         }
133       }else{
134         $smarty->assign($key,$val);
135       }
136     }
137   
138     /* Create a divlist to display all available class names with the depending object types */
139     $divlist = new divlist("ProfileEntry");
140     $divlist->SetSummary(_("This list displays all assigned class names for this profile."));
141     $divlist->SetEntriesPerPage(20);
142     $divlist->SetHeader(array(array("string"=>"Class name"),
143                               array("string"=>"Objects")));
145     /* Action button allows us to delete an entry */
146     $action = "<input type='hidden' name='ON_PAGE_%KEY%' value='1'>
147               <input type='checkbox' name='USE_%KEY%' value='%KEY%' onChange='document.mainform.submit();' %CHECK%>";
149     /* Check every single class name to match the current search filter */
150     foreach($this->FAIAllclasses as $usedClass => $classes){
152       $fi = str_replace("*",".*",$SUBfaifilter['Sregex']);  
153  
154       $abort = false; 
155       if(!preg_match("/".$fi."/",$usedClass)){
156         $abort = true;
157       }
158       if(($SUBfaifilter['SShowScripts'])&&(!in_array('FAIscript',$classes['objects']))){
159         $abort = true;
160       }
161       if(($SUBfaifilter['SShowTemplates'])&&(!in_array('FAItemplate',$classes['objects']))){
162         $abort = true;
163       }
164       if(($SUBfaifilter['SShowHooks'])&&(!in_array('FAIhook',$classes['objects']))){
165         $abort = true;
166       }
167       if(($SUBfaifilter['SShowVariables'])&&(!in_array('FAIvariable',$classes['objects']))){
168         $abort = true;
169       }
170       if(($SUBfaifilter['SShowPartitions'])&&(!in_array('FAIpartitionTable',$classes['objects']))){
171         $abort = true;
172       }
173       if(($SUBfaifilter['SShowPackages'])&&(!in_array('FAIpackages',$classes['objects']))){
174         $abort = true;
175       }
177       if(!$abort){
178         $str = "";
179         foreach($classes['objects'] as $class => $obj){
180           $str.= $objTypes[$obj];
181         }
183         /* Is this entry selected */ 
184         if($classes['status']==true){
185           $action_check = preg_replace("/%CHECK%/"," checked ",$action);
186         }else{
187           $action_check = preg_replace("/%CHECK%/","",$action);
188         }      
189         
190         /* Append to list */
191         $field1 = array("string"=> preg_replace("/%KEY%/",$usedClass,$action_check).$usedClass,"attach"=>"");
192         $field2 = array("string"=> $str,"attach"=>"");
193         $divlist->AddEntry(array($field1,$field2));
194       }
195     }
197     $smarty->assign("faihead"       , "");
198     $smarty->assign("failist"       , $divlist->DrawList());
199     $smarty->assign("infoimage"     , get_template_path('images/info.png'));
200     $smarty->assign("launchimage"   , get_template_path('images/launch.png'));
201     $smarty->assign("alphabet"      , generate_alphabet());
202     $smarty->assign("apply"         , apply_filter(TRUE));
203     $smarty->assign("search_image"  , get_template_path('images/search.png'));
205     $display.= $smarty->fetch(get_template_path('faiProfileEntry.tpl', TRUE));
206     return($display);
207   }
209   /* Save data to object */
210   function save_object()
211   {
212   }
214   /* Check supplied data */
215   function check()
216   {
217     $message= array();
218     return ($message);
219   }
221   function save()
222   {
223     $tmp = array();
224     foreach($this->FAIAllclasses as $class => $obj){
225       if($obj['status']==true){
226         $tmp[$class]=$class;
227       }
228     }
229     return($tmp);
230   }
232 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
233 ?>