public function isValid($params)
 {
     $isValid = parent::isValid($params);
     if ($isValid == true && $this->isEmailAntispamEnabled()) {
         if (!empty($params[$this->_orgEmailFieldName])) {
             $isValid = false;
         } else {
             $emailElementName = $this->getEmailElementFieldName();
             $this->{$this->_orgEmailFieldName}->setValue($params[$emailElementName]);
         }
     }
     return $isValid;
 }
Exemple #2
0
 public function isValid($data)
 {
     $isValid = parent::isValid($data);
     if ($isValid) {
         if ($data['is_long'] !== '1') {
             if (trim($data['content']) == '') {
                 $this->addErrorMessage('The content is required. Please input this field.');
                 return;
             }
         }
     }
     return $isValid;
 }
Exemple #3
0
 public function isValid($data)
 {
     $result = parent::isValid($data);
     if ($result) {
         $users = $this->getElement('users')->getValue();
         $recipients = $this->getElement('recipients')->getValue();
         if (empty($users) && empty($recipients)) {
             $this->addError('You have not entered any users or emails to invite joining event !');
             $result = false;
         }
     }
     return $result;
 }
Exemple #4
0
 public function isValid($data)
 {
     $isValid = parent::isValid($data);
     if ($isValid) {
         if (array_key_exists('start_date', $data)) {
             $startDate = $data['start_date'];
         }
         if (array_key_exists('end_date', $data)) {
             $endDate = $data['end_date'];
         }
         if (!empty($startDate) && !empty($endDate)) {
             $startDate = strtotime($startDate);
             $endDate = strtotime($endDate);
             if ($startDate > $endDate) {
                 $isValid = false;
             }
         }
     }
     return $isValid;
 }
 public function widgetAction()
 {
     // Render by widget name
     $mod = $this->_getParam('mod');
     $name = $this->_getParam('name');
     if (null === $name) {
         throw new Exception('no widget found with name: ' . $name);
     }
     if (null !== $mod) {
         $name = $mod . '.' . $name;
     }
     $contentInfoRaw = $this->getContentAreas();
     $contentInfo = array();
     foreach ($contentInfoRaw as $info) {
         $contentInfo[$info['name']] = $info;
     }
     // It has a form specified in content manifest
     if (!empty($contentInfo[$name]['adminForm'])) {
         if (is_string($contentInfo[$name]['adminForm'])) {
             // Core_Form_Admin_Widget_*
             $formClass = $contentInfo[$name]['adminForm'];
             Engine_Loader::loadClass($formClass);
             $this->view->form = $form = new $formClass();
         } else {
             if (is_array($contentInfo[$name]['adminForm'])) {
                 $this->view->form = $form = new Engine_Form($contentInfo[$name]['adminForm']);
             } else {
                 throw new Core_Model_Exception('Unable to load admin form class');
             }
         }
         // Try to set title if missing
         if (!$form->getTitle()) {
             $form->setTitle('Editing: ' . $contentInfo[$name]['title']);
         }
         // Try to set description if missing
         if (!$form->getDescription()) {
             $form->setDescription('placeholder');
         }
         $form->setAttrib('class', 'global_form_popup ' . $form->getAttrib('class'));
         // Add title element
         if (!$form->getElement('title')) {
             $form->addElement('Text', 'title', array('label' => 'Title', 'order' => -100));
         }
         // Add mobile element?
         if (!$form->getElement('nomobile')) {
             $form->addElement('Select', 'nomobile', array('label' => 'Hide on mobile site?', 'order' => 100000 - 5, 'multiOptions' => array('1' => 'Yes, do not display on mobile site.', '0' => 'No, display on mobile site.'), 'value' => '0'));
         }
         if (!empty($contentInfo[$name]['isPaginated']) && !$form->getElement('itemCountPerPage')) {
             $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))), 'order' => 1000000 - 1));
         }
         // Add submit button
         if (!$form->getElement('submit') && !$form->getElement('execute')) {
             $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000000));
         }
         // Add name
         $form->addElement('Hidden', 'name', array('value' => $name, 'order' => 1000010));
         if (!$form->getElement('cancel')) {
             $form->addElement('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000001));
         }
         if (!$form->getDisplayGroup('buttons')) {
             $submitName = $form->getElement('execute') ? 'execute' : 'submit';
             $form->addDisplayGroup(array($submitName, 'cancel'), 'buttons', array('order' => 1000002));
         }
         // Force method and action
         $form->setMethod('post')->setAction($_SERVER['REQUEST_URI']);
         if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
             $this->view->values = $form->getValues();
             $this->view->form = null;
         }
         return;
     }
     // Try to render admin page
     if (!empty($contentInfo[$name])) {
         try {
             $structure = array('type' => 'widget', 'name' => $name, 'request' => $this->getRequest(), 'action' => 'admin', 'throwExceptions' => true);
             // Create element (with structure)
             $element = new Engine_Content_Element_Container(array('elements' => array($structure), 'decorators' => array('Children')));
             $content = $element->render();
             $this->getResponse()->setBody($content);
             $this->_helper->viewRenderer->setNoRender(true);
             return;
         } catch (Exception $e) {
         }
     }
     // Just render default editing form
     $this->view->form = $form = new Engine_Form(array('title' => $contentInfo[$name]['title'], 'description' => 'placeholder', 'method' => 'post', 'action' => $_SERVER['REQUEST_URI'], 'class' => 'global_form_popup', 'elements' => array(array('Text', 'title', array('label' => 'Title')), array('Button', 'submit', array('label' => 'Save', 'type' => 'submit', 'decorators' => array('ViewHelper'), 'ignore' => true, 'order' => 1501)), array('Hidden', 'name', array('value' => $name)), array('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1502))), 'displaygroups' => array('buttons' => array('name' => 'buttons', 'elements' => array('submit', 'cancel'), 'options' => array('order' => 1500)))));
     if (!empty($contentInfo[$name]['isPaginated'])) {
         $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0)))));
     }
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         $this->view->values = $form->getValues();
         $this->view->form = null;
     } else {
         $form->populate($this->_getAllParams());
     }
 }
