/** * Save a form * * @todo take field names from fields table */ function saveform() { $mainframe =& JFactory::getApplication(); $db =& $this->_db; /* Default values */ $answer = ''; $return = false; $redcompetition = false; $redevent = false; $event_task = JRequest::getVar('event_task'); /* Check for the submit key */ $submit_key = JRequest::getVar('submit_key', false); if (!$submit_key) { $submit_key = uniqid(); } /* Get the form details */ $form = $this->getForm(JRequest::getInt('form_id')); if ($form->captchaactive) { JPluginHelper::importPlugin('redform_captcha'); $res = true; $dispatcher =& JDispatcher::getInstance(); $results = $dispatcher->trigger('onCheckCaptcha', array(&$res)); if (count($results) && $res == false) { $this->setError(JText::_('COM_REDFORM_CAPTCHA_WRONG')); return false; } } /* Load the fields */ $fieldlist = $this->getfields($form->id); /* Load the posted variables */ $post = JRequest::get('post'); $files = JRequest::get('files'); $posted = array_merge($post, $files); if (JRequest::getInt('competition_id', false)) { $redcompetition = true; $event_id = JRequest::getInt('competition_id', 0); $post['xref'] = $event_id; } else { $post['xref'] = 0; } $event = null; /* Loop through the different forms */ $totalforms = JRequest::getInt('curform'); //if ($event_task == 'userregister') $totalforms--; /* Sign up minimal 1 */ if ($totalforms == 0) { $totalforms = 1; } $allanswers = array(); for ($signup = 1; $signup <= $totalforms; $signup++) { // new answers object $answers = new rfanswers(); $answers->setFormId($form->id); if ($event) { $answers->initPrice($event->course_price); } /* Create an array of values to store */ $postvalues = array(); // remove the _X parts, where X is the form (signup) number foreach ($posted as $key => $value) { if (strpos($key, 'field') === 0 && strpos($key, '_' . $signup, 5) > 0) { $postvalues[str_replace('_' . $signup, '', $key)] = $value; } } /* Some default values needed */ if (isset($post['xref'])) { $postvalues['xref'] = $post['xref']; } else { $postvalues['xref'] = 0; } $postvalues['form_id'] = $post['form_id']; $postvalues['submit_key'] = $submit_key; if ($redcompetition) { $postvalues['integration'] = 'redcompetition'; } /* Get the raw form data */ $postvalues['rawformdata'] = serialize($posted); /* Build up field list */ foreach ($fieldlist as $key => $field) { if (isset($postvalues['field' . $key])) { /* Get the answers */ try { $answers->addPostAnswer($field, $postvalues['field' . $key]); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } } } // save answers if (!$answers->save($postvalues)) { return false; } $this->updateMailingList($answers); $allanswers[] = $answers; } /* End multi-user signup */ $this->_answers = $allanswers; /* Load the mailer in case we need to inform someone */ if ($form->submitterinform || $form->contactpersoninform) { $this->Mailer(); } /* Send a submission mail to the submitters if set */ if ($form->submitterinform) { foreach ($allanswers as $answers) { $this->notifysubmitter($answers, $form); } } // send email to miantainers if ($answers->isNew()) { $this->notifymaintainer($allanswers); } if ($form->activatepayment) { $redirect = 'index.php?option=com_redform&controller=payment&task=select&key=' . $submit_key; $mainframe->redirect(JRoute::_($redirect, false)); } /* All is good, check if we have an competition in that case redirect to redCOMPETITION */ if ($redcompetition) { $redirect = 'index.php?option=com_redcompetition&task=' . JRequest::getVar('competition_task') . '&competition_id=' . JRequest::getInt('competition_id') . '&submitter_id=' . $allanswers[0]->getAnswerId() . '&form_id=' . JRequest::getInt('form_id'); $mainframe->redirect(JRoute::_($redirect, false)); } return array($form->submitnotification, $form->notificationtext); }
function store() { echo '<pre>'; print_r('deprecated ?'); echo '</pre>'; exit; $mainframe =& JFactory::getApplication(); $db =& $this->_db; /* Default values */ $answer = ''; $return = false; $redcompetition = false; $redevent = false; $event_task = JRequest::getVar('event_task'); $submitter_id = Jrequest::getInt('submitter_id', 0); if ($submitter_id) { $submitter = $this->getSubmitter($submitter_id); $submit_key = $submitter->submit_key; } else { $submitter = false; $submit_key = uniqid(); } /* Get the form details */ $form = $this->getForm(JRequest::getInt('form_id')); /* Load the fields */ $fieldlist = $this->getfields($form->id); /* Load the posted variables */ $post = JRequest::get('post'); $files = JRequest::get('files'); $posted = array_merge($post, $files); /* See if we have an event ID */ if (JRequest::getInt('event_xref', 0)) { $redevent = true; $posted['xref'] = JRequest::getInt('event_xref', 0); } else { if (isset($post['integration']) && $post['integration'] == 'redevent') { $redevent = true; $posted['xref'] = JRequest::getInt('xref', 0); } else { if (JRequest::getInt('competition_id', 0)) { $redcompetition = true; $posted['xref'] = JRequest::getInt('competition_id', 0); } else { $posted['xref'] = 0; } } } if ($posted['xref'] && $redevent) { $event = $this->getEvent($posted['xref']); } else { $event = null; } // new answers object $answers = new rfanswers(); $answers->setFormId($form->id); if ($event) { $answers->initPrice($event->course_price); } /* Create an array of values to store */ $postvalues = array(); // remove the _X parts, where X is the form (signup) number $signup = 1; foreach ($posted as $key => $value) { if (strpos($key, 'field') === 0 && strpos($key, '_' . $signup, 5) > 0) { $postvalues[str_replace('_' . $signup, '', $key)] = $value; } } /* Some default values needed */ $postvalues['xref'] = $post['xref']; $postvalues['form_id'] = $post['form_id']; $postvalues['submit_key'] = $submit_key; if (isset($post['integration'])) { $postvalues['integration'] = $post['integration']; } /* Get the raw form data */ $postvalues['rawformdata'] = serialize($posted); /* Build up field list */ foreach ($fieldlist as $key => $field) { if (isset($postvalues['field' . $key])) { /* Get the answers */ try { $answers->addPostAnswer($field, $postvalues['field' . $key]); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } } } if ($submitter) { // this 'anwers' were already posted $answers->setAnswerId($submitter->answer_id); } // save answers if (!$answers->save($postvalues)) { return false; } // add an attendee in redevent ? $uid = JRequest::getInt('uid'); $this->updateMailingList($answers); return true; }