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 /* Show tab dialog headers */
50 $display= "";
52 /* Show main page */
53 $smarty= get_smarty();
55 /* Load attributes */
56 foreach($this->attributes as $val){
57 $smarty->assign("$val", $this->$val);
58 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
59 }
61 /* Check for invitation action */
62 $nr= 0;
63 while (isset($_POST["policy$nr"])){
64 if (isset($_POST["add$nr"])){
65 $this->kolabInvitationPolicy[]= ": ACT_MANUAL";
66 }
67 if (isset($_POST["remove$nr"])){
68 $new= array();
69 foreach ($this->kolabInvitationPolicy as $entry){
70 if (!preg_match("/^".$this->imapping[$nr].":/", $entry)){
71 $new[]= $entry;
72 }
73 }
74 $this->kolabInvitationPolicy= $new;
75 }
76 $nr++;
77 }
79 /* Unify addresses */
80 $new= array();
81 foreach($this->kolabInvitationPolicy as $value){
82 if (preg_match('/^:/', $value)){
83 continue;
84 }
85 $address= preg_replace('/^([^:]+:).*$/', '\1', $value);
86 $new[$address]= $value;
87 }
88 $this->kolabInvitationPolicy= array();
89 foreach($new as $value){
90 $this->kolabInvitationPolicy[]= $value;
91 }
93 /* Add delegation */
94 if (isset($_POST['add_delegation'])){
95 if ($_POST['delegate_address'] != ""){
97 /* Valid email address specified? */
98 $address= $_POST['delegate_address'];
99 $valid= FALSE;
100 if (!is_email($address)){
101 if (!is_email($address, TRUE)){
102 print_red (_("You're trying to add an invalid email address to the list of delegations."));
103 }
104 } else {
106 $ldap= $this->config->get_ldap_link();
107 $ldap->cd ($this->config->current['BASE']);
108 $ldap->search('(mail='.$address.')');
109 if ($ldap->count() == 0){
110 print_red (_("The mail address you're trying to add is no primary mail address of an existing user."));
111 } else {
112 $valid= TRUE;
113 }
114 }
116 if ($valid){
117 /* Add it */
118 if (chkacl ($this->acl, "kolabDelegate") == ""){
119 $this->addDelegate ($address);
120 $this->is_modified= TRUE;
121 }
123 }
124 }
125 }
127 /* Delete forward email addresses */
128 if (isset($_POST['delete_delegation'])){
129 if (count($_POST['delegate_list'])
130 && chkacl ($this->acl, "kolabDelegate") == ""){
132 $this->delDelegate ($_POST['delegate_list']);
133 }
134 }
136 /* Assemble policies */
137 $policies= array( 'ACT_ALWAYS_ACCEPT' => _("Always accept"),
138 'ACT_ALWAYS_REJECT' => _("Always reject"),
139 'ACT_REJECT_IF_CONFLICTS' => _("Reject if conflicts"),
140 'ACT_MANUAL_IF_CONFLICTS' => _("Manual if conflicts"),
141 'ACT_MANUAL' => _("Manual"));
142 $smarty->assign('policies', $policies);
144 /* Adjust checkbox */
145 if ($this->unrestrictedMailSize){
146 $smarty->assign('unrestrictedMailSizeState', "checked");
147 } else {
148 $smarty->assign('unrestrictedMailSizeState', "");
149 }
151 /* Transfer account states for this union */
152 if ($this->parent->by_object['mailAccount']->is_account){
153 $smarty->assign('is_account', 'true');
154 } else {
155 $smarty->assign('is_account', '');
156 }
158 /* Transfer delegation list */
159 $smarty->assign("kolabDelegate", $this->kolabDelegate);
161 /* Create InvitationPolicy table */
162 $invitation= "";
163 $this->imapping= array();
164 $nr= 0;
165 $acl= chkacl($this->acl, "kolabInvitationPolicy");
166 foreach ($this->kolabInvitationPolicy as $entry){
167 $invitation.= "<tr><td>";
169 /* The default entry does not have colons... */
170 if (!preg_match('/:/', $entry)){
171 $invitation.= _("Anonymous");
172 $name= "";
173 $mode= $entry;
174 } else {
175 $name= preg_replace('/:.*$/', '', $entry);
176 $mode= preg_replace('/^[^:]*: */', '', $entry);
177 $invitation.= "<input name=\"address$nr\" size=16 maxlength=60 $acl value=\"$name\">";
178 }
179 $invitation.= "</td>";
181 /* Add mode switch */
182 $invitation.= "<td><select size=\"1\" name=\"policy$nr\" $acl>";
183 foreach($policies as $key => $value){
184 if ($key == $mode){
185 $invitation.= "<option value=\"$key\" selected>$value</option>";
186 } else {
187 $invitation.= "<option value=\"$key\">$value</option>";
188 }
189 }
191 /* Assign buttons */
192 $button= "";
193 if ($nr == count($this->kolabInvitationPolicy)-1){
194 $button= "<input type=submit name=\"add$nr\" value=\""._("Add")."\">";
195 }
196 if ($nr != 0) {
197 $button.= "<input type=submit name=\"remove$nr\" value=\""._("Remove")."\">";
198 }
200 $invitation.= "</select> $button</td></tr>\n";
201 $this->imapping[$nr]= $name;
202 $nr++;
203 }
204 $smarty->assign("invitation", $invitation);
206 $display.= $smarty->fetch (get_template_path('kolab.tpl', TRUE, dirname(__FILE__)));
207 return ($display);
208 }
210 function remove_from_parent()
211 {
212 /* Optionally execute a command after we're done */
213 $this->handle_post_events('remove');
214 }
217 function check()
218 {
219 $message= array();
221 /* FBFuture is in days... */
222 if ($this->kolabFreeBusyFuture != "" && !preg_match('/^[0-9]+$/', $this->kolabFreeBusyFuture)){
223 $message[]= _("The value specified as Free Busy future needs to be an integer.");
224 }
226 /* Check for URL scheme... */
227 if ($this->calFBURL != "" && !preg_match('/^[^:/]+://[a-z0-9_/.+~-]+$/i', $this->calFBURL)){
228 $message[]= _("The value specified as Free Busy Information URL is invalid.");
229 }
231 /* Check invitation policy for existing mail addresses */
232 foreach($this->kolabInvitationPolicy as $policy){
234 /* Ignore anonymous string */
235 if (!preg_match('/:/', $policy)){
236 continue;
237 }
239 $address= preg_replace('/^([^:]+).*$/', '\1', $policy);
240 if (!is_email($address)){
241 if (!is_email($address, TRUE)){
242 $message[]= sprintf(_("The invitation policy entry for address '%s' is not valid."), $address);
243 }
244 } else {
246 $ldap= $this->config->get_ldap_link();
247 $ldap->cd ($this->config->current['BASE']);
248 $ldap->search('(mail='.$address.')');
249 if ($ldap->count() == 0){
250 $message[]= sprintf(_("There's no mail user with address '%s' for your invitation policy!"), $address);
251 } else {
252 $valid= TRUE;
253 }
254 }
255 }
257 return ($message);
258 }
260 /* Save data to object */
261 function save_object()
262 {
263 /* Do we need to flip is_account state? */
264 if (isset($_POST['connectivityTab'])){
265 if (chkacl('unrestrictedMailSize', $this->acl == "")){
266 if (isset($_POST['unrestrictedMailSize']) && $_POST['unrestrictedMailSize'] == 1){
267 $this->unrestrictedMailSize= 1;
268 } else {
269 $this->unrestrictedMailSize= 0;
270 }
271 }
272 }
274 plugin::save_object();
276 /* Save changes done in invitation policies */
277 $nr= 0;
278 $this->kolabInvitationPolicy= array();
279 while (isset($_POST["policy$nr"])){
281 /* Anonymous? */
282 if (!isset($_POST["address$nr"])){
283 $this->kolabInvitationPolicy[]= $_POST["policy$nr"];
284 } else {
285 $this->kolabInvitationPolicy[]= $_POST["address$nr"].": ".$_POST["policy$nr"];
286 }
288 $nr++;
289 }
291 }
294 /* Save to LDAP */
295 function save()
296 {
297 plugin::save();
299 /* Transfer arrays */
300 $this->attrs['kolabDelegate']= $this->kolabDelegate;
301 $this->attrs['kolabInvitationPolicy']= $this->kolabInvitationPolicy;
303 /* Write back to ldap */
304 $ldap= $this->config->get_ldap_link();
305 $ldap->cd($this->dn);
306 $ldap->modify($this->attrs);
307 show_ldap_error($ldap->get_error());
309 /* Optionally execute a command after we're done */
310 if ($this->initially_was_account == $this->is_account){
311 if ($this->is_modified){
312 $this->handle_post_events("mofify");
313 }
314 } else {
315 $this->handle_post_events("add");
316 }
317 }
320 /* Add entry to delegation list */
321 function addDelegate($address)
322 {
323 $this->kolabDelegate[]= $address;
324 $this->kolabDelegate= array_unique ($this->kolabDelegate);
326 sort ($this->kolabDelegate);
327 reset ($this->kolabDelegate);
328 $this->is_modified= TRUE;
329 }
331 function delDelegate($addresses)
332 {
333 $this->kolabDelegate= array_remove_entries ($addresses, $this->kolabDelegate);
334 $this->is_modified= TRUE;
335 }
337 }
339 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
340 ?>