From 36a9d3d29966f16dda4527719f2374dd04e46096 Mon Sep 17 00:00:00 2001 From: hzerres Date: Thu, 16 Sep 2010 12:27:09 +0000 Subject: [PATCH] Changed class namens to Camel Case - one class per file git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19708 594d385d-05f5-0310-b6e9-bd551577e9d8 --- ...ilterEditor.inc => class_FilterEditor.inc} | 2 +- ...terManager.inc => class_FilterManager.inc} | 10 +- .../personal/groupware/class_Groupware.inc | 856 ++++++++++++++++++ .../personal/groupware/class_GroupwareDao.inc | 262 ++++++ 4 files changed, 1124 insertions(+), 6 deletions(-) rename gosa-plugins/groupware/personal/groupware/{class_filterEditor.inc => class_FilterEditor.inc} (99%) rename gosa-plugins/groupware/personal/groupware/{class_filterManager.inc => class_FilterManager.inc} (95%) create mode 100644 gosa-plugins/groupware/personal/groupware/class_Groupware.inc create mode 100644 gosa-plugins/groupware/personal/groupware/class_GroupwareDao.inc diff --git a/gosa-plugins/groupware/personal/groupware/class_filterEditor.inc b/gosa-plugins/groupware/personal/groupware/class_FilterEditor.inc similarity index 99% rename from gosa-plugins/groupware/personal/groupware/class_filterEditor.inc rename to gosa-plugins/groupware/personal/groupware/class_FilterEditor.inc index 82590dac9..9f39d6eff 100644 --- a/gosa-plugins/groupware/personal/groupware/class_filterEditor.inc +++ b/gosa-plugins/groupware/personal/groupware/class_FilterEditor.inc @@ -1,6 +1,6 @@ filterListing->setAcl($acl); // Display filter editor while a filter rule is edited - if($this->filterEditor instanceOf filterEditor){ + if($this->filterEditor instanceOf FilterEditor){ $this->filterEditor->save_object(); return($this->filterEditor->execute()); } @@ -87,7 +87,7 @@ class filterManager extends plugin{ $key = $this->filterListing->getKey($key); if(isset($this->filter[$key])){ $filter = $this->filter[$key]; - $this->filterEditor = new filterEditor($this->config,$this->parent, $filter); + $this->filterEditor = new FilterEditor($this->config,$this->parent, $filter); $this->currentFilter = $key; } } @@ -114,17 +114,17 @@ class filterManager extends plugin{ 'VALUE' => '') ) ); - $this->filterEditor = new filterEditor($this->config,$this->parent, $filter); + $this->filterEditor = new FilterEditor($this->config,$this->parent, $filter); } // Close filter editor - if(isset($_POST['filterEditor_cancel']) && $this->filterEditor instanceOf filterEditor){ + if(isset($_POST['filterEditor_cancel']) && $this->filterEditor instanceOf FilterEditor){ $this->currentFilter = NULL; $this->filterEditor = NULL; } // Save filter modifications and close the dialog - if(isset($_POST['filterEditor_ok']) && $this->filterEditor instanceOf filterEditor){ + if(isset($_POST['filterEditor_ok']) && $this->filterEditor instanceOf FilterEditor){ $this->filterEditor->save_object(); $msgs = $this->filterEditor->check(); if(count($msgs)){ diff --git a/gosa-plugins/groupware/personal/groupware/class_Groupware.inc b/gosa-plugins/groupware/personal/groupware/class_Groupware.inc new file mode 100644 index 000000000..4213744dd --- /dev/null +++ b/gosa-plugins/groupware/personal/groupware/class_Groupware.inc @@ -0,0 +1,856 @@ +parent->by_object['group']) && isset($this->parent->by_object['group']->$attr)){ + $this->$attr = &$this->parent->by_object['group']->$attr; + }elseif(isset($this->attrs[$attr])){ + $this->$attr = $this->attrs[$attr][0]; + } + } + // Initialize the plugin using rpc. + $this->init(); + } + + + /*! \brief Try to execute a function on the gosa backend using json-rpc. + * This method also takes care about errors and sets the required + * class members, such as rpcError and rpcErrorMessage. + * @param String function The name of the function to call. + * @param Mixed args[0-n] The parameter to use. + * @return Mixed The result of the function call on success else NULL. + */ + function rpcExec($function) + { + $params = func_get_args(); + unset($params[0]); + echo "------
Calling function:".$function." Params".var_dump($params)."
"; + + $rpc = $this->config->getRpcHandle(); + + $res = call_user_func_array(array($rpc,$function),array_values($params)); + $this->rpcError = !$rpc->success(); + if($this->rpcError){ + $this->rpcErrorMessage = $rpc->get_error(); + return(NULL); + } + return($res); + } + + + /*! \brief TODO: comment + */ + public function isFeatureEnabled($featureName) + { + if(isset($this->enabledFeatures[$featureName]) && $this->enabledFeatures[$featureName]){ + return TRUE; + } + return FALSE; + } + + + /*! \brief Try initialize the groupware account. + * This method fetches all required information to manage the + * account using the GOsa gui. + */ + function init() + { + // Detect feature availability and enable/disable services correspondingly. + $this->groupwareDao = new GroupwareDao($this); + + $features = array(); + //feature names with a list of groupware function that must be availabele + //these groupware functions are not the rpc functions, because they are asked from the groupware server + $featureReq = array( + "primaryMail" => array( + 'acctGetPrimaryMailAddress'), + "quotaUsage" => array( + 'acctGetQuota'), + "quotaSize" => array( + 'acctSetQuota','acctGetQuota'), + "mailLocations" => array( + 'getMailboxLocations'), + "mailFilter" => array("_off", + 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'), + "alternateAddresses" => array( + 'acctDelAlternateMailAddress','acctSetAlternateMailAddresses', + 'acctAddAlternateMailAddress','acctGetAlternateMailAddresses'), + "forwardingAddresses" => array( + 'acctAddMailForwardAddress','acctDelMailForwardAddress', + 'acctGetMailForwardAddresses','acctSetMailForwardAddresses'), + "vacationMessage" => array("_off", + 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'), + "mailBoxWarnLimit" => array( + 'acctSetQuota','acctGetQuota'), + "mailBoxSendSizelimit" => array( + 'acctSetQuota','acctGetQuota'), + "mailBoxHardSizelimit" => array( + 'acctSetQuota','acctGetQuota'), + "mailBoxAutomaticRemoval" => array("_off", + 'acctSetQuota','acctGetQuota'), + "localDeliveryOnly" => array( "_off", + 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters'), + "dropOwnMails" => array( "_off", + 'acctDelFilter','acctGetFilters','acctSetFilters','acctSetFilters')); + + // Check if all required methods cann be called! + foreach($featureReq as $name => $requires){ + $active = TRUE; + foreach($requires as $methodName){ + $active &= $this->groupwareDao->gwFeatureAvailable($methodName); + } + $this->enabledFeatures[$name] = $active; + } + // Get rpc handle to fetch account info and feature availability. + $status = $this->rpcExec('gwAcctExists', $this->uid); + if($status !== NULL){ + $response = $this->groupwareDao->getComprehensiverUser($this->uid); + + $this->mapComprehensiveUserData($response); + $this->initially_was_account = $this->is_account = $status; + + $this->accountInitialized = TRUE; + } + // Set vacation start/stop if not set alreasy + $this->vacationStart = time(); + $this->vacationStop = time() + (14 * 60*60*24); + + // Prepare vacation start/stop time to be initially valid. + $this->vacationStart= date('d.m.Y', $this->vacationStart); + $this->vacationStop= date('d.m.Y', $this->vacationStop); + } + + + /*! \brief Generates the HTML user interface for the groupware plugin + * and take of several ui actions like adding or removing + * forward addresses, filters and the account itself. + */ + function execute() + { + // Register plugin execution + $display = plugin::execute(); + + // Log plugin execution. + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","users/".get_class($this),$this->dn); + } + + // Check if we were able to initialize the account already. + if(!$this->accountInitialized){ + $this->init(); + if(!$this->accountInitialized){ + $smarty = get_smarty(); + $smarty->assign("initFailed", !$this->accountInitialized); + return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); + } + } + + // Check if we were able to initialize the account already. + if($this->rpcError){ + $smarty = get_smarty(); + $smarty->assign("initFailed", !$this->accountInitialized); + $smarty->assign("rpcError", $this->rpcError); + return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); + } + + /**************** + Filter editor + ****************/ + + if(isset($_POST['filterManager_cancel'])) $this->filterManager = NULL; + if(isset($_POST['filterManager_ok'])){ + $this->filterManager->save_object(); + $msgs = $this->filterManager->check(); + if(count($msgs)){ + msg_dialog::displayChecks($msgs); + }else{ + $this->filterRules = $this->filterManager->save(); + $this->filterManager = NULL; + } + } + if(isset($_POST['configureFilter'])){ + $this->filterManager = new FilterManager($this->config, $this,$this->filterRules); + $this->filterManager->acl_base = $this->acl_base; + $this->filterManager->acl_category = $this->acl_category; + } + $this->dialog = FALSE; + if($this->filterManager instanceOf FilterManager){ + $this->filterManager->save_object(); + $this->dialog = TRUE; + return($this->filterManager->execute()); + } + + /**************** + Account status + ****************/ + + if(isset($_POST['modify_state'])){ + if($this->is_account && $this->acl_is_removeable()){ + $this->is_account= FALSE; + }elseif(!$this->is_account && $this->acl_is_createable()){ + $this->is_account= TRUE; + } + } + if(!$this->multiple_support_active){ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + msgPool::noValidExtension(_("Mail")).""; + $display.= back_to_main(); + return ($display); + } + if ($this->parent !== NULL){ + if ($this->is_account){ + $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Mail")),msgPool::featuresEnabled(_("Mail"))); + } else { + $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Mail")),msgPool::featuresDisabled(_("Mail"))); + return ($display); + } + } + } + + /**************** + Forward addresses + ****************/ + + // Display dialog to select a local fowarder + if (isset($_POST['addLocalForwardingAddress'])){ + $this->mailAddressSelectDialog= new mailAddressSelect($this->config, get_userinfo()); + $this->dialog= TRUE; + } + + // Close dialogs, action was canceled + if (isset($_POST['mailAddressSelect_cancel'])){ + $this->mailAddressSelectDialog= FALSE; + $this->dialog= FALSE; + } + + // Append selected forwarding addresses now. + if (isset($_POST['mailAddressSelect_save']) && $this->mailAddressSelectDialog instanceOf mailAddressSelect){ + if($this->acl_is_writeable("forwardingAddresses")){ + $list = $this->mailAddressSelectDialog->save(); + foreach ($list as $entry){ + $val = $entry['mail'][0]; + if (!in_array ($val, $this->alternateAddresses) && $val != $this->mailAddress){ + $this->addForwarder($val); + $this->is_modified= TRUE; + } + } + $this->mailAddressSelectDialog= FALSE; + $this->dialog= FALSE; + } else { + msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG); + } + } + + // Display the address selection dialog. + if($this->mailAddressSelectDialog instanceOf mailAddressSelect){ + $used = array(); + $used['mail'] = array_values($this->alternateAddresses); + $used['mail'] = array_merge($used['mail'], array_values($this->forwardingAddresses)); + $used['mail'][] = $this->mailAddress; + + // Build up blocklist + session::set('filterBlacklist', $used); + return($this->mailAddressSelectDialog->execute()); + } + + // Add manually inserted forwarding address. + if (isset($_POST['addForwardingAddress'])){ + if ($_POST['forwardingAddressInput'] != ""){ + $address= get_post('forwardingAddressInput'); + $valid= FALSE; + if (!tests::is_email($address)){ + if (!tests::is_email($address, TRUE)){ + if ($this->is_template){ + $valid= TRUE; + } else { + msg_dialog::display(_("Error"), msgPool::invalid(_("Mail address"), + "","","your-address@your-domain.com"),ERROR_DIALOG); + } + } + } elseif ($address == $this->mailAddress || in_array($address, $this->alternateAddresses)) { + msg_dialog::display(_("Error"),_("Cannot add primary address to the list of forwarders!") , ERROR_DIALOG); + } else { + $valid= TRUE; + } + if ($valid){ + if($this->acl_is_writeable("forwardingAddresses")){ + $this->addForwarder ($address); + $this->is_modified= TRUE; + } + } + } + } + if (isset($_POST['deleteForwardingAddress'])){ + $this->delForwarder ($_POST['forwardingAddressList']); + } + + /**************** + Alternate addresses + ****************/ + // Add manually inserted alternate mail address. + if (isset($_POST['addAlternateAddress'])){ + $valid= FALSE; + if (!tests::is_email($_POST['alternateAddressInput'])){ + if ($this->is_template){ + if (!(tests::is_email($_POST['alternateAddressInput'], TRUE))){ + msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"), + "","","your-domain@your-domain.com"),ERROR_DIALOG); + } else { + $valid= TRUE; + } + } else { + msg_dialog::display(_("Error"),msgPool::invalid(_("Mail address"), + "","","your-domain@your-domain.com"),ERROR_DIALOG); + } + } else { + $valid= TRUE; + } + if ($valid && ($user= $this->addAlternate (get_post('alternateAddressInput'))) != ""){ + $ui= get_userinfo(); + $addon= ""; + if ($user[0] == "!") { + $addon= sprintf(_("Address is already in use by group '%s'."), mb_substr($user, 1)); + } else { + $addon= sprintf(_("Address is already in use by user '%s'."), $user); + } + msg_dialog::display(_("Error"), msgPool::duplicated(_("Mail address"))."

