View Issue Details

IDProjectCategoryView StatusLast Update
05015User patches[All Projects] Otherpublic2012-06-21 13:23
Reporteruser12634Assigned Toc_schmitz  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version2.00 
Summary05015: SGQA identifier is reduntant
Description

While the question id (qid) is an unique key (see definition of table PREFIX_questions) and indentify each question unambiguous it is reduntant tu specify the survey id and the group id in the SGQA.
It will be much more easy to use the SGQA identifier if we have to check only one id instead of three. And if we don't have to specify the group id it would be insensitive to moving questions between groups, which is now very frustrating if I have many questions using SGQA.

Is it possible to introduce a simplified syntax, for example "XXquid" or "quid"?

I could write such patch by myself if you show me the part of the code wich is responsible for the SGQA.

TagsNo tags attached.
Complete LimeSurvey version number (& build)9797

Activities

user12634

2011-03-25 12:48

  ~14537

Here are small modyfications of two functions in common_functions.php (lime v1.91RC4) that let me use only QID for dynamic texts.
The loop through all the $_SESION table keys is no a pretty sollution, but while there is only dozen of keys in this table in my survey, it should not produce to big overhead.

function insertansReplace($line)
{
if (!isset($_SESSION['dateformats']['phpdate'])) $_SESSION['dateformats']['phpdate']='';
//<-- MATEUSZ 25.03.2011
// dirty patch implementing using only QID for retrieving answers that were already given, eg. {INSERTANS:1234} instead of {INSERTANS:1234X5678X9012}
while (($pos=strpos($line, "{INSERTANS:")) !== false)
{
$len=strpos($line, "}", $pos)-$pos+1;
$answreplace=substr($line, $pos, $len);
$answreplace2=substr($answreplace, 11, -1);
/
$answreplace=substr($line, strpos($line, "{INSERTANS:"), strpos($line, "}", strpos($line, "{INSERTANS:"))-strpos($line, "{INSERTANS:")+1);
$answreplace2=substr($answreplace, 11, strpos($answreplace, "}", strpos($answreplace, "{INSERTANS:"))-11);
/
$answreplace3=strip_tags(retrieve_Answer($answreplace2, $_SESSION['dateformats']['phpdate']));
$line=str_replace($answreplace, $answreplace3, $line);

}
//-->
return $line;

}

function retrieve_Answer($code, $phpdateformat=null)
{
//This function checks to see if there is an answer saved in the survey session
//data that matches the $code. If it does, it returns that data.
//It is used when building a questions text to allow incorporating the answer
//to an earlier question into the text of a later question.
//IE: Q1: What is your name? [Jason]
// Q2: Hi [Jason] how are you ?
//This function is called from the retriveAnswers function.
global $dbprefix, $connect, $clang;
//Find question details
//<-- MATEUSZ 25.03.2011
// dirty patch implementing using only QID for retrieving answers that were already given, eg. {INSERTANS:1234} instead of {INSERTANS:1234X5678X9012}
if (!isset($_SESSION[$code]))
{
foreach(array_keys($_SESSION) as $i)
{
$itmp=explode('X', $i);
if(count($itmp) < 3 ) continue;
$itmp=implode('X', array_slice($itmp, 2));
if($itmp == $code)
{
$code=$i;
break;
}
}
}
//-->
if (isset($_SESSION[$code]))
{
$questiondetails=getsidgidqidaidtype($code);
//the getsidgidqidaidtype function is in common.php and returns
//a SurveyID, GroupID, QuestionID and an Answer code
//extracted from a "fieldname" - ie: 1X2X3a
// also returns question type

    if ($questiondetails['type'] == &quot;M&quot; ||
    $questiondetails['type'] == &quot;P&quot;)
    {
        $query=&quot;SELECT * FROM {$dbprefix}questions WHERE parent_qid='&quot;.$questiondetails['qid'].&quot;' AND language='&quot;.$_SESSION['s_lang'].&quot;'&quot;;
        $result=db_execute_assoc($query) or safe_die(&quot;Error getting answer<br />$query<br />&quot;.$connect->ErrorMsg());  //Checked
        while($row=$result->FetchRow())
        {
            if (isset($_SESSION[$code.$row['title']]) && $_SESSION[$code.$row['title']] == &quot;Y&quot;)
            {
                $returns[] = $row['question'];
            }
            elseif (isset($_SESSION[$code]) && $_SESSION[$code] == &quot;Y&quot; && $questiondetails['aid']==$row['title'])
            {
                return $row['question'];
            }
        }
        if (isset($_SESSION[$code.&quot;other&quot;]) && $_SESSION[$code.&quot;other&quot;])
        {
            $returns[]=$_SESSION[$code.&quot;other&quot;];
        }
        if (isset($returns))
        {
            $return=implode(&quot;, &quot;, $returns);
            if (strpos($return, &quot;,&quot;))
            {
                $return=substr_replace($return, &quot; &&quot;, strrpos($return, &quot;,&quot;), 1);
            }
        }
        else
        {
            $return=$clang->gT(&quot;No answer&quot;);
        }
    }
    elseif (!$_SESSION[$code] && $_SESSION[$code] !=0)
    {
        $return=$clang->gT(&quot;No answer&quot;);
    }
    else
    {
        $return=getextendedanswer($code, $_SESSION[$code], 'INSERTANS',$phpdateformat);
    }
}
else
{
    $return=$clang->gT(&quot;Error&quot;) . &quot;($code)&quot;;
}
return html_escape($return);

}

c_schmitz

c_schmitz

2011-03-29 11:26

administrator   ~14592

This will be resolved in 1.92. Unfortunately this was coded the same time by one of our coders. Thank you anyway for the patch.

Issue History

Date Modified Username Field Change
2011-03-10 09:38 user12634 New Issue
2011-03-10 12:25 c_schmitz Project Bug reports => User patches
2011-03-25 12:48 user12634 Note Added: 14537
2011-03-29 11:26 c_schmitz Note Added: 14592
2011-03-29 11:26 c_schmitz Status new => resolved
2011-03-29 11:26 c_schmitz Fixed in Version => 2.00
2011-03-29 11:26 c_schmitz Resolution open => fixed
2011-03-29 11:26 c_schmitz Assigned To => c_schmitz
2012-06-21 13:23 c_schmitz Status resolved => closed