示例#1
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise a JError object.
  */
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     $layout = $this->getLayout();
     $document = JFactory::getDocument();
     $params = $app->getPageParameters();
     $templateName = $app->getTemplate();
     $css_filename = '/templates/' . $templateName . '/css/com_bwpostman.css';
     $this->captcha = BwPostmanHelper::getCaptcha(1);
     $document->setTitle($params->get('page_title'));
     $document->addStyleSheet(JURI::root(true) . '/components/com_bwpostman/assets/css/bwpostman.css');
     if (file_exists(JPATH_BASE . $css_filename)) {
         $document->addStyleSheet(JURI::root(true) . $css_filename);
     }
     switch ($layout) {
         case "error_accountblocked":
         case "error_accountgeneral":
         case "error_accountnotactivated":
         case "error_email":
         case "error_geteditlink":
             $this->_displayError($tpl);
             return;
             break;
         case "success_msg":
             $this->_displaySuccess($tpl);
             return;
             break;
         default:
             $this->_displayDefault($tpl);
             return;
             break;
     }
     parent::display($tpl);
 }
示例#2
0
 /**
  * Overloaded check method to ensure data integrity of a subscriber
  *
  * @access public
  * @return boolean True on success
  */
 public function check()
 {
     //Initialize
     jimport('joomla.mail.helper');
     $params = JComponentHelper::getParams('com_bwpostman');
     $app = JFactory::getApplication();
     $import = $app->getUserState('com_bwpostman.subscriber.import', false);
     $data = $app->getUserState('com_bwpostman.subscriber.register.data', array());
     $session = JFactory::getSession();
     $err = $session->get('session_error');
     $fault = false;
     $_db = $this->_db;
     $query = $_db->getQuery(true);
     $tester = false;
     $format_txt = array(0 => 'Text', 1 => 'HTML');
     if ($xtest = !'9') {
         $tester = true;
     }
     if ($import && $this->status == '9') {
         $tester = true;
     }
     // Remove all HTML tags from the name, firstname, email and special
     $filter = new JFilterInput(array(), array(), 0, 0);
     $this->name = $filter->clean($this->name);
     $this->firstname = $filter->clean($this->firstname);
     $this->email = $filter->clean($this->email);
     $this->special = $filter->clean($this->special);
     if (!$import) {
         // Check for valid firstname
         if ($data['show_firstname_field'] && $data['firstname_field_obligation']) {
             if (trim($this->firstname) == '') {
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_SUB_ERROR_FIRSTNAME'), 'error');
                 $fault = true;
             }
         }
         // Check for valid name
         if ($data['show_name_field'] && $data['name_field_obligation']) {
             if (trim($this->name) == '') {
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_SUB_ERROR_NAME'), 'error');
                 $fault = true;
             }
         }
         // Check for valid additional field
         if ($data['show_special'] && $data['special_field_obligation']) {
             if (trim($this->special) == '') {
                 $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_SPECIAL', JText::_($params->get('special_label'))), 'error');
                 $fault = true;
             }
         }
     }
     // Check for valid email address
     if (trim($this->email) == '') {
         $app->enqueueMessage(JText::_('COM_BWPOSTMAN_SUB_ERROR_EMAIL'), 'error');
         $fault = true;
     } elseif (!JMailHelper::isEmailAddress(trim($this->email))) {
         $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_EMAIL_INVALID', $this->email), 'error');
         $fault = true;
     }
     if ($app->isSite() && !$this->id) {
         // Check if any mailinglist is checked
         if (!$data['mailinglists']) {
             $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_LISTCHECK'), 'error');
             $fault = true;
         }
         // agreecheck
         if (JComponentHelper::getParams('com_bwpostman')->get('disclaimer') == 1) {
             if (!isset($data['agreecheck']) && !isset($data['agreecheck_mod'])) {
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_AGREECHECK'), 'error');
                 $fault = true;
             }
         }
         // Spamcheck 1
         // Set error message if a not visible (top: -5000px) inputfield is empty
         if ($data['falle'] != '') {
             // input wrong - set error
             $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_SPAMCHECK'), 'error');
             $fault = true;
         }
         // Spamcheck 2
         // Set error message if check of a dynamic time variable failed
         if (!isset($data['bwp-' . BwPostmanHelper::getCaptcha(1)]) && !isset($data['bwp-' . BwPostmanHelper::getCaptcha(2)])) {
             // input wrong - set error
             $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_SPAMCHECK2'), 'error');
             $fault = true;
         }
         // Captchacheck 1
         // Set error message if captchatest failed
         if (JComponentHelper::getParams('com_bwpostman')->get('use_captcha') == 1) {
             // start check
             if (trim($data['stringQuestion']) != trim(JComponentHelper::getParams('com_bwpostman')->get('security_answer'))) {
                 // input wrong - set error
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_CAPTCHA'), 'error');
                 $fault = true;
             }
         }
         // Captchacheck 2
         if (JComponentHelper::getParams('com_bwpostman')->get('use_captcha') == 2) {
             // Temp folder of captcha-images
             $captchaDir = JPATH_COMPONENT_SITE . '/assets/capimgdir/';
             // del old images after ? minutes
             $delFile = 10;
             // start check
             $resultCaptcha = BwPostmanHelper::CheckCaptcha($data['codeCaptcha'], $data['stringCaptcha'], $captchaDir, $delFile);
             if (!$resultCaptcha) {
                 // input wrong - set error
                 $app->enqueueMessage(JText::_('COM_BWPOSTMAN_ERROR_CAPTCHA'), 'error');
                 $fault = true;
             }
         }
     }
     if ($fault) {
         $app->setUserState('com_bwpostman.edit.subscriber.data', $this);
         //			$app->setUserState('com_bwpostman.edit.subscriber.register.errors', $err);
         $session->set('session_error', $err);
         //			$session->close();
         return false;
     }
     // Check for existing email
     $query->select($_db->quoteName('id'));
     $query->from($_db->quoteName('#__bwpostman_subscribers'));
     $query->where($_db->quoteName('email') . ' = ' . $_db->Quote($this->email));
     if (!$tester) {
         $query->where($_db->quoteName('status') . ' != ' . (int) 9);
     }
     $_db->setQuery($query);
     $_db->query();
     if (!$tester) {
         $xid = intval($this->_db->loadResult());
     } else {
         $xids = $this->_db->loadColumn();
     }
     //Test-recipient may have multiple entries, but may not be archived
     if ($tester) {
         foreach ($xids as $xid) {
             $xid = intval($xid);
             if ($xid && $xid != intval($this->id)) {
                 $query = $_db->getQuery(true);
                 $query->select($_db->quoteName('id'));
                 $query->select($_db->quoteName('emailformat'));
                 $query->select($_db->quoteName('archive_flag'));
                 $query->from($_db->quoteName('#__bwpostman_subscribers'));
                 $query->where($_db->quoteName('id') . ' = ' . (int) $xid);
                 $this->_db->setQuery($query);
                 $testrecipient = $this->_db->loadObject();
                 // Account with this emailformat already exists
                 if ($testrecipient->archive_flag == 0 && $testrecipient->emailformat == $this->emailformat) {
                     $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTEXISTS', $this->email, $format_txt[$this->emailformat], $testrecipient->id), 'error');
                     $err['err_code'] = 409;
                     $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTEXISTS', $this->email, $format_txt[$this->emailformat], $testrecipient->id);
                     $err['err_id'] = $xid;
                     $app->setUserState('com_bwpostman.subscriber.register.error', $err);
                     $this->setError(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTEXISTS', $this->email, $format_txt[$this->emailformat], $testrecipient->id));
                     $session->set('session_error', $err);
                     return false;
                 }
                 // Account is archived
                 if ($testrecipient->archive_flag == 1 && $testrecipient->emailformat == $this->emailformat) {
                     $app->enqueueMessage(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTARCHIVED', $this->email, $format_txt[$this->emailformat], $testrecipient->id), 'error');
                     $err['err_code'] = 410;
                     $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTARCHIVED', $this->email, $format_txt[$this->emailformat], $testrecipient->id);
                     $err['err_id'] = $xid;
                     $app->setUserState('com_bwpostman.subscriber.register.error', $err);
                     $this->setError(JText::sprintf('COM_BWPOSTMAN_TEST_ERROR_ACCOUNTARCHIVED', $this->email, $format_txt[$this->emailformat], $testrecipient->id));
                     $session->set('session_error', $err);
                     return false;
                 }
             }
         }
     } else {
         if ($xid && $xid != intval($this->id)) {
             $query = $_db->getQuery(true);
             $query->select($_db->quoteName('id'));
             $query->select($_db->quoteName('status'));
             $query->select($_db->quoteName('archive_flag'));
             $query->select($_db->quoteName('archived_by'));
             $query->from($_db->quoteName('#__bwpostman_subscribers'));
             $query->where($_db->quoteName('id') . ' = ' . (int) $xid);
             $_db->setQuery($query);
             $_db->query();
             $subscriber = $this->_db->loadObject();
             // Account is blocked by system/administrator
             if ($subscriber->archive_flag == 1 && $subscriber->archived_by > 0) {
                 $err['err_code'] = 405;
                 $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTBLOCKED_BY_SYSTEM', $this->email, $xid);
                 $err['err_id'] = $xid;
                 $err['err_email'] = $this->email;
                 $app->setUserState('com_bwpostman.subscriber.register.error', $err);
                 $this->setError(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTBLOCKED_BY_SYSTEM', $this->email, $xid));
                 $session->set('session_error', $err);
                 return false;
             }
             // Account is not activated
             if ($subscriber->status == 0) {
                 $err['err_code'] = 406;
                 $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTNOTACTIVATED', $this->email, $xid);
                 $err['err_id'] = $xid;
                 $err['err_email'] = $this->email;
                 $app->setUserState('com_bwpostman.subscriber.register.error', $err);
                 $this->setError(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTNOTACTIVATED', $this->email, $xid));
                 $session->set('session_error', $err);
                 return false;
             }
             // Account already exists
             if ($subscriber->status == 1 && $subscriber->archive_flag != 1) {
                 $err['err_code'] = 407;
                 $err['err_msg'] = JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTEXISTS', $this->email, JRoute::_('index.php?option=com_bwpostman&view=edit'));
                 $err['err_id'] = $xid;
                 $err['err_email'] = $this->email;
                 $app->setUserState('com_bwpostman.subscriber.register.error', $err);
                 $this->setError(JText::sprintf('COM_BWPOSTMAN_SUB_ERROR_DB_ACCOUNTEXISTS', $this->email, JRoute::_('index.php?option=com_bwpostman&view=edit')));
                 $session->set('session_error', $err);
                 return false;
             }
         }
     }
     return true;
 }
示例#3
0
 /**
  * Method to save the registration
  *
  * @access public
  * @author Romana Boldt
  *
  * @since	1.0.1
  */
 public function register_save()
 {
     $jinput = JFactory::getApplication()->input;
     $app = JFactory::getApplication();
     // Check for request forgeries
     if (!JSession::checkToken()) {
         jexit(JText::_('JINVALID_TOKEN'));
     }
     $model = $this->getModel('register');
     $session = JFactory::getSession();
     $error = $session->get('session_error');
     $post = $jinput->getArray(array('agreecheck_mod' => 'string', 'a_emailformat' => 'string', 'a_firstname' => 'string', 'a_name' => 'string', 'a_gender' => 'string', 'a_special' => 'string', 'agreecheck' => 'string', 'emailformat' => 'string', 'firstname' => 'string', 'name' => 'string', 'gender' => 'string', 'special' => 'string', 'email' => 'string', 'falle' => 'string', 'language' => 'string', 'mailinglists' => 'array', 'firstname_field_obligation' => 'string', 'name_field_obligation' => 'string', 'special_field_obligation' => 'string', 'firstname_field_obligation_mod' => 'string', 'name_field_obligation_mod' => 'string', 'special_field_obligation_mod' => 'string', 'show_special_mod' => 'string', 'show_special' => 'string', 'show_name_field' => 'string', 'show_name_field_mod' => 'string', 'show_firstname_field' => 'string', 'show_firstname_field_mod' => 'string', 'registration_ip' => 'string', 'stringQuestion' => 'string', 'stringCaptcha' => 'string', 'codeCaptcha' => 'string', 'bwp-' . BwPostmanHelper::getCaptcha(1) => 'string', 'bwp-' . BwPostmanHelper::getCaptcha(2) => 'string', 'task' => 'string'));
     if (isset($post['a_firstname'])) {
         if ($post['a_firstname'] == JText::_('COM_BWPOSTMAN_FIRSTNAME')) {
             $post['firstname'] = '';
         } else {
             $post['firstname'] = $post['a_firstname'];
         }
         unset($post['a_firstname']);
     }
     if (isset($post['a_name'])) {
         if ($post['a_name'] == JText::_('COM_BWPOSTMAN_NAME')) {
             $post['name'] = '';
         } else {
             $post['name'] = $post['a_name'];
         }
         unset($post['a_name']);
     }
     if (isset($post['a_gender'])) {
         $post['gender'] = $post['a_gender'];
         unset($post['a_gender']);
     }
     if (isset($post['a_special'])) {
         $post['special'] = $post['a_special'];
         unset($post['a_special']);
     }
     if (isset($post['name_field_obligation_mod'])) {
         $post['name_field_obligation'] = $post['name_field_obligation_mod'];
         unset($post['name_field_obligation_mod']);
     }
     if (isset($post['firstname_field_obligation_mod'])) {
         $post['firstname_field_obligation'] = $post['firstname_field_obligation_mod'];
         unset($post['firstname_field_obligation_mod']);
     }
     if (isset($post['special_field_obligation_mod'])) {
         $post['special_field_obligation'] = $post['special_field_obligation_mod'];
         unset($post['special_field_obligation_mod']);
     }
     if (isset($post['show_name_field_mod'])) {
         $post['show_name_field'] = $post['show_name_field_mod'];
         unset($post['show_name_field_mod']);
     }
     if (isset($post['show_firstname_field_mod'])) {
         $post['show_firstname_field'] = $post['show_firstname_field_mod'];
         unset($post['show_name_firstfield_mod']);
     }
     if (isset($post['show_special_mod'])) {
         $post['show_special'] = $post['show_special_mod'];
         unset($post['show_special_mod']);
     }
     if (isset($post['a_emailformat'])) {
         $post['emailformat'] = $post['a_emailformat'];
         unset($post['a_emailformat']);
     }
     if (isset($post['agreecheck_mod'])) {
         $post['agreecheck'] = $post['agreecheck_mod'];
         unset($post['agreecheck_mod']);
     }
     $app->setUserState('com_bwpostman.subscriber.register.data', $post);
     // Subscriber is guest
     if (!$this->_userid) {
         // Check if the email-adress from the registration form is stored in user-table and gives back the id
         $post['user_id'] = $model->isRegUser($post['email']);
         // Subscriber is user
     } else {
         $post['user_id'] = $this->_userid;
     }
     $date = JFactory::getDate();
     $time = $date->toSql();
     $post['status'] = 0;
     $post['registration_date'] = $time;
     $post['registered_by'] = 0;
     $post['confirmed_by'] = '-1';
     $post['archived_by'] = '-1';
     if (!$model->save($post)) {
         $subscriber_data = array('name' => $post['name'], 'firstname' => $post['firstname'], 'email' => $post['email'], 'emailformat' => $post['emailformat'], 'mailinglists' => $post['mailinglists']);
         $session->set('subscriber_data', $subscriber_data);
         $err = $app->getUserState('com_bwpostman.subscriber.register.error', null);
         if (is_array($err)) {
             $err = JArrayHelper::toObject($err);
             $this->errorSubscriberData($err, $post['user_id'], $post['email']);
         } else {
             $link = JRoute::_('index.php?option=com_bwpostman&view=register', false);
             $this->setRedirect($link);
         }
     } else {
         $subscriber = new stdClass();
         $subscriber->name = $post['name'];
         $subscriber->firstname = $post['firstname'];
         $subscriber->email = $post['email'];
         $subscriber->activation = $app->getUserState('com_bwpostman.subscriber.activation', '');
         $type = 0;
         // Send Registration email
         $itemid = $model->getItemid();
         // Send registration confirmation mail
         $res = $this->_sendMail($subscriber, $type, $itemid);
         if ($res === true) {
             // Email has been sent
             $msg = 'COM_BWPOSTMAN_SUCCESS_ACCOUNTREGISTRATION';
             $this->success($msg);
         } else {
             // Email has not been sent
             $err_msg = 'COM_BWPOSTMAN_ERROR_REGISTRATIONEMAIL';
             $this->errorSendingEmail($err_msg, $post['email']);
         }
     }
     parent::display();
 }
示例#4
0
}
// Get document object, set document title and add css
$templateName = $app->getTemplate();
$css_filename = '/templates/' . $templateName . '/css/mod_bwpostman.css';
$document->addStyleSheet(JURI::root(true) . '/modules/mod_bwpostman/css/bwpostman.css');
if (file_exists(JPATH_BASE . $css_filename)) {
    $document->addStyleSheet(JURI::root(true) . $css_filename);
}
if (!JComponentHelper::isEnabled('com_bwpostman', true)) {
    $app->enqueueMessage(JText::_('Module requires the com_bwpostman component'), 'error');
} else {
    $user = JFactory::getUser();
    $userid = $user->get('id');
    $usertype = '';
    $subscriberid = modBwPostmanHelper::getSubscriberID();
    $captcha = BwPostmanHelper::getCaptcha(1);
    // use module or component parameters
    if ($params->get('com_params') == 0) {
        // Moduleparams
        $paramsComponent = $params;
    } else {
        // Get the parameters of the component
        // --> we need these parameters because we have to ensure that both the component and the module will work with the same settings
        $paramsComponent = $app->getPageParameters('com_bwpostman');
    }
    if ($subscriberid) {
        $layout = "_linktocomponent";
    } else {
        $layout = "default";
        if ($userid > 0) {
            $subscriber = modBwPostmanHelper::getUserData($userid);