Code

print_red replacements, translation updates
[gosa.git] / gosa-plugins / fai / admin / fai / class_askClassName.inc
1 <?php
3 class askClassName extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account     = TRUE;
7   var $attributes         = array();
8   var $objectclasses      = array("whatever");
10   var $objectClass        = false;
11   var $forbidden          = array();
12   var $ClassName          = "";  
13   var $ClassAlreadyExists = false;
15   function askClassName (&$config,$dn,$ui,$objectClass)
16   {
17     $this->ui = $ui;
18     $this->objectClass = $objectClass;
19     plugin::plugin ($config, $dn);
20     if(!session::is_set('CurrentMainBase')){
21       session::set('CurrentMainBase',$this->config->current['BASE']);
22     }
23   }
25   function execute()
26   {
27     /* Call parent execute */
28     plugin::execute();
30     /* Fill templating stuff */
31     $smarty = get_smarty();
32     $display= "";
34     /* The faifilter contais 
35      * The base for all fai objects 
36      */
37     $faifilter  = session::get('faifilter');
39     /* First search for every ou, in given fai base
40      * With a second search detect all object that belong to the different ous. 
41      */
43     $base = get_ou('faiou').session::get('CurrentMainBase');
44     if($faifilter['branch'] != "main"){
45       $base = $faifilter['branch'];
46     }
47     $ldap = $this->config->get_ldap_link();
48     
49     $res= get_list("(&(objectClass=organizationalUnit)(!(objectClass=FAIbranch)))", "fai", $base,
50                    array("cn","description","objectClass"), GL_SIZELIMIT );
52     $delete = array();
53     $used   = array();
54     foreach($res as $objecttypes){
55       $res2= get_list("(objectClass=*)", "fai", $objecttypes['dn'],
56                       array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT | GL_CONVERT );
57       foreach($res2 as $object){
59         /* skip class names with this name */ 
60         if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){
61           if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){
62             continue;
63           }
64           $delete[] = $object['cn'][0];
65         }
66     
67         /* Skip profiles */
68         if(!in_array("FAIprofile",$object['objectClass'])){
69           if(isset($object['cn'])){
70             $used[$object['cn'][0]]= $object['cn'][0];
71           }
72         }
73       }
74     }
76     /* Create headline
77      * Depending on the object type we want to create, a different headline will be shown
78      */ 
79     switch($this->objectClass) {
80       case "FAIpartitionTable":  $str =_("Create new FAI object - partition table.");break;
81       case "FAIpackageList"   :  $str =_("Create new FAI object - package bundle.");break;
82       case "FAIscript"        :  $str =_("Create new FAI object - script bundle.");break;
83       case "FAIvariable"      :  $str =_("Create new FAI object - variable bundle.");break;
84       case "FAIhook"          :  $str =_("Create new FAI object - hook bundle.");break;
85       case "FAIprofile"       :  $str =_("Create new FAI object - profile.");break;
86       case "FAItemplate"      :  $str =_("Create new FAI object - template.");break;
87       default                 :  $str =_("Create new FAI object");break;
88     }
89     $smarty->assign("headline",$str);
90     
91     /* Save forbidden class names
92      */
93     $this->forbidden = $delete;
95     /* Delete all class names which already have this type of object 
96      */
97     foreach($delete as $del){
98       unset($used[$del]);
99     }
100    
101     /* if there is no class name which is missing for this type 
102      *  of objectClass, we only can create a new one, disable selectBox 
103      */
104     if(count ($used)==0){
105       $smarty->assign("ClassNamesAvailable", " disabled ");
106       $smarty->assign("grey", 'style="color:#C0C0C0"');
107     }else{
108       $smarty->assign("ClassNamesAvailable", "");
109       $smarty->assign("grey", "");
110     }
111     ksort($used);
112     $smarty->assign("ClassNames", $used);
113     $smarty->assign("ClassName",  $this->ClassName);
114     $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
115     return($display);
116   }
118   /* Get posts and set class name 
119    */ 
120   function save_object()
121   {
122     if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1 
123        && isset($_POST['edit_continue'])){
124       $this->ClassName          = $_POST['UseTextInputName'];
125       $this->ClassAlreadyExists = true;
126     }
127   
128     if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2 
129        && isset($_POST['edit_continue'])){
130       $this->ClassAlreadyExists = false;
131       $this->ClassName          = $_POST['SelectedClass'];
132     }
133   }
135   /* Check given class name 
136    */
137   function check()
138   {
139     /* Call common method to give check the hook */
140     $message= plugin::check();
141   
142     if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){
143       $message[] = _("Spaces are not allowed within class names.");
144     }
146     if(empty($this->ClassName)){
147       $message[]=_("The given class name is empty.");
148     }
150     if(in_array($this->ClassName,$this->forbidden)){
151       $message[]=_("The specified class name is already in use for this object type.");
152     }
154     return ($message);
155   }
158   /* Return the class name */
159   function save()
160   {
161     return($this->ClassName);
162   }
166 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
167 ?>