Code

Fixed problems in kolab/server tabs
[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     /* Classes... */
75     foreach ($this->additionaloc as $oc => $dummy){
76       if (isset($this->objectclasses[$oc])){
77         $smarty->assign("$oc", "checked");
78         $smarty->assign("$oc"."State", "");
79         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
80         
81       } else {
82         $smarty->assign("$oc", "");
83         $smarty->assign("$oc"."ACL", chkacl($this->acl, $oc));
84         $smarty->assign("$oc"."State", "disabled");
85       }
86     }
88     return($smarty->fetch (get_template_path('servdb.tpl', TRUE)));
89   }
91   function remove_from_parent()
92   {
93     /* This cannot be removed... */
94   }
97   /* Save data to object */
98   function save_object()
99   {
100     if (isset($_POST['dbtab'])){
101       plugin::save_object();
102       
103       /* Save checkbox state */
104       foreach ($this->additionaloc as $oc => $dummy){
105         if (isset($_POST[$oc]) && $_POST[$oc] == '1'){
106           $this->objectclasses[$oc]= $oc;
107         } else {
108           unset($this->objectclasses[$oc]);
109         }
110       }
111     }
112   }
115   /* Check supplied data */
116   function check()
117   {
118     $message= array();
120     /* All fields are marked as *must* */
121     if (in_array("goImapServer", $this->objectclasses)){
122       foreach (array("goImapAdmin", "goImapName") as $attr){
123         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
124           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
125         }
126       }
128       /* Check connect string */
129       if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
130         $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
131                     '{server-name:port/options}');
132       }
133       if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
134         $message[]= _("The sieve port needs to be numeric.");
135       }
136     }
137     if (in_array("goKrbServer", $this->objectclasses)){
138       foreach (array("goKrbAdmin", "goKrbRealm") as $attr){
139         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
140           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
141         }
142       }
143     }
144     if (in_array("goFaxServer", $this->objectclasses)){
145       if ($this->goFaxAdmin == "" || preg_match("/ /", $this->goFaxAdmin)){
146         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goFaxAdmin");
147       }
148     }
149     if (in_array("goLogServer", $this->objectclasses)){
150       if ($this->goLogAdmin == "" || preg_match("/ /", $this->goLogAdmin)){
151         $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), "goLogAdmin");
152       }
153     }
154     if (in_array("goFonServer", $this->objectclasses)){
155       foreach (array("goFonAdmin", "goFonAreaCode", "goFonCountryCode") as $attr){
156         if ($this->$attr == "" || preg_match("/ /", $this->$attr)){
157           $message[]= sprintf(_("The attribute '%s' is empty or contains invalid characters."), $attr);
158         }
159       }
160     }
162     return ($message);
163   }
166   /* Save to LDAP */
167   function save()
168   {
169     /* Normalize lazy objectclass arrays */
170     $objectclasses= array();
171     foreach($this->objectclasses as $oc){
172       $objectclasses[]= $oc;
173     }
174   
175     plugin::save();
176   
179     $test = $this->objectclasses;
180     $tmp = array_flip($this->attrs['objectClass']);
182     foreach($this->additionaloc as $key=>$val) {
183       unset($tmp[$key]);
184       }
186     $classes = (array_flip(array_merge(array_flip($test),$tmp)));
188     unset($this->attrs['objectClass']);
190     foreach($classes as $class){
191       $this->attrs['objectClass'][]=$class;
192     }
195     /* Remove unneeded attributes */
196     foreach ($this->additionaloc as $oc => $attrs){
197       if (!in_array($oc, $this->attrs['objectClass'])){
198         foreach ($attrs as $attr){
199           $this->attrs[$attr]= array();
200         }
201       }
202     }
203     $this->attrs = array_reverse($this->attrs);
207     /* Write to LDAP */
208     $ldap= $this->config->get_ldap_link();
209     $ldap->cd($this->dn);
210     $ldap->modify($this->attrs);
211     show_ldap_error($ldap->get_error());
213     /* Optionally execute a command after we're done */
214     if ($this->initially_was_account == $this->is_account){
215       if ($this->is_modified){
216         $this->handle_post_events("mofify");
217       }
218     } else {
219       $this->handle_post_events("add");
220     }
221   }
225 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
226 ?>