View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
04324Bug reportsSurvey editingpublic2010-06-08 21:51
ReporterCarbonaCat Assigned Tolemeur  
PrioritynormalSeveritytweak 
Status closedResolutionfixed 
Product Version1.90b 
Summary04324: Patch: Allow dropdowns for arrays
Description

This patch allows to use dropdowns in the "array" question type, instead of radios.

Steps To Reproduce

N/A

Additional Information

-Allows the use of the "use_dropdown" attribute for the "Array" question type (common.php).
-Render dropdowns instead of radios when the said attribute is enabled (quanda.php). The code is based on the code that render the dropdowns for the "Dual Scale Array" question type.

The zip file contains both old and new files, as well as the corresponding diffs.

TagsNo tags attached.
Attached Files
dropdown4arrays-svn8746.diff (6,157 bytes)   
Index: common.php
===================================================================
--- common.php	(revision 8748)
+++ common.php	(working copy)
@@ -3983,16 +3983,16 @@
     "caption"=>$clang->gT('Input box width'));
 
     $qattributes["use_dropdown"]=array(
-    "types"=>"1",
+    "types"=>"1F",
     'category'=>$clang->gT('Other'),
     'sortorder'=>100,
     'inputtype'=>'singleselect',
     'options'=>array(0=>$clang->gT('No'),
     1=>$clang->gT('Yes')),
     'default'=>0,      
-    "help"=>$clang->gT('Use dual dropdown boxes instead of dual scales'),
-    "caption"=>$clang->gT('Dual dropdown'));
-
+    "help"=>$clang->gT('Use dropdown boxes instead of scales'),
+    "caption"=>$clang->gT('Dropdown'));
+	
     $qattributes["scale_export"]=array(
     "types"=>"CEFGHLMOPWYZ1!:",
     'category'=>$clang->gT('Other'),
Index: qanda.php
===================================================================
--- qanda.php	(revision 8748)
+++ qanda.php	(working copy)
@@ -5276,8 +5276,17 @@
     }
     $columnswidth=100-$answerwidth;
 
+	if ($qidattributes['use_dropdown'] == 1)
+	{
+		$useDropdownLayout = true;
+	}
+	else
+	{
+		$useDropdownLayout = false;
+	}
+	
     $lresult = db_execute_assoc($lquery);   //Checked
