Code

Added some fixes for iframe scrolling
[gosa.git] / plugins / admin / systems / class_componentGeneric.inc
1 <?php
3 class componentGeneric 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();
12   var $ignore_account= TRUE;
14   /* Needed values and lists */
15   var $base= "";
16   var $cn= "";
17   var $description= "";
18   var $orig_dn= "";
20   /* attribute list for save action */
21   var $attributes= array("cn", "description");
22   var $objectclasses= array("top", "device", "ipHost", "ieee802Device");
23   var $netConfigDNS;
25   function componentgeneric ($config, $dn= NULL, $parent= NULL)
26   {
27     plugin::plugin ($config, $dn, $parent);
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     }
37     $this->netConfigDNS = new termDNS($this->config,$this->dn,$this->objectclasses, true);
38     /* Save dn for later references */
39     $this->orig_dn= $this->dn;
40   }
42   function execute()
43   {
44         /* Call parent execute */
45         plugin::execute();
47     /* Do we represent a valid phone? */
48     if (!$this->is_account && $this->parent == NULL){
49       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
50         _("This 'dn' has no network features.")."</b>";
51       return($display);
52     }
54     /* Base select dialog */
55     $once = true;
56     foreach($_POST as $name => $value){
57       if(preg_match("/^chooseBase/",$name) && $once){
58         $once = false;
59         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
60         $this->dialog->setCurrentBase($this->base);
61       }
62     }
64     /* Dialog handling */
65     if(is_object($this->dialog)){
66       /* Must be called before save_object */
67       $this->dialog->save_object();
69       if($this->dialog->isClosed()){
70         $this->dialog = false;
71       }elseif($this->dialog->isSelected()){
73         /* A new base was selected, check if it is a valid one */
74         $tmp = $this->get_allowed_bases();
75         if(isset($tmp[$this->dialog->isSelected()])){
76           $this->base = $this->dialog->isSelected();
77         }
79         $this->dialog= false;
80       }else{
81         return($this->dialog->execute());
82       }
83     }
85     /* Fill templating stuff */
86     $smarty= get_smarty();
87     $smarty->assign("bases", $this->config->idepartments);
89     /* Set acls */
90     $tmp = $this->plInfo();
91     foreach($tmp['plProvidedAcls'] as $name => $translation){
92       $smarty->assign($name."ACL",$this->getacl($name));
93     }
95     $smarty->assign("bases", $this->get_allowed_bases());
97     /* Assign attributes */
98     foreach ($this->attributes as $attr){
99       $smarty->assign("$attr", $this->$attr);
100     }
101     $smarty->assign("base_select", $this->base);
103     /* Show main page */
104     $smarty->assign("netconfig", $this->netConfigDNS->execute());
105     return($smarty->fetch (get_template_path('component.tpl', TRUE)));
106   }
108   function set_acl_base($base)
109   {
110     plugin::set_acl_base($base);
111     $this->netConfigDNS->set_acl_base($base);
112   }
114   function set_acl_category($cat)
115   {
116     plugin::set_acl_category($cat);
117     $this->netConfigDNS->set_acl_category($cat);
118   }
120   function remove_from_parent()
121   {
122     $ldap= $this->config->get_ldap_link();
123     $this->netConfigDNS->remove_from_parent();
124     $ldap->rmdir($this->dn);
125     show_ldap_error($ldap->get_error(), sprintf(_("Removing of system component/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     
143     /* Create a base backup and reset the
144        base directly after calling plugin::save_object();
145        Base will be set seperatly a few lines below */
146     $base_tmp = $this->base;
147     plugin::save_object();
148     $this->base = $base_tmp;
150     $this->netConfigDNS->save_object();
152     /* Set new base if allowed */
153     $tmp = $this->get_allowed_bases();
154     if(isset($_POST['base'])){
155       if(isset($tmp[$_POST['base']])){
156         $this->base= $_POST['base'];
157       }
158     }
159   }
162   /* Check supplied data */
163   function check()
164   {
165     /* Call common method to give check the hook */
166     $message= plugin::check();
167     $message= array_merge($message,$this->netConfigDNS->check());
169     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
171     if ($this->cn == "" ){
172       $message[]= _("The required field 'Component name' is not set.");
173     }
175     /* To check for valid ip*/
176     if($this->netConfigDNS->ipHostNumber == ""){
177        $message[]= _("The required field IP address is empty.");
178     } else {
179       if (!is_ip($this->netConfigDNS->ipHostNumber)){
180         $message[]= _("The field IP address contains an invalid address.");
181       }
182     }
184     if ($this->orig_dn != $this->dn){
185       $ldap= $this->config->get_ldap_link();
186       $ldap->cd ($this->base);
187       $ldap->search ("(cn=".$this->cn.")", array("cn"));
188       if ($ldap->count() != 0){
189         while ($attrs= $ldap->fetch()){
190           if ($attrs['dn'] != $this->orig_dn){
191             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
192             break;
193           }
194         }
195       }
196     }
198     return ($message);
199   }
202   /* Save to LDAP */
203   function save()
204   {
205     plugin::save();
207     /* Remove all empty values */
208     if ($this->orig_dn == 'new'){
209       $attrs= array();
210       foreach ($this->attrs as $key => $val){
211         if (is_array($val) && count($val) == 0){
212           continue;
213         }
214         $attrs[$key]= $val;
215       }
216       $this->attrs= $attrs;
217     }
219     /* If this is a new Object IP & Mac aren't set.
220          IP & Mac are msut attributes, so we set this values by here. */
221     if($this->orig_dn == 'new'){
222       $this->attrs['ipHostNumber'] = $this->netConfigDNS->ipHostNumber;
223       $this->attrs['macAddress']  = $this->netConfigDNS->macAddress;
224     }
226     /* Write back to ldap */
227     $ldap= $this->config->get_ldap_link();
228     if ($this->orig_dn == 'new'){
229       $ldap->cd($this->config->current['BASE']);
230       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
231       $ldap->cd($this->dn);
232       $ldap->add($this->attrs);
233       $this->handle_post_events("add");
234     } else {
235       if ($this->orig_dn != $this->dn){
236         $this->move($this->orig_dn, $this->dn);
237       }
239       $ldap->cd($this->dn);
240       $this->cleanup();
241       $ldap->modify ($this->attrs); 
243       $this->handle_post_events("modify");
244     }
246     $this->netConfigDNS->cn = $this->cn;
247     $this->netConfigDNS->save($this->dn);
249     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system component/generic with dn '%s' failed."),$this->dn));
251     /* Optionally execute a command after we're done */
252     $this->postcreate();
253   }
255   /* Return plugin informations for acl handling */
256   function plInfo()
257   {
258     return (array(
259           "plShortName"   => _("Generic"),
260           "plDescription" => _("Component generic"),
261           "plSelfModify"  => FALSE,
262           "plDepends"     => array(),
263           "plPriority"    => 1,
264           "plSection"     => array("administration"),
265           "plCategory"    => array("component" => array("description"  => _("Network device"),
266                                                         "objectClass"  => array("device", "ipHost", "ieee802Device"))),
267           "plProvidedAcls"=> array(
268             "cn"                  => _("Name"),
269             "base"                => _("Base"),
270             "description"         => _("Description"))
271           ));
272   }
277 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
278 ?>