From 4648894c359fd1dff47bb1ce5d6f10c81f56254a Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Sat, 3 Dec 2011 11:28:03 +0000 Subject: [PATCH] Implement jqgrid at browse response table - by GCI participant Licker Nandor git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11572 b72ed6b6-b9f8-46b5-92b4-906544132732 --- application/controllers/admin/browse.php | 1065 +++++++++++------ application/controllers/admin/dataentry.php | 139 ++- application/helpers/common_helper.php | 15 +- application/helpers/qanda_helper.php | 13 +- application/models/surveys_dynamic_model.php | 119 +- .../views/admin/browse/browsemenubar_view.php | 22 +- scripts/admin/browse.js | 254 ++-- scripts/jquery/jquery.qtip.js | 2 +- 8 files changed, 1009 insertions(+), 620 deletions(-) diff --git a/application/controllers/admin/browse.php b/application/controllers/admin/browse.php index 610c3d518b7..325aea91a44 100644 --- a/application/controllers/admin/browse.php +++ b/application/controllers/admin/browse.php @@ -40,22 +40,26 @@ public function _remap($method, $params = array()) function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $var3 = null, $var4 = null) { - $surveyid = sanitize_int($surveyid); - $_POST = $this->input->post(); - $clang = $this->limesurvey_lang; - $this->load->helper("database"); - $this->load->helper("surveytranslator"); - $data = array(); - - if (!isset($limit)) {$limit=returnglobal('limit');} + $surveyid = sanitize_int($surveyid); + $_POST = $this->input->post(); + $clang = $this->limesurvey_lang; + + $this->load->helper("database"); + $this->load->helper("surveytranslator"); + $this->load->model('Surveys_dynamic_model'); + + $data = array(); + + if (!isset($limit)) {$limit=returnglobal('limit');} if (!isset($surveyid)) {$surveyid=returnglobal('sid');} if (!isset($id)) {$id=returnglobal('id');} - if (!isset($order)) {$order=returnglobal('order');} - if (!isset($browselang)) {$browselang=returnglobal('browselang');} - - // Some test in response table - if (!isset($surveyid) && !isset($subaction)) //NO SID OR ACTION PROVIDED - { + if (!isset($order)) {$order=returnglobal('order');} + if (!isset($browselang)) {$browselang=returnglobal('browselang');} + + + // Some test in response table + if (!isset($surveyid) && !isset($subaction)) //NO SID OR ACTION PROVIDED + { show_error("\t
" . $clang->gT("Browse Responses")."
" .$clang->gT("Error")."\t
\n" @@ -70,12 +74,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, //CHECK IF SURVEY IS ACTIVATED AND EXISTS $actquery = "SELECT * FROM ".$this->db->dbprefix('surveys')." as a inner join ".$this->db->dbprefix('surveys_languagesettings')." as b on (b.surveyls_survey_id=a.sid and b.surveyls_language=a.language) WHERE a.sid=".$this->db->escape($surveyid); - - $actresult = db_execute_assoc($actquery); - $actcount = $actresult->num_rows(); - if ($actcount > 0) - { - foreach ($actresult->result_array() as $actrow) + + $actresult = db_execute_assoc($actquery); + $actcount = $actresult->num_rows(); + + if ($actcount > 0) + { + foreach ($actresult->result_array() as $actrow) { $surveytable = $this->db->dbprefix("survey_".$actrow['sid']); $surveytimingstable = $this->db->dbprefix("survey_".$actrow['sid']."_timings"); @@ -135,27 +140,311 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, } } else - { - $language = GetBaseLanguageFromSurveyID($surveyid); - } - - self::_getAdminHeader(); - $surveyoptions = ""; - self::_browsemenubar($surveyid, $clang->gT("Browse Responses")); - $browseoutput = ""; - - self::_js_admin_includes($this->config->item("adminscripts").'browse.js'); - - - - $qulanguage = GetBaseLanguageFromSurveyID($surveyid); - - - // Looking at a SINGLE entry - - if ($subaction == "id") - { - $id=sanitize_int($var1); + { + $language = GetBaseLanguageFromSurveyID($surveyid); + } + + + // Handle jqgrid edit operations + if($subaction == "grid") + { + if (isset($_POST['oper'])) { + switch ($_POST['oper']) { + + // Delete responses with ids in $_POST['id'] + case 'del': + if (!bHasSurveyPermission($surveyid,'responses','delete')) + { + echo '{"error": "'.$clang->gT('You don\'t have permissions to delete the survey!').'"}'; + } + if (!isset($_POST['id'])) + { + echo '{"error": "'.$clang->gT('Missing parameter: \'id\'').'"}'; + } + + $aIds = explode(',', $_POST['id']); + + foreach ($aIds as $responseID) + { + // Delete all the files associated to the response + $fieldmap = createFieldMap($surveyid); + $fuqtquestions = array(); + + // find all fuqt questions + foreach ($fieldmap as $field) + { + if ($field['type'] == "|" && strpos($field['fieldname'], "_filecount") == 0) + $fuqtquestions[] = $field['fieldname']; + } + + if (!empty($fuqtquestions)) + { + $responses = $this->Surveys_dynamic_model->getFieldsForID($fuqtquestions, $surveyid, $responseID); + + foreach ($responses->result_array() as $json) + { + foreach ($fuqtquestions as $fieldname) + { + $phparray = json_decode($json[$fieldname]); + if ($phparray) + { + foreach($phparray as $metadata) + { + $path = $this->config->item('uploaddir')."/surveys/".$surveyid."/files/"; + unlink($path.$metadata->filename); // delete the file + } + } + } + } + } + + $this->Surveys_dynamic_model->deleteResponse($surveyid, $responseID); + } + + return; + + // Dowload a single file + case 'downloadfile': + if (!isset($_POST['id']) || !isset($_POST['filename']) || !isset($_POST['fieldname'])) + { + show_error($clang->gT('Missing parameters')); + } + + $id = (int)$_POST['id']; + $filename = $_POST['filename']; + $fieldname = $_POST['fieldname']; + + $result = $this->Surveys_dynamic_model->getFieldsForID($fieldname, $surveyid, $id); + $row = $result->row_array(); + $phparray = json_decode(reset($row)); + for ($i = 0; $i < count($phparray); $i++) + { + if ($phparray[$i]->name == $filename) + { + $file = $this->config->item('uploaddir')."/surveys/" . $surveyid . "/files/" . $phparray[$i]->filename; + if (file_exists($file)) + { + 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)); + ob_clean(); + flush(); + readfile($file); + exit; + } + else + { + show_error($clang->gT("Missing file:").$filename); + } + break; + } + } + return; + + // Download a single zip with files + case 'downloadarchive': + $zipfilename = "LS_Responses_for_" . $_POST['id'] . ".zip"; + $this->zipFiles($surveyid, $_POST['id'], $zipfilename); + return; + + // Download all files for a response + case 'downloadarchives': + $zipfilename = "Responses_for_survey_" . $surveyid . ".zip"; + $this->zipFiles($surveyid, explode(',', $_POST['ids']), $zipfilename); + return; + + // Edit a response + case 'edit': + unset($_POST['oper']); + if (!isset($_POST['id'])) + { + echo '{"error": "'.$clang->gT('Missing parameter: \'id\'').'"}'; + } + + $id = (int)$_POST['id']; + unset($_POST['id']); + + $data = $this->Surveys_dynamic_model->getResponse($surveyid, $id)->row_array(); + + // handle the submitdate + if (isset($_POST['submitdate'])) + { + if ($_POST['submitdate'] == 'Y') + { + if ($data['submitdate'] == '') + { + $data['submitdate'] = date('Y-m-d H:m:s'); + } + } + else + { + $data['submitdate'] = NULL; + } + unset($_POST['submitdate']); + } + + // Loop through the array of changed values + foreach ($_POST as $field => $value) + { + $param = explode('_', $field); + if (count($param) == 1) + { + $data[$param[0]] = $value; + } + else + { + if ($param[1] == 'comment') + { + $fileID = (int)$param[2]; + $jsonData = json_decode($data[$param[0]], true); + if (isset($jsonData[$fileID])) + { + $jsonData[$fileID]['comment'] = $value; + } + $data[$param[0]] = json_encode($jsonData); + } + else if ($param[1] == 'title') + { + $fileID = (int)$param[2]; + $jsonData = json_decode($data[$param[0]], true); + if (isset($jsonData[$fileID])) + { + $jsonData[$fileID]['title'] = $value; + } + $data[$param[0]] = json_encode($jsonData); + } + } + } + + $data = $this->Surveys_dynamic_model->updateResponse($surveyid, $id, $data); + return; + default: + echo '{"error": "'.$clang->gT('Missing parameter: \'id\'').'"}'; + return; + } + } + + // No operation on the table - jqgrid is requesting data + if (!isset($_POST['page']) || !isset($_POST['rows']) || !isset($_POST['sidx']) || !isset($_POST['sord'])) + { + echo '{"error": "'.$clang->gT('Missing parameters').'"}'; + return; + } + + $aDataDisplayed = $_SESSION['browse']['dataDisplayed']; + + $dquery = $this->Surveys_dynamic_model->getAllRecords($surveyid); + + $response = array(); + $response["records"] = $this->Surveys_dynamic_model->getResponseCount($surveyid); + $response["page"] = $_POST['page']; + $response["total"] = ceil($response["records"] / $_POST['rows']); + + + foreach($dquery->result_array() as $arow) { + $aData = array(); + $actions = "".$clang->gT("; + if (bHasFileUploadQuestion($surveyid)) + { + $actions .="".$clang->gT("; + } + $aData[] = $actions; + + foreach($aDataDisplayed as $col) + { + switch($col['type']) { + case 'file': + $data = json_decode($arow[$col['field']]); + $inum = 0; + if ($data) + { + foreach ($data as $file) + { + if ($col['attr']['title'] == "1") + { + $aData[] = $file->title; + } + else + { + $aData[] = ' '; + } + + if ($col['attr']['comment'] == "1") + { + $aData[] = $file->comment; + } + else + { + $aData = ' '; + } + + $fileName = "name}')\">{$file->name}"; + array_push($aData, $fileName, floor($file->size)); + $inum++; + } + } + for ($i = $inum; $i < $col['attr']['numfiles']; $i++) + { + array_push($aData, ' ', '', ' ', "0"); + } + break; + case 'submitdate': + if ($arow['submitdate'] == '') + { + $aData[] = 'No'; + } + else + { + $aData[] = 'Yes'; + } + break; + default: + $aData[] = $arow[$col['field']]; + break; + } + } + + $response['rows'][] = array( + 'id' => $arow['id'], + 'cell' => $aData + ); + } + + echo json_encode($response); + return; + } + + // Load the jqgrid css & js + self::_js_admin_includes($this->config->item('generalscripts')."jquery/jqGrid/js/i18n/grid.locale-en.js"); + self::_js_admin_includes($this->config->item('generalscripts')."jquery/jqGrid/js/jquery.jqGrid.min.js"); + + $css_admin_includes[] = $this->config->item('generalscripts')."jquery/css/jquery.multiselect.css"; + $css_admin_includes[] = $this->config->item('generalscripts')."jquery/css/jquery.multiselect.filter.css"; + $css_admin_includes[] = $this->config->item('generalscripts')."jquery/jqGrid/css/ui.jqgrid.css"; + $css_admin_includes[] = $this->config->item('generalscripts')."jquery/jqGrid/css/jquery.ui.datepicker.css"; + + $this->config->set_item("css_admin_includes", $css_admin_includes); + + self::_getAdminHeader(); + + + self::_browsemenubar($surveyid, $clang->gT("Browse Responses")); + + $surveyoptions = ""; + $browseoutput = ""; + + $qulanguage = GetBaseLanguageFromSurveyID($surveyid); + + + // Looking at a SINGLE entry + if ($subaction == "id") + { + $id=sanitize_int($var1); //SHOW HEADER if (!isset($_POST['sql']) || !$_POST['sql']) {$browseoutput .= $surveyoptions;} // Don't show options if coming from tokens script //FIRST LETS GET THE NAMES OF THE QUESTIONS AND MATCH THEM TO THE FIELD NAMES FOR THE DATABASE @@ -201,13 +490,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, else { if ($field['aid']!=='filecount') - { - $qidattributes=getQuestionAttributeValues($field['qid']); - - for ($i = 0; $i < $qidattributes['max_files']; $i++) - { - if ($qidattributes['show_title'] == 1) - $fnames[] = array($field['fieldname'], "File ".($i+1)." - ".$field['question']." (Title)", "type"=>"|", "metadata"=>"title", "index"=>$i); + { + $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); @@ -217,13 +506,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, //$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 + else + $fnames[] = array($field['fieldname'], "File count"); + } + } + + $nfncount = count($fnames)-1; + //SHOW INDIVIDUAL RECORD $idquery = "SELECT * FROM $surveytable "; if ($surveyinfo['anonymized'] == "N" && db_tables_exist($tokentable)) $idquery .= "LEFT JOIN $tokentable ON $surveytable.token = $tokentable.token "; @@ -299,249 +588,270 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $this->load->view("admin/browse/browseidrow_view", $data); $highlight=!$highlight; } - } - $this->load->view("admin/browse/browseidfooter_view", $data); - } - - elseif ($subaction == "all") - { - if(isset($var3)) $order = $var3; + } + $this->load->view("admin/browse/browseidfooter_view", $data); + } + + elseif ($subaction == "all") + { + if(isset($var3)) $order = $var3; /** * fnames is used as informational array * it containts * $fnames[] = array(, , , , ); - */ - - if (!isset($_POST['sql'])) - {$browseoutput .= $surveyoptions;} //don't show options when called from another script with a filter on - else - { - $browseoutput .= "\t".$clang->gT("Browse Responses").": $surveyname\n" - ."\n\n" - ."\t\n" - ."\n" + ."\n\n"; - - } - - //Delete Individual answer using inrow delete buttons/links - checked - if (isset($_POST['deleteanswer']) && $_POST['deleteanswer'] != '' && $_POST['deleteanswer'] != 'marked' && bHasSurveyPermission($surveyid,'responses','delete')) - { - $_POST['deleteanswer']=(int) $_POST['deleteanswer']; // sanitize the value - - // delete the files as well if its a fuqt - - $fieldmap = createFieldMap($surveyid); - $fuqtquestions = array(); - // find all fuqt questions - foreach ($fieldmap as $field) - { - if ($field['type'] == "|" && strpos($field['fieldname'], "_filecount") == 0) - $fuqtquestions[] = $field['fieldname']; - } - - if (!empty($fuqtquestions)) - { - // find all responses (filenames) to the fuqt questions - $query="SELECT " . implode(", ", $fuqtquestions) . " FROM $surveytable where id={$_POST['deleteanswer']}"; - $responses = db_execute_assoc($query) or safe_die("Could not fetch responses
$query
".$connect->ErrorMsg()); - - foreach ($responses->result_array() as $json) - { - foreach ($fuqtquestions as $fieldname) - { - $phparray = json_decode($json[$fieldname]); - foreach($phparray as $metadata) - { - $path = $CI->config->item('uploaddir')."/surveys/".$surveyid."/files/"; - unlink($path.$metadata->filename); // delete the file - } - } - } - } - - // delete the row - $query="delete FROM $surveytable where id=".mysql_real_escape_string($_POST['deleteanswer']); - db_execute_assoc($query) or safe_die("Could not delete response
$dtquery
".$connect->ErrorMsg()); // checked - } - // Marked responses -> deal with the whole batch of marked responses - if (isset($_POST['markedresponses']) && count($_POST['markedresponses'])>0 && bHasSurveyPermission($surveyid,'responses','delete')) - { - // Delete the marked responses - checked - if (isset($_POST['deleteanswer']) && $_POST['deleteanswer'] === 'marked') - { - $fieldmap = createFieldMap($surveyid); - $fuqtquestions = array(); - // find all fuqt questions - foreach ($fieldmap as $field) - { - if ($field['type'] == "|" && strpos($field['fieldname'], "_filecount") == 0) - $fuqtquestions[] = $field['fieldname']; - } - - foreach ($_POST['markedresponses'] as $iResponseID) - { - $iResponseID=(int)$iResponseID; // sanitize the value - - if (!empty($fuqtquestions)) - { - // find all responses (filenames) to the fuqt questions - $query="SELECT " . implode(", ", $fuqtquestions) . " FROM $surveytable where id={$iResponseID}"; - $responses = db_execute_assoc($query) or safe_die("Could not fetch responses
$query
".$connect->ErrorMsg()); - - foreach ($responses->result_array() as $json) - { - foreach ($fuqtquestions as $fieldname) - { - $phparray = json_decode($json[$fieldname]); - foreach($phparray as $metadata) - { - $path = $CI->config->item('uploaddir')."/surveys/{$surveyid}/files/"; - unlink($path.$metadata->filename); // delete the file - } - } - } - } - - $query="delete FROM {$surveytable} where id={$iResponseID}"; - db_execute_assoc($query) or safe_die("Could not delete response
{$dtquery}
".$connect->ErrorMsg()); // checked - } - } - // Download all files for all marked responses - checked - else if (isset($_POST['downloadfile']) && $_POST['downloadfile'] === 'marked') - { - // Now, zip all the files in the filelist - $zipfilename = "Responses_for_survey_" . $surveyid . ".zip"; - $this->zipFiles($_POST['markedresponses'], $zipfilename); - } - } - // Download all files for this entry - checked - else if (isset($_POST['downloadfile']) && $_POST['downloadfile'] != '' && $_POST['downloadfile'] !== true) - { - // Now, zip all the files in the filelist - $zipfilename = "LS_Responses_for_" . $_POST['downloadfile'] . ".zip"; - $this->zipFiles($_POST['downloadfile'], $zipfilename); - } - else if (isset($_POST['downloadindividualfile']) && $_POST['downloadindividualfile'] != '') - { - $id = (int)$_POST['id']; - $downloadindividualfile = $_POST['downloadindividualfile']; - $fieldname = $_POST['fieldname']; - - $query = "SELECT ".db_quote_id($fieldname)." FROM {$surveytable} WHERE id={$id}"; - $result=db_execute_assoc($query); - $row=$result->row_array(); - $phparray = json_decode(reset($row)); - - for ($i = 0; $i < count($phparray); $i++) - { - if ($phparray[$i]->name == $downloadindividualfile) - { - $file = $CI->config->item('uploaddir')."/surveys/" . $surveyid . "/files/" . $phparray[$i]->filename; - - if (file_exists($file)) { - 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)); - ob_clean(); - flush(); - readfile($file); - exit; - } - break; - } - } - } - - - //add token to top of list if survey is not private - if ($surveyinfo['anonymized'] == "N" && db_tables_exist($tokentable)) //add token to top of list if survey is not private - { - $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("Completed"), $clang->gT("Completed"), "0", 'D'); - $fields = createFieldMap($surveyid, 'full', false, false, $language); - - $fnames[] = array("submitdate", "Completed", $clang->gT("Completed"), "0", 'D'); - $fields = createFieldMap($surveyid, 'full', false, false, $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; - if (isset($fielddetails['subquestion']) && $fielddetails['subquestion']!='') - $question .=' ('.$fielddetails['subquestion'].')'; - if (isset($fielddetails['subquestion1']) && isset($fielddetails['subquestion2'])) - $question .=' ('.$fielddetails['subquestion1'].':'.$fielddetails['subquestion2'].')'; - if (isset($fielddetails['scale_id'])) - $question .='['.$fielddetails['scale'].']'; - $fnames[]=array($fielddetails['fieldname'],$question); - } - else - { - if ($fielddetails['aid']!=='filecount') - { - $qidattributes=getQuestionAttributeValues($fielddetails['qid']); - - for ($i = 0; $i < $qidattributes['max_files']; $i++) - { - if ($qidattributes['show_title'] == 1) - $fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(Title)", "type"=>"|", "metadata"=>"title", "index"=>$i); - - if ($qidattributes['show_comment'] == 1) - $fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(Comment)", "type"=>"|", "metadata"=>"comment", "index"=>$i); - - $fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(File name)", "type"=>"|", "metadata"=>"name", "index"=>$i); - $fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(File 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'], "File count"); - } - } - - $fncount = count($fnames); - - //NOW LETS CREATE A TABLE WITH THOSE HEADINGS - - $tableheader = ""; - if ($fncount < 10) {$tableheader .= "
\n" + */ + + if (!isset($_POST['sql'])) + { + //don't show options when called from another script with a filter on + $browseoutput .= $surveyoptions; + } + else + { + $browseoutput .= "\t
".$clang->gT("Browse Responses").": $surveyname
\n" + ."\t\n" + ."\n" ."\t\n" - ."
\n" ."".$clang->gT("Showing Filtered Results")."
\n" ." [".$clang->gT("Close")."]" ."
\n";} - else {$tableheader .= "
\n";} - $tableheader .= "\t\n" - . "\n" - . "\n"; - foreach ($fnames as $fn) - { - if (!isset($currentgroup)) {$currentgroup = $fn[1]; $gbc = "odd";} + ."
".$clang->gT('Actions')."
\n"; + + } + + // $colNames contains the name of colums for jqgrid + $colNames = array(); + + // $colModel contains the models for the columns + $colModel = array(); + + // $aDataDisplayed will contain the fields which are displayed + $aDataDisplayed = array(array('field'=>'submitdate', 'type'=>'submitdate')); + + $colNames[] = $clang->gT("Actions"); + $colModel[] = array( + 'name' => "actions", + 'index' => "actions", + 'align' => 'center', + 'sortable' => false, + 'width' => 50 + ); + + //$fnames[] = array("submitdate", $clang->gT("Completed"), $clang->gT("Completed"), "0", 'D'); + $colNames[] = $clang->gT("Completed"); + $colModel[] = array( + 'name' => "submitdate", + 'index' => "submitdate", + 'align' => 'center', + 'sorttype' => 'string', + 'width' => 50, + 'editable' => true, + 'edittype' => 'select', + 'editoptions' => array('value' => "Y:Yes;N:No") + ); + + //add token to top of list if survey is not private + if ($surveyinfo['anonymized'] == "N" && db_tables_exist($tokentable)) //add token to top of list if survey is not private + { + $aDataDisplayed[] = array(array('field'=>'token', 'type'=>'firstname')); + //$fnames[] = array("token", "Token", $clang->gT("Token ID"), 0); + $colNames[] = $clang->gT("Token ID"); + $colModel[] = array( + 'name' => "token", + 'index' => "token", + 'width' => 100, + 'align' => 'center', + 'sorttype' => 'int' + ); + + + $aDataDisplayed[] = array(array('field'=>'firstname', 'type'=>'firstname')); + //$fnames[] = array("firstname", "First name", $clang->gT("First name"), 0); + $colNames[] = $clang->gT("First Name"); + $colModel[] = array( + 'name' => "firstname", + 'index' => "firstname", + 'align' => 'center', + 'sorttype' => 'string' + ); + + + $aDataDisplayed[] = array(array('field'=>'lastname', 'type'=>'lastname')); + //$fnames[] = array("lastname", "Last name", $clang->gT("Last name"), 0); + $colNames[] = $clang->gT("Last Name"); + $colModel[] = array( + 'name' => "lastname", + 'index' => "lastname", + 'align' => 'center', + 'sorttype' => 'string' + ); + + + $aDataDisplayed[] = array(array('field'=>'email', 'type'=>'email')); + //$fnames[] = array("email", "Email", $clang->gT("Email"), 0); + $colNames[] = $clang->gT("Email"); + $colModel[] = array( + 'name' => "lastname", + 'index' => "lastname", + 'align' => 'center', + 'sorttype' => 'string' + ); + + } + + $fields = createFieldMap($surveyid, 'full', false, false, $language); + + foreach ($fields as $fielddetails) + { + if ($fielddetails['fieldname']=='lastpage' || $fielddetails['fieldname'] == 'submitdate') + continue; + + $question = strlen($fielddetails['question']) > 13 ? substr($fielddetails['question'], 0, 10)."..." : $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' || $fielddetails['type']=='page_time' || $fielddetails['type']=='answer_time') + { + continue; + } + + if (isset($fielddetails['subquestion']) && $fielddetails['subquestion']!='') + $question .=' ('.( strlen($fielddetails['subquestion']) > 13 ? substr($fielddetails['subquestion'], 0, 10)."..." : $fielddetails['subquestion']).')'; + + if (isset($fielddetails['subquestion1']) && isset($fielddetails['subquestion2'])) + $question .=' ('.( strlen($fielddetails['subquestion1']) > 13 ? substr($fielddetails['subquestion1'], 0, 10)."..." : $fielddetails['subquestion1']) + .':'.( strlen($fielddetails['subquestion2']) > 13 ? substr($fielddetails['subquestion2'], 0, 10)."..." : $fielddetails['subquestion2']).')'; + + if (isset($fielddetails['scale_id'])) + $question .= '['.( strlen($fielddetails['scale']) > 13 ? substr($fielddetails['scale'], 0, 10)."..." : $fielddetails['scale']).']'; + + // $fnames[]=array($fielddetails['fieldname'],$question); + $aDataDisplayed[] = array('field' => $fielddetails['fieldname'], 'type' => 'normal'); + $colNames[] = $question; + $colModel[] = array( + 'name' => $fielddetails['fieldname'], + 'index' => $fielddetails['fieldname'], + 'align' => 'center', + 'sorttype' => 'string', + 'editable' => ($fielddetails['fieldname'] == 'id' ? false: true) + ); + } + + else + { + if ($fielddetails['aid']!=='filecount') + { + $qidattributes = getQuestionAttributeValues($fielddetails['qid']); + + for ($i = 0; $i < $qidattributes['max_num_of_files']; $i++) + { + if ($qidattributes['show_title'] == 1) + { + //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(Title)", "type"=>"|", "metadata"=>"title", "index"=>$i); + $colNames[] ="File ".($i+1)." - ".$fielddetails['question']."(Title)"; + $colModel[] = array( + 'name' => $fielddetails['fieldname']."_title_$i", + 'index' => $fielddetails['fieldname']."_title_$i", + 'align' => 'center', + 'sorttype' => 'string', + 'editable' => true + ); + } + + if ($qidattributes['show_comment'] == 1) + { + //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(Comment)", "type"=>"|", "metadata"=>"comment", "index"=>$i); + $colNames[] = "File ".($i+1)." - ".$fielddetails['question']."(Comment)"; + $colModel[] = array( + 'name' => $fielddetails['fieldname']."_comment_$i", + 'index' => $fielddetails['fieldname']."_comment_$i", + 'align' => 'center', + 'sorttype' => 'string', + 'editable' => true + ); + } + + //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(File name)", "type"=>"|", "metadata"=>"name", "index"=>$i); + $colNames[] = "File ".($i+1)." - ".$fielddetails['question']."(File name)"; + $colModel[] = array( + 'name' => $fielddetails['fieldname']."_name_$i", + 'index' => $fielddetails['fieldname']."_name_$i", + 'align' => 'center', + 'sorttype' => 'string' + ); + + //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(File size)", "type"=>"|", "metadata"=>"size", "index"=>$i); + $colNames[] = "File ".($i+1)." - ".$fielddetails['question']."(File size) (KB)"; + $colModel[] = array( + 'name' => $fielddetails['fieldname']."_size_$i", + 'index' => $fielddetails['fieldname']."_size_$i", + 'align' => 'center', + 'sorttype' => 'int' + ); + + + //$fnames[] = array($fielddetails['fieldname'], "File ".($i+1)." - ".$fielddetails['question']."(extension)", "type"=>"|", "metadata"=>"ext", "index"=>$i); + } + + $aDataDisplayed[] = array( + 'field' => $fielddetails['fieldname'], + 'type' => 'file', + 'attr' => array( + 'title' => $qidattributes['show_title'], + 'comment' => $qidattributes['show_comment'], + 'numfiles' => $qidattributes['max_num_of_files'] + ) + ); + + } + else + { + //$fnames[] = array($fielddetails['fieldname'], "File count"); + $aDataDisplayed[] = array('field' => $fielddetails['fieldname'], 'type' => 'filecount'); + $colNames[] = $question; + $colModel[] = array( + 'name' => 'File count', + 'index' => $fielddetails['fieldname'], + 'align' => 'center', + 'sorttype' => 'int' + ); + } + } + } + + // $fncount = count($fnames); + + $data = array( + 'surveyID' => $surveyid, + 'colNames' => $colNames, + 'colModel' => $colModel + ); + + $_SESSION['browse'] = array('dataDisplayed' => $aDataDisplayed); + + $this->load->view('admin/browse/displayResponses_view', $data); + self::_js_admin_includes($this->config->item('adminscripts')."browse.js"); + + /* + //NOW LETS CREATE A TABLE WITH THOSE HEADINGS + $tableheader = ""; + if ($fncount < 10) {$tableheader .= "\n";} + else {$tableheader .= "
\n";} + $tableheader .= "\t\n" + . "\n" + . "\n"; + + foreach ($fnames as $fn) + { + if (!isset($currentgroup)) {$currentgroup = $fn[1]; $gbc = "odd";} if ($currentgroup != $fn[1]) { $currentgroup = $fn[1]; @@ -593,20 +903,18 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, //LETS COUNT THE DATA $dtquery = "SELECT count(*) FROM $sql_from"; - if ($sql_where!="") - { - $dtquery .=" WHERE $sql_where"; - } - - $dtresult=db_execute_assoc($dtquery) or safe_die("Couldn't get response data
$dtquery
".$connect->ErrorMsg()); - $dtrow=$dtresult->row_array(); - $dtcount=reset($dtrow); - - if ($limit > $dtcount) {$limit=$dtcount;} - - //NOW LETS SHOW THE DATA - if (isset($_POST['sql'])) - { + if ($sql_where!="") + { + $dtquery .=" WHERE $sql_where"; + } + + $dtresult=db_execute_assoc($dtquery) or safe_die("Couldn't get response data
$dtquery
".$connect->ErrorMsg()); + $dtrow=$dtresult->row_array(); + $dtcount=reset($dtrow); + + //NOW LETS SHOW THE DATA + if (isset($_POST['sql'])) + { if ($_POST['sql'] == "NULL" ) { if ($surveyinfo['anonymized'] == "N" && db_tables_exist($tokentable)) @@ -694,13 +1002,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $data['start'] = $start; $data['tableheader'] = $tableheader; $data['limit'] = $limit; - $data['last'] = $last; - $data['next'] = $next; - $data['end'] = $end; - $this->load->view("admin/browse/browseallheader_view", $data); - - foreach ($dtresult->result_array() as $dtrow) - { + $data['last'] = $last; + $data['next'] = $next; + $data['end'] = $end; + //$this->load->view("admin/browse/browseallheader_view", $data); + + foreach ($dtresult->result_array() as $dtrow) + { if (!isset($bgcc)) {$bgcc="even";} else { @@ -709,15 +1017,15 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, } $data['bgcc'] = $bgcc; $data['dtrow'] = $dtrow; - $data['surveyinfo'] = $surveyinfo; - $data['fncount'] = $fncount; - $data['fnames'] = $fnames; - $this->load->view("admin/browse/browseallrow_view", $data); - } - $this->load->view("admin/browse/browseallfooter_view", $data); - } - elseif ($surveyinfo['savetimings']=="Y" && $subaction == "time"){ - $browseoutput .= $surveyoptions; + $data['surveyinfo'] = $surveyinfo; + $data['fncount'] = $fncount; + $data['fnames'] = $fnames; + //$this->load->view("admin/browse/browseallrow_view", $data); + } + //$this->load->view("admin/browse/browseallfooter_view", $data);*/ + } + elseif ($surveyinfo['savetimings']=="Y" && $subaction == "time"){ + $browseoutput .= $surveyoptions; $browseoutput .= '
'.$clang->gT('Time statistics').'
'; // table of time statistics - only display completed surveys @@ -791,13 +1099,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, //LETS COUNT THE DATA $dtquery = "SELECT count(tid) FROM {$surveytimingstable} INNER JOIN {$surveytable} ON {$surveytimingstable}.id={$surveytable}.id WHERE submitdate IS NOT NULL "; - - $dtresult=db_execute_assoc($dtquery) or safe_die("Couldn't get response data
$dtquery
".$connect->ErrorMsg()); - $dtrow=$dtresult->row_array(); - $dtcount=reset($dtrow); - - if ($limit > $dtcount) {$limit=$dtcount;} - + + $dtresult=db_execute_assoc($dtquery) or safe_die("Couldn't get response data
$dtquery
".$connect->ErrorMsg()); + $dtrow=$dtresult->row_array(); + $dtcount=reset($dtrow); + + if ($limit > $dtcount) {$limit=$dtcount;} + //NOW LETS SHOW THE DATA $dtquery = "SELECT t.* FROM {$surveytimingstable} t INNER JOIN {$surveytable} ON t.id={$surveytable}.id WHERE submitdate IS NOT NULL ORDER BY {$surveytable}.id"; @@ -809,12 +1117,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $dtresult = db_select_limit_assoc($dtquery, $limit, $start) or safe_die("Couldn't get surveys
$dtquery
".$connect->ErrorMsg()); } else - { - $dtresult = db_execute_assoc($dtquery) or safe_die("Couldn't get surveys
$dtquery
".$connect->ErrorMsg()); - } - $dtcount2 = $dtresult->num_rows(); - $cells = $fncount+1; - + { + $dtresult = db_execute_assoc($dtquery) or safe_die("Couldn't get surveys
$dtquery
".$connect->ErrorMsg()); + } + echo "DFSA"; + $dtcount2 = $dtresult->num_rows(); + $cells = $fncount+1; + //CONTROL MENUBAR $last=$start-$limit; $next=$start+$limit; @@ -959,13 +1268,13 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $browseoutput .= '
".$clang->gT('Actions')."
'; } elseif ($subaction=="time") - { - $browseoutput .= $surveyoptions; - $browseoutput .= "
".$clang->gT("Timings")."
"; - $browseoutput .= "Timing saving is disabled or the timing table does not exist. Try to reactivate survey.\n"; - } - else - { + { + $browseoutput .= $surveyoptions; + $browseoutput .= "
".$clang->gT("Timings")."
"; + $browseoutput .= "Timing saving is disabled or the timing table does not exist. Try to reactivate survey.\n"; + } + else + { $browseoutput .= $surveyoptions; $num_total_answers=0; $num_completed_answers=0; @@ -980,27 +1289,26 @@ function action($surveyid = null, $subaction = null, $var1 = null, $var2 = null, $data['num_completed_answers']=reset($gnrow2); $this->load->view("admin/browse/browseindex_view", $data); } - - echo $browseoutput; - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); - - } - - + + echo $browseoutput; + self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + } + + /** * 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 - * @return ZipArchive - */ - function zipFiles($responseIds, $zipfilename) { - global $surveyid, $surveytable; - - $tmpdir = $CI->config->item('uploaddir'). "/surveys/" . $surveyid . "/files/"; - - $filelist = array(); - $fieldmap = createFieldMap($surveyid, 'full'); + * @param array $responseIds + * @return ZipArchive + */ + function zipFiles($surveyid, $responseIds, $zipfilename) { + $surveytable = $this->db->dbprefix('survey_'.$surveyid); + + $tmpdir = $this->config->item('uploaddir'). "/surveys/" . $surveyid . "/files/"; + + $filelist = array(); + $fieldmap = createFieldMap($surveyid, 'full'); foreach ($fieldmap as $field) { @@ -1012,18 +1320,17 @@ function zipFiles($responseIds, $zipfilename) { $initquery = "SELECT " . implode(', ', $filequestion); - foreach ((array)$responseIds as $responseId) - { - $responseId=(int)$responseId; // sanitize the value - - $query = $initquery . " FROM $surveytable WHERE id=$responseId"; - $filearray = db_execute_assoc($query) or safe_die("Could not download response
$query
".$connect->ErrorMsg()); - $metadata = array(); - $filecount = 0; - while ($metadata = $filearray->FetchRow()) - { - foreach ($metadata as $data) - { + foreach ((array)$responseIds as $responseId) + { + $responseId=(int)$responseId; // sanitize the value + $query = $initquery . " FROM $surveytable WHERE id=$responseId"; + $filearray = db_execute_assoc($query) or safe_die("Could not download response
$query
".$connect->ErrorMsg()); + $metadata = array(); + $filecount = 0; + foreach($filearray->result_array() as $metadata) + { + foreach ($metadata as $data) + { $phparray = json_decode($data, true); if (is_array($phparray)) { foreach($phparray as $file) { @@ -1047,13 +1354,13 @@ function zipFiles($responseIds, $zipfilename) { if (count($filelist)>0) { $this->load->library("admin/pclzip/pclzip",array('p_zipname' => $tempdir.$zipfilename)); $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'); + 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'); @@ -1066,7 +1373,7 @@ function zipFiles($responseIds, $zipfilename) { unlink($tmpdir . "/" . $zipfilename); exit; } - } - } - -} \ No newline at end of file + } + } + +} diff --git a/application/controllers/admin/dataentry.php b/application/controllers/admin/dataentry.php index 3b7b4dc5026..bb6ec740336 100644 --- a/application/controllers/admin/dataentry.php +++ b/application/controllers/admin/dataentry.php @@ -591,16 +591,20 @@ function import($surveyid) * @param mixed $subaction * @param mixed $id * @param mixed $surveyid - * @param mixed $language - * @return - */ - function editdata($subaction,$id,$surveyid,$language) - { - $surveyid = sanitize_int($surveyid); - $id = sanitize_int($id); - if (!isset($sDataEntryLanguage)) - { - $sDataEntryLanguage = GetBaseLanguageFromSurveyID($surveyid); + * @param mixed $language + * @return + */ + function editdata($subaction,$id,$surveyid,$language='') + { + if ($language == '') { + $language = GetBaseLanguageFromSurveyID($surveyid); + } + + $surveyid = sanitize_int($surveyid); + $id = sanitize_int($id); + if (!isset($sDataEntryLanguage)) + { + $sDataEntryLanguage = GetBaseLanguageFromSurveyID($surveyid); } $surveyinfo=getSurveyInfo($surveyid); @@ -1196,14 +1200,13 @@ function editdata($subaction,$id,$surveyid,$language) case "|": //FILE UPLOAD $dataentryoutput .= "\n"; if ($fname['aid']!=='filecount' && isset($idrow[$fname['fieldname'] . '_filecount']) && ($idrow[$fname['fieldname'] . '_filecount'] > 0)) - {//file metadata - $metadata = json_decode($idrow[$fname['fieldname']], true); - $qAttributes = getQuestionAttributeValues($fname['qid']); - - for ($i = 0; $i < $qAttributes['max_files'], isset($metadata[$i]); $i++) - { - if ($qAttributes['show_title']) - $dataentryoutput .= ''; + {//file metadata + $metadata = json_decode($idrow[$fname['fieldname']], true); + $qAttributes = getQuestionAttributeValues($fname['qid']); + for ($i = 0; $i < $qAttributes['max_num_of_files'], isset($metadata[$i]); $i++) + { + if ($qAttributes['show_title']) + $dataentryoutput .= ''; if ($qAttributes['show_comment']) $dataentryoutput .= ''; @@ -1949,13 +1952,13 @@ function insert() $filecount = 0; for ($i = 0; $filecount < count($phparray); $i++) - { - if ($_FILES[$fieldname."_file_".$i]['error'] != 4) - { - $target = $CI->config->item('uploaddir')."/surveys/". $thissurvey['sid'] ."/files/".sRandomChars(20); - $size = 0.001 * $_FILES[$fieldname."_file_".$i]['size']; - $name = rawurlencode($_FILES[$fieldname."_file_".$i]['name']); - + { + if ($_FILES[$fieldname."_file_".$i]['error'] != 4) + { + $target = $this->config->item('uploaddir')."/surveys/". $thissurvey['sid'] ."/files/".sRandomChars(20); + $size = 0.001 * $_FILES[$fieldname."_file_".$i]['size']; + $name = rawurlencode($_FILES[$fieldname."_file_".$i]['name']); + if (move_uploaded_file($_FILES[$fieldname."_file_".$i]['tmp_name'], $target)) { $phparray[$filecount]->filename = basename($target); @@ -2163,17 +2166,17 @@ function insert() * @param mixed $surveyid * @param mixed $lang * @return - */ - function view($surveyid,$lang=NULL) - { - $surveyid = sanitize_int($surveyid); - if(isset($lang)) $lang=sanitize_languagecode($urlParam); - self::_getAdminHeader(); - - if (bHasSurveyPermission($surveyid, 'responses','read')) - { - $clang = $this->limesurvey_lang; - + */ + function view($surveyid,$lang=NULL) + { + $surveyid = sanitize_int($surveyid); + if(isset($lang)) $lang=sanitize_languagecode($urlParam); + self::_getAdminHeader(); + + if (bHasSurveyPermission($surveyid, 'responses', 'read')) + { + $clang = $this->limesurvey_lang; + $sDataEntryLanguage = GetBaseLanguageFromSurveyID($surveyid); $surveyinfo=getSurveyInfo($surveyid); @@ -2193,12 +2196,13 @@ function view($surveyid,$lang=NULL) $blang = $this->limesurvey_lang; //new limesurvey_lang($lang); $sDataEntryLanguage = $lang; } - - $langlistbox = languageDropdown($surveyid,$sDataEntryLanguage); - $thissurvey=getSurveyInfo($surveyid); - //This is the default, presenting a blank dataentry form - $fieldmap=createFieldMap($surveyid); - // PRESENT SURVEY DATAENTRY SCREEN + + $langlistbox = languageDropdown($surveyid,$sDataEntryLanguage); + $thissurvey=getSurveyInfo($surveyid); + + //This is the default, presenting a blank dataentry form + $fieldmap=createFieldMap($surveyid); + // PRESENT SURVEY DATAENTRY SCREEN //$dataentryoutput .= $surveyoptions; /** $dataentryoutput .= "
".$clang->gT("Data entry")."
\n"; @@ -2290,25 +2294,28 @@ function view($surveyid,$lang=NULL) LimeExpressionManager::StartProcessingPage(false,true,true); // means that all variables are on the same page - $this->load->view("admin/dataentry/caption_view",$data); - - $this->load->helper('database'); - - - // SURVEY NAME AND DESCRIPTION TO GO HERE - $degquery = "SELECT * FROM ".$this->db->dbprefix."groups WHERE sid=$surveyid AND language='{$sDataEntryLanguage}' ORDER BY ".$this->db->dbprefix."groups.group_order"; - $degresult = db_execute_assoc($degquery); - // GROUP NAME - $dataentryoutput = ''; - foreach ($degresult->result_array() as $degrow) + $this->load->view("admin/dataentry/caption_view",$data); + + $this->load->helper('database'); + $this->load->helper('database'); + + + // SURVEY NAME AND DESCRIPTION TO GO HERE + $degquery = "SELECT * FROM ".$this->db->dbprefix."groups WHERE sid=$surveyid AND language='{$sDataEntryLanguage}' ORDER BY ".$this->db->dbprefix."groups.group_order"; + $degresult = db_execute_assoc($degquery); + + // GROUP NAME + $dataentryoutput = ''; + foreach ($degresult->result_array() as $degrow) { LimeExpressionManager::StartProcessingGroup($degrow['gid'],($thissurvey['anonymized']!="N"),$surveyid); - - $deqquery = "SELECT * FROM ".$this->db->dbprefix."questions WHERE sid=$surveyid AND parent_qid=0 AND gid={$degrow['gid']} AND language='{$sDataEntryLanguage}'"; - $deqresult = db_execute_assoc($deqquery); - $dataentryoutput .= "\t\n" - ."\n" - ."\t\n"; + + $deqquery = "SELECT * FROM ".$this->db->dbprefix."questions WHERE sid=$surveyid AND parent_qid=0 AND gid={$degrow['gid']} AND language='{$sDataEntryLanguage}'"; + $deqresult = db_execute_assoc($deqquery); + + $dataentryoutput .= "\t\n" + ."\n" + ."\t\n"; $gid = $degrow['gid']; $dataentryoutput .= "\t\n"; @@ -3574,13 +3581,13 @@ function saveshow(value) } - self::_loadEndScripts(); - - - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); - - - } + self::_loadEndScripts(); + + + self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + + + } } diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 6758e98282c..d46eee2b1b2 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -3176,13 +3176,14 @@ function getQuestionAttributeValues($qid, $type='') if (isset($cache[$qid])) { return $cache[$qid]; - } - $CI->load->model('questions_model'); - $result = $CI->questions_model->getSomeRecords(array('type','sid'),array('qid'=>$qid)) or safe_die("Error finding question attributes"); //Checked - $row=$result->row_array(); - if ($row===false) // Question was deleted while running the survey - { - $cache[$qid]=false; + } + $CI->load->model('questions_model'); + $result = $CI->questions_model->getSomeRecords(array('type','sid'),array('qid'=>$qid)) or safe_die("Error finding question attributes"); //Checked + $row=$result->row_array(); + + if ($row===false) // Question was deleted while running the survey + { + $cache[$qid]=false; return false; } $type=$row['type']; diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index f561ead73a5..12bf6a0bf38 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -5303,13 +5303,12 @@ function do_shortfreetext($ia) if ($_SESSION[$ia[1]]) {$answer .= str_replace("\\", "", $_SESSION[$ia[1]]);} - $answer .= "\n"; - } - elseif((int)($aQuestionAttributes['location_mapservice'])!=0){ - - $mapservice = $aQuestionAttributes['location_mapservice']; - $currentLocation = $_SESSION[$ia[1]]; - $currentLatLong = null; + $answer .= "\n"; + } + elseif((int)($aQuestionAttributes['location_mapservice'])!=0){ + $mapservice = $aQuestionAttributes['location_mapservice']; + $currentLocation = $_SESSION[$ia[1]]; + $currentLatLong = null; $floatLat = 0; $floatLng = 0; diff --git a/application/models/surveys_dynamic_model.php b/application/models/surveys_dynamic_model.php index f07637a9c38..7dcaf666143 100644 --- a/application/models/surveys_dynamic_model.php +++ b/application/models/surveys_dynamic_model.php @@ -29,27 +29,102 @@ function getSomeRecords($fields,$iSurveyID,$condition=FALSE,$order=FALSE) $this->db->order_by($order); } $data = $this->db->get('survey_'.$iSurveyID); - - return $data; - } - - function quotaCompletedCount($iSurveyID,$querycond) - { + + return $data; + } + + /** + * Get the records with ids from $iFrom to $iFrom + $iCount + * @param $iSurveyID ID of the survey + * @param $iFrom Beginning of the range + * @param $iCount Number of rows + * @param $sSortCol Sort the elements by this colum + * @param $sSortOrder Order of the sort + * @return mixed + */ + function getRecordsInRange($iSurveyID, $iFrom, $iCount, $sSortCol, $sSortOrder) + { + $this->db->order_by($sSortCol, $sSortOrder); + return $this->db->get('survey_'.$iSurveyID, $iCount, $iFrom); + } + + function quotaCompletedCount($iSurveyID,$querycond) + { //Used by get_quotaCompletedCount() $querysel = "SELECT count(id) as count FROM ".db_table_name('survey_'.$iSurveyID)." WHERE ".implode(' AND ',$querycond)." "." AND submitdate IS NOT NULL"; - return $this->db->query($querysel); - } - - function insertRecords($iSurveyID,$data) - { - return $this->db->insert('survey_'.$iSurveyID, $data); - } - - function deleteRecords($iSurveyID,$condition) - { - $this->db->where($condition); - return $this->db->delete('survey_'.$iSurveyID); - } - - -} + return $this->db->query($querysel); + } + + /** + * Insert a new response + * @param int $iSurveyID ID of the survey + * @param array $data The response + * @return mixed + */ + function insertRecords($iSurveyID, $data) + { + return $this->db->insert('survey_'.$iSurveyID, $data); + } + + /** + * Get data from certain columns for a response + * @param array $aFields Array containing field names + * @param int $iSurveyID ID of the survey + * @param int $iResponseID ID of the response + * @return mixed + */ + function getFieldsForID($aFields, $iSurveyID, $iResponseID) + { + foreach ($aFields as $field) + { + $this->db->select($field); + } + + $this->db->where('id', $iResponse); + return $this->db->get('survey_'.$iSurveyID); + } + + + /** + * Get a response from the database + * @param int $iSurveyID ID of the survey + * @param int $iResponseID ID of the response + * @return mixed + */ + function getResponse($iSurveyID, $iResponseID) + { + $this->db->where('id', $iResponseID); + return $this->db->get('survey_'.$iSurveyID); + } + + function deleteRecords($iSurveyID,$condition) + { + $this->db->where($condition); + return $this->db->delete('survey_'.$iSurveyID); + } + + function deleteResponse($iSurveyID, $iResponseID) + { + $this->db->where('id', $iResponseID); + return $this->db->delete('survey_'.$iSurveyID); + } + + function getResponseCount($iSurveyID) + { + return $this->db->count_all_results('survey_'.$iSurveyID); + } + + + /** + * Update a response + * @param int $iSurveyID ID of the survey + * @param int $iResponseID ID of the response + * @param array $aData Array containg response data + * @return mixed + */ + function updateResponse($iSurveyID, $iResponseID, $aData) + { + $this->db->where('id', $iResponseID); + $this->db->update('survey_'.$iSurveyID, $aData); + } +} diff --git a/application/views/admin/browse/browsemenubar_view.php b/application/views/admin/browse/browsemenubar_view.php index 892a5bd0717..fd3b9449c7f 100644 --- a/application/views/admin/browse/browsemenubar_view.php +++ b/application/views/admin/browse/browsemenubar_view.php @@ -13,13 +13,13 @@ "> <?php echo $clang->gT("Show summary information");?> - "> - <?php echo $clang->gT("Display Responses");?> - - " > - <?php echo $clang->gT("Display Responses");?> - -
gT("Please select a language:");?>
- \ No newline at end of file + + + + diff --git a/scripts/admin/browse.js b/scripts/admin/browse.js index 5843240fb15..bdb9415303a 100644 --- a/scripts/admin/browse.js +++ b/scripts/admin/browse.js @@ -1,132 +1,132 @@ /* * LimeSurvey -* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz -* All rights reserved. -* License: GNU/GPL License v2 or later, see LICENSE.php -* LimeSurvey is free software. This version may have been modified pursuant -* to the GNU General Public License, and as distributed it includes or -* is derivative of works licensed under the GNU General Public License or -* other free or open source software licenses. +* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz +* All rights reserved. +* License: GNU/GPL License v2 or later, see LICENSE.php +* LimeSurvey is free software. This xversion may have been modified pursuant +* to the GNU General Public License, and as distributed it includes or +* is derivative of works licensed under the GNU General Public License or +* other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. * * $Id: browse.js 10251 2011-06-10 17:33:49Z tpartner $ -*/ - -$(document).ready(function(){ - // Delete individual file - $(".deleteresponse").click(function(){ - thisid=removechars($(this).attr('id')); - answer = confirm(strdeleteconfirm); - if (answer==true) - { - $('#deleteanswer').val(thisid); - $('.cbResponseMarker').attr('checked',false); - $('#resulttableform').submit(); - } - }); - - // Delete all marked responses - $("#imgDeleteMarkedResponses").click(function(){ - if ($('.cbResponseMarker:checked').size()>0) - { - thisid=removechars($(this).attr('id')); - answer = confirm(strDeleteAllConfirm); - if (answer==true) - { - $('#deleteanswer').val('marked'); - $('#resulttableform').submit(); - } - } - else - alert(noFilesSelectedForDeletion) - }); - - // Download individual file bundle - $(".downloadfile").click(function() { - thisid = removechars($(this).attr('id')); - $('#downloadfile').val(thisid); - $('.cbResponseMarker').attr('checked', false); - $('#resulttableform').submit(); - }); - - // Download all marked files - $("#imgDownloadMarkedFiles").click(function() { - if ($('.cbResponseMarker:checked').size() > 0) - { - $('#downloadfile').val('marked'); - $('#resulttableform').submit(); - } - else - alert(noFilesSelectedForDnld) - }); - - $("#selectall").click(function(){ - $('.cbResponseMarker').attr('checked',$(this).attr('checked')); - }); - - $('#browseresponses').qtip({ - content:{ - text:$('#browselangpopup') - }, - style: { name: 'cream', - tip:true, - color:'#111111', - border: { - width: 1, - radius: 5, - color: '#EADF95'} - }, - position: { adjust: { - screen: true, scroll:true }, - corner: { - target: 'bottomMiddle', - tooltip: 'topMiddle'} - }, - show: {effect: { length:50}, - when: { - event:'click' - }}, - hide: {fixed:true, - when: { - event:'unfocus' - }} - }); - - // Fix the heigh of the cell - $('.browsetable td').each(function(){ - if ($(this).text().length> 30){ - $(this).html(""+$(this).html()+""); - } - }); - $('.browsetable th strong').each(function(){ - if ($(this).text().length> 30){ - $(this).addClass("content"); - $(this).attr("title",$(this).text()); - } - }); - - $('.browsetable td span.content').qtip({ - hide: { - fixed: true, - delay: 500 - }, - position: { - corner: { - target: 'leftMiddle', - tooltip: 'topRight' - } - } - }); - $('.browsetable th strong.content').qtip({ - hide: { - fixed: true, - delay: 500 - }, - position: { - corner: { - target: 'leftMiddle', - tooltip: 'topRight' - } - } - }); -}); +*/ + +$(document).ready(function(){ + var lastSel = 0; + + $("#responseTable") + .jqGrid({ + url: siteURL + "/admin/browse/" + surveyID + "/grid", + editurl: siteURL + "/admin/browse/" + surveyID + "/grid", + datatype: "json", + mtype: "POST", + caption: "Responses", + width: "100%", + height: "100%", + rowNum: 25, + pager: "#responsePager", + editable: true, + colNames: colNames, + colModel: colModel, + sortname: 'id', + sortorder: 'asc', + viewrecords : true, + gridview: true, + multiselect: true, + loadonce: true, + rowList: [25,50,100,250,500,1000,5000,10000], + ondblClickRow: function(id) { + if (lastSel != id) { + $('#responseTable').saveRow(lastSel); + $('#responseTable').editRow(id, true); + lastSel=id; + } + }, + onSelectRow: function(id) { + $('#responseTable').saveRow(lastSel); + } + }) + .filterToolbar({ + 'autosearch': true, + 'searchOnEnter': false + }) + .navGrid("#responsePager", { + 'add': false, + 'refresh': false, + 'edit': false + }) + .navButtonAdd("#responsePager", { + 'caption': 'Download marked files', + 'onClickButton': function (rows) { + var rows = $("#responseTable").getGridParam('selarrrow'); + + if (rows.length <= 0) { + alert ("Please select some records first!"); + return; + } + + sendPost(siteURL + "/admin/browse/" + surveyID + "/grid", { + 'oper': 'downloadarchives', + 'ids': rows + }); + } + }) +}); + + +/** + Send a post request to the server to download a file + + @param myaction post action + @param data parameters for $_POST + +*/ +function sendPost(myaction, data) +{ + var myform = document.createElement('form'); + document.body.appendChild(myform); + myform.action = myaction; + myform.method = 'POST'; + + for (var key in data) { + var myel = document.createElement('input'); + myel.type = 'hidden'; + myel.name = key; + myform.appendChild(myel); + myel.value = data[key]; + } + + myform.submit(); +} + + +/** + Dowload a file from a response + @param id ID of the response + @param column Field of the text upload question + @param filename Name of the file +*/ +function getFile(id, field, filename) +{ + sendPost(siteURL + "/admin/browse/" + surveyID + "/grid", { + 'id': id, + 'fieldname': field, + 'oper': 'downloadfile', + 'filename': filename + }); +} + + +/** + Get an archive containing all the file from a response + @param id ID of the response +*/ +function getArchive(id) +{ + sendPost(siteURL + "/admin/browse/" + surveyID + "/grid", { + 'oper': 'downloadarchive', + 'id': id + }); +} + diff --git a/scripts/jquery/jquery.qtip.js b/scripts/jquery/jquery.qtip.js index 348a5f0edcc..0dc1644b26c 100644 --- a/scripts/jquery/jquery.qtip.js +++ b/scripts/jquery/jquery.qtip.js @@ -2146,4 +2146,4 @@ classes: { tooltip: 'qtip-blue' } } }; -})(jQuery); \ No newline at end of file +})(jQuery);
Title
Title
Comment
".FlattenText($degrow['group_name'],true)."
".FlattenText($degrow['group_name'],true)."