Skip to content

Commit

Permalink
Dev Fixes for Multi-Flexi and ranking questions
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@8666 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed May 1, 2010
1 parent 5363d38 commit 0025af2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
18 changes: 18 additions & 0 deletions admin/admin.php
Expand Up @@ -761,4 +761,22 @@ function gettemplatelist()
}


/**
* This function set a question attribute to a certain value
*
* @param mixed $qid
* @param mixed $sAttributeName
* @param mixed $sAttributeValue
*/
function setQuestionAttribute($qid,$sAttributeName,$sAttributeValue)
{
global $dbprefix,$connect;
$tablename=$dbprefix.'question_attributes';
$aInsertArray=array('qid'=>$qid,
'attribute'=>$sAttributeName,
'value'=>$sAttributeValue);
$sQuery=$connect->GetInsertSQL($tablename,$aInsertArray);
$connect->Execute('delete from '.db_table_name('question_attributes')." where qid={$qid} and attribute=".db_quoteall($sAttributeName));
$connect->Execute($sQuery);
}
// Closing PHP tag intentionally left out - yes, it is okay
38 changes: 24 additions & 14 deletions admin/importsurvey.php
Expand Up @@ -873,26 +873,26 @@ function CSVImportSurvey($sFullFilepath)
$data='';
}

$qinsert = "insert INTO ".db_table_name('questions')." ($fieldname parent_qid,title,question,question_order,language,scale_id,type)
VALUES ($data{$aQIDReplacements[$oldqid]},".db_quoteall($labelrow['code']).",".db_quoteall($labelrow['title']).",".db_quoteall($labelrow['sortorder']).",".db_quoteall($labelrow['language']).",0,'{$questionrowdata['type']}')";
$qinsert = "insert INTO ".db_table_name('questions')." ($fieldname parent_qid,title,question,question_order,language,scale_id,type, sid, gid)
VALUES ($data{$aQIDReplacements[$oldqid]},".db_quoteall($labelrow['code']).",".db_quoteall($labelrow['title']).",".db_quoteall($labelrow['sortorder']).",".db_quoteall($labelrow['language']).",1,'{$questionrowdata['type']}',{$questionrowdata['sid']},{$questionrowdata['gid']})";
$qres = $connect->Execute($qinsert) or safe_die ($clang->gT("Error").": Failed to insert question <br />\n$qinsert<br />\n".$connect->ErrorMsg());
if ($fieldname=='')
{
$aSQIDReplacements[$labelrow['code'].'_'.$saveqid]=$connect->Insert_ID("{$dbprefix}questions","qid");
}
}
if (isset($oldlid2) && $qtypes[$questionrowdata['type']]['answerscales']>1)
{
$query="select * from ".db_table_name('labels')." where lid={$aLIDReplacements[$oldlid2]} and language='{$questionrowdata['language']}'";
$oldlabelsresult=db_execute_assoc($query);
while($labelrow=$oldlabelsresult->FetchRow())
{
$qinsert = "insert INTO ".db_table_name('answers')." (qid,code,answer,sortorder,language,assessment_value,scale_id)
VALUES ({$aQIDReplacements[$oldqid]},".db_quoteall($labelrow['code']).",".db_quoteall($labelrow['title']).",".db_quoteall($labelrow['sortorder']).",".db_quoteall($labelrow['language']).",".db_quoteall($labelrow['assessment_value']).",1)";
$qres = $connect->Execute($qinsert) or safe_die ($clang->gT("Error").": Failed to insert answer (lid2)<br />\n$qinsert<br />\n".$connect->ErrorMsg());
}
}
}
}
}
if (isset($oldlid2) && $qtypes[$questionrowdata['type']]['answerscales']>1)
{
$query="select * from ".db_table_name('labels')." where lid={$aLIDReplacements[$oldlid2]} and language='{$questionrowdata['language']}'";
$oldlabelsresult=db_execute_assoc($query);
while($labelrow=$oldlabelsresult->FetchRow())
{
$qinsert = "insert INTO ".db_table_name('answers')." (qid,code,answer,sortorder,language,assessment_value,scale_id)
VALUES ({$aQIDReplacements[$oldqid]},".db_quoteall($labelrow['code']).",".db_quoteall($labelrow['title']).",".db_quoteall($labelrow['sortorder']).",".db_quoteall($labelrow['language']).",".db_quoteall($labelrow['assessment_value']).",1)";
$qres = $connect->Execute($qinsert) or safe_die ($clang->gT("Error").": Failed to insert answer (lid2)<br />\n$qinsert<br />\n".$connect->ErrorMsg());
}
}
}
}
Expand Down Expand Up @@ -997,6 +997,16 @@ function CSVImportSurvey($sFullFilepath)
}
}

// Fix up the slots for ranking questions
$sQuery = "SELECT qid FROM {$dbprefix}questions where sid=$newsid and type='R' and parent_qid=0"; //Get last question added (finds new qid)
$gres = db_execute_assoc($sQuery);
while ($aRow = $gres->FetchRow())
{
$iSlots=$connect->GetOne("select count(code) from {$dbprefix}answers where qid={$aRow['qid']} where language='{$sBaseLanguage}');
setQuestionAttribute($aRow['qid'],'ranking_slots',$iSlots);
}
//... and for the questions inside the groups
// get all group ids and fix questions inside each group
$gquery = "SELECT gid FROM {$dbprefix}groups where sid=$newsid group by gid ORDER BY gid"; //Get last question added (finds new qid)
Expand Down
2 changes: 1 addition & 1 deletion admin/questionhandling.php
Expand Up @@ -882,7 +882,7 @@ function questionjavascript($type)
$ajaxoutput .= "<li>"
."<label for='{$qa['name']}' title='".$qa['help']."'>".$qa['caption']."</label>";

if (isset($qa['readonly']) && $qa['readonly']==true && $thissurvey['active']==true)
if (isset($qa['readonly']) && $qa['readonly']==true && $thissurvey['active']=='Y')
{
$ajaxoutput .= "$value";
}
Expand Down
1 change: 1 addition & 0 deletions group.php
Expand Up @@ -1084,6 +1084,7 @@ function checkconditions(value, name, type)
$question['essentials'] = 'id="question'.$qa[4].'"'.$n_q_display;
$question['class'] = $q_class;
$question['man_class'] = $man_class;
$question['code']=$qa[5];
//===================================================================
$answer=$qa[1];
$help=$qa[2];
Expand Down
2 changes: 1 addition & 1 deletion qanda.php
Expand Up @@ -3779,7 +3779,7 @@ function do_multiplenumeric($ia)
}
else
{
$answer_and_slider_array=explode($slider_separator,$ansrow['answer']);
$answer_and_slider_array=explode($slider_separator,$ansrow['question']);
if (isset($answer_and_slider_array[0]))
$theanswer=$answer_and_slider_array[0];
else
Expand Down

0 comments on commit 0025af2

Please sign in to comment.