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 $smarty->assign("ClassName", $this->ClassName);
114 $display.= $smarty->fetch(get_template_path('askClassName.tpl', TRUE));
115 return($display);
116 }
118 /* Get posts and set class name
119 */
120 function save_object()
121 {
122 if(isset($_POST['classSelector']) && $_POST['classSelector'] == 1
123 && isset($_POST['edit_continue'])){
124 $this->ClassName = $_POST['UseTextInputName'];
125 $this->ClassAlreadyExists = true;
126 }
128 if(isset($_POST['classSelector']) && $_POST['classSelector'] == 2
129 && isset($_POST['edit_continue'])){
130 $this->ClassAlreadyExists = false;
131 $this->ClassName = $_POST['SelectedClass'];
132 }
133 }
135 /* Check given class name
136 */
137 function check()
138 {
139 /* Call common method to give check the hook */
140 $message= plugin::check();
142 if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){
143 $message[] = _("Spaces are not allowed within class names.");
144 }
146 if(empty($this->ClassName)){
147 $message[]=_("The given class name is empty.");
148 }
150 if(in_array($this->ClassName,$this->forbidden)){
151 $message[]=_("The specified class name is already in use for this object type.");
152 }
154 return ($message);
155 }
158 /* Return the class name */
159 function save()
160 {
161 return($this->ClassName);
162 }
164 }
166 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
167 ?>