Code

added all alt="" tags to folder /plugins
[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 $macAddress= "";
17   var $ipHostNumber= "";
18   var $description= "";
19   var $orig_dn= "";
20   var $shadowLastChange="";
21   var $uidNumber="";
22   var $gidNumber="";
23   var $loginShell="";
24   var $gecos="";
25   var $shadowMin="";
26   var $shadowWarning="";
27   var $shadowInactive="";
28   var $uid="";
29   var $sn="";
30   var $givenName="";
31   var $homeDirectory="";
32   var $sambaSID="";
33   var $sambaPrimaryGroupSID="";
34   var $displayName="";
35   var $sambaPwdCanChange2="";
36   var $sambaPwdMustChange="";
37   var $sambaNTPassword="";
38   var $sambaPwdLastSet="";
39   var $sambaAcctFlags="";
40                                                                                                                   
48   /* attribute list for save action */
49   var $attributes   = array("cn", "description", "macAddress", "ipHostNumber","shadowLastChange",
50                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
51                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
52                             "sambaPrimaryGroupSID","displayName", "sambaPwdCanChange2","sambaPwdMustChange",
53                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
54   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top", "device", "ipHost", "ieee802Device");
57 // These are insertet !!!
58 //"posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount"
60 //$attrs2("shadowLastChange","uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning","shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID","sambaPrimaryGroupSID","displayName","sambaPwdCanChange2","sambaPwdMustChange","sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
63   function wingeneric ($config, $dn= NULL)
64   {
65     plugin::plugin ($config, $dn);
67     /* Set base */
68     if ($this->dn == "new"){
69       $ui= get_userinfo();
70       $this->base= dn2base($ui->dn);
71       $this->cn= "";
72     } else {
73       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
74     }
76     /* Save dn for later references */
77     $this->orig_dn= $this->dn;
78   }
80   function execute()
81   {
82     /* Do we represent a valid phone? */
83     if (!$this->is_account && $this->parent == NULL){
84       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
85         _("This 'dn' has no network features.")."</b>";
86       return($display);
87     }
89     /* Fill templating stuff */
90     $smarty= get_smarty();
91     $smarty->assign("bases", $this->config->idepartments);
93     /* Assign attributes */
94     foreach ($this->attributes as $attr){
95       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
96       $smarty->assign("$attr", $this->$attr);
97     }
98     
99     
100     $smarty->assign("base_select", $this->base);
102     /* Show main page */
103     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
104     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
105   }
107   function remove_from_parent()
108   {
109     $ldap= $this->config->get_ldap_link();
110     $ldap->rmdir($this->dn);
111     show_ldap_error($ldap->get_error());
112     $this->handle_post_events("remove");
114     /* Delete references to object groups */
115     $ldap->cd ($this->config->current['BASE']);
116     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
117     while ($ldap->fetch()){
118       $og= new ogroup($this->config, $ldap->getDN());
119       unset($og->member[$this->dn]);
120       $og->save ();
121     }
123   }
126   /* Save data to object */
127   function save_object()
128   {
129     plugin::save_object();
131     /* Save base, since this is no LDAP attribute */
132     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
133       $this->base= $_POST['base'];
134     }
135   }
138   /* Check supplied data */
139   function check()
140   {
141     $message= array();
142     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
144     /* must: cn, macAddress */
145     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
146       $message[]= "The required field 'Component name' is not set.";
147     }
148     if ($this->macAddress == "" && chkacl ($this->acl, "macAddresscn") == ""){
149       $message[]= "The required field 'MAC-address' is not set.";
150     }
152     $ui= get_userinfo();
153     $acl= get_permissions ($this->dn, $ui->subtreeACL);
154     $acl= get_module_permission($acl, "component", $this->dn);
155     if (chkacl($acl, "create") != ""){
156       $message[]= _("You have no permissions to create a component on this 'Base'.");
157     }
159     if ($this->orig_dn != $this->dn){
160       $ldap= $this->config->get_ldap_link();
161       $ldap->cd ($this->base);
162       $ldap->search ("(cn=".$this->cn.")", array("cn"));
163       if ($ldap->count() != 0){
164         while ($attrs= $ldap->fetch()){
165           if ($attrs['dn'] != $this->orig_dn){
166             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
167             break;
168           }
169         }
170       }
171     }
173     return ($message);
174   }
177   /* Save to LDAP */
178   function save()
179   {
180     plugin::save();
182     /* Remove all empty values */
183     if ($this->orig_dn == 'new'){
184       $attrs= array();
185       foreach ($this->attrs as $key => $val){
186         if (is_array($val) && count($val) == 0){
187           continue;
188         }
189         $attrs[$key]= $val;
190       }
191       $this->attrs= $attrs;
192     }
194     /* Write back to ldap */
195     $ldap= $this->config->get_ldap_link();
196     if ($this->orig_dn == 'new'){
197       $ldap->cd($this->config->current['BASE']);
198       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
199       $ldap->cd($this->dn);
200       $ldap->add($this->attrs);
201       $this->handle_post_events("add");
202     } else {
203       if ($this->orig_dn != $this->dn){
204         $this->move($this->orig_dn, $this->dn);
205       }
207       $ldap->cd($this->dn);
208       $ldap->modify($this->attrs);
209       $this->handle_post_events("modify");
210     }
211     show_ldap_error($ldap->get_error());
213     /* Optionally execute a command after we're done */
214     $this->postcreate();
215   }
219 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
220 ?>