mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
New Feature: Pre-generation of cases and copying of sample variables to Limesurvey attributes for "Web First" then CATI methodology
This commit is contained in:
@@ -92,6 +92,57 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['sample']) && isset($_GET['
|
||||
VALUES('$questionnaire_id','$sid','$cm','$cam','$selecttype','$am', '$an')";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
if (isset($_GET['generatecases']))
|
||||
{
|
||||
include_once("../functions/functions.operator.php");
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
$lime_sid = $db->GetOne("SELECT lime_sid FROM questionnaire WHERE questionnaire_id = '$questionnaire_id'");
|
||||
$testing = $db->GetOne("SELECT testing FROM questionnaire WHERE questionnaire_id = '$questionnaire_id'");
|
||||
|
||||
//add limesurvey attribute for each sample var record
|
||||
$sql = "SELECT var,type
|
||||
FROM sample_import_var_restrict
|
||||
WHERE sample_import_id = '$sid'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
$i = 1;
|
||||
|
||||
$fields = array();
|
||||
$fieldcontents='';
|
||||
foreach($rs as $r)
|
||||
{
|
||||
$fields[]=array('attribute_'.$i,'C','255');
|
||||
$fieldcontents.='attribute_'.$i.'='.$r['var']."\n";
|
||||
$i++;
|
||||
}
|
||||
$dict = NewDataDictionary($db);
|
||||
$sqlarray = $dict->ChangeTableSQL(LIME_PREFIX ."tokens_$lime_sid", $fields);
|
||||
$execresult=$dict->ExecuteSQLArray($sqlarray, false);
|
||||
|
||||
$sql = "UPDATE " . LIME_PREFIX . "surveys
|
||||
SET attributedescriptions = " . $db->qstr($fieldcontents) . "
|
||||
WHERE sid='$lime_sid'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
//generate one case for each sample record and set outcome to 41
|
||||
$sql = "SELECT sample_id
|
||||
FROM sample
|
||||
WHERE import_id = '$sid'";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
foreach($rs as $r)
|
||||
{
|
||||
add_case($r['sample_id'],$questionnaire_id,"NULL",$testing,41, true);
|
||||
}
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['edit']))
|
||||
@@ -266,7 +317,14 @@ if ($questionnaire_id != false)
|
||||
|
||||
<label for="allownew" class="control-label col-sm-4"><?php echo T_("Allow new numbers to be drawn?");?></label>
|
||||
<div class="col-sm-1"><input type="checkbox" id = "allownew" name="allownew" checked="checked" class="col-sm-1" data-toggle="toggle" data-size="small" data-on="<?php echo T_("Yes");?>" data-off="<?php echo T_("No");?>" data-width="85"/></div><br/><br/><br/>
|
||||
|
||||
|
||||
<?php $self_complete = $db->GetOne("SELECT self_complete FROM questionnaire WHERE questionnaire_id = '$questionnaire_id'");
|
||||
if ($self_complete) {?>
|
||||
<label for="generatecases" class="control-label col-sm-4"><?php echo T_("Generate cases for all sample records and set outcome to 'Self completion email invitation sent'? (Ideal if you intend to send an email invitation to sample members before attempting to call using queXS)");?></label>
|
||||
<div class="col-sm-1"><input type="checkbox" id = "generatecases" name="generatecases" class="col-sm-1" data-toggle="toggle" data-size="small" data-on="<?php echo T_("Yes");?>" data-off="<?php echo T_("No");?>" data-width="85"/></div><br/><br/><br/>
|
||||
<?php }?>
|
||||
|
||||
<input type="hidden" name="questionnaire_id" value="<?php print($questionnaire_id);?>"/>
|
||||
|
||||
<div class="col-sm-offset-4 col-sm-3"><button type="submit" name="add_sample" class="btn btn-primary"><i class="fa fa-plus-circle fa-lg"></i> <?php echo T_("Add sample");?></button></div>
|
||||
|
||||
@@ -345,17 +345,19 @@ function is_respondent_selection($operator_id)
|
||||
* @param int $questionnaire_id The questionnaire id
|
||||
* @param int $operator_id The operator id (Default NULL)
|
||||
* @param int $testing 0 if a live case otherwise 1 for a testing case
|
||||
* @param int $current_outcome_id The current outcome id (defaults to 1 - not attempted)
|
||||
* @param bool $addlimeattributes If true, add sample values as lime attributes
|
||||
*
|
||||
* @return int The case id
|
||||
*/
|
||||
function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = 0)
|
||||
function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing = 0, $current_outcome_id = 1, $addlimeattributes = false)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$token = sRandomChars();
|
||||
|
||||
$sql = "INSERT INTO `case` (case_id, sample_id, questionnaire_id, last_call_id, current_operator_id, current_call_id, current_outcome_id,token)
|
||||
VALUES (NULL, $sample_id, $questionnaire_id, NULL, $operator_id, NULL, 1, '$token')";
|
||||
VALUES (NULL, $sample_id, $questionnaire_id, NULL, $operator_id, NULL, '$current_outcome_id','$token')";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
@@ -440,10 +442,75 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
|
||||
|
||||
if ($lime_sid)
|
||||
{
|
||||
$lfirstname = '';
|
||||
$llastname = '';
|
||||
$lemail = '';
|
||||
|
||||
if ($addlimeattributes)
|
||||
{
|
||||
$lfirstname = $db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '6'");
|
||||
|
||||
$llastname = $db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '7'");
|
||||
|
||||
$lemail = $db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '8'");
|
||||
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,mpid)
|
||||
VALUES (NULL,'','','','$token','".DEFAULT_LOCALE."','N','N',NULL)";
|
||||
VALUES (NULL,'$lfirstname','$llastname','$lemail','$token','".DEFAULT_LOCALE."','N','N',NULL)";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
$tid = $db->Insert_Id();
|
||||
|
||||
if ($addlimeattributes)
|
||||
{
|
||||
//also add sample values as attributes
|
||||
//match by name
|
||||
|
||||
$sql = "SELECT attributedescriptions
|
||||
FROM " . LIME_PREFIX . "surveys
|
||||
WHERE sid = '$lime_sid'";
|
||||
|
||||
$names = $db->GetOne($sql);
|
||||
|
||||
$attdescriptiondata=explode("\n",$names);
|
||||
$atts=array();
|
||||
|
||||
foreach ($attdescriptiondata as $attdescription)
|
||||
{
|
||||
if (!empty($attdescription))
|
||||
$atts['attribute_'.substr($attdescription,10,strpos($attdescription,'=')-10)] = substr($attdescription,strpos($attdescription,'=')+1);
|
||||
}
|
||||
|
||||
foreach($atts as $key => $val)
|
||||
{
|
||||
$lval = $db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.var LIKE '$val'");
|
||||
|
||||
$sql = "UPDATE " . LIME_PREFIX . "tokens_$lime_sid
|
||||
SET $key = '$lval'
|
||||
WHERE tid = '$tid'";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user