private function loadSurveyResponses() { $c = Page::getCurrentPage(); $db = Loader::db(); $tempMiniSurvey = new MiniSurvey(); $pageBase = \URL::to($c); if ($_REQUEST['action'] == 'deleteForm') { if (!Loader::helper('validation/token')->validate('deleteForm')) { $this->error->add(t('Invalid Token.')); } else { $this->deleteForm($_REQUEST['bID'], $_REQUEST['qsID']); } } if ($_REQUEST['action'] == 'deleteFormAnswers') { if (!Loader::helper('validation/token')->validate('deleteFormAnswers')) { $this->error->add(t('Invalid Token.')); } else { $this->deleteFormAnswers($_REQUEST['qsID']); $this->redirect('/dashboard/reports/forms'); } } if ($_REQUEST['action'] == 'deleteResponse') { if (!Loader::helper('validation/token')->validate('deleteResponse')) { $this->error->add(t('Invalid Token.')); } else { $this->deleteAnswers($_REQUEST['asid']); } } //load surveys $surveysRS = FormBlockStatistics::loadSurveys($tempMiniSurvey); //index surveys by question set id $surveys = array(); while ($survey = $surveysRS->fetchRow()) { //get Survey Answers $survey['answerSetCount'] = MiniSurvey::getAnswerCount($survey['questionSetId']); $surveys[$survey['questionSetId']] = $survey; } //load requested survey response if (!empty($_REQUEST['qsid'])) { $questionSet = intval(preg_replace('/[^[:alnum:]]/', '', $_REQUEST['qsid'])); //get Survey Questions $questionsRS = MiniSurvey::loadQuestions($questionSet); $questions = array(); while ($question = $questionsRS->fetchRow()) { $questions[$question['msqID']] = $question; } //get Survey Answers $answerSetCount = MiniSurvey::getAnswerCount($questionSet); //pagination $pageBaseSurvey = $pageBase . '?qsid=' . $questionSet; $paginator = Loader::helper('pagination'); $sortBy = $_REQUEST['sortBy']; $paginator->init((int) $_REQUEST['page'], $answerSetCount, $pageBaseSurvey . '&page=%pageNum%&sortBy=' . $sortBy, $this->pageSize); if ($this->pageSize > 0) { $limit = $paginator->getLIMIT(); } else { $limit = ''; } $answerSets = FormBlockStatistics::buildAnswerSetsArray($questionSet, $sortBy, $limit); } $this->set('questions', $questions); $this->set('answerSets', $answerSets); $this->set('paginator', $paginator); $this->set('questionSet', $questionSet); $this->set('surveys', $surveys); }
<?php /************************************************************ * DESIGNERS: SCROLL DOWN! (IGNORE ALL THIS STUFF AT THE TOP) ************************************************************/ defined('C5_EXECUTE') or die("Access Denied."); use Concrete\Block\Form\MiniSurvey; $survey = $controller; $miniSurvey = new MiniSurvey($b); $miniSurvey->frontEndMode = true; //Clean up variables from controller so html is easier to work with... $bID = intval($bID); $qsID = intval($survey->questionSetId); $formAction = $view->action('submit_form') . '#formblock' . $bID; $questionsRS = $miniSurvey->loadQuestions($qsID, $bID); $questions = array(); while ($questionRow = $questionsRS->fetchRow()) { $question = $questionRow; $question['input'] = $miniSurvey->loadInputType($questionRow, false); //Make type names common-sensical if ($questionRow['inputType'] == 'text') { $question['type'] = 'textarea'; } else { if ($questionRow['inputType'] == 'field') { $question['type'] = 'text'; } else { $question['type'] = $questionRow['inputType']; } } $question['labelFor'] = 'for="Question' . $questionRow['msqID'] . '"'; //Remove hardcoded style on textareas
public function view() { $miniSurvey = new MiniSurvey(); $miniSurvey->frontEndMode = true; $bID = intval($this->bID); $qsID = intval($this->questionSetId); $formDomId = "miniSurveyView{$bID}"; $hasFileUpload = false; $questionsRS = $miniSurvey->loadQuestions($qsID, $bID); $questions = array(); while ($questionRow = $questionsRS->fetchRow()) { $question = $questionRow; $question['input'] = $miniSurvey->loadInputType($questionRow, false); if ($questionRow['inputType'] == 'fileupload') { $hasFileUpload = true; } //Make type names common-sensical if ($questionRow['inputType'] == 'text') { $question['type'] = 'textarea'; } else { if ($questionRow['inputType'] == 'field') { $question['type'] = 'text'; } else { $question['type'] = $questionRow['inputType']; } } //Construct label "for" (and misc. hackery for checkboxlist / radio lists) if ($question['type'] == 'checkboxlist') { $question['input'] = str_replace('<div class="checkboxPair">', '<div class="checkboxPair"><label>', $question['input']); $question['input'] = str_replace("</div>\n", "</label></div>\n", $question['input']); //include linebreak in find/replace string so we don't replace the very last closing </div> (the one that closes the "checkboxList" wrapper div that's around this whole question) } else { if ($question['type'] == 'radios') { //Put labels around each radio items (super hacky string replacement -- this might break in future versions of C5) $question['input'] = str_replace('<div class="radioPair">', '<div class="radioPair"><label>', $question['input']); $question['input'] = str_replace('</div>', '</label></div>', $question['input']); //Make radioList wrapper consistent with checkboxList wrapper $question['input'] = "<div class=\"radioList\">\n{$question['input']}\n</div>\n"; } else { $question['labelFor'] = 'for="Question' . $questionRow['msqID'] . '"'; } } //Remove hardcoded style on textareas if ($question['type'] == 'textarea') { $question['input'] = str_replace('style="width:95%"', '', $question['input']); } $questions[] = $question; } //Prep thank-you message $success = $_GET['surveySuccess'] && $_GET['qsid'] == intval($qsID); $thanksMsg = $this->thankyouMsg; //Prep error message(s) $errorHeader = $this->get('formResponse'); $errors = $this->get('errors'); $errors = is_array($errors) ? $errors : array(); //Send data to the view $this->set('formDomId', $formDomId); $this->set('hasFileUpload', $hasFileUpload); $this->set('qsID', $qsID); $this->set('pURI', $pURI); $this->set('success', $success); $this->set('thanksMsg', $thanksMsg); $this->set('errorHeader', $errorHeader); $this->set('errors', $errors); $this->set('questions', $questions); $this->set('enableSpamHoneypot', $this->enableSpamHoneypot); $this->set('formName', $surveyBlockInfo['surveyName']); //for GA event tracking }