View Issue Details

This issue affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
04250Bug reportsOtherpublic2010-05-05 10:28
Reporterelameno Assigned Torakete  
PrioritynormalSeveritypartial_block 
Status closedResolutionfixed 
Product Version1.87+ 
Summary04250: Cannot insert participants that have an apostrophe in their name via LSRC
Description

When I attempt to insert participants that contain people who have an apostrophe in their name LSRC returns that it did not insert all the participant records I submitted. The ones that are missing are the ones that have apostrophes.

Steps To Reproduce
  1. Create a survey.
  2. Insert a set of participants via LSRC sInsertParticipants call, one or more with an apostrophe in the name.
  3. Look and see that the participants that had an apostrophe in their name are not inserted as participants in Lime.
TagsNo tags attached.
Attached Files
sInsertParticipants_ApostropheFix.txt (3,922 bytes)   
Index: lsrc.helper.php
===================================================================
--- lsrc.helper.php	(revision 8411)
+++ lsrc.helper.php	(working copy)
@@ -4211,7 +4225,8 @@
 			{
 				$asDatafield = explode($sDatafieldSeperator, $sData);
 				$checkCnt=1;
-
+				
+				//Null out any field that is an empty string.
 				$iDataLength = count($asDatafield);
 				for($n=0;$n>=$iDataLength;++$n)
 				{
@@ -4223,7 +4238,7 @@
 
 				// token generieren
 
-
+				//Generate a random token.
 				while($checkCnt>0)
 				{
 					$value = randomkey(10); //change randomkey value for different tokenlength (up to 36 chars max.)
@@ -4231,25 +4246,36 @@
 					$result = db_execute_assoc($cQuery);
 					$checkCnt = $result->RecordCount();
 				}
+
+				//If we weren't supplied with a token for this participant, then set it to the one we just created.
 				if(!isset($asDatafield[4]) || $asDatafield[4]=='')
 				{
 					$asDatafield[4]= $value;
 				}
+
 				//set session language if no language is set
 				if(!isset($asDatafield[3]) || $asDatafield[3]=='')
 				{
 					$asDatafield[3] = $_SESSION['lang'];
 				}
 
+				//Begin to prepare our statement here. One array for the columns to insert and a parallel array with the values.
+				$insertColumns = array('firstname', 'lastname', 'email', 'language', 'token');
+				$insertValues = array($asDatafield[0], $asDatafield[1], $asDatafield[2], $asDatafield[3], $asDatafield[4]);
+				
 				if(isset($asDatafield[5]) && $asDatafield[5]!=null)
 				{
-					$validity .= ',validfrom';
-					$validityData .=",'$asDatafield[5]'";
+					//$validity .= ',validfrom';
+					//$validityData .=",'$asDatafield[5]'";
+					$insertColumns[] = 'validfrom';
+					$insertValues[] = $asDatafield[5];
 				}
 				if(isset($asDatafield[6]) && $asDatafield[5]!=null)
 				{
-					$validity .= ',validuntil';
-					$validityData .=",'$asDatafield[6]'";
+					//$validity .= ',validuntil';
+					//$validityData .=",'$asDatafield[6]'";
+					$insertColumns[] = 'validuntil';
+					$insertValues[] = $asDatafield[6];
 				}
 
 				if(isset($asDatafield[7]) && $asDatafield[7]!='')
@@ -4263,8 +4289,10 @@
 						//$check = "SELECT attribute_$n FROM {$dbprefix}_tokens_$iVid ";
 
 						$sql = "ALTER TABLE {$dbprefix}tokens_$iVid ADD COLUMN attribute_$n VARCHAR(255); ";
-						$attributes.=",attribute_$n";
-						$attributesData.= ",'$attribute'";
+						//$attributes.=",attribute_$n";
+						//$attributesData.= ",'$attribute'";
+						$insertColumns[] = "attribute_$n";
+						$insertValues[] = $attribute;
 
 						$this->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", Attribute_$n mit $attribute anlegen ,sql: $sql");
 						//modify_database("","$sql");
@@ -4274,12 +4302,16 @@
 				}
 
 
-				$sInsertParti = "INSERT INTO ".$dbprefix."tokens_".$iVid
+				/*$sInsertParti = "INSERT INTO ".$dbprefix."tokens_".$iVid
 				."(firstname,lastname,email,token,"
 				."language $validity $attributes) "
 				."VALUES ('{$asDatafield[0]}', '{$asDatafield[1]}' , '{$asDatafield[2]}', '{$asDatafield[4]}' , "
-				."'{$asDatafield[3]}' $validityData $attributesData) ";
+				."'{$asDatafield[3]}' $validityData $attributesData) ";*/
 
+				$sInsertParti = "INSERT INTO {$dbprefix}tokens_$iVid (".implode(',', $insertColumns).") VALUES (".trim(str_repeat('?,', count($insertColumns)), ',').");";
+				
+						
+
 				$this->debugLsrc("$sInsertParti");
 
 
@@ -4290,7 +4322,7 @@
 				//					'".$asDatafield[1]."' , '".$asDatafield[2]."' , 'OK' , '".$asDatafield[5]."',
 				//					'".$_SESSION['lang']."', 'N', 'N', '".$asDatafield[3]."' , '".$asDatafield[4]."' , NULL); ";
 				//
-				if($connect->Execute($sInsertParti))
+				if($connect->Execute($sInsertParti, $insertValues))
 				{
 					++$iInsertedParticipants;
 					// check participants eMail status and set it
lsrc.helper.php (175,246 bytes)
Bug heat4
Complete LimeSurvey version number (& build)8411
I will donate to the project if issue is resolved
BrowserFirefox
Database type & versionMySQL 5
Server OS (if known)Fedora Linux 10
Webserver software & version (if known)Apache 2.2
PHP Version5.2.9
Git branch / Pull Request URL

Users monitoring this issue

There are no users monitoring this issue.

Activities

elameno

elameno

2010-03-29 23:19

reporter   ~11542

I've attached a fix to the insertParticipants function in the lsrc.helper.php.

I had other changes in my local lsrc.helper.php so I manually edited the diff to isolate the changes necessary to patch this issue. If you find any problems with it, let me know and I'll post a new one.

rakete

rakete

2010-03-31 19:36

reporter   ~11559

diff files are ugly to handle, can you provide a full helper file with your fixes?
that would be great, thank you...

elameno

elameno

2010-03-31 21:36

reporter   ~11562

There's the lsrc.helper.php with the patch applied.

rakete

rakete

2010-04-01 20:26

reporter   ~11565

thx for you patch... IT's in the repos.

Why not joining the team? seems like you now something about ado and programming... :) LSRC needs some help...

Issue History

Date Modified Username Field Change
2010-03-29 22:12 elameno New Issue
2010-03-29 23:19 elameno Note Added: 11542
2010-03-29 23:19 elameno File Added: sInsertParticipants_ApostropheFix.txt
2010-03-31 16:25 c_schmitz Status new => assigned
2010-03-31 16:25 c_schmitz Assigned To => rakete
2010-03-31 19:36 rakete Note Added: 11559
2010-03-31 21:36 elameno File Added: lsrc.helper.php
2010-03-31 21:36 elameno Note Added: 11562
2010-04-01 20:26 rakete Note Added: 11565
2010-04-01 20:26 rakete Status assigned => resolved
2010-04-01 20:26 rakete Resolution open => fixed
2010-05-05 10:28 c_schmitz Status resolved => closed
2011-10-20 18:29 c_schmitz Category RemoteControl => (No Category)