/** * getSurveyContent * Render the actual survey question for the specified form id that passed . * * @return string rendered template * * @param int $formId The id of the survey to get the content for. * @param tpl $tpl This is the actual template system parsed from the front end */ public function getSurveyContent($surveyId, $tpl) { // give the form an action to handle the submission // $tpl->Assign('action', 'admin/index.php?Page=Addons&Addon=surveys&Action=Submit&ajax=1&formId=' . $surveyId); $success_message = IEM::sessionGet('survey.addon.' . $surveyId . '.successMessage'); if ($success_message) { IEM::sessionRemove('survey.addon.' . $surveyId . '.successMessage'); $tpl->Assign('successMessage', $success_message); return $tpl->ParseTemplate('survey_success'); } $tpl->Assign('action', 'surveys_submit.php?ajax=1&formId=' . $surveyId); // check for valid ID if (!isset($surveyId)) { return; } require_once 'widgets.php'; $widgets_api = new Addons_survey_widgets_api(); $loadRes = $this->Load($surveyId); if ($loadRes === false) { echo 'invalid form id'; return; } $surveyData = $this->GetData(); $widgets = $this->getWidgets($this->id); // and if there are widgets // iterate through each one $widgetErrors = array(); if ($widgets) { $widgetErrors = IEM::sessionGet('survey.addon.' . $surveyId . '.widgetErrors'); foreach ($widgets as $k => &$widget) { if ($widget['is_visible'] == 1 || $widget['type'] == 'section.break') { // $widget->className = Interspire_String::camelCase($widget->type, true); // Getting error from form.. $widget['className'] = 'Widget_' . str_replace('.', '_', $widget['type']); $widgets_api->SetId($widget['id']); $widget['fields'] = $widgets_api->getFields(false); // if there are errors for this widget, set them if ($widgetErrors && count($widgetErrors[$widget['id']]) > 0) { $widget['errors'] = $widgetErrors[$widget['id']]; } // randomize the fields if told to do so if ($widget['is_random'] == 1) { shuffle($widget['fields']); } // tack on an other field if one exists if ($otherField = $widgets_api->getOtherField()) { $otherField['value'] = '__other__'; $widget['fields'][] = $otherField; } // if it is a file widget, then grab the file types if ($widget['type'] == 'file') { $widget['fileTypes'] = preg_split('/\\s*,\\s*/', $widget['allowed_file_types']); $widget['lastFileType'] = array_pop($widget['fileTypes']); } // assign the widget information to the view $tpl->Assign('widget', $widget); // render the widget template $widget['template'] = $tpl->parseTemplate('widget.front.' . $widget['type'], true); } else { unset($widgets[$k]); } } // clear the widget errors session variable IEM::sessionRemove('survey.addon.' . $surveyId . '.widgetErrors'); } // assign the form, widget and widget-field data to the template $tpl->Assign('errorMessage', IEM::sessionGet('survey.addon.' . $surveyId . '.errorMessage')); $tpl->Assign('successMessage', IEM::sessionGet('survey.addon.' . $surveyId . '.successMessage')); $tpl->Assign('survey', $surveyData); $tpl->Assign('widgets', $widgets); // unset the message that was set, so it doesn't get displayed again IEM::sessionRemove('survey.addon.' . $surveyId . '.errorMessage'); IEM::sessionRemove('survey.addon.' . $surveyId . '.successMessage'); //return $this->template->parseTemplate('form', true); return $tpl->ParseTemplate('survey'); }