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 = "none";
14 var $SystemType = "workstation";
16 var $dn;
18 function SelectDeviceType (&$config, $dn= NULL)
19 {
20 if(!is_array($dn)){
21 $this->dns = array($dn);
22 plugin::plugin ($config, NULL);
23 }else{
24 $this->dns = $dn;
25 plugin::plugin ($config, $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 if(class_available("opsi")){
41 $this->SystemTypes["opsi_client"]= _("Windows workstation");
42 }
43 }
45 function execute()
46 {
47 /* Call parent execute */
48 plugin::execute();
51 /* Get object groups */
52 $ldap = $this->config->get_ldap_link();
53 $ldap->cd ($this->config->current['BASE']);
54 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("gosaGroupObjects","cn"));
55 $tmp= array("W" => array(),"T" => array(), "S" => array(),"O" => array());
56 while($attrs = $ldap->fetch()){
57 $tmp[preg_replace("/[\[\] ]/","",$attrs['gosaGroupObjects'][0])][$attrs['dn']] = $attrs['cn'][0];
58 }
60 /* Fill templating stuff */
61 $smarty= get_smarty();
62 $display= "";
64 $map = array("workstation" => "W","terminal" => "T","server" => "S", "opsi_client" => "O");
65 $smarty->assign("dns_cnt" , count($this->dns));
66 $smarty->assign("ogroups", $tmp[$map[$this->SystemType]]);
67 $smarty->assign("SystemTypes" ,$this->SystemTypes);
68 $smarty->assign("SystemTypeKeys" ,array_flip($this->SystemTypes));
69 $smarty->assign("ObjectGroup",$this->ObjectGroup);
70 $smarty->assign("SystemType",$this->SystemType);
71 $display.= $smarty->fetch(get_template_path('SelectDeviceType.tpl', TRUE,dirname(__FILE__)));
72 return($display);
73 }
75 /* Save data to object */
76 function save_object()
77 {
79 echo "Calleed";
80 plugin::save_object();
81 foreach($this->attributes as $attr){
82 if(isset($_POST[$attr])){
83 $this->$attr = $_POST[$attr];
84 }
85 }
86 }
88 /* Check supplied data */
89 function check()
90 {
91 /* Call common method to give check the hook */
92 $message= plugin::check();
94 return ($message);
95 }
97 /* Save to LDAP */
98 function save()
99 {
100 }
101 }
103 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
104 ?>