Skip to content

Commit

Permalink
Fixed issue: Problems with using the File Upload question type
Browse files Browse the repository at this point in the history
Dev Fixed issue #5928: Unable to edit answer or subquestion
  • Loading branch information
c-schmitz committed Mar 20, 2012
1 parent 0d8dde4 commit b57d62a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 112 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/printablesurvey.php
Expand Up @@ -54,12 +54,12 @@ function index($surveyid, $lang = null)
// Setting the selected language for printout
$clang = new limesurvey_lang($surveyprintlang);

$desrow = Survey::model()->with('languagesettings')->findByAttributes(array('sid' => $surveyid, 'language' => $surveyprintlang));
$desrow = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findByAttributes(array('sid' => $surveyid, 'language' => $surveyprintlang));

if (is_null($desrow))
$this->getController()->error('Invalid survey ID');

$desrow = array_merge($desrow->attributes, $desrow->languagesettings->attributes);
$desrow = array_merge($desrow->attributes, $desrow->languagesettings[0]->attributes);

//echo '<pre>'.print_r($desrow,true).'</pre>';
$template = $desrow['template'];
Expand Down
20 changes: 10 additions & 10 deletions application/controllers/admin/question.php
Expand Up @@ -382,12 +382,12 @@ public function _editansweroptions($surveyid, $gid, $qid)
$aData['scalecount'] = $scalecount;

// The following line decides if the assessment input fields are visible or not
$sumresult1 = Survey::model()->with('languagesettings')->together()->findByAttributes(array('sid' => $surveyid));
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->together()->findByAttributes(array('sid' => $surveyid));
if (is_null($sumresult1))
$this->getController()->error('Invalid survey ID');

$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings->attributes);
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings[0]->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);
$assessmentvisible = ($surveyinfo['assessments'] == 'Y' && $qtypes[$qtype]['assessable'] == 1);
$aData['assessmentvisible'] = $assessmentvisible;
Expand Down Expand Up @@ -583,12 +583,12 @@ public function _editsubquestion($surveyid, $gid, $qid)

$aData['scalecount'] = $scalecount = $qtypes[$qtype]['subquestions'];

$sumresult1 = Survey::model()->with('languagesettings')->together()->findByAttributes(array('sid' => $surveyid));
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->together()->findByAttributes(array('sid' => $surveyid));
if ($sumresult1 == null)
$this->getController()->error('Invalid survey id');

$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings->attributes);
$surveyinfo = array_merge($surveyinfo, $sumresult1->languagesettings[0]->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);

$aData['activated'] = $activated = $surveyinfo['active'];
Expand Down Expand Up @@ -940,7 +940,7 @@ public function ajaxquestionattributes()
$aData['attributedata'] = $aAttributesPrepared;
$this->getController()->render('/admin/survey/Question/advanced_settings_view', $aData);
}

