Skip to content

Commit

Permalink
Dev Reworked CreateFieldMap
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev_cs@8291 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Jan 22, 2010
1 parent 0a375eb commit 4443165
Show file tree
Hide file tree
Showing 8 changed files with 447 additions and 606 deletions.
12 changes: 6 additions & 6 deletions admin/activate.php
Expand Up @@ -129,16 +129,16 @@

//ChECK THAT certain array question types have answers set
$chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=0)=0 and sid={$_GET['sid']} AND type IN ('F', 'H', 'W', 'Z', ':', '1')";
$chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing sub-questions<br />$chkquery<br />".$connect->ErrorMsg());
$chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing answers<br />$chkquery<br />".$connect->ErrorMsg());
while($chkrow = $chkresult->FetchRow()){
$failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires sub-questions, but none are set."), $chkrow['gid']);
$failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires answers, but none are set."), $chkrow['gid']);
} // while

//CHECK THAT FLEXIBLE LABEL TYPE QUESTIONS has answers set
//CHECK THAT DUAL Array has answers set
$chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=1)=0 and sid={$_GET['sid']} AND type='1'";
$chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing LIDs<br />$chkquery<br />".$connect->ErrorMsg());
$chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing 2nd answer set<br />$chkquery<br />".$connect->ErrorMsg());
while($chkrow = $chkresult->FetchRow()){
$failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a second Labelset, but none is set."), $chkrow['gid']);
$failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a second answer set but none is set."), $chkrow['gid']);
} // while


