### Eclipse Workspace Patch 1.0
#P limesurvey
Index: admin/fck_LimeReplacementFields.php
===================================================================
--- admin/fck_LimeReplacementFields.php	(revision 8856)
+++ admin/fck_LimeReplacementFields.php	(working copy)
@@ -215,6 +215,7 @@
     //TO AVOID NATURAL SORT ORDER ISSUES,
     //FIRST GET ALL QUESTIONS IN NATURAL SORT ORDER
     //, AND FIND OUT WHICH NUMBER IN THAT ORDER THIS QUESTION IS
+    /*
     $qquery = "SELECT * "
     ."FROM {$dbprefix}questions, "
     ."{$dbprefix}groups "
@@ -227,17 +228,19 @@
     $qrows = $qresult->GetRows();
     // Perform a case insensitive natural sort on group name then question title (known as "code" in the form) of a multidimensional array
     usort($qrows, 'GroupOrderThenQuestionOrder');
+    */
+    $fieldmap = createFieldMap($surveyid, 'full');
 
 
-
     $surveyInfo = getSurveyInfo($surveyid);
     $surveyformat = $surveyInfo['format'];// S, G, A
     $prevquestion=null;
     $previouspagequestion = true;
     //Go through each question until we reach the current one
     //error_log(print_r($qrows,true));
-    foreach ($qrows as $qrow)
+    foreach ($fieldmap as $field)
     {
+        if (empty($field['qid'])) continue;
         $AddQuestion=True;
         switch ($action)
         {
@@ -248,7 +251,7 @@
             case 'editgroup':
                 if (empty($gid)) {die("No GID provided.");}
 
-                if ($qrow['gid'] == $gid)
+                if ($field['gid'] == $gid)
                 {
                     $AddQuestion=False;
                 }
@@ -259,7 +262,7 @@
 
                 if ( !is_null($prevquestion) &&
                 $prevquestion['gid'] == $gid &&
-                $qrow['gid'] != $gid)
+                $field['gid'] != $gid)
                 {
                     $AddQuestion=False;
                 }
@@ -271,8 +274,8 @@
                 if (empty($gid)) {die("No GID provided.");}
                 if (empty($qid)) {die("No QID provided.");}
 
-                if ($qrow['gid'] == $gid &&
-                $qrow['qid'] == $qid)
+                if ($field['gid'] == $gid &&
+                $field['qid'] == $qid)
                 {
                     $AddQuestion=False;
                 }
@@ -285,8 +288,7 @@
                 die("No Action provided.");
                 break;
         }
-
-        if ( $AddQuestion===True)
+        if ( $AddQuestion===True )
         {
             if ($surveyformat == "S")
             {
@@ -296,7 +298,7 @@
             {
                 if ($previouspagequestion === true)
                 { // Last question was on a previous page
-                    if ($qrow["gid"] == $gid)
+                    if ($field["gid"] == $gid)
                     { // This question is on same page
                         $previouspagequestion = false;
                     }
@@ -311,8 +313,8 @@
                 $previouspagequestion = true;
             }
 
-            $questionlist[]=Array( "qid" => $qrow["qid"], "previouspage" => $previouspagequestion);
-            $prevquestion=$qrow;
+            $questionlist[]=array_merge($field,Array( "previouspage" => $previouspagequestion));
+            $prevquestion=$field;
         }
         else
         {
@@ -329,7 +331,8 @@
     //		}
 
     $theserows=array();
-
+    $theserows = $questionlist;
+    /*
     if (isset($questionlist) && is_array($questionlist))
     {
         foreach ($questionlist as $ql)
@@ -368,8 +371,8 @@
             }
         }
     }
+    */
 
-
     $questionscount=count($theserows);
 
     if ($questionscount > 0)
@@ -381,9 +384,15 @@
 
         foreach($theserows as $rows)
         {
-            $shortquestion=$rows['title'].": ".FlattenText($rows['question']);
+            $question = $rows['question'];
+            
+            if (isset($rows['subquestion'])) $question = "[{$rows['subquestion']}] " . $question;
+            if (isset($rows['subquestion1'])) $question = "[{$rows['subquestion1']}] " . $question;
+            if (isset($rows['subquestion2'])) $question = "[{$rows['subquestion2']}] " . $question;
+            
+            $shortquestion=$rows['title'].": ".FlattenText($question);
 
-            if ($rows['type'] == "A" ||
+            /*if ($rows['type'] == "A" ||
             $rows['type'] == "B" ||
             $rows['type'] == "C" ||
             $rows['type'] == "E" ||
@@ -508,9 +517,9 @@
 
             }   //Answer multi scale
             else
-            {
-                $cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'],$rows['previouspage']);
-            } //else
+            {*/
+                $cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['fieldname'],$rows['previouspage']);
+            //} //else
         } //foreach theserows
     } //if questionscount > 0
 
