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