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:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class dFunctionHide implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
|
||||
$funcName=array_shift($args);
|
||||
try
|
||||
{
|
||||
$func = dTexts::loadFunction($funcName);
|
||||
$newStr = $func->run($args);
|
||||
if(strtolower($newStr)=='true'){
|
||||
$id=time().rand(0,100);
|
||||
$hideJS=<<<EOF
|
||||
<div id="hide_$id" style="display:none;"/>
|
||||
<script type="text/javascript">
|
||||
var elem = $('#hide_$id').parent();
|
||||
if(elem.is("li")){
|
||||
elem.css('display','none');
|
||||
}else{
|
||||
elem = elem.parent();
|
||||
if(elem.is("li")){
|
||||
elem.css('display','none');
|
||||
}else{
|
||||
elem = elem.parent();
|
||||
if(elem.is("li")){
|
||||
elem.css('display','none');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
EOF;
|
||||
return $hideJS;
|
||||
}
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
return '';
|
||||
|
||||
}
|
||||
}
|
||||
34
include/limesurvey/classes/dTexts/dFunctions/dFunctionIf.php
Normal file
34
include/limesurvey/classes/dTexts/dFunctions/dFunctionIf.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class dFunctionIf implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
global $connect, $dbprefix;
|
||||
list($field, $value, $valueForTrue, $valueForFalse) = $args;
|
||||
if($valueForTrue === null)
|
||||
$valueForTrue = 'true'; // deafult value
|
||||
if($valueForFalse === null)
|
||||
$valueForFalse = 'false'; // deafult value
|
||||
$srid = $_SESSION['srid'];
|
||||
$sid = $_POST['sid'];
|
||||
$query = "SELECT $field FROM {$dbprefix}survey_$sid WHERE id = $srid";
|
||||
if(!$result = $connect->Execute($query)){
|
||||
throw new Exception("Couldn't get question '$field' answer<br />".$connect->ErrorMsg()); //Checked
|
||||
}
|
||||
$row = $result->fetchRow();
|
||||
|
||||
if ($row[$field] == $value)
|
||||
{
|
||||
return $valueForTrue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $valueForFalse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class dFunctionIfCount implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
global $connect, $dbprefix;
|
||||
list($field, $min, $max, $valueForTrue, $valueForFalse) = $args;
|
||||
if($valueForTrue === null)
|
||||
$valueForTrue = 'true'; // deafult value
|
||||
if($valueForFalse === null)
|
||||
$valueForFalse = 'false'; // deafult value
|
||||
if($max == 0) // if field with $max is empty '::'
|
||||
$max = PHP_INT_MAX;
|
||||
|
||||
$srid = $_SESSION['srid'];
|
||||
$sid = $_POST['sid'];
|
||||
$query = "SELECT * FROM {$dbprefix}survey_$sid WHERE id = $srid";
|
||||
if(!$result = $connect->Execute($query)){
|
||||
throw new Exception("Couldn't get question '$field' answer<br />".$connect->ErrorMsg()); //Checked
|
||||
}
|
||||
$row = $result->fetchRow();
|
||||
|
||||
$hits = 0;
|
||||
while($e = each($row))
|
||||
if(stripos($e['key'], $field) !== false) // we're checking only fields containing answer to our question
|
||||
if(($e['value'] !== "")) // increase hits if user answered that question
|
||||
++$hits;
|
||||
|
||||
if($hits >= $min && $hits <= $max)
|
||||
return $valueForTrue;
|
||||
else
|
||||
return $valueForFalse;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class dFunctionIfIn implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
global $connect, $dbprefix;
|
||||
$field = array_shift($args);
|
||||
$valueForTrue = array_shift($args); // value that will'be inserted if user's answer hits one of our options
|
||||
$srid = $_SESSION['srid'];
|
||||
$sid = $_POST['sid'];
|
||||
$query = "SELECT $field FROM {$dbprefix}survey_$sid WHERE id = $srid";
|
||||
if(!$result = $connect->Execute($query)){
|
||||
throw new Exception("Couldn't get question '$field' answer<br />".$connect->ErrorMsg()); //Checked
|
||||
}
|
||||
$row = $result->fetchRow();
|
||||
$value = $row[$field];
|
||||
|
||||
if(in_array($value, $args))
|
||||
return $valueForTrue;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class dFunctionInsertAns implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
global $connect;
|
||||
$field = $args[0];
|
||||
if (isset($_SESSION['srid'])) $srid = $_SESSION['srid'];
|
||||
$sid = returnglobal('sid');
|
||||
return retrieve_Answer($field, $_SESSION['dateformats']['phpdate']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Interface for dynamic texts functions/classes
|
||||
* @author lime-nk Michal Kurzeja
|
||||
*
|
||||
*/
|
||||
interface dFunctionInterface
|
||||
{
|
||||
public function __construct();
|
||||
public function run($args);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
class dFunctionSwitch implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
global $connect, $dbprefix;
|
||||
$field = $args[0];
|
||||
$srid = $_SESSION['srid'];
|
||||
$sid = $_POST['sid'];
|
||||
$query = "SELECT $field FROM {$dbprefix}survey_$sid WHERE id = $srid";
|
||||
if(!$result = $connect->Execute($query)){
|
||||
throw new Exception("Couldn't get question '$field' answer<br />".$connect->ErrorMsg()); //Checked
|
||||
}
|
||||
$row = $result->fetchRow();
|
||||
$value = $row[$field];
|
||||
|
||||
$found = array_keys($args, $value);
|
||||
if(count($found))
|
||||
{
|
||||
while($e = each($found))
|
||||
if($e['value'] % 2 != 0) // we check this, as only at odd indexes there are 'cases'
|
||||
return $args[$e['value']+1]; // returns value associated with found 'case'
|
||||
}
|
||||
// return empty string if none of cases matches user's answer
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class dFunctionToken implements dFunctionInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run($args)
|
||||
{
|
||||
global $surveyid;
|
||||
if (isset($_SESSION['token']) && $_SESSION['token'] != '')
|
||||
{
|
||||
//Gather survey data for tokenised surveys, for use in presenting questions
|
||||
$_SESSION['thistoken']=getTokenData($surveyid, $_SESSION['token']);
|
||||
}
|
||||
|
||||
if (isset($_SESSION['thistoken']))
|
||||
{
|
||||
if (!strcmp(strtolower($args[0]),'firstname')) return $_SESSION['thistoken']['firstname'];
|
||||
if (!strcmp(strtolower($args[0]),'lastname')) return $_SESSION['thistoken']['lastname'];
|
||||
if (!strcmp(strtolower($args[0]),'email')) return $_SESSION['thistoken']['email'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if(stripos($args[0],'attribute_')!==FALSE){
|
||||
$attr_no=(int)str_replace('ATTRIBUTE_','',$args[0]);
|
||||
if (isset($_SESSION['thistoken']['attribute_'.$attr_no])) return $_SESSION['thistoken']['attribute_'.$attr_no];
|
||||
}
|
||||
|
||||
throw new Exception('TOKEN incorrect!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user