Expand Down Expand Up @@ -407,7 +407,7 @@
AND q.qid=".$arow['qid']."
AND a.scale_id=0
ORDER BY a.sortorder, a.answer";
$ab2result=db_execute_assoc($ab2query) or die("Couldn't get list of labels in createFieldMap function (case :)<br />$ab2query<br />".htmlspecialchars($connection->ErrorMsg()));
$ab2result=db_execute_assoc($ab2query) or die("Couldn't get list of answers in createFieldMap function (case :)<br />$ab2query<br />".htmlspecialchars($connection->ErrorMsg()));
while($ab2row=$ab2result->FetchRow())
{
$lset[]=$ab2row;
Expand Down
424 changes: 217 additions & 207 deletions admin/admin.php

Large diffs are not rendered by default.

153 changes: 33 additions & 120 deletions admin/browse.php
Expand Up @@ -151,141 +151,54 @@
// Perform a case insensitive natural sort on group name then question title of a multidimensional array
usort($fnrows, 'CompareGroupThenTitle');

$fnames[] = array("id", "id", "id");

$fnames[] = array("id", "id");
if ($private == "N") //add token to top ofl ist is survey is not private
{
$fnames[] = array("token", "token", $clang->gT("Token ID"));
$fnames[] = array("token", $clang->gT("Token ID"));
}

$fnames[] = array("completed", "Completed", $clang->gT("Completed"), "0");
$fnames[] = array("completed", $clang->gT("Completed"), "0");

if ($datestamp == "Y") //add datetime to list if survey is datestamped
{
// submitdate for not-datestamped surveys is always 1980/01/01
// so only display it when datestamped
$fnames[] = array("startdate", "startdate", $clang->gT("Date Started"));
$fnames[] = array("datestamp", "datestamp", $clang->gT("Date Last Action"));
$fnames[] = array("submitdate", "submitdate", $clang->gT("Date Submitted"));
$fnames[] = array("startdate", $clang->gT("Date Started"));
$fnames[] = array("datestamp", $clang->gT("Date Last Action"));
$fnames[] = array("submitdate", $clang->gT("Date Submitted"));
}
if ($ipaddr == "Y") //add ipaddr to list if survey should save submitters IP address
{
$fnames[] = array("ipaddr", "ipaddr", $clang->gT("IP Address"));
$fnames[] = array("ipaddr", $clang->gT("IP Address"));
}
if ($refurl == "Y") //add refer_URL to list if survey should save referring URL
{
$fnames[] = array("refurl", "refurl", $clang->gT("Referring URL"));
}
foreach ($fnrows as $fnrow)
{
$field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}";
$ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}";
$fquestion = $fnrow['question'];
if ($fnrow['type'] == "Q" || $fnrow['type'] == "M" ||
$fnrow['type'] == "A" || $fnrow['type'] == "B" ||
$fnrow['type'] == "C" || $fnrow['type'] == "E" ||
$fnrow['type'] == "F" || $fnrow['type'] == "H" ||
$fnrow['type'] == "J" || $fnrow['type'] == "K" ||
$fnrow['type'] == "P" || $fnrow['type'] == "^")
{
$fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} AND language='{$language}' ORDER BY sortorder, answer";
$fnrresult = db_execute_assoc($fnrquery);
while ($fnrrow = $fnrresult->FetchRow())
{
$fnames[] = array("$field{$fnrrow['code']}", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']} ({$fnrrow['answer']})");
if ($fnrow['type'] == "P") {$fnames[] = array("$field{$fnrrow['code']}"."comment", "$ftitle"."comment", "{$fnrow['question']} (".$clang->gT("Comment").")");}
}
if ($fnrow['other'] == "Y" and ($fnrow['type']=="!" or $fnrow['type']=="L" or $fnrow['type']=="M" or $fnrow['type']=="P" ))
{
$fnames[] = array("$field"."other", "$ftitle"."other", "{$fnrow['question']}(".$clang->gT("Other").")");
if ($fnrow['type'] == "P") {$fnames[] = array("$field{$fnrrow['code']}"."othercomment", "$ftitle"."othercomment", "{$fnrow['question']} (".$clang->gT("Other Comment").")");}
}
}
elseif ($fnrow['type'] == ":" || $fnrow['type'] == ";")
{
$lset=array();
$fnrquery = "SELECT *
FROM ".db_table_name('answers')."
WHERE qid={$fnrow['qid']}
AND language='{$language}'
ORDER BY sortorder, answer";
$fnrresult = db_execute_assoc($fnrquery);
$fnr2query = "SELECT *
FROM ".db_table_name('labels')."
WHERE lid={$fnrow['lid']}
AND language = '{$language}'
ORDER BY sortorder, title";
$fnr2result = db_execute_assoc($fnr2query);
while( $fnr2row = $fnr2result->FetchRow())
{
$lset[]=$fnr2row;
}
while ($fnrrow = $fnrresult->FetchRow())
{
foreach($lset as $ls)
{
$fnames[] = array("$field{$fnrrow['code']}_{$ls['code']}", "$ftitle ({$fnrrow['code']})", "{$fnrow['question']} ({$fnrrow['answer']}: {$ls['title']})");
}
}
}
elseif ($fnrow['type'] == "R")
{
$fnrquery = "SELECT * FROM ".db_table_name("answers")." WHERE qid={$fnrow['qid']} AND
language='{$language}'
ORDER BY sortorder, answer";
$fnrresult = $connect->Execute($fnrquery);
$fnrcount = $fnrresult->RecordCount();
for ($i=1; $i<=$fnrcount; $i++)
{
$fnames[] = array("$field$i", "$ftitle ($i)", "{$fnrow['question']} ($i)");
}
}
elseif ($fnrow['type'] == "O")
{
$fnames[] = array("$field", "$ftitle", "{$fnrow['question']}");
$field2 = $field."comment";
$ftitle2 = $ftitle."[Comment]";
$longtitle = "{$fnrow['question']}<br />[Comment]";
$fnames[] = array("$field2", "$ftitle2", "$longtitle");
}
elseif ($fnrow['type'] == "1") // multi scale
{
$i2query = "SELECT ".db_table_name("answers").".*, ".db_table_name("questions").".other FROM ".db_table_name("answers").", ".db_table_name("questions")."
WHERE ".db_table_name("answers").".qid=".db_table_name("questions").".qid AND
".db_table_name("answers").".language='{$language}' AND ".db_table_name("questions").".language='{$language}' AND
".db_table_name("questions").".qid={$fnrow['qid']} AND ".db_table_name("questions").".sid=$surveyid
ORDER BY ".db_table_name("answers").".sortorder, ".db_table_name("answers").".answer";
$i2result = db_execute_assoc($i2query);
$otherexists = "";
while ($i2row = $i2result->FetchRow())
{
// first scale
$field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}{$i2row['code']}#0";
$ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}Opt{$i2row['code']}";
if ($i2row['other'] == "Y") {$otherexists = "Y";}
$fnames[] = array("$field", "$ftitle", "{$fnrow['question']}<br />\n[{$i2row['answer']}]<br />[".$clang->gT("1. scale")."]", "{$fnrow['gid']}");
// second scale
$field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}{$i2row['code']}#1";
$ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}Opt{$i2row['code']}";
if ($i2row['other'] == "Y") {$otherexists = "Y";}
$fnames[] = array("$field", "$ftitle", "{$fnrow['question']}<br />\n[{$i2row['answer']}]<br />[".$clang->gT("2. scale")."]", "{$fnrow['gid']}");
}
if ($otherexists == "Y")
{
$field = "{$fnrow['sid']}X{$fnrow['gid']}X{$fnrow['qid']}"."other";
$ftitle = "Grp{$fnrow['gid']}Qst{$fnrow['title']}OptOther";
$fnames[] = array("$field", "$ftitle", "{$fnrow['question']}<br />\n[Other]", "{$fnrow['gid']}");
}
}

