2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Merging the Limesurvey 1.91+ branch of queXS in to the trunk

This commit is contained in:
azammitdcarf
2011-09-08 01:58:41 +00:00
parent dfa55a3b9e
commit eaa9578ab8
2312 changed files with 811461 additions and 597534 deletions

View File

@@ -1,23 +1,23 @@
<?php
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: fck_LimeReplacementFields.php 7161 2009-06-22 19:13:21Z lemeur $
*/
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: fck_LimeReplacementFields.php 10925 2011-09-02 14:12:02Z c_schmitz $
*/
include_once("login_check.php");
if(!isset($_SESSION['loginID']))
{
die ("Unauthenticated Access Forbiden");
die ("Unauthenticated Access Forbiden");
}
$surveyid=returnglobal('sid');
@@ -32,550 +32,415 @@ $InsertansUnsupportedtypes=Array(); // Currently all question types are supporte
$replFields=Array();
$isInstertansEnabled=false;
$limereplacementoutput="<html>\n"
. "\t<head>\n"
. "\t\t<title>LimeReplacementFields</title>\n"
. "\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"
. "\t\t<meta content=\"noindex, nofollow\" name=\"robots\">\n"
. "\t\t<script src=\"$fckeditordir/editor/dialog/common/fck_dialog_common.js\" type=\"text/javascript\"></script>\n"
. "\t\t<script src=\"$rooturl/scripts/jquery/jquery.js\" type=\"text/javascript\"></script>\n"
. "\t\t<script language=\"javascript\">\n"
. "\t\t\tvar mydialog = window.parent ;\n"
. "\t\t\tvar oEditor = mydialog.InnerDialogLoaded() ;\n"
. "\t\t\tvar dialog = oEditor.FCK ;\n"
. "\t\t\tvar FCKLang = oEditor.FCKLang ;\n"
. "\t\t\tvar FCKLimeReplacementFieldss = oEditor.FCKLimeReplacementFieldss ;\n"
. "\t\t\$(document).ready(function ()\n"
. "\t\t\t{\n"
. "\t\t\t\toEditor.FCKLanguageManager.TranslatePage( document ) ;\n"
. "\t\t\t\tLoadSelected() ;\n"
. "\t\t\t\tmydialog.SetOkButton( true ) ;\n"
. "\n"
. "\t\t\t\tSelectField( 'cquestions' ) ;\n"
. "\t\t\t});\n"
. "\n";
$limereplacementoutput="\t\t<script language=\"javascript\">\n"
. "\t\t\$(document).ready(function ()\n"
. "\t\t\t{\n"
. "\t\t\t\tLoadSelected() ;\n"
. "\t\t\t\tmydialog.SetOkButton( true ) ;\n"
. "\n"
. "SelectField( 'cquestions' ) ;\n"
. "\t});\n"
. "\n";
/**$limereplacementoutput="\n"
. "if (! oEditor.FCKBrowserInfo.IsIE)\n"
. "{\n"
. "\tinnertext = '' + dialog.EditorWindow.getSelection() + '' ;\n"
. "}\n"
. "else\n"
. "{\n"
. "\tinnertext = '' + dialog.EditorDocument.selection.createRange().text + '' ;\n"
. "}\n";
**/
. "if (! oEditor.FCKBrowserInfo.IsIE)\n"
. "{\n"
. "\tinnertext = '' + dialog.EditorWindow.getSelection() + '' ;\n"
. "}\n"
. "else\n"
. "{\n"
. "\tinnertext = '' + dialog.EditorDocument.selection.createRange().text + '' ;\n"
. "}\n";
**/
$limereplacementoutput .= ""
. "\t\t\tvar eSelected = dialog.Selection.GetSelectedElement() ;\n"
. "\n";
. "\tvar eSelected = dialog.Selection.GetSelectedElement() ;\n"
. "\n";
/**
$limereplacementoutput="\n"
. "function LoadSelected()\n"
. "{\n"
. "\tif ( innertext == '' )\n"
. "\t\treturn ;\n"
. "var replcode=innertext.substring(innertext.indexOf('{')+1,innertext.lastIndexOf('}'));\n"
. "\t\tdocument.getElementById('cquestions').value = replcode;\n"
. "}\n";
**/
$limereplacementoutput="\n"
. "function LoadSelected()\n"
. "{\n"
. "\tif ( innertext == '' )\n"
. "return ;\n"
. "var replcode=innertext.substring(innertext.indexOf('{')+1,innertext.lastIndexOf('}'));\n"
. "document.getElementById('cquestions').value = replcode;\n"
. "}\n";
**/
$limereplacementoutput .= ""
. "\t\t\tfunction LoadSelected()\n"
. "\t\t\t{\n"
. "\t\t\t\tif ( !eSelected )\n"
. "\t\t\t\t\treturn ;\n"
. "\t\t\t\tif ( eSelected.tagName == 'SPAN' && eSelected._fckLimeReplacementFields )\n"
. "\t\t\t\t\t document.getElementById('cquestions').value = eSelected._fckLimeReplacementFields ;\n"
. "\t\t\t\telse\n"
. "\t\t\t\t\teSelected == null ;\n"
. "\t\t\t}\n";
$limereplacementoutput .= ""
. "\t\t\tfunction Ok()\n"
. "\t\t\t{\n"
. "\t\t\t\tvar sValue = document.getElementById('cquestions').value ;\n"
. "\t\t\t\tFCKLimeReplacementFieldss.Add( sValue ) ;\n"
. "\t\t\t\treturn true ;\n"
. "\t\t\t}\n";
. "\tfunction LoadSelected()\n"
. "\t{\n"
. "if ( !eSelected )\n"
. "\treturn ;\n"
. "if ( eSelected.tagName == 'SPAN' && eSelected._fckLimeReplacementFields )\n"
. "\t document.getElementById('cquestions').value = eSelected._fckLimeReplacementFields ;\n"
. "else\n"
. "\teSelected == null ;\n"
. "\t}\n";
$limereplacementoutput .= ""
. "\t\t\t</script>\n"
. "\t\t</head>\n";
. "\tfunction Ok()\n"
. "\t{\n"
. "var sValue = document.getElementById('cquestions').value ;\n"
$limereplacementoutput .= "\t<body scroll=\"no\" style=\"OVERFLOW: hidden\">\n"
. "\t\t<table height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n"
. "\t\t\t<tr>\n"
. "\t\t\t\t<td>\n";
. "FCKLimeReplacementFieldss.Add( sValue ) ;\n"
. "return true ;\n"
. "\t}\n";
$limereplacementoutput .= ""
. "\t</script>\n"
. "</head>\n";
$limereplacementoutput .= "\t<body scroll=\"no\" style=\"OVERFLOW: hidden;\">\n"
. "<table height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n"
. "\t<tr>\n"
. "<td>\n";
switch ($fieldtype)
{
case 'survey-desc':
case 'survey-welc':
case 'survey-endtext':
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("Firstname from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('TOKEN:EMAIL',$clang->gT("Email from the token"));
case 'survey-desc':
case 'survey-welc':
case 'survey-endtext':
case 'edittitle': // for translation
case 'editdescription': // for translation
case 'editwelcome': // for translation
case 'editend': // for translation
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Last name from token"));
$replFields[]=array('TOKEN:EMAIL',$clang->gT("Email from the token"));
$replFields[]=array('TOKEN:USESLEFT',$clang->gT("Uses left"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array('TOKEN:'.strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date (YYYY-MM-DD)"));
$replFields[]=array('EXPIRY-DMY',$clang->gT("Survey expiration date (DD-MM-YYYY)"));
$replFields[]=array('EXPIRY-MDY',$clang->gT("Survey expiration date (MM-DD-YYYY)"));
break;
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
break;
case 'email-inv':
case 'email-rem':
// these 2 fields are supported by email-inv and email-rem
// but not email-conf and email-reg for the moment
$replFields[]=array('EMAIL',$clang->gT("Email from the token"));
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
case 'email-conf':
case 'email-reg':
$replFields[]=array('FIRSTNAME',$clang->gT("Firstname from token"));
$replFields[]=array('LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
case 'email-admin-notification':
$replFields[]=array('RELOADURL',$clang->gT("Reload URL"));
$replFields[]=array('VIEWRESPONSEURL',$clang->gT("View response URL"));
$replFields[]=array('EDITRESPONSEURL',$clang->gT("Edit response URL"));
$replFields[]=array('STATISTICSURL',$clang->gT("Statistics URL"));
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Last name from token"));
$replFields[]=array('TOKEN:USESLEFT',$clang->gT("Uses left"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
$replFields[]=array('SURVEYURL',$clang->gT("URL of the survey"));
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date (YYYY-MM-DD)"));
$replFields[]=array('EXPIRY-DMY',$clang->gT("Survey expiration date (DD-MM-YYYY)"));
$replFields[]=array('EXPIRY-MDY',$clang->gT("Survey expiration date (MM-DD-YYYY)"));
break;
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
break;
case 'email-admin-resp':
$replFields[]=array('RELOADURL',$clang->gT("Reload URL"));
$replFields[]=array('VIEWRESPONSEURL',$clang->gT("View response URL"));
$replFields[]=array('EDITRESPONSEURL',$clang->gT("Edit response URL"));
$replFields[]=array('STATISTICSURL',$clang->gT("Statistics URL"));
$replFields[]=array('ANSWERTABLE',$clang->gT("Answers from this response"));
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Last name from token"));
$replFields[]=array('TOKEN:USESLEFT',$clang->gT("Uses left"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
break;
case 'email-inv':
case 'email-rem':
// these 3 fields are supported by email-inv and email-rem
// but not email-reg for the moment
$replFields[]=array('EMAIL',$clang->gT("Email from the token"));
$replFields[]=array('USESLEFT',$clang->gT("Uses left"));
$replFields[]=array('OPTOUTURL',$clang->gT("URL for a respondent to opt-out this survey"));
case 'email-reg':
$replFields[]=array('FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('LASTNAME',$clang->gT("Last name from token"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
$replFields[]=array('SURVEYID',$clang->gT("ID of the survey"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
$replFields[]=array('SURVEYURL',$clang->gT("URL of the survey"));
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
break;
case 'group-desc':
case 'question-text':
case 'question-help':
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("Firstname from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Lastname from token"));
$replFields[]=array('TOKEN:EMAIL',$clang->gT("Email from the token"));
case 'email-conf':
$replFields[]=array('TOKEN',$clang->gT("Token code for this participant"));
$replFields[]=array('FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('LASTNAME',$clang->gT("Last name from token"));
$replFields[]=array('SURVEYNAME',$clang->gT("Name of the survey"));
$replFields[]=array('SURVEYDESCRIPTION',$clang->gT("Description of the survey"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array(strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('ADMINNAME',$clang->gT("Name of the survey administrator"));
$replFields[]=array('ADMINEMAIL',$clang->gT("Email address of the survey administrator"));
$replFields[]=array('SURVEYURL',$clang->gT("URL of the survey"));
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
// email-conf can accept insertans fields for non anonymous surveys
if (isset($surveyid))
{
$surveyInfo = getSurveyInfo($surveyid);
if ($surveyInfo['anonymized'] == "N")
{
$isInstertansEnabled=true;
}
}
break;
case 'group-desc':
case 'question-text':
case 'question-help':
case 'editgroup': // for translation
case 'editgroup_desc': // for translation
case 'editquestion': // for translation
case 'editquestion_help': // for translation
$replFields[]=array('TOKEN:FIRSTNAME',$clang->gT("First name from token"));
$replFields[]=array('TOKEN:LASTNAME',$clang->gT("Last name from token"));
$replFields[]=array('TOKEN:EMAIL',$clang->gT("Email from the token"));
$replFields[]=array('TOKEN:USESLEFT',$clang->gT("Uses left"));
$attributes=GetTokenFieldsAndNames($surveyid,true);
foreach ($attributes as $attributefield=>$attributedescription)
{
$replFields[]=array('TOKEN:'.strtoupper($attributefield), sprintf($clang->gT("Token attribute: %s"),$attributedescription));
}
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date (YYYY-MM-DD)"));
$replFields[]=array('EXPIRY-DMY',$clang->gT("Survey expiration date (DD-MM-YYYY)"));
$replFields[]=array('EXPIRY-MDY',$clang->gT("Survey expiration date (MM-DD-YYYY)"));
case 'editanswer':
$isInstertansEnabled=true;
break;
case 'assessment-text':
$replFields[]=array('TOTAL',$clang->gT("Overall assessment score"));
$replFields[]=array('PERC',$clang->gT("Assessment group score"));
break;
$replFields[]=array('EXPIRY',$clang->gT("Survey expiration date"));
case 'editanswer':
$isInstertansEnabled=true;
break;
case 'assessment-text':
$replFields[]=array('TOTAL',$clang->gT("Overall assessment score"));
$replFields[]=array('PERC',$clang->gT("Assessment group score"));
break;
}
if ($isInstertansEnabled===true)
{
if (empty($surveyid)) {die("No SID provided.");}
//2: Get all other questions that occur before this question that are pre-determined answer types
//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 "
."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid "
."AND {$dbprefix}questions.sid=$surveyid "
."AND {$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."AND {$dbprefix}groups.language='".GetBaseLanguageFromSurveyID($surveyid)."' " ;
$qresult = db_execute_assoc($qquery) or safe_die ("$qquery<br />".$connect->ErrorMsg());
$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, 'CompareGroupThenTitle');
if (empty($surveyid)) {safe_die("No SID provided.");}
//2: Get all other questions that occur before this question that are pre-determined answer types
$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)
{
$AddQuestion=True;
switch ($action)
{
case 'addgroup':
$AddQuestion=True;
break;
case 'editgroup':
if (empty($gid)) {die("No GID provided.");}
if ($qrow['gid'] == $gid)
{
$AddQuestion=False;
}
break;
case 'addquestion':
if (empty($gid)) {die("No GID provided.");}
if ( !is_null($prevquestion) &&
$prevquestion['gid'] == $gid &&
$qrow['gid'] != $gid)
{
$AddQuestion=False;
}
break;
case 'editanswer':
case 'copyquestion':
case 'editquestion':
if (empty($gid)) {die("No GID provided.");}
if (empty($qid)) {die("No QID provided.");}
if ($qrow['gid'] == $gid &&
$qrow['qid'] == $qid)
{
$AddQuestion=False;
}
break;
default:
die("No Action provided.");
break;
}
if ( $AddQuestion===True)
{
if ($surveyformat == "S")
{
$previouspagequestion = true;
}
elseif ($surveyformat == "G")
{
if ($previouspagequestion === true)
{ // Last question was on a previous page
if ($qrow["gid"] == $gid)
{ // This question is on same page
$previouspagequestion = false;
}
}
}
elseif ($surveyformat == "A")
{
$previouspagequestion = false;
}
$questionlist[]=Array( "qid" => $qrow["qid"], "previouspage" => $previouspagequestion);
$prevquestion=$qrow;
}
else
{
break;
}
}
// if ($qrow["qid"] != $qid)
// {
// if (!in_array($qrow['type'],$InsertansUnsupportedtypes)
// { //remember the questions of this type
// $questionlist[]=$qrow["qid"];
// }
// }
$theserows=array();
if (isset($questionlist) && is_array($questionlist))
{
foreach ($questionlist as $ql)
{
$query = "SELECT {$dbprefix}questions.qid, "
."{$dbprefix}questions.sid, "
."{$dbprefix}questions.gid, "
."{$dbprefix}questions.question, "
."{$dbprefix}questions.type, "
."{$dbprefix}questions.lid, "
."{$dbprefix}questions.lid1, "
."{$dbprefix}questions.title "
."FROM {$dbprefix}questions, "
."{$dbprefix}groups "
."WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid "
."AND {$dbprefix}questions.qid=".$ql['qid']." "
."AND {$dbprefix}questions.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."AND {$dbprefix}groups.language='".GetBaseLanguageFromSurveyID($surveyid)."'" ;
$result=db_execute_assoc($query) or die("Couldn't get question $qid");
$thiscount=$result->RecordCount();
// And store ¿again? these questions in this array...
while ($myrows=$result->FetchRow())
{ //key => value
$theserows[]=array("qid"=>$myrows['qid'],
"sid"=>$myrows['sid'],
"gid"=>$myrows['gid'],
"previouspage"=>$ql['previouspage'],
"question"=>$myrows['question'],
"type"=>$myrows['type'],
"lid"=>$myrows['lid'],
"lid1"=>$myrows['lid1'],
"title"=>$myrows['title']);
}
}
}
$questionscount=count($theserows);
if ($questionscount > 0)
{
$X="X";
// Will detect if the questions are type D to use latter
$dquestions=array();
foreach($theserows as $rows)
{
$shortquestion=$rows['title'].": ".strip_tags($rows['question']);
if ($rows['type'] == "A" ||
$rows['type'] == "B" ||
$rows['type'] == "C" ||
$rows['type'] == "E" ||
$rows['type'] == "F" ||
$rows['type'] == "H" ||
$rows['type'] == "Q" ||
$rows['type'] == "K") // K added by lemeur
{
$aquery="SELECT * "
."FROM {$dbprefix}answers "
."WHERE qid={$rows['qid']} "
."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, "
."answer";
$aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Array questions<br />$aquery<br />".$connect->ErrorMsg());
while ($arows = $aresult->FetchRow())
{
$shortanswer = strip_tags($arows['answer']);
$shortanswer .= " [{$arows['code']}]";
$cquestions[]=array("$shortquestion [$shortanswer]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code'],$rows['previouspage']);
} //while
} //if A,B,C,E,F,H
elseif ($rows['type'] == ":" || $rows['type'] == ";") // Multiflexi
{
//Get the LIDs
$fquery = "SELECT * "
."FROM {$dbprefix}labels "
."WHERE lid={$rows['lid']} "
."AND language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, code ";
$fresult = db_execute_assoc($fquery);
while ($frow=$fresult->FetchRow())
{
$lids[$frow['code']]=$frow['title'];
}
//Now cycle through the answers
$aquery="SELECT * "
."FROM {$dbprefix}answers "
."WHERE qid={$rows['qid']} "
."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, "
."answer";
$aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Array questions<br />$aquery<br />".$connect->ErrorMsg());
while ($arows = $aresult->FetchRow())
{
$shortanswer = strip_tags($arows['answer']);
$shortanswer .= " [{$arows['code']}]";
foreach($lids as $key=>$val)
{
$cquestions[]=array("$shortquestion [$shortanswer [$val]] ", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arows['code']."_".$key,$rows['previouspage']);
}
}
} //TIBO
elseif ($rows['type'] == "R") //Answer Ranking
{
$aquery="SELECT * "
."FROM {$dbprefix}answers "
."WHERE qid={$rows['qid']} "
."AND ".db_table_name('answers').".language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, answer";
$aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to Ranking question<br />$aquery<br />".$connect->ErrorMsg());
$acount=$aresult->RecordCount();
while ($arow=$aresult->FetchRow())
{
$theanswer = addcslashes($arow['answer'], "'");
$quicky[]=array($arow['code'], $theanswer);
}
for ($i=1; $i<=$acount; $i++)
{
$cquestions[]=array("$shortquestion [RANK $i]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$i,$rows['previouspage']);
}
unset($quicky);
} // for type R
elseif ($rows['type'] == "1") //Answer multi scale
$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));
$questionlist=array();
foreach ($fieldmap as $field)
{
if (empty($field['qid'])) continue;
$AddQuestion=True;
switch ($action)
{
$aquery="SELECT * "
."FROM {$dbprefix}answers "
."WHERE qid={$rows['qid']} "
."AND {$dbprefix}answers.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, "
."answer";
$aresult=db_execute_assoc($aquery) or safe_die ("Couldn't get answers to multi scale question<br />$aquery<br />".$connect->ErrorMsg());
$acount=$aresult->RecordCount();
while ($arow=$aresult->FetchRow())
case 'addgroup':
$AddQuestion=True;
break;
case 'editgroup':
case 'editgroup_desc':
case 'translategroup':
if (empty($gid)) {safe_die("No GID provided.");}
if ($field['gid'] == $gid)
{
$AddQuestion=False;
}
break;
case 'addquestion':
if (empty($gid)) {safe_die("No GID provided.");}
if ( !is_null($prevquestion) &&
$prevquestion['gid'] == $gid &&
$field['gid'] != $gid)
{
$AddQuestion=False;
}
break;
case 'editanswer':
case 'copyquestion':
case 'editquestion':
case 'translatequestion':
case 'translateanswer':
if (empty($gid)) {safe_die("No GID provided.");}
if (empty($qid)) {safe_die("No QID provided.");}
if ($field['gid'] == $gid &&
$field['qid'] == $qid)
{
$AddQuestion=False;
}
break;
case 'emailtemplates':
// this is the case for email-conf
$AddQuestion=True;
break;
default:
safe_die("No Action provided.");
break;
}
if ( $AddQuestion===True)
{
if ($action == 'tokens' && $fieldtype == 'email-conf')
{
$theanswer = addcslashes($arow['code'], "'");
$quicky[]=array($arow['code'], $theanswer);
//For confirmation email all fields are valid
$previouspagequestion = true;
}
elseif ($surveyformat == "S")
{
$previouspagequestion = true;
}
elseif ($surveyformat == "G")
{
if ($previouspagequestion === true)
{ // Last question was on a previous page
if ($field["gid"] == $gid)
{ // This question is on same page
$previouspagequestion = false;
}
}
}
elseif ($surveyformat == "A")
{
$previouspagequestion = false;
}
$lquery="SELECT * "
."FROM {$dbprefix}labels "
."WHERE lid={$rows['lid']} "
."AND {$dbprefix}labels.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, "
."lid";
$lresult=db_execute_assoc($lquery) or safe_die ("Couldn't get labels to Array <br />$lquery<br />".$connect->ErrorMsg());
while ($lrows = $lresult->FetchRow())
{
$cquestions[]=array($rows['title']." ".$arow['code']." [Label ".$lrows['code']."]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arow['code']."#0",$rows['previouspage']);
}
$lquery="SELECT * "
."FROM {$dbprefix}labels "
."WHERE lid={$rows['lid1']} "
."AND {$dbprefix}labels.language='".GetBaseLanguageFromSurveyID($surveyid)."' "
."ORDER BY sortorder, "
."lid";
$lresult=db_execute_assoc($lquery) or safe_die ("Couldn't get labels to Array <br />$lquery<br />".$connect->ErrorMsg());
while ($lrows = $lresult->FetchRow())
{
$cquestions[]=array($rows['title']." ".$arow['code']." [Label ".$lrows['code']."]", $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'].$arow['code']."#1",$rows['previouspage']);
}
$questionlist[]=array_merge($field,Array( "previouspage" => $previouspagequestion));
$prevquestion=$field;
}
else
{
break;
}
}
}
unset($quicky);
$questionscount=count($questionlist);
if ($questionscount > 0)
{
foreach($questionlist as $rows)
{
$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);
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['fieldname'],$rows['previouspage']);
} //foreach questionlist
} //if questionscount > 0
// Now I´ll add a hack to add the questions before as option
// if they are date type
} //Answer multi scale
else
{
$cquestions[]=array($shortquestion, $rows['qid'], $rows['type'], $rows['sid'].$X.$rows['gid'].$X.$rows['qid'],$rows['previouspage']);
} //else
} //foreach theserows
} //if questionscount > 0
// Now I´ll add a hack to add the questions before as option
// if they are date type
//$limereplacementoutput .="\t\t\t<div style='overflow-x:scroll; width:100%; overflow: -moz-scrollbars-horizontal; overflow-y:scroll; height: 100px;'>\n"
}
if (count($replFields) > 0 || isset($cquestions) )
{
$limereplacementoutput .= "\t\t\t\t\t<select name='cquestions' id='cquestions' style='font-family:verdana; background-color: #FFFFFF; font-size:10; border: 0px;width:99%;' size='15' ondblclick='Ok();'>\n";
$noselection = false;
$limereplacementoutput .= "\t<select name='cquestions' id='cquestions' style='font-family:verdana; background-color: #FFFFFF; font-size:10; border: 0px;width:99%;' size='15' ondblclick='Ok();'>\n";
$noselection = false;
}
else
{
$limereplacementoutput .= $clang->gT("No replacement variable available for this field");
//echo $limereplacementoutput;
//return;
$noselection = true;
$limereplacementoutput .= $clang->gT("No replacement variable available for this field");
$noselection = true;
}
if (count($replFields) > 0)
{
$limereplacementoutput .= "\t\t\t\t\t\t<optgroup label='".$clang->gT("Standard Fields")."'>\n";
$limereplacementoutput .= "<optgroup label='".$clang->gT("Standard Fields")."'>\n";
foreach ($replFields as $stdfield)
{
$limereplacementoutput .= "\t\t\t\t\t\t\t<option value='".$stdfield[0]."'";
$limereplacementoutput .= ">".$stdfield[1]."</option>\n";
}
$limereplacementoutput .= "\t\t\t\t\t\t</optgroup>\n";
foreach ($replFields as $stdfield)
{
$limereplacementoutput .= "\t<option value='".$stdfield[0]."' title='".$stdfield[1]."'";
$limereplacementoutput .= ">".$stdfield[1]."</option>\n";
}
$limereplacementoutput .= "</optgroup>\n";
}
if (isset($cquestions))
{
$limereplacementoutput .= "\t\t\t\t\t\t<optgroup label='".$clang->gT("Previous Answers Fields")."'>\n";
foreach ($cquestions as $cqn)
{
$isDisabled="";
if (in_array($cqn[2],$InsertansUnsupportedtypes))
{
$isDisabled=" disabled='disabled'";
}
elseif ($cqn[4] === false)
{
$isDisabled=" disabled='disabled'";
}
$limereplacementoutput .= "<optgroup label='".$clang->gT("Previous Answers Fields")."'>\n";
foreach ($cquestions as $cqn)
{
$isDisabled="";
if (in_array($cqn[2],$InsertansUnsupportedtypes))
{
$isDisabled=" disabled='disabled'";
}
elseif ($cqn[4] === false)
{
$isDisabled=" disabled='disabled'";
}
$limereplacementoutput .= "\t\t\t\t\t\t\t<option value='INSERTANS:$cqn[3]'";
$limereplacementoutput .= " $isDisabled >$cqn[0]</option>\n";
}
$limereplacementoutput .= "\t\t\t\t\t\t</optgroup>\n";
$limereplacementoutput .= "\t<option value='INSERTANS:$cqn[3]' title='".$cqn[0]."'";
$limereplacementoutput .= " $isDisabled >$cqn[0]</option>\n";
}
$limereplacementoutput .= "</optgroup>\n";
}
if ($noselection === false)
{
$limereplacementoutput .= "\t\t\t\t\t</select>\n";
$limereplacementoutput .= "\t</select>\n";
}
$limereplacementoutput .= "\t\t\t\t</td>\n"
. "\t\t\t</tr>\n";
$limereplacementoutput .= "</td>\n"
. "\t</tr>\n";
if (isset($surveyformat))
{
switch ($surveyformat)
{
case 'A':
$limereplacementoutput .= "\t\t\t<tr>\n"
. "\t\t\t\t<td>\n";
$limereplacementoutput .= "\t\t\t\t\t<br />\n"
. "\t\t\t\t\t<font color='orange'>".$clang->gT("Some Question have been disabled")."</font>\n";
$limereplacementoutput .= "\t\t\t\t\t<br />\n"
. "\t\t\t\t\t".sprintf($clang->gT("Survey Format is %s:"), $clang->gT("All in one"))
. "\t\t\t\t\t<br />\n"
. "\t\t\t\t\t<i>".$clang->gT("Only Previous pages answers are available")."</i>\n"
. "\t\t\t\t\t<br />\n";
$limereplacementoutput .= "\t\t\t\t</td>\n"
. "\t\t\t</tr>\n";
break;
case 'G':
$limereplacementoutput .= "\t\t\t<tr>\n"
. "\t\t\t\t<td>\n";
$limereplacementoutput .= "\t\t\t\t\t<br /><font color='orange'>".$clang->gT("Some Question have been disabled")."</font>";
case 'A':
$limereplacementoutput .= "\t<tr>\n"
. "<td>\n";
$limereplacementoutput .= "\t<br />\n"
. "\t<font color='orange'>".$clang->gT("Some Question have been disabled")."</font>\n";
$limereplacementoutput .= "\t<br />\n"
. "\t".sprintf($clang->gT("Survey Format is %s:"), $clang->gT("All in one"))
. "\t<br />\n"
. "\t<i>".$clang->gT("Only Previous pages answers are available")."</i>\n"
. "\t<br />\n";
$limereplacementoutput .= "</td>\n"
. "\t</tr>\n";
break;
case 'G':
$limereplacementoutput .= "\t<tr>\n"
. "<td>\n";
$limereplacementoutput .= "\t<br /><font color='orange'>".$clang->gT("Some Question have been disabled")."</font>";
$limereplacementoutput .= "<br />".sprintf($clang->gT("Survey mode is set to %s:"), $clang->gT("Group by Group"))."<br/><i>".$clang->gT("Only Previous pages answers are available")."</i><br />";
$limereplacementoutput .= "\t\t\t\t</td>\n"
. "\t\t\t</tr>\n";
break;
$limereplacementoutput .= "</td>\n"
. "\t</tr>\n";
break;
}
}
$limereplacementoutput .= "\t\t</table>\n"
. "\t</body>\n"
. "</html>";
$limereplacementoutput .= "</table>\n";
echo $limereplacementoutput;
exit;
?>