Code

Added empty lines
[gosa.git] / plugins / personal / connectivity / class_kolabAccount.inc
1 <?php
2 class kolabAccount extends plugin
3 {
4   /* Definitions */
5   var $plHeadline= "Kolab";
6   var $plDescription= "This does something";
8   /* CLI vars */
9   var $cli_summary= "Manage users Kolab account";
10   var $cli_description= "Some longer text\nfor help";
11   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
13   /* Kolab attributes */
14   var $kolabInvitationPolicy= array();
15   var $kolabFreeBusyFuture= 60;
16   var $unrestrictedMailSize= 0;
17   var $calFBURL= "";
18   var $kolabDelegate= array();
20   /* attribute list for save action */
21   var $attributes= array( "kolabFreeBusyFuture", "unrestrictedMailSize", "calFBURL");
22   var $objectclasses= array();
24   /* Helper */
25   var $imapping= array();
27   function kolabAccount ($config, $dn= NULL)
28   {
29     plugin::plugin ($config, $dn);
31     /* Pull arrays */
32     foreach(array("kolabDelegate", "kolabInvitationPolicy") as $attr){
33       if (isset($this->attrs["$attr"]["count"])){
34         for ($i= 0; $i<$this->attrs["$attr"]["count"]; $i++){
35           array_push($this->$attr, $this->attrs["$attr"][$i]);
36         }
37       }
38     }
40     /* If this one is empty, preset with ACT_MANUAL for anonymous users */
41     if (count ($this->kolabInvitationPolicy) == 0){
42        $this->kolabInvitationPolicy= array("ACT_MANUAL");
43     }
45   }
47   function execute()
48   {
49         /* Call parent execute */
50         plugin::execute();
52     /* Show tab dialog headers */
53     $display= "";
55     /* Show main page */
56     $smarty= get_smarty();
58     /* Load attributes */
59     foreach($this->attributes as $val){
60       $smarty->assign("$val", $this->$val);
61       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
62     }
64     /* Check for invitation action */
65     $nr= 0;
66     while (isset($_POST["policy$nr"])){
67       if (isset($_POST["add$nr"])){
68         $this->kolabInvitationPolicy[]= ": ACT_MANUAL";
69       }
70       if (isset($_POST["remove$nr"])){
71         $new= array();
72         foreach ($this->kolabInvitationPolicy as $entry){
73           if (!preg_match("/^".$this->imapping[$nr].":/", $entry)){
74             $new[]= $entry;
75           }
76         }
77         $this->kolabInvitationPolicy= $new;
78       }
79       $nr++;
80     }
82     /* Unify addresses */
83     $new= array();
84     foreach($this->kolabInvitationPolicy as $value){
85       if (preg_match('/^:/', $value)){
86         continue;
87       }
88       $address= preg_replace('/^([^:]+:).*$/', '\1', $value);
89       $new[$address]= $value;
90     }
91     $this->kolabInvitationPolicy= array();
92     foreach($new as $value){
93       $this->kolabInvitationPolicy[]= $value;
94     }
96     /* Add delegation */
97     if (isset($_POST['add_delegation'])){
98       if ($_POST['delegate_address'] != ""){
100         /* Valid email address specified? */
101         $address= $_POST['delegate_address'];
102         $valid= FALSE;
103         if (!is_email($address)){
104           if (!is_email($address, TRUE)){
105               print_red (_("You're trying to add an invalid email address to the list of delegations."));
106           }
107         } else {
109           $ldap= $this->config->get_ldap_link();
110           $ldap->cd ($this->config->current['BASE']);
111           $ldap->search('(mail='.$address.')');
112           if ($ldap->count() == 0){
113             print_red (_("The mail address you're trying to add is no primary mail address of an existing user."));
114           } else {
115             $valid= TRUE;
116           }
117         }
119         if ($valid){
120           /* Add it */
121           if (chkacl ($this->acl, "kolabDelegate") == ""){
122             $this->addDelegate ($address);
123             $this->is_modified= TRUE;
124           }
126         }
127       }
128     }
130     /* Delete forward email addresses */
131     if (isset($_POST['delete_delegation'])){
132       if (count($_POST['delegate_list'])
133           && chkacl ($this->acl, "kolabDelegate") == ""){
135         $this->delDelegate ($_POST['delegate_list']);
136       }
137     }
139     /* Assemble policies */
140     $policies= array( 'ACT_ALWAYS_ACCEPT'       => _("Always accept"),
141                       'ACT_ALWAYS_REJECT'       => _("Always reject"),
142                       'ACT_REJECT_IF_CONFLICTS' => _("Reject if conflicts"),
143                       'ACT_MANUAL_IF_CONFLICTS' => _("Manual if conflicts"),
144                       'ACT_MANUAL'              => _("Manual"));
145     $smarty->assign('policies', $policies);
147     /* Adjust checkbox */
148     if ($this->unrestrictedMailSize){
149       $smarty->assign('unrestrictedMailSizeState', "checked");
150     } else {
151       $smarty->assign('unrestrictedMailSizeState', "");
152     }
154     /* Transfer account states for this union */
155     if (isset($this->parent) && $this->parent->by_object['mailAccount']->is_account){
156       $smarty->assign('is_account', 'true');
157     } else {
158       $smarty->assign('is_account', '');
159     }
161     /* Transfer delegation list */
162     if (!count($this->kolabDelegate)){
163       /* Smarty will produce <option value=""></option> and tidy don't like that, so tell smarty to create no option (array();)*/
164       $smarty->assign("kolabDelegate", array());
165     } else {
166       $smarty->assign("kolabDelegate", $this->kolabDelegate);
167     }
168     $smarty->assign("kolabDelegateACL", chkacl($this->acl, $this->kolabDelegate));
170     /* Create InvitationPolicy table */
171     $invitation= "";
172     $this->imapping= array();
173     $nr= 0;
174     $acl= chkacl($this->acl, "kolabInvitationPolicy");
175     foreach ($this->kolabInvitationPolicy as $entry){
176       $invitation.= "<tr><td>";
178       /* The default entry does not have colons... */
179       if (!preg_match('/:/', $entry)){
180         $invitation.= _("Anonymous");
181         $name= "";
182         $mode= $entry;
183       } else {
184         $name= preg_replace('/:.*$/', '', $entry);
185         $mode= preg_replace('/^[^:]*: */', '', $entry);
186         $invitation.= "<input name=\"address$nr\" size=16 maxlength=60 $acl value=\"$name\">";
187       }
188       $invitation.= "</td>";
190       /* Add mode switch */
191       $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl>";
192       foreach($policies as $key => $value){
193         if ($key == $mode){
194           $invitation.= "<option value=\"$key\" selected>$value</option>";
195         } else {
196           $invitation.= "<option value=\"$key\">$value</option>";
197         }
198       }
199       
200       /* Assign buttons */
201       $button= "";
202       if ($nr == count($this->kolabInvitationPolicy)-1){
203         $button= "<input type=submit name=\"add$nr\" value=\""._("Add")."\">";
204       }
205       if ($nr != 0) {
206         $button.= "<input type=submit name=\"remove$nr\" value=\""._("Remove")."\">";
207       }
208       
209       $invitation.= "</select>&nbsp;$button</td></tr>\n";
210       $this->imapping[$nr]= $name;
211       $nr++;
212     }
213     $smarty->assign("invitation", $invitation);
215     $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
216     return ($display);
217   }
219   function remove_from_parent()
220   {
221     /* Optionally execute a command after we're done */
222     $this->handle_post_events('remove');
223   }
226   function check()
227   {
228     $message= array();
230     /* FBFuture is in days... */
231     if ($this->kolabFreeBusyFuture != "" && !preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
232       $message[]= _("The value specified as Free Busy future needs to be an integer.");
233     }
235     /* Check for URL scheme... */
236     if ($this->calFBURL != "" && !preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
237       $message[]= _("The value specified as Free Busy Information URL is invalid.");
238     }
240     /* Check invitation policy for existing mail addresses */
241     foreach($this->kolabInvitationPolicy as $policy){
242       
243       /* Ignore anonymous string */
244       if (!preg_match('/:/', $policy)){
245         continue;
246       }
247       
248       $address= preg_replace('/^([^:]+).*$/', '\1', $policy);
249       if (!is_email($address)){
250         if (!is_email($address, TRUE)){
251           $message[]= sprintf(_("The invitation policy entry for address '%s' is not valid."), $address);
252         }
253       } else {
255         $ldap= $this->config->get_ldap_link();
256         $ldap->cd ($this->config->current['BASE']);
257         $ldap->search('(mail='.$address.')');
258         if ($ldap->count() == 0){
259           $message[]= sprintf(_("There's no mail user with address '%s' for your invitation policy!"), $address);
260         } else {
261           $valid= TRUE;
262         }
263       }
264     }
266     return ($message);
267   }
269   /* Save data to object */
270   function save_object()
271   {
272     /* Do we need to flip is_account state? */
273     if (isset($_POST['connectivityTab'])){
274       if (chkacl('unrestrictedMailSize', $this->acl == "")){
275         if (isset($_POST['unrestrictedMailSize']) && $_POST['unrestrictedMailSize'] == 1){
276           $this->unrestrictedMailSize= 1;
277         } else {
278           $this->unrestrictedMailSize= 0;
279         }
280       }
281     }
283     plugin::save_object();
285     /* Save changes done in invitation policies */
286     $nr= 0;
287     $this->kolabInvitationPolicy= array();
288     while (isset($_POST["policy$nr"])){
290       /* Anonymous? */
291       if (!isset($_POST["address$nr"])){
292         $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
293       } else {
294         $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
295       }
296       
297       $nr++;
298     }
299     
300     /* If this one is empty, preset with ACT_MANUAL for anonymous users */
301     if (count ($this->kolabInvitationPolicy) == 0){
302       $this->kolabInvitationPolicy= array("ACT_MANUAL");
303     }
305   }
308   /* Save to LDAP */
309   function save()
310   {
311     /* Check mailmethod before doing something useful */
312     plugin::save();
314     /* Transfer arrays */
315     $this->attrs['kolabDelegate']= $this->kolabDelegate;
316     $this->attrs['kolabInvitationPolicy']= $this->kolabInvitationPolicy;
318     /* Write back to ldap */
319     $ldap= $this->config->get_ldap_link();
320     $ldap->cd($this->dn);
321     $ldap->modify($this->attrs);
322     show_ldap_error($ldap->get_error());
324     /* Optionally execute a command after we're done */
325     if ($this->initially_was_account == $this->is_account){
326       if ($this->is_modified){
327         $this->handle_post_events("mofify");
328       }
329     } else {
330       $this->handle_post_events("add");
331     }
332   }
335   /* Add entry to delegation list */
336   function addDelegate($address)
337   {
338     $this->kolabDelegate[]= $address;
339     $this->kolabDelegate= array_unique ($this->kolabDelegate);
341     sort ($this->kolabDelegate);
342     reset ($this->kolabDelegate);
343     $this->is_modified= TRUE;
344   }
346   function delDelegate($addresses)
347   {
348     $this->kolabDelegate= array_remove_entries ($addresses, $this->kolabDelegate);
349     $this->is_modified= TRUE;
350   }
354 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
355 ?>