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 /* skip class names with this name */
53 if(in_array($this->objectClass,$object['objectClass'])){
54 $delete[] = $object['cn'][0];
55 }
57 /* Skip profiles */
58 if(!in_array("FAIprofile",$object['objectClass'])){
59 $used[$object['cn'][0]]= $object['cn'][0];
60 }
61 }
62 }
64 /* Create headline
65 * Depending on the object type we want to create, a different headline will be shown
66 */
67 switch($this->objectClass) {
68 case "FAIpartitionTable": $str =_("Create new FAI object - partition table.");break;
69 case "FAIpackageList" : $str =_("Create new FAI object - package bundle.");break;
70 case "FAIscript" : $str =_("Create new FAI object - script bundle.");break;
71 case "FAIvariable" : $str =_("Create new FAI object - variable bundle.");break;
72 case "FAIhook" : $str =_("Create new FAI object - hook bundle.");break;
73 case "FAIprofile" : $str =_("Create new FAI object - profile.");break;
74 case "FAItemplate" : $str =_("Create new FAI object - template.");break;
75 default : $str =_("Create new FAI object");break;
76 }
77 $smarty->assign("headline",$str);
79 /* Save forbidden class names
80 */
81 $this->forbidden = $delete;
83 /* Delete all class names which already have this type of object
84 */
85 foreach($delete as $del){
86 unset($used[$del]);
87 }
89 /* if there is no class name which is missing for this type
90 * of objectClass, we only can create a new one, disable selectBox
91 */
92 if(count ($used)==0){
93 $smarty->assign("ClassNamesAvailable", " disabled ");
94 }else{
95 $smarty->assign("ClassNamesAvailable", "");
96 }
97 $smarty->assign("ClassNames", $used);
98 $smarty->assign("ClassNameKeys", $used);
99 $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
100 return($display);
101 }
103 /* Get posts and set class name
104 */
105 function save_object()
106 {
107 if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1
108 && isset($_POST['edit_continue'])){
109 $this->ClassName = $_POST['UseTextInputName'];
110 $this->ClassAlreadyExists = true;
111 }
113 if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2
114 && isset($_POST['edit_continue'])){
115 $this->ClassAlreadyExists = false;
116 $this->ClassName = $_POST['SelectedClass'];
117 }
118 }
120 /* Check given class name
121 */
122 function check()
123 {
124 $message= array();
125 if(empty($this->ClassName)){
126 $message[]=_("The given class name is empty.");
127 }
129 if(in_array($this->ClassName,$this->forbidden)){
130 $message[]=_("The specified class name is already in use for this object type.");
131 }
133 return ($message);
134 }
137 /* Return the class name */
138 function save()
139 {
140 return($this->ClassName);
141 }
143 }
145 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
146 ?>