else
{
$fnames[] = array("$field", "$ftitle", "{$fnrow['question']}");
if (($fnrow['type'] == "L" || $fnrow['type'] == "!") && $fnrow['other'] == "Y")
{
$fnames[] = array("$field"."other", "$ftitle"."other", "{$fnrow['question']}(".$clang->gT("Other").")");
}
}
$fnames[] = array("refurl", $clang->gT("Referring URL"));
}

$fieldmap=createFieldMap($surveyid,'full');
unset($fieldmap[0]);
unset($fieldmap[1]);
foreach ($fieldmap as $field)
{
$question=$field['question'];
if (isset($field['subquestion']) && $field['subquestion']!='')
{
$question .=' ('.$field['subquestion'];
}
if (isset($field['answer']) && $field['answer']!='')
{
$question .=' : '.$field['answer'];
}
$question .=')';
if (isset($field['scale_id']))
{
$question .='['.$field['scale'].']';
}
$fnames[]=array($field['fieldname'],$question);
}

$nfncount = count($fnames)-1;
//SHOW INDIVIDUAL RECORD
$idquery = "SELECT *, CASE WHEN submitdate IS NULL THEN 'N' ELSE 'Y' END as completed FROM $surveytable WHERE ";
Expand Down Expand Up @@ -348,7 +261,7 @@
{
$browseoutput .= "\t<tr>\n"
."<th align='right' width='50%'>"
.strip_tags(strip_javascript($fnames[$i][2]))."</th>\n"
.strip_tags(strip_javascript($fnames[$i][1]))."</th>\n"
."<td align='left' >"
.htmlspecialchars(strip_tags(strip_javascript(getextendedanswer($fnames[$i][0], $idrow[$fnames[$i][0]], '', $dateformatdetails['phpdate']))), ENT_QUOTES)
."</td>\n"
Expand Down
20 changes: 10 additions & 10 deletions admin/conditionshandling.php
Expand Up @@ -630,7 +630,7 @@
$fresult = db_execute_assoc($fquery);
while ($frow=$fresult->FetchRow())
{
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], $frow['code'], $frow['title']);
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], $frow['code'], $frow['answer']);
}
break;
}
Expand Down Expand Up @@ -776,14 +776,14 @@

while ($arows = $aresult->FetchRow())
{
$shortanswer = "{$arows['code']}: [" . strip_tags($arows['answer']) . "]";
$shortanswer = "{$arows['title']}: [" . strip_tags($arows['question']) . "]";
$shortquestion=$rows['title'].":$shortanswer ".strip_tags($rows['question']);
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']);
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']);

// Only Show No-Answer if question is not mandatory
if ($rows['mandatory'] != 'Y')
{
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], "", $clang->gT("No answer"));
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], "", $clang->gT("No answer"));
}

} //while
Expand Down Expand Up @@ -833,15 +833,15 @@

while ($arows=$aresult->FetchRow())
{
$theanswer = addcslashes($arows['answer'], "'");
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $arows['code'], $theanswer);
$theanswer = addcslashes($arows['question'], "'");
$canswers[]=array($rows['sid'].$X.$rows['gid'].$X.$rows['qid'], $arows['title'], $theanswer);