-    if ($lresult->RecordCount() > 0)
+    if ($useDropdownLayout === false && $lresult->RecordCount() > 0)
     {
         while ($lrow=$lresult->FetchRow())
         {
@@ -5453,7 +5462,124 @@
 
         $answer = $answer_start . $answer_cols . $answer_head .$answer . "\t</tbody>\n</table>\n";
     }
-    else
+	elseif ($useDropdownLayout === true && $lresult->RecordCount() > 0)
+	{
+		while ($lrow=$lresult->FetchRow())
+			$labels[]=Array('code' => $lrow['code'],
+							'answer' => $lrow['answer']);
+        $ansquery = "SELECT question FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND question like '%|%' ";
+		$ansresult = db_execute_assoc($ansquery);  //Checked
+		if ($ansresult->RecordCount()>0) {$right_exists=true;$answerwidth=$answerwidth/2;} else {$right_exists=false;} 
+		// $right_exists is a flag to find out if there are any right hand answer parts. If there arent we can leave out the right td column
+        if ($qidattributes['random_order']==1) {
+            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
+        }
+        else
+        {
+            $ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid={$ia[0]} AND language='".$_SESSION['s_lang']."' ORDER BY question_order";
+        }
+		$ansresult = db_execute_assoc($ansquery); //Checked
+		$anscount = $ansresult->RecordCount();
+		$fn=1;
+
+		$numrows = count($labels);
+		if ($ia[6] != 'Y' && $shownoanswer == 1)
+		{
+			++$numrows;
+		}
+		if ($right_exists)
+		{
+			++$numrows;
+		}
+		$cellwidth = round( ($columnswidth / $numrows ) , 1 );
+
+		$answer_start = "\n<table class=\"question\" summary=\"".str_replace('"','' ,strip_tags($ia[3]))." - an array type question\" >\n";
+
+		$answer = "\t<tbody>\n";
+		$trbc = '';
+        $inputnames=array();
+
+		while ($ansrow = $ansresult->FetchRow())
+		{
+			$myfname = $ia[1].$ansrow['title'];
+			$trbc = alternation($trbc , 'row');
+			$answertext=answer_replace($ansrow['question']);
+            $answertextsave=$answertext;
+			if (strpos($answertext,'|'))
+			{
+				$answertext=substr($answertext,0, strpos($answertext,'|'));
+			}
+			/* Check if this item has not been answered: the 'notanswered' variable must be an array,
+			containing a list of unanswered questions, the current question must be in the array,
+			and there must be no answer available for the item in this session. */
+
+			if (strpos($answertext,'|')) {$answerwidth=$answerwidth/2;}
+
+			if ((is_array($notanswered)) && (array_search($ia[1], $notanswered) !== FALSE) && ($_SESSION[$myfname] == '') ) {
+				$answertext = '<span class="errormandatory">'.$answertext.'</span>';
+			}
+			// Get array_filter stuff
+			list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $qidattributes, $thissurvey, $ansrow, $myfname, $trbc, $myfname);
+			$answer .= $htmltbody2;
+			
+			$answer .= "<tr class=\"$trbc\">\n"
+			. "\t<th class=\"answertext\">\n$answertext"
+			. $hiddenfield
+			. "<input type=\"hidden\" name=\"java$myfname\" id=\"java$myfname\" value=\"";
+			if (isset($_SESSION[$myfname]))
+			{
+				$answer .= $_SESSION[$myfname];
+			}
+			$answer .= "\" />\n\t</th>\n";
+			
+			$answer .= "\t<td >\n"
+			. "<select name=\"$myfname\" id=\"answer$myfname\" onchange=\"$checkconditionFunction(this.value, this.name, this.type);\">\n";
+
+			if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] =='')
+			{
+				$answer .= "\t<option value=\"\" ".SELECTED.'>'.$clang->gT('Please choose')."...</option>\n";
+			}
+
+			foreach ($labels as $lrow)
+			{
+				$answer .= "\t<option value=\"".$lrow['code'].'" ';
+				if (isset($_SESSION[$myfname]) && $_SESSION[$myfname] == $lrow['code'])
+				{
+					$answer .= SELECTED;
+				}
+				$answer .= '>'.$lrow['answer']."</option>\n";
+			}
+			// If not mandatory and showanswer, show no ans
+			if ($ia[6] != 'Y' && $shownoanswer == 1)
+			{
+				$answer .= "\t<option value=\"\" ";
+				if (!isset($_SESSION[$myfname]) || $_SESSION[$myfname] == '')
+				{
+					$answer .= SELECTED;
+				}
+				$answer .= '>'.$clang->gT('No answer')."</option>\n";
+			}
+			$answer .= "</select>\n";
+				
+			if (strpos($answertextsave,'|')) 
+			{
+				$answertext=substr($answertextsave,strpos($answertextsave,'|')+1);
+				$answer .= "\t<th class=\"answertextright\">$answertext</th>\n";
+			}
+			elseif ($right_exists)
+			{
+				$answer .= "\t<td class=\"answertextright\">&nbsp;</td>\n";
+			}
+			
+			$answer .= "</tr>\n</tbody>";
+			$inputnames[]=$myfname;
+			//IF a MULTIPLE of flexi-redisplay figure, repeat the headings
+			$fn++;
+		}
+
+		$answer = $answer_start . $answer . "\t</tbody>\n</table>\n";
+	}
+	else
     {
         $answer = "\n<p class=\"error\">".$clang->gT("Error: There are no answer options for this question and/or they don't exist in this language.")."</p>\n";
         $inputnames='';
dropdown4arrays-svn8746.diff (6,157 bytes)   
Bug heat8
Complete LimeSurvey version number (& build)8691
I will donate to the project if issue is resolved
BrowserAll
Database type & versionMySQL
Server OS (if known)Windows XP SP2
Webserver software & version (if known)WAMP
PHP Version5.3

Users monitoring this issue

CarbonaCat

Activities

Mazi

Mazi

2010-05-10 15:50

updater   ~11744

Hi Thibault, can you preview this patch and give some advice?
Thanks!

Mazi

Mazi

2010-05-21 14:43

updater   ~11901

Thibault, the user asked at the forum if he can help to bring this feature forward.
Can you provide some feedback?
Do you think we should add it to the 1.90RC1 milestones?

lemeur

lemeur

2010-05-21 17:39

developer   ~11906

[QUOTE]Thibault, the user asked at the forum if he can help to bring this feature forward.[/QUOTE]

Sure, the best would be to provide a patch against the limesurvey-dev/ branch.

[QUOTE]Do you think we should add it to the 1.90RC1 milestones?[/QUOTE]

I'm afraid not, there was a feature freeze decided when 1.90beta was released (Wednesday, 05 May 2010). this will be for 1.91.

Thibault

Mazi

Mazi

2010-05-22 14:38

updater   ~11944

[QUOTE]Sure, the best would be to provide a patch against the limesurvey-dev/ branch.[/QUOTE]

CarbonaCat, can you provide a .diff patch against the latest SVN/beta3 version of Limesurvey 1.90?

CarbonaCat

CarbonaCat

2010-05-25 09:29

reporter   ~11950

Sure, I'll do that in the afternoon

(Sorry for the lack of reaction, I had a prolonged weekend due the the Lundi de Pentecote :P)

CarbonaCat

CarbonaCat

2010-05-25 11:57

reporter   ~11951

I attached the diff file against the revision 08746.

Mazi

Mazi

2010-05-26 13:58

updater   ~11966

Thibault, can you have a look and if it looks fine put it on the feature list for the next 1.9x release?

lemeur

lemeur

2010-05-26 23:45

developer   ~11994

Implemented in rev 8752 in the limesurvey_dev branch.
Thanks for the work.

Please stay tuned in case we find bugs, we may contact you ;-)

