public function index()
{
$surveyid = intval(App()->request->getQuery('surveyid'));
$gid = intval(App()->request->getQuery('gid'));
$qid = intval(App()->request->getQuery('qid'));
$fieldtype = sanitize_xss_string(App()->request->getQuery('fieldtype'));
$action = sanitize_xss_string(App()->request->getQuery('action'));
if (!Yii::app()->session['loginID']) {
throw new CHttpException(401);
}
list($replacementFields, $isInstertAnswerEnabled) = $this->_getReplacementFields($fieldtype, $surveyid);
if ($isInstertAnswerEnabled === true) {
//2: Get all other questions that occur before this question that are pre-determined answer types
$fieldmap = createFieldMap($surveyid, 'full', false, false, getBaseLanguageFromSurveyID($surveyid));
$surveyInfo = getSurveyInfo($surveyid);
$surveyformat = $surveyInfo['format'];
// S, G, A
//Go through each question until we reach the current one
//error_log(print_r($qrows,true));
$questionlist = $this->_getQuestionList($action, $gid, $qid, $fieldmap, $fieldtype, $surveyformat);
$childQuestions = $this->_getChildQuestions($questionlist);
}
$data['countfields'] = count($replacementFields);
$data['replFields'] = $replacementFields;
if (isset($childQuestions)) {
$data['cquestions'] = $childQuestions;
}
if (isset($surveyformat)) {
$data['surveyformat'] = $surveyformat;
}
$this->getController()->render('/admin/limeReplacementFields_view', $data);
}
/**
* Function to activate a survey
* @param int $iSurveyID The Survey ID
* @param bool $simulate
* @return string
*/
function activateSurvey($iSurveyID, $simulate = false)
{
$createsurvey = '';
$activateoutput = '';
$createsurveytimings = '';
$fieldstiming = array();
$createsurveydirectory = false;
//Check for any additional fields for this survey and create necessary fields (token and datestamp)
$prow = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
//Get list of questions for the base language
$fieldmap = createFieldMap($iSurveyID, 'full', true, false, getBaseLanguageFromSurveyID($iSurveyID));
$createsurvey = array();
foreach ($fieldmap as $j => $arow) {
switch ($arow['type']) {
case 'startlanguage':
$createsurvey[$arow['fieldname']] = "string(20) NOT NULL";
break;
case 'id':
$createsurvey[$arow['fieldname']] = "pk";
break;
case "startdate":
case "datestamp":
$createsurvey[$arow['fieldname']] = "datetime NOT NULL";
break;
case "submitdate":
$createsurvey[$arow['fieldname']] = "datetime";
break;
case "lastpage":
$createsurvey[$arow['fieldname']] = "integer";
break;
case "N":
//Numerical
//Numerical
case "K":
//Multiple Numerical
$createsurvey[$arow['fieldname']] = "decimal (30,10)";
break;
case "S":
//SHORT TEXT
$createsurvey[$arow['fieldname']] = "text";
break;
case "L":
//LIST (RADIO)
//LIST (RADIO)
case "!":
//LIST (DROPDOWN)
//LIST (DROPDOWN)
case "M":
//Multiple choice
//Multiple choice
case "P":
//Multiple choice with comment
//Multiple choice with comment
case "O":
//DROPDOWN LIST WITH COMMENT
if ($arow['aid'] != 'other' && strpos($arow['aid'], 'comment') === false && strpos($arow['aid'], 'othercomment') === false) {
$createsurvey[$arow['fieldname']] = "string(5)";
} else {
$createsurvey[$arow['fieldname']] = "text";
}
break;
case "U":
//Huge text
//Huge text
case "Q":
//Multiple short text
//Multiple short text
case "T":
//LONG TEXT
//LONG TEXT
case ";":
//Multi Flexi
//Multi Flexi
case ":":
//Multi Flexi
$createsurvey[$arow['fieldname']] = "text";
break;
case "D":
//DATE
$createsurvey[$arow['fieldname']] = "datetime";
break;
case "5":
//5 Point Choice
//5 Point Choice
case "G":
//Gender
//Gender
case "Y":
//YesNo
//YesNo
case "X":
//Boilerplate
$createsurvey[$arow['fieldname']] = "string(1)";
break;
//.........这里部分代码省略.........
/**
* Function to activate a survey
* @param int $iSurveyID The Survey ID
* @param bool $simulate
* @return string
*/
function activateSurvey($iSurveyID, $simulate = false)
{
$createsurvey = '';
$activateoutput = '';
$createsurveytimings = '';
$fieldstiming = array();
$createsurveydirectory = false;
//Check for any additional fields for this survey and create necessary fields (token and datestamp)
$prow = Survey::model()->findByAttributes(array('sid' => $iSurveyID));
//Get list of questions for the base language
$fieldmap = createFieldMap($iSurveyID, 'full', true, false, getBaseLanguageFromSurveyID($iSurveyID));
$createsurvey = array();
foreach ($fieldmap as $j => $arow) {
switch ($arow['type']) {
case 'startlanguage':
$createsurvey[$arow['fieldname']] = "VARCHAR(20) NOT NULL";
break;
case 'id':
$createsurvey[$arow['fieldname']] = "pk";
break;
case "startdate":
case "datestamp":
$createsurvey[$arow['fieldname']] = "datetime NOT NULL";
break;
case "submitdate":
$createsurvey[$arow['fieldname']] = "datetime";
break;
case "lastpage":
$createsurvey[$arow['fieldname']] = "integer";
break;
case "N":
//NUMERICAL
$createsurvey[$arow['fieldname']] = "decimal (30,10)";
break;
case "S":
//SHORT TEXT
if (Yii::app()->db->driverName == 'mysql' || Yii::app()->db->driverName == 'mysqli') {
$createsurvey[$arow['fieldname']] = "text";
} else {
$createsurvey[$arow['fieldname']] = "string";
}
break;
case "L":
//LIST (RADIO)
//LIST (RADIO)
case "!":
//LIST (DROPDOWN)
//LIST (DROPDOWN)
case "M":
//Multiple choice
//Multiple choice
case "P":
//Multiple choice with comment
//Multiple choice with comment
case "O":
//DROPDOWN LIST WITH COMMENT
if ($arow['aid'] != 'other' && strpos($arow['aid'], 'comment') === false && strpos($arow['aid'], 'othercomment') === false) {
$createsurvey[$arow['fieldname']] = "VARCHAR(5)";
} else {
$createsurvey[$arow['fieldname']] = "text";
}
break;
case "K":
// Multiple Numerical
$createsurvey[$arow['fieldname']] = "float";
break;
case "U":
//Huge text
//Huge text
case "Q":
//Multiple short text
//Multiple short text
case "T":
//LONG TEXT
//LONG TEXT
case ";":
//Multi Flexi
//Multi Flexi
case ":":
//Multi Flexi
$createsurvey[$arow['fieldname']] = "text";
break;
case "D":
//DATE
$createsurvey[$arow['fieldname']] = "datetime";
break;
case "5":
//5 Point Choice
//5 Point Choice
case "G":
//Gender
//Gender
case "Y":
//YesNo
//.........这里部分代码省略.........
/**
* Generates statistics
*
* @param int $surveyid The survey id
* @param mixed $allfields
* @param mixed $q2show
* @param mixed $usegraph
* @param string $outputType Optional - Can be xls, html or pdf - Defaults to pdf
* @param string $pdfOutput Sets the target for the PDF output: DD=File download , F=Save file to local disk
* @param string $statlangcode Lamguage for statistics
* @param mixed $browse Show browse buttons
* @return buffer
*/
public function generate_statistics($surveyid, $allfields, $q2show = 'all', $usegraph = 0, $outputType = 'pdf', $pdfOutput = 'I', $sLanguageCode = null, $browse = true)
{
$aStatisticsData = array();
//astatdata generates data for the output page's javascript so it can rebuild graphs on the fly
//load surveytranslator helper
Yii::import('application.helpers.surveytranslator_helper', true);
Yii::import('application.third_party.ar-php.Arabic', true);
$sOutputHTML = "";
//This string carries all the actual HTML code to print.
$sTempDir = Yii::app()->getConfig("tempdir");
$this->pdf = array();
//Make sure $this->pdf exists - it will be replaced with an object if a $this->pdf is actually being created
//pick the best font file if font setting is 'auto'
if (is_null($sLanguageCode)) {
$sLanguageCode = getBaseLanguageFromSurveyID($surveyid);
}
Yii::app()->setLanguage($sLanguageCode);
/*
* this variable is used in the function shortencode() which cuts off a question/answer title
* after $maxchars and shows the rest as tooltip (in html mode)
*/
$maxchars = 13;
//we collect all the html-output within this variable
$sOutputHTML = '';
/**
* $outputType: html || pdf ||
*/
/**
* get/set Survey Details
*/
//no survey ID? -> come and get one
if (!isset($surveyid)) {
$surveyid = returnGlobal('sid');
}
//Get an array of codes of all available languages in this survey
$surveylanguagecodes = Survey::model()->findByPk($surveyid)->additionalLanguages;
$surveylanguagecodes[] = Survey::model()->findByPk($surveyid)->language;
$fieldmap = createFieldMap($surveyid, "full", false, false, $sLanguageCode);
// Set language for questions and answers to base language of this survey
$language = $sLanguageCode;
if ($q2show == 'all') {
$summarySql = " SELECT gid, parent_qid, qid, type " . " FROM {{questions}} WHERE parent_qid=0" . " AND sid={$surveyid} ";
$summaryRs = Yii::app()->db->createCommand($summarySql)->query()->readAll();
foreach ($summaryRs as $field) {
$myField = $surveyid . "X" . $field['gid'] . "X" . $field['qid'];
// Multiple choice get special treatment
if ($field['type'] == "M") {
$myField = "M{$myField}";
}
if ($field['type'] == "P") {
$myField = "P{$myField}";
}
//numerical input will get special treatment (arihtmetic mean, standard derivation, ...)
if ($field['type'] == "N") {
$myField = "N{$myField}";
}
if ($field['type'] == "|") {
$myField = "|{$myField}";
}
if ($field['type'] == "Q") {
$myField = "Q{$myField}";
}
// textfields get special treatment
if ($field['type'] == "S" || $field['type'] == "T" || $field['type'] == "U") {
$myField = "T{$myField}";
}
//statistics for Date questions are not implemented yet.
if ($field['type'] == "D") {
$myField = "D{$myField}";
}
if ($field['type'] == "F" || $field['type'] == "H") {
//Get answers. We always use the answer code because the label might be too long elsewise
$query = "SELECT code, answer FROM {{answers}} WHERE qid='" . $field['qid'] . "' AND scale_id=0 AND language='{$language}' ORDER BY sortorder, answer";
$result = Yii::app()->db->createCommand($query)->query();
$counter2 = 0;
//check all the answers
foreach ($result->readAll() as $row) {
$row = array_values($row);
$myField = "{$myField}{$row[0]}";
}
//$myField = "{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]";
}
if ($q2show == 'all') {
$summary[] = $myField;
}
//$allfields[]=$myField;
}
//.........这里部分代码省略.........
/**
* Loads a survey from the database that has the given ID. If no matching
* survey is found then null is returned. Note that no results are loaded
* from this function call, only survey structure/definition.
*
* In the future it would be nice to load all languages from the db at
* once and have the infrastructure be able to return responses based
* on language codes.
*
* @param int $id
* @return Survey
*/
public function loadSurveyById($id)
{
$survey = new SurveyObj();
$clang = Yii::app()->lang;
$intId = sanitize_int($id);
$survey->id = $intId;
$survey->info = getSurveyInfo($survey->id);
$lang = Survey::model()->findByPk($intId)->language;
$clang = new limesurvey_lang($lang);
$survey->fieldMap = createFieldMap($intId, 'full', false, false, getBaseLanguageFromSurveyID($intId));
// Check to see if timings are present and add to fieldmap if needed
if ($survey->info['savetimings'] == "Y") {
$survey->fieldMap = $survey->fieldMap + createTimingsFieldMap($intId, 'full', false, false, getBaseLanguageFromSurveyID($intId));
}
if (empty($intId)) {
//The id given to us is not an integer, croak.
safeDie("An invalid survey ID was encountered: {$sid}");
}
//Load groups
$sQuery = 'SELECT g.* FROM {{groups}} AS g ' . 'WHERE g.sid = ' . $intId . ' ' . 'ORDER BY g.group_order;';
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->groups = $recordSet;
//Load questions
$sQuery = 'SELECT q.* FROM {{questions}} AS q ' . 'JOIN {{groups}} AS g ON q.gid = g.gid ' . 'WHERE q.sid = ' . $intId . ' AND q.language = \'' . $lang . '\' ' . 'ORDER BY g.group_order, q.question_order;';
$survey->questions = Yii::app()->db->createCommand($sQuery)->query()->readAll();
//Load answers
$sQuery = 'SELECT DISTINCT a.* FROM {{answers}} AS a ' . 'JOIN {{questions}} AS q ON a.qid = q.qid ' . 'WHERE q.sid = ' . $intId . ' AND a.language = \'' . $lang . '\' ' . 'ORDER BY a.qid, a.sortorder;';
//$survey->answers = Yii::app()->db->createCommand($sQuery)->queryAll();
$aAnswers = Yii::app()->db->createCommand($sQuery)->queryAll();
foreach ($aAnswers as $aAnswer) {
$aAnswer['answer'] = stripTagsFull($aAnswer['answer']);
$survey->answers[$aAnswer['qid']][$aAnswer['scale_id']][$aAnswer['code']] = $aAnswer;
}
//Load tokens
if (tableExists('{{tokens_' . $intId . '}}')) {
$sQuery = 'SELECT t.* FROM {{tokens_' . $intId . '}} AS t;';
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->tokens = $recordSet;
} else {
$survey->tokens = array();
}
//Load language settings
$sQuery = 'SELECT * FROM {{surveys_languagesettings}} WHERE surveyls_survey_id = ' . $intId . ';';
$recordSet = Yii::app()->db->createCommand($sQuery)->query()->readAll();
$survey->languageSettings = $recordSet;
return $survey;
}
请发表评论