". + "$addon", ERROR_DIALOG); + } + } + + // Remove alternate mail address. + if (isset($_POST['deleteAlternateAddress']) && isset($_POST['alternateAddressList'])){ + $this->delAlternate ($_POST['alternateAddressList']); + } + + + /**************** + SMARTY- Assign smarty variables + ****************/ + + $smarty = get_smarty(); + foreach($this->attributes as $attr){ + + $smarty->assign($attr, $this->$attr); + } + + $plInfo = $this->plInfo(); + foreach($plInfo['plProvidedAcls'] as $acl => $name){ + $smarty->assign($acl."ACL", $this->getacl($acl)); + } + foreach($this->enabledFeatures as $feature => $state){ + $smarty->assign($feature."_isActive", $state); + } + + $smarty->assign("mailLocations", $this->mailLocations); + if (count($this->vacationTemplates)){ + $smarty->assign("displayTemplateSelector", "true"); + $smarty->assign("vacationTemplate", set_post($this->vacationTemplate)); + $smarty->assign("vacationTemplates", set_post($this->vacationTemplates)); + $smarty->assign("template", set_post(get_post('vacation_template'))); + } else { + $smarty->assign("displayTemplateSelector", "false"); + } + + $smarty->assign("initFailed", !$this->accountInitialized); + $smarty->assign("rpcError", $this->rpcError); + $smarty->assign("rpcErrorMessage", $this->rpcErrorMessage); + + return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__)))); + } + + + /*! \brief This method handles potential _POST and _GET values. + * It captures modifcations from the ui, like changing + * the mailAddress. + * This method respects the attribute permissions. + */ + function save_object() + { + if(isset($_POST['groupwarePluginPosted'])){ + + // We ran into a communication error with the backend. + // Try a simple communication operation with the backend + // again and let us see if it works. + if(isset($_POST['retry'])){ + $this->rpcExec('gwGetCapabilities'); + } + + // Get ui modifications and store them in the class. + $testAttrs = array("mailAddress","mailLocation","quotaUsage","quotaSize", + "alternateAddresses","forwardingAddresses","vacationEnabled","vacationStart", + "vacationStop","vacationMessage"); + foreach($testAttrs as $attr){ + if(isset($_POST[$attr]) && $this->acl_is_writeable($attr)){ + $this->$attr = get_post($attr); + } + } + + // Detect checkbox states + $checkAttrs = array("mailBoxWarnLimit","mailBoxSendSizelimit", + "mailBoxHardSizelimit","mailBoxAutomaticRemoval"); + foreach($checkAttrs as $boxname){ + if($this->acl_is_writeable($boxname)){ + $v = $boxname."Value"; + $e = $boxname."Enabled"; + $this->$e = isset($_POST[$e]); + if($this->$e){ + $this->$v = get_post($v); + } + } + } + + // Get posted flag changes + $flagAttrs = array("localDeliveryOnly","dropOwnMails"); + foreach($flagAttrs as $attr){ + $this->$attr = isset($_POST[$attr]); + } + } + } + + + /*! \brief Parse vacation templates and build up an array + * containing 'filename' => 'description'. + * Used to fill vacation dropdown box. + * @return Array All useable vacation templates. + */ + function get_vacation_templates() + { + $vct = array(); + if ($this->config->get_cfg_value("core","vacationTemplateDirectory") != ""){ + $dir= $this->config->get_cfg_value("core","vacationTemplateDirectory"); + if (is_dir($dir) && is_readable($dir)){ + $dh = opendir($dir); + while($file = readdir($dh)){ + $description= ""; + if (is_file($dir."/".$file)){ + $fh = fopen($dir."/".$file, "r"); + $line= fgets($fh, 256); + if (!preg_match('/^DESC:/', $line)){ + msg_dialog::display(_("Configuration error"), sprintf(_("No DESC tag in vacation template '%s'!"), $file), ERROR_DIALOG); + }else{ + $description= trim(preg_replace('/^DESC:\s*/', '', $line)); + } + fclose ($fh); + } + if ($description != ""){ + $vct["$dir/$file"]= $description; + } + } + closedir($dh); + } + } + return($vct); + } + + + /*! \brief Adds the given mail address to the list of mail forwarders + */ + function addForwarder($address) + { + if(empty($address)) return; + if($this->acl_is_writeable("forwardingAddresses")){ + $this->forwardingAddresses[]= $address; + $this->forwardingAddresses= array_unique ($this->forwardingAddresses); + sort ($this->forwardingAddresses); + reset ($this->forwardingAddresses); + $this->is_modified= TRUE; + }else{ + msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG); + } + } + + + /*! \brief Removes the given mail address from the list of mail forwarders + */ + function delForwarder($addresses) + { + if($this->acl_is_writeable("forwardingAddresses")){ + $this->forwardingAddresses= array_remove_entries ($addresses, $this->forwardingAddresses); + $this->is_modified= TRUE; + }else{ + msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG); + } + } + + + /*! \brief Add given mail address to the list of alternate adresses , + * check if this mal address is used, skip adding in this case + */ + function addAlternate($address) + { + if(empty($address)) return; + if($this->acl_is_writeable("alternateAddresses")){ + $ldap= $this->config->get_ldap_link(); + $address= strtolower($address); + + /* Is this address already assigned in LDAP? */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=$address)". + "(alias=$address)(gosaMailAlternateAddress=$address)))", array("uid", "cn")); + if ($ldap->count() > 0){ + $attrs= $ldap->fetch (); + if (!isset($attrs["uid"])) { + return ("!".$attrs["cn"][0]); + } + return ($attrs["uid"][0]); + } + if (!in_array($address, $this->alternateAddresses)){ + $this->alternateAddresses[]= $address; + $this->is_modified= TRUE; + } + sort ($this->alternateAddresses); + reset ($this->alternateAddresses); + return (""); + }else{ + msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG); + } + } + + + /*! \brief Removes the given mail address from the alternate addresses list + */ + function delAlternate($addresses) + { + if($this->acl_is_writeable("alternateAddresses")){ + $this->alternateAddresses= array_remove_entries ($addresses,$this->alternateAddresses); + $this->is_modified= TRUE; + }else{ + msg_dialog::display(_("Permission error"), _("You have no permission to modify these addresses!"), ERROR_DIALOG); + } + } + + + /*! \brief Prepare importet vacation string. \ + * Replace placeholder like %givenName a.s.o. + * @param string Vacation string + * @return string Completed vacation string + */ + private function prepare_vacation_template($contents) + { + /* Replace attributes */ + $attrs = array(); + $obj = NULL; + if(isset($this->parent->by_object['user'])){ + $attrs = $this->parent->by_object['user']->attributes; + $obj = $this->parent->by_object['user']; + }else{ + $obj = new user($this->config,$this->dn); + $attrs = $obj->attributes; + } + if($obj){ + + /* Replace vacation start and end time */ + if($this->enabledFeatures['vacationMessage']){ + if(preg_match("/%start/",$contents)){ + $contents = preg_replace("/%start/",$this->vacationStart,$contents); + } + if(preg_match("/%end/",$contents)){ + $contents = preg_replace("/%end/",$this->vacationStop,$contents); + } + }else{ + if(preg_match("/%start/",$contents)){ + $contents = preg_replace("/%start/", _("unknown"),$contents); + } + if(preg_match("/%end/",$contents)){ + $contents = preg_replace("/%end/", _("unknown"), $contents); + } + } + + foreach ($attrs as $val){ + + // We can only replace strings here + if(!is_string($obj->$val)) continue; + + if(preg_match("/dateOfBirth/",$val)){ + if($obj->use_dob){ + $contents= preg_replace("/%$val/",date("Y-d-m",$obj->dateOfBirth),$contents); + } + }else { + $contents= preg_replace("/%$val/", + $obj->$val, $contents); + } + + } + } + $contents = ltrim(preg_replace("/^DESC:.*$/m","",$contents),"\n "); + return($contents); + } + + + /*! \brief Remove the account form the groupware server completely. + */ + function remove_from_parent() + { + // Get rpc handle to remove the account + if($this->initially_was_account){ + if($this->rpcExec('gwAcctDel', $this->uid) === NULL){ + msg_dialog::display(_("Error"), _("Groupware account removal failed!"), ERROR_DIALOG); + } + } + } + + + /* \brief Persists the values of this plugin to the groupware server. + * Save method is called on "apply" and "ok" in the Gosa Frontend. + * All other actions will update values in the form or + * cancel and therefore discard the changes so far. + */ + function save() + { + // Get rpc handle to create or update the account + if(!$this->initially_was_account){ + if($this->rpcExec('gwAcctAdd', $this->uid, $this->mailAddress) === NULL){ + msg_dialog::display(_("Error"), _("Groupware account creation failed!"), ERROR_DIALOG); + } + } + + // Save the primary Email Address. + if(!empty($this->mailAddress)){ + $this->groupwareDao->save("primaryMail", $this->uid, $this->mailAddress); + } + + // Save alternateAddresses and forwarding. + + + if(!empty($this->forwardingAddresses) + && isset($this->alternateAddresses) + && is_array($this->alternateAddresses)){ + $this->groupwareDao->save("alternateAddresses", $this->uid, array($this->alternateAddresses)); + + } + if(!empty($this->forwardingAddresses) + && isset($this->forwardingAddresses) + && is_array($this->forwardingAddresses)){ + $this->groupwareDao->save("forwardingAddresses", $this->uid, array($this->forwardingAddresses)); + + } + // Save the quota + if(true){ + + $quota = array( "warn_limit" => $this->mailBoxWarnLimitValue, + "send_limit" => $this->mailBoxSendSizelimitValue, + "hard_limit" => $this->mailBoxHardSizelimitValue, + "hold" => $this->quotaSize, + "usage" => $this->quotaUsage); + $this->groupwareDao->save("quotaSize", $this->uid, $quota); + } + + // TODO: save Mailbox location + + } + + + /*! \brief Check given values + */ + function check() + { + // TODO: Remove all echo Messages + $messages = plugin::check(); + + //Check the dates + + // TODO: check only if features are enabled. + + //required vacationEnabled + if($this->vacationEnabled){ + if(!tests::is_date($this->vacationStart)){ + $messages[] = msgPool::invalid(_("Vacation start date"),$this->vacationStart , "", "01.03.2010"); + } + if(!tests::is_date($this->vacationStop)){ + $messages[] = msgPool::invalid(_("Vacation stop date"),$this->vacationStop , "", "01.03.2010"); + } + $diff = tests::compareDate($this->vacationStart, $this->vacationStop); + + if($diff>=0){ + $messages[] = msgPool::invalid(_("Vacation dates")); + } + } + if(!tests::is_email ($this->mailAddress)){ + $messages[] = msgPool::invalid(_("Mail address"),$this->mailAddress , "", "user@excom.intranet.gonicus.de"); + } + + if(isset($this->forwardingAddresses) && is_array($this->forwardingAddresses)){ + foreach($this->forwardingAddresses as $fAddress){ + if(!tests::is_email ($fAddress)){ + $messages[] = msgPool::invalid(_("Alternate address"),$fAddress, "", + "user@excom.intranet.gonicus.de"); + } + if($fAddress == $this->mailAddress){ + $messages[] = _("The primary address cannot be used as alternative address!"); + } + } + } + if(isset($this->alternateAddresses) && is_array($this->alternateAddresses)){ + foreach($this->alternateAddresses as $fAddress){ + if(!tests::is_email ($fAddress)){ + $messages[] = msgPool::invalid(_("Forward address"),$fAddress, "", "user@excom.intranet.gonicus.de"); + } + if($fAddress == $this->mailAddress){ + $messages[] = _("The primary address cannot be used as forward address!"); + } + } + } + + // TODO: Checks for quota and Locations? + return($messages); + } + + + /*! \brief ACL settings + */ + static function plInfo() + { + return (array( + "plShortName" => _("Groupware"), + "plDescription" => _("Groupware settings"), + "plSelfModify" => TRUE, + "plDepends" => array("user"), // This plugin depends on + "plPriority" => 4, // Position in tabs + "plSection" => array("personal" => _("My account")), + "plCategory" => array("users"), + "plOptions" => array(), + "plProvidedAcls" => array( + "mailAddress" => _("Mail address"), + "mailLocation" => _("Mail location"), + "quotaUsage" => _("Quota usage"), + "mailFilter" => _("Mail filter"), + "quotaSize" => _("Quota size"), + "alternateAddresses" => _("Alternate mail addresses"), + "forwardingAddresses" => _("Forwarding mail addresses"), + "vacationEnabled" => _("Vaction switch"), + "vacationStart" => _("Vacation start time"), + "vacationStop" => _("Vacation stop time"), + "vacationMessage" => _("Vacation message"), + "mailBoxWarnLimit" => _("Warn sizelimit"), + "mailBoxSendSizelimit" => _("Send sizelimit"), + "mailBoxHardSizelimit" => _("Hard sizelimit"), + "mailBoxAutomaticRemoval" => _("Automatic mail removal"), + "localDeliveryOnly" => _("Local delivery only"), + "dropOwnMails" => _("Drop own mails") + ) + )); + } + + + /*! \brief Maps the resultset fetched from the Dao to the class variables + * of the plugin. + */ + function mapComprehensiveUserData($callBackMap) + { + $map = array( + "mailLocations" => "mailLocations", + "mailAddress" => "primaryMail", + "mailLocation" => "mailLocation", + "quotaUsage" => "quotaUsage", + "quotaSize" => "quotaSize", + "alternateAddresses" => "alternateAddresses", + "forwardingAddresses" => "forwardingAddresses", + "vacationEnabled" => "vacationEnabled", + "vacationStart" => "vacationStart", + "vacationStop" => "vacationStop", + "vacationMessage" => "vacationMessage", + "mailBoxWarnLimitEnabled" => "mailBoxWarnLimitEnabled", + "mailBoxWarnLimitValue" => "mailBoxWarnLimitValue", + "mailBoxSendSizelimitEnabled" => "mailBoxSendSizelimitEnabled", + "mailBoxSendSizelimitValue" => "mailBoxSendSizelimitValue", + "mailBoxHardSizelimitEnabled" => "mailBoxHardSizelimitEnabled", + "mailBoxHardSizelimitValue" => "mailBoxHardSizelimitValue", + "mailBoxAutomaticRemovalEnabled" => "mailBoxAutomaticRemovalEnabled", + "mailBoxAutomaticRemovalValue" => "mailBoxAutomaticRemovalValue", + "localDeliveryOnly" => "localDeliveryOnly", + "dropOwnMails" => "dropOwnMails"); + + // Map values from source array to class members + foreach($map as $target => $source){ + if(isset($callBackMap[$source])){ + $this->$target = $callBackMap[$source]; + } + } + } +} + + +?> diff --git a/gosa-plugins/groupware/personal/groupware/class_GroupwareDao.inc b/gosa-plugins/groupware/personal/groupware/class_GroupwareDao.inc new file mode 100644 index 000000000..adade44ab --- /dev/null +++ b/gosa-plugins/groupware/personal/groupware/class_GroupwareDao.inc @@ -0,0 +1,262 @@ + array( "get"=>"gwAcctGetPrimaryMailAddress", + "save"=>"gwAcctSetPrimaryMailAddress"), + "mailLocations" => array("get"=>"gwGetMailboxLocations"), + "quotaSize" =>array( "get"=>"gwAcctGetQuota", + "save"=>"gwAcctSetQuota", + "delete"=>"gwAcctSetQuota"), + "mailFilter" =>array( "get"=>"gwAcctGetFilters", + "save"=>"gwAcctSetFilters", + "delete"=>"gwAcctDelFilter"), + "alternateAddresses" =>array( "get"=>"gwAcctGetAlternateMailAddresses", + "save"=>"gwAcctSetAlternateMailAddresses", + "delete"=>"gwAcctDelAlternateMailAddress"), + "forwardingAddresses" =>array( "get"=>"gwAcctGetMailForwardAddresses", + "save"=>"gwAcctSetMailForwardAddresses", + "delete"=>"gwAcctDelMailForwardAddress"), + "vacationMessage" =>array( "get"=>"gwAcctGetOutOfOfficeReply", + "save"=>"gwAcctSetOutOfOfficeReply", + "delete"=>"gwAcctDelOutOfOfficeReply"), + "mailBoxWarnLimit" =>array( "get"=>"", + "save"=>"", + "delete"=>""), + "mailBoxSendSizelimit" =>array( "get"=>"gwAcctGetQuota", + "save"=>"gwAcctSetQuota", + "delete"=>"gwAcctDelQuota"), + "mailBoxHardSizelimit" =>array( "get"=>"gwAcctGetMailLimit", + "save"=>"gwAcctSetMailLimit", + "delete"=>"gwAcctDelMailLimit"), + "mailBoxAutomaticRemoval" =>array( "get"=>"", + "save"=>"", + "delete"=>""), + "localDeliveryOnly" =>array( "get"=>"", + "save"=>"", + "delete"=>""), + "dropOwnMails" =>array( "get"=>"", + "save"=>"", + "delete"=>""), + "accountProperties" => array("get"=>"gwAcctGetProperties", + "save"=>"gwAcctSetProperties", + "delete"=>"gwAcctDelProperties") + + ); + + + /*! \brief Constructor sets the connection to the rpc service + * initializes the class + */ + function __construct(&$pluginRef) + { + $this->groupwarePluginRef = &$pluginRef; + + // TODO: Remove all echos + + $this->init(); + } + + + /*! \brief Gets the capabilities of the server + * builds an array with availbale features and knows how to call get, save, delete functions of + * groupware rpc. + */ + public function init() + { + $this->availableMethods = $this->groupwarePluginRef->rpcExec('gwGetCapabilities'); + //$this->availableProperties = $this->groupwarePluginRef->rpcExec('gwGetSupportedProperties'); + //$this->debug("availableProperties on init:", $this->availableProperties); + } + + + /*! \brief Generic saving method for all features defined in $gwFeatures + * which are the available features. + */ + public function save($feature, $uid, $valueArray) + { + $function = GroupwareDao::$gwFeatures[$feature]["save"]; + if(is_array($valueArray)){ + $valueArray = array_merge(array($function, $uid), $valueArray); + }else{ + $valueArray = array($function, $uid, $valueArray); + } + $this->debug("SAVING (feature, value)", $valueArray); + $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray); + return $result; + } + + + /*! \brief generic get method for all features defined in $gwFeatures + * which are the available features. + */ + public function get($feature, $valueArray) + { + // TODO: Check if feture available ? get and return the result. + $function = GroupwareDao::$gwFeatures[$feature]["get"]; + if(is_array($valueArray)){ + $valueArray = array_merge(array($function), $valueArray); + }else{ + $valueArray = array($function, $valueArray); + } + + $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray); + return $result; + } + + + /*! \brief generic delete function for all features defined in $gwFeatures + * which are the available features. + * + * NOT YET IMPLEMENTED + */ + public function del($feature, $valueArray) + { + // TODO: check if feture available del and return the result. + + echo "deletion of values is not implemented yet"; + /* + $function = GroupwareDao::$gwFeatures[$feature]["delete"]; + $valueArray = array_merge(array($function), $valueArray); + $result = call_user_func_array(array($this->groupwarePluginRef, 'rpcExec'), $valueArray); + return $result; + */ + } + + + /*! \brief determine availability of features. + * + * @param methodName + * @return boolean + */ + public function gwFeatureAvailable($methodName) + { + return(isset($this->availableMethods[$methodName]) && ($this->availableMethods[$methodName])); + } + + + /*! \brief comprehensive user info will dessolve into one groupware call later + * right now it will get all data of the features that are available in the plugin. + * @param int $uid + * @return assoc array "feature" => "gwValue"; + */ + public function getComprehensiverUser( $uid) + { + //$hi = $this->groupwarePluginRef->rpcExec('gwGetCapabilities'); + $resultArr = array(); + + if($this->groupwarePluginRef->isFeatureEnabled("primaryMail")){ + $resultArr["primaryMail"] = $this->get("primaryMail", array($uid)); + } + + if($this->groupwarePluginRef->isFeatureEnabled("alternateAddresses")){ + $resultArr["alternateAddresses"] = $this->get("alternateAddresses", array($uid)); + } + + if($this->groupwarePluginRef->isFeatureEnabled("forwardingAddresses")){ + $resultArr["forwardingAddresses"] = $this->get("forwardingAddresses", array($uid)); + } + + if($this->groupwarePluginRef->isFeatureEnabled("forwardingAddresses")){ + $resultArr["forwardingAddresses"] = $this->get("forwardingAddresses", array($uid)); + } + + // Location dropdownlist - only readable + if($this->groupwarePluginRef->isFeatureEnabled("mailLocations")){ + $resultArr["mailLocations"] = $this->groupwarePluginRef->rpcExec('gwGetMailboxLocations'); + $resultArr["mailLocation"] = $this->groupwarePluginRef->rpcExec('gwAcctGetLocation',$uid); + } + + + //TODO: getLocation muss ebenfalls geholt werden + + // Quota quotaUsage, quotaSize + if($this->groupwarePluginRef->isFeatureEnabled("quotaSize") || + $this->groupwarePluginRef->isFeatureEnabled("quotaUsage") || + $this->groupwarePluginRef->isFeatureEnabled("mailBoxWarnLimit") || + $this->groupwarePluginRef->isFeatureEnabled("mailBoxSendSizelimit") || + $this->groupwarePluginRef->isFeatureEnabled("mailBoxHardSizelimit")){ + + // Usage is a Mapi function which is not yet + + // TODO: Remove the following dummy and enable the qota fetch from groupware + + echo "Quota function not yet implemented on server side!!"; + //$quota = $this->get("quotaSize", array($uid)); + $quota = array( "warn_limit" => 1008, + "send_limit" => 108, + "hard_limit" => 1108, + "hold" => 508, + "usage" => 1108); + $resultArr["quotaSize"] = $quota["usage"]; + $resultArr["quotaSize"] = $quota["hold"]; + if($quota["warn_limit"] > 0){ + $resultArr["mailBoxWarnLimitEnabled"] = true; + $resultArr["mailBoxWarnLimitValue"] = $quota["warn_limit"]; + }else{ + $resultArr["mailBoxWarnLimitEnabled"] = false; + $resultArr["mailBoxWarnLimitValue"] = 0; + } + if($quota["send_limit"] > 0){ + $resultArr["mailBoxSendSizelimitEnabled"] = True; + $resultArr["mailBoxSendSizelimitValue"] = $quota["send_limit"]; + }else{ + $resultArr["mailBoxSendSizelimitEnabled"] = FALSE; + $resultArr["mailBoxSendSizelimitValue"] = 0; + } + if($quota["hard_limit"] > 0){ + $resultArr["mailBoxHardSizelimitEnabled"] = True; + $resultArr["mailBoxHardSizelimitValue"] = $quota["hard_limit"]; + }else{ + $resultArr["mailBoxHardSizelimitEnabled"] = FALSE; + $resultArr["mailBoxHardSizelimitValue"] = 0; + } + } + + //this function seems to be broken on the server. + //addding dummy + + if($this->groupwarePluginRef->isFeatureEnabled("vacationMessage")){ + + $vacMessage = $this->get("vacationMessage", array($uid)); + //$resultArr["vacationMessage"] = "dummy Vacation message - (getOutOfOfficeReply currently throws errors )"; + } + + $this->debug("getComprehensiverUser:", $resultArr); + return $resultArr; + } + + + /*! \brief TODO: remove all debug functions. Remove them also in the class_Groupware.inc + */ + public function debug($name, $message) + { + if($this->debug){ + echo"".$name.""; + if(is_array($message)){ + echo "
";
+                print_r($message);
+                echo "
"; + }else{ + echo "$message"; + } + } + } +} +?> \ No newline at end of file -- 2.30.2