Code

Added a first set of reference changes - nearly untested
[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     if(!isset($_SESSION['CurrentMainBase'])){
26       $_SESSION['CurrentMainBase'] = $this->config->current['BASE'];
27     }
28   }
30   function execute()
31   {
32     /* Call parent execute */
33     plugin::execute();
35     /* Fill templating stuff */
36     $smarty = get_smarty();
37     $display= "";
39     /* The faifilter contais 
40      * The base for all fai objects 
41      */
42     $faifilter = $_SESSION['faifilter'];
44     /* First search for every ou, in given fai base
45      * With a second search detect all object that belong to the different ous. 
46      */
48     $base = "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
49     if($faifilter['branch'] != "main"){
50       $base = $faifilter['branch'];
51     }
52     $ldap = $this->config->get_ldap_link();
53     
54     $res= get_list("(&(objectClass=organizationalUnit)(!(objectClass=FAIbranch)))", "fai", $base,
55                    array("cn","description","objectClass"), GL_SIZELIMIT );
57     $delete = array();
58     $used   = array();
59     foreach($res as $objecttypes){
60       $res2= get_list("(objectClass=*)", "fai", $objecttypes['dn'],
61                       array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT | GL_CONVERT );
62       foreach($res2 as $object){
64         /* skip class names with this name */ 
65         if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){
66           if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){
67             continue;
68           }
69           $delete[] = $object['cn'][0];
70         }
71     
72         /* Skip profiles */
73         if(!in_array("FAIprofile",$object['objectClass'])){
74           if(isset($object['cn'])){
75             $used[$object['cn'][0]]= $object['cn'][0];
76           }
77         }
78       }
79     }
81     /* Create headline
82      * Depending on the object type we want to create, a different headline will be shown
83      */ 
84     switch($this->objectClass) {
85       case "FAIpartitionTable":  $str =_("Create new FAI object - partition table.");break;
86       case "FAIpackageList"   :  $str =_("Create new FAI object - package bundle.");break;
87       case "FAIscript"        :  $str =_("Create new FAI object - script bundle.");break;
88       case "FAIvariable"      :  $str =_("Create new FAI object - variable bundle.");break;
89       case "FAIhook"          :  $str =_("Create new FAI object - hook bundle.");break;
90       case "FAIprofile"       :  $str =_("Create new FAI object - profile.");break;
91       case "FAItemplate"      :  $str =_("Create new FAI object - template.");break;
92       default                 :  $str =_("Create new FAI object");break;
93     }
94     $smarty->assign("headline",$str);
95     
96     /* Save forbidden class names
97      */
98     $this->forbidden = $delete;
100     /* Delete all class names which already have this type of object 
101      */
102     foreach($delete as $del){
103       unset($used[$del]);
104     }
105    
106     /* if there is no class name which is missing for this type 
107      *  of objectClass, we only can create a new one, disable selectBox 
108      */
109     if(count ($used)==0){
110       $smarty->assign("ClassNamesAvailable", " disabled ");
111       $smarty->assign("grey", 'style="color:#C0C0C0"');
112     }else{
113       $smarty->assign("ClassNamesAvailable", "");
114       $smarty->assign("grey", "");
115     }
116     ksort($used);
117     $smarty->assign("ClassNames", $used);
118     $smarty->assign("ClassName",  $this->ClassName);
119     $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
120     return($display);
121   }
123   /* Get posts and set class name 
124    */ 
125   function save_object()
126   {
127     if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1 
128        && isset($_POST['edit_continue'])){
129       $this->ClassName          = $_POST['UseTextInputName'];
130       $this->ClassAlreadyExists = true;
131     }
132   
133     if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2 
134        && isset($_POST['edit_continue'])){
135       $this->ClassAlreadyExists = false;
136       $this->ClassName          = $_POST['SelectedClass'];
137     }
138   }
140   /* Check given class name 
141    */
142   function check()
143   {
144     /* Call common method to give check the hook */
145     $message= plugin::check();
146   
147     if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){
148       $message[] = _("Spaces are not allowed within class names.");
149     }
151     if(empty($this->ClassName)){
152       $message[]=_("The given class name is empty.");
153     }
155     if(in_array($this->ClassName,$this->forbidden)){
156       $message[]=_("The specified class name is already in use for this object type.");
157     }
159     return ($message);
160   }
163   /* Return the class name */
164   function save()
165   {
166     return($this->ClassName);
167   }
171 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
172 ?>