Code

remove old templates
[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     /* Set base */
53     if ($this->dn == "new"){
54       $ui= get_userinfo();
55       $this->base= dn2base($ui->dn);
56       $this->cn= "";
57     } else {
58       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
59     }
61     /* Save dn for later references */
62     $this->orig_dn= $this->dn;
63   }
65   function execute()
66   {
67         /* Call parent execute */
68         plugin::execute();
70     /* Do we represent a valid phone? */
71     if (!$this->is_account && $this->parent == NULL){
72       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
73         _("This 'dn' has no network features.")."</b>";
74       return($display);
75     }
77     /* Base select dialog */
78     $once = true;
79     foreach($_POST as $name => $value){
80       if(preg_match("/^chooseBase/",$name) && $once){
81         $once = false;
82         $this->dialog = new baseSelectDialog($this->config,$this);
83         $this->dialog->setCurrentBase($this->base);
84       }
85     }
87     /* Dialog handling */
88     if(is_object($this->dialog)){
89       /* Must be called before save_object */
90       $this->dialog->save_object();
92       if($this->dialog->isClosed()){
93         $this->dialog = false;
94       }elseif($this->dialog->isSelected()){
95         $this->base = $this->dialog->isSelected();
96         $this->dialog= false;
97       }else{
98         return($this->dialog->execute());
99       }
100     }
102     /* Fill templating stuff */
103     $smarty= get_smarty();
105     // Undefined index in wingeneric.tpl ... 
106     $smarty->assign("bases", $this->config->idepartments);
108     /* Assign attributes */
109     foreach ($this->attributes as $attr){
110       $smarty->assign("$attr", $this->$attr);
111     }
112     
113     $smarty->assign("base_select", $this->base);
115     /* Show main page */
116     $smarty->assign("netconfig", $this->netConfigDNS->execute());
117     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
118   }
120   function remove_from_parent()
121   {
122     $this->netConfigDNS->remove_from_parent();
123     $ldap= $this->config->get_ldap_link();
124     $ldap->rmdir($this->dn);
125     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system wingeneric/generic with dn '%s' failed."),$this->dn));
126     $this->handle_post_events("remove");
128     /* Delete references to object groups */
129     $ldap->cd ($this->config->current['BASE']);
130     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
131     while ($ldap->fetch()){
132       $og= new ogroup($this->config, $ldap->getDN());
133       unset($og->member[$this->dn]);
134       $og->save ();
135     }
136   }
139   /* Save data to object */
140   function save_object()
141   {
142     plugin::save_object();
143     $this->netConfigDNS->save_object();
144     /* Save base, since this is no LDAP attribute */
145     if (isset($_POST['base']) && $this->acl_is_moveable(){
146       $this->base= $_POST['base'];
147     }
148   }
151   /* Check supplied data */
152   function check()
153   {
154     /* Call common method to give check the hook */
155     $message= plugin::check();
156     $message= array_merge($message, $this->netConfigDNS->check());
157     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
159     $ui= get_userinfo();
160     $acl= get_permissions ($this->dn, $ui->subtreeACL);
161     $acl= get_module_permission($acl, "component", $this->dn);
162     if(!$this->acl_is_createable() && $this->dn == "new"){
163       $message[]= _("You have no permissions to create a component on this 'Base'.");
164     }
166     if ($this->orig_dn != $this->dn){
167       $ldap= $this->config->get_ldap_link();
168       $ldap->cd ($this->base);
169       $ldap->search ("(cn=".$this->cn.")", array("cn"));
170       if ($ldap->count() != 0){
171         while ($attrs= $ldap->fetch()){
172           if ($attrs['dn'] != $this->orig_dn){
173             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
174             break;
175           }
176         }
177       }
178     }
180     return ($message);
181   }
184   /* Save to LDAP */
185   function save()
186   {
187     plugin::save();
189     /* Remove all empty values */
190     if ($this->orig_dn == 'new'){
191       $attrs= array();
192       foreach ($this->attrs as $key => $val){
193         if (is_array($val) && count($val) == 0){
194           continue;
195         }
196         $attrs[$key]= $val;
197       }
198       $this->attrs= $attrs;
199     }
201     /* Write back to ldap */
202     $ldap= $this->config->get_ldap_link();
203     if ($this->orig_dn == 'new'){
204       $ldap->cd($this->config->current['BASE']);
205       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
206       $ldap->cd($this->dn);
207       $ldap->add($this->attrs);
208       $this->handle_post_events("add");
209     } else {
210       if ($this->orig_dn != $this->dn){
211         $this->move($this->orig_dn, $this->dn);
212       }
214       $ldap->cd($this->dn);
215       $this->cleanup();
216       $ldap->modify ($this->attrs); 
218       $this->handle_post_events("modify");
219     }
221     $this->netConfigDNS->cn = $this->cn;
222     $this->netConfigDNS->save($this->dn);
223     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system wingeneric/generic with dn '%s' failed."),$this->dn));
225     /* Optionally execute a command after we're done */
226     $this->postcreate();
227   }
229   /* Return plugin informations for acl handling
230   #FIXME FAIscript seams to ununsed within this class... */
231   function plInfo()
232   {
233     return (array(
234           "plShortName"   => _("Win generic"),
235           "plDescription" => _("Windows workstation generic"),
236           "plSelfModify"  => FALSE,
237           "plDepends"     => array(),
238           "plPriority"    => 0,
239           "plSection"     => array("administration"),
240           "plCategory"    => array("winworkstation" => array("description"  => _("Win workstation"),
241                                                           "objectClass"  => "gotoWorkstation")),
242           "plProvidedAcls"=> array(
243             "cn"                  => _("Workstation name"),
244             "description"         => _("Description"))
245           ));
246   }
251 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
252 ?>