Ejemplo n.º 1
1
 /**
  * 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);
     }
 }
Ejemplo n.º 2
0
                //No corresponding token in the token tabel, just didsplay the token
                $browsedatafield .= "{$dtrow['token']}";
            }
        ?>
        <td align='center'><?php echo $browsedatafield; ?></td>
        <?php
            $i++;   //We skip the first record (=token) as we just outputted that one
        }

        for ($i; $i < $fncount; $i++)
        {
            if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|")
            {
                $index = $fnames[$i]['index'];
                $metadata = $fnames[$i]['metadata'];
                $phparray = json_decode_ls($dtrow[$fnames[$i][0]], true);
                if (isset($phparray[$index]))
                {
                    if ($metadata === "size")
                    {
                    ?>
                    <td align='center'><?php echo rawurldecode(((int) ($phparray[$index][$metadata])) . " KB"); ?></td>
                    <?php }
                    else if ($metadata === "name")
                        { ?>
                        <td><a href='#' onclick=" <?php echo convertGETtoPOST('?action=browse&amp;subaction=all&amp;downloadindividualfile=' . $phparray[$index][$metadata] . '&amp;fieldname=' . $fnames[$i][0] . '&amp;id=' . $dtrow['id'] . '&amp;sid=' . $surveyid); ?>" ><?php echo rawurldecode($phparray[$index][$metadata]); ?></a></td>
                        <?php }
                        else
                        { ?>
                        <td><?php echo rawurldecode($phparray[$index][$metadata]); ?></td>
                        <?php
Ejemplo n.º 3
0
 /**
  * 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();
 }
Ejemplo n.º 4
0
 function browse($iSurveyID)
 {
     $aData = $this->_getData($iSurveyID);
     extract($aData);
     $aViewUrls = array();
     $oBrowseLanguage = new Limesurvey_lang($aData['language']);
     $tokenRequest = Yii::app()->request->getParam('token', null);
     //Delete Individual answer using inrow delete buttons/links - checked
     if (Yii::app()->request->getPost('deleteanswer') && Yii::app()->request->getPost('deleteanswer') != '' && Yii::app()->request->getPost('deleteanswer') != 'marked') {
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'delete')) {
             $iResponseID = (int) Yii::app()->request->getPost('deleteanswer');
             // sanitize the value
             Response::model($iSurveyID)->findByPk($iResponseID)->delete(true);
             // delete timings if savetimings is set
             if ($aData['surveyinfo']['savetimings'] == "Y") {
                 SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
             }
             Yii::app()->session['flashmessage'] = sprintf(gT("Response ID %s was successfully deleted."), $iResponseID);
         } else {
             Yii::app()->session['flashmessage'] = gT("Access denied!", 'js');
         }
     }
     // Marked responses -> deal with the whole batch of marked responses
     if (Yii::app()->request->getPost('markedresponses') && count(Yii::app()->request->getPost('markedresponses')) > 0) {
         // Delete the marked responses - checked
         if (Yii::app()->request->getPost('deleteanswer') && Yii::app()->request->getPost('deleteanswer') === 'marked') {
             if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'delete')) {
                 foreach (Response::model($iSurveyID)->findAllByPk(Yii::app()->request->getPost('markedresponses')) as $response) {
                     $response->deleteFiles();
                     // delete timings if savetimings is set
                     /**
                      * @todo Move this to the Response model.
                      */
                     if ($aData['surveyinfo']['savetimings'] == "Y") {
                         SurveyTimingDynamic::model($iSurveyID)->deleteByPk($iResponseID);
                     }
                 }
                 Response::model($iSurveyID)->deleteByPk(Yii::app()->request->getPost('markedresponses'));
                 Yii::app()->session['flashmessage'] = sprintf(ngT("%s response was successfully deleted.", "%s responses were successfully deleted.", count(Yii::app()->request->getPost('markedresponses'))), count(Yii::app()->request->getPost('markedresponses')), 'js');
             } else {
                 Yii::app()->session['flashmessage'] = $clang->gT("Access denied!", 'js');
             }
         } elseif (Yii::app()->request->getPost('downloadfile') && Yii::app()->request->getPost('downloadfile') === 'marked') {
             if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
                 // Now, zip all the files in the filelist
                 $zipfilename = "Responses_for_survey_{$iSurveyID}.zip";
                 $this->_zipFiles($iSurveyID, Yii::app()->request->getPost('markedresponses'), $zipfilename);
             }
         }
     } elseif (Yii::app()->request->getPost('downloadfile') && Yii::app()->request->getPost('downloadfile') != '' && Yii::app()->request->getPost('downloadfile') !== true) {
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
             // Now, zip all the files in the filelist
             $zipfilename = "Files_for_responses_" . Yii::app()->request->getPost('downloadfile') . ".zip";
             $this->_zipFiles($iSurveyID, Yii::app()->request->getPost('downloadfile'), $zipfilename);
         }
     } elseif (Yii::app()->request->getParam('downloadindividualfile') != '') {
         if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
             $iId = (int) Yii::app()->request->getParam('id');
             $downloadindividualfile = Yii::app()->request->getParam('downloadindividualfile');
             $fieldname = Yii::app()->request->getParam('fieldname');
             $oRow = SurveyDynamic::model($iSurveyID)->findByAttributes(array('id' => $iId));
             $phparray = json_decode_ls($oRow->{$fieldname});
             for ($i = 0; $i < count($phparray); $i++) {
                 if (rawurldecode($phparray[$i]['name']) == rawurldecode($downloadindividualfile)) {
                     $file = Yii::app()->getConfig('uploaddir') . "/surveys/" . $iSurveyID . "/files/" . $phparray[$i]['filename'];
                     if (file_exists($file)) {
                         @ob_clean();
                         header('Content-Description: File Transfer');
                         header('Content-Type: application/octet-stream');
                         header('Content-Disposition: attachment; filename="' . rawurldecode($phparray[$i]['name']) . '"');
                         header('Content-Transfer-Encoding: binary');
                         header('Expires: 0');
                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                         header('Pragma: public');
                         header('Content-Length: ' . filesize($file));
                         readfile($file);
                         exit;
                     } else {
                         Yii::app()->session['flashmessage'] = gT("The requested file does not exist on the server.");
                     }
                     break;
                 }
             }
         }
     }
     /**
      * fnames is used as informational array
      * it containts
      *             $fnames[] = array(<dbfieldname>, <some strange title>, <questiontext>, <group_id>, <questiontype>);
      */
     if (Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'read')) {
         if (Yii::app()->request->getPost('sql')) {
             $aViewUrls[] = 'browseallfiltered_view';
         }
         //add token to top of list if survey is not private
         if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyID)) {
             if (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("Completed"), $clang->gT("Completed"), "0", 'D');
         $fields = createFieldMap($iSurveyID, 'full', false, false, $aData['language']);
         foreach ($fields as $fielddetails) {
             if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate') {
                 continue;
             }
             $question = $fielddetails['question'];
             if ($fielddetails['type'] != "|") {
                 if ($fielddetails['fieldname'] == 'lastpage' || $fielddetails['fieldname'] == 'submitdate' || $fielddetails['fieldname'] == 'token') {
                     continue;
                 }
                 // no headers for time data
                 if ($fielddetails['type'] == 'interview_time') {
                     continue;
                 }
                 if ($fielddetails['type'] == 'page_time') {
                     continue;
                 }
                 if ($fielddetails['type'] == 'answer_time') {
                     continue;
                 }
                 $fnames[] = array($fielddetails['fieldname'], viewHelper::getFieldText($fielddetails), 'code' => viewHelper::getFieldCode($fielddetails, array('LEMcompat' => true)));
             } elseif ($fielddetails['aid'] !== 'filecount') {
                 $qidattributes = getQuestionAttributeValues($fielddetails['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($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('Title') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(title)', "type" => "|", "metadata" => "title", "index" => $i);
                     }
                     if ($qidattributes['show_comment'] == 1) {
                         $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('Comment') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(comment)', "type" => "|", "metadata" => "comment", "index" => $i);
                     }
                     $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('File name') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(name)', "type" => "|", "metadata" => "name", "index" => $i);
                     $fnames[] = array($fielddetails['fieldname'], "{$filenum} - {$question} (" . $clang->gT('File size') . ")", 'code' => viewHelper::getFieldCode($fielddetails) . '(size)', "type" => "|", "metadata" => "size", "index" => $i);
                     //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(extension)", "type"=>"|", "metadata"=>"ext",     "index"=>$i);
                 }
             } else {
                 $fnames[] = array($fielddetails['fieldname'], $clang->gT("File count"), 'code' => viewHelper::getFieldCode($fielddetails));
             }
         }
         $fncount = count($fnames);
         $start = (int) Yii::app()->request->getParam('start', 0);
         $limit = (int) Yii::app()->request->getParam('limit', 50);
         $order = Yii::app()->request->getParam('order', 'asc');
         if (!$limit) {
             $limit = 50;
         }
         $oCriteria = new CDbCriteria();
         //Create the query
         if ($aData['surveyinfo']['anonymized'] == "N" && tableExists("{{tokens_{$iSurveyID}}}") && Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'read')) {
             $oCriteria = SurveyDynamic::model($iSurveyID)->addTokenCriteria($oCriteria);
         }
         if (incompleteAnsFilterState() == "incomplete") {
             $oCriteria->addCondition("submitdate IS NULL");
         } elseif (incompleteAnsFilterState() == "complete") {
             $oCriteria->addCondition("submitdate IS NOT NULL");
         }
         $dtcount = SurveyDynamic::model($iSurveyID)->count($oCriteria);
         // or die("Couldn't get response data<br />");
         if ($limit > $dtcount) {
             $limit = $dtcount;
         }
         //NOW LETS SHOW THE 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')));
         }
         if (!is_null($tokenRequest)) {
             $oCriteria->addCondition('t.token = ' . Yii::app()->db->quoteValue($tokenRequest));
         }
         $oCriteria->order = 'id ' . ($order == 'desc' ? 'desc' : 'asc');
         $oCriteria->offset = $start;
         $oCriteria->limit = $limit;
         $dtresult = SurveyDynamic::model($iSurveyID)->findAllAsArray($oCriteria);
         $dtcount2 = count($dtresult);
         $cells = $fncount + 1;
         // Fix start if order is desc, only if actual start is 0
         if ($order == 'desc' && $start == 0) {
             $start = $dtcount - count($dtresult);
         }
         //CONTROL MENUBAR
         $last = $start - $limit;
         $next = $start + $limit;
         $end = $dtcount - $limit;
         if ($end < 0) {
             $end = 0;
         }
         if ($last < 0) {
             $last = 0;
         }
         if ($next >= $dtcount) {
             $next = $dtcount - $limit;
         }
         if ($end < 0) {
             $end = 0;
         }
         $aData['dtcount2'] = $dtcount2;
         $aData['sCompletionStateValue'] = incompleteAnsFilterState();
         $aData['start'] = $start;
         $aData['limit'] = $limit;
         $aData['last'] = $last;
         $aData['next'] = $next;
         $aData['end'] = $end;
         $aData['fncount'] = $fncount;
         $aData['fnames'] = $fnames;
         $aData['bHasFileUploadQuestion'] = hasFileUploadQuestion($iSurveyID);
         $aViewUrls[] = 'browseallheader_view';
         $bgcc = 'even';
         foreach ($dtresult as $dtrow) {
             if ($bgcc == "even") {
                 $bgcc = "odd";
             } else {
                 $bgcc = "even";
             }
             $aData['dtrow'] = $dtrow;
             $aData['bgcc'] = $bgcc;
             $aData['oBrowseLanguage'] = $oBrowseLanguage;
             $aViewUrls['browseallrow_view'][] = $aData;
         }
         $aViewUrls[] = 'browseallfooter_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);
     }
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 /**
  * Supply an array with the responseIds and all files will be added to the zip
  * and it will be be spit out on success
  *
  * @param array $responseIds
  * @param string $zipfilename
  * @param string $language
  * @return ZipArchive
  */
 private function _zipFiles($iSurveyID, $responseIds, $zipfilename, $language)
 {
     Yii::app()->loadLibrary('admin/pclzip/pclzip');
     $tmpdir = Yii::app()->getConfig('uploaddir') . DIRECTORY_SEPARATOR . "surveys" . DIRECTORY_SEPARATOR . $iSurveyID . DIRECTORY_SEPARATOR . "files" . DIRECTORY_SEPARATOR;
     $filelist = array();
     $fieldmap = createFieldMap($iSurveyID, 'full', false, false, $language);
     foreach ($fieldmap as $field) {
         if ($field['type'] == "|" && $field['aid'] !== 'filecount') {
             $filequestion[] = $field['fieldname'];
         }
     }
     foreach ((array) $responseIds as $responseId) {
         $responseId = (int) $responseId;
         // sanitize the value
         $filearray = Survey_dynamic::model($iSurveyID)->findAllByAttributes(array('id' => $responseId)) or die('Could not download response');
         $metadata = array();
         $filecount = 0;
         foreach ($filearray as $metadata) {
             foreach ($metadata as $aData) {
                 $phparray = json_decode_ls($aData);
                 if (is_array($phparray)) {
                     foreach ($phparray as $file) {
                         $filecount++;
                         $file['responseid'] = $responseId;
                         $file['name'] = rawurldecode($file['name']);
                         $file['index'] = $filecount;
                         /*
                          * Now add the file to the archive, prefix files with responseid_index to keep them
                          * unique. This way we can have 234_1_image1.gif, 234_2_image1.gif as it could be
                          * files from a different source with the same name.
                          */
                         $filelist[] = array(PCLZIP_ATT_FILE_NAME => $tmpdir . $file['filename'], PCLZIP_ATT_FILE_NEW_FULL_NAME => sprintf("%05s_%02s_%s", $file['responseid'], $file['index'], $file['name']));
                     }
                 }
             }
         }
     }
     if (count($filelist) > 0) {
         // TODO: to extend the yii app function loadLibrary to meet the app requirements
         $zip = new PclZip($tmpdir . $zipfilename);
         if ($zip->create($filelist) === 0) {
             //Oops something has gone wrong!
         }
         if (file_exists($tmpdir . '/' . $zipfilename)) {
             header('Content-Description: File Transfer');
             header('Content-Type: application/octet-stream');
             header('Content-Disposition: attachment; filename=' . basename($zipfilename));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
             header('Content-Length: ' . filesize($tmpdir . "/" . $zipfilename));
             ob_clean();
             flush();
             readfile($tmpdir . '/' . $zipfilename);
             unlink($tmpdir . '/' . $zipfilename);
             exit;
         }
     }
 }