Esempio n. 1
0
 /**
  * Deletes one or more submitters
  * 
  * @param array id of submitters records to delete
  * @param boolean force deletion of integration rows
  */
 function delete($cid, $force = false)
 {
     $mainframe = JFactory::getApplication();
     $database = JFactory::getDBO();
     JArrayHelper::toInteger($cid);
     if (!is_array($cid) || count($cid) < 1) {
         $mainframe->enqueueMessage(JText::_('COM_REDFORM_No_submitter_found_to_delete'));
         return false;
     }
     if (count($cid)) {
         $cids = ' s.id IN (' . implode(',', $cid) . ') ';
         // first, check that there is no integration (xref is then > 0) among these 'submitter'
         if (!$force) {
             $query = ' SELECT COUNT(*) FROM #__rwf_submitters AS s WHERE ' . $cids . ' AND s.xref > 0 ';
             $database->setQuery($query);
             $res = $database->loadResult();
             if ($res) {
                 $msg = JText::_('COM_REDFORM_CANNOT_DELETE_REDEVENT_REGISTRATION');
                 $this->setError($msg);
                 JError::raiseWarning(0, $msg);
                 return false;
             }
         }
         // first delete the answers
         $query = ' DELETE a.* ' . ' FROM #__rwf_submitters AS s ' . ' INNER JOIN #__rwf_forms_' . JRequest::getInt('form_id') . ' AS a ON s.answer_id = a.id ' . ' WHERE ' . $cids;
         $this->_db->setQuery($query);
         $res = $this->_db->loadObjectList();
         if (!$database->query()) {
             $mainframe->enqueueMessage(JText::_('COM_REDFORM_A_problem_occured_when_deleting_the_answers'));
             RedformHelperLog::simpleLog(JText::_('COM_REDFORM_A_problem_occured_when_deleting_the_answers') . ': ' . $database->getErrorMsg());
             return false;
         }
         /* then delete the submitters */
         $query = ' DELETE s.* FROM #__rwf_submitters AS s ' . ' WHERE ' . $cids . '	AND s.form_id = ' . JRequest::getInt('form_id');
         $database->setQuery($query);
         if (!$database->query()) {
             $mainframe->enqueueMessage(JText::_('COM_REDFORM_A_problem_occured_when_deleting_the_submitter'));
             RedformHelperLog::simpleLog(JText::_('COM_REDFORM_A_problem_occured_when_deleting_the_submitter') . ': ' . $database->getErrorMsg());
             return false;
         }
         if (count($cid) > 1) {
             $mainframe->enqueueMessage(JText::_('COM_REDFORM_Submitters_have_been_deleted'));
         } else {
             $mainframe->enqueueMessage(JText::_('COM_REDFORM_Submitter_has_been_deleted'));
         }
     }
     return JText::_('COM_REDFORM_Removal_succesfull');
 }
