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