1 <?php
3 class askClassName extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = TRUE;
7 var $attributes = array();
8 var $objectclasses = array("whatever");
10 var $objectClass = false;
11 var $forbidden = array();
12 var $ClassName = "";
13 var $ClassAlreadyExists = false;
14 var $parent;
16 function askClassName (&$config,$dn,$ui,$objectClass)
17 {
18 $this->ui = $ui;
19 $this->objectClass = $objectClass;
20 plugin::plugin ($config, $dn);
21 }
23 function execute()
24 {
25 /* Call parent execute */
26 plugin::execute();
28 /* Fill templating stuff */
29 $smarty = get_smarty();
30 $display= "";
32 /* First search for every ou, in given fai base
33 * With a second search detect all object that belong to the different ous.
34 */
36 $base = $this->parent->fai_release;
37 $ldap = $this->config->get_ldap_link();
39 $type_acl_mapping = array(
40 "FAIpartitionTable" => "faiPartitionTable",
41 "FAIpackageList" => "faiPackageList",
42 "FAIscript" => "faiScript",
43 "FAIvariable" => "faiVariable",
44 "FAIhook" => "faiHook",
45 "FAIprofile" => "faiProfile",
46 "FAItemplate" => "faiTemplate");
48 $filter = "";
49 foreach($type_acl_mapping as $map){
50 $filter .= "(objectClass=".$map.")";
51 }
53 $res = FAI::get_all_objects_for_given_base($base,"(|".$filter.")",TRUE);
55 $delete = array();
56 $used = array();
57 foreach($res as $object){
59 /* skip class names with this name */
60 if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){
61 if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){
62 continue;
63 }
64 $delete[] = $object['cn'][0];
65 }
67 /* Skip profiles */
68 if(!in_array("FAIprofile",$object['objectClass'])){
69 if(isset($object['cn'])){
70 $used[$object['cn'][0]]= $object['cn'][0];
71 }
72 }
73 }
75 /* Create headline
76 * Depending on the object type we want to create, a different headline will be shown
77 */
78 switch($this->objectClass) {
79 case "FAIpartitionTable": $str =_("Create new FAI object")." - "._("Partition table");break;
80 case "FAIpackageList" : $str =_("Create new FAI object")." - "._("Package bundle");break;
81 case "FAIscript" : $str =_("Create new FAI object")." - "._("Script bundle");break;
82 case "FAIvariable" : $str =_("Create new FAI object")." - "._("Variable bundle");break;
83 case "FAIhook" : $str =_("Create new FAI object")." - "._("Hook bundle");break;
84 case "FAIprofile" : $str =_("Create new FAI object")." - "._("Profile");break;
85 case "FAItemplate" : $str =_("Create new FAI object")." - "._("Template bundle");break;
86 default : $str =_("Create new FAI object");break;
87 }
88 $smarty->assign("headline",$str);
90 /* Save forbidden class names
91 */
92 $this->forbidden = $delete;
94 /* Delete all class names which already have this type of object
95 */
96 foreach($delete as $del){
97 unset($used[$del]);
98 }
100 /* if there is no class name which is missing for this type
101 * of objectClass, we only can create a new one, disable selectBox
102 */
103 if(count ($used)==0){
104 $smarty->assign("ClassNamesAvailable", " disabled ");
105 $smarty->assign("grey", 'style="color:#C0C0C0"');
106 }else{
107 $smarty->assign("ClassNamesAvailable", "");
108 $smarty->assign("grey", "");
109 }
110 ksort($used);
111 $smarty->assign("ClassNames", $used);
112 $smarty->assign("ClassName", $this->ClassName);
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($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){
142 $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->ClassName),"/[^_]/");
143 }
145 if(empty($this->ClassName)){
146 $message[]= msgPool::required(_("Name"));
147 }
149 if(in_array($this->ClassName,$this->forbidden)){
150 $message[]= msgPool::duplicated(_("Name"));
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 ?>