25157ba5a4ff4977058f3c39bc205b40d28a97d3
1 <?php
2 /*
3 * This code is part of GOsa (https://gosa.gonicus.de)
4 * Copyright (C) 2008 Cajus Pollmeier
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
22 class Groupware extends plugin
23 {
24 var $plHeadline = "Mail";
25 var $plDescription = "GOsa mail extension.";
26 var $view_logged = FALSE;
28 var $accountInitialized = FALSE;
29 var $rpcError = FALSE;
30 var $rpcErrorMessage = "";
32 var $attributes = array(
33 "mailAddress", "mailLocation", "quotaUsage", "quotaSize", "alternateAddresses",
34 "forwardingAddresses", "vacationEnabled", "vacationStart", "vacationStop",
35 "vacationMessage", "mailBoxWarnLimitEnabled", "mailBoxWarnLimitValue",
36 "mailBoxSendSizelimitEnabled", "mailBoxSendSizelimitValue", "mailBoxHardSizelimitEnabled",
37 "mailBoxHardSizelimitValue", "mailBoxAutomaticRemovalEnabled", "mailBoxAutomaticRemovalValue",
38 "localDeliveryOnly", "dropOwnMails");
41 var $enabledFeatures = array();
43 var $flagAttributes = array("vacationEnabled","mailBoxWarnLimitEnabled","mailBoxSendSizelimitEnabled",
44 "mailBoxHardSizelimitEnabled","mailBoxAutomaticRemovalEnabled","localDeliveryOnly","dropOwnMails");
46 var $mailAddressSelectDialog = NULL;
47 var $filterManager = NULL;
48 var $filterRules = array();
49 var $vacationTemplates = array();
51 //the dropdown
52 var $mailLocations = array();
54 var $mailAddress = "";
55 var $mailLocation = "";
56 var $quotaUsage = 0;
57 var $quotaSize = 0;
58 var $alternateAddresses = array();
59 var $forwardingAddresses = array();
60 var $vacationEnabled = FALSE;
61 var $vacationStart = 0;
62 var $vacationStop = 0;
63 var $vacationMessage = "";
64 var $mailBoxWarnLimitEnabled = FALSE;
65 var $mailBoxWarnLimitValue = 100;
66 var $mailBoxSendSizelimitEnabled = FALSE;
67 var $mailBoxSendSizelimitValue = 100;
68 var $mailBoxHardSizelimitEnabled = FALSE;
69 var $mailBoxHardSizelimitValue = 100;
70 var $mailBoxAutomaticRemovalEnabled = FALSE;
71 var $mailBoxAutomaticRemovalValue = 100;
72 var $localDeliveryOnly = FALSE;
73 var $dropOwnMails = FALSE;
75 var $groupwareDao = null;
77 /*! \brief
78 */
79 function __construct ($config, $dn= NULL)
80 {
81 plugin::plugin($config,$dn);
83 // Get attributes from parent object
84 foreach(array("uid","cn") as $attr){
85 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
86 $this->$attr = &$this->parent->by_object['group']->$attr;
87 }elseif(isset($this->attrs[$attr])){
88 $this->$attr = $this->attrs[$attr][0];
89 }
90 }
91 // Initialize the plugin using rpc.
92 $this->init();
93 }
96 /*! \brief Try to execute a function on the gosa backend using json-rpc.
97 * This method also takes care about errors and sets the required
98 * class members, such as rpcError and rpcErrorMessage.
99 * @param String function The name of the function to call.
100 * @param Mixed args[0-n] The parameter to use.
101 * @return Mixed The result of the function call on success else NULL.
102 */
103 function rpcExec($function)
104 {
105 $params = func_get_args();
106 unset($params[0]);
107 //echo "------<br>Calling function:".$function." Params".var_dump($params)."<br>";
109 $rpc = $this->config->getRpcHandle();
111 $res = call_user_func_array(array($rpc,$function),array_values($params));
112 $this->rpcError = !$rpc->success();
113 if($this->rpcError){
114 $this->rpcErrorMessage = $rpc->get_error();
115 return(NULL);
116 }
117 return($res);
118 }
121 /*! \brief TODO: comment
122 */
123 public function isFeatureEnabled($featureName)
124 {
125 if(isset($this->enabledFeatures[$featureName]) && $this->enabledFeatures[$featureName]){
126 return TRUE;
127 }
128 return FALSE;
129 }
132 /*! \brief Try initialize the groupware account.
133 * This method fetches all required information to manage the
134 * account using the GOsa gui.
135 */
136 function init()
137 {
138 // Detect feature availability and enable/disable services correspondingly.
139 $this->groupwareDao = new GroupwareDao($this);
141 $features = array();
142 //feature names with a list of groupware function that must be availabele
143 //these groupware functions are not the rpc functions, because they are asked from the groupware server
144 $featureReq = array(
145 "primaryMail" => array(
146 'acctGetPrimaryMailAddress'),
147 "quotaUsage" => array(
148 'acctGetQuota'),
149 "quotaSize" => array(
150 'acctSetQuota','acctGetQuota'),
151 "mailLocations" => array(
152 'getMailboxLocations'),
153 "mailFilter" => array("_off",
154 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
155 "alternateAddresses" => array(
156 'acctDelAlternateMailAddress','acctSetAlternateMailAddresses',
157 'acctAddAlternateMailAddress','acctGetAlternateMailAddresses'),
158 "forwardingAddresses" => array(
159 'acctAddMailForwardAddress','acctDelMailForwardAddress',
160 'acctGetMailForwardAddresses','acctSetMailForwardAddresses'),
161 "vacationMessage" => array("_off",
162 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
163 "mailBoxWarnLimit" => array(
164 'acctSetQuota','acctGetQuota'),
165 "mailBoxSendSizelimit" => array(
166 'acctSetQuota','acctGetQuota'),
167 "mailBoxHardSizelimit" => array(
168 'acctSetQuota','acctGetQuota'),
169 "mailBoxAutomaticRemoval" => array("_off",
170 'acctSetQuota','acctGetQuota'),
171 "localDeliveryOnly" => array( "_off",
172 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
173 "dropOwnMails" => array( "_off",
174 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'));
176 // Check if all required methods cann be called!
177 foreach($featureReq as $name => $requires){
178 $active = TRUE;
179 foreach($requires as $methodName){
180 $active &= $this->groupwareDao->gwFeatureAvailable($methodName);
181 }
182 $this->enabledFeatures[$name] = $active;
183 }
184 // Get rpc handle to fetch account info and feature availability.
185 $status = $this->rpcExec('gwAcctExists', $this->uid);
186 if($status !== NULL){
187 $response = $this->groupwareDao->getComprehensiverUser($this->uid);
189 $this->mapComprehensiveUserData($response);
190 $this->initially_was_account = $this->is_account = $status;
192 $this->accountInitialized = TRUE;
193 }
194 // Set vacation start/stop if not set alreasy
195 $this->vacationStart = time();
196 $this->vacationStop = time() + (14 * 60*60*24);
198 // Prepare vacation start/stop time to be initially valid.
199 $this->vacationStart= date('d.m.Y', $this->vacationStart);
200 $this->vacationStop= date('d.m.Y', $this->vacationStop);
201 }
204 /*! \brief Generates the HTML user interface for the groupware plugin
205 * and take of several ui actions like adding or removing
206 * forward addresses, filters and the account itself.
207 */
208 function execute()
209 {
210 // Register plugin execution
211 $display = plugin::execute();
213 // Log plugin execution.
214 if($this->is_account && !$this->view_logged){
215 $this->view_logged = TRUE;
216 new log("view","users/".get_class($this),$this->dn);
217 }
219 // Check if we were able to initialize the account already.
220 if(!$this->accountInitialized){
221 $this->init();
222 if(!$this->accountInitialized){
223 $smarty = get_smarty();
224 $smarty->assign("initFailed", !$this->accountInitialized);
225 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
226 }
227 }
229 // Check if we were able to initialize the account already.
230 if($this->rpcError){
231 $smarty = get_smarty();
232 $smarty->assign("initFailed", !$this->accountInitialized);
233 $smarty->assign("rpcError", $this->rpcError);
234 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
235 }
237 /****************
238 Filter editor
239 ****************/
241 if(isset($_POST['filterManager_cancel'])) $this->filterManager = NULL;
242 if(isset($_POST['filterManager_ok'])){
243 $this->filterManager->save_object();
244 $msgs = $this->filterManager->check();
245 if(count($msgs)){
246 msg_dialog::displayChecks($msgs);
247 }else{
248 $this->filterRules = $this->filterManager->save();
249 $this->filterManager = NULL;
250 }
251 }
252 if(isset($_POST['configureFilter'])){
253 $this->filterManager = new FilterManager($this->config, $this,$this->filterRules);
254 $this->filterManager->acl_base = $this->acl_base;
255 $this->filterManager->acl_category = $this->acl_category;
256 }
257 $this->dialog = FALSE;
258 if($this->filterManager instanceOf FilterManager){
259 $this->filterManager->save_object();
260 $this->dialog = TRUE;
261 return($this->filterManager->execute());
262 }
264 /****************
265 Account status
266 ****************/
268 if(isset($_POST['modify_state'])){
269 if($this->is_account && $this->acl_is_removeable()){
270 $this->is_account= FALSE;
271 }elseif(!$this->is_account && $this->acl_is_createable()){
272 $this->is_account= TRUE;
273 }
274 }
275 if(!$this->multiple_support_active){
276 if (!$this->is_account && $this->parent === NULL){
277 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
278 msgPool::noValidExtension(_("Mail"))."</b>";
279 $display.= back_to_main();
280 return ($display);
281 }
282 if ($this->parent !== NULL){
283 if ($this->is_account){
284 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
285 } else {
286 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
287 return ($display);
288 }
289 }
290 }
292 /****************
293 Forward addresses
294 ****************/
296 // Display dialog to select a local fowarder
297 if (isset($_POST['addLocalForwardingAddress'])){
298 $this->mailAddressSelectDialog= new mailAddressSelect($this->config, get_userinfo());
299 $this->dialog= TRUE;
300 }
302 // Close dialogs, action was canceled
303 if (isset($_POST['mailAddressSelect_cancel'])){
304 $this->mailAddressSelectDialog= FALSE;
305 $this->dialog= FALSE;
306 }
308 // Append selected forwarding addresses now.
309 if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelectDialog instanceOf mailAddressSelect){
310 if($this->acl_is_writeable("forwardingAddresses")){
311 $list = $this->mailAddressSelectDialog->save();
312 foreach ($list as $entry){
313 $val = $entry['mail'][0];
314 if (!in_array ($val, $this->alternateAddresses) && $val != $this->mailAddress){
315 $this->addForwarder($val);
316 $this->is_modified= TRUE;
317 }
318 }
319 $this->mailAddressSelectDialog= FALSE;
320 $this->dialog= FALSE;
321 } else {
322 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
323 }
324 }
326 // Display the address selection dialog.
327 if($this->mailAddressSelectDialog instanceOf mailAddressSelect){
328 $used = array();
329 $used['mail'] = array_values($this->alternateAddresses);
330 $used['mail'] = array_merge($used['mail'], array_values($this->forwardingAddresses));
331 $used['mail'][] = $this->mailAddress;
333 // Build up blocklist
334 session::set('filterBlacklist', $used);
335 return($this->mailAddressSelectDialog->execute());
336 }
338 // Add manually inserted forwarding address.
339 if (isset($_POST['addForwardingAddress'])){
340 if ($_POST['forwardingAddressInput'] != ""){
341 $address= get_post('forwardingAddressInput');
342 $valid= FALSE;
343 if (!tests::is_email($address)){
344 if (!tests::is_email($address, TRUE)){
345 if ($this->is_template){
346 $valid= TRUE;
347 } else {
348 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
349 "","","your-address@your-domain.com"),ERROR_DIALOG);
350 }
351 }
352 } elseif ($address == $this->mailAddress || in_array($address, $this->alternateAddresses)) {
353 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
354 } else {
355 $valid= TRUE;
356 }
357 if ($valid){
358 if($this->acl_is_writeable("forwardingAddresses")){
359 $this->addForwarder ($address);
360 $this->is_modified= TRUE;
361 }
362 }
363 }
364 }
365 if (isset($_POST['deleteForwardingAddress'])){
366 $this->delForwarder ($_POST['forwardingAddressList']);
367 }
369 /****************
370 Alternate addresses
371 ****************/
372 // Add manually inserted alternate mail address.
373 if (isset($_POST['addAlternateAddress'])){
374 $valid= FALSE;
375 if (!tests::is_email($_POST['alternateAddressInput'])){
376 if ($this->is_template){
377 if (!(tests::is_email($_POST['alternateAddressInput'], TRUE))){
378 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),
379 "","","your-domain@your-domain.com"),ERROR_DIALOG);
380 } else {
381 $valid= TRUE;
382 }
383 } else {
384 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),
385 "","","your-domain@your-domain.com"),ERROR_DIALOG);
386 }
387 } else {
388 $valid= TRUE;
389 }
390 if ($valid && ($user= $this->addAlternate (get_post('alternateAddressInput'))) != ""){
391 $ui= get_userinfo();
392 $addon= "";
393 if ($user[0] == "!") {
394 $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
395 } else {
396 $addon= sprintf(_("Address is already in use by user '%s'."), $user);
397 }
398 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
399 "$addon</i>", ERROR_DIALOG);
400 }
401 }
403 // Remove alternate mail address.
404 if (isset($_POST['deleteAlternateAddress']) && isset($_POST['alternateAddressList'])){
405 $this->delAlternate ($_POST['alternateAddressList']);
406 }
409 /****************
410 SMARTY- Assign smarty variables
411 ****************/
413 $smarty = get_smarty();
414 foreach($this->attributes as $attr){
416 $smarty->assign($attr, $this->$attr);
417 }
419 $plInfo = $this->plInfo();
420 foreach($plInfo['plProvidedAcls'] as $acl => $name){
421 $smarty->assign($acl."ACL", $this->getacl($acl));
422 }
423 foreach($this->enabledFeatures as $feature => $state){
424 $smarty->assign($feature."_isActive", $state);
425 }
427 $smarty->assign("mailLocations", $this->mailLocations);
428 if (count($this->vacationTemplates)){
429 $smarty->assign("displayTemplateSelector", "true");
430 $smarty->assign("vacationTemplate", set_post($this->vacationTemplate));
431 $smarty->assign("vacationTemplates", set_post($this->vacationTemplates));
432 $smarty->assign("template", set_post(get_post('vacation_template')));
433 } else {
434 $smarty->assign("displayTemplateSelector", "false");
435 }
437 $smarty->assign("initFailed", !$this->accountInitialized);
438 $smarty->assign("rpcError", $this->rpcError);
439 $smarty->assign("rpcErrorMessage", $this->rpcErrorMessage);
441 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
442 }
445 /*! \brief This method handles potential _POST and _GET values.
446 * It captures modifcations from the ui, like changing
447 * the mailAddress.
448 * This method respects the attribute permissions.
449 */
450 function save_object()
451 {
452 if(isset($_POST['groupwarePluginPosted'])){
454 // We ran into a communication error with the backend.
455 // Try a simple communication operation with the backend
456 // again and let us see if it works.
457 if(isset($_POST['retry'])){
458 $this->rpcExec('gwGetCapabilities');
459 }
461 // Get ui modifications and store them in the class.
462 $testAttrs = array("mailAddress","mailLocation","quotaUsage","quotaSize",
463 "alternateAddresses","forwardingAddresses","vacationEnabled","vacationStart",
464 "vacationStop","vacationMessage");
465 foreach($testAttrs as $attr){
466 if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
467 $this->$attr = get_post($attr);
468 }
469 }
471 // Detect checkbox states
472 $checkAttrs = array("mailBoxWarnLimit","mailBoxSendSizelimit",
473 "mailBoxHardSizelimit","mailBoxAutomaticRemoval");
474 foreach($checkAttrs as $boxname){
475 if($this->acl_is_writeable($boxname)){
476 $v = $boxname."Value";
477 $e = $boxname."Enabled";
478 $this->$e = isset($_POST[$e]);
479 if($this->$e){
480 $this->$v = get_post($v);
481 }
482 }
483 }
485 // Get posted flag changes
486 $flagAttrs = array("localDeliveryOnly","dropOwnMails");
487 foreach($flagAttrs as $attr){
488 $this->$attr = isset($_POST[$attr]);
489 }
490 }
491 }
494 /*! \brief Parse vacation templates and build up an array
495 * containing 'filename' => 'description'.
496 * Used to fill vacation dropdown box.
497 * @return Array All useable vacation templates.
498 */
499 function get_vacation_templates()
500 {
501 $vct = array();
502 if ($this->config->get_cfg_value("core","vacationTemplateDirectory") != ""){
503 $dir= $this->config->get_cfg_value("core","vacationTemplateDirectory");
504 if (is_dir($dir) && is_readable($dir)){
505 $dh = opendir($dir);
506 while($file = readdir($dh)){
507 $description= "";
508 if (is_file($dir."/".$file)){
509 $fh = fopen($dir."/".$file, "r");
510 $line= fgets($fh, 256);
511 if (!preg_match('/^DESC:/', $line)){
512 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
513 }else{
514 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
515 }
516 fclose ($fh);
517 }
518 if ($description != ""){
519 $vct["$dir/$file"]= $description;
520 }
521 }
522 closedir($dh);
523 }
524 }
525 return($vct);
526 }
529 /*! \brief Adds the given mail address to the list of mail forwarders
530 */
531 function addForwarder($address)
532 {
533 if(empty($address)) return;
534 if($this->acl_is_writeable("forwardingAddresses")){
535 $this->forwardingAddresses[]= $address;
536 $this->forwardingAddresses= array_unique ($this->forwardingAddresses);
537 sort ($this->forwardingAddresses);
538 reset ($this->forwardingAddresses);
539 $this->is_modified= TRUE;
540 }else{
541 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
542 }
543 }
546 /*! \brief Removes the given mail address from the list of mail forwarders
547 */
548 function delForwarder($addresses)
549 {
550 if($this->acl_is_writeable("forwardingAddresses")){
551 $this->forwardingAddresses= array_remove_entries ($addresses, $this->forwardingAddresses);
552 $this->is_modified= TRUE;
553 }else{
554 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
555 }
556 }
559 /*! \brief Add given mail address to the list of alternate adresses ,
560 * check if this mal address is used, skip adding in this case
561 */
562 function addAlternate($address)
563 {
564 if(empty($address)) return;
565 if($this->acl_is_writeable("alternateAddresses")){
566 $ldap= $this->config->get_ldap_link();
567 $address= strtolower($address);
569 /* Is this address already assigned in LDAP? */
570 $ldap->cd ($this->config->current['BASE']);
571 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
572 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
573 if ($ldap->count() > 0){
574 $attrs= $ldap->fetch ();
575 if (!isset($attrs["uid"])) {
576 return ("!".$attrs["cn"][0]);
577 }
578 return ($attrs["uid"][0]);
579 }
580 if (!in_array($address, $this->alternateAddresses)){
581 $this->alternateAddresses[]= $address;
582 $this->is_modified= TRUE;
583 }
584 sort ($this->alternateAddresses);
585 reset ($this->alternateAddresses);
586 return ("");
587 }else{
588 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
589 }
590 }
593 /*! \brief Removes the given mail address from the alternate addresses list
594 */
595 function delAlternate($addresses)
596 {
597 if($this->acl_is_writeable("alternateAddresses")){
598 $this->alternateAddresses= array_remove_entries ($addresses,$this->alternateAddresses);
599 $this->is_modified= TRUE;
600 }else{
601 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
602 }
603 }
606 /*! \brief Prepare importet vacation string. \
607 * Replace placeholder like %givenName a.s.o.
608 * @param string Vacation string
609 * @return string Completed vacation string
610 */
611 private function prepare_vacation_template($contents)
612 {
613 /* Replace attributes */
614 $attrs = array();
615 $obj = NULL;
616 if(isset($this->parent->by_object['user'])){
617 $attrs = $this->parent->by_object['user']->attributes;
618 $obj = $this->parent->by_object['user'];
619 }else{
620 $obj = new user($this->config,$this->dn);
621 $attrs = $obj->attributes;
622 }
623 if($obj){
625 /* Replace vacation start and end time */
626 if($this->enabledFeatures['vacationMessage']){
627 if(preg_match("/%start/",$contents)){
628 $contents = preg_replace("/%start/",$this->vacationStart,$contents);
629 }
630 if(preg_match("/%end/",$contents)){
631 $contents = preg_replace("/%end/",$this->vacationStop,$contents);
632 }
633 }else{
634 if(preg_match("/%start/",$contents)){
635 $contents = preg_replace("/%start/", _("unknown"),$contents);
636 }
637 if(preg_match("/%end/",$contents)){
638 $contents = preg_replace("/%end/", _("unknown"), $contents);
639 }
640 }
642 foreach ($attrs as $val){
644 // We can only replace strings here
645 if(!is_string($obj->$val)) continue;
647 if(preg_match("/dateOfBirth/",$val)){
648 if($obj->use_dob){
649 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
650 }
651 }else {
652 $contents= preg_replace("/%$val/",
653 $obj->$val, $contents);
654 }
656 }
657 }
658 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
659 return($contents);
660 }
663 /*! \brief Remove the account form the groupware server completely.
664 */
665 function remove_from_parent()
666 {
667 // Get rpc handle to remove the account
668 if($this->initially_was_account){
669 if($this->rpcExec('gwAcctDel', $this->uid) === NULL){
670 msg_dialog::display(_("Error"), _("Groupware account removal failed!"), ERROR_DIALOG);
671 }
672 }
673 }
676 /* \brief Persists the values of this plugin to the groupware server.
677 * Save method is called on "apply" and "ok" in the Gosa Frontend.
678 * All other actions will update values in the form or
679 * cancel and therefore discard the changes so far.
680 */
681 function save()
682 {
683 // Get rpc handle to create or update the account
684 if(!$this->initially_was_account){
685 if($this->rpcExec('gwAcctAdd', $this->uid, $this->mailAddress) === NULL){
686 msg_dialog::display(_("Error"), _("Groupware account creation failed!"), ERROR_DIALOG);
687 }
688 }
690 // Save the primary Email Address.
691 if(!empty($this->mailAddress)){
692 $this->groupwareDao->save("primaryMail", $this->uid, $this->mailAddress);
693 }\r
695 // Save alternateAddresses and forwarding.
696 \r
697 \r
698 if(!empty($this->forwardingAddresses)
699 && isset($this->alternateAddresses)
700 && is_array($this->alternateAddresses)){
701 $this->groupwareDao->save("alternateAddresses", $this->uid, array($this->alternateAddresses));
702 \r
703 }\r
704 if(!empty($this->forwardingAddresses)
705 && isset($this->forwardingAddresses)
706 && is_array($this->forwardingAddresses)){
707 $this->groupwareDao->save("forwardingAddresses", $this->uid, array($this->forwardingAddresses));
708 \r
709 }
710 // Save the quota
711 if(true){
712 \r
713 $quota = array( "warn_limit" => $this->mailBoxWarnLimitValue,
714 "send_limit" => $this->mailBoxSendSizelimitValue,
715 "hard_limit" => $this->mailBoxHardSizelimitValue,
716 "hold" => $this->quotaSize,
717 "usage" => $this->quotaUsage);
718 $this->groupwareDao->save("quotaSize", $this->uid, $quota);
719 }
721 // TODO: save Mailbox location
722 \r
723 }
726 /*! \brief Check given values
727 */
728 function check()
729 {
730 // TODO: Remove all echo Messages
731 $messages = plugin::check();
733 //Check the dates
735 // TODO: check only if features are enabled.
737 //required vacationEnabled
738 if($this->vacationEnabled){
739 if(!tests::is_date($this->vacationStart)){
740 $messages[] = msgPool::invalid(_("Vacation start date"),$this->vacationStart , "", "01.03.2010");
741 }
742 if(!tests::is_date($this->vacationStop)){
743 $messages[] = msgPool::invalid(_("Vacation stop date"),$this->vacationStop , "", "01.03.2010");
744 }
745 $diff = tests::compareDate($this->vacationStart, $this->vacationStop);
747 if($diff>=0){
748 $messages[] = msgPool::invalid(_("Vacation dates"));
749 }
750 }
751 if(!tests::is_email ($this->mailAddress)){
752 $messages[] = msgPool::invalid(_("Mail address"),$this->mailAddress , "", "user@excom.intranet.gonicus.de");
753 }
755 if(isset($this->forwardingAddresses) && is_array($this->forwardingAddresses)){
756 foreach($this->forwardingAddresses as $fAddress){
757 if(!tests::is_email ($fAddress)){
758 $messages[] = msgPool::invalid(_("Alternate address"),$fAddress, "",
759 "user@excom.intranet.gonicus.de");
760 }
761 if($fAddress == $this->mailAddress){
762 $messages[] = _("The primary address cannot be used as alternative address!");
763 }
764 }
765 }
766 if(isset($this->alternateAddresses) && is_array($this->alternateAddresses)){
767 foreach($this->alternateAddresses as $fAddress){
768 if(!tests::is_email ($fAddress)){
769 $messages[] = msgPool::invalid(_("Forward address"),$fAddress, "", "user@excom.intranet.gonicus.de");
770 }
771 if($fAddress == $this->mailAddress){
772 $messages[] = _("The primary address cannot be used as forward address!");
773 }
774 }
775 }
777 // TODO: Checks for quota and Locations?
778 return($messages);
779 }
782 /*! \brief ACL settings
783 */
784 static function plInfo()
785 {
786 return (array(
787 "plShortName" => _("Groupware"),
788 "plDescription" => _("Groupware settings"),
789 "plSelfModify" => TRUE,
790 "plDepends" => array("user"), // This plugin depends on
791 "plPriority" => 4, // Position in tabs
792 "plSection" => array("personal" => _("My account")),
793 "plCategory" => array("users"),
794 "plOptions" => array(),
795 "plProvidedAcls" => array(
796 "mailAddress" => _("Mail address"),
797 "mailLocation" => _("Mail location"),
798 "quotaUsage" => _("Quota usage"),
799 "mailFilter" => _("Mail filter"),
800 "quotaSize" => _("Quota size"),
801 "alternateAddresses" => _("Alternate mail addresses"),
802 "forwardingAddresses" => _("Forwarding mail addresses"),
803 "vacationEnabled" => _("Vaction switch"),
804 "vacationStart" => _("Vacation start time"),
805 "vacationStop" => _("Vacation stop time"),
806 "vacationMessage" => _("Vacation message"),
807 "mailBoxWarnLimit" => _("Warn sizelimit"),
808 "mailBoxSendSizelimit" => _("Send sizelimit"),
809 "mailBoxHardSizelimit" => _("Hard sizelimit"),
810 "mailBoxAutomaticRemoval" => _("Automatic mail removal"),
811 "localDeliveryOnly" => _("Local delivery only"),
812 "dropOwnMails" => _("Drop own mails")
813 )
814 ));
815 }
818 /*! \brief Maps the resultset fetched from the Dao to the class variables
819 * of the plugin.
820 */
821 function mapComprehensiveUserData($callBackMap)
822 {
823 $map = array(
824 "mailLocations" => "mailLocations",
825 "mailAddress" => "primaryMail",
826 "mailLocation" => "mailLocation",
827 "quotaUsage" => "quotaUsage",
828 "quotaSize" => "quotaSize",
829 "alternateAddresses" => "alternateAddresses",
830 "forwardingAddresses" => "forwardingAddresses",
831 "vacationEnabled" => "vacationEnabled",
832 "vacationStart" => "vacationStart",
833 "vacationStop" => "vacationStop",
834 "vacationMessage" => "vacationMessage",
835 "mailBoxWarnLimitEnabled" => "mailBoxWarnLimitEnabled",
836 "mailBoxWarnLimitValue" => "mailBoxWarnLimitValue",
837 "mailBoxSendSizelimitEnabled" => "mailBoxSendSizelimitEnabled",
838 "mailBoxSendSizelimitValue" => "mailBoxSendSizelimitValue",
839 "mailBoxHardSizelimitEnabled" => "mailBoxHardSizelimitEnabled",
840 "mailBoxHardSizelimitValue" => "mailBoxHardSizelimitValue",
841 "mailBoxAutomaticRemovalEnabled" => "mailBoxAutomaticRemovalEnabled",
842 "mailBoxAutomaticRemovalValue" => "mailBoxAutomaticRemovalValue",
843 "localDeliveryOnly" => "localDeliveryOnly",
844 "dropOwnMails" => "dropOwnMails");
846 // Map values from source array to class members
847 foreach($map as $target => $source){
848 if(isset($callBackMap[$source])){
849 $this->$target = $callBackMap[$source];
850 }
851 }
852 }
853 }
856 ?>