82b7a202d7eede852c42b95a6ed418bf5fa637f7
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 */
20 class groupware extends plugin
21 {
22 var $plHeadline = "Mail";
23 var $plDescription = "GOsa mail extension.";
24 var $view_logged = FALSE;
26 var $accountInitialized = FALSE;
27 var $rpcError = FALSE;
28 var $rpcErrorMessage = "";
31 var $attributes = array(
32 "mailAddress",
33 "mailLocation",
34 "quotaUsage",
35 "quotaSize",
36 "alternateAddresses",
37 "forwardingAddresses",
38 "vacationEnabled",
39 "vacationStart",
40 "vacationStop",
41 "vacationMessage",
42 "mailBoxWarnLimitEnabled",
43 "mailBoxWarnLimitValue",
44 "mailBoxSendSizelimitEnabled",
45 "mailBoxSendSizelimitValue",
46 "mailBoxHardSizelimitEnabled",
47 "mailBoxHardSizelimitValue",
48 "mailBoxAutomaticRemovalEnabled",
49 "mailBoxAutomaticRemovalValue",
50 "localDeliveryOnly",
51 "dropOwnMails"
52 );
55 var $enabledFeatures = array();
57 var $flagAttributes = array("vacationEnabled","mailBoxWarnLimitEnabled","mailBoxSendSizelimitEnabled",
58 "mailBoxHardSizelimitEnabled","mailBoxAutomaticRemovalEnabled","localDeliveryOnly","dropOwnMails");
60 var $mailAddressSelectDialog = NULL;
61 var $filterManager = NULL;
62 var $filterRules = array();
63 var $vacationTemplates = array();
65 //the dropdown
66 var $mailLocations = array();
68 var $mailAddress = "";
69 var $mailLocation = "";
70 var $quotaUsage = 0;
71 var $quotaSize = 0;
72 var $alternateAddresses = array();
73 var $forwardingAddresses = array();
74 var $vacationEnabled = FALSE;
75 var $vacationStart = 0;
76 var $vacationStop = 0;
77 var $vacationMessage = "";
78 var $mailBoxWarnLimitEnabled = FALSE;
79 var $mailBoxWarnLimitValue = 100;
80 var $mailBoxSendSizelimitEnabled = FALSE;
81 var $mailBoxSendSizelimitValue = 100;
82 var $mailBoxHardSizelimitEnabled = FALSE;
83 var $mailBoxHardSizelimitValue = 100;
84 var $mailBoxAutomaticRemovalEnabled = FALSE;
85 var $mailBoxAutomaticRemovalValue = 100;
86 var $localDeliveryOnly = FALSE;
87 var $dropOwnMails = FALSE;
89 var $groupwareDao = FALSE;
90 function __construct ($config, $dn= NULL)
91 {
92 plugin::plugin($config,$dn);
94 // Get attributes from parent object
95 foreach(array("uid","cn") as $attr){
96 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
97 $this->$attr = &$this->parent->by_object['group']->$attr;
98 }elseif(isset($this->attrs[$attr])){
99 $this->$attr = $this->attrs[$attr][0];
100 }
101 }
102 // Initialize the plugin using rpc.
103 $this->init();
104 }
106 /*! \brief Try to execute a function on the gosa backend using json-rpc.
107 * This method also takes care about errors and sets the required
108 * class members, such as rpcError and rpcErrorMessage.
109 * @param String function The name of the function to call.
110 * @param Mixed args[0-n] The parameter to use.
111 * @return Mixed The result of the function call on success else NULL.
112 */
113 function rpcExec($function)
114 {
115 $params = func_get_args();
116 unset($params[0]);
117 //echo "------<br>Calling function:".$function." Params".var_dump($params)."<br>";
119 $rpc = $this->config->getRpcHandle();
121 $res = call_user_func_array(array($rpc,$function),array_values($params));
122 $this->rpcError = !$rpc->success();
123 if($this->rpcError){
124 $this->rpcErrorMessage = $rpc->get_error();
125 return(NULL);
126 }
127 return($res);
128 }
129 public function isFeatureEnabled($featureName){
130 if(isset($this->enabledFeatures[$featureName]) && $this->enabledFeatures[$featureName]){
131 return TRUE;
132 }
133 return FALSE;
134 }
136 /*! \brief Try initialize the groupware account.
137 * This method fetches all required information to manage the
138 * account using the GOsa gui.
139 */
140 function init()
141 {
142 // Detect feature availability and enable/disable services correspondingly.
143 $this->groupwareDao = new groupware_dao($this);
145 $features = array();
147 /*
148 * feature names with a list of groupware function that must be availabele
149 * these groupware functions are not the rpc functions, because they are asked from the groupware server
150 */
151 $featureReq = array(
152 "primaryMail" => array(
153 'acctGetPrimaryMailAddress'),
154 "quotaUsage" => array(
155 'acctGetQuota'),
156 "quotaSize" => array(
157 'acctSetQuota','acctGetQuota'),
158 "mailLocations" => array(
159 'getMailboxLocations'),
160 "mailFilter" => array("_off",
161 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
162 "alternateAddresses" => array(
163 'acctDelAlternateMailAddress','acctSetAlternateMailAddresses',
164 'acctAddAlternateMailAddress','acctGetAlternateMailAddresses'),
165 "forwardingAddresses" => array(
166 'acctAddMailForwardAddress','acctDelMailForwardAddress',
167 'acctGetMailForwardAddresses','acctSetMailForwardAddresses'),
168 "vacationMessage" => array("_off",
169 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
170 "mailBoxWarnLimit" => array(
171 'acctSetQuota','acctGetQuota'),
172 "mailBoxSendSizelimit" => array(
173 'acctSetQuota','acctGetQuota'),
174 "mailBoxHardSizelimit" => array(
175 'acctSetQuota','acctGetQuota'),
176 "mailBoxAutomaticRemoval" => array("_off",
177 'acctSetQuota','acctGetQuota'),
178 "localDeliveryOnly" => array( "_off",
179 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
180 "dropOwnMails" => array( "_off",
181 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'));
183 // Check if all required methods cann be called!
184 foreach($featureReq as $name => $requires){
185 $active = TRUE;
186 foreach($requires as $methodName){
187 $active &= $this->groupwareDao->gwFeatureAvailable($methodName);
188 }
189 $this->enabledFeatures[$name] = $active;
190 }
191 // Get rpc handle to fetch account info and feature availability.
192 $status = $this->rpcExec('gwAcctExists', $this->uid);
193 if($status !== NULL){
196 $compResponse = $this->groupwareDao->getComprehensiverUser($this->uid);
197 /*
198 $response = array("mailAddress"=>"hape@exdom.de",
199 "mailLocation"=>"mailbox 1",
200 "mailLocations"=>array("hape","mailbox 1"),
201 "quotaUsage"=>10,
202 "quotaSize"=>100,
203 "alternateAddresses"=>"alternateAddresses@exdom.de",
204 "forwardingAddresses"=>"forwardingAddresses@exdom.de",
205 "vacationEnabled"=>1,
206 "vacationStart"=>"09.09.2010",
207 "vacationStop"=>"08.09.2010",
208 "vacationMessage"=>"bin in Urlaub message",
209 "mailBoxWarnLimitEnabled"=>1,
210 "mailBoxWarnLimitValue"=>99,
211 "mailBoxSendSizelimitEnabled"=>1,
212 "mailBoxSendSizelimitValue"=>100,
213 "mailBoxHardSizelimitEnabled"=>1,
214 "mailBoxHardSizelimitValue"=>105,
215 "mailBoxAutomaticRemovalEnabled"=>0,
216 "mailBoxAutomaticRemovalValue"=>"mailBoxAutomaticRemovalValue",
217 "localDeliveryOnly"=>0,
218 "dropOwnMails"=>0 );
220 $response = array_merge( $response, $compResponse);
221 */
223 $this->mapComprehensiveUserData($response);
224 $this->initially_was_account = $this->is_account = $status;
226 $this->accountInitialized = TRUE;
227 }
228 // Set vacation start/stop if not set alreasy
229 $this->vacationStart = time();
230 $this->vacationStop = time() + (14 * 60*60*24);
232 // Prepare vacation start/stop time to be initially valid.
233 $this->vacationStart= date('d.m.Y', $this->vacationStart);
234 $this->vacationStop= date('d.m.Y', $this->vacationStop);
235 }
238 /*! \brief Generates the HTML user interface for the groupware plugin
239 * and take of several ui actions like adding or removing
240 * forward addresses, filters and the account itself.
241 */
242 function execute()
243 {
244 // Register plugin execution
245 $display = plugin::execute();
247 // Log plugin execution.
248 if($this->is_account && !$this->view_logged){
249 $this->view_logged = TRUE;
250 new log("view","users/".get_class($this),$this->dn);
251 }
253 // Check if we were able to initialize the account already.
254 if(!$this->accountInitialized){
255 $this->init();
256 if(!$this->accountInitialized){
257 $smarty = get_smarty();
258 $smarty->assign("initFailed", !$this->accountInitialized);
259 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
260 }
261 }
263 // Check if we were able to initialize the account already.
264 if($this->rpcError){
265 $smarty = get_smarty();
266 $smarty->assign("initFailed", !$this->accountInitialized);
267 $smarty->assign("rpcError", $this->rpcError);
268 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
269 }
271 /****************
272 Filter editor
273 ****************/
275 if(isset($_POST['filterManager_cancel'])) $this->filterManager = NULL;
276 if(isset($_POST['filterManager_ok'])){
277 $this->filterManager->save_object();
278 $msgs = $this->filterManager->check();
279 if(count($msgs)){
280 msg_dialog::displayChecks($msgs);
281 }else{
282 $this->filterRules = $this->filterManager->save();
283 $this->filterManager = NULL;
284 }
285 }
286 if(isset($_POST['configureFilter'])){
287 $this->filterManager = new filterManager($this->config, $this,$this->filterRules);
288 $this->filterManager->acl_base = $this->acl_base;
289 $this->filterManager->acl_category = $this->acl_category;
290 }
291 $this->dialog = FALSE;
292 if($this->filterManager instanceOf filterManager){
293 $this->filterManager->save_object();
294 $this->dialog = TRUE;
295 return($this->filterManager->execute());
296 }
298 /****************
299 Account status
300 ****************/
302 if(isset($_POST['modify_state'])){
303 if($this->is_account && $this->acl_is_removeable()){
304 $this->is_account= FALSE;
305 }elseif(!$this->is_account && $this->acl_is_createable()){
306 $this->is_account= TRUE;
307 }
308 }
309 if(!$this->multiple_support_active){
310 if (!$this->is_account && $this->parent === NULL){
311 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
312 msgPool::noValidExtension(_("Mail"))."</b>";
313 $display.= back_to_main();
314 return ($display);
315 }
316 if ($this->parent !== NULL){
317 if ($this->is_account){
318 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
319 } else {
320 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
321 return ($display);
322 }
323 }
324 }
326 /****************
327 Forward addresses
328 ****************/
330 // Display dialog to select a local fowarder
331 if (isset($_POST['addLocalForwardingAddress'])){
332 $this->mailAddressSelectDialog= new mailAddressSelect($this->config, get_userinfo());
333 $this->dialog= TRUE;
334 }
336 // Close dialogs, action was canceled
337 if (isset($_POST['mailAddressSelect_cancel'])){
338 $this->mailAddressSelectDialog= FALSE;
339 $this->dialog= FALSE;
340 }
342 // Append selected forwarding addresses now.
343 if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelectDialog instanceOf mailAddressSelect){
344 if($this->acl_is_writeable("forwardingAddresses")){
345 $list = $this->mailAddressSelectDialog->save();
346 foreach ($list as $entry){
347 $val = $entry['mail'][0];
348 if (!in_array ($val, $this->alternateAddresses) && $val != $this->mailAddress){
349 $this->addForwarder($val);
350 $this->is_modified= TRUE;
351 }
352 }
353 $this->mailAddressSelectDialog= FALSE;
354 $this->dialog= FALSE;
355 } else {
356 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
357 }
358 }
360 // Display the address selection dialog.
361 if($this->mailAddressSelectDialog instanceOf mailAddressSelect){
362 $used = array();
363 $used['mail'] = array_values($this->alternateAddresses);
364 $used['mail'] = array_merge($used['mail'], array_values($this->forwardingAddresses));
365 $used['mail'][] = $this->mailAddress;
367 // Build up blocklist
368 session::set('filterBlacklist', $used);
369 return($this->mailAddressSelectDialog->execute());
370 }
372 // Add manually inserted forwarding address.
373 if (isset($_POST['addForwardingAddress'])){
374 if ($_POST['forwardingAddressInput'] != ""){
375 $address= get_post('forwardingAddressInput');
376 $valid= FALSE;
377 if (!tests::is_email($address)){
378 if (!tests::is_email($address, TRUE)){
379 if ($this->is_template){
380 $valid= TRUE;
381 } else {
382 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
383 "","","your-address@your-domain.com"),ERROR_DIALOG);
384 }
385 }
386 } elseif ($address == $this->mailAddress || in_array($address, $this->alternateAddresses)) {
387 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
388 } else {
389 $valid= TRUE;
390 }
391 if ($valid){
392 if($this->acl_is_writeable("forwardingAddresses")){
393 $this->addForwarder ($address);
394 $this->is_modified= TRUE;
395 }
396 }
397 }
398 }
399 if (isset($_POST['deleteForwardingAddress'])){
400 $this->delForwarder ($_POST['forwardingAddressList']);
401 }
403 /****************
404 Alternate addresses
405 ****************/
406 // Add manually inserted alternate mail address.
407 if (isset($_POST['addAlternateAddress'])){
408 $valid= FALSE;
409 if (!tests::is_email($_POST['alternateAddressInput'])){
410 if ($this->is_template){
411 if (!(tests::is_email($_POST['alternateAddressInput'], TRUE))){
412 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),
413 "","","your-domain@your-domain.com"),ERROR_DIALOG);
414 } else {
415 $valid= TRUE;
416 }
417 } else {
418 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),
419 "","","your-domain@your-domain.com"),ERROR_DIALOG);
420 }
421 } else {
422 $valid= TRUE;
423 }
424 if ($valid && ($user= $this->addAlternate (get_post('alternateAddressInput'))) != ""){
425 $ui= get_userinfo();
426 $addon= "";
427 if ($user[0] == "!") {
428 $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
429 } else {
430 $addon= sprintf(_("Address is already in use by user '%s'."), $user);
431 }
432 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
433 "$addon</i>", ERROR_DIALOG);
434 }
435 }
437 // Remove alternate mail address.
438 if (isset($_POST['deleteAlternateAddress']) && isset($_POST['alternateAddressList'])){
439 $this->delAlternate ($_POST['alternateAddressList']);
440 }
443 /****************
444 SMARTY- Assign smarty variables
445 ****************/
447 $smarty = get_smarty();
448 foreach($this->attributes as $attr){
450 $smarty->assign($attr, $this->$attr);
451 }
453 $plInfo = $this->plInfo();
454 foreach($plInfo['plProvidedAcls'] as $acl => $name){
455 $smarty->assign($acl."ACL", $this->getacl($acl));
456 }
457 foreach($this->enabledFeatures as $feature => $state){
458 $smarty->assign($feature."_isActive", $state);
459 }
462 $smarty->assign("mailLocations", $this->mailLocations);
463 if (count($this->vacationTemplates)){
464 $smarty->assign("displayTemplateSelector", "true");
465 $smarty->assign("vacationTemplate", set_post($this->vacationTemplate));
466 $smarty->assign("vacationTemplates", set_post($this->vacationTemplates));
467 $smarty->assign("template", set_post(get_post('vacation_template')));
468 } else {
469 $smarty->assign("displayTemplateSelector", "false");
470 }
472 $smarty->assign("initFailed", !$this->accountInitialized);
473 $smarty->assign("rpcError", $this->rpcError);
474 $smarty->assign("rpcErrorMessage", $this->rpcErrorMessage);
477 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
478 }
481 /*! \brief This method handles potential _POST and _GET values.
482 * It captures modifcations from the ui, like changing
483 * the mailAddress.
484 * This method respects the attribute permissions.
485 */
486 function save_object()
487 {
488 if(isset($_POST['groupwarePluginPosted'])){
490 // We ran into a communication error with the backend.
491 // Try a simple communication operation with the backend
492 // again and let us see if it works.
493 if(isset($_POST['retry'])){
494 $this->rpcExec('gwGetCapabilities');
495 }
497 // Get ui modifications and store them in the class.
498 $testAttrs = array("mailAddress","mailLocation","quotaUsage","quotaSize",
499 "alternateAddresses","forwardingAddresses","vacationEnabled","vacationStart",
500 "vacationStop","vacationMessage");
501 foreach($testAttrs as $attr){
502 if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
503 $this->$attr = get_post($attr);
504 }
505 }
507 // Detect checkbox states
508 $checkAttrs = array("mailBoxWarnLimit","mailBoxSendSizelimit",
509 "mailBoxHardSizelimit","mailBoxAutomaticRemoval");
510 foreach($checkAttrs as $boxname){
511 if($this->acl_is_writeable($boxname)){
512 $v = $boxname."Value";
513 $e = $boxname."Enabled";
514 $this->$e = isset($_POST[$e]);
515 if($this->$e){
516 $this->$v = get_post($v);
517 }
518 }
519 }
521 // Get posted flag changes
522 $flagAttrs = array("localDeliveryOnly","dropOwnMails");
523 foreach($flagAttrs as $attr){
524 $this->$attr = isset($_POST[$attr]);
525 }
526 }
527 }
530 /*! \brief Parse vacation templates and build up an array
531 containing 'filename' => 'description'.
532 Used to fill vacation dropdown box.
533 @return Array All useable vacation templates.
534 */
535 function get_vacation_templates()
536 {
537 $vct = array();
538 if ($this->config->get_cfg_value("core","vacationTemplateDirectory") != ""){
539 $dir= $this->config->get_cfg_value("core","vacationTemplateDirectory");
540 if (is_dir($dir) && is_readable($dir)){
541 $dh = opendir($dir);
542 while($file = readdir($dh)){
543 $description= "";
544 if (is_file($dir."/".$file)){
545 $fh = fopen($dir."/".$file, "r");
546 $line= fgets($fh, 256);
547 if (!preg_match('/^DESC:/', $line)){
548 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
549 }else{
550 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
551 }
552 fclose ($fh);
553 }
554 if ($description != ""){
555 $vct["$dir/$file"]= $description;
556 }
557 }
558 closedir($dh);
559 }
560 }
561 return($vct);
562 }
565 /*! \brief Adds the given mail address to the list of mail forwarders
566 */
567 function addForwarder($address)
568 {
569 if(empty($address)) return;
570 if($this->acl_is_writeable("forwardingAddresses")){
571 $this->forwardingAddresses[]= $address;
572 $this->forwardingAddresses= array_unique ($this->forwardingAddresses);
573 sort ($this->forwardingAddresses);
574 reset ($this->forwardingAddresses);
575 $this->is_modified= TRUE;
576 }else{
577 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
578 }
579 }
582 /*! \brief Removes the given mail address from the list of mail forwarders
583 */
584 function delForwarder($addresses)
585 {
586 if($this->acl_is_writeable("forwardingAddresses")){
587 $this->forwardingAddresses= array_remove_entries ($addresses, $this->forwardingAddresses);
588 $this->is_modified= TRUE;
589 }else{
590 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
591 }
592 }
595 /*! \brief Add given mail address to the list of alternate adresses ,
596 . check if this mal address is used, skip adding in this case
597 */
598 function addAlternate($address)
599 {
600 if(empty($address)) return;
601 if($this->acl_is_writeable("alternateAddresses")){
602 $ldap= $this->config->get_ldap_link();
603 $address= strtolower($address);
605 /* Is this address already assigned in LDAP? */
606 $ldap->cd ($this->config->current['BASE']);
607 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
608 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
609 if ($ldap->count() > 0){
610 $attrs= $ldap->fetch ();
611 if (!isset($attrs["uid"])) {
612 return ("!".$attrs["cn"][0]);
613 }
614 return ($attrs["uid"][0]);
615 }
616 if (!in_array($address, $this->alternateAddresses)){
617 $this->alternateAddresses[]= $address;
618 $this->is_modified= TRUE;
619 }
620 sort ($this->alternateAddresses);
621 reset ($this->alternateAddresses);
622 return ("");
623 }else{
624 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
625 }
626 }
629 /*! \brief Removes the given mail address from the alternate addresses list
630 */
631 function delAlternate($addresses)
632 {
633 if($this->acl_is_writeable("alternateAddresses")){
634 $this->alternateAddresses= array_remove_entries ($addresses,$this->alternateAddresses);
635 $this->is_modified= TRUE;
636 }else{
637 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
638 }
639 }
642 /*! \brief Prepare importet vacation string. \
643 . Replace placeholder like %givenName a.s.o.
644 @param string Vacation string
645 @return string Completed vacation string
646 */
647 private function prepare_vacation_template($contents)
648 {
649 /* Replace attributes */
650 $attrs = array();
651 $obj = NULL;
652 if(isset($this->parent->by_object['user'])){
653 $attrs = $this->parent->by_object['user']->attributes;
654 $obj = $this->parent->by_object['user'];
655 }else{
656 $obj = new user($this->config,$this->dn);
657 $attrs = $obj->attributes;
658 }
659 if($obj){
661 /* Replace vacation start and end time */
662 if($this->enabledFeatures['vacationMessage']){
663 if(preg_match("/%start/",$contents)){
664 $contents = preg_replace("/%start/",$this->vacationStart,$contents);
665 }
666 if(preg_match("/%end/",$contents)){
667 $contents = preg_replace("/%end/",$this->vacationStop,$contents);
668 }
669 }else{
670 if(preg_match("/%start/",$contents)){
671 $contents = preg_replace("/%start/", _("unknown"),$contents);
672 }
673 if(preg_match("/%end/",$contents)){
674 $contents = preg_replace("/%end/", _("unknown"), $contents);
675 }
676 }
678 foreach ($attrs as $val){
680 // We can only replace strings here
681 if(!is_string($obj->$val)) continue;
683 if(preg_match("/dateOfBirth/",$val)){
684 if($obj->use_dob){
685 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
686 }
687 }else {
688 $contents= preg_replace("/%$val/",
689 $obj->$val, $contents);
690 }
692 }
693 }
694 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
695 return($contents);
696 }
699 /*
700 * TODO: Comment
701 */
702 function remove_from_parent()
703 {
704 // Get rpc handle to remove the account
705 if($this->initially_was_account){
706 if($this->rpcExec('gwAcctDel', $this->uid) === NULL){
707 msg_dialog::display(_("Error"), _("Groupware account removal failed!"), ERROR_DIALOG);
708 }
709 }
710 }
712 /*
713 * TODO: Comment
714 */
715 function save()
716 {
717 // Get rpc handle to create or update the account
718 if(!$this->initially_was_account){
719 if($this->rpcExec('gwAcctAdd', $this->uid, $this->mailAddress) === NULL){
720 msg_dialog::display(_("Error"), _("Groupware account creation failed!"), ERROR_DIALOG);
721 }
722 }
724 /*
725 *save the primary Email Address.
726 */
727 if(!empty($this->mailAddress)){
728 $this->groupwareDao->save("primaryMail", $this->uid, $this->mailAddress);
729 }
731 /*
732 * save alternateAddresses and forwarding.
733 */
734 if(isset($this->alternateAddresses) && is_array($this->alternateAddresses)){
735 $this->groupwareDao->save("alternateAddresses", $this->uid, $this->alternateAddresses);
736 }
737 if(isset($this->forwardingAddresses) && is_array($this->forwardingAddresses)){
738 $this->groupwareDao->save("forwardingAddresses", $this->uid, $this->forwardingAddresses);
739 }
740 /*
741 * save the quota
742 */
743 if(true){
744 $quota = array( "warn_limit" => $this->mailBoxWarnLimitValue,
745 "send_limit" => $this->mailBoxSendSizelimitValue,
746 "hard_limit" => $this->mailBoxHardSizelimitValue,
747 "hold" => $this->quotaSize,
748 "usage" => $this->quotaUsage);
749 $this->groupwareDao->save("quotaSize", $this->uid, $quota);
750 }
752 /*
753 * TODO: save Mailbox location
754 */
756 }
759 /*! \brief Check given values
760 */
761 function check()
762 {
763 /*
764 * TODO: Remove all echo Messages
765 */
766 $messages = plugin::check();
767 /*
768 * Check the dates
769 */
771 /*
772 * TODO: check only if features are enabled.
773 */
774 //required vacationEnabled
775 if($this->vacationEnabled){
776 if(!tests::is_date($this->vacationStart)){
777 $messages[] = msgPool::invalid(_("Vacation start date"),$this->vacationStart , "", _("Example of date : 01.03.2010"));
778 }
779 if(!tests::is_date($this->vacationStop)){
780 $messages[] = msgPool::invalid(_("Vacation stop date"),$this->vacationStop , "", _("Example of date : 01.03.2010"));
781 }
782 $diff = tests::compareDate($this->vacationStart, $this->vacationStop);
784 if($diff>=0){
785 $messages[] = msgPool::invalid(_("Vacation dates"), $this->vacationStart." - ".$this->vacationStop, "", _("Enddate before Start or the same."));
786 }
787 }
788 if(!tests::is_email ($this->mailAddress)){
789 $messages[] = msgPool::invalid(_("Mail address"),$this->mailAddress , "", _("Example: user@excom.intranet.gonicus.de"));
790 }
791 /*
792 * forwarding Addresses
793 * $alternateAddresses
794 * $forwardingAddresses
795 */
796 if(isset($this->forwardingAddresses) && is_array($this->forwardingAddresses)){
797 foreach($this->forwardingAddresses as $fAddress){
798 if(!tests::is_email ($fAddress)){
799 $messages[] = msgPool::invalid(_("Mail address"),$fAddress, "",
800 _("Example: user@excom.intranet.gonicus.de"));
801 }
802 if($fAddress == $this->mailAddress){
803 $messages[] = msgPool::invalid(_("Mail address same as primary Email Address"),$fAddress, "",
804 _("Forward Address and primary Email Address must not be the same (cirle reference)"));
805 }
806 }
807 }
808 if(isset($this->alternateAddresses) && is_array($this->alternateAddresses)){
809 foreach($this->alternateAddresses as $fAddress){
810 if(!tests::is_email ($fAddress)){
811 $messages[] = msgPool::invalid(_("Mail address"),$fAddress, "", _("Example: user@excom.intranet.gonicus.de"));
812 }
813 if($fAddress == $this->mailAddress){
814 $messages[] = msgPool::invalid(_("Mail address same as primary Email Address"),$fAddress, "",
815 _("Alternative Address and primary Email Address must not be the same (cirle reference)"));
816 }
817 }
818 }
819 //TODO: Checks for quota and Locations?
821 return($messages);
822 }
825 /*! \brief Adapt from template, using 'dn'
826 */
827 function adapt_from_template($dn, $skip= array())
828 {
829 plugin::adapt_from_template($dn, $skip);
831 }
834 /*! \brief ACL settings
835 */
836 static function plInfo()
837 {
838 return (array(
839 "plShortName" => _("Groupware"),
840 "plDescription" => _("Groupware settings"),
841 "plSelfModify" => TRUE,
842 "plDepends" => array("user"), // This plugin depends on
843 "plPriority" => 4, // Position in tabs
844 "plSection" => array("personal" => _("My account")),
845 "plCategory" => array("users"),
846 "plOptions" => array(),
847 "plProvidedAcls" => array(
848 "mailAddress" => _("Mail address"),
849 "mailLocation" => _("Mail location"),
850 "quotaUsage" => _("Quota usage"),
851 "mailFilter" => _("Mail filter"),
852 "quotaSize" => _("Quota size"),
853 "alternateAddresses" => _("Alternate mail addresses"),
854 "forwardingAddresses" => _("Forwarding mail addresses"),
855 "vacationEnabled" => _("Vaction switch"),
856 "vacationStart" => _("Vacation start time"),
857 "vacationStop" => _("Vacation stop time"),
858 "vacationMessage" => _("Vacation message"),
859 "mailBoxWarnLimit" => _("Warn sizelimit"),
860 "mailBoxSendSizelimit" => _("Send sizelimit"),
861 "mailBoxHardSizelimit" => _("Hard sizelimit"),
862 "mailBoxAutomaticRemoval" => _("Automatic mail removal"),
863 "localDeliveryOnly" => _("Local delivery only"),
864 "dropOwnMails" => _("Drop own mails")
865 )
866 ));
867 }
870 /*
871 * TODO: comments
872 */
873 function mapComprehensiveUserData($callBackMap)
874 {
876 $this->mailLocations = $callBackMap["mailLocations"];
878 $this->mailAddress = $callBackMap["primaryMail"];
879 $this->mailLocation = $callBackMap["mailLocation"];
880 $this->quotaUsage = $callBackMap["quotaUsage"];
881 $this->quotaSize = $callBackMap["quotaSize"];
882 $this->alternateAddresses = $callBackMap["alternateAddresses"];
883 $this->forwardingAddresses = $callBackMap["forwardingAddresses"];
884 $this->vacationEnabled = $callBackMap["vacationEnabled"];
885 $this->vacationStart = $callBackMap["vacationStart"];
886 $this->vacationStop = $callBackMap["vacationStop"];
887 $this->vacationMessage = $callBackMap["vacationMessage"];
888 $this->mailBoxWarnLimitEnabled = $callBackMap["mailBoxWarnLimitEnabled"];
889 $this->mailBoxWarnLimitValue = $callBackMap["mailBoxWarnLimitValue"];
890 $this->mailBoxSendSizelimitEnabled = $callBackMap["mailBoxSendSizelimitEnabled"];
891 $this->mailBoxSendSizelimitValue = $callBackMap["mailBoxSendSizelimitValue"];
892 $this->mailBoxHardSizelimitEnabled = $callBackMap["mailBoxHardSizelimitEnabled"];
893 $this->mailBoxHardSizelimitValue = $callBackMap["mailBoxHardSizelimitValue"];
894 $this->mailBoxAutomaticRemovalEnabled = $callBackMap["mailBoxAutomaticRemovalEnabled"];
895 $this->mailBoxAutomaticRemovalValue = $callBackMap["mailBoxAutomaticRemovalValue"];
896 $this->localDeliveryOnly = $callBackMap["localDeliveryOnly"];
897 $this->dropOwnMails = $callBackMap["dropOwnMails"];
899 }
900 }
903 /*
904 * Data Access Object for groupwares
905 */
906 class groupware_dao{
907 /*
908 * TODO: Remove the debug
909 */
910 private $debug = false;
911 /*
912 * TODO: fill the following vars on init.
913 */
914 private $availableMethods;
915 private $availableProperties;
916 private $accountLocations;
918 private static $gwFeatures = array(
919 "primaryMail" => array( "get"=>"gwAcctGetPrimaryMailAddress",
920 "save"=>"gwAcctSetPrimaryMailAddress"),
921 "mailLocations" => array("get"=>"gwGetMailboxLocations"),
922 "quotaSize" =>array( "get"=>"gwAcctGetQuota",
923 "save"=>"gwAcctSetQuota",
924 "delete"=>"gwAcctSetQuota"),
925 "mailFilter" =>array( "get"=>"gwAcctGetFilters",
926 "save"=>"gwAcctSetFilters",
927 "delete"=>"gwAcctDelFilter"),
928 "alternateAddresses" =>array( "get"=>"gwAcctGetAlternateMailAddresses",
929 "save"=>"gwAcctSetAlternateMailAddresses",
930 "delete"=>"gwAcctDelAlternateMailAddress"),
931 "forwardingAddresses" =>array( "get"=>"gwAcctGetMailForwardAddresses",
932 "save"=>"gwAcctSetMailForwardAddresses",
933 "delete"=>"gwAcctDelMailForwardAddress"),
934 "vacationMessage" =>array( "get"=>"gwAcctGetOutOfOfficeReply",
935 "save"=>"gwAcctSetOutOfOfficeReply",
936 "delete"=>"gwAcctDelOutOfOfficeReply"),
937 "mailBoxWarnLimit" =>array( "get"=>"",
938 "save"=>"",
939 "delete"=>""),
940 "mailBoxSendSizelimit" =>array( "get"=>"gwAcctGetQuota",
941 "save"=>"gwAcctSetQuota",
942 "delete"=>"gwAcctDelQuota"),
943 "mailBoxHardSizelimit" =>array( "get"=>"gwAcctGetMailLimit",
944 "save"=>"gwAcctSetMailLimit",
945 "delete"=>"gwAcctDelMailLimit"),
946 "mailBoxAutomaticRemoval" =>array( "get"=>"",
947 "save"=>"",
948 "delete"=>""),
949 "localDeliveryOnly" =>array( "get"=>"",
950 "save"=>"",
951 "delete"=>""),
952 "dropOwnMails" =>array( "get"=>"",
953 "save"=>"",
954 "delete"=>""),
955 "accountProperties" => array("get"=>"gwAcctGetProperties",
956 "save"=>"gwAcctSetProperties",
957 "delete"=>"gwAcctDelProperties")
959 );
960 private $groupwarePluginRef = False;
963 /*
964 * TODO: comments
965 */
966 function __construct(&$pluginRef)
967 {
969 $this->groupwarePluginRef = &$pluginRef;
971 /*
972 * TODO:
973 * Remove all echos
974 */
976 $this->init();
977 }
980 /*
981 * gets the capabilities of the server
982 * builds an array with availbale features and knows how to call get, save, delete functions of
983 * groupware rpc.
984 */
985 public function init()
986 {
988 $this->availableMethods = $this->groupwarePluginRef->rpcExec('gwGetCapabilities');
989 //$this->availableProperties = $this->groupwarePluginRef->rpcExec('gwGetSupportedProperties');
990 //$this->debug("availableProperties on init:", $this->availableProperties);
992 }
995 /*
996 * TODO: comment
997 */
998 public function save($feature, $uid, $valueArray)
999 {
1000 /*
1001 * TODO:
1002 * check if feature available
1003 * save and return the result.
1004 */
1005 $function = groupware_dao::$gwFeatures[$feature]["save"];
1007 if(is_array($valueArray)){
1008 $valueArray = array_merge(array($function, $uid), $valueArray);
1009 }
1010 else{
1011 $valueArray = array($function, $uid, $valueArray);
1012 }
1013 $this->debug("SAVING (feature, value)", $valueArray);
1014 $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray);
1016 return $result;
1017 }
1020 /*
1021 * TODO: comment
1022 */
1023 public function get($feature, $valueArray)
1024 {
1025 /*
1026 * TODO:
1027 * check if feture available ?
1028 * get and return the result.
1029 */
1030 $function = groupware_dao::$gwFeatures[$feature]["get"];
1031 if(is_array($valueArray)){
1032 $valueArray = array_merge(array($function), $valueArray);
1033 }
1034 else{
1035 $valueArray = array($function, $valueArray);
1036 }
1038 $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray);
1040 return $result;
1041 }
1044 /*
1045 * TODO: comment
1046 */
1047 public function del($feature, $valueArray)
1048 {
1049 /*
1050 * TODO:
1051 * check if feture available
1052 * del and return the result.
1053 */
1054 echo "deletion of values is not implemented yet";
1055 /*
1056 $function = groupware_dao::$gwFeatures[$feature]["delete"];
1058 $valueArray = array_merge(array($function), $valueArray);
1060 $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray);
1062 return $result;
1063 */
1064 }
1067 /*
1068 * TODO: comment
1069 */
1070 public function gwFeatureAvailable($methodName)
1071 {
1073 return $this->availableMethods[$methodName];
1074 }
1077 /*
1078 * TODO: comment
1079 */
1080 public function getComprehensiverUser( $uid)
1081 {
1082 //$hi = $this->groupwarePluginRef->rpcExec('gwGetCapabilities');
1083 $resultArr = array();
1085 if($this->groupwarePluginRef->isFeatureEnabled("primaryMail")){
1086 $resultArr["primaryMail"] = $this->get("primaryMail", array($uid));
1087 }
1089 if($this->groupwarePluginRef->isFeatureEnabled("alternateAddresses")){
1090 $resultArr["alternateAddresses"] = $this->get("alternateAddresses", array($uid));
1091 }
1093 if($this->groupwarePluginRef->isFeatureEnabled("forwardingAddresses")){
1094 $resultArr["forwardingAddresses"] = $this->get("forwardingAddresses", array($uid));
1095 }
1097 if($this->groupwarePluginRef->isFeatureEnabled("forwardingAddresses")){
1098 $resultArr["forwardingAddresses"] = $this->get("forwardingAddresses", array($uid));
1099 }
1101 //location dropdownlist - only readable
1102 if($this->groupwarePluginRef->isFeatureEnabled("mailLocations")){
1103 $resultArr["mailLocations"] = $this->groupwarePluginRef->rpcExec('gwGetMailboxLocations');
1104 $resultArr["mailLocation"] = $this->groupwarePluginRef->rpcExec(array('gwAcctGetLocation',$uid));
1105 }
1106 /*
1107 * TODO:
1108 * getLocation muss ebenfalls geholt werden
1109 */
1111 //Quota quotaUsage, quotaSize
1112 if($this->groupwarePluginRef->isFeatureEnabled("quotaSize") ||
1113 $this->groupwarePluginRef->isFeatureEnabled("quotaUsage") ||
1114 $this->groupwarePluginRef->isFeatureEnabled("mailBoxWarnLimit") ||
1115 $this->groupwarePluginRef->isFeatureEnabled("mailBoxSendSizelimit") ||
1116 $this->groupwarePluginRef->isFeatureEnabled("mailBoxHardSizelimit")){
1118 /*
1119 * Usage is a Mapi function which is not yet
1120 */
1121 /*
1122 * TODO:
1123 * remove the following dummy and enable the qota fetch from groupware
1124 */
1125 echo "Quota function not yet implemented on server side!!";
1126 //$quota = $this->get("quotaSize", array($uid));
1127 $quota = array( "warn_limit" => 1008,
1128 "send_limit" => 108,
1129 "hard_limit" => 1108,
1130 "hold" => 508,
1131 "usage" => 1108);
1132 $resultArr["quotaSize"] = $quota["usage"];
1133 $resultArr["quotaSize"] = $quota["hold"];
1134 if($quota["warn_limit"] > 0){
1135 $resultArr["mailBoxWarnLimitEnabled"] = true;
1136 $resultArr["mailBoxWarnLimitValue"] = $quota["warn_limit"];
1137 }
1138 else{
1139 $resultArr["mailBoxWarnLimitEnabled"] = false;
1140 $resultArr["mailBoxWarnLimitValue"] = 0;
1141 }
1142 if($quota["send_limit"] > 0){
1143 $resultArr["mailBoxSendSizelimitEnabled"] = True;
1144 $resultArr["mailBoxSendSizelimitValue"] = $quota["send_limit"];
1145 }
1146 else{
1147 $resultArr["mailBoxSendSizelimitEnabled"] = FALSE;
1148 $resultArr["mailBoxSendSizelimitValue"] = 0;
1149 }
1150 if($quota["hard_limit"] > 0){
1151 $resultArr["mailBoxHardSizelimitEnabled"] = True;
1152 $resultArr["mailBoxHardSizelimitValue"] = $quota["hard_limit"];
1153 }
1154 else{
1155 $resultArr["mailBoxHardSizelimitEnabled"] = FALSE;
1156 $resultArr["mailBoxHardSizelimitValue"] = 0;
1157 }
1158 }
1160 /*
1161 * this function seems to be broken on the server.
1162 * addding dummy
1163 */
1164 if($this->groupwarePluginRef->isFeatureEnabled("vacationMessage")){
1166 //$vacMessage = $this->get("vacationMessage", array($uid));
1167 $resultArr["vacationMessage"] = "dummy Vacation message - (getOutOfOfficeReply currently throws errors )";
1168 }
1170 $this->debug("getComprehensiverUser:", $resultArr);
1171 return $resultArr;
1172 }
1175 /*
1176 * TODO: remove all debug functions.
1177 */
1178 public function debug($name, $message)
1179 {
1180 if($this->debug){
1181 echo"<b>".$name."</b>";
1182 if(is_array($message)){
1183 echo "<pre>";
1184 print_r($message);
1185 echo "</pre>";
1186 }
1187 else{
1188 echo "$message";
1189 }
1190 }
1191 }
1192 }
1193 ?>