$shortanswer = "{$arows['code']}: [" . strip_tags($arows['answer']) . "]";
$shortanswer = "{$arows['title']}: [" . strip_tags($arows['question']) . "]";
$shortanswer .= "[".$clang->gT("Single checkbox")."]";
$shortquestion=$rows['title'].":$shortanswer ".strip_tags($rows['question']);
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], "+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']);
$canswers[]=array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], 'Y', 'checked');
$canswers[]=array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'], '', 'not checked');
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], "+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title']);
$canswers[]=array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], 'Y', 'checked');
$canswers[]=array("+".$rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['title'], '', 'not checked');
}
}
elseif($rows['type'] == "X") //Boilerplate question
Expand Down
8 changes: 4 additions & 4 deletions admin/database.php
Expand Up @@ -1194,9 +1194,9 @@ function get_max_question_order($gid)
." surveyls_dateformat) "
." VALUES ({$postsid}, '".$langname."', '',"
.db_quoteall($bplang->gT("Invitation to participate in survey",'unescaped')).","
.db_quoteall(conditional2_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped'),$ishtml)).","
.db_quoteall(conditional2_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped')."\n\n".$bplang->gT("If you do not want to participate in this survey and don't want to receive any more invitations please click the following link: {OPTOUTURL}",'unescaped'),$ishtml)).","
.db_quoteall($bplang->gT("Reminder to participate in survey",'unescaped')).","
.db_quoteall(conditional2_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped'),$ishtml)).","
.db_quoteall(conditional2_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped')."\n\n".$bplang->gT("If you do not want to participate in this survey and don't want to receive any more invitations please click the following link: {OPTOUTURL}",'unescaped'),$ishtml)).","
.db_quoteall($bplang->gT("Confirmation of completed survey",'unescaped')).","
.db_quoteall(conditional2_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nThis email is to confirm that you have completed the survey titled {SURVEYNAME} and your response has been saved. Thank you for participating.\n\nIf you have any further questions about this email, please contact {ADMINNAME} on {ADMINEMAIL}.\n\nSincerely,\n\n{ADMINNAME}",'unescaped'),$ishtml)).","
.db_quoteall($bplang->gT("Survey Registration Confirmation",'unescaped')).","
Expand Down Expand Up @@ -1425,9 +1425,9 @@ function get_max_question_order($gid)
'surveyls_endtext'=>$_POST['endtext'],
'surveyls_url'=>$_POST['url'],
'surveyls_email_invite_subj'=>$bplang->gT("Invitation to participate in survey",'unescaped'),
'surveyls_email_invite'=>conditional_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped'),$is_html_email,'unescaped'),
'surveyls_email_invite'=>conditional_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped')."\n\n".$bplang->gT("If you do not want to participate in this survey and don't want to receive any more invitations please click the following link: {OPTOUTURL}",'unescaped'),$is_html_email,'unescaped'),
'surveyls_email_remind_subj'=>$bplang->gT("Reminder to participate in survey",'unescaped'),
'surveyls_email_remind'=>conditional_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped'),$is_html_email,'unescaped'),
'surveyls_email_remind'=>conditional_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped')."\n\n".$bplang->gT("If you do not want to participate in this survey and don't want to receive any more invitations please click the following link: {OPTOUTURL}",'unescaped'),$is_html_email,'unescaped'),
'surveyls_email_confirm_subj'=>$bplang->gT("Confirmation of completed survey",'unescaped'),
'surveyls_email_confirm'=>conditional_nl2br($bplang->gT("Dear {FIRSTNAME},\n\nThis email is to confirm that you have completed the survey titled {SURVEYNAME} and your response has been saved. Thank you for participating.\n\nIf you have any further questions about this email, please contact {ADMINNAME} on {ADMINEMAIL}.\n\nSincerely,\n\n{ADMINNAME}",'unescaped'),$is_html_email,'unescaped'),
'surveyls_email_register_subj'=>$bplang->gT("Survey Registration Confirmation",'unescaped'),
Expand Down

0 comments on commit 4443165

Please sign in to comment.