private function _showReorderForm($iSurveyID) { // Prepare data for the view $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; LimeExpressionManager::StartSurvey($iSurveyID, 'survey'); LimeExpressionManager::StartProcessingPage(true, Yii::app()->baseUrl); $aGrouplist = QuestionGroup::model()->getGroups($iSurveyID); $initializedReplacementFields = false; foreach ($aGrouplist as $iGID => $aGroup) { LimeExpressionManager::StartProcessingGroup($aGroup['gid'], false, $iSurveyID); if (!$initializedReplacementFields) { templatereplace("{SITENAME}"); // Hack to ensure the EM sets values of LimeReplacementFields $initializedReplacementFields = true; } $oQuestionData = Question::model()->getQuestions($iSurveyID, $aGroup['gid'], $sBaseLanguage); $qs = array(); $junk = array(); foreach ($oQuestionData->readAll() as $q) { $relevance = $q['relevance'] == '' ? 1 : $q['relevance']; $question = '[{' . $relevance . '}] ' . $q['question']; LimeExpressionManager::ProcessString($question, $q['qid']); $q['question'] = LimeExpressionManager::GetLastPrettyPrintExpression(); $q['gid'] = $aGroup['gid']; $qs[] = $q; } $aGrouplist[$iGID]['questions'] = $qs; LimeExpressionManager::FinishProcessingGroup(); } LimeExpressionManager::FinishProcessingPage(); $aData['aGroupsAndQuestions'] = $aGrouplist; $aData['surveyid'] = $iSurveyID; $this->_renderWrappedTemplate('survey', 'organizeGroupsAndQuestions_view', $aData); }
/** * Load edit/new question screen depending on $action. * * @access public * @param string $action * @param int $surveyid * @param int $gid * @param int $qid * @return void */ public function index($sa, $surveyid, $gid, $qid = null) { $action = $sa; $surveyid = sanitize_int($surveyid); $gid = sanitize_int($gid); if (isset($qid)) { $qid = sanitize_int($qid); } $aViewUrls = array(); $aData['surveyid'] = $surveyid; $aData['gid'] = $gid; $aData['qid'] = $qid; $aData['display']['menu_bars']['surveysummary'] = 'viewgroup'; $aData['display']['menu_bars']['gid_action'] = 'addquestion'; Yii::app()->session['FileManagerContext'] = "create:question:{$surveyid}"; if (hasSurveyPermission($surveyid, 'surveycontent', 'read')) { $clang = $this->getController()->lang; $surveyinfo = getSurveyInfo($surveyid); Yii::app()->loadHelper('admin/htmleditor'); Yii::app()->loadHelper('surveytranslator'); if (isset($_POST['sortorder'])) { $postsortorder = sanitize_int($_POST['sortorder']); } $aData['adding'] = $adding = $action == 'addquestion'; $aData['copying'] = $copying = $action == 'copyquestion'; $questlangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $baselang = Survey::model()->findByPk($surveyid)->language; $questlangs[] = $baselang; $questlangs = array_flip($questlangs); // Prepare selector Mode TODO: with and without image if (!$adding) { Yii::app()->session['FileManagerContext'] = "edit:question:{$surveyid}"; $aData['display']['menu_bars']['qid_action'] = 'editquestion'; $egresult = Questions::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid)); foreach ($egresult as $esrow) { if (!array_key_exists($esrow->language, $questlangs)) { // Language Exists, BUT ITS NOT ON THE SURVEY ANYMORE. $esrow->delete(); } else { $questlangs[$esrow->language] = 99; } if ($esrow->language == $baselang) { $esrow = $esrow->attributes; $basesettings = array('question_order' => $esrow['question_order'], 'other' => $esrow['other'], 'mandatory' => $esrow['mandatory'], 'type' => $esrow['type'], 'title' => $esrow['title'], 'preg' => $esrow['preg'], 'question' => $esrow['question'], 'help' => $esrow['help']); } } if (!$egresult) { $this->getController()->error('Invalid question id'); } while (list($key, $value) = each($questlangs)) { if ($value != 99) { Questions::model()->insert(array('qid' => $qid, 'sid' => $surveyid, 'gid' => $gid, 'type' => $basesettings['type'], 'title' => $basesettings['title'], 'question' => $basesettings['question'], 'preg' => $basesettings['preg'], 'help' => $basesettings['help'], 'other' => $basesettings['other'], 'mandatory' => $basesettings['mandatory'], 'question_order' => $basesettings['question_order'], 'language' => $key)); } } $eqresult = Questions::model()->with('groups')->together()->findByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid, 'language' => $baselang)); } else { // This is needed to properly color-code content if it contains replacements LimeExpressionManager::StartProcessingPage(false, Yii::app()->baseUrl, true); // so can click on syntax highlighting to edit questions } $qtypelist = getQuestionTypeList('', 'array'); $qDescToCode = 'qDescToCode = {'; $qCodeToInfo = 'qCodeToInfo = {'; foreach ($qtypelist as $qtype => $qdesc) { $qDescToCode .= " '{$qdesc['description']}' : '{$qtype}', \n"; $qCodeToInfo .= " '{$qtype}' : '" . ls_json_encode($qdesc) . "', \n"; } $aData['qTypeOutput'] = "{$qDescToCode} 'null':'null' }; \n {$qCodeToInfo} 'null':'null' };"; if (!$adding) { $eqrow = array_merge($eqresult->attributes, $eqresult->groups->attributes); // Todo: handler in case that record is not found if ($copying) { $eqrow['title'] = ''; } } else { $eqrow['language'] = $baselang; $eqrow['title'] = ''; $eqrow['question'] = ''; $eqrow['help'] = ''; $eqrow['type'] = 'T'; $eqrow['lid'] = 0; $eqrow['lid1'] = 0; $eqrow['gid'] = $gid; $eqrow['other'] = 'N'; $eqrow['mandatory'] = 'N'; $eqrow['preg'] = ''; $eqrow['relevance'] = 1; $eqrow['group_name'] = ''; } $aData['eqrow'] = $eqrow; $aData['surveyid'] = $surveyid; $aData['gid'] = $gid; if (!$adding) { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid)); $criteria->params[':lang'] = $baselang; $criteria->addCondition('language != :lang'); $aqresult = Questions::model()->findAll($criteria); $aData['aqresult'] = $aqresult; } $aData['clang'] = $clang; $aData['action'] = $action; $sumresult1 = Survey::model()->findByPk($surveyid); if (is_null($sumresult1)) { $this->getController()->error('Invalid Survey ID'); } $surveyinfo = $sumresult1->attributes; $surveyinfo = array_map('flattenText', $surveyinfo); $aData['activated'] = $activated = $surveyinfo['active']; if ($activated != "Y") { // Prepare selector Class for javascript function : TODO with or without picture $selectormodeclass = 'full'; if (Yii::app()->session['questionselectormode'] == 'none') { $selectormodeclass = 'none'; } $aData['selectormodeclass'] = $selectormodeclass; } if (!$adding) { $qattributes = questionAttributes(); } else { $qattributes = array(); } if ($adding) { // Get the questions for this group $baselang = Survey::model()->findByPk($surveyid)->language; $oqresult = Questions::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $baselang, 'parent_qid' => 0), array('order' => 'question_order')); $aData['oqresult'] = $oqresult; } $this->getController()->_js_admin_includes(Yii::app()->getConfig('adminscripts') . 'questions.js'); $aViewUrls['editQuestion_view'][] = $aData; $aViewUrls['questionJavascript_view'][] = array('type' => $eqrow['type']); } else { include 'accessDenied.php'; } $this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData); }
/** * Shows the welcome page, used in group by group and question by question mode */ function display_first_page() { global $token, $surveyid, $thissurvey, $navigator; $totalquestions = $_SESSION['survey_' . $surveyid]['totalquestions']; $clang = Yii::app()->lang; // Fill some necessary var for template $navigator = surveymover(); $sitename = Yii::app()->getConfig('sitename'); $languagechanger = makeLanguageChangerSurvey($clang->langcode); sendCacheHeaders(); doHeader(); LimeExpressionManager::StartProcessingPage(); LimeExpressionManager::StartProcessingGroup(-1, false, $surveyid); // start on welcome page $redata = compact(array_keys(get_defined_vars())); $sTemplatePath = $_SESSION['survey_' . $surveyid]['templatepath']; echo templatereplace(file_get_contents($sTemplatePath . "startpage.pstpl"), array(), $redata, 'frontend_helper[2757]'); echo CHtml::form(array("/survey/index"), 'post', array('id' => 'limesurvey', 'name' => 'limesurvey', 'autocomplete' => 'off')); echo "\n\n<!-- START THE SURVEY -->\n"; echo templatereplace(file_get_contents($sTemplatePath . "welcome.pstpl"), array(), $redata, 'frontend_helper[2762]') . "\n"; if ($thissurvey['anonymized'] == "Y") { echo templatereplace(file_get_contents($sTemplatePath . "/privacy.pstpl"), array(), $redata, 'frontend_helper[2765]') . "\n"; } echo templatereplace(file_get_contents($sTemplatePath . "navigator.pstpl"), array(), $redata, 'frontend_helper[2767]'); if ($thissurvey['active'] != "Y") { echo "<p style='text-align:center' class='error'>" . $clang->gT("This survey is currently not active. You will not be able to save your responses.") . "</p>\n"; } echo "\n<input type='hidden' name='sid' value='{$surveyid}' id='sid' />\n"; if (isset($token) && !empty($token)) { echo "\n<input type='hidden' name='token' value='{$token}' id='token' />\n"; } echo "\n<input type='hidden' name='lastgroupname' value='_WELCOME_SCREEN_' id='lastgroupname' />\n"; //This is to ensure consistency with mandatory checks, and new group test $loadsecurity = returnGlobal('loadsecurity', true); if (isset($loadsecurity)) { echo "\n<input type='hidden' name='loadsecurity' value='{$loadsecurity}' id='loadsecurity' />\n"; } $_SESSION['survey_' . $surveyid]['LEMpostKey'] = mt_rand(); echo "<input type='hidden' name='LEMpostKey' value='{$_SESSION['survey_' . $surveyid]['LEMpostKey']}' id='LEMpostKey' />\n"; echo "<input type='hidden' name='thisstep' id='thisstep' value='0' />\n"; echo "\n</form>\n"; echo templatereplace(file_get_contents($sTemplatePath . "endpage.pstpl"), array(), $redata, 'frontend_helper[2782]'); echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); LimeExpressionManager::FinishProcessingPage(); doFooter(); }
/** * Renders template(s) wrapped in header and footer * * Addition of parameters should be avoided if they can be added to $aData * * @param string $sAction Current action, the folder to fetch views from * @param string|array $aViewUrls View url(s) * @param array $aData Data to be passed on. Optional. */ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $aData = array()) { // Gather the data $aData['clang'] = $clang = Yii::app()->lang; $aData['sImageURL'] = Yii::app()->getConfig('adminimageurl'); $aData = $this->_addPseudoParams($aData); $aViewUrls = (array) $aViewUrls; $sViewPath = '/admin/'; if (!empty($sAction)) { $sViewPath .= $sAction . '/'; } // Header if (!isset($aData['display']['header']) || $aData['display']['header'] !== false) { // Send HTTP header header("Content-type: text/html; charset=UTF-8"); // needed for correct UTF-8 encoding Yii::app()->getController()->_getAdminHeader(); } // Menu bars if (!isset($aData['display']['menu_bars']) || $aData['display']['menu_bars'] !== false && (!is_array($aData['display']['menu_bars']) || !in_array('browse', array_keys($aData['display']['menu_bars'])))) { Yii::app()->getController()->_showadminmenu(!empty($aData['surveyid']) ? $aData['surveyid'] : null); if (!empty($aData['surveyid'])) { LimeExpressionManager::StartProcessingPage(false, Yii::app()->baseUrl, true); // so can click on syntax highlighting to edit questions $this->_surveybar($aData['surveyid'], !empty($aData['gid']) ? $aData['gid'] : null); if (isset($aData['display']['menu_bars']['surveysummary'])) { if ((empty($aData['display']['menu_bars']['surveysummary']) || !is_string($aData['display']['menu_bars']['surveysummary'])) && !empty($aData['gid'])) { $aData['display']['menu_bars']['surveysummary'] = 'viewgroup'; } $this->_surveysummary($aData['surveyid'], !empty($aData['display']['menu_bars']['surveysummary']) ? $aData['display']['menu_bars']['surveysummary'] : null, !empty($aData['gid']) ? $aData['gid'] : null); } if (!empty($aData['gid'])) { if (empty($aData['display']['menu_bars']['gid_action']) && !empty($aData['qid'])) { $aData['display']['menu_bars']['gid_action'] = 'viewquestion'; } $this->_questiongroupbar($aData['surveyid'], $aData['gid'], !empty($aData['qid']) ? $aData['qid'] : null, !empty($aData['display']['menu_bars']['gid_action']) ? $aData['display']['menu_bars']['gid_action'] : null); if (!empty($aData['qid'])) { $this->_questionbar($aData['surveyid'], $aData['gid'], $aData['qid'], !empty($aData['display']['menu_bars']['qid_action']) ? $aData['display']['menu_bars']['qid_action'] : null); } } LimeExpressionManager::FinishProcessingPage(); } } if (!empty($aData['display']['menu_bars']['browse']) && !empty($aData['surveyid'])) { $this->_browsemenubar($aData['surveyid'], $aData['display']['menu_bars']['browse']); } if (!empty($aData['display']['menu_bars']['user_group'])) { $this->_userGroupBar(!empty($aData['ugid']) ? $aData['ugid'] : 0); } // Load views foreach ($aViewUrls as $sViewKey => $viewUrl) { if (empty($sViewKey) || !in_array($sViewKey, array('message', 'output'))) { if (is_numeric($sViewKey)) { Yii::app()->getController()->render($sViewPath . $viewUrl, $aData); } elseif (is_array($viewUrl)) { foreach ($viewUrl as $aSubData) { $aSubData = array_merge($aData, $aSubData); Yii::app()->getController()->render($sViewPath . $sViewKey, $aSubData); } } } else { switch ($sViewKey) { // Message case 'message': if (empty($viewUrl['class'])) { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message']); } else { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message'], $viewUrl['class']); } break; // Output // Output case 'output': echo $viewUrl; break; } } } // Footer if (!isset($aData['display']['endscripts']) || $aData['display']['endscripts'] !== false) { Yii::app()->getController()->_loadEndScripts(); } if (!isset($aData['display']['footer']) || $aData['display']['footer'] !== false) { Yii::app()->getController()->_getAdminFooter('http://docs.limesurvey.org', $clang->gT('LimeSurvey online manual')); } }
/** * Shows the welcome page, used in group by group and question by question mode */ function display_first_page() { global $token, $surveyid, $thissurvey, $navigator; $totalquestions = $_SESSION['survey_' . $surveyid]['totalquestions']; // Fill some necessary var for template $aNavigator = surveymover(); $moveprevbutton = $aNavigator['sMovePrevButton']; $movenextbutton = $aNavigator['sMoveNextButton']; $navigator = $moveprevbutton . ' ' . $movenextbutton; $sitename = Yii::app()->getConfig('sitename'); $languagechanger = makeLanguageChangerSurvey(App()->language); sendCacheHeaders(); doHeader(); LimeExpressionManager::StartProcessingPage(); LimeExpressionManager::StartProcessingGroup(-1, false, $surveyid); // start on welcome page $redata = compact(array_keys(get_defined_vars())); $oTemplate = Template::model()->getInstance('', $surveyid); $sTemplatePath = $oTemplate->path; $sTemplateViewPath = $oTemplate->viewPath; echo templatereplace(file_get_contents($sTemplateViewPath . "startpage.pstpl"), array(), $redata, 'frontend_helper[2757]'); echo CHtml::form(array("/survey/index", "sid" => $surveyid), 'post', array('id' => 'limesurvey', 'name' => 'limesurvey', 'autocomplete' => 'off', 'class' => 'frontend_helper')); echo templatereplace(file_get_contents($sTemplateViewPath . "welcome.pstpl"), array(), $redata, 'frontend_helper[2762]') . "\n"; if ($thissurvey['anonymized'] == "Y") { echo templatereplace(file_get_contents($sTemplateViewPath . "/privacy.pstpl"), array(), $redata, 'frontend_helper[2765]') . "\n"; } echo templatereplace(file_get_contents($sTemplateViewPath . "navigator.pstpl"), array(), $redata, 'frontend_helper[2767]'); echo "\n<input type='hidden' name='sid' value='{$surveyid}' id='sid' />\n"; if (isset($token) && !empty($token)) { echo "\n<input type='hidden' name='token' value='{$token}' id='token' />\n"; } echo "\n<input type='hidden' name='lastgroupname' value='_WELCOME_SCREEN_' id='lastgroupname' />\n"; //This is to ensure consistency with mandatory checks, and new group test $loadsecurity = returnGlobal('loadsecurity', true); if (isset($loadsecurity)) { echo "\n<input type='hidden' name='loadsecurity' value='{$loadsecurity}' id='loadsecurity' />\n"; } $_SESSION['survey_' . $surveyid]['LEMpostKey'] = mt_rand(); echo "<input type='hidden' name='LEMpostKey' value='{$_SESSION['survey_' . $surveyid]['LEMpostKey']}' id='LEMpostKey' />\n"; echo "<input type='hidden' name='thisstep' id='thisstep' value='0' />\n"; echo "<!--frontendhelper --></form>"; echo templatereplace(file_get_contents($sTemplateViewPath . "endpage.pstpl"), array(), $redata, 'frontend_helper[2782]'); echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); LimeExpressionManager::FinishProcessingPage(); doFooter(); echo "<!-- end of frontend_helper / display_first_page -->"; }
} } //OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK. //SHOW HEADER $printoutput = ''; if (isset($usepdfexport) && $usepdfexport == 1) { $printoutput .= "<form action='printanswers.php?printableexport=pdf&sid={$surveyid}' method='post'>\n<center><input type='submit' value='" . $clang->gT("PDF Export") . "'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>"; } if (isset($_POST['printableexport'])) { $pdf = new PDF($pdforientation); $pdf->SetFont($pdfdefaultfont, '', $pdffontsize); $pdf->AddPage(); $pdf->titleintopdf($clang->gT("Survey name (ID)", 'unescaped') . ": {$surveyname} ({$surveyid})"); } $printoutput .= "\t<div class='printouttitle'><strong>" . $clang->gT("Survey name (ID):") . "</strong> {$surveyname} ({$surveyid})</div><p> \n"; LimeExpressionManager::StartProcessingPage(true); // means that all variables are on the same page // Since all data are loaded, and don't need JavaScript, pretend all from Group -1 LimeExpressionManager::StartProcessingGroup(-1, $thissurvey['anonymized'] != "N", $surveyid); $bHonorConditions = $printanswershonorsconditions == 1; $aFullResponseTable = aGetFullResponseTable($surveyid, $id, $language, $bHonorConditions); //Get the fieldmap @TODO: do we need to filter out some fields? unset($aFullResponseTable['id']); unset($aFullResponseTable['token']); unset($aFullResponseTable['lastpage']); unset($aFullResponseTable['startlanguage']); unset($aFullResponseTable['datestamp']); unset($aFullResponseTable['startdate']); $printoutput .= "<table class='printouttable' >\n"; if (isset($_POST['printableexport'])) { $pdf->intopdf($clang->gT("Question", 'unescaped') . ": " . $clang->gT("Your answer", 'unescaped'));
/** * Unit test Relevance using a simplified syntax to represent questions. */ static function UnitTestRelevance() { // Tests: varName~relevance~inputType~message $tests = <<<EOT name~1~text~What is your name? age~1~text~How old are you (must be 16-80)? badage~1~expr~{badage=((age<16) || (age>80))} agestop~!is_empty(age) && ((age<16) || (age>80))~message~Sorry, {name}, you are too {if((age<16),'young',if((age>80),'old','middle-aged'))} for this test. kids~!((age<16) || (age>80))~yesno~Do you have children (Y/N)? kidsO~!is_empty(kids) && !(kids=='Y' or kids=='N')~message~Please answer the question about whether you have children with 'Y' or 'N'. wantsKids~kids=='N'~yesno~Do you hope to have kids some day (Y/N)? wantsKidsY~wantsKids=='Y'~message~{name}, I hope you are able to have children some day! wantsKidsN~wantsKids=='N'~message~{name}, I hope you have a wonderfully fulfilling life! wantsKidsO~!is_empty(wantsKids) && !(wantsKids=='Y' or wantsKids=='N')~message~Please answer the question about whether you want children with 'Y' or 'N'. parents~1~expr~{parents = (!badage && kids=='Y')} numKids~kids=='Y'~text~How many children do you have? numKidsValidation~parents and strlen(numKids) > 0 and numKids <= 0~message~{name}, please check your entries. You said you do have children, {numKids} of them, which makes no sense. kid1~numKids >= 1~text~How old is your first child? kid2~numKids >= 2~text~How old is your second child? kid3~numKids >= 3~text~How old is your third child? kid4~numKids >= 4~text~How old is your fourth child? kid5~numKids >= 5~text~How old is your fifth child? sumage~1~expr~{sumage=sum(kid1.NAOK,kid2.NAOK,kid3.NAOK,kid4.NAOK,kid5.NAOK)} report~numKids > 0~message~{name}, you said you are {age} and that you have {numKids} kids. The sum of ages of your first {min(numKids,5)} kids is {sumage}. EOT; $vars = array(); $varsNAOK = array(); $varSeq = array(); $testArgs = array(); $argInfo = array(); LimeExpressionManager::SetDirtyFlag(); $LEM =& LimeExpressionManager::singleton(); LimeExpressionManager::StartProcessingPage(true); LimeExpressionManager::StartProcessingGroup(1); // pretending this is group 1 // collect variables $i = 0; foreach (explode("\n", $tests) as $test) { $args = explode("~", $test); $type = $args[1] == 'expr' ? '*' : $args[1] == 'message' ? 'X' : 'S'; $vars[$args[0]] = array('sgqa' => $args[0], 'code' => '', 'jsName' => 'java' . $args[0], 'jsName_on' => 'java' . $args[0], 'readWrite' => 'Y', 'type' => $type, 'relevanceStatus' => '1', 'gid' => 1, 'gseq' => 1, 'qseq' => $i, 'qid' => $i); $varSeq[] = $args[0]; $testArgs[] = $args; $LEM->questionId2questionSeq[$i] = $i; $LEM->questionId2groupSeq[$i] = 1; $LEM->questionSeq2relevance[$i] = array('relevance' => htmlspecialchars(preg_replace('/[[:space:]]/', ' ', $args[1]), ENT_QUOTES), 'qid' => $i, 'qseq' => $i, 'gseq' => 1, 'jsResultVar' => 'java' . $args[0], 'type' => $type, 'hidden' => false, 'gid' => 1); ++$i; } $LEM->knownVars = $vars; $LEM->gRelInfo[1] = array('gid' => 1, 'gseq' => 1, 'eqn' => '', 'result' => 1, 'numJsVars' => 0, 'relevancejs' => '', 'relevanceVars' => '', 'prettyPrint' => ''); $LEM->ProcessAllNeededRelevance(); // collect relevance $alias2varName = array(); $varNameAttr = array(); for ($i = 0; $i < count($testArgs); ++$i) { $testArg = $testArgs[$i]; $var = $testArg[0]; $rel = LimeExpressionManager::QuestionIsRelevant($i); $question = LimeExpressionManager::ProcessString($testArg[3], $i, NULL, true, 1, 1); $jsVarName = 'java' . str_replace('#', '_', $testArg[0]); $argInfo[] = array('num' => $i, 'name' => $jsVarName, 'sgqa' => $testArg[0], 'type' => $testArg[2], 'question' => $question, 'relevance' => $testArg[1], 'relevanceStatus' => $rel); $alias2varName[$var] = array('jsName' => $jsVarName, 'jsPart' => "'" . $var . "':'" . $jsVarName . "'"); $alias2varName[$jsVarName] = array('jsName' => $jsVarName, 'jsPart' => "'" . $jsVarName . "':'" . $jsVarName . "'"); $varNameAttr[$jsVarName] = "'" . $jsVarName . "':{" . "'jsName':'" . $jsVarName . "','jsName_on':'" . $jsVarName . "','sgqa':'" . substr($jsVarName, 4) . "','qid':" . $i . ",'gid':" . 1 . "}"; } $LEM->alias2varName = $alias2varName; $LEM->varNameAttr = $varNameAttr; LimeExpressionManager::FinishProcessingGroup(); LimeExpressionManager::FinishProcessingPage(); print <<<EOD <script type='text/javascript'> <!-- var LEMradix='.'; function checkconditions(value, name, type, evt_type) { if (typeof evt_type === 'undefined') { evt_type = 'onchange'; } ExprMgr_process_relevance_and_tailoring(evt_type,name,type); } // --> </script> EOD; print LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); // Print Table of questions print "<h3>This is a test of dynamic relevance.</h3>"; print "Enter your name and age, and try all the permutations of answers to whether you have or want children.<br />\n"; print "Note how the text and sum of ages changes dynamically; that prior answers are remembered; and that irrelevant values are not included in the sum of ages.<br />"; print "<table class='table' border='1'><tr><td>"; foreach ($argInfo as $arg) { $rel = LimeExpressionManager::QuestionIsRelevant($arg['num']); print "<div id='question" . $arg['num'] . ($rel ? "'" : "' style='display: none'") . ">\n"; print "<input type='hidden' id='display" . $arg['num'] . "' name='" . $arg['num'] . "' value='" . ($rel ? 'on' : '') . "'/>\n"; if ($arg['type'] == 'expr') { // Hack for testing purposes - rather than using LimeSurvey internals to store the results of equations, process them via a hidden <div> print "<div style='display: none' id='hack_" . $arg['name'] . "'>" . $arg['question']; print "<input type='hidden' id='" . $arg['name'] . "' name='" . $arg['name'] . "' value=''/></div>\n"; } else { print "<table class='table' border='1' width='100%'>\n<tr>\n<td>[Q" . $arg['num'] . "] " . $arg['question'] . "</td>\n"; switch ($arg['type']) { case 'yesno': case 'text': print "<td><input type='text' id='" . $arg['name'] . "' name='" . $arg['sgqa'] . "' value='' onchange='checkconditions(this.value, this.name, this.type)'/></td>\n"; break; case 'message': print "<input type='hidden' id='" . $arg['name'] . "' name='" . $arg['sgqa'] . "' value=''/>\n"; break; } print "</tr>\n</table>\n"; } print "</div>\n"; } print "</table>"; LimeExpressionManager::SetDirtyFlag(); // so subsequent tests don't try to access these variables }
/** * printanswers::view() * View answers at the end of a survey in one place. To export as pdf, set 'usepdfexport' = 1 in lsconfig.php and $printableexport='pdf'. * @param mixed $surveyid * @param bool $printableexport * @return */ function actionView($surveyid, $printableexport = FALSE) { global $siteadminname, $siteadminemail; Yii::app()->loadHelper("frontend"); Yii::import('application.libraries.admin.pdf'); $surveyid = (int) $surveyid; Yii::app()->loadHelper('database'); if (isset($_SESSION['survey_' . $surveyid]['sid'])) { $surveyid = $_SESSION['survey_' . $surveyid]['sid']; } else { die('Invalid survey/session'); } //Debut session time out if (!isset($_SESSION['survey_' . $surveyid]['finished']) || !isset($_SESSION['survey_' . $surveyid]['srid'])) { //require_once($rootdir.'/classes/core/language.php'); $baselang = Survey::model()->findByPk($surveyid)->language; Yii::import('application.libraries.Limesurvey_lang', true); $clang = new Limesurvey_lang($baselang); //A nice exit sendCacheHeaders(); doHeader(); echo templatereplace(file_get_contents(getTemplatePath(validateTemplateDir("default")) . "/startpage.pstpl"), array(), array()); echo "<center><br />\n" . "\t<font color='RED'><strong>" . $clang->gT("Error") . "</strong></font><br />\n" . "\t" . $clang->gT("We are sorry but your session has expired.") . "<br />" . $clang->gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.") . "<br />\n" . "\t" . sprintf($clang->gT("Please contact %s ( %s ) for further assistance."), $siteadminname, $siteadminemail) . "\n" . "</center><br />\n"; echo templatereplace(file_get_contents(getTemplatePath(validateTemplateDir("default")) . "/endpage.pstpl"), array(), array()); doFooter(); exit; } //Fin session time out $id = $_SESSION['survey_' . $surveyid]['srid']; //I want to see the answers with this id $clang = $_SESSION['survey_' . $surveyid]['s_lang']; //Ensure script is not run directly, avoid path disclosure //if (!isset($rootdir) || isset($_REQUEST['$rootdir'])) {die( "browse - Cannot run this script directly");} // Set the language for dispay //require_once($rootdir.'/classes/core/language.php'); // has been secured if (isset($_SESSION['survey_' . $surveyid]['s_lang'])) { $clang = SetSurveyLanguage($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']); $language = $_SESSION['survey_' . $surveyid]['s_lang']; } else { $language = Survey::model()->findByPk($surveyid)->language; $clang = SetSurveyLanguage($surveyid, $language); } // Get the survey inforamtion $thissurvey = getSurveyInfo($surveyid, $language); //SET THE TEMPLATE DIRECTORY if (!isset($thissurvey['templatedir']) || !$thissurvey['templatedir']) { $thistpl = validateTemplateDir("default"); } else { $thistpl = validateTemplateDir($thissurvey['templatedir']); } if ($thissurvey['printanswers'] == 'N') { die; //Die quietly if print answers is not permitted } //CHECK IF SURVEY IS ACTIVATED AND EXISTS $surveytable = "{{survey_{$surveyid}}}"; $surveyname = $thissurvey['surveyls_title']; $anonymized = $thissurvey['anonymized']; //OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK. //SHOW HEADER $printoutput = ''; $printoutput .= "<form action='" . Yii::app()->getController()->createUrl('printanswers/view/surveyid/' . $surveyid . '/printableexport/pdf') . "' method='post'>\n<center><input type='submit' value='" . $clang->gT("PDF export") . "'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>"; if ($printableexport == 'pdf') { require Yii::app()->getConfig('rootdir') . '/application/config/tcpdf.php'; Yii::import('application.libraries.admin.pdf', true); $pdf = new pdf(); $pdf->setConfig($tcpdf); //$pdf->SetFont($pdfdefaultfont,'',$pdffontsize); $pdf->AddPage(); //$pdf->titleintopdf($clang->gT("Survey name (ID)",'unescaped').": {$surveyname} ({$surveyid})"); $pdf->SetTitle($clang->gT("Survey name (ID)", 'unescaped') . ": {$surveyname} ({$surveyid})"); } $printoutput .= "\t<div class='printouttitle'><strong>" . $clang->gT("Survey name (ID):") . "</strong> {$surveyname} ({$surveyid})</div><p> \n"; LimeExpressionManager::StartProcessingPage(true); // means that all variables are on the same page // Since all data are loaded, and don't need JavaScript, pretend all from Group 1 LimeExpressionManager::StartProcessingGroup(1, $thissurvey['anonymized'] != "N", $surveyid); $aFullResponseTable = getFullResponseTable($surveyid, $id, $language, true); //Get the fieldmap @TODO: do we need to filter out some fields? unset($aFullResponseTable['id']); unset($aFullResponseTable['token']); unset($aFullResponseTable['lastpage']); unset($aFullResponseTable['startlanguage']); unset($aFullResponseTable['datestamp']); unset($aFullResponseTable['startdate']); $printoutput .= "<table class='printouttable' >\n"; if ($printableexport == 'pdf') { $pdf->intopdf($clang->gT("Question", 'unescaped') . ": " . $clang->gT("Your answer", 'unescaped')); } $oldgid = 0; $oldqid = 0; foreach ($aFullResponseTable as $sFieldname => $fname) { if (substr($sFieldname, 0, 4) == 'gid_') { if ($printableexport) { $pdf->intopdf(flattenText($fname[0], false, true)); $pdf->ln(2); } else { $printoutput .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n"; } } elseif (substr($sFieldname, 0, 4) == 'qid_') { if ($printableexport == 'pdf') { $pdf->intopdf(flattenText($fname[0] . $fname[1], false, true) . ": " . $fname[2]); $pdf->ln(2); } else { $printoutput .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n"; } } elseif ($sFieldname == 'submitdate') { if ($anonymized != 'Y') { if ($printableexport == 'pdf') { $pdf->intopdf(flattenText($fname[0] . $fname[1], false, true) . ": " . $fname[2]); $pdf->ln(2); } else { $printoutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]} {$sFieldname}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>"; } } } else { if ($printableexport == 'pdf') { $pdf->intopdf(flattenText($fname[0] . $fname[1], false, true) . ": " . $fname[2]); $pdf->ln(2); } else { $printoutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>"; } } } $printoutput .= "</table>\n"; if ($printableexport == 'pdf') { header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); $sExportFileName = sanitize_filename($surveyname); $pdf->Output($sExportFileName . "-" . $surveyid . ".pdf", "D"); } //Display the page with user answers if (!$printableexport) { sendCacheHeaders(); doHeader(); echo templatereplace(file_get_contents(getTemplatePath($thistpl) . '/startpage.pstpl')); echo templatereplace(file_get_contents(getTemplatePath($thistpl) . '/printanswers.pstpl'), array('ANSWERTABLE' => $printoutput)); echo templatereplace(file_get_contents(getTemplatePath($thistpl) . '/endpage.pstpl')); echo "</body></html>"; } LimeExpressionManager::FinishProcessingGroup(); LimeExpressionManager::FinishProcessingPage(); }
/** * Load edit/new question screen depending on $action. * * @access public * @param string $sa subaction * @param int $surveyid * @param int $gid * @param int $qid * @return void */ public function index($sa, $surveyid, $gid, $qid = null) { App()->getClientScript()->registerPackage('qTip2'); $action = $sa; $surveyid = $iSurveyID = sanitize_int($surveyid); $gid = sanitize_int($gid); if (isset($qid)) { $qid = sanitize_int($qid); } $aViewUrls = array(); $aData['surveyid'] = $surveyid; $aData['gid'] = $gid; $aData['qid'] = $qid; $aData['display']['menu_bars']['surveysummary'] = 'viewgroup'; $aData['display']['menu_bars']['gid_action'] = 'addquestion'; $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo; $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")"; $aData['questiongroupbar']['savebutton']['form'] = 'frmeditgroup'; $aData['questiongroupbar']['saveandclosebutton']['form'] = 'frmeditgroup'; $aData['questiongroupbar']['closebutton']['url'] = 'admin/questions/sa/view/surveyid/' . $surveyid . '/gid/' . $gid . '/qid/' . $qid; Yii::app()->session['FileManagerContext'] = "create:question:{$surveyid}"; if (Permission::model()->hasSurveyPermission($surveyid, 'surveycontent', 'read')) { $surveyinfo = getSurveyInfo($surveyid); Yii::app()->loadHelper('admin/htmleditor'); Yii::app()->loadHelper('surveytranslator'); if (isset($_POST['sortorder'])) { $postsortorder = sanitize_int($_POST['sortorder']); } $aData['adding'] = $adding = $action == 'addquestion'; $aData['copying'] = $copying = $action == 'copyquestion'; $questlangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $baselang = Survey::model()->findByPk($surveyid)->language; $questlangs[] = $baselang; $questlangs = array_flip($questlangs); // Prepare selector Mode TODO: with and without image if (!$adding) { Yii::app()->session['FileManagerContext'] = "edit:question:{$surveyid}"; $aData['display']['menu_bars']['qid_action'] = 'editquestion'; $egresult = Question::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid)); foreach ($egresult as $esrow) { if (!array_key_exists($esrow->language, $questlangs)) { // Language Exists, BUT ITS NOT ON THE SURVEY ANYMORE. $esrow->delete(); } else { $questlangs[$esrow->language] = 99; } if ($esrow->language == $baselang) { $esrow = $esrow->attributes; $basesettings = array('question_order' => $esrow['question_order'], 'other' => $esrow['other'], 'mandatory' => $esrow['mandatory'], 'type' => $esrow['type'], 'title' => $esrow['title'], 'preg' => $esrow['preg'], 'question' => $esrow['question'], 'help' => $esrow['help']); } } if (!$egresult) { $this->getController()->error('Invalid question id'); } while (list($key, $value) = each($questlangs)) { if ($value != 99) { $arQuestion = new Question(); $arQuestion->qid = $qid; $arQuestion->sid = $surveyid; $arQuestion->gid = $gid; $arQuestion->type = $basesettings['type']; $arQuestion->title = $basesettings['title']; $arQuestion->question = $basesettings['question']; $arQuestion->preg = $basesettings['preg']; $arQuestion->help = $basesettings['help']; $arQuestion->other = $basesettings['other']; $arQuestion->mandatory = $basesettings['mandatory']; $arQuestion->question_order = $basesettings['question_order']; $arQuestion->language = $key; $arQuestion->insert(); } } $eqresult = Question::model()->with('groups')->together()->findByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid, 'language' => $baselang)); } else { // This is needed to properly color-code content if it contains replacements LimeExpressionManager::StartProcessingPage(false, Yii::app()->baseUrl, true); // so can click on syntax highlighting to edit questions } $qtypelist = getQuestionTypeList('', 'array'); $qDescToCode = 'qDescToCode = {'; $qCodeToInfo = 'qCodeToInfo = {'; foreach ($qtypelist as $qtype => $qdesc) { $qDescToCode .= " '{$qdesc['description']}' : '{$qtype}', \n"; $qCodeToInfo .= " '{$qtype}' : '" . ls_json_encode($qdesc) . "', \n"; } $aData['qTypeOutput'] = "{$qDescToCode} 'null':'null' }; \n {$qCodeToInfo} 'null':'null' };"; if (!$adding) { if (is_object($eqresult->groups)) { $eqrow = array_merge($eqresult->attributes, $eqresult->groups->attributes); } else { $eqrow = $eqresult->attributes; } // Todo: handler in case that record is not found if ($copying) { $eqrow['title'] = ''; } } else { $eqrow['language'] = $baselang; $eqrow['title'] = ''; $eqrow['question'] = ''; $eqrow['help'] = ''; $eqrow['type'] = 'T'; $eqrow['lid'] = 0; $eqrow['lid1'] = 0; $eqrow['gid'] = $gid; $eqrow['other'] = 'N'; $eqrow['mandatory'] = 'N'; $eqrow['preg'] = ''; $eqrow['relevance'] = 1; $eqrow['group_name'] = ''; } $eqrow['conditions_number'] = Condition::Model()->count("qid=:qid", array('qid' => $qid)); if ($eqrow['modulename'] != null) { $oQuestionModule = Question::getQuestionModule($esrow['modulename']); $questionTitle = (array) $oQuestionModule->title; $questionModuleName = (array) $oQuestionModule->modulename; $eqrow['modulename'] = $questionModuleName[0]; $eqrow['moduletitle'] = $questionTitle[0]; } $aData['eqrow'] = $eqrow; $aData['surveyid'] = $surveyid; $aData['gid'] = $gid; if (!$adding) { $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('sid' => $surveyid, 'gid' => $gid, 'qid' => $qid)); $criteria->params[':lang'] = $baselang; $criteria->addCondition('language != :lang'); $aqresult = Question::model()->findAll($criteria); $aData['aqresult'] = $aqresult; } $aData['action'] = $action; $sumresult1 = Survey::model()->findByPk($surveyid); if (is_null($sumresult1)) { $this->getController()->error('Invalid Survey ID'); } $surveyinfo = $sumresult1->attributes; $surveyinfo = array_map('flattenText', $surveyinfo); $aData['activated'] = $activated = $surveyinfo['active']; if ($activated != "Y") { // Prepare selector Class for javascript function if (Yii::app()->session['questionselectormode'] !== 'default') { $selectormodeclass = Yii::app()->session['questionselectormode']; } else { $selectormodeclass = getGlobalSetting('defaultquestionselectormode', 'default'); } $aData['selectormodeclass'] = $selectormodeclass; } if (!$adding) { $qattributes = questionAttributes(); } else { $qattributes = array(); } if ($adding) { // Get the questions for this group $baselang = Survey::model()->findByPk($surveyid)->language; $oqresult = Question::model()->findAllByAttributes(array('sid' => $surveyid, 'gid' => $gid, 'language' => $baselang, 'parent_qid' => 0), array('order' => 'question_order')); $aData['oqresult'] = $oqresult; } App()->getClientScript()->registerScriptFile(App()->getAssetManager()->publish(ADMIN_SCRIPT_PATH . 'questions.js')); $aData['sValidateUrl'] = $adding || $copying ? $this->getController()->createUrl('admin/questions', array('sa' => 'ajaxValidate', 'surveyid' => $surveyid)) : $this->getController()->createUrl('admin/questions', array('sa' => 'ajaxValidate', 'surveyid' => $surveyid, 'qid' => $qid)); $aData['addlanguages'] = Survey::model()->findByPk($surveyid)->additionalLanguages; $aViewUrls['editQuestion_view'][] = $aData; $aViewUrls['questionJavascript_view'][] = array('type' => $eqrow['type']); } else { include 'accessDenied.php'; } $aData['ajaxDatas']['sValidateUrl'] = isset($aData['sValidateUrl']) ? $aData['sValidateUrl'] : $this->getController()->createUrl('admin/questions', array('sa' => 'ajaxValidate', 'surveyid' => $surveyid)); $aData['ajaxDatas']['qTypeOutput'] = $aData['qTypeOutput']; /////////// // sidemenu $aData['sidemenu']['state'] = false; $aData['sidemenu']['explorer']['state'] = true; $aData['sidemenu']['explorer']['gid'] = isset($gid) ? $gid : false; $aData['sidemenu']['explorer']['qid'] = isset($qid) ? $qid : false; $this->_renderWrappedTemplate('survey/Question', $aViewUrls, $aData); }
/** * printanswers::view() * View answers at the end of a survey in one place. To export as pdf, set 'usepdfexport' = 1 in lsconfig.php and $printableexport='pdf'. * @param mixed $surveyid * @param bool $printableexport * @return */ function actionView($surveyid, $printableexport = FALSE) { Yii::app()->loadHelper("frontend"); Yii::import('application.libraries.admin.pdf'); $iSurveyID = (int) $surveyid; $sExportType = $printableexport; Yii::app()->loadHelper('database'); if (isset($_SESSION['survey_' . $iSurveyID]['sid'])) { $iSurveyID = $_SESSION['survey_' . $iSurveyID]['sid']; } else { //die('Invalid survey/session'); } // Get the survey inforamtion // Set the language for dispay if (isset($_SESSION['survey_' . $iSurveyID]['s_lang'])) { $sLanguage = $_SESSION['survey_' . $iSurveyID]['s_lang']; } elseif (Survey::model()->findByPk($iSurveyID)) { $sLanguage = Survey::model()->findByPk($iSurveyID)->language; } else { $iSurveyID = 0; $sLanguage = Yii::app()->getConfig("defaultlang"); } SetSurveyLanguage($iSurveyID, $sLanguage); $aSurveyInfo = getSurveyInfo($iSurveyID, $sLanguage); $oTemplate = Template::model()->getInstance(null, $iSurveyID); //Survey is not finished or don't exist if (!isset($_SESSION['survey_' . $iSurveyID]['finished']) || !isset($_SESSION['survey_' . $iSurveyID]['srid'])) { sendCacheHeaders(); doHeader(); /// $oTemplate is a global variable defined in controller/survey/index echo templatereplace(file_get_contents($oTemplate->viewPath . '/startpage.pstpl'), array()); echo "<center><br />\n" . "\t<font color='RED'><strong>" . gT("Error") . "</strong></font><br />\n" . "\t" . gT("We are sorry but your session has expired.") . "<br />" . gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.") . "<br />\n" . "\t" . sprintf(gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail")) . "\n" . "</center><br />\n"; echo templatereplace(file_get_contents($oTemplate->viewPath . '/endpage.pstpl'), array()); doFooter(); exit; } //Fin session time out $sSRID = $_SESSION['survey_' . $iSurveyID]['srid']; //I want to see the answers with this id //Ensure script is not run directly, avoid path disclosure //if (!isset($rootdir) || isset($_REQUEST['$rootdir'])) {die( "browse - Cannot run this script directly");} //Ensure Participants printAnswer setting is set to true or that the logged user have read permissions over the responses. if ($aSurveyInfo['printanswers'] == 'N' && !Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) { throw new CHttpException(401, 'You are not allowed to print answers.'); } //CHECK IF SURVEY IS ACTIVATED AND EXISTS $sSurveyName = $aSurveyInfo['surveyls_title']; $sAnonymized = $aSurveyInfo['anonymized']; //OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK. //SHOW HEADER if ($sExportType != 'pdf') { $sOutput = CHtml::form(array("printanswers/view/surveyid/{$iSurveyID}/printableexport/pdf"), 'post') . "<center><input class='btn btn-default' type='submit' value='" . gT("PDF export") . "'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>"; $sOutput .= "\t<div class='printouttitle'><strong>" . gT("Survey name (ID):") . "</strong> {$sSurveyName} ({$iSurveyID})</div><p> \n"; LimeExpressionManager::StartProcessingPage(true); // means that all variables are on the same page // Since all data are loaded, and don't need JavaScript, pretend all from Group 1 LimeExpressionManager::StartProcessingGroup(1, $aSurveyInfo['anonymized'] != "N", $iSurveyID); $printanswershonorsconditions = Yii::app()->getConfig('printanswershonorsconditions'); $aFullResponseTable = getFullResponseTable($iSurveyID, $sSRID, $sLanguage, $printanswershonorsconditions); //Get the fieldmap @TODO: do we need to filter out some fields? if ($aSurveyInfo['datestamp'] != "Y" || $sAnonymized == 'Y') { unset($aFullResponseTable['submitdate']); } else { unset($aFullResponseTable['id']); } unset($aFullResponseTable['token']); unset($aFullResponseTable['lastpage']); unset($aFullResponseTable['startlanguage']); unset($aFullResponseTable['datestamp']); unset($aFullResponseTable['startdate']); $sOutput .= "<table class='printouttable' >\n"; foreach ($aFullResponseTable as $sFieldname => $fname) { if (substr($sFieldname, 0, 4) == 'gid_') { $sOutput .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n"; $sOutput .= "\t<tr class='printanswersgroupdesc'><td colspan='2'>{$fname[1]}</td></tr>\n"; } elseif ($sFieldname == 'submitdate') { if ($sAnonymized != 'Y') { $sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]} {$sFieldname}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>"; } } elseif (substr($sFieldname, 0, 4) != 'qid_') { $sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>" . flattenText($fname[2]) . "</td></tr>"; } } $sOutput .= "</table>\n"; $sData['thissurvey'] = $aSurveyInfo; $sOutput = templatereplace($sOutput, array(), $sData, '', $aSurveyInfo['anonymized'] == "Y", NULL, array(), true); // Do a static replacement ob_start(function ($buffer, $phase) { App()->getClientScript()->render($buffer); App()->getClientScript()->reset(); return $buffer; }); ob_implicit_flush(false); sendCacheHeaders(); doHeader(); echo templatereplace(file_get_contents($oTemplate->viewPath . '/startpage.pstpl'), array(), $sData); echo templatereplace(file_get_contents($oTemplate->viewPath . '/printanswers.pstpl'), array('ANSWERTABLE' => $sOutput), $sData); echo templatereplace(file_get_contents($oTemplate->viewPath . '/endpage.pstpl'), array(), $sData); echo "</body></html>"; ob_flush(); } if ($sExportType == 'pdf') { // Get images for TCPDF from template directory define('K_PATH_IMAGES', getTemplatePath($aSurveyInfo['template']) . DIRECTORY_SEPARATOR); Yii::import('application.libraries.admin.pdf', true); Yii::import('application.helpers.pdfHelper'); $aPdfLanguageSettings = pdfHelper::getPdfLanguageSettings(App()->language); $oPDF = new pdf(); $sDefaultHeaderString = $sSurveyName . " (" . gT("ID", 'unescaped') . ":" . $iSurveyID . ")"; $oPDF->initAnswerPDF($aSurveyInfo, $aPdfLanguageSettings, Yii::app()->getConfig('sitename'), $sSurveyName, $sDefaultHeaderString); LimeExpressionManager::StartProcessingPage(true); // means that all variables are on the same page // Since all data are loaded, and don't need JavaScript, pretend all from Group 1 LimeExpressionManager::StartProcessingGroup(1, $aSurveyInfo['anonymized'] != "N", $iSurveyID); $printanswershonorsconditions = Yii::app()->getConfig('printanswershonorsconditions'); $aFullResponseTable = getFullResponseTable($iSurveyID, $sSRID, $sLanguage, $printanswershonorsconditions); //Get the fieldmap @TODO: do we need to filter out some fields? if ($aSurveyInfo['datestamp'] != "Y" || $sAnonymized == 'Y') { unset($aFullResponseTable['submitdate']); } else { unset($aFullResponseTable['id']); } unset($aFullResponseTable['token']); unset($aFullResponseTable['lastpage']); unset($aFullResponseTable['startlanguage']); unset($aFullResponseTable['datestamp']); unset($aFullResponseTable['startdate']); foreach ($aFullResponseTable as $sFieldname => $fname) { if (substr($sFieldname, 0, 4) == 'gid_') { $oPDF->addGidAnswer($fname[0], $fname[1]); } elseif ($sFieldname == 'submitdate') { if ($sAnonymized != 'Y') { $oPDF->addAnswer($fname[0] . " " . $fname[1], $fname[2]); } } elseif (substr($sFieldname, 0, 4) != 'qid_') { $oPDF->addAnswer($fname[0] . " " . $fname[1], $fname[2]); } } header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); $sExportFileName = sanitize_filename($sSurveyName); $oPDF->Output($sExportFileName . "-" . $iSurveyID . ".pdf", "D"); } LimeExpressionManager::FinishProcessingGroup(); LimeExpressionManager::FinishProcessingPage(); }
/** * Renders template(s) wrapped in header and footer * * Addition of parameters should be avoided if they can be added to $aData * * @param string $sAction Current action, the folder to fetch views from * @param string|array $aViewUrls View url(s) * @param array $aData Data to be passed on. Optional. */ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $aData = array()) { // Gather the data $aData['clang'] = $clang = Yii::app()->lang; $aData['sImageURL'] = Yii::app()->getConfig('adminimageurl'); $aData = $this->_addPseudoParams($aData); $aViewUrls = (array) $aViewUrls; $sViewPath = '/pl/'; if (!empty($sAction)) { $sViewPath .= $sAction . '/'; } // Header ob_start(); if (!isset($aData['display']['header']) || $aData['display']['header'] !== false) { // Send HTTP header header("Content-type: text/html; charset=UTF-8"); // needed for correct UTF-8 encoding Yii::app()->getController()->_getPLHeader(); } // Menu bars if (!isset($aData['display']['menu_bars']) || $aData['display']['menu_bars'] !== false && (!is_array($aData['display']['menu_bars']) || !in_array('browse', array_keys($aData['display']['menu_bars'])))) { Yii::app()->getController()->_showPLmenu(!empty($aData['plid']) ? $aData['plid'] : null); if (!empty($aData['plid'])) { LimeExpressionManager::StartProcessingPage(false, Yii::app()->baseUrl, true); // so can click on syntax highlighting to edit questions $this->_surveybar($aData['plid'], !empty($aData['gid']) ? $aData['gid'] : null); LimeExpressionManager::FinishProcessingPage(); } } // Load views foreach ($aViewUrls as $sViewKey => $viewUrl) { if (empty($sViewKey) || !in_array($sViewKey, array('message', 'output'))) { if (is_numeric($sViewKey)) { Yii::app()->getController()->renderPartial($sViewPath . $viewUrl, $aData); } elseif (is_array($viewUrl)) { foreach ($viewUrl as $aSubData) { $aSubData = array_merge($aData, $aSubData); Yii::app()->getController()->renderPartial($sViewPath . $sViewKey, $aSubData); } } } else { switch ($sViewKey) { // Message case 'message': if (empty($viewUrl['class'])) { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message']); } else { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message'], $viewUrl['class']); } break; // Output // Output case 'output': echo $viewUrl; break; } } } // Footer /* if (!isset($aData['display']['endscripts']) || $aData['display']['endscripts'] !== false) Yii::app()->getController()->_loadEndScripts(); */ if (!isset($aData['display']['footer']) || $aData['display']['footer'] !== false) { Yii::app()->getController()->_getPLFooter('http://docs.gowebsurvey.com', $clang->gT('GoWebSurvey Online Manual')); } $out = ob_get_contents(); ob_clean(); App()->getClientScript()->render($out); echo $out; }
$surveysummary .= "<tr>" . "<td align='right' valign='top'><strong>" . $clang->gT("Survey URL") . " (" . getLanguageNameFromCode($surveyinfo['language'], false) . "):</strong></td>\n"; if ($modrewrite) { $tmp_url = $GLOBALS['publicurl'] . '/' . $surveyinfo['sid']; $surveysummary .= "<td align='left'> <a href='{$tmp_url}/lang-" . $surveyinfo['language'] . "' target='_blank'>{$tmp_url}/lang-" . $surveyinfo['language'] . "</a>"; foreach ($aAdditionalLanguages as $langname) { $surveysummary .= " <a href='{$tmp_url}/lang-{$langname}' target='_blank'><img title='" . $clang->gT("Survey URL for language:") . " " . getLanguageNameFromCode($langname, false) . "' alt='" . getLanguageNameFromCode($langname, false) . " " . $clang->gT("Flag") . "' src='../images/flags/{$langname}.png' /></a>"; } } else { $tmp_url = $GLOBALS['publicurl'] . '/index.php?sid=' . $surveyinfo['sid']; $surveysummary .= "<td align='left'> <a href='{$tmp_url}&lang=" . $surveyinfo['language'] . "' target='_blank'>{$tmp_url}&lang=" . $surveyinfo['language'] . "</a>"; foreach ($aAdditionalLanguages as $langname) { $surveysummary .= " <a href='{$tmp_url}&lang={$langname}' target='_blank'><img title='" . $clang->gT("Survey URL for language:") . " " . getLanguageNameFromCode($langname, false) . "' alt='" . getLanguageNameFromCode($langname, false) . " " . $clang->gT("Flag") . "' src='../images/flags/{$langname}.png' /></a>"; } } $surveysummary .= "</td></tr>\n" . "<tr><td align='right' valign='top'><strong>" . $clang->gT("Description:") . "</strong></td>\n<td align='left'>"; LimeExpressionManager::StartProcessingPage(false, $rooturl); // so can click on syntax highlighting to edit questions LimeExpressionManager::StartProcessingGroup($gid, false, $surveyid); // loads list of replacement values available for this group if (trim($surveyinfo['surveyls_description']) != '') { templatereplace($surveyinfo['surveyls_description']); $surveysummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); } $surveysummary .= "</td></tr>\n" . "<tr >\n" . "<td align='right' valign='top'><strong>" . $clang->gT("Welcome:") . "</strong></td>\n" . "<td align='left'>"; templatereplace($surveyinfo['surveyls_welcometext']); $surveysummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); $surveysummary .= "</td></tr>\n" . "<tr ><td align='right' valign='top'><strong>" . $clang->gT("Administrator:") . "</strong></td>\n" . "<td align='left'> {$surveyinfo['admin']} ({$surveyinfo['adminemail']})</td></tr>\n"; if (trim($surveyinfo['faxto']) != '') { $surveysummary .= "<tr><td align='right' valign='top'><strong>" . $clang->gT("Fax to:") . "</strong></td>\n<td align='left'>{$surveyinfo['faxto']}"; $surveysummary .= "</td></tr>\n"; }
/** * dataentry::view() * view a dataentry * @param mixed $surveyid * @param mixed $lang * @return */ public function view($surveyid, $lang = NULL) { $surveyid = sanitize_int($surveyid); $lang = isset($_GET['lang']) ? $_GET['lang'] : NULL; if (isset($lang)) { $lang = sanitize_languagecode($lang); } $aViewUrls = array(); if (Permission::model()->hasSurveyPermission($surveyid, 'responses', 'create')) { $sDataEntryLanguage = Survey::model()->findByPk($surveyid)->language; $surveyinfo = getSurveyInfo($surveyid); $slangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $baselang = Survey::model()->findByPk($surveyid)->language; array_unshift($slangs, $baselang); if (is_null($lang) || !in_array($lang, $slangs)) { $sDataEntryLanguage = $baselang; } else { $sDataEntryLanguage = $lang; } $langlistbox = languageDropdown($surveyid, $sDataEntryLanguage); $thissurvey = getSurveyInfo($surveyid); //This is the default, presenting a blank dataentry form LimeExpressionManager::StartSurvey($surveyid, 'survey', NULL, false, LEM_PRETTY_PRINT_ALL_SYNTAX); $moveResult = LimeExpressionManager::NavigateForwards(); $aData['thissurvey'] = $thissurvey; $aData['langlistbox'] = $langlistbox; $aData['surveyid'] = $surveyid; $aData['sDataEntryLanguage'] = $sDataEntryLanguage; $aData['site_url'] = Yii::app()->homeUrl; LimeExpressionManager::StartProcessingPage(true, Yii::app()->baseUrl); // means that all variables are on the same page $aViewUrls[] = 'caption_view'; Yii::app()->loadHelper('database'); // SURVEY NAME AND DESCRIPTION TO GO HERE $degquery = "SELECT * FROM {{groups}} WHERE sid={$surveyid} AND language='{$sDataEntryLanguage}' ORDER BY {{groups}}.group_order"; $degresult = dbExecuteAssoc($degquery); // GROUP NAME $aDataentryoutput = ''; foreach ($degresult->readAll() as $degrow) { LimeExpressionManager::StartProcessingGroup($degrow['gid'], $thissurvey['anonymized'] != "N", $surveyid); $deqquery = "SELECT * FROM {{questions}} WHERE sid={$surveyid} AND parent_qid=0 AND gid={$degrow['gid']} AND language='{$sDataEntryLanguage}'"; $deqrows = (array) dbExecuteAssoc($deqquery)->readAll(); $aDataentryoutput .= "\t<tr class='info'>\n" . "<!-- Inside controller dataentry.php -->" . "<td colspan='3'><h4>" . flattenText($degrow['group_name'], true) . "</h4></td>\n" . "\t</tr>\n"; $gid = $degrow['gid']; $aDataentryoutput .= "\t<tr class='data-entry-separator'><td colspan='3'></td></tr>\n"; // Perform a case insensitive natural sort on group name then question title of a multidimensional array usort($deqrows, 'groupOrderThenQuestionOrder'); $bgc = 'odd'; foreach ($deqrows as $deqrow) { $cdata = array(); $qidattributes = getQuestionAttributeValues($deqrow['qid']); $cdata['qidattributes'] = $qidattributes; $hidden = isset($qidattributes['hidden']) ? $qidattributes['hidden'] : 0; // TODO - can questions be hidden? Are JavaScript variables names used? Consistently with everywhere else? // LimeExpressionManager::ProcessRelevance($qidattributes['relevance'],$deqrow['qid'],NULL,$deqrow['type'],$hidden); // TMSW Condition->Relevance: Show relevance equation instead of conditions here - better yet, have data entry use survey-at-a-time but with different view $qinfo = LimeExpressionManager::GetQuestionStatus($deqrow['qid']); $relevance = trim($qinfo['info']['relevance']); $explanation = trim($qinfo['relEqn']); $validation = trim($qinfo['prettyValidTip']); $qidattributes = getQuestionAttributeValues($deqrow['qid']); $array_filter_help = flattenText($this->_array_filter_help($qidattributes, $sDataEntryLanguage, $surveyid)); if ($relevance != '' && $relevance != '1' || $validation != '' || $array_filter_help != '') { $showme = '<div class="alert alert-warning col-sm-8 col-sm-offset-2" role="alert">'; if ($bgc == "even") { $bgc = "odd"; } else { $bgc = "even"; } //Do no alternate on explanation row if ($relevance != '' && $relevance != '1') { $showme = '<strong>' . gT("Only answer this if the following conditions are met:", 'html', $sDataEntryLanguage) . "</strong><br />{$explanation}\n"; } if ($validation != '') { $showme .= '<strong>' . gT("The answer(s) must meet these validation criteria:", 'html', $sDataEntryLanguage) . "</strong><br />{$validation}\n"; } if ($showme != '' && $array_filter_help != '') { $showme .= '<br/>'; } if ($array_filter_help != '') { $showme .= '<strong>' . gT("The answer(s) must meet these array_filter criteria:", 'html', $sDataEntryLanguage) . "</strong><br />{$array_filter_help}\n"; } $showme .= '</div>'; $cdata['explanation'] = "<tr class ='data-entry-explanation'><td class='data-entry-small-text' colspan='3' align='left'>{$showme}</td></tr>\n"; } //END OF GETTING CONDITIONS //Alternate bgcolor for different groups if (!isset($bgc)) { $bgc = "even"; } if ($bgc == "even") { $bgc = "odd"; } else { $bgc = "even"; } $qid = $deqrow['qid']; $fieldname = "{$surveyid}" . "X" . "{$gid}" . "X" . "{$qid}"; $cdata['bgc'] = $bgc; $cdata['fieldname'] = $fieldname; $cdata['deqrow'] = $deqrow; $cdata['thissurvey'] = $thissurvey; if ($deqrow['help']) { $hh = addcslashes($deqrow['help'], "..'\""); //Escape ASCII decimal 0-32 plus single and double quotes to make JavaScript happy. $hh = htmlspecialchars($hh, ENT_QUOTES); //Change & " ' < > to HTML entities to make HTML happy. $cdata['hh'] = $hh; } switch ($deqrow['type']) { case "Q": //MULTIPLE SHORT TEXT //MULTIPLE SHORT TEXT case "K": $deaquery = "SELECT question,title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $dearesult = dbExecuteAssoc($deaquery); $cdata['dearesult'] = $dearesult->readAll(); break; case "1": // multi scale^ $deaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$baselang}' ORDER BY question_order"; $dearesult = dbExecuteAssoc($deaquery); $cdata['dearesult'] = $dearesult->readAll(); $oquery = "SELECT other FROM {{questions}} WHERE qid={$deqrow['qid']} AND language='{$baselang}'"; $oresult = dbExecuteAssoc($oquery) or safeDie("Couldn't get other for list question<br />" . $oquery); foreach ($oresult->readAll() as $orow) { $cdata['fother'] = $orow['other']; } break; case "L": //LIST drop-down/radio-button list //LIST drop-down/radio-button list case "!": // $qidattributes=getQuestionAttributeValues($deqrow['qid']); if ($deqrow['type'] == '!' && trim($qidattributes['category_separator']) != '') { $optCategorySeparator = $qidattributes['category_separator']; } else { unset($optCategorySeparator); } $defexists = ""; $deaquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer"; $dearesult = dbExecuteAssoc($deaquery); //$aDataentryoutput .= "\t<select name='$fieldname' class='form-control' >\n"; $aDatatemp = ''; if (!isset($optCategorySeparator)) { foreach ($dearesult->readAll() as $dearow) { $aDatatemp .= "<option value='{$dearow['code']}'"; //if ($dearow['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$dearow['answer']}</option>\n"; } } else { $defaultopts = array(); $optgroups = array(); foreach ($dearesult->readAll() as $dearow) { list($categorytext, $answertext) = explode($optCategorySeparator, $dearow['answer']); if ($categorytext == '') { $defaultopts[] = array('code' => $dearow['code'], 'answer' => $answertext, 'default_value' => $dearow['assessment_value']); } else { $optgroups[$categorytext][] = array('code' => $dearow['code'], 'answer' => $answertext, 'default_value' => $dearow['assessment_value']); } } foreach ($optgroups as $categoryname => $optionlistarray) { $aDatatemp .= "<optgroup class=\"dropdowncategory\" label=\"" . $categoryname . "\">\n"; foreach ($optionlistarray as $optionarray) { $aDatatemp .= "\t<option value='{$optionarray['code']}'"; //if ($optionarray['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$optionarray['answer']}</option>\n"; } $aDatatemp .= "</optgroup>\n"; } foreach ($defaultopts as $optionarray) { $aDatatemp .= "\t<option value='{$optionarray['code']}'"; //if ($optionarray['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$optionarray['answer']}</option>\n"; } } $oquery = "SELECT other FROM {{questions}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}'"; $oresult = dbExecuteAssoc($oquery) or safeDie("Couldn't get other for list question<br />"); foreach ($oresult->readAll() as $orow) { $fother = $orow['other']; } $cdata['fother'] = $fother; $cdata['defexists'] = $defexists; $cdata['datatemp'] = $aDatatemp; break; case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea $defexists = ""; $deaquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer"; $dearesult = dbExecuteAssoc($deaquery); //$aDataentryoutput .= "\t<select name='$fieldname'>\n"; $aDatatemp = ''; foreach ($dearesult->readAll() as $dearow) { $aDatatemp .= "<option value='{$dearow['code']}'"; //if ($dearow['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$dearow['answer']}</option>\n"; } $cdata['datatemp'] = $aDatatemp; $cdata['defexists'] = $defexists; break; case "R": //RANKING TYPE QUESTION $thisqid = $deqrow['qid']; $ansquery = "SELECT * FROM {{answers}} WHERE qid={$thisqid} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer"; $ansresult = dbExecuteAssoc($ansquery); $ansresult = $ansresult->readAll(); $anscount = count($ansresult); $cdata['thisqid'] = $thisqid; $cdata['anscount'] = $anscount; $ansresult = Yii::app()->db->createCommand($ansquery)->query()->readAll(); //Checked $anscount = count($ansresult); $answers = array(); foreach ($ansresult as $ansrow) { $answers[] = $ansrow; } $cdata['answers'] = $answers; App()->getClientScript()->registerPackage('jquery-actual'); $this->registerScriptFile('SCRIPT_PATH', 'ranking.js'); $this->registerCssFile('PUBLIC', 'ranking.css'); unset($answers); break; case "M": //Multiple choice checkbox (Quite tricky really!) if (trim($qidattributes['display_columns']) != '') { $dcols = $qidattributes['display_columns']; } else { $dcols = 0; } $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); $meacount = count($cdata['mearesult']); $cdata['meacount'] = $meacount; $cdata['dcols'] = $dcols; break; case "I": //Language Switch $slangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $sbaselang = Survey::model()->findByPk($surveyid)->language; array_unshift($slangs, $sbaselang); $cdata['slangs'] = $slangs; break; case "P": //Multiple choice with comments checkbox + text //$aDataentryoutput .= "<table border='0'>\n"; $meaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order, question"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); break; case "|": // $qidattributes = getQuestionAttributeValues($deqrow['qid']); $cdata['qidattributes'] = $qidattributes; $maxfiles = $qidattributes['max_num_of_files']; $cdata['maxfiles'] = $maxfiles; break; case "A": //ARRAY (5 POINT CHOICE) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); break; case "B": //ARRAY (10 POINT CHOICE) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); break; case "E": //ARRAY (YES/UNCERTAIN/NO) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or safeDie("Couldn't get answers, Type \"E\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); break; case ":": //ARRAY (Multi Flexi) // $qidattributes=getQuestionAttributeValues($deqrow['qid']); $minvalue = 1; $maxvalue = 10; if (trim($qidattributes['multiflexible_max']) != '' && trim($qidattributes['multiflexible_min']) == '') { $maxvalue = $qidattributes['multiflexible_max']; $minvalue = 1; } if (trim($qidattributes['multiflexible_min']) != '' && trim($qidattributes['multiflexible_max']) == '') { $minvalue = $qidattributes['multiflexible_min']; $maxvalue = $qidattributes['multiflexible_min'] + 10; } if (trim($qidattributes['multiflexible_min']) != '' && trim($qidattributes['multiflexible_max']) != '') { if ($qidattributes['multiflexible_min'] < $qidattributes['multiflexible_max']) { $minvalue = $qidattributes['multiflexible_min']; $maxvalue = $qidattributes['multiflexible_max']; } } if (trim($qidattributes['multiflexible_step']) != '') { $stepvalue = $qidattributes['multiflexible_step']; } else { $stepvalue = 1; } if ($qidattributes['multiflexible_checkbox'] != 0) { $minvalue = 0; $maxvalue = 1; $stepvalue = 1; } $cdata['minvalue'] = $minvalue; $cdata['maxvalue'] = $maxvalue; $cdata['stepvalue'] = $stepvalue; $lquery = "SELECT question, title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} and scale_id=1 and language='{$sDataEntryLanguage}' ORDER BY question_order"; $lresult = dbExecuteAssoc($lquery) or die("Couldn't get labels, Type \":\"<br />{$lquery}<br />"); $lresult = dbExecuteAssoc($lquery); if (!$lresult) { $eMessage = "Couldn't get labels, Type \":\"<br />{$lquery}<br />"; Yii::app()->setFlashMessage($eMessage); $this->getController()->redirect($this->getController()->createUrl("/admin/")); } $cdata['lresult'] = $lresult->readAll(); $meaquery = "SELECT question, title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} and scale_id=0 and language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); if (!$mearesult) { $eMessage = "Couldn't get answers, Type \":\"<br />{$meaquery}<br />"; Yii::app()->setFlashMessage($eMessage); $this->getController()->redirect($this->getController()->createUrl("/admin/")); } $cdata['mearesult'] = $mearesult->readAll(); break; case ";": //ARRAY (Multi Flexi) $lquery = "SELECT * FROM {{questions}} WHERE scale_id=1 and parent_qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY question_order"; $lresult = dbExecuteAssoc($lquery) or die("Couldn't get labels, Type \":\"<br />{$lquery}<br />"); $cdata['lresult'] = $lresult->readAll(); $meaquery = "SELECT * FROM {{questions}} WHERE scale_id=0 and parent_qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or die("Couldn't get answers, Type \":\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); break; case "F": //ARRAY (Flexible Labels) //ARRAY (Flexible Labels) case "H": $meaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or safeDie("Couldn't get answers, Type \"E\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); $fquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY sortorder, code"; $fresult = dbExecuteAssoc($fquery); $cdata['fresult'] = $fresult->readAll(); break; } $cdata['sDataEntryLanguage'] = $sDataEntryLanguage; $viewdata = $this->getController()->renderPartial("/admin/dataentry/content_view", $cdata, TRUE); $viewdata_em = LimeExpressionManager::ProcessString($viewdata, $deqrow['qid'], NULL, false, 1, 1); $aDataentryoutput .= $viewdata_em; } LimeExpressionManager::FinishProcessingGroup(); } LimeExpressionManager::FinishProcessingPage(); $aDataentryoutput .= LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); $aViewUrls['output'] = $aDataentryoutput; $aData['thissurvey'] = $thissurvey; $aData['surveyid'] = $surveyid; $aData['sDataEntryLanguage'] = $sDataEntryLanguage; if ($thissurvey['active'] == "Y" && $thissurvey['allowsave'] == "Y") { $slangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $sbaselang = Survey::model()->findByPk($surveyid)->language; array_unshift($slangs, $sbaselang); $aData['slangs'] = $slangs; $aData['baselang'] = $baselang; } $aViewUrls[] = 'active_html_view'; $aData['sidemenu']['state'] = false; $aData['menu']['edition'] = true; $aData['menu']['save'] = true; $aData['menu']['close'] = true; $this->_renderWrappedTemplate('dataentry', $aViewUrls, $aData); } }
/** * Show the form for Organize question groups/questions * * @todo Change function name to _showOrganizeGroupsAndQuestions? * @param int $iSurveyID * @return void */ private function _showReorderForm($iSurveyID) { $surveyinfo = Survey::model()->findByPk($iSurveyID)->surveyinfo; $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyID . ")"; // Prepare data for the view $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; LimeExpressionManager::StartSurvey($iSurveyID, 'survey'); LimeExpressionManager::StartProcessingPage(true, Yii::app()->baseUrl); $aGrouplist = QuestionGroup::model()->getGroups($iSurveyID); $initializedReplacementFields = false; $aData['organizebar']['savebuttonright'] = true; //$aData['organizebar']['returnbutton']['url'] = $this->getController()->createUrl("admin/survey/sa/view/", array('surveyid' => $iSurveyID)); //$aData['organizebar']['returnbutton']['text'] = gT('Return to survey summary'); foreach ($aGrouplist as $iGID => $aGroup) { LimeExpressionManager::StartProcessingGroup($aGroup['gid'], false, $iSurveyID); if (!$initializedReplacementFields) { templatereplace("{SITENAME}"); // Hack to ensure the EM sets values of LimeReplacementFields $initializedReplacementFields = true; } $oQuestionData = Question::model()->getQuestions($iSurveyID, $aGroup['gid'], $sBaseLanguage); $qs = array(); $junk = array(); foreach ($oQuestionData->readAll() as $q) { $relevance = $q['relevance'] == '' ? 1 : $q['relevance']; $question = '[{' . $relevance . '}] ' . $q['question']; LimeExpressionManager::ProcessString($question, $q['qid']); $q['question'] = viewHelper::stripTagsEM(LimeExpressionManager::GetLastPrettyPrintExpression()); $q['gid'] = $aGroup['gid']; $qs[] = $q; } $aGrouplist[$iGID]['questions'] = $qs; LimeExpressionManager::FinishProcessingGroup(); } LimeExpressionManager::FinishProcessingPage(); $aData['aGroupsAndQuestions'] = $aGrouplist; $aData['surveyid'] = $iSurveyID; $this->_renderWrappedTemplate('survey', 'organizeGroupsAndQuestions_view', $aData); }
/** * printanswers::view() * View answers at the end of a survey in one place. To export as pdf, set 'usepdfexport' = 1 in lsconfig.php and $printableexport='pdf'. * @param mixed $surveyid * @param bool $printableexport * @return */ function actionView($surveyid, $printableexport = FALSE) { Yii::app()->loadHelper("frontend"); Yii::import('application.libraries.admin.pdf'); $iSurveyID = (int) $surveyid; $sExportType = $printableexport; Yii::app()->loadHelper('database'); if (isset($_SESSION['survey_' . $iSurveyID]['sid'])) { $iSurveyID = $_SESSION['survey_' . $iSurveyID]['sid']; } else { //die('Invalid survey/session'); } // Get the survey inforamtion // Set the language for dispay if (isset($_SESSION['survey_' . $iSurveyID]['s_lang'])) { $sLanguage = $_SESSION['survey_' . $iSurveyID]['s_lang']; } elseif (Survey::model()->findByPk($iSurveyID)) { $sLanguage = Survey::model()->findByPk($iSurveyID)->language; } else { $iSurveyID = 0; $sLanguage = Yii::app()->getConfig("defaultlang"); } $clang = SetSurveyLanguage($iSurveyID, $sLanguage); $aSurveyInfo = getSurveyInfo($iSurveyID, $sLanguage); //SET THE TEMPLATE DIRECTORY if (!isset($aSurveyInfo['templatedir']) || !$aSurveyInfo['templatedir']) { $aSurveyInfo['templatedir'] = Yii::app()->getConfig('defaulttemplate'); } $sTemplate = validateTemplateDir($aSurveyInfo['templatedir']); //Survey is not finished or don't exist if (!isset($_SESSION['survey_' . $iSurveyID]['finished']) || !isset($_SESSION['survey_' . $iSurveyID]['srid'])) { sendCacheHeaders(); doHeader(); echo templatereplace(file_get_contents(getTemplatePath($sTemplate) . '/startpage.pstpl'), array()); echo "<center><br />\n" . "\t<font color='RED'><strong>" . $clang->gT("Error") . "</strong></font><br />\n" . "\t" . $clang->gT("We are sorry but your session has expired.") . "<br />" . $clang->gT("Either you have been inactive for too long, you have cookies disabled for your browser, or there were problems with your connection.") . "<br />\n" . "\t" . sprintf($clang->gT("Please contact %s ( %s ) for further assistance."), Yii::app()->getConfig("siteadminname"), Yii::app()->getConfig("siteadminemail")) . "\n" . "</center><br />\n"; echo templatereplace(file_get_contents(getTemplatePath($sTemplate) . '/endpage.pstpl'), array()); doFooter(); exit; } //Fin session time out $sSRID = $_SESSION['survey_' . $iSurveyID]['srid']; //I want to see the answers with this id //Ensure script is not run directly, avoid path disclosure //if (!isset($rootdir) || isset($_REQUEST['$rootdir'])) {die( "browse - Cannot run this script directly");} if ($aSurveyInfo['printanswers'] == 'N') { die; //Die quietly if print answers is not permitted } //CHECK IF SURVEY IS ACTIVATED AND EXISTS $sSurveyName = $aSurveyInfo['surveyls_title']; $sAnonymized = $aSurveyInfo['anonymized']; //OK. IF WE GOT THIS FAR, THEN THE SURVEY EXISTS AND IT IS ACTIVE, SO LETS GET TO WORK. //SHOW HEADER $sOutput = CHtml::form(array("printanswers/view/surveyid/{$iSurveyID}/printableexport/pdf"), 'post') . "<center><input type='submit' value='" . $clang->gT("PDF export") . "'id=\"exportbutton\"/><input type='hidden' name='printableexport' /></center></form>"; if ($sExportType == 'pdf') { //require (Yii::app()->getConfig('rootdir').'/application/config/tcpdf.php'); Yii::import('application.libraries.admin.pdf', true); Yii::import('application.helpers.pdfHelper'); $aPdfLanguageSettings = pdfHelper::getPdfLanguageSettings($clang->langcode); $oPDF = new pdf(); $oPDF->SetTitle($clang->gT("Survey name (ID)", 'unescaped') . ": {$sSurveyName} ({$iSurveyID})"); $oPDF->SetSubject($sSurveyName); $oPDF->SetDisplayMode('fullpage', 'two'); $oPDF->setLanguageArray($aPdfLanguageSettings['lg']); $oPDF->setHeaderFont(array($aPdfLanguageSettings['pdffont'], '', PDF_FONT_SIZE_MAIN)); $oPDF->setFooterFont(array($aPdfLanguageSettings['pdffont'], '', PDF_FONT_SIZE_DATA)); $oPDF->SetFont($aPdfLanguageSettings['pdffont'], '', $aPdfLanguageSettings['pdffontsize']); $oPDF->AddPage(); $oPDF->titleintopdf($clang->gT("Survey name (ID)", 'unescaped') . ": {$sSurveyName} ({$iSurveyID})"); } $sOutput .= "\t<div class='printouttitle'><strong>" . $clang->gT("Survey name (ID):") . "</strong> {$sSurveyName} ({$iSurveyID})</div><p> \n"; LimeExpressionManager::StartProcessingPage(true); // means that all variables are on the same page // Since all data are loaded, and don't need JavaScript, pretend all from Group 1 LimeExpressionManager::StartProcessingGroup(1, $aSurveyInfo['anonymized'] != "N", $iSurveyID); $printanswershonorsconditions = Yii::app()->getConfig('printanswershonorsconditions'); $aFullResponseTable = getFullResponseTable($iSurveyID, $sSRID, $sLanguage, $printanswershonorsconditions); //Get the fieldmap @TODO: do we need to filter out some fields? if ($aSurveyInfo['datestamp'] != "Y" || $sAnonymized == 'Y') { unset($aFullResponseTable['submitdate']); } else { unset($aFullResponseTable['id']); } unset($aFullResponseTable['token']); unset($aFullResponseTable['lastpage']); unset($aFullResponseTable['startlanguage']); unset($aFullResponseTable['datestamp']); unset($aFullResponseTable['startdate']); $sOutput .= "<table class='printouttable' >\n"; foreach ($aFullResponseTable as $sFieldname => $fname) { if (substr($sFieldname, 0, 4) == 'gid_') { $sOutput .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n"; } elseif (substr($sFieldname, 0, 4) == 'qid_') { $sOutput .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n"; } elseif ($sFieldname == 'submitdate') { if ($sAnonymized != 'Y') { $sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]} {$sFieldname}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>"; } } else { $sOutput .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>" . flattenText($fname[2]) . "</td></tr>"; } } $sOutput .= "</table>\n"; $sData['thissurvey'] = $aSurveyInfo; $sOutput = templatereplace($sOutput, array(), $sData, '', $aSurveyInfo['anonymized'] == "Y", NULL, array(), true); // Do a static replacement if ($sExportType == 'pdf') { $oPDF->writeHTML($sOutput); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); $sExportFileName = sanitize_filename($sSurveyName); $oPDF->Output($sExportFileName . "-" . $iSurveyID . ".pdf", "D"); } else { ob_start(function ($buffer, $phase) { App()->getClientScript()->render($buffer); App()->getClientScript()->reset(); return $buffer; }); ob_implicit_flush(false); sendCacheHeaders(); doHeader(); echo templatereplace(file_get_contents(getTemplatePath($sTemplate) . '/startpage.pstpl'), array(), $sData); echo templatereplace(file_get_contents(getTemplatePath($sTemplate) . '/printanswers.pstpl'), array('ANSWERTABLE' => $sOutput), $sData); echo templatereplace(file_get_contents(getTemplatePath($sTemplate) . '/endpage.pstpl'), array(), $sData); echo "</body></html>"; ob_flush(); } LimeExpressionManager::FinishProcessingGroup(); LimeExpressionManager::FinishProcessingPage(); }
/** * Renders template(s) wrapped in header and footer * * Addition of parameters should be avoided if they can be added to $aData * * NOTE FROM LOUIS : We want to remove this function, wich doesn't respect MVC pattern. * The work it's doing should be handle by layout files, and subviews inside views. * Eg : for route "admin/survey/sa/listquestiongroups/surveyid/282267" * the Group controller should use a main layout (with admin menu bar as a widget), then render the list view, in wich the question group bar is called as a subview. * * So for now, we try to evacuate all the renderWrappedTemplate logic (if statements, etc.) to subfunctions, then it will be easier to remove. * Comments starting with //// indicate how it should work in the future * * @param string $sAction Current action, the folder to fetch views from * @param string|array $aViewUrls View url(s) * @param array $aData Data to be passed on. Optional. */ protected function _renderWrappedTemplate($sAction = '', $aViewUrls = array(), $aData = array()) { // Gather the data $aData = $this->_addPseudoParams($aData); //// the check of the surveyid should be done in the Admin controller it self. $aData['sImageURL'] = Yii::app()->getBaseUrl(true) . '/images/lime-icons/328637/'; //// This will be handle by subviews inclusions $aViewUrls = (array) $aViewUrls; $sViewPath = '/admin/'; if (!empty($sAction)) { $sViewPath .= $sAction . '/'; } ob_start(); //// That was used before the MVC pattern, in procedural code. Will not be used anymore. $this->_showHeaders($aData); //// THe headers will be called from the layout $this->_showadminmenu(); //// The admin menu will be called from the layout, probably as a widget for dynamic content. $this->_userGroupBar($aData); //// Here will start the rendering from the controller of the main view. //// For example, the Group controller will use the main.php layout, and then render the view list_group.php //// This view will call as a subview the questiongroupbar, and then _listquestiongroup subview. //// This check will be useless when it will be handle directly by each specific controller. if (!empty($aData['surveyid'])) { //// TODO : check what is doing exactly this function. (application/helpers/expressions/em_manager_helper.php) //// If it's about initialiazing global variables, should be removed and parsed in right controllers. //// But it seems that it's just useless. LimeExpressionManager::StartProcessingPage(false, Yii::app()->baseUrl, true); // so can click on syntax highlighting to edit questions $oSurvey = $aData['oSurvey'] = Survey::model()->findByPk($aData['surveyid']); $this->_titlebar($aData); //// Each view will call the correct bar as a subview. $this->_surveybar($aData); $this->_nquestiongroupbar($aData); $this->_questionbar($aData); $this->_browsemenubar($aData); $this->_tokenbar($aData); $this->_organizequestionbar($aData); //// TODO : check what it's doing exactly, and why it is here (not after or before) //// It seems that it is not used at all. It's about timing LimeExpressionManager::FinishProcessingPage(); //// TODO : Move this div inside each correct view ASAP ! echo '<div class="container-fluid" id="in_survey_common"><div class="row">'; $this->_updatenotification(); $this->_notifications(); //// Here the main content views. $this->_surveysidemenu($aData); $this->_listquestiongroups($aData); $this->_listquestions($aData); $this->_nsurveysummary($aData); } else { /// $this->_fullpagebar($aData); $this->_updatenotification(); $this->_notifications(); //// TODO : Move this div inside each correct view ASAP ! echo ' <!-- Full page, started in Survey_Common_Action::render_wrapped_template() --> <div class="container-fluid full-page-wrapper" id="in_survey_common_action"> <div class="row">'; } //// Here the rendering of all the subviews process. Will not be use anymore, because each subview will be directly called from her parent view. //// TODO : while refactoring, we must replace the use of $aViewUrls by $aData[.. conditions ..], and then call to function such as $this->_nsurveysummary($aData); // Load views foreach ($aViewUrls as $sViewKey => $viewUrl) { if (empty($sViewKey) || !in_array($sViewKey, array('message', 'output'))) { if (is_numeric($sViewKey)) { Yii::app()->getController()->renderPartial($sViewPath . $viewUrl, $aData); } elseif (is_array($viewUrl)) { foreach ($viewUrl as $aSubData) { $aSubData = array_merge($aData, $aSubData); Yii::app()->getController()->renderPartial($sViewPath . $sViewKey, $aSubData); } } } else { switch ($sViewKey) { //// We'll use some Bootstrap alerts, and call them inside each correct view. // Message case 'message': if (empty($viewUrl['class'])) { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message']); } else { Yii::app()->getController()->_showMessageBox($viewUrl['title'], $viewUrl['message'], $viewUrl['class']); } break; // Output // Output case 'output': //// TODO : http://goo.gl/ABl5t5 echo $viewUrl; if (isset($aViewUrls['afteroutput'])) { echo $aViewUrls['afteroutput']; } break; } } } //// TODO : Move this div inside each correct view ASAP ! echo '</div></div>'; //// THe footer will be called directly from the layout. // Footer if (!isset($aData['display']['endscripts']) || $aData['display']['endscripts'] !== false) { Yii::app()->getController()->_loadEndScripts(); } if (!Yii::app()->user->isGuest) { if (!isset($aData['display']['footer']) || $aData['display']['footer'] !== false) { Yii::app()->getController()->_getAdminFooter('http://manual.limesurvey.org', gT('LimeSurvey online manual')); } } $out = ob_get_contents(); ob_clean(); App()->getClientScript()->render($out); echo $out; }
/** * dataentry::view() * view a dataentry * @param mixed $surveyid * @param mixed $lang * @return */ public function view($surveyid, $lang = NULL) { $surveyid = sanitize_int($surveyid); $lang = isset($_GET['lang']) ? $_GET['lang'] : NULL; if (isset($lang)) { $lang = sanitize_languagecode($lang); } $aViewUrls = array(); if (hasSurveyPermission($surveyid, 'responses', 'read')) { $clang = Yii::app()->lang; $sDataEntryLanguage = Survey::model()->findByPk($surveyid)->language; $surveyinfo = getSurveyInfo($surveyid); $slangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $baselang = Survey::model()->findByPk($surveyid)->language; array_unshift($slangs, $baselang); if (is_null($lang) || !in_array($lang, $slangs)) { $sDataEntryLanguage = $baselang; $blang = $clang; } else { Yii::app()->loadLibrary('Limesurvey_lang', array($lang)); $blang = new Limesurvey_lang($lang); $sDataEntryLanguage = $lang; } $langlistbox = languageDropdown($surveyid, $sDataEntryLanguage); $thissurvey = getSurveyInfo($surveyid); //This is the default, presenting a blank dataentry form LimeExpressionManager::StartSurvey($surveyid, 'survey', NULL, false, LEM_PRETTY_PRINT_ALL_SYNTAX); $moveResult = LimeExpressionManager::NavigateForwards(); $aData['thissurvey'] = $thissurvey; $aData['langlistbox'] = $langlistbox; $aData['surveyid'] = $surveyid; $aData['blang'] = $blang; $aData['site_url'] = Yii::app()->homeUrl; LimeExpressionManager::StartProcessingPage(true, Yii::app()->baseUrl); // means that all variables are on the same page $aViewUrls[] = 'caption_view'; Yii::app()->loadHelper('database'); // SURVEY NAME AND DESCRIPTION TO GO HERE $degquery = "SELECT * FROM {{groups}} WHERE sid={$surveyid} AND language='{$sDataEntryLanguage}' ORDER BY {{groups}}.group_order"; $degresult = dbExecuteAssoc($degquery); // GROUP NAME $aDataentryoutput = ''; foreach ($degresult->readAll() as $degrow) { LimeExpressionManager::StartProcessingGroup($degrow['gid'], $thissurvey['anonymized'] != "N", $surveyid); $deqquery = "SELECT * FROM {{questions}} WHERE sid={$surveyid} AND parent_qid=0 AND gid={$degrow['gid']} AND language='{$sDataEntryLanguage}'"; $deqrows = (array) dbExecuteAssoc($deqquery)->readAll(); $aDataentryoutput .= "\t<tr>\n" . "<td colspan='3' align='center'><strong>" . flattenText($degrow['group_name'], true) . "</strong></td>\n" . "\t</tr>\n"; $gid = $degrow['gid']; $aDataentryoutput .= "\t<tr class='data-entry-separator'><td colspan='3'></td></tr>\n"; // Perform a case insensitive natural sort on group name then question title of a multidimensional array usort($deqrows, 'groupOrderThenQuestionOrder'); $bgc = 'odd'; foreach ($deqrows as $deqrow) { $qidattributes = getQuestionAttributeValues($deqrow['qid'], $deqrow['type']); $cdata['qidattributes'] = $qidattributes; $hidden = isset($qidattributes['hidden']) ? $qidattributes['hidden'] : 0; // TODO - can questions be hidden? Are JavaScript variables names used? Consistently with everywhere else? // LimeExpressionManager::ProcessRelevance($qidattributes['relevance'],$deqrow['qid'],NULL,$deqrow['type'],$hidden); // TMSW Conditions->Relevance: Show relevance equation instead of conditions here - better yet, have data entry use survey-at-a-time but with different view $qinfo = LimeExpressionManager::GetQuestionStatus($deqrow['qid']); $relevance = trim($qinfo['info']['relevance']); $explanation = trim($qinfo['relEqn']); $validation = trim($qinfo['prettyValidTip']); $qidattributes = getQuestionAttributeValues($deqrow['qid']); $array_filter_help = flattenText($this->_array_filter_help($qidattributes, $sDataEntryLanguage, $surveyid)); if ($relevance != '' && $relevance != '1' || $validation != '' || $array_filter_help != '') { $showme = ''; if ($bgc == "even") { $bgc = "odd"; } else { $bgc = "even"; } //Do no alternate on explanation row if ($relevance != '' && $relevance != '1') { $showme = "[" . $blang->gT("Only answer this if the following conditions are met:") . "]<br />{$explanation}\n"; } if ($showme != '' && $validation != '') { $showme .= '<br/>'; } if ($validation != '') { $showme .= "[" . $blang->gT("The answer(s) must meet these validation criteria:") . "]<br />{$validation}\n"; } if ($showme != '' && $array_filter_help != '') { $showme .= '<br/>'; } if ($array_filter_help != '') { $showme .= "[" . $blang->gT("The answer(s) must meet these array_filter criteria:") . "]<br />{$array_filter_help}\n"; } $cdata['explanation'] = "<tr class ='data-entry-explanation'><td class='data-entry-small-text' colspan='3' align='left'>{$showme}</td></tr>\n"; } //END OF GETTING CONDITIONS //Alternate bgcolor for different groups if (!isset($bgc)) { $bgc = "even"; } if ($bgc == "even") { $bgc = "odd"; } else { $bgc = "even"; } $qid = $deqrow['qid']; $fieldname = "{$surveyid}" . "X" . "{$gid}" . "X" . "{$qid}"; $cdata['bgc'] = $bgc; $cdata['fieldname'] = $fieldname; $cdata['deqrow'] = $deqrow; $cdata['clang'] = $clang; //DIFFERENT TYPES OF DATA FIELD HERE $cdata['blang'] = $blang; $cdata['thissurvey'] = $thissurvey; if ($deqrow['help']) { $hh = addcslashes($deqrow['help'], "..'\""); //Escape ASCII decimal 0-32 plus single and double quotes to make JavaScript happy. $hh = htmlspecialchars($hh, ENT_QUOTES); //Change & " ' < > to HTML entities to make HTML happy. $cdata['hh'] = $hh; //$aDataentryoutput .= "\t<img src='$imageurl/help.gif' alt='".$blang->gT("Help about this question")."' align='right' onclick=\"javascript:alert('Question {$deqrow['title']} Help: $hh')\" />\n"; } switch ($deqrow['type']) { case "Q": //MULTIPLE SHORT TEXT //MULTIPLE SHORT TEXT case "K": $deaquery = "SELECT question,title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $dearesult = dbExecuteAssoc($deaquery); $cdata['dearesult'] = $dearesult->readAll(); break; case "1": // multi scale^ $deaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$baselang}' ORDER BY question_order"; $dearesult = dbExecuteAssoc($deaquery); $cdata['dearesult'] = $dearesult->readAll(); $oquery = "SELECT other FROM {{questions}} WHERE qid={$deqrow['qid']} AND language='{$baselang}'"; $oresult = dbExecuteAssoc($oquery) or safeDie("Couldn't get other for list question<br />" . $oquery); foreach ($oresult->readAll() as $orow) { $cdata['fother'] = $orow['other']; } break; case "L": //LIST drop-down/radio-button list //LIST drop-down/radio-button list case "!": // $qidattributes=getQuestionAttributeValues($deqrow['qid']); if ($deqrow['type'] == '!' && trim($qidattributes['category_separator']) != '') { $optCategorySeparator = $qidattributes['category_separator']; } else { unset($optCategorySeparator); } $defexists = ""; $deaquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer"; $dearesult = dbExecuteAssoc($deaquery); //$aDataentryoutput .= "\t<select name='$fieldname'>\n"; $aDatatemp = ''; if (!isset($optCategorySeparator)) { foreach ($dearesult->readAll() as $dearow) { $aDatatemp .= "<option value='{$dearow['code']}'"; //if ($dearow['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$dearow['answer']}</option>\n"; } } else { $defaultopts = array(); $optgroups = array(); foreach ($dearesult->readAll() as $dearow) { list($categorytext, $answertext) = explode($optCategorySeparator, $dearow['answer']); if ($categorytext == '') { $defaultopts[] = array('code' => $dearow['code'], 'answer' => $answertext, 'default_value' => $dearow['assessment_value']); } else { $optgroups[$categorytext][] = array('code' => $dearow['code'], 'answer' => $answertext, 'default_value' => $dearow['assessment_value']); } } foreach ($optgroups as $categoryname => $optionlistarray) { $aDatatemp .= "<optgroup class=\"dropdowncategory\" label=\"" . $categoryname . "\">\n"; foreach ($optionlistarray as $optionarray) { $aDatatemp .= "\t<option value='{$optionarray['code']}'"; //if ($optionarray['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$optionarray['answer']}</option>\n"; } $aDatatemp .= "</optgroup>\n"; } foreach ($defaultopts as $optionarray) { $aDatatemp .= "\t<option value='{$optionarray['code']}'"; //if ($optionarray['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$optionarray['answer']}</option>\n"; } } $oquery = "SELECT other FROM {{questions}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}'"; $oresult = dbExecuteAssoc($oquery) or safeDie("Couldn't get other for list question<br />"); foreach ($oresult->readAll() as $orow) { $fother = $orow['other']; } $cdata['fother'] = $fother; $cdata['defexists'] = $defexists; $cdata['datatemp'] = $aDatatemp; break; case "O": //LIST WITH COMMENT drop-down/radio-button list + textarea $defexists = ""; $deaquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer"; $dearesult = dbExecuteAssoc($deaquery); //$aDataentryoutput .= "\t<select name='$fieldname'>\n"; $aDatatemp = ''; foreach ($dearesult->readAll() as $dearow) { $aDatatemp .= "<option value='{$dearow['code']}'"; //if ($dearow['default_value'] == "Y") {$aDatatemp .= " selected='selected'"; $defexists = "Y";} $aDatatemp .= ">{$dearow['answer']}</option>\n"; } $cdata['datatemp'] = $aDatatemp; $cdata['defexists'] = $defexists; break; case "R": //RANKING TYPE QUESTION $thisqid = $deqrow['qid']; $ansquery = "SELECT * FROM {{answers}} WHERE qid={$thisqid} AND language='{$sDataEntryLanguage}' ORDER BY sortorder, answer"; $ansresult = dbExecuteAssoc($ansquery); $ansresult = $ansresult->readAll(); $anscount = count($ansresult); $cdata['thisqid'] = $thisqid; $cdata['anscount'] = $anscount; foreach ($ansresult as $ansrow) { $answers[] = array($ansrow['code'], $ansrow['answer']); } for ($i = 1; $i <= $anscount; $i++) { if (isset($fname)) { $myfname = $fname . $i; } if (isset($myfname) && Yii::app()->session[$myfname]) { $existing++; } } for ($i = 1; $i <= $anscount; $i++) { if (isset($fname)) { $myfname = $fname . $i; } if (isset($myfname) && Yii::app()->session[$myfname]) { foreach ($answers as $ans) { if ($ans[0] == Yii::app()->session[$myfname]) { $thiscode = $ans[0]; $thistext = $ans[1]; } } } if (!isset($ranklist)) { $ranklist = ""; } $ranklist .= " <font color='#000080'>{$i}: <input class='ranklist' type='text' name='RANK{$i}' id='RANK_{$thisqid}{$i}'"; if (isset($myfname) && Yii::app()->session[$myfname]) { $ranklist .= " value='"; $ranklist .= $thistext; $ranklist .= "'"; } $ranklist .= " onFocus=\"this.blur()\" />\n"; $ranklist .= "<input type='hidden' id='d{$fieldname}{$i}' name='{$fieldname}{$i}' value='"; $chosen[] = ""; //create array if (isset($myfname) && Yii::app()->session[$myfname]) { $ranklist .= $thiscode; $chosen[] = array($thiscode, $thistext); } $ranklist .= "' /></font>\n"; $ranklist .= "<img src='" . Yii::app()->getConfig('imageurl') . "/cut.gif' alt='" . $blang->gT("Remove this item") . "' title='" . $blang->gT("Remove this item") . "' "; if (!isset($existing) || $i != $existing) { $ranklist .= "style='display:none'"; } $mfn = $fieldname . $i; $ranklist .= " id='cut_{$thisqid}{$i}' onclick=\"deletethis_{$thisqid}(document.addsurvey.RANK_{$thisqid}{$i}.value, document.addsurvey.d{$fieldname}{$i}.value, document.addsurvey.RANK_{$thisqid}{$i}.id, this.id)\" /><br />\n\n"; } if (!isset($choicelist)) { $choicelist = ""; } $choicelist .= "<select size='{$anscount}' class='choicelist' name='CHOICES' id='CHOICES_{$thisqid}' onclick=\"rankthis_{$thisqid}(this.options[this.selectedIndex].value, this.options[this.selectedIndex].text)\" >\n"; foreach ($answers as $ans) { if (!in_array($ans, $chosen)) { $choicelist .= "\t<option value='{$ans[0]}'>{$ans[1]}</option>\n"; } } $choicelist .= "</select>\n"; $cdata['choicelist'] = $choicelist; $cdata['ranklist'] = $ranklist; if (isset($multifields)) { $cdata['multifields'] = $multifields; } $choicelist = ""; $ranklist = ""; unset($answers); break; case "M": //Multiple choice checkbox (Quite tricky really!) // $qidattributes=getQuestionAttributeValues($deqrow['qid']); if (trim($qidattributes['display_columns']) != '') { $dcols = $qidattributes['display_columns']; } else { $dcols = 0; } $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['dcols'] = $dcols; $cdata['meacount'] = $meacount; $cdata['mearesult'] = $mearesult->readAll(); $meacount = count($cdata['mearesult']); break; case "I": //Language Switch $slangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $sbaselang = Survey::model()->findByPk($surveyid)->language; array_unshift($slangs, $sbaselang); $cdata['slangs'] = $slangs; break; case "P": //Multiple choice with comments checkbox + text //$aDataentryoutput .= "<table border='0'>\n"; $meaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order, question"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); break; case "|": // $qidattributes = getQuestionAttributeValues($deqrow['qid']); $cdata['qidattributes'] = $qidattributes; $maxfiles = $qidattributes['max_num_of_files']; $cdata['maxfiles'] = $maxfiles; break; case "A": //ARRAY (5 POINT CHOICE) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); break; case "B": //ARRAY (10 POINT CHOICE) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); case "C": //ARRAY (YES/UNCERTAIN/NO) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery); $cdata['mearesult'] = $mearesult->readAll(); break; case "E": //ARRAY (YES/UNCERTAIN/NO) radio-buttons $meaquery = "SELECT title, question FROM {{questions}} WHERE parent_qid={$deqrow['qid']} AND language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or safeDie("Couldn't get answers, Type \"E\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); break; case ":": //ARRAY (Multi Flexi) // $qidattributes=getQuestionAttributeValues($deqrow['qid']); $minvalue = 1; $maxvalue = 10; if (trim($qidattributes['multiflexible_max']) != '' && trim($qidattributes['multiflexible_min']) == '') { $maxvalue = $qidattributes['multiflexible_max']; $minvalue = 1; } if (trim($qidattributes['multiflexible_min']) != '' && trim($qidattributes['multiflexible_max']) == '') { $minvalue = $qidattributes['multiflexible_min']; $maxvalue = $qidattributes['multiflexible_min'] + 10; } if (trim($qidattributes['multiflexible_min']) != '' && trim($qidattributes['multiflexible_max']) != '') { if ($qidattributes['multiflexible_min'] < $qidattributes['multiflexible_max']) { $minvalue = $qidattributes['multiflexible_min']; $maxvalue = $qidattributes['multiflexible_max']; } } if (trim($qidattributes['multiflexible_step']) != '') { $stepvalue = $qidattributes['multiflexible_step']; } else { $stepvalue = 1; } if ($qidattributes['multiflexible_checkbox'] != 0) { $minvalue = 0; $maxvalue = 1; $stepvalue = 1; } $cdata['minvalue'] = $minvalue; $cdata['maxvalue'] = $maxvalue; $cdata['stepvalue'] = $stepvalue; $lquery = "SELECT question, title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} and scale_id=1 and language='{$sDataEntryLanguage}' ORDER BY question_order"; $lresult = dbExecuteAssoc($lquery) or die("Couldn't get labels, Type \":\"<br />{$lquery}<br />"); $cdata['lresult'] = $lresult->readAll(); $meaquery = "SELECT question, title FROM {{questions}} WHERE parent_qid={$deqrow['qid']} and scale_id=0 and language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or die("Couldn't get answers, Type \":\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); break; case ";": //ARRAY (Multi Flexi) $lquery = "SELECT * FROM {{questions}} WHERE scale_id=1 and parent_qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY question_order"; $lresult = dbExecuteAssoc($lquery) or die("Couldn't get labels, Type \":\"<br />{$lquery}<br />"); $cdata['lresult'] = $lresult->readAll(); $meaquery = "SELECT * FROM {{questions}} WHERE scale_id=0 and parent_qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or die("Couldn't get answers, Type \":\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); break; case "F": //ARRAY (Flexible Labels) //ARRAY (Flexible Labels) case "H": $meaquery = "SELECT * FROM {{questions}} WHERE parent_qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY question_order"; $mearesult = dbExecuteAssoc($meaquery) or safeDie("Couldn't get answers, Type \"E\"<br />{$meaquery}<br />"); $cdata['mearesult'] = $mearesult->readAll(); $fquery = "SELECT * FROM {{answers}} WHERE qid={$deqrow['qid']} and language='{$sDataEntryLanguage}' ORDER BY sortorder, code"; $fresult = dbExecuteAssoc($fquery); $cdata['fresult'] = $fresult->readAll(); break; } $cdata['sDataEntryLanguage'] = $sDataEntryLanguage; $viewdata = $this->getController()->render("/admin/dataentry/content_view", $cdata, TRUE); $viewdata_em = LimeExpressionManager::ProcessString($viewdata, $deqrow['qid'], NULL, false, 1, 1); $aDataentryoutput .= $viewdata_em; } LimeExpressionManager::FinishProcessingGroup(); } LimeExpressionManager::FinishProcessingPage(); $aDataentryoutput .= LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); $aViewUrls['output'] = $aDataentryoutput; $aData['thissurvey'] = $thissurvey; $aData['surveyid'] = $surveyid; $aData['sDataEntryLanguage'] = $sDataEntryLanguage; if ($thissurvey['active'] == "Y" && $thissurvey['allowsave'] == "Y") { $slangs = Survey::model()->findByPk($surveyid)->additionalLanguages; $sbaselang = Survey::model()->findByPk($surveyid)->language; array_unshift($slangs, $sbaselang); $aData['slangs'] = $slangs; $aData['baselang'] = $baselang; } $aViewUrls[] = 'active_html_view'; $this->_renderWrappedTemplate('dataentry', $aViewUrls, $aData); } }
/** * Shows the welcome page, used in group by group and question by question mode */ function display_first_page() { global $clang, $thistpl, $token, $surveyid, $thissurvey, $navigator, $publicurl; sendcacheheaders(); doHeader(); LimeExpressionManager::StartProcessingPage(); LimeExpressionManager::StartProcessingGroup(-1, false, $surveyid); // start on welcome page echo templatereplace(file_get_contents("{$thistpl}/startpage.pstpl")); echo "\n<form method='post' action='{$publicurl}/index.php' id='limesurvey' name='limesurvey' autocomplete='off'>\n"; echo "\n\n<!-- START THE SURVEY -->\n"; echo templatereplace(file_get_contents("{$thistpl}/welcome.pstpl")) . "\n"; if ($thissurvey['anonymized'] == "Y") { echo templatereplace(file_get_contents("{$thistpl}/privacy.pstpl")) . "\n"; } $navigator = surveymover(); echo templatereplace(file_get_contents("{$thistpl}/navigator.pstpl")); if ($thissurvey['active'] != "Y") { echo "<p style='text-align:center' class='error'>" . $clang->gT("This survey is currently not active. You will not be able to save your responses.") . "</p>\n"; } echo "\n<input type='hidden' name='sid' value='{$surveyid}' id='sid' />\n"; if (isset($token) && !empty($token)) { echo "\n<input type='hidden' name='token' value='{$token}' id='token' />\n"; } echo "\n<input type='hidden' name='lastgroupname' value='_WELCOME_SCREEN_' id='lastgroupname' />\n"; //This is to ensure consistency with mandatory checks, and new group test $loadsecurity = returnglobal('loadsecurity'); if (isset($loadsecurity)) { echo "\n<input type='hidden' name='loadsecurity' value='{$loadsecurity}' id='loadsecurity' />\n"; } $_SESSION['LEMpostKey'] = mt_rand(); echo "<input type='hidden' name='LEMpostKey' value='{$_SESSION['LEMpostKey']}' id='LEMpostKey' />\n"; echo "<input type='hidden' name='thisstep' id='thisstep' value='0' />\n"; echo "\n</form>\n"; echo templatereplace(file_get_contents("{$thistpl}/endpage.pstpl")); echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript(); LimeExpressionManager::FinishProcessingPage(); doFooter(); }