Esempio n. 2
0
 /**
  * send email to form maintaineers or/and selected recipients
  * @param array $allanswers
  */
 function notifymaintainer($allanswers, $new = true)
 {
     $mainframe =& JFactory::getApplication();
     $params = JComponentHelper::getParams('com_redform');
     $form = $this->getForm();
     /* Inform contact person if need */
     // form recipients
     $recipients = $allanswers[0]->getRecipients();
     $cond_recipients = RedFormCore::getConditionalRecipients($form, $allanswers[0]);
     if ($cond_recipients) {
         foreach ($cond_recipients as $c) {
             $recipients[] = $c[0];
         }
     }
     if ($form->contactpersoninform || !empty($recipients)) {
         // init mailer
         $mailer =& JFactory::getMailer();
         $mailer->isHTML(true);
         if ($form->contactpersoninform) {
             if (strstr($form->contactpersonemail, ';')) {
                 $addresses = explode(";", $form->contactpersonemail);
             } else {
                 $addresses = explode(",", $form->contactpersonemail);
             }
             foreach ($addresses as $a) {
                 $a = trim($a);
                 if (JMailHelper::isEmailAddress($a)) {
                     $mailer->addRecipient($a);
                 }
             }
         }
         if (!empty($recipients)) {
             foreach ($recipients as $r) {
                 $mailer->addRecipient($r);
             }
         }
         if (!empty($xref_group_recipients)) {
             foreach ($xref_group_recipients as $r) {
                 $mailer->addRecipient($r);
             }
         }
         // we put the submitter as the email 'from' and reply to.
         $user =& JFactory::getUser();
         if ($params->get('allow_email_aliasing', 1)) {
             if ($user->get('id')) {
                 $sender = array($user->email, $user->name);
             } else {
                 if ($allanswers[0]->getSubmitterEmails()) {
                     if ($allanswers[0]->getFullname()) {
                         $sender = array(reset($allanswers[0]->getSubmitterEmails()), $allanswers[0]->getFullname());
                     } else {
                         $sender = array(reset($allanswers[0]->getSubmitterEmails()), null);
                     }
                 } else {
                     // default to site settings
                     $sender = array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('sitename'));
                 }
             }
         } else {
             // default to site settings
             $sender = array($mainframe->getCfg('mailfrom'), $mainframe->getCfg('sitename'));
         }
         $mailer->setSender($sender);
         $mailer->addReplyTo($sender);
         // set the email subject
         if ($new) {
             $mailer->setSubject(str_replace('[formname]', $form->formname, JText::_('COM_REDFORM_CONTACT_NOTIFICATION_EMAIL_SUBJECT')));
         } else {
             $mailer->setSubject(str_replace('[formname]', $form->formname, JText::_('COM_REDFORM_CONTACT_NOTIFICATION_UPDATE_EMAIL_SUBJECT')));
         }
         // Mail body
         $htmlmsg = '<html><head><title></title></title></head><body>';
         if ($new) {
             $htmlmsg .= JText::sprintf('COM_REDFORM_MAINTAINER_NOTIFICATION_EMAIL_BODY', $form->formname);
         } else {
             $htmlmsg .= JText::sprintf('COM_REDFORM_MAINTAINER_NOTIFICATION_UPDATE_EMAIL_BODY', $form->formname);
         }
         /* Add user submitted data if set */
         if ($form->contactpersonfullpost) {
             foreach ($allanswers as $answers) {
                 $rows = $answers->getAnswers();
                 $patterns[0] = '/\\r\\n/';
                 $patterns[1] = '/\\r/';
                 $patterns[2] = '/\\n/';
                 $replacements[2] = '<br />';
                 $replacements[1] = '<br />';
                 $replacements[0] = '<br />';
                 $htmlmsg .= '<br /><table border="1">';
                 foreach ($rows as $key => $answer) {
                     switch ($answer['type']) {
                         case 'recipients':
                             break;
                         case 'email':
                             $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>';
                             $htmlmsg .= '<a href="mailto:' . $answer['value'] . '">' . $answer['value'] . '</a>';
                             $htmlmsg .= '&nbsp;';
                             $htmlmsg .= '</td></tr>' . "\n";
                             break;
                         case 'text':
                             $userinput = preg_replace($patterns, $replacements, $answer['value']);
                             $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>';
                             if (strpos($answer['value'], 'http://') === 0) {
                                 $htmlmsg .= '<a href="' . $answer['value'] . '">' . $answer['value'] . '</a>';
                             } else {
                                 $htmlmsg .= $answer['value'];
                             }
                             $htmlmsg .= '&nbsp;';
                             $htmlmsg .= '</td></tr>' . "\n";
                             break;
                         case 'file':
                             $userinput = preg_replace($patterns, $replacements, $answer['value']);
                             $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>';
                             $htmlmsg .= $answer['value'] && file_exists($answer['value']) ? basename($answer['value']) : '';
                             $htmlmsg .= '</td></tr>' . "\n";
                             // attach to mail
                             if ($answer['value'] && file_exists($answer['value'])) {
                                 $mailer->addAttachment($answer['value']);
                             }
                             break;
                         default:
                             $userinput = preg_replace($patterns, $replacements, $answer['value']);
                             $htmlmsg .= '<tr><td>' . $answer['field'] . '</td><td>';
                             $htmlmsg .= str_replace('~~~', '<br />', $userinput);
                             $htmlmsg .= '&nbsp;';
                             $htmlmsg .= '</td></tr>' . "\n";
                             break;
                     }
                 }
                 if ($p = $answers->getPrice()) {
                     $htmlmsg .= '<tr><td>' . JText::_('COM_REDFORM_TOTAL_PRICE') . '</td><td>';
                     $htmlmsg .= $p;
                     $htmlmsg .= '</td></tr>' . "\n";
                 }
                 $htmlmsg .= "</table><br />";
             }
         }
         $htmlmsg .= '</body></html>';
         $mailer->setBody($htmlmsg);
         // send the mail
         if (!$mailer->Send()) {
             RedformHelperLog::simpleLog(JText::_('COM_REDFORM_NO_MAIL_SEND') . ' (contactpersoninform): ' . $mailer->error);
         }
     }
 }
