1 <?php
3 class mailgroup extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage mail groups/shared folders";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 var $method= "mailMethod";
11 /* plugin specific values */
12 var $mail= "";
13 var $uid= "";
14 var $cn= "";
15 var $gosaMailAlternateAddress= array();
16 var $gosaMailForwardingAddress= array();
17 var $gosaMailDeliveryMode= "[L ]";
18 var $gosaMailServer= "";
19 var $gosaMailQuota= "";
20 var $gosaMailMaxSize= "";
21 var $gosaVacationMessage= "";
22 var $gosaSpamSortLevel= "";
23 var $gosaSpamMailbox= "";
24 var $gosaSharedFolderTarget;
25 var $quotaUsage= 0;
26 var $forward_dialog= FALSE;
27 var $members= array();
28 var $mailusers= array();
29 var $perms= array();
30 var $imapacl= array('anyone' => 'p', '%members%' => 'lrsp', '' => 'p');
31 var $mmethod= "";
33 /* Helper */
34 var $indexed_acl= array();
35 var $indexed_user= array();
37 /* attribute list for save action */
38 var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailAlternateAddress","gosaMailForwardingAddress",
39 "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","acl","gosaSharedFolderTarget",
40 "gosaVacationMessage");
41 var $objectclasses= array("gosaMailAccount");
44 /* constructor, if 'dn' is set, the node loads the given
45 'dn' from LDAP */
46 function mailgroup ($config, $dn= NULL, $ui= NULL)
47 {
48 /* Configuration is fine, allways */
49 $this->config= $config;
51 /* Load bases attributes */
52 plugin::plugin($config, $dn);
54 /* Set mailMethod to the one defined in gosa.conf */
55 if (isset($this->config->current['MAILMETHOD'])){
56 $this->mmethod= $this->config->current['MAILMETHOD'];
57 }
59 if (class_exists("mailMethod$this->mmethod")){
60 $this->method= "mailMethod$this->mmethod";
61 } else {
62 print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
63 }
65 /* Load Mailserver string, only in case of kolab ???? */
66 if(preg_match("/kolab/i",$this->mmethod)){
67 if(isset($this->attrs['gosaMailServer'][0])){
68 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
69 }
70 }
72 /* Convert cn to uid in case of existing entries */
73 if (isset($this->attrs['cn'][0])){
74 $this->uid= $this->attrs['cn'][0];
75 }
77 if ($dn != NULL){
79 /* Load attributes containing arrays */
80 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
81 $this->$val = array();
82 if (isset($this->attrs["$val"]["count"])){
83 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
84 array_push($this->$val, $this->attrs["$val"][$i]);
85 }
86 }
87 }
89 /* Only do IMAP actions if gosaMailServer attribute is set */
90 if (isset ($this->attrs["gosaMailServer"][0])){
91 $method= new $this->method($this->config);
92 if ($method->connect($this->attrs["gosaMailServer"][0])){
93 $quota= $method->getQuota($this->uid);
95 /* Maybe the entry is not saved in new style, get
96 permissions from IMAP and convert them to acl attributes */
97 if (!isset($this->attrs['acl'])){
98 $this->imapacl= $method->getSharedFolderPermissions($this->uid);
100 /* Need to filter what a member acl could be... */
101 $vote= array();
102 $peak= 0;
103 $leader= "";
104 foreach ($this->imapacl as $user => $acl){
106 if ($user != "anyone" ){
107 if (!isset($vote[$acl])){
108 $vote[$acl]= 1;
109 } else {
110 $vote[$acl]++;
111 }
112 if ($vote[$acl] > $peak){
113 $leader= $acl;
114 $peek= $vote[$acl];
115 }
116 }
118 }
120 /* Highest count wins as %members%, remove all members
121 with the same acl */
122 $this->imapacl['%members%']= $leader;
123 foreach ($this->imapacl as $user => $acl){
124 if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
125 unset($this->imapacl[$user]);
126 }
127 }
129 }
131 /* Update quota values */
132 if ($quota['gosaMailQuota'] == 2147483647){
133 $this->quotaUsage= "";
134 $this->gosaMailQuota= "";
135 } else {
136 $this->quotaUsage= $quota['quotaUsage'];
137 $this->gosaMailQuota= $quota['gosaMailQuota'];
138 }
139 $method->disconnect();
140 }
142 /* Adapt attributes if needed */
143 $method->fixAttributesOnLoad($this);
144 }
145 }
147 /* Get global filter config */
148 if (!is_global("gmailfilter")){
149 $ui= get_userinfo();
150 $base= get_base_from_people($ui->dn);
151 $gmailfilter= array( "depselect" => $base,
152 "muser" => "",
153 "regex" => "*");
154 register_global("gmailfilter", $gmailfilter);
155 }
157 /* Load permissions */
158 $tmp = array();
159 if(preg_match("/kolab/i",$this->mmethod)){
160 $ldap = $this->config->get_ldap_link();
161 if (isset($this->attrs['acl'])){
162 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
163 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
165 /* Add to list */
166 $this->imapacl[$user]= $permission;
168 /* Get all user permissions sorted by acl, to detect the most used acl
169 This acl is then used for %members%
170 */
171 $tmp[$permission][] = $user;
173 /* There is an entry in $this->imapacl like this this ...
174 $this->attrs['imapacl']['anyone'] = "p";
175 $this->attrs['imapacl']['%members%'] = "lprs";
176 $this->attrs['imapacl'][''] = ""; <------ This is used to diplay an empty
177 Field for special acls in our template.
178 If there is at least one special acl in out imapacl,
179 we don't need this entry anymore, because it is already displayed.
180 */
181 if ($user != "anyone" && $user != "%members%"){
182 unset($this->imapacl['']);
183 }
184 }
185 }
187 /* In this section we dectect which acl is tho most used
188 This will be used as %members% acl
189 */
190 $tmp2 = array();
191 foreach($tmp as $acl => $user){
192 $tmp2[count($tmp[$acl])]=$acl;
193 }
194 /* Most used at last */
195 ksort($tmp2);
197 /* Assign last (most used acl) to %members% acl */
198 $this->imapacl['%members%']=array_pop($tmp2);
200 /* Open ldap connection */
201 $ldap = $this->config->get_ldap_link();
202 $ldap->cd($this->config->current['BASE']);
204 /* Remove those users, that use %members% acl && are member of this group. */
205 foreach($this->imapacl as $mail => $permission){
206 $ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
207 $atr = $ldap->fetch();
208 if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
209 unset($this->imapacl[$mail]);
210 }
211 }
213 /* Append an empty entry, for special acl handling */
214 if(count($this->imapacl)==2){
215 $this->imapacl[''] ="";
216 }
217 }else{
218 /* Load permissions */
219 if (isset($this->attrs['acl'])){
220 for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
221 list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
222 $this->imapacl[$user]= $permission;
223 if ($user != "anyone" && $user != "%members%"){
224 unset($this->imapacl['']);
225 }
226 }
227 }
228 }
229 /* Fill translations */
230 $this->perms["lrs"]= _("read");
231 $this->perms["lrsp"]= _("post");
232 $this->perms["p"]= _("external post");
233 $this->perms["lrsip"]= _("append");
234 $this->perms["lrswipcd"]= _("write");
235 }
238 function execute()
239 {
240 /* Call parent execute */
241 //plugin::execute();
243 /* Load templating engine */
244 $smarty= get_smarty();
245 if ($_SESSION['js']==FALSE){
246 $smarty->assign("javascript", "false");
247 } else {
248 $smarty->assign("javascript", "true");
249 }
251 /* Do we need to flip is_account state? */
252 if (isset($_POST['modify_state'])){
253 $this->is_account= !$this->is_account;
254 }
256 /* Do we represent a valid account? */
257 if (!$this->is_account && $this->parent == NULL){
258 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
259 _("This 'dn' has no valid mail extensions.")."</b>";
260 return ($display);
261 }
263 /* Show tab dialog headers */
264 $display= "";
265 if ($this->parent != NULL){
266 if ($this->is_account){
267 $display= $this->show_header(_("Remove mail account"),
268 _("This account has mail features enabled. You can disable them by clicking below."));
269 } else {
270 $display= $this->show_header(_("Create mail account"),
271 _("This account has mail features disabled. You can enable them by clicking below."));
272 return ($display);
273 }
274 }
276 /* Add ACL? */
277 foreach ($this->indexed_user as $nr => $user){
278 if (isset($_POST["add_$nr"])){
279 $this->imapacl[""]= "l";
280 }
281 if (isset($_POST["del_$nr"])){
282 unset ($this->imapacl[$user]);
283 }
284 }
286 /* Trigger forward add dialog? */
287 if (isset($_POST['add_local_forwarder'])){
288 $this->forward_dialog= TRUE;
289 $this->dialog= TRUE;
290 }
292 /* Cancel forward add dialog? */
293 if (isset($_POST['add_locals_cancel'])){
294 $this->forward_dialog= FALSE;
295 $this->dialog= FALSE;
296 }
298 /* Finished adding of locals? */
299 if (isset($_POST['add_locals_finish'])){
300 if (count ($_POST['local_list']) &&
301 chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
303 /* Walk through list of forwarders, ignore own addresses */
304 foreach ($_POST['local_list'] as $val){
305 if (!in_array ($val, $this->gosaMailAlternateAddress) &&
306 $val != $this->mail){
308 $this->addForwarder($val);
309 }
310 }
311 }
312 $this->forward_dialog= FALSE;
313 $this->dialog= FALSE;
314 }
316 /* Add forward email addresses */
317 if (isset($_POST['add_forwarder'])){
318 if ($_POST['forward_address'] != ""){
320 /* Valid email address specified? */
321 $address= $_POST['forward_address'];
322 if (!is_email($address)){
324 print_red (_("You're trying to add an invalid email address ".
325 "to the list of forwarders."));
327 } elseif ($address == $this->mail
328 || in_array($address, $this->gosaMailAlternateAddress)) {
330 print_red (_("Adding your one of your own addresses to the forwarders makes no sense."));
332 } else {
334 /* Add it */
335 if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
336 $this->addForwarder ($address);
337 }
339 }
340 }
341 }
343 /* Delete forward email addresses */
344 if (isset($_POST['delete_forwarder'])){
345 if (count($_POST['forwarder_list'])
346 && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
348 $this->delForwarder ($_POST['forwarder_list']);
349 }
350 }
352 /* Add alternate email addresses */
353 if (isset($_POST['add_alternate'])){
354 if ($_POST['alternate_address'] != "" &&
355 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
357 if (!is_email($_POST['alternate_address'])){
358 print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
360 } elseif (($user= $this->addAlternate ($_POST['alternate_address'])) != ""){
361 $ui= get_userinfo();
362 if ($user != $ui->username){
363 print_red (_("The address you're trying to add is already used by user")." '$user'.");
364 }
365 }
366 }
367 }
369 /* Delete alternate email addresses */
370 if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
371 if (count($_POST['alternates_list']) &&
372 chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
374 $this->delAlternate ($_POST['alternates_list']);
375 }
376 }
378 /* Show forward add dialog */
379 if ($this->forward_dialog){
380 $ldap= $this->config->get_ldap_link();
382 /* Save data */
383 $gmailfilter= get_global("gmailfilter");
384 foreach( array("depselect", "muser", "regex") as $type){
385 if (isset($_POST[$type])){
386 $gmailfilter[$type]= $_POST[$type];
387 }
388 }
389 if (isset($_GET['search'])){
390 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
391 if ($s == "**"){
392 $s= "*";
393 }
394 $gmailfilter['regex']= $s;
395 }
396 register_global("gmailfilter", $gmailfilter);
398 /* Get actual list */
399 $mailusers= array ();
400 if ($gmailfilter['regex'] != '*' && $gmailfilter['regex'] != ""){
401 $regex= $gmailfilter['regex'];
402 $filter= "(|(mail=$regex)(gosaMailAlternateAddress=$regex))";
403 } else {
404 $filter= "";
405 }
406 if ($gmailfilter['muser'] != ""){
407 $user= $gmailfilter['muser'];
408 $filter= "$filter(|(uid=$user)(cn=$user)(givenName=$user)(sn=$user))";
409 }
411 /* Add already present people to the filter */
412 $exclude= "";
413 foreach ($this->gosaMailForwardingAddress as $mail){
414 $exclude.= "(mail=$mail)";
415 }
416 if ($exclude != ""){
417 $filter.= "(!(|$exclude))";
418 }
420 $acl= array($this->config->current['BASE'] => ":all");
421 $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
422 $ldap->cd($gmailfilter['depselect']);
423 $ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
424 error_reporting (0);
425 while ($attrs= $ldap->fetch()){
426 if(preg_match('/%/', $attrs['mail'][0])){
427 continue;
428 }
429 $name= $this->make_name($attrs);
430 $mailusers[$attrs['mail'][0]]= $name."<".
431 $attrs['mail'][0].">";
432 }
433 error_reporting (E_ALL);
434 natcasesort ($mailusers);
435 reset ($mailusers);
437 /* Show dialog */
438 $smarty->assign("search_image", get_template_path('images/search.png'));
439 $smarty->assign("usearch_image", get_template_path('images/search_user.png'));
440 $smarty->assign("tree_image", get_template_path('images/tree.png'));
441 $smarty->assign("infoimage", get_template_path('images/info.png'));
442 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
443 $smarty->assign("mailusers", $mailusers);
444 $smarty->assign("deplist", $this->config->idepartments);
445 $smarty->assign("apply", apply_filter());
446 $smarty->assign("alphabet", generate_alphabet());
447 $smarty->assign("hint", print_sizelimit_warning());
448 foreach( array("depselect", "muser", "regex") as $type){
449 $smarty->assign("$type", $gmailfilter[$type]);
450 }
451 $smarty->assign("hint", print_sizelimit_warning());
452 $display.= $smarty->fetch (get_template_path('mail_locals.tpl', TRUE));
453 return ($display);
454 }
456 /* Assemble normal permissions */
457 $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
458 if (isset($this->imapacl['anyone'])){
459 $smarty->assign("default_permissions", $this->imapacl['anyone']);
460 }
461 $smarty->assign("member_permissions", "lrsp");
462 if (isset($this->imapacl['%members%'])){
463 $smarty->assign("member_permissions", $this->imapacl['%members%']);
464 }
466 /* Assemble extra attributes */
467 $perm= chkacl($this->acl, "permissions");
468 $tmp= "";
469 $nr= 0;
470 $count= count($this->imapacl);
471 $this->indexed_user= array();
472 $this->indexed_acl= array();
473 foreach($this->imapacl as $user => $acl){
474 if ($user != "anyone" && $user != "%members%"){
475 $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
476 "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
477 foreach ($this->perms as $key => $value){
478 if ($acl == $key){
479 $tmp.= "<option value=$key selected>$value</option>";
480 } else {
481 $tmp.= "<option value=$key>$value</option>";
482 }
483 }
484 $tmp.= "</select> ";
485 if ($nr == $count - 1){
486 $tmp.= "<input type=submit value=\""._("Add")."\" ".
487 "name=\"add_$nr\" $perm>";
488 }
489 if ($count > 3){
490 $tmp.= "<input type=submit value=\""._("Remove")."\" ".
491 "name=\"del_$nr\" $perm></td></tr>";
492 }
493 }
494 $this->indexed_user[$nr]= $user;
495 $this->indexed_acl[$nr++]= $acl;
496 }
497 $smarty->assign("plusattributes", $tmp);
499 /* Show main page */
500 $mailserver= array();
501 foreach ($this->config->data['SERVERS']['IMAP'] as $key => $val){
502 $mailserver[]= $key;
503 }
504 $smarty->assign("mailServers", $mailserver);
505 foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
506 "gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
507 $smarty->assign("$val", $this->$val);
508 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
509 }
510 if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
511 $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
512 $smarty->assign("quotadefined", "true");
513 } else {
514 $smarty->assign("quotadefined", "false");
515 }
517 $display.= $smarty->fetch (get_template_path('mail.tpl', TRUE));
518 return ($display);
519 }
522 /* remove object from parent */
523 function remove_from_parent()
524 {
525 /* Added these ObjectClass and Attributes, because they were not
526 removed correctly, only in case of kolab ...
527 */
528 if(isset($this->config->current['MAILMETHOD'])&&preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
529 $this->attributes[]="acl";
530 $this->attributes[]="kolabHomeServer";
531 $this->objectclasses[] = "kolabSharedFolder";
532 }
533 /* include global link_info */
534 $ldap= $this->config->get_ldap_link();
536 /* Remove and write to LDAP */
537 plugin::remove_from_parent();
539 /* Zero arrays */
540 $this->attrs['gosaMailAlternateAddress']= array();
541 $this->attrs['gosaMailForwardingAddress']= array();
542 $this->attrs['gosaSharedFolderTarget']= array();
544 /* Keep uid */
545 unset ($this->attrs['uid']);
546 $ldap->cd($this->dn);
547 $this->cleanup();
548 $ldap->modify ($this->attrs);
550 show_ldap_error($ldap->get_error());
552 /* Connect to IMAP server for account deletion */
553 if ($this->is_account){
554 $method= new $this->method($this->config);
555 if ($method->connect($this->attrs["gosaMailServer"][0])){
556 /* Remove account from IMAP server */
557 $method->deleteMailbox($this->uid);
558 $method->disconnect();
559 }
560 $method->fixAttributesOnRemove($this);
561 }
563 /* Optionally execute a command after we're done */
564 $this->handle_post_events("remove");
565 }
568 /* Save data to object */
569 function save_object()
570 {
571 /* Assemble mail delivery mode
572 The mode field in ldap consists of values between braces, this must
573 be called when 'mail' is set, because checkboxes may not be set when
574 we're in some other dialog.
576 Example for gosaMailDeliveryMode [LR ]
577 L: Local delivery
578 R: Reject when exceeding mailsize limit
579 S: Use spam filter
580 V: Use vacation message
581 C: Use custom sieve script
582 I: Only insider delivery */
583 if (isset($_POST['mailedit'])){
585 /* Save ldap attributes */
586 plugin::save_object();
588 $tmp= "";
589 if (!isset($_POST["drop_own_mails"])){
590 $tmp.= "L";
591 }
592 if (isset($_POST["use_mailsize_limit"])){
593 $tmp.= "R";
594 }
595 if (isset($_POST["use_spam_filter"])){
596 $tmp.= "S";
597 }
598 if (isset($_POST["use_vacation"])){
599 $tmp.= "V";
600 }
601 if (isset($_POST["own_script"])){
602 $tmp.= "C";
603 }
604 if (isset($_POST["only_local"])){
605 $tmp.= "I";
606 }
607 $tmp= "[$tmp]";
609 if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
610 $this->gosaMailDeliveryMode= $tmp;
611 }
613 /* Collect data and re-assign it to the imapacl array */
614 if (chkacl($this->acl, "permissions") == ""){
615 $this->imapacl= array();
616 $this->imapacl['%members%']= $_POST['member_permissions'];
617 $this->imapacl['anyone']= $_POST['default_permissions'];
618 foreach ($this->indexed_user as $nr => $user){
619 if (!isset($_POST["user_$nr"])){
620 continue;
621 }
622 if ($_POST["user_$nr"] != $user ||
623 $_POST["perm_$nr"] != $this->indexed_acl[$nr]){
624 $this->is_modified= TRUE;
625 }
626 $this->imapacl[$_POST["user_$nr"]]= $_POST["perm_$nr"];
627 }
628 }
629 }
631 }
634 /*
635 Backup for function save
636 Änderungen : fixAttributesOnStore($this) wurde erst nach dem this->cleanup();
637 $ldap->modify
639 Ausgeführt, deshalb wurden die gemappten Attribute auch nicht
640 gespeichert.
642 Von : Fabian Hickert
643 Datum : 15.12.2005
645 Alter Quellcode :
647 /* Save data to LDAP, depending on is_account we save or delete * /
648 function save()
649 {
650 $ldap= $this->config->get_ldap_link();
652 /* Call parents save to prepare $this->attrs * /
653 plugin::save();
655 /* Save arrays * /
656 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
657 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
659 /* Save shared folder target * /
660 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
662 /* Save acl's * /
663 $this->attrs['acl']= array();
664 foreach ($this->imapacl as $user => $acl){
665 if ($user == ""){
666 continue;
667 }
668 $this->attrs['acl'][]= "$user $acl";
669 }
671 /* Save data to LDAP * /
672 $ldap->cd($this->dn);
673 $this->cleanup();
674 $ldap->modify ($this->attrs);
676 show_ldap_error($ldap->get_error());
678 /* Only do IMAP actions if we are not a template * /
679 if (!$this->is_template){
680 $method= new $this->method($this->config);
681 $method->fixAttributesOnStore($this);
682 if ($method->connect($this->gosaMailServer)){
683 $method->updateMailbox($this->uid);
684 $method->setQuota($this->uid, $this->gosaMailQuota);
686 /* Exchange '%member%' pseudo entry * /
687 $memberacl= $this->imapacl['%members%'];
688 unset ($this->imapacl['%members%']);
689 foreach ($this->members as $user){
690 if (!isset($this->imapacl[$user])){
691 $this->imapacl[$user]= $memberacl;
692 }
693 }
695 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
696 $method->disconnect();
697 }
698 }
700 /* Optionally execute a command after we're done * /
701 if ($this->initially_was_account == $this->is_account){
702 if ($this->is_modified){
703 $this->handle_post_events("mofify");
704 }
705 } else {
706 $this->handle_post_events("add");
707 }
708 }
710 ENDE Alter Quellcode
711 */
720 /* Save data to LDAP, depending on is_account we save or delete */
721 function save()
722 {
723 $ldap= $this->config->get_ldap_link();
725 /* Call parents save to prepare $this->attrs */
726 plugin::save();
728 /* Save arrays */
729 $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
730 $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
732 /* Save shared folder target */
733 $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
735 if(preg_match("/kolab/i",$this->mmethod)){
736 /* Save acl's */
737 $this->attrs['acl']= array();
738 foreach ($this->imapacl as $user => $acl){
739 if ($user == ""){
740 continue;
741 }
742 $ldap->search("(&(objectClass=person)(uid=".$user."))",array("mail"));
743 $mail = $ldap->fetch();
744 if($mail){
745 if(isset($mail['mail'][0])){
746 $this->attrs['acl'][]= $mail['mail'][0]." $acl";
747 }
748 }else{
749 $this->attrs['acl'][]= "$user $acl";
750 }
751 }
752 }else{
753 /* Save acl's */
754 $this->attrs['acl']= array();
755 foreach ($this->imapacl as $user => $acl){
756 if ($user == ""){
757 continue;
758 }
759 $this->attrs['acl'][]= "$user $acl";
760 }
761 }
763 /* Only do IMAP actions if we are not a template */
764 if(preg_match("/kolab/i",$this->mmethod)){
765 if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
766 if(isset($this->attrs['gosaMailServer'][0])){
767 $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
768 }
769 }
770 }
772 if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
773 $method= new $this->method($this->config);
774 $method->fixAttributesOnStore($this);
775 if ($method->connect($this->gosaMailServer)){
776 $method->updateMailbox($this->uid);
777 $method->setQuota($this->uid, $this->gosaMailQuota);
779 /* Exchange '%member%' pseudo entry */
780 $memberacl= $this->imapacl['%members%'];
781 unset ($this->imapacl['%members%']);
782 foreach ($this->members as $user){
783 if (!isset($this->imapacl[$user])){
784 $this->imapacl[$user]= $memberacl;
785 }
786 }
788 $method->setSharedFolderPermissions($this->uid, $this->imapacl);
789 $method->disconnect();
790 }
791 }
793 /* Save data to LDAP */
794 $ldap->cd($this->dn);
795 $this->cleanup();
796 $ldap->modify ($this->attrs);
798 show_ldap_error($ldap->get_error());
800 /* Optionally execute a command after we're done */
801 if ($this->initially_was_account == $this->is_account){
802 if ($this->is_modified){
803 $this->handle_post_events("mofify");
804 }
805 } else {
806 $this->handle_post_events("add");
807 }
808 }
810 /* Check formular input */
811 function check()
812 {
813 $ldap= $this->config->get_ldap_link();
815 $message= array();
817 /* must: mail */
818 if ($this->mail == ""){
819 $message[]= _("The required field 'Primary address' is not set.");
820 }
821 if (!is_email($this->mail)){
822 $message[]= _("Please enter a valid email addres in 'Primary address' field.");
823 }
824 $ldap->cd($this->config->current['BASE']);
825 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
826 $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
827 if ($ldap->count() != 0){
828 $message[]= _("The primary address you've entered is already in use.");
829 }
831 /* Check quota */
832 if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
833 if (!is_numeric($this->gosaMailQuota)) {
834 $message[]= _("Value in 'Quota size' is not valid.");
835 } else {
836 $this->gosaMailQuota= (int) $this->gosaMailQuota;
837 }
838 }
840 /* Check rejectsize for integer */
841 if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
842 if (!is_numeric($this->gosaMailMaxSize)){
843 $message[]= _("Please specify a vaild mail size for mails to be rejected.");
844 } else {
845 $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
846 }
847 }
849 /* Need gosaMailMaxSize if use_mailsize_limit is checked */
850 if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
851 $message[]= _("You need to set the maximum mail size in order to reject anything.");
852 }
854 if(ord($this->imapacl['anyone'][0])==194){
855 $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
856 }
858 if(empty($this->gosaMailServer)){
859 $message[] = _("Please select a valid mail server.");
860 }
862 return ($message);
863 }
865 /* Adapt from template, using 'dn' */
866 function adapt_from_template($dn)
867 {
868 plugin::adapt_from_template($dn);
870 foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
871 $this->$val= array();
872 if (isset($this->attrs["$val"]["count"])){
873 for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
874 $value= $this->attrs["$val"][$i];
875 foreach (array("sn", "givenName", "uid") as $repl){
876 if (preg_match("/%$repl/i", $value)){
877 $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
878 }
879 }
880 array_push($this->$val, $value);
881 }
882 }
883 }
884 }
886 /* Add entry to forwarder list */
887 function addForwarder($address)
888 {
889 $this->gosaMailForwardingAddress[]= $address;
890 $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
892 sort ($this->gosaMailForwardingAddress);
893 reset ($this->gosaMailForwardingAddress);
894 $this->is_modified= TRUE;
895 }
897 /* Remove list of addresses from forwarder list */
898 function delForwarder($addresses)
899 {
900 $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
901 $this->gosaMailForwardingAddress);
902 $this->is_modified= TRUE;
903 }
907 function addAlternate($address)
908 {
909 $ldap= $this->config->get_ldap_link();
911 $address= strtolower($address);
913 /* Is this address already assigned in LDAP? */
914 $ldap->cd ($this->config->current['BASE']);
915 $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
916 "(gosaMailAlternateAddress=$address)))");
918 if ($ldap->count() > 0){
919 $attrs= $ldap->fetch ();
920 return ($attrs["uid"][0]);
921 }
923 /* Add to list of alternates */
924 if (!in_array($address, $this->gosaMailAlternateAddress)){
925 $this->gosaMailAlternateAddress[]= $address;
926 }
928 sort ($this->gosaMailAlternateAddress);
929 reset ($this->gosaMailAlternateAddress);
930 $this->is_modified= TRUE;
932 return ("");
933 }
936 function delAlternate($addresses)
937 {
938 $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
939 $this->gosaMailAlternateAddress);
940 $this->is_modified= TRUE;
941 }
944 function make_name($attrs)
945 {
946 $name= "";
947 if (isset($attrs['sn'][0])){
948 $name= $attrs['sn'][0];
949 }
950 if (isset($attrs['givenName'][0])){
951 if ($name != ""){
952 $name.= ", ".$attrs['givenName'][0];
953 } else {
954 $name.= $attrs['givenName'][0];
955 }
956 }
957 if ($name != ""){
958 $name.= " ";
959 }
961 return ($name);
962 }
964 }
966 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
967 ?>