diff options
Diffstat (limited to 'apps/admin/modules/address')
-rw-r--r-- | apps/admin/modules/address/actions/actions.class.php | 165 | ||||
-rw-r--r-- | apps/admin/modules/address/config/generator.yml | 48 | ||||
-rw-r--r-- | apps/admin/modules/address/templates/_alias.php | 9 | ||||
-rw-r--r-- | apps/admin/modules/address/templates/_destination.php | 23 | ||||
-rw-r--r-- | apps/admin/modules/address/templates/_domain_id.php | 1 | ||||
-rw-r--r-- | apps/admin/modules/address/templates/_localpart.php | 1 | ||||
-rw-r--r-- | apps/admin/modules/address/templates/_mailbox_id.php | 1 | ||||
-rw-r--r-- | apps/admin/modules/address/validate/create.yml | 10 | ||||
-rw-r--r-- | apps/admin/modules/address/validate/edit.yml | 10 |
9 files changed, 268 insertions, 0 deletions
diff --git a/apps/admin/modules/address/actions/actions.class.php b/apps/admin/modules/address/actions/actions.class.php new file mode 100644 index 0000000..d042fbf --- /dev/null +++ b/apps/admin/modules/address/actions/actions.class.php @@ -0,0 +1,165 @@ +<?php + +/** + * address actions. + * + * @package mailadmin + * @subpackage address + * @author Your name here + * @version SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $ + */ +class addressActions extends autoaddressActions +{ + public function executeList() + { + // pageination + if($this->hasRequestParameter("max_per_page")) + $this->getUser()->setResultsPerPage($this->getRequestParameter("max_per_page")); + + return parent::executeList(); + } + + public function executeCreate() + { + $this->setTemplate("edit"); + $result = $this->executeEdit(); + + if($this->getRequest()->getMethod() == sfRequest::GET) + { + if(!$this->hasRequestParameter("id")) + { + $this->updateAddressFromRequest(); + } + $this->address->setActive(true); + $this->address->setSaveInMailbox(true); + } + + return $result; + } + + public function handleErrorCreate() + { + $this->setTemplate("edit"); + return $this->handleErrorEdit(); + } + + public function validateCreate() + { + return $this->validateEdit(); + } + + public function validateEdit() + { + $i18n = sfI18N::getInstance(); + + if($this->getRequest()->getMethod() == sfRequest::GET) + return true; + + $newaddress = $this->getRequestParameter('address'); + if($newaddress["domain_id"]=='') + { + $this->getRequest()->setError('address{alias}', 'A domain must be selected'); + return false; + } + + $address = new Address(); + + if($this->getRequest()->hasParameter('id')) + $address = AddressPeer::retrieveByPk($this->getRequestParameter('id')); + + // if we got different values than the current record already has + if($this->getActionName()=="create" || + $address->getLocalpart() != $newaddress["localpart"] || + $address->getDomainId() != $newaddress["domain_id"] + ) + { + // check if localpart@domain is already used + $c = new Criteria(); + $c->add(AddressPeer::LOCALPART, $newaddress["localpart"]); + $c->add(AddressPeer::DOMAIN_ID, $newaddress["domain_id"]); + $checkaddress = AddressPeer::doSelectOne($c); + if($checkaddress) + { + $this->getRequest()->setError('address{alias}', $i18n->__('The address "%1%" already exists', array("%1%"=>$checkaddress))); + return false; + } + } + + // check if either save to mailbox option or destination is set to satisfy message routing + if(!isset($newaddress["save_in_mailbox"]) && $newaddress["destination"]=='') + { + $this->getRequest()->setError('address{save_in_mailbox}', 'If messages are not saved in the mailbox, the forward destination has to be set'); + $this->getRequest()->setError('address{destination}', 'Destination can not be empty if the message is not saved in the mailbox'); + return false; + + } + + // verify destination list + $ev = new sfEmailValidator(); + $destinations = Address::getDestinationAsArray($newaddress["destination"]); + foreach($destinations as $dest) + { + if($dest=='') + continue; + + // check email + if(strpos($dest, "@") !== false) + { + $error = ''; + $ev->initialize($this->getContext(), array( + 'email_error' => $i18n->__('Invalid E-Mail address "%1%"', array("%1%" => $dest)) + )); + + if(!$ev->execute($dest, $error)) + { + $this->getRequest()->setError('address{destination}', $error); + return false; + } + } + else // check if mailbox name is valid + { + // superadmin has all freedom + if($this->getUser()->hasCredential("superadmin")) + continue; + + $c = new Criteria(); + $c->add(MailboxPeer::NAME, $dest); + $mailbox = MailboxPeer::doSelectOne($c); + if(!$mailbox) + { + // no such target + $this->getRequest()->setError('address{destination}', $i18n->__('Mailbox "%1%" does not exist', array("%1%" => $dest))); + return false; + } + + // check permissions + $c = new Criteria(); + $c->add(DomainPermissionPeer::DOMAIN_ID, $mailbox->getDomainId()); + $permissions = $this->getUser()->getDomainPermissions($c); + if(!$permissions) + { + $this->getRequest()->setError('address{destination}', $i18n->__('No permissions to use Mailbox "%1%" as destination', array("%1%" => $dest))); + return false; + } + } + } + + return true; + } + + protected function updateAddressFromRequest() + { + $address = $this->getRequestParameter('address'); + + if (isset($address['localpart'])) + { + $this->address->setLocalpart($address['localpart']); + } + if (isset($address['domain_id'])) + { + $this->address->setDomainId($address['domain_id']); + } + + return parent::updateAddressFromRequest(); + } +} diff --git a/apps/admin/modules/address/config/generator.yml b/apps/admin/modules/address/config/generator.yml new file mode 100644 index 0000000..2bd2e44 --- /dev/null +++ b/apps/admin/modules/address/config/generator.yml @@ -0,0 +1,48 @@ +generator: + class: sfPropelAdminGenerator + param: + model_class: Address + theme: mailadmin + + fields: + destination: { name: Destination } + mailbox_id: { name: Mailbox } + active: { name: Active } + + list: + peer_method: doSelectJoinAll + title: List of Addresses + display: [=_localpart, _domain_id, _destination, active, _mailbox_id] + filters: [alias, domain_id, active, mailbox_id, destination] + max_per_page: '$this->getUser()->getResultsPerPage("pager")' + sort: [mailbox_id, asc] + fields: + localpart: { name: Address, params: align=right } + domain_id: { params: align=left } + alias: { params: align=left } + destination: { params: align=left } + active: { params: align=center width=1% } + mailbox_id: { params: align=right } + object_actions: + edit: { name: Edit Address, action: edit, icon: edit.gif } + delete: { name: Delete Address, action: delete, icon: trash.gif, params: confirm=Are you sure? } + actions: {} + + create: + title: Create New Address + + edit: + title: 'Editing Address %%alias%%' + display: + 'Address': [_alias, active, mailbox_id] + 'Destination': [save_in_mailbox, destination] + fields: + mailbox_id: { name: For Mailbox, help: 'The primary mailbox for this address' } + alias: { name: Address, help: 'Leave blank if this is a catch all address' } + save_in_mailbox: { name: Save to Mailbox, type: checkbox_tag, help: 'Incoming messages are saved, then forwarded' } + destination: { name: Forward to these Destinations, params: size=51x8, help: 'E-Mail addresses and/or mailbox names, one per line or comma-seperated' } + active: { name: Active, help: Inactive addresses are not routed } + actions: + _save_and_list: { name: Save } + _save_and_add: { name: 'Save, then create new one' } + _list: { name: Cancel } diff --git a/apps/admin/modules/address/templates/_alias.php b/apps/admin/modules/address/templates/_alias.php new file mode 100644 index 0000000..e6550c1 --- /dev/null +++ b/apps/admin/modules/address/templates/_alias.php @@ -0,0 +1,9 @@ +<?php use_helper("Object") ?><?php $value = object_input_tag($address, 'getLocalpart', array ( + 'size' => 25, + 'control_name' => 'address[localpart]', + 'style' => 'text-align:right', +)); echo $value ? $value : ' ' ?> @ <?php $value = object_select_tag($address, 'getDomainId', array ( + 'related_class' => 'Domain', + 'control_name' => 'address[domain_id]', + 'include_blank' => true, +)); echo $value ? $value : ' ' ?> diff --git a/apps/admin/modules/address/templates/_destination.php b/apps/admin/modules/address/templates/_destination.php new file mode 100644 index 0000000..f01676c --- /dev/null +++ b/apps/admin/modules/address/templates/_destination.php @@ -0,0 +1,23 @@ +<?php use_helper('I18N','Javascript'); ?> +<?php $list = Address::getDestinationAsArray($address->getDestination()); + if($address->getSaveInMailbox()) + $list = array_merge(array($address->getMailbox()->getName()), $list); +?> +<div class="slidelist"> +<?php if(count($list) > sfConfig::get('app_address_dest_collapse_count')): ?> + +<?php echo link_to_function(__("Multiple (%1% entries)", array('%1%' => count($list))), visual_effect( +'toggle_slide', 'addresslist_'.$address->getId())) ?> +<div id="addresslist_<?php echo $address->getId() ?>" style="display:none"> +<?php endif; ?> + +<ul> +<?php foreach($list as $destination): ?> +<li><?php echo ($destination==$address->getMailbox()->getName()? __("Mailbox"): $destination) ?></li> +<?php endforeach; ?> +</ul> + +<?php if(count($list) > 1): ?> +</div> +<?php endif; ?> +</div> diff --git a/apps/admin/modules/address/templates/_domain_id.php b/apps/admin/modules/address/templates/_domain_id.php new file mode 100644 index 0000000..bb51b3d --- /dev/null +++ b/apps/admin/modules/address/templates/_domain_id.php @@ -0,0 +1 @@ +@<?php echo $address->getDomain() ?> diff --git a/apps/admin/modules/address/templates/_localpart.php b/apps/admin/modules/address/templates/_localpart.php new file mode 100644 index 0000000..e01fe5d --- /dev/null +++ b/apps/admin/modules/address/templates/_localpart.php @@ -0,0 +1 @@ +<?php echo ($address->isCatchAll() ? "*": $address->getLocalpart() ) ?> diff --git a/apps/admin/modules/address/templates/_mailbox_id.php b/apps/admin/modules/address/templates/_mailbox_id.php new file mode 100644 index 0000000..0ab885b --- /dev/null +++ b/apps/admin/modules/address/templates/_mailbox_id.php @@ -0,0 +1 @@ +<?php echo $address->getMailbox() ?> diff --git a/apps/admin/modules/address/validate/create.yml b/apps/admin/modules/address/validate/create.yml new file mode 100644 index 0000000..a55efed --- /dev/null +++ b/apps/admin/modules/address/validate/create.yml @@ -0,0 +1,10 @@ +fillin: + enabled: true + +fields: + address{domain_id}: + required: + msg: A domain has to be selected + address{mailbox_id}: + required: + msg: A primary mailbox has to be selected diff --git a/apps/admin/modules/address/validate/edit.yml b/apps/admin/modules/address/validate/edit.yml new file mode 100644 index 0000000..a55efed --- /dev/null +++ b/apps/admin/modules/address/validate/edit.yml @@ -0,0 +1,10 @@ +fillin: + enabled: true + +fields: + address{domain_id}: + required: + msg: A domain has to be selected + address{mailbox_id}: + required: + msg: A primary mailbox has to be selected |