/** * View a single response in detail * * @param mixed $iSurveyID * @param mixed $iId * @param mixed $sBrowseLang */ public function view($iSurveyID, $iId, $sBrowseLang = '') { if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) { $aData = $this->_getData(array('iId' => $iId, 'iSurveyId' => $iSurveyID, 'browselang' => $sBrowseLang)); $sBrowseLanguage = $aData['language']; extract($aData); $aViewUrls = array(); $fieldmap = createFieldMap($iSurveyID, 'full', false, false, $aData['language']); $bHaveToken = $aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID); // Boolean : show (or not) the token if (!Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) { unset($fieldmap['token']); $bHaveToken = false; } //add token to top of list if survey is not private if ($bHaveToken) { $fnames[] = array("token", gT("Token ID"), 'code' => 'token'); $fnames[] = array("firstname", gT("First name"), 'code' => 'firstname'); // or token:firstname ? $fnames[] = array("lastname", gT("Last name"), 'code' => 'lastname'); $fnames[] = array("email", gT("Email"), 'code' => 'email'); } $fnames[] = array("submitdate", gT("Submission date"), gT("Completed"), "0", 'D', 'code' => 'submitdate'); $fnames[] = array("completed", gT("Completed"), "0"); foreach ($fieldmap as $field) { if ($field['fieldname'] == 'lastpage' || $field['fieldname'] == 'submitdate') { continue; } if ($field['type'] == 'interview_time') { continue; } if ($field['type'] == 'page_time') { continue; } if ($field['type'] == 'answer_time') { continue; } //$question = $field['question']; $question = viewHelper::getFieldText($field); if ($field['type'] != "|") { $fnames[] = array($field['fieldname'], viewHelper::getFieldText($field), 'code' => viewHelper::getFieldCode($field, array('LEMcompat' => true))); } elseif ($field['aid'] !== 'filecount') { $qidattributes = getQuestionAttributeValues($field['qid']); for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) { $filenum = sprintf(gT("File %s"), $i + 1); if ($qidattributes['show_title'] == 1) { $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('Title') . ")", 'code' => viewHelper::getFieldCode($field) . '(title)', "type" => "|", "metadata" => "title", "index" => $i); } if ($qidattributes['show_comment'] == 1) { $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('Comment') . ")", 'code' => viewHelper::getFieldCode($field) . '(comment)', "type" => "|", "metadata" => "comment", "index" => $i); } $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('File name') . ")", 'code' => viewHelper::getFieldCode($field) . '(name)', "type" => "|", "metadata" => "name", "index" => $i); $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . gT('File size') . ")", 'code' => viewHelper::getFieldCode($field) . '(size)', "type" => "|", "metadata" => "size", "index" => $i); //$fnames[] = array($field['fieldname'], "File ".($i+1)." - ".$field['question']." (extension)", "type"=>"|", "metadata"=>"ext", "index"=>$i); } } else { $fnames[] = array($field['fieldname'], gT("File count")); } } $nfncount = count($fnames) - 1; if ($iId < 1) { $iId = 1; } $exist = SurveyDynamic::model($iSurveyID)->exist($iId); $next = SurveyDynamic::model($iSurveyID)->next($iId, true); $previous = SurveyDynamic::model($iSurveyID)->previous($iId, true); $aData['exist'] = $exist; $aData['next'] = $next; $aData['previous'] = $previous; $aData['id'] = $iId; $aViewUrls[] = 'browseidheader_view'; if ($exist) { $oPurifier = new CHtmlPurifier(); //SHOW INDIVIDUAL RECORD $oCriteria = new CDbCriteria(); if ($bHaveToken) { $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria); } $oCriteria->addCondition("id = {$iId}"); $iIdresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria); foreach ($iIdresult as $iIdrow) { $iId = $iIdrow['id']; $rlanguage = $iIdrow['startlanguage']; } $aData['bHasFile'] = false; if (isset($rlanguage)) { $aData['rlanguage'] = $rlanguage; } foreach ($iIdresult as $iIdrow) { $highlight = false; for ($i = 0; $i < $nfncount + 1; $i++) { if ($fnames[$i][0] != 'completed' && is_null($iIdrow[$fnames[$i][0]])) { continue; // irrelevant, so don't show } $inserthighlight = ''; if ($highlight) { $inserthighlight = "class='highlight'"; } if ($fnames[$i][0] == 'completed') { if ($iIdrow['submitdate'] == NULL || $iIdrow['submitdate'] == "N") { $answervalue = "N"; } else { $answervalue = "Y"; } } else { if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|") { $index = $fnames[$i]['index']; $metadata = $fnames[$i]['metadata']; $phparray = json_decode_ls($iIdrow[$fnames[$i][0]]); if (isset($phparray[$index])) { switch ($metadata) { case "size": $answervalue = sprintf(gT("%s KB"), intval($phparray[$index][$metadata])); break; case "name": $answervalue = CHtml::link($oPurifier->purify(rawurldecode($phparray[$index][$metadata])), $this->getController()->createUrl("/admin/responses", array("sa" => "actionDownloadfile", "surveyid" => $surveyid, "iResponseId" => $iId, "sFileName" => $phparray[$index][$metadata]))); break; default: $answervalue = htmlspecialchars(strip_tags(stripJavaScript($phparray[$index][$metadata]))); } $aData['bHasFile'] = true; } else { $answervalue = ""; } } else { $answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $sBrowseLanguage))), ENT_QUOTES); } } $aData['answervalue'] = $answervalue; $aData['inserthighlight'] = $inserthighlight; $aData['fnames'] = $fnames; $aData['i'] = $i; $aViewUrls['browseidrow_view'][] = $aData; } } } else { Yii::app()->session['flashmessage'] = gT("This response ID is invalid."); } $aViewUrls[] = 'browseidfooter_view'; $aData['sidemenu']['state'] = false; $aData['menu']['edition'] = true; $aData['menu']['view'] = true; $aData['menu']['close'] = true; // This resets the url on the close button to go to the upper view $aData['menu']['closeurl'] = $this->getController()->createUrl("admin/responses/sa/browse/surveyid/" . $iSurveyId); $this->_renderWrappedTemplate('', $aViewUrls, $aData); } else { $aData = array(); $aData['surveyid'] = $iSurveyID; $message = array(); $message['title'] = gT('Access denied!'); $message['message'] = gT('You do not have permission to access this page.'); $message['class'] = "error"; $this->_renderWrappedTemplate('survey', array("message" => $message), $aData); } }
{ ?> <td><?php echo rawurldecode($phparray[$index][$metadata]); ?></td> <?php } } else { ?> <td> </td> <?php } } else { if (isset($fnames[$i][4]) && $fnames[$i][4] == 'D' && $fnames[$i][0] != '') { if ($dtrow[$fnames[$i][0]] == NULL) $browsedatafield = "N"; else $browsedatafield = "Y"; } else { $browsedatafield = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($surveyid, $fnames[$i][0], $dtrow[$fnames[$i][0]], $oBrowseLanguage))), ENT_QUOTES); } echo "<td><span>$browsedatafield</span></td>\n"; } } ?> </tr>
/** * Creates an array with details on a particular response for display purposes * Used in Print answers, Detailed response view and Detailed admin notification email * * @param mixed $iSurveyID * @param mixed $iResponseID * @param mixed $sLanguageCode * @param boolean $bHonorConditions Apply conditions */ function getFullResponseTable($iSurveyID, $iResponseID, $sLanguageCode, $bHonorConditions = true) { $aFieldMap = createFieldMap($iSurveyID, 'full', false, false, $sLanguageCode); //Get response data $idrow = SurveyDynamic::model($iSurveyID)->findByAttributes(array('id' => $iResponseID)); // Create array of non-null values - those are the relevant ones $aRelevantFields = array(); foreach ($aFieldMap as $sKey => $fname) { if (LimeExpressionManager::QuestionIsRelevant($fname['qid']) || $bHonorConditions == false) { $aRelevantFields[$sKey] = $fname; } } $aResultTable = array(); $oldgid = 0; $oldqid = 0; foreach ($aRelevantFields as $sKey => $fname) { if (!empty($fname['qid'])) { $attributes = getQuestionAttributeValues($fname['qid']); if (getQuestionAttributeValue($attributes, 'hidden') == 1) { continue; } } $question = $fname['question']; $subquestion = ''; if (isset($fname['gid']) && !empty($fname['gid'])) { //Check to see if gid is the same as before. if not show group name if ($oldgid !== $fname['gid']) { $oldgid = $fname['gid']; if (LimeExpressionManager::GroupIsRelevant($fname['gid']) || $bHonorConditions == false) { $aResultTable['gid_' . $fname['gid']] = array($fname['group_name'], QuestionGroup::model()->getGroupDescription($fname['gid'], $sLanguageCode)); } } } if (!empty($fname['qid'])) { if ($oldqid !== $fname['qid']) { $oldqid = $fname['qid']; if (isset($fname['subquestion']) || isset($fname['subquestion1']) || isset($fname['subquestion2'])) { $aResultTable['qid_' . $fname['sid'] . 'X' . $fname['gid'] . 'X' . $fname['qid']] = array($fname['question'], '', ''); } else { $answer = getExtendedAnswer($iSurveyID, $fname['fieldname'], $idrow[$fname['fieldname']], $sLanguageCode); $aResultTable[$fname['fieldname']] = array($question, '', $answer); continue; } } } else { $answer = getExtendedAnswer($iSurveyID, $fname['fieldname'], $idrow[$fname['fieldname']], $sLanguageCode); $aResultTable[$fname['fieldname']] = array($question, '', $answer); continue; } if (isset($fname['subquestion'])) { $subquestion = "[{$fname['subquestion']}]"; } if (isset($fname['subquestion1'])) { $subquestion = "[{$fname['subquestion1']}]"; } if (isset($fname['subquestion2'])) { $subquestion .= "[{$fname['subquestion2']}]"; } $answer = getExtendedAnswer($iSurveyID, $fname['fieldname'], $idrow[$fname['fieldname']], $sLanguageCode); $aResultTable[$fname['fieldname']] = array($question, $subquestion, $answer); } return $aResultTable; }
/** * Returns survey responses in json format for a given survey * * @access public * @param $iSurveyID : survey id * @return json */ public function getResponses_json($iSurveyID) { if (!Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) { Yii::app()->end(); } $aData = $this->_getData($iSurveyID); $bHaveToken = $aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID) && Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read'); extract($aData); $aViewUrls = array(); $sBrowseLanguage = $aData['language']; $sImageURL = Yii::app()->getConfig('adminimageurl'); $fnames = array(); $aSpecificColumns = array('submitdate', 'token', 'id', 'lastpage'); $aFieldmap = createFieldMap($iSurveyID, 'full', true, false, $aData['language']); // Get the survey responses $sOrder = Yii::app()->request->getPost('sord') == 'desc' ? 'desc' : 'asc'; $sOrderBy = Yii::app()->request->getPost('sidx', 'id'); $iPage = Yii::app()->request->getPost('page', 1); $iLimit = Yii::app()->request->getPost('rows', 50); // Default to 50 ? // Old behaviour : ajax default request from jqgrid need sort / rows (limit) / page (start) / sidx for order by : use javacript log please .... $oCriteria = new CDbCriteria(); //Create the query if ($bHaveToken) { $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria); $aSpecificColumns = array_merge($aSpecificColumns, TokenDynamic::model($iSurveyID)->getTableSchema()->getColumnNames()); } if (incompleteAnsFilterState() == "incomplete") { $oCriteria->addCondition("submitdate IS NULL"); } elseif (incompleteAnsFilterState() == "complete") { $oCriteria->addCondition("submitdate IS NOT NULL"); } //Get the filter data //if (Yii::app()->request->getPost('sql') && stripcslashes(Yii::app()->request->getPost('sql')) !== "" && Yii::app()->request->getPost('sql') != "NULL") // $oCriteria->addCondition(stripcslashes(Yii::app()->request->getPost('sql'))); $aKnowColumns = array_keys(SurveyDynamic::model($iSurveyID)->attributes); if ($bHaveToken) { $aKnowColumns[] = 'firstname'; $aKnowColumns[] = 'lastname'; $aKnowColumns[] = 'email'; } switch ($sOrderBy) { case 'completed': $sOrderBy = 'submitdate'; break; default: if (!in_array($sOrderBy, $aKnowColumns)) { Yii::trace("unknow column {$sOrderBy} in json request"); $sOrderBy = 'id'; } } $sOrderBy = Yii::app()->db->quoteColumnName($sOrderBy); // Maybe need to fix if $sOrderBy is in columns name $oCriteria->order = "{$sOrderBy} {$sOrder}"; if (Yii::app()->request->getParam('_search')) { if ($value = Yii::app()->request->getParam('completed')) { if ($value == 'Y') { $oCriteria->addCondition("submitdate IS NOT NULL"); Yii::app()->session['incompleteanswers'] = 'complete'; } elseif ($value == 'N') { $oCriteria->addCondition("submitdate IS NULL"); Yii::app()->session['incompleteanswers'] = 'incomplete'; } else { Yii::app()->session['incompleteanswers'] = 'all'; } } //Get the filter data if (App()->request->getQuery('statfilter') && is_array(Yii::app()->session['statistics_selects_' . $iSurveyID])) { foreach (Yii::app()->session['statistics_selects_' . $iSurveyID] as $sCondition) { $oCriteria->addCondition($sCondition); } } foreach ($aKnowColumns as $sFiltering) { if ($value = Yii::app()->request->getParam($sFiltering)) { if ($sFiltering == 'token') { $sFiltering = 'tokens.token'; } $oCriteria->compare(Yii::app()->db->quoteColumnName($sFiltering), $value, true); } } if ($sFilters = Yii::app()->request->getParam('filters')) { $aFilters = json_decode($sFilters); // TODO : groupOp and rules } } // Elements for nav bar of jquery $iCount = SurveyDynamic::model($iSurveyID)->count($oCriteria); // or die("Couldn't get response data<br />"); $iLimit = (int) $iLimit > 0 ? (int) $iLimit : 50; if (!$iLimit || $iLimit > $iCount) { $iLimit = $iCount; } $iStart = (int) $iPage > 0 ? (int) $iPage * $iLimit - $iLimit : 0; $aSurveyEntries = new stdClass(); $aSurveyEntries->page = $iPage; // Did we need to fix page ? $aSurveyEntries->total = $iCount > 0 ? ceil($iCount / $iLimit) : 0; $aSurveyEntries->records = $iCount; // Last criteria update $oCriteria->offset = $iStart; $oCriteria->limit = $iLimit; // Get the rows $dtresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria); $all_rows = array(); foreach ($dtresult as $row) { // View detail icon $action_html = '<a href="' . Yii::app()->createUrl("admin/responses/view/surveyid/{$surveyid}/id/{$row['id']}") . '"><span class="glyphicon glyphicon-list-alt text-success" title="' . gT('View response details') . '"></span></a>'; // Edit icon if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'update')) { $action_html .= "<a href='" . Yii::app()->createUrl("admin/dataentry/editdata/subaction/edit/surveyid/{$surveyid}/id/{$row['id']}") . "'>\n <span class='glyphicon glyphicon-pencil text-success' title='" . gT('Edit this response') . "'></span></a>"; } // Download icon if (hasFileUploadQuestion($surveyid)) { if (Response::model($surveyid)->findByPk($row['id'])->getFiles()) { $action_url = Yii::app()->createUrl("admin/responses", array("sa" => "actionDownloadfiles", "surveyid" => $surveyid, "sResponseId" => $row['id'])); $action_html .= '<a title="' . gT('Download all files in this response as a zip file') . '" href="' . $action_url . '"><span class="glyphicon glyphicon-download-alt downloadfile"></span></a>'; } } // Delete icon if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'delete')) { $action_html .= "<a href='" . Yii::app()->createUrl("admin/responses", array("sa" => "actionDelete", "surveyid" => $surveyid, "sResponseId" => $row['id'])) . "' data-delete='" . $row['id'] . "'>\n <span title='" . sprintf(gT('Delete response %s'), $row['id']) . "' class='deleteresponse glyphicon glyphicon-trash text-warning'></span></a>"; } $aSurveyEntry = array(); $aSurveyEntry[] = $action_html; $aSurveyEntry[] = $row['id']; $aSurveyEntry[] = $row['lastpage']; // completed $aSurveyEntry[] = empty($row['submitdate']) ? 'N' : 'Y'; if ($bHaveToken) { if (is_null($row['tid'])) { $aSurveyEntry[] = strip_tags($row['token']); } else { $aSurveyEntry[] = "<a href='" . Yii::app()->createUrl("admin/tokens", array("sa" => "edit", "surveyid" => $surveyid, "tokenid" => $row['tid'])) . "'>" . strip_tags($row['token']) . "</a>"; } $aSurveyEntry[] = strip_tags($row['firstname']); $aSurveyEntry[] = strip_tags($row['lastname']); $aSurveyEntry[] = strip_tags($row['email']); } // startlanguage //$aSurveyEntry[] = $row['startlanguage']; foreach ($row as $aFieldName => $mFieldValue) { if (in_array($aFieldName, $aSpecificColumns)) { continue; } $sSurveyEntry = strip_tags(getExtendedAnswer($iSurveyID, $aFieldName, $mFieldValue, $sBrowseLanguage)); // This fix XSS and get the value if ($aFieldmap[$aFieldName]['type'] == '|' && strpos($aFieldName, 'filecount') === false) { $aQuestionAttributes = getQuestionAttributeValues($aFieldmap[$aFieldName]['qid']); $aFilesInfo = json_decode_ls($mFieldValue); for ($iFileIndex = 0; $iFileIndex < $aQuestionAttributes['max_num_of_files']; $iFileIndex++) { if (isset($aFilesInfo[$iFileIndex])) { $aSurveyEntry[] = htmlspecialchars($aFilesInfo[$iFileIndex]['title'], ENT_QUOTES, 'UTF-8'); $aSurveyEntry[] = htmlspecialchars($aFilesInfo[$iFileIndex]['comment'], ENT_QUOTES, 'UTF-8'); $aSurveyEntry[] = CHtml::link(rawurldecode($aFilesInfo[$iFileIndex]['name']), $this->getController()->createUrl("/admin/responses", array("sa" => "actionDownloadfile", "surveyid" => $surveyid, "iResponseId" => $row['id'], "sFileName" => $aFilesInfo[$iFileIndex]['name']))); $aSurveyEntry[] = sprintf('%s Mb', round($aFilesInfo[$iFileIndex]['size'] / 1000, 2)); } else { $aSurveyEntry[] = ""; $aSurveyEntry[] = ""; $aSurveyEntry[] = ""; $aSurveyEntry[] = ""; } } } else { $aSurveyEntry[] = $sSurveyEntry; } } $all_rows[] = array('id' => $row['id'], 'cell' => $aSurveyEntry); } $aSurveyEntries->rows = $all_rows; viewHelper::disableHtmlLogging(); // It's better with but we need to fix error actually header('Content-type: application/json'); echo json_encode($aSurveyEntries); Yii::app()->end(); }
public function view($iSurveyID, $iId, $sBrowseLang = '') { if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) { $aData = $this->_getData(array('iId' => $iId, 'iSurveyId' => $iSurveyID, 'browselang' => $sBrowseLang)); $oBrowseLanguage = new Limesurvey_lang($aData['language']); extract($aData); $clang = Yii::app()->lang; $aViewUrls = array(); $fncount = 0; $fieldmap = createFieldMap($iSurveyID, 'full', false, false, $aData['language']); //add token to top of list if survey is not private if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID) && Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) { $fnames[] = array("token", $clang->gT("Token ID"), 'code' => 'token'); $fnames[] = array("firstname", $clang->gT("First name"), 'code' => 'firstname'); // or token:firstname ? $fnames[] = array("lastname", $clang->gT("Last name"), 'code' => 'lastname'); $fnames[] = array("email", $clang->gT("Email"), 'code' => 'email'); } $fnames[] = array("submitdate", $clang->gT("Submission date"), $clang->gT("Completed"), "0", 'D', 'code' => 'submitdate'); $fnames[] = array("completed", $clang->gT("Completed"), "0"); foreach ($fieldmap as $field) { if ($field['fieldname'] == 'lastpage' || $field['fieldname'] == 'submitdate') { continue; } if ($field['type'] == 'interview_time') { continue; } if ($field['type'] == 'page_time') { continue; } if ($field['type'] == 'answer_time') { continue; } //$question = $field['question']; $question = viewHelper::getFieldText($field); if ($field['type'] != "|") { $fnames[] = array($field['fieldname'], viewHelper::getFieldText($field), 'code' => viewHelper::getFieldCode($field, array('LEMcompat' => true))); } elseif ($field['aid'] !== 'filecount') { $qidattributes = getQuestionAttributeValues($field['qid']); for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) { $filenum = sprintf($clang->gT("File %s"), $i + 1); if ($qidattributes['show_title'] == 1) { $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . $clang->gT('Title') . ")", 'code' => viewHelper::getFieldCode($field) . '(title)', "type" => "|", "metadata" => "title", "index" => $i); } if ($qidattributes['show_comment'] == 1) { $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . $clang->gT('Comment') . ")", 'code' => viewHelper::getFieldCode($field) . '(comment)', "type" => "|", "metadata" => "comment", "index" => $i); } $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . $clang->gT('File name') . ")", 'code' => viewHelper::getFieldCode($field) . '(name)', "type" => "|", "metadata" => "name", "index" => $i); $fnames[] = array($field['fieldname'], "{$filenum} - {$question} (" . $clang->gT('File size') . ")", 'code' => viewHelper::getFieldCode($field) . '(size)', "type" => "|", "metadata" => "size", "index" => $i); //$fnames[] = array($field['fieldname'], "File ".($i+1)." - ".$field['question']." (extension)", "type"=>"|", "metadata"=>"ext", "index"=>$i); } } else { $fnames[] = array($field['fieldname'], $clang->gT("File count")); } } $nfncount = count($fnames) - 1; if ($iId < 1) { $iId = 1; } $exist = SurveyDynamic::model($iSurveyID)->exist($iId); $next = SurveyDynamic::model($iSurveyID)->next($iId, true); $previous = SurveyDynamic::model($iSurveyID)->previous($iId, true); $aData['exist'] = $exist; $aData['next'] = $next; $aData['previous'] = $previous; $aData['id'] = $iId; $aViewUrls[] = 'browseidheader_view'; if ($exist) { $oPurifier = new CHtmlPurifier(); //SHOW INDIVIDUAL RECORD $oCriteria = new CDbCriteria(); if ($aData['surveyinfo']['anonymized'] == 'N' && tableExists("{{tokens_{$iSurveyID}}}}") && Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) { $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria); } // If admin ask an specific response, then show it // Don't add incompleteAnsFilterState # if (incompleteAnsFilterState() == 'incomplete') # $oCriteria->addCondition('submitdate = ' . mktime(0, 0, 0, 1, 1, 1980) . ' OR submitdate IS NULL'); # elseif (incompleteAnsFilterState() == 'complete') # $oCriteria->addCondition('submitdate >= ' . mktime(0, 0, 0, 1, 1, 1980)); $oCriteria->addCondition("id = {$iId}"); $iIdresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria); foreach ($iIdresult as $iIdrow) { $iId = $iIdrow['id']; $rlanguage = $iIdrow['startlanguage']; } $next = SurveyDynamic::model($iSurveyID)->next($iId); $previous = SurveyDynamic::model($iSurveyID)->previous($iId); if (isset($rlanguage)) { $aData['rlanguage'] = $rlanguage; } foreach ($iIdresult as $iIdrow) { $highlight = false; for ($i = 0; $i < $nfncount + 1; $i++) { if ($fnames[$i][0] != 'completed' && is_null($iIdrow[$fnames[$i][0]])) { continue; // irrelevant, so don't show } $inserthighlight = ''; if ($highlight) { $inserthighlight = "class='highlight'"; } if ($fnames[$i][0] == 'completed') { if ($iIdrow['submitdate'] == NULL || $iIdrow['submitdate'] == "N") { $answervalue = "N"; } else { $answervalue = "Y"; } } else { if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|") { $index = $fnames[$i]['index']; $metadata = $fnames[$i]['metadata']; $phparray = json_decode_ls($iIdrow[$fnames[$i][0]]); if (isset($phparray[$index])) { if ($metadata === "size") { $answervalue = rawurldecode((int) $phparray[$index][$metadata] . " KB"); } else { if ($metadata === "name") { $answervalue = CHtml::link($oPurifier->purify(rawurldecode($phparray[$index][$metadata])), $this->getController()->createUrl("/admin/responses/sa/browse/fieldname/{$fnames[$i][0]}/id/{$iId}/surveyid/{$iSurveyID}", array('downloadindividualfile' => $phparray[$index][$metadata]))); } else { $answervalue = rawurldecode($phparray[$index][$metadata]); } } } else { $answervalue = ""; } } else { $answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $oBrowseLanguage))), ENT_QUOTES); } } $aData['answervalue'] = $answervalue; $aData['inserthighlight'] = $inserthighlight; $aData['fnames'] = $fnames; $aData['i'] = $i; $aViewUrls['browseidrow_view'][] = $aData; } } } else { Yii::app()->session['flashmessage'] = $clang->gT("This response ID is invalid."); } $aViewUrls[] = 'browseidfooter_view'; $this->_renderWrappedTemplate('', $aViewUrls, $aData); } else { $clang = $this->getController()->lang; $aData['surveyid'] = $iSurveyID; App()->getClientScript()->registerPackage('jquery-superfish'); $message['title'] = $clang->gT('Access denied!'); $message['message'] = $clang->gT('You do not have sufficient rights to access this page.'); $message['class'] = "error"; $this->_renderWrappedTemplate('survey', array("message" => $message), $aData); } }
public function getExtendedData($colName, $sLanguage, $base64jsonFieldMap) { $oFieldMap = json_decode(base64_decode($base64jsonFieldMap)); $value = $this->{$colName}; $sFullValue = strip_tags(getExtendedAnswer(self::$sid, $oFieldMap->fieldname, $value, $sLanguage)); if (strlen($sFullValue) > 50) { $sElipsizedValue = ellipsize($sFullValue, $this->ellipsize_question_value); $sValue = '<span data-toggle="tooltip" data-placement="left" title="' . quoteText($sFullValue) . '">' . $sElipsizedValue . '</span>'; } else { $sValue = $sFullValue; } // Upload question if ($oFieldMap->type == '|' && strpos($oFieldMap->fieldname, 'filecount') === false) { $sSurveyEntry = "<table class='table table-condensed upload-question'><tr>"; $aQuestionAttributes = getQuestionAttributeValues($oFieldMap->qid); $aFilesInfo = json_decode_ls($this->{$colName}); for ($iFileIndex = 0; $iFileIndex < $aQuestionAttributes['max_num_of_files']; $iFileIndex++) { $sSurveyEntry .= '<tr>'; if (isset($aFilesInfo[$iFileIndex])) { $sSurveyEntry .= '<td>' . CHtml::link(rawurldecode($aFilesInfo[$iFileIndex]['name']), App()->createUrl("/admin/responses", array("sa" => "actionDownloadfile", "surveyid" => self::$sid, "iResponseId" => $this->id, "sFileName" => $aFilesInfo[$iFileIndex]['name']))) . '</td>'; $sSurveyEntry .= '<td>' . sprintf('%s Mb', round($aFilesInfo[$iFileIndex]['size'] / 1000, 2)) . '</td>'; if ($aQuestionAttributes['show_title']) { if (!isset($aFilesInfo[$iFileIndex]['title'])) { $aFilesInfo[$iFileIndex]['title'] = ''; } $sSurveyEntry .= '<td>' . htmlspecialchars($aFilesInfo[$iFileIndex]['title'], ENT_QUOTES, 'UTF-8') . '</td>'; } if ($aQuestionAttributes['show_comment']) { if (!isset($aFilesInfo[$iFileIndex]['comment'])) { $aFilesInfo[$iFileIndex]['comment'] = ''; } $sSurveyEntry .= '<td>' . htmlspecialchars($aFilesInfo[$iFileIndex]['comment'], ENT_QUOTES, 'UTF-8') . '</td>'; } } $sSurveyEntry .= '</tr>'; } $sSurveyEntry .= '</table>'; $sValue = $sSurveyEntry; } return $sValue; }
public function view($iSurveyID, $iId, $sBrowseLang = '') { $aData = $this->_getData(array('iId' => $iId, 'iSurveyId' => $iSurveyID, 'browselang' => $sBrowseLang)); $oBrowseLanguage = new Limesurvey_lang($aData['language']); extract($aData); $clang = Yii::app()->lang; $aViewUrls = array(); $fncount = 0; $fieldmap = createFieldMap($iSurveyID, 'full', false, false, $aData['language']); //add token to top of list if survey is not private if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID)) { $fnames[] = array("token", "Token", $clang->gT("Token ID"), 0); $fnames[] = array("firstname", "First name", $clang->gT("First name"), 0); $fnames[] = array("lastname", "Last name", $clang->gT("Last name"), 0); $fnames[] = array("email", "Email", $clang->gT("Email"), 0); } $fnames[] = array("submitdate", $clang->gT("Submission date"), $clang->gT("Completed"), "0", 'D'); $fnames[] = array("completed", $clang->gT("Completed"), "0"); foreach ($fieldmap as $field) { if ($field['fieldname'] == 'lastpage' || $field['fieldname'] == 'submitdate') { continue; } if ($field['type'] == 'interview_time') { continue; } if ($field['type'] == 'page_time') { continue; } if ($field['type'] == 'answer_time') { continue; } $question = $field['question']; if ($field['type'] != "|") { if (isset($field['subquestion']) && $field['subquestion'] != '') { $question .= ' (' . $field['subquestion'] . ')'; } if (isset($field['subquestion1']) && isset($field['subquestion2'])) { $question .= ' (' . $field['subquestion1'] . ':' . $field['subquestion2'] . ')'; } if (isset($field['scale_id'])) { $question .= '[' . $field['scale'] . ']'; } $fnames[] = array($field['fieldname'], $question); } else { if ($field['aid'] !== 'filecount') { $qidattributes = getQuestionAttributeValues($field['qid']); for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) { if ($qidattributes['show_title'] == 1) { $fnames[] = array($field['fieldname'], "File " . ($i + 1) . " - " . $field['question'] . " (Title)", "type" => "|", "metadata" => "title", "index" => $i); } if ($qidattributes['show_comment'] == 1) { $fnames[] = array($field['fieldname'], "File " . ($i + 1) . " - " . $field['question'] . " (Comment)", "type" => "|", "metadata" => "comment", "index" => $i); } $fnames[] = array($field['fieldname'], "File " . ($i + 1) . " - " . $field['question'] . " (File name)", "type" => "|", "metadata" => "name", "index" => $i); $fnames[] = array($field['fieldname'], "File " . ($i + 1) . " - " . $field['question'] . " (File size)", "type" => "|", "metadata" => "size", "index" => $i); //$fnames[] = array($field['fieldname'], "File ".($i+1)." - ".$field['question']." (extension)", "type"=>"|", "metadata"=>"ext", "index"=>$i); } } else { $fnames[] = array($field['fieldname'], "File count"); } } } $nfncount = count($fnames) - 1; //SHOW INDIVIDUAL RECORD $oCriteria = new CDbCriteria(); if ($aData['surveyinfo']['anonymized'] == 'N' && tableExists("{{tokens_{$iSurveyID}}}}")) { $oCriteria = Survey_dynamic::model($iSurveyID)->addTokenCriteria($oCriteria); } if (incompleteAnsFilterState() == 'incomplete') { $oCriteria->addCondition('submitdate = ' . mktime(0, 0, 0, 1, 1, 1980) . ' OR submitdate IS NULL'); } elseif (incompleteAnsFilterState() == 'complete') { $oCriteria->addCondition('submitdate >= ' . mktime(0, 0, 0, 1, 1, 1980)); } if ($iId < 1) { $iId = 1; } $oCriteria->addCondition("id = {$iId}"); $iIdresult = Survey_dynamic::model($iSurveyID)->findAllAsArray($oCriteria) or die("Couldn't get entry"); foreach ($iIdresult as $iIdrow) { $iId = $iIdrow['id']; $rlanguage = $iIdrow['startlanguage']; } $next = $iId + 1; $last = $iId - 1; $aData['id'] = $iId; if (isset($rlanguage)) { $aData['rlanguage'] = $rlanguage; } $aData['next'] = $next; $aData['last'] = $last; $aViewUrls[] = 'browseidheader_view'; foreach ($iIdresult as $iIdrow) { $highlight = false; for ($i = 0; $i < $nfncount + 1; $i++) { if ($fnames[$i][0] != 'completed' && is_null($iIdrow[$fnames[$i][0]])) { continue; // irrelevant, so don't show } $inserthighlight = ''; if ($highlight) { $inserthighlight = "class='highlight'"; } if ($fnames[$i][0] == 'completed') { if ($iIdrow['submitdate'] == NULL || $iIdrow['submitdate'] == "N") { $answervalue = "N"; } else { $answervalue = "Y"; } } else { if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|") { $index = $fnames[$i]['index']; $metadata = $fnames[$i]['metadata']; $phparray = json_decode_ls($iIdrow[$fnames[$i][0]]); if (isset($phparray[$index])) { if ($metadata === "size") { $answervalue = rawurldecode((int) $phparray[$index][$metadata] . " KB"); } else { if ($metadata === "name") { $answervalue = CHtml::link(rawurldecode($phparray[$index][$metadata]), $this->getController()->createUrl("/admin/responses/index/downloadindividualfile/{$phparray[$index][$metadata]}/fieldname/{$fnames[$i][0]}/id/{$iId}/surveyid/{$iSurveyID}")); } else { $answervalue = rawurldecode($phparray[$index][$metadata]); } } } else { $answervalue = ""; } } else { $answervalue = htmlspecialchars(strip_tags(stripJavaScript(getExtendedAnswer($iSurveyID, $fnames[$i][0], $iIdrow[$fnames[$i][0]], $oBrowseLanguage))), ENT_QUOTES); } } $aData['answervalue'] = $answervalue; $aData['inserthighlight'] = $inserthighlight; $aData['fnames'] = $fnames; $aData['i'] = $i; $aViewUrls['browseidrow_view'][] = $aData; } } $aViewUrls[] = 'browseidfooter_view'; $this->_renderWrappedTemplate('', $aViewUrls, $aData); }