1 <?php
3 class phoneGeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage phone base 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 /* Generic terminal attributes */
11 var $interfaces= array();
12 var $ignore_account= TRUE;
14 /* Needed values and lists */
15 var $base= "";
16 var $cn= "";
17 var $macAddress= "";
18 var $ipHostNumber= "";
19 var $description= "";
20 var $orig_dn= "";
22 /* attribute list for save action */
23 var $attributes= array("cn", "description", "macAddress", "ipHostNumber");
24 var $objectclasses= array("top", "goFonHardware");
26 function phonegeneric ($config, $dn= NULL)
27 {
28 plugin::plugin ($config, $dn);
30 /* Set base */
31 if ($this->dn == "new"){
32 $ui= get_userinfo();
33 $this->base= dn2base($ui->dn);
34 $this->cn= "";
35 } else {
36 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
37 }
39 /* Save dn for later references */
40 $this->orig_dn= $this->dn;
41 }
43 function execute()
44 {
45 /* Do we represent a valid phone? */
46 if (!$this->is_account && $this->parent == NULL){
47 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
48 _("This 'dn' has no phone features.")."</b>";
49 return($display);
50 }
52 /* Fill templating stuff */
53 $smarty= get_smarty();
54 $smarty->assign("bases", $this->config->idepartments);
56 /* Assign attributes */
57 foreach ($this->attributes as $attr){
58 $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
59 $smarty->assign("$attr", $this->$attr);
60 }
61 $smarty->assign("base_select", $this->base);
63 /* Show Asterisk for required attribute ipHostNumber and macAddress */
64 $smarty->assign("staticAddress", "<font class=\"must\">*</font>");
66 /* Show main page */
67 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
68 return($smarty->fetch (get_template_path('phone.tpl', TRUE)));
69 }
71 function remove_from_parent()
72 {
73 $ldap= $this->config->get_ldap_link();
74 $ldap->rmdir($this->dn);
75 show_ldap_error($ldap->get_error());
76 $this->handle_post_events("remove");
78 /* Delete references to object groups */
79 $ldap->cd ($this->config->current['BASE']);
80 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
81 while ($ldap->fetch()){
82 $og= new ogroup($this->config, $ldap->getDN());
83 unset($og->member[$this->dn]);
84 $og->save ();
85 }
87 }
90 /* Save data to object */
91 function save_object()
92 {
93 plugin::save_object();
95 /* Save base, since this is no LDAP attribute */
96 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
97 $this->base= $_POST['base'];
98 }
99 }
102 /* Check supplied data */
103 function check()
104 {
105 $message= array();
106 $this->dn= "cn=".$this->cn.",ou=phones,ou=systems,".$this->base;
108 /* must: cn, macAddress, ipHostNumber */
109 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
110 $message[]= _("The required field 'Phone name' is not set.");
111 }
112 if ($this->cn == "0" && chkacl ($this->acl, "cn") == ""){
113 $message[]= _("The 'Phone name' '0' is reserved and cannot be used.");
114 }
115 if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
116 $message[]= _("The required field 'MAC-address' is not set.");
117 }
118 if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
119 $message[]= _("The required field 'IP-address' is not set.");
120 }
122 $ui= get_userinfo();
123 $acl= get_permissions ($this->dn, $ui->subtreeACL);
124 $acl= get_module_permission($acl, "phone", $this->dn);
125 if (chkacl($acl, "create") != ""){
126 $message[]= _("You have no permissions to create a phone on this 'Base'.");
127 }
129 if ($this->orig_dn != $this->dn){
130 $ldap= $this->config->get_ldap_link();
131 $ldap->cd ($this->base);
132 $ldap->search ("(cn=".$this->cn.")", array("cn"));
133 if ($ldap->count() != 0){
134 while ($attrs= $ldap->fetch()){
135 if ($attrs['dn'] != $this->orig_dn){
136 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
137 break;
138 }
139 }
140 }
141 }
143 return ($message);
144 }
147 /* Save to LDAP */
148 function save()
149 {
150 plugin::save();
152 /* Remove all empty values */
153 if ($this->orig_dn == 'new'){
154 $attrs= array();
155 foreach ($this->attrs as $key => $val){
156 if (is_array($val) && count($val) == 0){
157 continue;
158 }
159 $attrs[$key]= $val;
160 }
161 $this->attrs= $attrs;
162 }
164 /* Write back to ldap */
165 $ldap= $this->config->get_ldap_link();
166 if ($this->orig_dn == 'new'){
167 $ldap->cd($this->config->current['BASE']);
168 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
169 $ldap->cd($this->dn);
170 $ldap->add($this->attrs);
171 $this->handle_post_events("add");
172 } else {
173 if ($this->orig_dn != $this->dn){
174 $this->move($this->orig_dn, $this->dn);
175 }
177 $ldap->cd($this->dn);
178 $ldap->modify($this->attrs);
179 $this->handle_post_events("modify");
180 }
181 show_ldap_error($ldap->get_error());
183 /* Optionally execute a command after we're done */
184 $this->postcreate();
185 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>