Exemple #6
0
 public function notificationsAction()
 {
     $user = Engine_Api::_()->core()->getSubject();
     // Build the different notification types
     $modules = Engine_Api::_()->getDbtable('modules', 'core')->getModulesAssoc();
     $notificationTypes = Engine_Api::_()->getDbtable('notificationTypes', 'activity')->getNotificationTypes();
     $notificationSettings = Engine_Api::_()->getDbtable('notificationSettings', 'activity')->getEnabledNotifications($user);
     $notificationTypesAssoc = array();
     $notificationSettingsAssoc = array();
     foreach ($notificationTypes as $type) {
         if (in_array($type->module, array('core', 'activity', 'fields', 'authorization', 'messages', 'user'))) {
             $elementName = 'general';
             $category = 'General';
         } else {
             if (isset($modules[$type->module])) {
                 $elementName = preg_replace('/[^a-zA-Z0-9]+/', '-', $type->module);
                 $category = $modules[$type->module]->title;
             } else {
                 $elementName = 'misc';
                 $category = 'Misc';
             }
         }
         $notificationTypesAssoc[$elementName]['category'] = $category;
         $notificationTypesAssoc[$elementName]['types'][$type->type] = 'ACTIVITY_TYPE_' . strtoupper($type->type);
         if (in_array($type->type, $notificationSettings)) {
             $notificationSettingsAssoc[$elementName][] = $type->type;
         }
     }
     ksort($notificationTypesAssoc);
     $notificationTypesAssoc = array_filter(array_merge(array('general' => array(), 'misc' => array()), $notificationTypesAssoc));
     // Make form
     $this->view->form = $form = new Engine_Form(array('title' => 'Notification Settings', 'description' => 'Which of the these do you want to receive email alerts about?'));
     foreach ($notificationTypesAssoc as $elementName => $info) {
         $form->addElement('MultiCheckbox', $elementName, array('label' => $info['category'], 'multiOptions' => $info['types'], 'value' => (array) @$notificationSettingsAssoc[$elementName]));
     }
     $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit'));
     // Check method
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     // Process
     $values = array();
     foreach ($form->getValues() as $key => $value) {
         if (!is_array($value)) {
             continue;
         }
         foreach ($value as $skey => $svalue) {
             if (!isset($notificationTypesAssoc[$key]['types'][$svalue])) {
                 continue;
             }
             $values[] = $svalue;
         }
     }
     // Set notification setting
     Engine_Api::_()->getDbtable('notificationSettings', 'activity')->setEnabledNotifications($user, $values);
     $form->addNotice('Your changes have been saved.');
 }
 public function notificationsAction()
 {
     error_reporting(E_ALL);
     ini_set('display_errors', TRUE);
     // Build the different notification types
     $modules = Engine_Api::_()->getDbtable('modules', 'core')->getModulesAssoc();
     $notificationTypes = Engine_Api::_()->getDbtable('notificationTypes', 'activity')->getNotificationTypes();
     $notificationSettings = Engine_Api::_()->getDbtable('notificationTypes', 'activity')->getDefaultNotifications();
     $notificationTypesAssoc = array();
     $notificationSettingsAssoc = array();
     foreach ($notificationTypes as $type) {
         if (in_array($type->module, array('core', 'activity', 'fields', 'authorization', 'messages', 'user'))) {
             $elementName = 'general';
             $category = 'General';
         } else {
             if (isset($modules[$type->module])) {
                 $elementName = preg_replace('/[^a-zA-Z0-9]+/', '-', $type->module);
                 $category = $modules[$type->module]->title;
             } else {
                 $elementName = 'misc';
                 $category = 'Misc';
             }
         }
         $notificationTypesAssoc[$elementName]['category'] = $category;
         $notificationTypesAssoc[$elementName]['types'][$type->type] = 'ACTIVITY_TYPE_' . strtoupper($type->type);
         if (in_array($type->type, $notificationSettings)) {
             $notificationSettingsAssoc[$elementName][] = $type->type;
         }
     }
     ksort($notificationTypesAssoc);
     $notificationTypesAssoc = array_filter(array_merge(array('general' => array(), 'misc' => array()), $notificationTypesAssoc));
     $this->view->form = $form = new Engine_Form(array('title' => 'Default Email Notifications', 'description' => 'This page allows you to specify the default email notifications for new users.'));
     foreach ($notificationTypesAssoc as $elementName => $info) {
         $form->addElement('MultiCheckbox', $elementName, array('label' => $info['category'], 'multiOptions' => $info['types'], 'value' => (array) @$notificationSettingsAssoc[$elementName]));
     }
     // init submit
     $form->addElement('Button', 'submit', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true));
     // Check method
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = array();
     foreach ($form->getValues() as $key => $value) {
         if (!is_array($value)) {
             continue;
         }
         foreach ($value as $skey => $svalue) {
             if (!isset($notificationTypesAssoc[$key]['types'][$svalue])) {
                 continue;
             }
             $values[] = $svalue;
         }
     }
     Engine_Api::_()->getDbtable('notificationTypes', 'activity')->setDefaultNotifications($values);
     $form->addNotice('Your changes have been saved.');
 }