/**
* This function prepares the data for label set details
*
Expand All @@ -951,12 +951,12 @@ public function ajaxlabelsetdetails()
{
$lid=returnglobal('lid');
Yii::app()->loadHelper('surveytranslator');

$labelsetdata=Labelsets::model()->find('lid=:lid',array(':lid' => $lid)); //$connect->GetArray($query);

$labelsetlanguages=explode(' ',$labelsetdata->languages);
foreach ($labelsetlanguages as $language){

//$query='select * from lime_labels where lid='.$lid." and language='{$language}' order by sortorder";
$criteria=new CDbCriteria;
$criteria->condition='lid=:lid and language=:language';
Expand All @@ -978,10 +978,10 @@ public function ajaxlabelsetdetails()
//$labels=dbExecuteAssoc($query); //Label::model()->find(array('lid' => $lid, 'language' => $language), array('order' => 'sortorder')); //$connect->GetArray($query);
$resultdata[]=array($language=>array($labels,getLanguageNameFromCode($language,false)));
}

echo json_encode($resultdata);
}

/**
* This function prepares the data for labelset
*
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/admin/translate.php
Expand Up @@ -298,8 +298,8 @@ private function _getSurveyButton($surveyid, $menuitem_url)
$baselang = Survey::model()->findByPk($surveyid)->language;
$langs = Survey::model()->findByPk($surveyid)->additionalLanguages;

$surveyinfo = Survey::model()->with('languagesettings')->findByPk($surveyid);
$surveyinfo = array_merge($surveyinfo->attributes, $surveyinfo->languagesettings->attributes);
$surveyinfo = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->findByPk($surveyid);
$surveyinfo = array_merge($surveyinfo->attributes, $surveyinfo->languagesettings[0]->attributes);

$surveyinfo = array_map('flattenText', $surveyinfo);
$menutext = ( $surveyinfo['active'] == "N" ) ? $clang->gT("Test This Survey") : $clang->gT("Execute This Survey");
Expand Down
202 changes: 114 additions & 88 deletions scripts/modaldialog.js
@@ -1,89 +1,115 @@
$(document).ready(function() {
// $('#basic').hide();
// var jsonstring = $('#".$ia[1]."').val();
// var filecount = $('#".$ia[1]."_filecount').val();
// displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show_comment, pos);

$(function() {
$('.upload').click(function(e) {
e.preventDefault();
var $this = $(this);

var show_title = getQueryVariable('show_title', this.href);
var show_comment = getQueryVariable('show_comment', this.href);
var pos = getQueryVariable('pos', this.href);
var fieldname = getQueryVariable('fieldname', this.href);
var buttonsOpts = {};
buttonsOpts[translt.returnTxt] = function() {
// Fix for the IE bug 04965
var pass; if(document.getElementById('uploader').contentDocument) { if(document.getElementById('uploader').contentDocument.defaultView) { /*Firefox*/ pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos); }else{ /*IE8*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos); } }else{ /*IE6*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos); }
if (pass) {
$(this).dialog('destroy');
$('iframe#uploader').remove();
}
};

var horizontalPadding = 30;
var verticalPadding = 20;
$('#uploader').dialog('destroy'); // destroy the old modal dialog

if ($('#uploader').length > 0)
{

$('iframe#uploader', parent.document).dialog({
title: translt.title,
autoOpen: true,
width: 984,
height: 440,
modal: true,
resizable: true,
autoResize: true,
draggable: true,
closeOnEscape: false,
beforeclose: function() {
var pass; if(document.getElementById('uploader').contentDocument) { if(document.getElementById('uploader').contentDocument.defaultView) { /*Firefox*/ pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos); }else{ /*IE8*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos); } }else{ /*IE6*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos); }
if (pass) {
$(this).dialog('destroy');
$('iframe#uploader').remove();
// $('#basic').hide();
// var jsonstring = $('#".$ia[1]."').val();
// var filecount = $('#".$ia[1]."_filecount').val();
// displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show_comment, pos);

$(function() {
$('.upload').click(function(e) {
e.preventDefault();
var $this = $(this);

var show_title = getQueryVariable('show_title', this.href);
var show_comment = getQueryVariable('show_comment', this.href);
var pos = getQueryVariable('pos', this.href);
var fieldname = getQueryVariable('fieldname', this.href);
var buttonsOpts = {};
buttonsOpts[translt.returnTxt] = function() {
// Fix for the IE bug 04965
var pass;
if(document.getElementById('uploader').contentDocument) {
if(document.getElementById('uploader').contentDocument.defaultView)
{ /*Firefox*/
pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos);
}
else
{ /*IE8*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
}
else
{ /*IE6*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
if (pass) {
$(this).dialog('close');
$('iframe#uploader').remove();
$(this).dialog('destroy');
}
};

var horizontalPadding = 30;
var verticalPadding = 20;
$('#uploader').dialog('destroy'); // destroy the old modal dialog

if ($('#uploader').length > 0)
{

$('iframe#uploader', parent.document).dialog({
title: translt.title,
autoOpen: true,
width: 984,
height: 440,
modal: true,
resizable: true,
autoResize: true,
draggable: true,
closeOnEscape: false,
beforeclose: function() {
var pass; if(document.getElementById('uploader').contentDocument) {
if(document.getElementById('uploader').contentDocument.defaultView) { /*Firefox*/
pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos);
}else{ /*IE8*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
}else{
/*IE6*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
else {
$(this).dialog('destroy');
$('iframe#uploader').remove();
return true;

},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts
}).width(984 - horizontalPadding).height(440 - verticalPadding);
}
else
{
$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
title: translt.title,
autoOpen: true,
width: 984,
height: 440,
modal: true,
resizable: true,
autoResize: true,
draggable: true,
closeOnEscape: false,
beforeclose: function() {
var pass;
if(document.getElementById('uploader').contentDocument) {
if(document.getElementById('uploader').contentDocument.defaultView)
{ /*Firefox*/
pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos);
}else{ /*IE8*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}
}else{ /*IE6*/
pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos);
}

},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts
}).width(984 - horizontalPadding).height(440 - verticalPadding);
}
else
{
$('<iframe id=\"uploader\" name=\"uploader\" class=\"externalSite\" src=\"' + this.href + '\" />').dialog({
title: translt.title,
autoOpen: true,
width: 984,
height: 440,
modal: true,
resizable: true,
autoResize: true,
draggable: true,
closeOnEscape: false,
beforeclose: function() {
var pass; if(document.getElementById('uploader').contentDocument) { if(document.getElementById('uploader').contentDocument.defaultView) { /*Firefox*/ pass=document.getElementById('uploader').contentDocument.defaultView.saveAndExit(fieldname,show_title,show_comment,pos); }else{ /*IE8*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos); } }else{ /*IE6*/ pass=document.getElementById('uploader').contentWindow.saveAndExit(fieldname,show_title,show_comment,pos); }
return pass;
},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts
}).width(984 - horizontalPadding).height(440 - verticalPadding);
}
return pass;
},
overlay: {
opacity: 0.85,
background: 'black'
},
buttons: buttonsOpts
}).width(984 - horizontalPadding).height(440 - verticalPadding);
}
});
});
});

});