Esempio n. 3
0
 /**
  * returns email if answers match the condition
  *
  * @param string $conditionline
  * @param object $answers
  * @return string|boolean email or false
  */
 protected static function _parseCondition($conditionline, $answers)
 {
     $parts = explode(";", $conditionline);
     if (!count($parts)) {
         return false;
     }
     // cleanup
     array_walk($parts, 'trim');
     if (count($parts) < 5) {
         // invalid condition...
         RedformHelperLog::simpleLog('invalid condition formatting' . $conditionline);
         return false;
     }
     // first should be the email address
     if (!JMailHelper::isEmailAddress($parts[0])) {
         RedformHelperLog::simpleLog('invalid email in conditional recipient: ' . $parts[0]);
         return false;
     }
     $email = $parts[0];
     // then the name of the recipient
     if (!$parts[1]) {
         RedformHelperLog::simpleLog('invalid name in conditional recipient: ' . $parts[0]);
         return false;
     }
     $name = $parts[1];
     // then, we shoulg get the field
     $field_id = intval($parts[2]);
     $answer = $answers->getFieldAnswer($field_id);
     if ($answer === false) {
         RedformHelperLog::simpleLog('invalid field id for conditional recipient: ' . $parts[1]);
         return false;
     }
     $value = $answer['value'];
     $isvalid = false;
     // then, we should get the function
     switch ($parts[3]) {
         case 'between':
             if (!isset($parts[5])) {
                 RedformHelperLog::simpleLog('missing max value in between conditional recipient: ' . $conditionline);
             }
             if (is_numeric($value)) {
                 $value = floatval($value);
                 $min = floatval($parts[4]);
                 $max = floatval($parts[5]);
                 $isvalid = $value >= $min && $value <= $max ? $email : false;
             } else {
                 $isvalid = strcasecmp($value, $parts[4]) >= 0 && strcasecmp($value, $parts[5]) <= 0;
             }
             break;
         case 'inferior':
             if (is_numeric($value)) {
                 $value = floatval($value);
                 $max = floatval($parts[4]);
                 $isvalid = $value <= $max ? $email : false;
             } else {
                 $isvalid = strcasecmp($value, $parts[4]) <= 0;
             }
             break;
         case 'superior':
             if (is_numeric($value)) {
                 $value = floatval($value);
                 $min = floatval($parts[4]);
                 $isvalid = $value >= $min ? $email : false;
             } else {
                 $isvalid = strcasecmp($value, $parts[4]) >= 0;
             }
             break;
         default:
             RedformHelperLog::simpleLog('invalid email in conditional recipient: ' . $parts[0]);
             return false;
     }
     if ($isvalid) {
         return array($email, $name);
     }
 }
Esempio n. 4
0
 /**
  * Handle notifications (callback) from the gateways
  *
  * @throws Exception
  * @return void
  */
 public function notify()
 {
     $app = JFactory::getApplication();
     $submit_key = $app->input->get('key');
     $gw = $app->input->get('gw', '');
     RedformHelperLog::simpleLog('PAYMENT NOTIFICATION RECEIVED' . ': ' . $gw);
     if (empty($gw)) {
         RedformHelperLog::simpleLog('PAYMENT NOTIFICATION MISSING GATEWAY' . ': ' . $gw);
         throw new Exception('PAYMENT NOTIFICATION MISSING GATEWAY' . ': ' . $gw, 404);
     }
     $model = $this->getModel('payment');
     $alreadypaid = $model->hasAlreadyPaid();
     $helper = $model->getGatewayHelper($gw);
     $res = $helper->notify();
     if ($res) {
         // The payment was received !
         $app->input->set('state', 'accepted');
         if (!$alreadypaid) {
             // Trigger event for custom handling
             JPluginHelper::importPlugin('redform');
             $dispatcher = JDispatcher::getInstance();
             $dispatcher->trigger('onAfterPaymentVerified', array($submit_key));
             // Built-in notifications
             $model->notifyPaymentReceived();
         }
     } else {
         $app->input->set('state', 'failed');
     }
     $submitters = $model->getSubmitters();
     if (count($submitters)) {
         $first = current($submitters);
         if (!empty($first->integration)) {
             switch ($first->integration) {
                 case 'redevent':
                     $app->redirect('index.php?option=com_redevent&view=payment&submit_key=' . $submit_key . '&state=' . ($res ? 'accepted' : 'refused'));
                     break;
                 default:
                     $app->redirect('index.php?option=com_' . $first->integration . '&view=payment&submit_key=' . $submit_key . '&state=' . ($res ? 'accepted' : 'refused'));
                     break;
             }
         }
     }
     $app->input->set('view', 'payment');
     $app->input->set('layout', 'final');
     $this->display();
 }
Esempio n. 5
0
 /**
  * return gateway helper
  * @param string name
  * @return object or false if no corresponding gateway
  */
 function getGatewayHelper($name)
 {
     $gw = $this->getGateways();
     foreach ($gw as $g) {
         if (strcasecmp($g['name'], $name) == 0) {
             return $g['helper'];
         }
     }
     RedformHelperLog::simpleLog('NOTIFICATION GATEWAY NOT FOUND' . ': ' . $name);
     return false;
 }
Esempio n. 6
0
 function setPrice()
 {
     if (!$this->_sid) {
         return false;
     }
     $params =& JComponentHelper::getParams('com_redform');
     if ($params->get('allow_negative_total', 1)) {
         $price = $this->_price;
     } else {
         $price = max(array(0, $this->_price));
     }
     $db =& JFactory::getDBO();
     $query = ' UPDATE #__rwf_submitters SET price = ' . $db->Quote($price) . ' WHERE id = ' . $db->Quote($this->_sid);
     $db->setQuery($query);
     $res = $db->query();
     if (!$res) {
         RedformHelperLog::simpleLog($db->getErrorMsg());
         return false;
     }
     return $res;
 }