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();
54 $res= get_list("(&(objectClass=organizationalUnit)(!(objectClass=FAIbranch)))", $this->ui->subtreeACL, $base,
55 array("cn","description","objectClass"), GL_SIZELIMIT );
57 $delete = array();
58 $used = array();
59 foreach($res as $objecttypes){
60 $res2= get_list("(objectClass=*)", $this->ui->subtreeACL, $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'])){
66 if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){
67 continue;
68 }
69 $delete[] = $object['cn'][0];
70 }
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);
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 }
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 $smarty->assign("ClassNames", $used);
117 $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
118 return($display);
119 }
121 /* Get posts and set class name
122 */
123 function save_object()
124 {
125 if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1
126 && isset($_POST['edit_continue'])){
127 $this->ClassName = $_POST['UseTextInputName'];
128 $this->ClassAlreadyExists = true;
129 }
131 if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2
132 && isset($_POST['edit_continue'])){
133 $this->ClassAlreadyExists = false;
134 $this->ClassName = $_POST['SelectedClass'];
135 }
136 }
138 /* Check given class name
139 */
140 function check()
141 {
142 /* Call common method to give check the hook */
143 $message= plugin::check();
145 if(empty($this->ClassName)){
146 $message[]=_("The given class name is empty.");
147 }
149 if(in_array($this->ClassName,$this->forbidden)){
150 $message[]=_("The specified class name is already in use for this object type.");
151 }
153 return ($message);
154 }
157 /* Return the class name */
158 function save()
159 {
160 return($this->ClassName);
161 }
163 }
165 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
166 ?>