1 <?php
2 class ArpNewDevice extends plugin
3 {
4 var $cn= "";
5 var $description = "";
6 var $netConfigDNS = NULL;
7 var $attributes= array("cn","description");
8 var $objectclasses = array("gotoHard");
9 var $ignore_account = TRUE;
11 var $ObjectGroups = array();
12 var $SystemTypes = array();
14 var $ObjectGroup = "none";
15 var $SystemType = "gotoWorkstation";
17 var $gotoIntegration = FALSE;
19 function ArpNewDevice ($config, $dn= NULL, $parent= NULL)
20 {
21 plugin :: plugin($config,$dn);
22 $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
23 $this->acl = "#all#";
24 $this->netConfigDNS->acl = $this->acl;
25 $this->netConfigDNS->force_dns();
27 /* Get object groups */
28 $ldap = $this->config->get_ldap_link();
29 $ldap->cd ($this->config->current['BASE']);
30 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
31 $tmp= array();
32 while($attrs = $ldap->fetch()){
33 $tmp[$attrs['dn']]= $attrs['cn'][0];
34 }
35 asort($tmp, SORT_LOCALE_STRING);
36 $this->ObjectGroups= $tmp;
38 $this->SystemTypes =array("gotoWorkstation"=>_("Workstation"), "gotoTermminal"=>_("Terminal"), "goServer"=>_("Server"));
39 if(class_available("opsi")){
40 $this->SystemTypes["FAKE_OC_OpsiHost"]= _("Windows workstation");
41 }
42 }
44 function execute()
45 {
46 /* Get object groups */
47 $ldap = $this->config->get_ldap_link();
48 $ldap->cd ($this->config->current['BASE']);
49 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("gosaGroupObjects","cn"));
50 $tmp= array("W" => array(),"T" => array(), "S" => array(),"O" => array());
51 while($attrs = $ldap->fetch()){
52 $tmp[preg_replace("/[\[\] ]/","",$attrs['gosaGroupObjects'][0])][$attrs['dn']] = $attrs['cn'][0];
53 }
55 $smarty = get_smarty();
56 foreach($this->attributes as $attr){
57 $smarty->assign($attr,$this->$attr);
58 }
59 $this->netConfigDNS->cn= $this->cn;
61 $map = array("gotoWorkstation" => "W","gotoTerminal" => "T","goServer" => "S", "FAKE_OC_OpsiHost" => "O");
62 $smarty->assign("netconfig", $this->netConfigDNS->execute());
63 $smarty->assign("ogroups", $tmp[$map[$this->SystemType]]);
64 $smarty->assign("SystemTypes" ,$this->SystemTypes);
65 $smarty->assign("SystemTypeKeys" ,array_flip($this->SystemTypes));
66 $smarty->assign("ObjectGroup",$this->ObjectGroup);
67 $smarty->assign("SystemType",$this->SystemType);
69 $smarty->assign("gotoIntegration",$this->gotoIntegration);
71 /* Display sub dialog from network settings */
72 $this->netConfigDNS->acl = $this->acl;
73 if($this->netConfigDNS->dialog){
74 $this->dialog = TRUE;
75 return($this->netConfigDNS->execute());
76 }else{
77 $this->dialog = FALSE;
78 }
80 return($smarty->fetch (get_template_path('ArpNewDevice.tpl', TRUE,dirname(__FILE__))));
81 }
83 function check()
84 {
85 $message= plugin::check();
86 $message= array_merge($message, $this->netConfigDNS->check());
87 if(empty($this->cn)){
88 $message[] = msgPool::required(_("Name"));
89 }
90 return($message);
91 }
93 function save_object()
94 {
95 if(isset($_POST['ArpNewDevice_posted'])){
96 plugin::save_object();
97 $this->netConfigDNS->save_object();
99 $this->gotoIntegration = isset($_POST['gotoIntegration']);
100 if($this->gotoIntegration){
101 if(isset($_POST['SystemType'])){
102 $this->SystemType = get_post('SystemType');
103 }
104 if(isset($_POST['ObjectGroup'])){
105 $this->ObjectGroup = get_post('ObjectGroup');
106 }
107 }
108 }
109 }
111 function save()
112 {
114 $this->netConfigDNS->acl = $this->acl;
115 plugin::save();
116 $this->netConfigDNS->cn = $this->cn;
117 $this->netConfigDNS->save($this->dn);
119 // Do not remove this Arp-Device if gotoIntegration was selected.
120 if(!$this->gotoIntegration){
122 $ldap = $this->config->get_ldap_link();
123 $ldap->cd($this->config->current['BASE']);
124 $ldap->rmdir_recursive($this->dn);
125 if (!$ldap->success()){
126 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $key->dn, LDAP_DEL, get_class()));
127 }
128 }
129 }
130 }
132 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
133 ?>