Example #1
0
 /**
  * This function sends the shared participant info to the share panel using JSON encoding
  * This function is called after the share panel grid is loaded
  * This function returns the json depending on the user logged in by checking it from the session
  * @param it takes the session user data loginID
  * @return JSON encoded string containg sharing information
  */
 function getTokens_json($iSurveyId, $search = null)
 {
     // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
     $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}');
     if (!$bTokenExists) {
         $clang->eT("No token table.");
         // return json ? error not treated in js.
         return;
     }
     $clang = $this->getController()->lang;
     if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'read')) {
         $clang->eT("We are sorry but you don't have permissions to do this.");
         // return json ? error not treated in js.
         return;
     }
     $page = Yii::app()->request->getPost('page', 1);
     $sidx = Yii::app()->request->getPost('sidx', 'lastname');
     $sord = Yii::app()->request->getPost('sord', 'asc');
     $limit = Yii::app()->request->getPost('rows', 25);
     $aData = new stdClass();
     $aData->page = $page;
     $aSearchArray = Yii::app()->request->getPost('searcharray');
     if (empty($search) && !empty($aSearchArray)) {
         $search = $aSearchArray;
     }
     if (!empty($search)) {
         $condition = TokenDynamic::model($iSurveyId)->getSearchMultipleCondition($search);
     } else {
         $condition = new CDbCriteria();
     }
     $condition->order = $sidx . " " . $sord;
     $condition->offset = ($page - 1) * $limit;
     $condition->limit = $limit;
     $tokens = Token::model($iSurveyId)->findAll($condition);
     $condition->offset = 0;
     $condition->limit = 0;
     $aData->records = Token::model($iSurveyId)->count($condition);
     if ($limit > $aData->records) {
         $limit = $aData->records;
     }
     if ($limit != 0) {
         $aData->total = ceil($aData->records / $limit);
     } else {
         $aData->total = 0;
     }
     Yii::app()->loadHelper("surveytranslator");
     $format = getDateFormatData(Yii::app()->session['dateformat']);
     $aSurveyInfo = Survey::model()->findByPk($iSurveyId)->getAttributes();
     //Get survey settings
     $attributes = getAttributeFieldNames($iSurveyId);
     // Now find all responses for the visible tokens
     $visibleTokens = array();
     $answeredTokens = array();
     if ($aSurveyInfo['anonymized'] == "N" && $aSurveyInfo['active'] == "Y") {
         foreach ($tokens as $token) {
             if (isset($token['token']) && $token['token']) {
                 $visibleTokens[] = $token['token'];
             }
         }
         $answers = SurveyDynamic::model($iSurveyId)->findAllByAttributes(array('token' => $visibleTokens));
         foreach ($answers as $answer) {
             $answeredTokens[$answer['token']] = $answer['token'];
         }
     }
     $bReadPermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read');
     $bCreatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'create');
     $bTokenUpdatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update');
     $bTokenDeletePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'delete');
     $bGlobalPanelReadPermission = Permission::model()->hasGlobalPermission('participantpanel', 'read');
     foreach ($tokens as $token) {
         $aRowToAdd = array();
         if ((int) $token['validfrom']) {
             $token['validfrom'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validfrom'])));
         } else {
             $token['validfrom'] = '';
         }
         if ((int) $token['validuntil']) {
             $token['validuntil'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validuntil'])));
         } else {
             $token['validuntil'] = '';
         }
         $aRowToAdd['id'] = $token['tid'];
         $action = "";
         $action .= "<div class='inputbuttons'>";
         // so we can hide this when edit is clicked
         // Check is we have an answer
         if (in_array($token['token'], $answeredTokens) && $bReadPermission) {
             // @@TODO change link
             $url = $this->getController()->createUrl("admin/responses/sa/browse/surveyid/{$iSurveyId}", array('token' => $token['token']));
             $title = $clang->gT("View response details");
             $action .= CHtml::link(CHtml::image(Yii::app()->getConfig('adminimageurl') . 'token_viewanswer.png', $title, array('title' => $title)), $url, array('class' => 'imagelink'));
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         // Check if the token can be taken
         if ($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] == "" || $aSurveyInfo['alloweditaftercompletion'] == "Y") && $bCreatePermission) {
             $action .= viewHelper::getImageLink('do_16.png', "survey/index/sid/{$iSurveyId}/token/{$token['token']}/lang/{$token['language']}/newtest/Y", $clang->gT("Do survey"), '_blank');
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         if ($bTokenDeletePermission) {
             $attribs = array('onclick' => 'if (confirm("' . $clang->gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}');
             $action .= viewHelper::getImageLink('token_delete.png', null, $clang->gT("Delete token entry"), null, 'imagelink btnDelete', $attribs);
         }
         if (strtolower($token['emailstatus']) == 'ok' && $token['email'] && $bTokenUpdatePermission) {
             if ($token['completed'] == 'N' && $token['usesleft'] > 0) {
                 if ($token['sent'] == 'N') {
                     $action .= viewHelper::getImageLink('token_invite.png', "admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send invitation email to this person (if they have not yet been sent an invitation email)"), "_blank");
                 } else {
                     $action .= viewHelper::getImageLink('token_remind.png', "admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], $clang->gT("Send reminder email to this person (if they have already received the invitation email)"), "_blank");
                 }
             } else {
                 $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
             }
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         if ($bTokenUpdatePermission) {
             $action .= viewHelper::getImageLink('edit_16.png', null, $clang->gT("Edit token entry"), null, 'imagelink token_edit');
         }
         if (!empty($token['participant_id']) && $token['participant_id'] != "" && $bGlobalPanelReadPermission) {
             $action .= viewHelper::getImageLink('cpdb_16.png', null, $clang->gT("View this person in the central participants database"), null, 'imagelink cpdb', array('onclick' => "sendPost('" . $this->getController()->createUrl('admin/participants/sa/displayParticipants') . "','',['searchcondition'],['participant_id||equal||{$token['participant_id']}']);"));
         } else {
             $action .= '<div style="width: 20px; height: 16px; float: left;"></div>';
         }
         $action .= '</div>';
         $aRowToAdd['cell'] = array($token['tid'], $action, $token['firstname'], $token['lastname'], $token['email'], $token['emailstatus'], $token['token'], $token['language'], $token['sent'], $token['remindersent'], $token['remindercount'], $token['completed'], $token['usesleft'], $token['validfrom'], $token['validuntil']);
         foreach ($attributes as $attribute) {
             $aRowToAdd['cell'][] = $token[$attribute];
         }
         $aData->rows[] = $aRowToAdd;
     }
     viewHelper::disableHtmlLogging();
     header("Content-type: application/json");
     echo ls_json_encode($aData);
 }
Example #2
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();
 }
Example #3
0
function group_export($action, $iSurveyID, $gid)
{
    $fn = "limesurvey_group_{$gid}.lsg";
    $xml = getXMLWriter();
    viewHelper::disableHtmlLogging();
    header("Content-Type: application/force-download");
    header("Content-Disposition: attachment; filename={$fn}");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // Date in the past
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Pragma: cache");
    // HTTP/1.0
    $xml->openUri('php://output');
    $xml->setIndent(true);
    $xml->startDocument('1.0', 'UTF-8');
    $xml->startElement('document');
    $xml->writeElement('LimeSurveyDocType', 'Group');
    $xml->writeElement('DBVersion', getGlobalSetting("DBVersion"));
    $xml->startElement('languages');
    $lresult = QuestionGroup::model()->findAllByAttributes(array('gid' => $gid), array('select' => 'language', 'group' => 'language'));
    foreach ($lresult as $row) {
        $xml->writeElement('language', $row->language);
    }
    $xml->endElement();
    groupGetXMLStructure($xml, $gid);
    $xml->endElement();
    // close columns
    $xml->endDocument();
}
Example #4
0
 private function _surveyexport($action, $iSurveyID)
 {
     viewHelper::disableHtmlLogging();
     if ($action == "exportstructurexml") {
         $fn = "limesurvey_survey_{$iSurveyID}.lss";
         $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT");
         echo surveyGetXMLData($iSurveyID);
         exit;
     } elseif ($action == "exportstructurejson") {
         $fn = "limesurvey_survey_{$iSurveyID}.json";
         $this->_addHeaders($fn, "application/json", "Mon, 26 Jul 1997 05:00:00 GMT");
         $surveyInXmlFormat = surveyGetXMLData($iSurveyID);
         // now convert this xml into json format and then return
         echo _xmlToJson($surveyInXmlFormat);
         exit;
     } elseif ($action == "exportstructurequexml") {
         if (isset($surveyprintlang) && !empty($surveyprintlang)) {
             $quexmllang = $surveyprintlang;
         } else {
             $quexmllang = Survey::model()->findByPk($iSurveyID)->language;
         }
         if (!(isset($noheader) && $noheader == TRUE)) {
             $fn = "survey_{$iSurveyID}_{$quexmllang}.xml";
             $this->_addHeaders($fn, "text/xml", "Mon, 26 Jul 1997 05:00:00 GMT");
             echo quexml_export($iSurveyID, $quexmllang);
             exit;
         }
     } elseif ($action == 'exportstructuretsv') {
         $this->_exporttsv($iSurveyID);
     } elseif ($action == "exportarchive") {
         $this->_exportarchive($iSurveyID);
     }
 }