1 <?php
3 class SelectDeviceType extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account= TRUE;
7 var $attributes= array("ObjectGroup","SystemType");
8 var $objectclasses= array("whatever");
10 var $ObjectGroups = array();
11 var $SystemTypes = array();
13 var $ObjectGroup = "";
14 var $SystemType = "";
16 var $dn;
18 function SelectDeviceType (&$config, $dn= NULL)
19 {
20 plugin::plugin ($config, NULL);
22 if(!is_array($dn)){
23 $this->dns = array($dn);
24 }else{
25 $this->dns = $dn;
26 }
28 /* Get object groups */
29 $ldap = $this->config->get_ldap_link();
30 $ldap->cd ($this->config->current['BASE']);
31 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
32 $tmp= array();
33 while($attrs = $ldap->fetch()){
34 $tmp[$attrs['dn']]= $attrs['cn'][0];
35 }
36 asort($tmp, SORT_LOCALE_STRING);
37 $this->ObjectGroups= $tmp;
39 $this->SystemTypes =array("workstation"=>_("Workstation"), "terminal"=>_("Terminal"), "server"=>_("Server"));
40 }
42 function execute()
43 {
44 /* Call parent execute */
45 plugin::execute();
47 /* Fill templating stuff */
48 $smarty= get_smarty();
49 $display= "";
51 $smarty->assign("dns" , $this->dns);
52 $smarty->assign("dns_cnt" , count($this->dns));
54 /* Add none to the list of object groups, if there is only one
55 object that currently edited. This will allow to modify attributes manually and
56 skip object group inherit.
57 */
58 $ogs = $this->ObjectGroups;
59 if(count($this->dns) == 1){
60 $tmpa['none']=_("none");
61 $ogs = array_merge($tmpa,$ogs);
62 }
64 $smarty->assign("ObjectGroups" ,$ogs);
65 $smarty->assign("ObjectGroupKeys" ,array_flip($ogs));
66 $smarty->assign("SystemTypes" ,$this->SystemTypes);
67 $smarty->assign("SystemTypeKeys" ,array_flip($this->SystemTypes));
69 $smarty->assign("ObjectGroup",$this->ObjectGroup);
70 $smarty->assign("SystemType",$this->SystemType);
72 $display.= $smarty->fetch(get_template_path('SelectDeviceType.tpl', TRUE,dirname(__FILE__)));
73 return($display);
74 }
76 /* Save data to object */
77 function save_object()
78 {
79 plugin::save_object();
80 foreach($this->attributes as $attr){
81 if(isset($_POST[$attr])){
82 $this->$attr = $_POST[$attr];
83 }
84 }
85 }
87 /* Check supplied data */
88 function check()
89 {
90 /* Call common method to give check the hook */
91 $message= plugin::check();
93 return ($message);
94 }
96 /* Save to LDAP */
97 function save()
98 {
99 }
100 }
102 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
103 ?>