Code

Add asterisk for required attributes in network.tpl
[gosa.git] / plugins / admin / systems / class_servDB.inc
1 <?php
3 class servdb extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server basic 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   /* Object information */
11   var $goImapName= "";
12   var $goImapConnect= "";
13   var $goImapAdmin= "";
14   var $goImapPassword= "";
15   var $goImapSieveServer= "";
16   var $goImapSievePort= "";
17   var $goKrbRealm= "";
18   var $goKrbAdmin= "";
19   var $goKrbPassword= "";
20   var $goFaxAdmin= "";
21   var $goFaxPassword= "";
22   var $goLogAdmin= "";
23   var $goLogPassword= "";
24   var $goFonAdmin= "";
25   var $goFonPassword= "";
26   var $goFonAreaCode= "";
27   var $goFonCountryCode= "";
28   var $ignore_account= TRUE;
30   /* attribute list for save action */
31   var $attributes= array("goImapName", "goImapConnect", "goImapAdmin", "goImapPassword",
32                          "goImapSieveServer", "goImapSievePort", "goKrbRealm", 
33                          "goKrbAdmin", "goKrbPassword", "goFaxAdmin", "goFaxPassword",
34                          "goLogAdmin", "goLogPassword", "goFonAdmin", "goFonPassword",
35                          "goFonAreaCode", "goFonCountryCode");
36   var $objectclasses= array("top", "goServer");
37   var $additionaloc= array("goImapServer" => array("goImapName", "goImapConnect",
38                                                 "goImapAdmin", "goImapPassword",
39                                                 "goImapSieveServer", 
40                                                 "goImapSievePort"),
41                           "goKrbServer" => array("goKrbRealm", "goKrbAdmin",
42                                                 "goKrbPassword"),
43                           "goFaxServer" => array("goFaxAdmin", "goFaxPassword"),
44                           "goLogDBServer" => array("goLogAdmin", "goLogPassword"),
45                           "goFonServer" => array("goFonAdmin", "goFonPassword",
46                                                 "goFonAreaCode", "goFonCountryCode"));
48   function servdb ($config, $dn= NULL)
49   {
50     plugin::plugin ($config, $dn);
52     /* Make dynamic list of objectClasses */
53     foreach ($this->additionaloc as $oc => $dummy){
54       if (isset($this->attrs['objectClass']) && in_array($oc, $this->attrs['objectClass'])){
55         $this->objectclasses[$oc]= $oc;
56       }
57     }
59     /* Always is account... */
60     $this->is_account= TRUE;
61   }
63   function execute()
64   {
65     /* Fill templating stuff */
66     $smarty= get_smarty();
68     /* Attributes... */
69     foreach ($this->attributes as $attr){
70       $smarty->assign("$attr", $this->$attr);
71       $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
72     }
74     /* Don't show Asterisk for non-required attribute ipHostNumber and macAddress */
75     $smarty->assign("staticAddress", "");
77     /* Classes... */
78     foreach ($this->additionaloc as $oc => $dummy){
79       if (isset($this->objectclasses[$oc])){
80         $smarty->assign("$oc", "checked");
81         $smarty->assign("$oc"."State", "");
82         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
83         
84       } else {
85         $smarty->assign("$oc", "");
86         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
87         $smarty->assign("$oc"."State", "disabled");
88       }
89     }
91     return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
92   }
94   function remove_from_parent()
95   {
96     /* This cannot be removed... */
97   }
100   /* Save data to object */
101   function save_object()
102   {
103     if (isset($_POST['dbtab'])){
104       plugin::save_object();
105       
106       /* Save checkbox state */
107       foreach ($this->additionaloc as $oc => $dummy){
108         if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
109           $this->objectclasses[$oc]= $oc;
110         } else {
111           unset($this->objectclasses[$oc]);
112         }
113       }
114     }
115   }
118   /* Check supplied data */
119   function check()
120   {
121     $message= array();
123     /* All fields are marked as *must* */
124     if (in_array("goImapServer", $this->objectclasses)){
125       foreach (array("goImapAdmin", "goImapName") as $attr){
126         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
127           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
128         }
129       }
131       /* Check connect string */
132       if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
133         $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
134                     '{server-name:port/options}');
135       }
136       if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
137         $message[]= _("The sieve port needs to be numeric.");
138       }
139     }
140     if (in_array("goKrbServer", $this->objectclasses)){
141       foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
142         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
143           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
144         }
145       }
146     }
147     if (in_array("goFaxServer", $this->objectclasses)){
148       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
149         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
150       }
151     }
152     if (in_array("goLogServer", $this->objectclasses)){
153       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
154         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
155       }
156     }
157     if (in_array("goFonServer", $this->objectclasses)){
158       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
159         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
160           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
161         }
162       }
163     }
165     return ($message);
166   }
169   /* Save to LDAP */
170   function save()
171   {
172     /* Normalize lazy objectclass arrays */
173     $objectclasses= array();
174     foreach($this->objectclasses as $oc){
175       $objectclasses[]= $oc;
176     }
177   
178     plugin::save();
179   
182     $test = $this->objectclasses;
183     $tmp = array_flip($this->attrs['objectClass']);
185     foreach($this->additionaloc as $key=>$val) {
186       unset($tmp[$key]);
187       }
189     $classes = (array_flip(array_merge(array_flip($test),$tmp)));
191     unset($this->attrs['objectClass']);
193     foreach($classes as $class){
194       $this->attrs['objectClass'][]=$class;
195     }
198     /* Remove unneeded attributes */
199     foreach ($this->additionaloc as $oc => $attrs){
200       if (!in_array($oc, $this->attrs['objectClass'])){
201         foreach ($attrs as $attr){
202           $this->attrs[$attr]= array();
203         }
204       }
205     }
206     $this->attrs = array_reverse($this->attrs);
210     /* Write to LDAP */
211     $ldap= $this->config->get_ldap_link();
212     $ldap->cd($this->dn);
213     $ldap->modify($this->attrs);
214     show_ldap_error($ldap->get_error());
216     /* Optionally execute a command after we're done */
217     if ($this->initially_was_account == $this->is_account){
218       if ($this->is_modified){
219         $this->handle_post_events("mofify");
220       }
221     } else {
222       $this->handle_post_events("add");
223     }
224   }
228 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
229 ?>