Code

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1522 594d385d-05f5-0310...
[gosa.git] / plugins / admin / fai / class_askClassName.inc
1 <?php
3 class askClassName 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("whatever");
15   var $objectClass    = false;
16   var $forbidden      =array();
17   var $ClassName          = "";  
18   var $ClassAlreadyExists = false;
20   function askClassName ($config, $dn= NULL,$ui = false, $objectClass)
21   {
22     $this->ui = $ui;
23     $this->objectClass = $objectClass;
24     plugin::plugin ($config, $dn);
25   }
27   function execute()
28   {
29     /* Fill templating stuff */
30     $smarty = get_smarty();
31     $display= "";
33     /* The faifilter contais 
34        The base for all fai objects 
35      */
36     $faifilter = $_SESSION['faifilter'];
38     /* First search for every ou, in given fai base
39      * With a second search detect all object that belong to the different ous. 
40      */
41     $base = "ou=fai,ou=configs,ou=systems,".$faifilter['base'];
42     $ldap = $this->config->get_ldap_link();
43     $res  = get_list($this->ui->subtreeACL, "(objectClass=organizationalUnit)",FALSE, $base, array("cn","description","objectClass"),TRUE);
44     $used = array();
46     $delete = array();
47     foreach($res as $objecttypes){
48       $res2 = get_list2($this->ui->subtreeACL, "(objectClass=*)",
49           FALSE, $objecttypes['dn'], array("cn","description","objectClass","FAIclass"),TRUE);
51       foreach($res2 as $object){
52       
53         /* skip class names with this name */ 
54         if(in_array($this->objectClass,$object['objectClass'])){
55           $delete[] = $object['cn'][0];
56         }
57     
58         /* Skip profiles */
59         if(!in_array("FAIprofile",$object['objectClass'])){
60           $used[$object['cn'][0]]= $object['cn'][0];
61         }
62       }
63     }
64     
65     /* Create headline
66      * Depending on the object type we want to create, a different headline will be shown
67      */ 
68     switch($this->objectClass) {
69       case "FAIpartitionTable":  $str =_("Create new FAI object - partition table.");break;
70       case "FAIpackageList"   :  $str =_("Create new FAI object - package bundle.");break;
71       case "FAIscript"        :  $str =_("Create new FAI object - script bundle.");break;
72       case "FAIvariable"      :  $str =_("Create new FAI object - variable bundle.");break;
73       case "FAIhook"          :  $str =_("Create new FAI object - hook bundle.");break;
74       case "FAIprofile"       :  $str =_("Create new FAI object - profile.");break;
75       case "FAItemplate"      :  $str =_("Create new FAI object - template.");break;
76       default                 :  $str =_("Create new FAI object");break;
77     }
78     $smarty->assign("headline",$str);
79     
80     /* Save forbidden class names
81      */
82     $this->forbidden = $delete;
84     /* Delete all class names which already have this type of object 
85      */
86     foreach($delete as $del){
87       unset($used[$del]);
88     }
89    
90     /* if there is no class name which is missing for this type 
91      *  of objectClass, we only can create a new one, disable selectBox 
92      */
93     if(count ($used)==0){
94       $smarty->assign("ClassNamesAvailable", " disabled ");
95     }else{
96       $smarty->assign("ClassNamesAvailable", "");
97     }
98     $smarty->assign("ClassNames", $used);
99     $smarty->assign("ClassNameKeys", $used);
100     $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
101     return($display);
102   }
104   /* Get posts and set class name 
105    */ 
106   function save_object()
107   {
108     if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1 
109        && isset($_POST['edit_continue'])){
110       $this->ClassName          = $_POST['UseTextInputName'];
111       $this->ClassAlreadyExists = true;
112     }
113   
114     if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2 
115        && isset($_POST['edit_continue'])){
116       $this->ClassAlreadyExists = false;
117       $this->ClassName          = $_POST['SelectedClass'];
118     }
119   }
121   /* Check given class name 
122    */
123   function check()
124   {
125     $message= array();
126     if(empty($this->ClassName)){
127       $message[]=_("The given class name is empty.");
128     }
130     if(in_array($this->ClassName,$this->forbidden)){
131       $message[]=_("The specified class name is already in use for this object type.");
132     }
134     if(preg_match("/[^a-z0-9]/i",$this->ClassName)){
135       $message[]=_("Please enter a valid class name. Only 0-9 a-z is allowed here.");
136     }
137  
138     return ($message);
139   }
142   /* Return the class name */
143   function save()
144   {
145     return($this->ClassName);
146   }
150 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
151 ?>