Expand Down Expand Up @@ -121,7 +147,7 @@ function displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show
}

if (jsonstring !== '')
{
{
jsonobj = eval('(' + jsonstring + ')');
display = '<table width="100%"><tr><th align="center" width="20%">&nbsp;</th>';
if (show_title != 0)
Expand All @@ -132,16 +158,16 @@ function displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show
var image_extensions = new Array('gif', 'jpeg', 'jpg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'jp2', 'iff', 'bmp', 'xbm', 'ico');

for (i = 0; i < filecount; i++)
{
if (pos)
{
if (pos)
{
if (isValueInArray(image_extensions, jsonobj[i].ext))
display += '<tr><td><img src="uploader/index/sid/'+surveyid+'/filegetcontents/'+decodeURIComponent(jsonobj[i].filename)+'" height=100px align="center"/></td>';
else
display += '<tr><td><img src="images/placeholder.png" height=100px align="center"/></td>';
}
else
{
{
if (isValueInArray(image_extensions, jsonobj[i].ext))
display += '<tr><td><img src="uploader/index/filegetcontents/'+decodeURIComponent(jsonobj[i].filename)+'" height=100px align="center"/></td>';
else
Expand All @@ -162,7 +188,7 @@ function displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show
function copyJSON(jsonstring, filecount, fieldname, show_title, show_comment, pos) {
$('#'+fieldname).val(jsonstring);
$('#'+fieldname+'_filecount').val(filecount);

displayUploadedFiles(jsonstring, filecount, fieldname, show_title, show_comment, pos);
}

Expand All @@ -173,4 +199,4 @@ function showBasic() {

function hideBasic() {
$('#basic').hide();
}
}
15 changes: 5 additions & 10 deletions scripts/uploader.js
Expand Up @@ -203,11 +203,11 @@ function passJSON(fieldname, show_title, show_comment, pos) {

while (i <= licount)
{
if (filecount > 0)
json += ",";

if ($("#"+fieldname+"_li_"+i).is(':visible'))
{
if (filecount > 0)
json += ",";
json += '{';

if ($("#"+fieldname+"_show_title").val() == 1)
Expand All @@ -220,12 +220,8 @@ function passJSON(fieldname, show_title, show_comment, pos) {
'"ext":"' +$("#"+fieldname+"_ext_" +i).val()+'"}';

filecount += 1;
i += 1;
}
else
{
i += 1;
}
i += 1;
}
json += "]";
window.parent.window.copyJSON(json, filecount, fieldname, show_title, show_comment, pos);
Expand Down Expand Up @@ -300,7 +296,6 @@ function deletefile(fieldname, count) {
}
filename=$("#"+fieldname+"_filename_"+count).val();
name=$("#"+fieldname+"_name_"+count).val();
//xmlhttp.open('GET','delete.php?sid='+surveyid+'&fieldname='+fieldname+'&filename='+filename+'&name='+encodeURI(name), true);
alert('Not yet implemented!');
xmlhttp.open('GET','delete.php?sid='+surveyid+'&fieldname='+fieldname+'&filename='+filename+'&name='+encodeURI(name), true);
xmlhttp.send();
}
}

0 comments on commit b57d62a

Please sign in to comment.