Issue History

Date Modified Username Field Change
2010-05-10 09:58 CarbonaCat New Issue
2010-05-10 09:58 CarbonaCat Status new => assigned
2010-05-10 09:58 CarbonaCat Assigned To => user372
2010-05-10 09:58 CarbonaCat File Added: dropdown4arrays-build8691.zip
2010-05-10 15:50 Mazi Assigned To user372 => lemeur
2010-05-10 15:50 Mazi Note Added: 11744
2010-05-21 14:43 Mazi Note Added: 11901
2010-05-21 17:39 lemeur Note Added: 11906
2010-05-22 14:38 Mazi Note Added: 11944
2010-05-22 14:38 Mazi Status assigned => feedback
2010-05-25 09:29 CarbonaCat Note Added: 11950
2010-05-25 09:29 CarbonaCat Status feedback => assigned
2010-05-25 11:56 CarbonaCat File Added: dropdown4arrays-svn8746.diff
2010-05-25 11:57 CarbonaCat Note Added: 11951
2010-05-25 15:35 CarbonaCat Issue Monitored: CarbonaCat
2010-05-26 13:58 Mazi Note Added: 11966
2010-05-26 23:45 lemeur Note Added: 11994
2010-05-26 23:45 lemeur Status assigned => resolved
2010-05-26 23:45 lemeur Resolution open => fixed
2010-06-08 21:51 c_schmitz Status resolved => closed
2010-10-25 00:17 c_schmitz Category Survey Design => Survey design
2019-11-01 17:25 c_schmitz Category Survey design => Survey editing
2021-08-12 14:40 guest Bug heat 6 => 8