Esempio n. 1
0
<?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
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Block\Form\MiniSurvey;
//$miniSurveyInfo['surveyName']= $bs->surveyName;
$miniSurvey = new MiniSurvey($b);
$miniSurveyInfo = $miniSurvey->getMiniSurveyBlockInfo($b->getBlockID());
MiniSurvey::questionCleanup(intval($miniSurveyInfo['questionSetId']), $b->getBlockID());
$u = new User();
$ui = UserInfo::getByID($u->uID);
?>

<script>
<?php 
if (is_object($b->getProxyBlock())) {
    ?>
	var thisbID=parseInt(<?php 
    echo $b->getProxyBlock()->getBlockID();
    ?>
); 
<?php 
} else {
    ?>
	var thisbID=parseInt(<?php 
    echo $b->getBlockID();
    ?>
); 
<?php 
}
?>
var thisbtID=parseInt(<?php 
Esempio n. 4
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Block\Form\MiniSurvey;
$miniSurvey = new MiniSurvey();
$bID = $_GET['bID'];
//Permissions Check
$bID = $_REQUEST['bID'];
if ($_GET['cID'] && $_GET['arHandle']) {
    $c = Page::getByID($_GET['cID'], 'RECENT');
    $a = Area::get($c, $_GET['arHandle']);
    if (intval($_GET['bID']) == 0) {
        //add survey mode
        $ap = new Permissions($a);
        $bt = BlockType::getByID($_GET['btID']);
        if (!$ap->canAddBlock($bt)) {
            $badPermissions = true;
        }
    } else {
        //edit survey mode
        // this really ought to be refactored
        if (!$a->isGlobalArea()) {
            $b = Block::getByID($_REQUEST['bID'], $c, $a);
            if ($b->getBlockTypeHandle() == BLOCK_HANDLE_SCRAPBOOK_PROXY) {
                $b = Block::getByID($b->getController()->getOriginalBlockID());
                $b->setBlockAreaObject($a);
                $b->loadNewCollection($c);
                $bID = $b->getBlockID();
            }
        } else {
            $b = Block::getByID($_REQUEST['bID'], Stack::getByName($a->getAreaHandle()), STACKS_AREA_NAME);
Esempio n. 5
0
 public function delete()
 {
     $db = Database::connection();
     $deleteData['questionsIDs'] = [];
     $deleteData['strandedAnswerSetIDs'] = [];
     $miniSurvey = new MiniSurvey();
     $info = $miniSurvey->getMiniSurveyBlockInfo($this->bID);
     //get all answer sets
     $q = "SELECT asID FROM {$this->btAnswerSetTablename} WHERE questionSetId = " . intval($info['questionSetId']);
     $answerSetsRS = $db->query($q);
     //delete the questions
     $deleteData['questionsIDs'] = $db->getAll("SELECT qID FROM {$this->btQuestionsTablename} WHERE questionSetId = " . intval($info['questionSetId']) . ' AND bID=' . intval($this->bID));
     foreach ($deleteData['questionsIDs'] as $questionData) {
         $db->query("DELETE FROM {$this->btQuestionsTablename} WHERE qID=" . intval($questionData['qID']));
     }
     //delete left over answers
     $strandedAnswerIDs = $db->getAll('SELECT fa.aID FROM `btFormAnswers` AS fa LEFT JOIN btFormQuestions as fq ON fq.msqID=fa.msqID WHERE fq.msqID IS NULL');
     foreach ($strandedAnswerIDs as $strandedAnswer) {
         $db->query('DELETE FROM `btFormAnswers` WHERE aID=' . intval($strandedAnswer['aID']));
     }
     //delete the left over answer sets
     $deleteData['strandedAnswerSetIDs'] = $db->getAll('SELECT aset.asID FROM btFormAnswerSet AS aset LEFT JOIN btFormAnswers AS fa ON aset.asID=fa.asID WHERE fa.asID IS NULL');
     foreach ($deleteData['strandedAnswerSetIDs'] as $strandedAnswerSetIDs) {
         $db->query('DELETE FROM btFormAnswerSet WHERE asID=' . intval($strandedAnswerSetIDs['asID']));
     }
     //delete the form block
     $q = "delete from {$this->btTable} where bID = '{$this->bID}'";
     $r = $db->query($q);
     parent::delete();
     return $deleteData;
 }
Esempio n. 6
0
 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
 }