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