Code

Fixed remove from parent for dns extension
[gosa.git] / plugins / admin / systems / class_winGeneric.inc
1 <?php
3 class wingeneric extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary        = "Manage component 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 $description= "";
17   var $orig_dn= "";
18   var $shadowLastChange="";
19   var $uidNumber="";
20   var $gidNumber="";
21   var $loginShell="";
22   var $gecos="";
23   var $shadowMin="";
24   var $shadowWarning="";
25   var $shadowInactive="";
26   var $uid="";
27   var $sn="";
28   var $givenName="";
29   var $homeDirectory="";
30   var $sambaSID="";
31   var $sambaPrimaryGroupSID="";
32   var $displayName="";
33   var $sambaPwdMustChange="";
34   var $sambaNTPassword="";
35   var $sambaPwdLastSet="";
36   var $sambaAcctFlags="";
37   var $netConfigDNS;
38   /* attribute list for save action */
39   var $ignore_account= TRUE;
40   var $attributes   = array("cn", "description","shadowLastChange",
41                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
42                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
43                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
44                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
45   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
48   function wingeneric ($config, $dn= NULL, $parent= NULL)
49   {
50     plugin::plugin ($config, $dn, $parent);
51     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses);
52     $this->netConfigDNS->acl = $this->acl;
54     /* Set base */
55     if ($this->dn == "new"){
56       $ui= get_userinfo();
57       $this->base= dn2base($ui->dn);
58       $this->cn= "";
59     } else {
60       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
61     }
63     /* Save dn for later references */
64     $this->orig_dn= $this->dn;
65   }
67   function execute()
68   {
69     $this->netConfigDNS->acl = $this->acl;
71     /* Call parent execute */
72     plugin::execute();
74     /* Do we represent a valid phone? */
75     if (!$this->is_account && $this->parent == NULL){
76       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
77         _("This 'dn' has no network features.")."</b>";
78       return($display);
79     }
81     /* Base select dialog */
82     $once = true;
83     foreach($_POST as $name => $value){
84       if(preg_match("/^chooseBase/",$name) && $once){
85         $once = false;
86         $this->dialog = new baseSelectDialog($this->config);
87         $this->dialog->setCurrentBase($this->base);
88       }
89     }
91     /* Dialog handling */
92     if(is_object($this->dialog)){
93       /* Must be called before save_object */
94       $this->dialog->save_object();
96       if($this->dialog->isClosed()){
97         $this->dialog = false;
98       }elseif($this->dialog->isSelected()){
99         $this->base = $this->dialog->isSelected();
100         $this->dialog= false;
101       }else{
102         return($this->dialog->execute());
103       }
104     }
106     /* Fill templating stuff */
107     $smarty= get_smarty();
109     // Undefined index in wingeneric.tpl ... 
110     $smarty->assign("bases", $this->config->idepartments);
112     /* Assign attributes */
113     foreach ($this->attributes as $attr){
114       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
115       $smarty->assign("$attr", $this->$attr);
116     }
117     
118     $smarty->assign("base_select", $this->base);
120     /* Show main page */
121     $this->netConfigDNS->cn= $this->cn;
122     $smarty->assign("netconfig", $this->netConfigDNS->execute());
123     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
124   }
126   function remove_from_parent()
127   {
128     $this->netConfigDNS->acl = $this->acl;
129     $this->netConfigDNS->remove_from_parent();
130     $ldap= $this->config->get_ldap_link();
131     $ldap->rmdir($this->dn);
132     show_ldap_error($ldap->get_error(), _("Removing Samba workstation failed"));
133     $this->handle_post_events("remove");
135     /* Delete references to object groups */
136     $ldap->cd ($this->config->current['BASE']);
137     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
138     while ($ldap->fetch()){
139       $og= new ogroup($this->config, $ldap->getDN());
140       unset($og->member[$this->dn]);
141       $og->save ();
142     }
143   }
146   /* Save data to object */
147   function save_object()
148   {
149     plugin::save_object();
150     $this->netConfigDNS->save_object();
151     /* Save base, since this is no LDAP attribute */
152     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
153       $this->base= $_POST['base'];
154     }
155   }
158   /* Check supplied data */
159   function check()
160   {
161     /* Call common method to give check the hook */
162     $message= plugin::check();
163     $message= array_merge($message, $this->netConfigDNS->check());
164     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
166     $ui= get_userinfo();
167     $acl= get_permissions ($this->dn, $ui->subtreeACL);
168     $acl= get_module_permission($acl, "component", $this->dn);
169     if (chkacl($acl, "create") != ""){
170       $message[]= _("You have no permissions to create a component on this 'Base'.");
171     }
173     if ($this->orig_dn != $this->dn){
174       $ldap= $this->config->get_ldap_link();
175       $ldap->cd ($this->base);
176       $ldap->search ("(cn=".$this->cn.")", array("cn"));
177       if ($ldap->count() != 0){
178         while ($attrs= $ldap->fetch()){
179           if ($attrs['dn'] != $this->orig_dn){
180             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
181             break;
182           }
183         }
184       }
185     }
187     return ($message);
188   }
191   /* Save to LDAP */
192   function save()
193   {
194     $this->netConfigDNS->acl = $this->acl;
195     plugin::save();
197     /* Remove all empty values */
198     if ($this->orig_dn == 'new'){
199       $attrs= array();
200       foreach ($this->attrs as $key => $val){
201         if (is_array($val) && count($val) == 0){
202           continue;
203         }
204         $attrs[$key]= $val;
205       }
206       $this->attrs= $attrs;
207     }
209     /* Write back to ldap */
210     $ldap= $this->config->get_ldap_link();
211     if ($this->orig_dn == 'new'){
212       $ldap->cd($this->config->current['BASE']);
213       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
214       $ldap->cd($this->dn);
215       $ldap->add($this->attrs);
216       $this->handle_post_events("add");
217     } else {
218       if ($this->orig_dn != $this->dn){
219         $this->move($this->orig_dn, $this->dn);
220       }
222       $ldap->cd($this->dn);
223       $this->cleanup();
224       $ldap->modify ($this->attrs); 
226       $this->handle_post_events("modify");
227     }
229     $this->netConfigDNS->cn = $this->cn;
230     $this->netConfigDNS->save($this->dn);
231     show_ldap_error($ldap->get_error(), _("Saving Samba workstation failed"));
233     /* Optionally execute a command after we're done */
234     $this->postcreate();
235   }
239 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
240 ?>