dc8dc4b90a5ca29ea6ece263023a9e414b28a1b2
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 = "";
30 var $attributes = array(
31 "mailAddress",
32 "mailLocation",
33 "quotaUsage",
34 "quotaSize",
35 "alternateAddresses",
36 "forwardingAddresses",
37 "vacationEnabled",
38 "vacationStart",
39 "vacationStop",
40 "vacationMessage",
41 "mailBoxWarnLimitEnabled",
42 "mailBoxWarnLimitValue",
43 "mailBoxSendSizelimitEnabled",
44 "mailBoxSendSizelimitValue",
45 "mailBoxHardSizelimitEnabled",
46 "mailBoxHardSizelimitValue",
47 "mailBoxAutomaticRemovalEnabled",
48 "mailBoxAutomaticRemovalValue",
49 "localDeliveryOnly",
50 "dropOwnMails"
51 );
53 var $enabledFeatures = array();
55 var $flagAttributes = array("vacationEnabled","mailBoxWarnLimitEnabled","mailBoxSendSizelimitEnabled",
56 "mailBoxHardSizelimitEnabled","mailBoxAutomaticRemovalEnabled","localDeliveryOnly","dropOwnMails");
58 var $mailAddressSelectDialog = NULL;
59 var $filterManager = NULL;
60 var $filterRules = array();
61 var $vacationTemplates = array();
63 var $mailAddress = "";
64 var $mailLocation = "";
65 var $quotaUsage = 0;
66 var $quotaSize = 0;
67 var $alternateAddresses = array();
68 var $forwardingAddresses = array();
69 var $vacationEnabled = FALSE;
70 var $vacationStart = 0;
71 var $vacationStop = 0;
72 var $vacationMessage = "";
73 var $mailBoxWarnLimitEnabled = FALSE;
74 var $mailBoxWarnLimitValue = 100;
75 var $mailBoxSendSizelimitEnabled = FALSE;
76 var $mailBoxSendSizelimitValue = 100;
77 var $mailBoxHardSizelimitEnabled = FALSE;
78 var $mailBoxHardSizelimitValue = 100;
79 var $mailBoxAutomaticRemovalEnabled = FALSE;
80 var $mailBoxAutomaticRemovalValue = 100;
81 var $localDeliveryOnly = FALSE;
82 var $dropOwnMails = FALSE;
84 var $groupwareDao = FALSE;
85 function __construct ($config, $dn= NULL)
86 {
87 plugin::plugin($config,$dn);
89 // Get attributes from parent object
90 foreach(array("uid","cn") as $attr){
91 if(isset($this->parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){
92 $this->$attr = &$this->parent->by_object['group']->$attr;
93 }elseif(isset($this->attrs[$attr])){
94 $this->$attr = $this->attrs[$attr][0];
95 }
96 }
97 // Initialize the plugin using rpc.
98 $this->init();
99 }
101 /*! \brief Try to execute a function on the gosa backend using json-rpc.
102 * This method also takes care about errors and sets the required
103 * class members, such as rpcError and rpcErrorMessage.
104 * @param String function The name of the function to call.
105 * @param Mixed args[0-n] The parameter to use.
106 * @return Mixed The result of the function call on success else NULL.
107 */
108 function rpcExec($function)
109 {
110 $params = func_get_args();
111 unset($params[0]);
112 //echo "------<br>Calling function:".$function." Params".var_dump($params)."<br>";
113 echo "------<br>Calling function:".$function."<br>";
115 $rpc = $this->config->getRpcHandle();
116 echo get_class($rpc);
117 $res = call_user_func_array(array($rpc,$function),array_values($params));
118 $this->rpcError = !$rpc->success();
119 if($this->rpcError){
120 $this->rpcErrorMessage = $rpc->get_error();
121 return(NULL);
122 }
123 return($res);
124 }
125 public function isFeatureEnabled($featureName){
126 if(isset($this->enabledFeatures[$featureName]) && $this->enabledFeatures[$featureName]){
127 return TRUE;
128 }
129 return FALSE;
130 }
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 groupware_dao($this);
141 $features = array();
142 $featureReq = array(
143 "primaryMail" => array(
144 'acctGetPrimaryMailAddress'),
145 "quotaUsage" => array(
146 'acctGetQuota'),
147 "quotaSize" => array(
148 'acctSetQuota','acctGetQuota'),
149 "mailFilter" => array(
150 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
151 "alternateAddresses" => array(
152 'acctDelAlternateMailAddress','acctSetAlternateMailAddresses',
153 'acctAddAlternateMailAddress','acctGetAlternateMailAddresses'),
154 "forwardingAddresses" => array(
155 'acctAddMailForwardAddress','acctDelMailForwardAddress',
156 'acctGetMailForwardAddresses','acctSetMailForwardAddresses'),
157 "vacationMessage" => array(
158 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
159 "mailBoxWarnLimit" => array(
160 'acctSetQuota','acctGetQuota'),
161 "mailBoxSendSizelimit" => array(
162 'acctSetQuota','acctGetQuota'),
163 "mailBoxHardSizelimit" => array(
164 'acctSetQuota','acctGetQuota'),
165 "mailBoxAutomaticRemoval" => array(
166 'acctSetQuota','acctGetQuota'),
167 "localDeliveryOnly" => array(
168 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'),
169 "dropOwnMails" => array(
170 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'));
172 // Check if all required methods cann be called!
173 foreach($featureReq as $name => $requires){
174 $active = TRUE;
175 foreach($requires as $methodName){
176 $active &= $this->groupwareDao->gwFeatureAvailable($methodName);
177 }
178 $this->enabledFeatures[$name] = $active;
179 }
180 // Get rpc handle to fetch account info and feature availability.
181 $status = $this->rpcExec('gwAcctExists', $this->uid);
182 if($status !== NULL){
184 var_dump($this->rpcExec('gwAcctGetLocation',$this->uid));
185 $compResponse = $this->groupwareDao->getComprehensiverUser($this->uid);
187 $response = array("mailAddress"=>"hape@exdom.de",
188 "mailLocation"=>"hape@exdom.de",
189 "quotaUsage"=>10,
190 "quotaSize"=>100,
191 "alternateAddresses"=>"alternateAddresses@exdom.de",
192 "forwardingAddresses"=>"forwardingAddresses@exdom.de",
193 "vacationEnabled"=>1,
194 "vacationStart"=>"09.09.2010",
195 "vacationStop"=>"08.09.2010",
196 "vacationMessage"=>"bin in Urlaub message",
197 "mailBoxWarnLimitEnabled"=>1,
198 "mailBoxWarnLimitValue"=>99,
199 "mailBoxSendSizelimitEnabled"=>1,
200 "mailBoxSendSizelimitValue"=>100,
201 "mailBoxHardSizelimitEnabled"=>1,
202 "mailBoxHardSizelimitValue"=>105,
203 "mailBoxAutomaticRemovalEnabled"=>0,
204 "mailBoxAutomaticRemovalValue"=>"mailBoxAutomaticRemovalValue",
205 "localDeliveryOnly"=>0,
206 "dropOwnMails"=>0 );
208 $response = array_merge( $response, $compResponse);
211 $this->mapComprehensiveUserData($response);
212 $this->initially_was_account = $this->is_account = $status;
214 $this->accountInitialized = TRUE;
215 }
216 // Set vacation start/stop if not set alreasy
217 $this->vacationStart = time();
218 $this->vacationStop = time() + (14 * 60*60*24);
220 // Prepare vacation start/stop time to be initially valid.
221 $this->vacationStart= date('d.m.Y', $this->vacationStart);
222 $this->vacationStop= date('d.m.Y', $this->vacationStop);
223 }
226 /*! \brief Generates the HTML user interface for the groupware plugin
227 * and take of several ui actions like adding or removing
228 * forward addresses, filters and the account itself.
229 */
230 function execute()
231 {
232 // Register plugin execution
233 $display = plugin::execute();
235 // Log plugin execution.
236 if($this->is_account && !$this->view_logged){
237 $this->view_logged = TRUE;
238 new log("view","users/".get_class($this),$this->dn);
239 }
241 // Check if we were able to initialize the account already.
242 if(!$this->accountInitialized){
243 $this->init();
244 if(!$this->accountInitialized){
245 $smarty = get_smarty();
246 $smarty->assign("initFailed", !$this->accountInitialized);
247 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
248 }
249 }
251 // Check if we were able to initialize the account already.
252 if($this->rpcError){
253 $smarty = get_smarty();
254 $smarty->assign("initFailed", !$this->accountInitialized);
255 $smarty->assign("rpcError", $this->rpcError);
256 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
257 }
259 /****************
260 Filter editor
261 ****************/
263 if(isset($_POST['filterManager_cancel'])) $this->filterManager = NULL;
264 if(isset($_POST['filterManager_ok'])){
265 $this->filterManager->save_object();
266 $msgs = $this->filterManager->check();
267 if(count($msgs)){
268 msg_dialog::displayChecks($msgs);
269 }else{
270 $this->filterRules = $this->filterManager->save();
271 $this->filterManager = NULL;
272 }
273 }
274 if(isset($_POST['configureFilter'])){
275 $this->filterManager = new filterManager($this->config, $this,$this->filterRules);
276 $this->filterManager->acl_base = $this->acl_base;
277 $this->filterManager->acl_category = $this->acl_category;
278 }
279 $this->dialog = FALSE;
280 if($this->filterManager instanceOf filterManager){
281 $this->filterManager->save_object();
282 $this->dialog = TRUE;
283 return($this->filterManager->execute());
284 }
287 /****************
288 Account status
289 ****************/
291 if(isset($_POST['modify_state'])){
292 if($this->is_account && $this->acl_is_removeable()){
293 $this->is_account= FALSE;
294 }elseif(!$this->is_account && $this->acl_is_createable()){
295 $this->is_account= TRUE;
296 }
297 }
298 if(!$this->multiple_support_active){
299 if (!$this->is_account && $this->parent === NULL){
300 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
301 msgPool::noValidExtension(_("Mail"))."</b>";
302 $display.= back_to_main();
303 return ($display);
304 }
305 if ($this->parent !== NULL){
306 if ($this->is_account){
307 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail")));
308 } else {
309 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail")));
310 return ($display);
311 }
312 }
313 }
315 /****************
316 Forward addresses
317 ****************/
319 // Display dialog to select a local fowarder
320 if (isset($_POST['addLocalForwardingAddress'])){
321 $this->mailAddressSelectDialog= new mailAddressSelect($this->config, get_userinfo());
322 $this->dialog= TRUE;
323 }
325 // Close dialogs, action was canceled
326 if (isset($_POST['mailAddressSelect_cancel'])){
327 $this->mailAddressSelectDialog= FALSE;
328 $this->dialog= FALSE;
329 }
331 // Append selected forwarding addresses now.
332 if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelectDialog instanceOf mailAddressSelect){
333 if($this->acl_is_writeable("forwardingAddresses")){
334 $list = $this->mailAddressSelectDialog->save();
335 foreach ($list as $entry){
336 $val = $entry['mail'][0];
337 if (!in_array ($val, $this->alternateAddresses) && $val != $this->mailAddress){
338 $this->addForwarder($val);
339 $this->is_modified= TRUE;
340 }
341 }
342 $this->mailAddressSelectDialog= FALSE;
343 $this->dialog= FALSE;
344 } else {
345 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
346 }
347 }
349 // Display the address selection dialog.
350 if($this->mailAddressSelectDialog instanceOf mailAddressSelect){
351 $used = array();
352 $used['mail'] = array_values($this->alternateAddresses);
353 $used['mail'] = array_merge($used['mail'], array_values($this->forwardingAddresses));
354 $used['mail'][] = $this->mailAddress;
356 // Build up blocklist
357 session::set('filterBlacklist', $used);
358 return($this->mailAddressSelectDialog->execute());
359 }
361 // Add manually inserted forwarding address.
362 if (isset($_POST['addForwardingAddress'])){
363 if ($_POST['forwardingAddressInput'] != ""){
364 $address= get_post('forwardingAddressInput');
365 $valid= FALSE;
366 if (!tests::is_email($address)){
367 if (!tests::is_email($address, TRUE)){
368 if ($this->is_template){
369 $valid= TRUE;
370 } else {
371 msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"),
372 "","","your-address@your-domain.com"),ERROR_DIALOG);
373 }
374 }
375 } elseif ($address == $this->mailAddress || in_array($address, $this->alternateAddresses)) {
376 msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG);
377 } else {
378 $valid= TRUE;
379 }
380 if ($valid){
381 if($this->acl_is_writeable("forwardingAddresses")){
382 $this->addForwarder ($address);
383 $this->is_modified= TRUE;
384 }
385 }
386 }
387 }
388 if (isset($_POST['deleteForwardingAddress'])){
389 $this->delForwarder ($_POST['forwardingAddressList']);
390 }
393 /****************
394 Alternate addresses
395 ****************/
398 // Add manually inserted alternate mail address.
399 if (isset($_POST['addAlternateAddress'])){
400 $valid= FALSE;
401 if (!tests::is_email($_POST['alternateAddressInput'])){
402 if ($this->is_template){
403 if (!(tests::is_email($_POST['alternateAddressInput'], TRUE))){
404 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),
405 "","","your-domain@your-domain.com"),ERROR_DIALOG);
406 } else {
407 $valid= TRUE;
408 }
409 } else {
410 msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"),
411 "","","your-domain@your-domain.com"),ERROR_DIALOG);
412 }
413 } else {
414 $valid= TRUE;
415 }
416 if ($valid && ($user= $this->addAlternate (get_post('alternateAddressInput'))) != ""){
417 $ui= get_userinfo();
418 $addon= "";
419 if ($user[0] == "!") {
420 $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1));
421 } else {
422 $addon= sprintf(_("Address is already in use by user '%s'."), $user);
423 }
424 msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."<br><br><i>".
425 "$addon</i>", ERROR_DIALOG);
426 }
427 }
429 // Remove alternate mail address.
430 if (isset($_POST['deleteAlternateAddress']) && isset($_POST['alternateAddressList'])){
431 $this->delAlternate ($_POST['alternateAddressList']);
432 }
435 /****************
436 SMARTY- Assign smarty variables
437 ****************/
439 $smarty = get_smarty();
440 foreach($this->attributes as $attr){
441 $smarty->assign($attr, $this->$attr);
442 }
444 $plInfo = $this->plInfo();
445 foreach($plInfo['plProvidedAcls'] as $acl => $name){
446 $smarty->assign($acl."ACL", $this->getacl($acl));
447 }
448 foreach($this->enabledFeatures as $feature => $state){
449 $smarty->assign($feature."_isActive", $state);
450 }
452 $smarty->assign("mailLocations", array("tester"));
453 if (count($this->vacationTemplates)){
454 $smarty->assign("displayTemplateSelector", "true");
455 $smarty->assign("vacationTemplate", set_post($this->vacationTemplate));
456 $smarty->assign("vacationTemplates", set_post($this->vacationTemplates));
457 $smarty->assign("template", set_post(get_post('vacation_template')));
458 } else {
459 $smarty->assign("displayTemplateSelector", "false");
460 }
462 $smarty->assign("initFailed", !$this->accountInitialized);
463 $smarty->assign("rpcError", $this->rpcError);
464 $smarty->assign("rpcErrorMessage", $this->rpcErrorMessage);
467 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
468 }
472 /*! \brief This method handles potential _POST and _GET values.
473 * It captures modifcations from the ui, like changing
474 * the mailAddress.
475 * This method respects the attribute permissions.
476 */
477 function save_object()
478 {
479 if(isset($_POST['groupwarePluginPosted'])){
481 // We ran into a communication error with the backend.
482 // Try a simple communication operation with the backend
483 // again and let us see if it works.
484 if(isset($_POST['retry'])){
485 $this->rpcExec('gwGetCapabilities');
486 }
488 // Get ui modifications and store them in the class.
489 foreach($this->attributes as $attr){
490 if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){
491 $this->$attr = get_post($attr);
492 }
493 }
494 /*
495 * TODO: ACL check is missing
496 */
497 echo 'ACL checks missing!';
499 foreach($this->flagAttributes as $attr){
500 $this->$attr = isset($_POST[$attr]);
501 }
502 }
503 }
506 /*! \brief Parse vacation templates and build up an array
507 containing 'filename' => 'description'.
508 Used to fill vacation dropdown box.
509 @return Array All useable vacation templates.
510 */
511 function get_vacation_templates()
512 {
513 $vct = array();
514 if ($this->config->get_cfg_value("core","vacationTemplateDirectory") != ""){
515 $dir= $this->config->get_cfg_value("core","vacationTemplateDirectory");
516 if (is_dir($dir) && is_readable($dir)){
517 $dh = opendir($dir);
518 while($file = readdir($dh)){
519 $description= "";
520 if (is_file($dir."/".$file)){
521 $fh = fopen($dir."/".$file, "r");
522 $line= fgets($fh, 256);
523 if (!preg_match('/^DESC:/', $line)){
524 msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG);
525 }else{
526 $description= trim(preg_replace('/^DESC:\s*/', '', $line));
527 }
528 fclose ($fh);
529 }
530 if ($description != ""){
531 $vct["$dir/$file"]= $description;
532 }
533 }
534 closedir($dh);
535 }
536 }
537 return($vct);
538 }
541 /*! \brief Adds the given mail address to the list of mail forwarders
542 */
543 function addForwarder($address)
544 {
545 if(empty($address)) return;
546 if($this->acl_is_writeable("forwardingAddresses")){
547 $this->forwardingAddresses[]= $address;
548 $this->forwardingAddresses= array_unique ($this->forwardingAddresses);
549 sort ($this->forwardingAddresses);
550 reset ($this->forwardingAddresses);
551 $this->is_modified= TRUE;
552 }else{
553 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
554 }
555 }
558 /*! \brief Removes the given mail address from the list of mail forwarders
559 */
560 function delForwarder($addresses)
561 {
562 if($this->acl_is_writeable("forwardingAddresses")){
563 $this->forwardingAddresses= array_remove_entries ($addresses, $this->forwardingAddresses);
564 $this->is_modified= TRUE;
565 }else{
566 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
567 }
568 }
571 /*! \brief Add given mail address to the list of alternate adresses ,
572 . check if this mal address is used, skip adding in this case
573 */
574 function addAlternate($address)
575 {
576 if(empty($address)) return;
577 if($this->acl_is_writeable("alternateAddresses")){
578 $ldap= $this->config->get_ldap_link();
579 $address= strtolower($address);
581 /* Is this address already assigned in LDAP? */
582 $ldap->cd ($this->config->current['BASE']);
583 $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)".
584 "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn"));
585 if ($ldap->count() > 0){
586 $attrs= $ldap->fetch ();
587 if (!isset($attrs["uid"])) {
588 return ("!".$attrs["cn"][0]);
589 }
590 return ($attrs["uid"][0]);
591 }
592 if (!in_array($address, $this->alternateAddresses)){
593 $this->alternateAddresses[]= $address;
594 $this->is_modified= TRUE;
595 }
596 sort ($this->alternateAddresses);
597 reset ($this->alternateAddresses);
598 return ("");
599 }else{
600 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
601 }
602 }
605 /*! \brief Removes the given mail address from the alternate addresses list
606 */
607 function delAlternate($addresses)
608 {
609 if($this->acl_is_writeable("alternateAddresses")){
610 $this->alternateAddresses= array_remove_entries ($addresses,$this->alternateAddresses);
611 $this->is_modified= TRUE;
612 }else{
613 msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG);
614 }
615 }
618 /*! \brief Prepare importet vacation string. \
619 . Replace placeholder like %givenName a.s.o.
620 @param string Vacation string
621 @return string Completed vacation string
622 */
623 private function prepare_vacation_template($contents)
624 {
625 /* Replace attributes */
626 $attrs = array();
627 $obj = NULL;
628 if(isset($this->parent->by_object['user'])){
629 $attrs = $this->parent->by_object['user']->attributes;
630 $obj = $this->parent->by_object['user'];
631 }else{
632 $obj = new user($this->config,$this->dn);
633 $attrs = $obj->attributes;
634 }
635 if($obj){
637 /* Replace vacation start and end time */
638 if($this->enabledFeatures['vacationMessage']){
639 if(preg_match("/%start/",$contents)){
640 $contents = preg_replace("/%start/",$this->vacationStart,$contents);
641 }
642 if(preg_match("/%end/",$contents)){
643 $contents = preg_replace("/%end/",$this->vacationStop,$contents);
644 }
645 }else{
646 if(preg_match("/%start/",$contents)){
647 $contents = preg_replace("/%start/", _("unknown"),$contents);
648 }
649 if(preg_match("/%end/",$contents)){
650 $contents = preg_replace("/%end/", _("unknown"), $contents);
651 }
652 }
654 foreach ($attrs as $val){
656 // We can only replace strings here
657 if(!is_string($obj->$val)) continue;
659 if(preg_match("/dateOfBirth/",$val)){
660 if($obj->use_dob){
661 $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents);
662 }
663 }else {
664 $contents= preg_replace("/%$val/",
665 $obj->$val, $contents);
666 }
668 }
669 }
670 $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n ");
671 return($contents);
672 }
675 function remove_from_parent()
676 {
677 // Get rpc handle to remove the account
678 if($this->initially_was_account){
679 if($this->rpcExec('gwAcctDel', $this->uid) === NULL){
680 msg_dialog::display(_("Error"), _("Groupware account removal failed!"), ERROR_DIALOG);
681 }
682 }
683 }
686 function save()
687 {
688 // Get rpc handle to create or update the account
689 if(!$this->initially_was_account){
690 if($this->rpcExec('gwAcctAdd', $this->uid, $this->mailAddress) === NULL){
691 msg_dialog::display(_("Error"), _("Groupware account creation failed!"), ERROR_DIALOG);
692 }
693 }
695 /*
696 * Trying to save the primary Email Address.
697 */
698 if(!empty($this->mailAddress)){
699 $this->groupwareDao->save("primaryMail", array($this->uid, $this->mailAddress));
700 }
702 }
705 /*! \brief Check given values
706 */
707 function check()
708 {
709 /*
710 * TODO: Remove all echo Messages
711 */
712 $messages = plugin::check();
713 /*
714 * Check the dates
715 */
717 /*
718 * TODO: check only if features are enabled.
719 */
720 //required vacationEnabled
721 if($this->vacationEnabled){
722 if(!tests::is_date($this->vacationStart)){
723 $messages[] = msgPool::invalid(_("vacationstart"),$this->vacationStart , "", _("Example of date : 01.03.2010"));
724 }
725 if(!tests::is_date($this->vacationStop)){
726 $messages[] = msgPool::invalid(_("vacationstop"),$this->vacationStop , "", _("Example of date : 01.03.2010"));
727 }
728 $diff = tests::compareDate($this->vacationStart, $this->vacationStop);
730 if($diff>=0){
731 $messages[] = msgPool::invalid(_("vacation dates"), $this->vacationStart." - ".$this->vacationStop, "", _("Enddate before Start or the same."));
732 }
733 }
734 if(!tests::is_email ($this->mailAddress)){
735 $messages[] = msgPool::invalid(_("Email"),$this->mailAddress , "", _("Example: user@excom.intranet.gonicus.de"));
736 }
737 /*
738 * forwarding Addresses
739 * $alternateAddresses
740 * $forwardingAddresses
741 */
742 if(isset($this->forwardingAddresses) && is_array($this->forwardingAddresses)){
743 foreach($this->forwardingAddresses as $fAddress){
744 if(!tests::is_email ($fAddress)){
745 $messages[] = msgPool::invalid(_("Email"),$fAddress, "", _("Example: user@excom.intranet.gonicus.de"));
746 }
747 }
748 }
749 if(isset($this->alternateAddresses) && is_array($this->alternateAddresses)){
750 foreach($this->alternateAddresses as $fAddress){
751 if(!tests::is_email ($fAddress)){
752 $messages[] = msgPool::invalid(_("Email"),$fAddress, "", _("Example: user@excom.intranet.gonicus.de"));
753 }
754 }
755 }
757 return($messages);
758 }
760 /*! \brief Adapt from template, using 'dn'
761 */
762 function adapt_from_template($dn, $skip= array())
763 {
764 plugin::adapt_from_template($dn, $skip);
766 }
768 /*! \brief ACL settings
769 */
770 static function plInfo()
771 {
772 return (array(
773 "plShortName" => _("Groupware"),
774 "plDescription" => _("Groupware settings"),
775 "plSelfModify" => TRUE,
776 "plDepends" => array("user"), // This plugin depends on
777 "plPriority" => 4, // Position in tabs
778 "plSection" => array("personal" => _("My account")),
779 "plCategory" => array("users"),
780 "plOptions" => array(),
781 "plProvidedAcls" => array(
782 "mailAddress" => _("Mail address"),
783 "mailLocation" => _("Mail location"),
784 "quotaUsage" => _("Quota usage"),
785 "mailFilter" => _("Mail filter"),
786 "quotaSize" => _("Quota size"),
787 "alternateAddresses" => _("Alternate mail addresses"),
788 "forwardingAddresses" => _("Forwarding mail addresses"),
789 "vacationEnabled" => _("Vaction switch"),
790 "vacationStart" => _("Vacation start time"),
791 "vacationStop" => _("Vacation stop time"),
792 "vacationMessage" => _("Vacation message"),
793 "mailBoxWarnLimit" => _("Warn sizelimit"),
794 "mailBoxSendSizelimit" => _("Send sizelimit"),
795 "mailBoxHardSizelimit" => _("Hard sizelimit"),
796 "mailBoxAutomaticRemoval" => _("Automatic mail removal"),
797 "localDeliveryOnly" => _("Local delivery only"),
798 "dropOwnMails" => _("Drop own mails")
799 )
800 ));
801 }
802 function mapComprehensiveUserData($callBackMap){
803 $this->mailAddressSelectDialog = $callBackMap["mailAddressSelectDialog"];
804 $this->filterManager = $callBackMap["filterManager"];
805 $this->filterRules = $callBackMap["filterRules"];
806 $this->vacationTemplates = $callBackMap["vacationTemplates"];
808 $this->mailAddress = $callBackMap["primaryMail"];
809 $this->mailLocation = $callBackMap["mailLocation"];
810 $this->quotaUsage = $callBackMap["quotaUsage"];
811 $this->quotaSize = $callBackMap["quotaSize"];
812 $this->alternateAddresses = $callBackMap["alternateAddresses"];
813 $this->forwardingAddresses = $callBackMap["forwardingAddresses"];
814 $this->vacationEnabled = $callBackMap["vacationEnabled"];
815 $this->vacationStart = $callBackMap["vacationStart"];
816 $this->vacationStop = $callBackMap["vacationStop"];
817 $this->vacationMessage = $callBackMap["vacationMessage"];
818 $this->mailBoxWarnLimitEnabled = $callBackMap["mailBoxWarnLimitEnabled"];
819 $this->mailBoxWarnLimitValue = $callBackMap["mailBoxWarnLimitValue"];
820 $this->mailBoxSendSizelimitEnabled = $callBackMap["mailBoxSendSizelimitEnabled"];
821 $this->mailBoxSendSizelimitValue = $callBackMap["mailBoxSendSizelimitValue"];
822 $this->mailBoxHardSizelimitEnabled = $callBackMap["mailBoxHardSizelimitEnabled"];
823 $this->mailBoxHardSizelimitValue = $callBackMap["mailBoxHardSizelimitValue"];
824 $this->mailBoxAutomaticRemovalEnabled = $callBackMap["mailBoxAutomaticRemovalEnabled"];
825 $this->mailBoxAutomaticRemovalValue = $callBackMap["mailBoxAutomaticRemovalValue"];
826 $this->localDeliveryOnly = $callBackMap["localDeliveryOnly"];
827 $this->dropOwnMails = $callBackMap["dropOwnMails"];
829 }
830 }
832 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
833 /*
834 * Data Access Object for groupwares
835 */
836 class groupware_dao{
837 /*
838 * TODO: Remove the debug
839 */
840 private $debug = false;
841 /*
842 * TODO: fill the following vars on init.
843 */
844 private $availableMethods;
845 private $availableProperties;
846 private $accountLocations;
848 private static $gwFeatures = array(
849 "primaryMail" => array( "get"=>"gwAcctGetPrimaryMailAddress",
850 "save"=>"gwAcctSetPrimaryMailAddress"),
851 "quotaSize" =>array( "get"=>"gwAcctGetQuota",
852 "save"=>"gwAcctSetQuota",
853 "delete"=>"gwAcctSetQuota"),
854 "mailFilter" =>array( "get"=>"gwAcctGetFilters",
855 "save"=>"gwAcctSetFilters",
856 "delete"=>"gwAcctDelFilter"),
857 "alternateAddresses" =>array( "get"=>"gwAcctGetAlternateMailAddresses",
858 "save"=>"gwAcctSetAlternateMailAddresses",
859 "delete"=>"gwAcctDelAlternateMailAddress"),
860 "forwardingAddresses" =>array( "get"=>"gwAcctGetMailForwardAddresses",
861 "save"=>"gwAcctSetMailForwardAddresses",
862 "delete"=>"gwAcctDelMailForwardAddress"),
863 "vacationMessage" =>array( "get"=>"gwAcctGetOutOfOfficeReply",
864 "save"=>"gwAcctSetOutOfOfficeReply",
865 "delete"=>"gwAcctDelOutOfOfficeReply"),
866 "mailBoxWarnLimit" =>array( "get"=>"",
867 "save"=>"",
868 "delete"=>""),
869 "mailBoxSendSizelimit" =>array( "get"=>"gwAcctGetQuota",
870 "save"=>"gwAcctSetQuota",
871 "delete"=>"gwAcctDelQuota"),
872 "mailBoxHardSizelimit" =>array( "get"=>"gwAcctGetMailLimit",
873 "save"=>"gwAcctSetMailLimit",
874 "delete"=>"gwAcctDelMailLimit"),
875 "mailBoxAutomaticRemoval" =>array( "get"=>"",
876 "save"=>"",
877 "delete"=>""),
878 "localDeliveryOnly" =>array( "get"=>"",
879 "save"=>"",
880 "delete"=>""),
881 "dropOwnMails" =>array( "get"=>"",
882 "save"=>"",
883 "delete"=>""),
884 "accountProperties" => array("get"=>"gwAcctGetProperties",
885 "save"=>"gwAcctSetProperties",
886 "delete"=>"gwAcctDelProperties")
888 );
890 private $groupwarePluginRef = False;
891 function __construct(&$pluginRef)
892 {
894 $this->groupwarePluginRef = &$pluginRef;
896 /*
897 * TODO:
898 * Remove all echos
899 */
901 $this->init();
902 }
905 /*
906 * gets the capabilities of the server
907 * builds an array with availbale features and knows how to call get, save, delete functions of
908 * groupware rpc.
909 */
910 public function init()
911 {
913 $this->availableMethods = $this->groupwarePluginRef->rpcExec('gwGetCapabilities');
914 //$this->availableProperties = $this->groupwarePluginRef->rpcExec('gwGetSupportedProperties');
915 //$this->debug("availableProperties on init:", $this->availableProperties);
917 $this->accountLocations = $this->groupwarePluginRef->rpcExec('gwGetMailboxLocations');
918 $this->debug("gwGetMailboxLocations on init:", $this->accountLocations);
920 }
923 public function save($feature, $valueArray)
924 {
925 /*
926 * TODO:
927 * check if feature available
928 * save and return the result.
929 */
930 $function = groupware_dao::$gwFeatures[$feature]["save"];
931 if(is_array($valueArray)){
932 $valueArray = array_merge(array($function), $valueArray);
933 }
934 else{
935 $valueArray = array($function, $valueArray);
936 }
937 $this->debug("SAVING (feature, value)", $valueArray);
938 $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray);
940 return $result;
941 }
944 public function get($feature, $valueArray)
945 {
946 /*
947 * TODO:
948 * check if feture available ?
949 * get and return the result.
950 */
951 $function = groupware_dao::$gwFeatures[$feature]["get"];
952 if(is_array($valueArray)){
953 $valueArray = array_merge(array($function), $valueArray);
954 }
955 else{
956 $valueArray = array($function, $valueArray);
957 }
959 $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray);
961 return $result;
962 }
965 public function del($feature, $valueArray)
966 {
967 /*
968 * TODO:
969 * check if feture available
970 * del and return the result.
971 */
972 $function = groupware_dao::$gwFeatures[$feature]["delete"];
974 $valueArray = array_merge(array($function), $valueArray);
976 $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray);
978 return $result;
979 }
982 public function gwFeatureAvailable($methodName)
983 {
985 return $this->availableMethods[$methodName];
986 }
989 public function getMailboxLocations()
990 {
991 echo "acctGetMailboxLocations";
992 return $this->groupwarePluginRef->rpcExec("acctGetMailboxLocations");
993 }
996 public function getComprehensiverUser($uid)
997 {
998 //$hi = $this->groupwarePluginRef->rpcExec('gwGetCapabilities');
999 $resultArr = array();
1001 if($this->groupwarePluginRef->isFeatureEnabled("primaryMail")){
1003 $pMail = $this->get("primaryMail", array($uid));
1004 $resultArr["primaryMail"] = $pMail;
1005 }
1006 if($this->groupwarePluginRef->isFeatureEnabled("alternateAddresses")){
1008 $addresses = $this->get("alternateAddresses", array($uid));
1009 $resultArr["alternateAddresses"] = $addresses;
1010 }
1011 if($this->groupwarePluginRef->isFeatureEnabled("forwardingAddresses")){
1013 $addresses = $this->get("forwardingAddresses", array($uid));
1014 $resultArr["forwardingAddresses"] = $addresses;
1015 }
1016 /*
1017 * this function seems to be broken on the server.
1018 * addding dummy
1019 */
1020 if($this->groupwarePluginRef->isFeatureEnabled("vacationMessage")){
1022 //$vacMessage = $this->get("vacationMessage", array($uid));
1023 $resultArr["vacationMessage"] = "dummy Vacation message - (getOutOfOfficeReply currently throws errors )";
1024 }
1025 else{
1026 echo "vacationMessage not enabled.";
1027 }
1028 /*
1029 * this function seems to be broken on the server.
1030 * addding dummy
1031 */
1032 if($this->groupwarePluginRef->isFeatureEnabled("quotaSize")){
1034 //$quotMessage = $this->get("quotaSize", array($uid));
1036 $resultArr["quotaSize"] = 123456789;
1037 }
1038 else{
1039 echo "vacationMessage not enabled.";
1040 }
1042 $this->debug("getComprehensiverUser:", $resultArr);
1043 return $resultArr;
1044 }
1047 public function debug($name, $message)
1048 {
1049 if($this->debug){
1050 echo"<b>".$name."</b>";
1051 if(is_array($message)){
1052 echo "<pre>";
1053 print_r($message);
1054 echo "</pre>";
1055 }
1056 else{
1057 echo "$message";
1058 }
1059 }
1060 }
1061 }
1062 ?>