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