/**
 * return the tasklist as an xml document that 
 * would be used by the drdat app on a phone
 */
function smarty_function_tasklist2xml($params, &$smarty)
{
    if (!Check::digits($params['study_id'], $empty = false)) {
        return;
    }
    $s = new Schedule();
    return htmlentities($s->tasklist2xml($params['study_id']));
}
Beispiel #2
0
/**
 * get task information for the specified task
 */
function smarty_function_task($params, &$smarty)
{
    $t = new Task();
    if (!Check::digits($params['task_id'], $empty = false)) {
        return;
    }
    $smarty->assign('task', $t->getone($params['task_id']));
}
Beispiel #3
0
/**
 * find the tasks for this particular study
 */
function smarty_function_tasks($params, &$smarty)
{
    $t = new Task();
    if (!Check::digits($params['study_id'])) {
        return;
    }
    $smarty->assign('tasks', $t->tasks($params['study_id'], $_SESSION['user']['researcher_id'], $params['all'] ? true : false));
}
Beispiel #4
0
/**
 * take our raw form data and make a data structure out of it
 * that can be used in templates
 */
function smarty_function_forms($params, &$smarty)
{
    if (!Check::digits($params['task_id'], $empty = false)) {
        return;
    }
    $t = new Task();
    $smarty->assign('forms', $t->parseforms($params['task_id']));
}
Beispiel #5
0
/**
 * get data for a participant and create a smarty $part variable
 */
function smarty_function_part($params, &$smarty)
{
    if (!Check::digits($params['part_id'], $empty = false)) {
        return;
    }
    $p = new Participant();
    $smarty->assign('part', $p->getone($params['part_id']));
}
Beispiel #6
0
/**
 * take our raw form data and make an xml representation of it
 * that should be exactly what gets sent to the phones
 */
function smarty_function_formhtml($params, &$smarty)
{
    if (!Check::digits($params['task_id'], $empty = false)) {
        return;
    }
    # study_id is needed for the scheduling information for the task
    if (!Check::digits($params['study_id'], $empty = false)) {
        return;
    }
    $t = new Task();
    if ($params['style'] == 'mobile') {
        if ($params['width'] > 0) {
            $width = (int) $params['width'];
        } else {
            $width = 400;
        }
        $rawhtml = $t->forms2html($params['task_id'], $params['study_id']);
        $forms = explode('<!-- split -->', $rawhtml);
        $numforms = count($forms) - 1;
        foreach ($forms as $block) {
            $f++;
            if ($f > $numforms) {
                break;
            }
            $spacer = "";
            if ($f == 1) {
                $prev = "&lt; prev";
                $next = "<input type=submit value=\"next &gt;\">";
            } else {
                if ($f < $numforms) {
                    $prev = "<input type=submit value=\"&lt; prev\">";
                    $next = "<input type=submit value=\"next &gt;\">";
                } else {
                    $prev = "<input type=submit value=\"&lt; prev\">";
                }
            }
            if ($f == $numforms) {
                $next = "<input type=submit value=\"Save data\">";
                $spacer = "<br><br><br>";
            }
            $html .= <<<HTML
<h4>Form {$f}</h4>
<table cellpadding=2 cellspacing=0 border=1 style="width: {$width}" width={$width} class="nobgcolor">
<tr><td>
{$block}
<br>
{$prev} {$next}
<br><br>
</td></tr>
</table>
{$spacer}

HTML;
        }
        return $html;
    }
    return htmlentities($t->forms2html($params['task_id'], $params['study_id']));
}
Beispiel #7
0
/**
 * grab the schedule for a task in a study
 */
function smarty_function_schedule($params, &$smarty)
{
    if (!Check::digits($params['study_id'])) {
        return;
    }
    if (!Check::digits($params['task_id'])) {
        return;
    }
    $s = new Schedule();
    $smarty->assign('schedule', $s->getone(array('study_id' => $params['study_id'], 'task_id' => $params['task_id'])));
}
Beispiel #8
0
/**
 * take our raw form data and make an xml representation of it
 * that should be exactly what gets sent to the phones
 */
function smarty_function_formxml($params, &$smarty)
{
    if (!Check::digits($params['task_id'], $empty = false)) {
        return;
    }
    # study_id is needed for the scheduling information for the task
    if (!Check::digits($params['study_id'], $empty = false)) {
        return;
    }
    $t = new Task();
    return htmlentities($t->forms2xml($params['task_id'], $params['study_id']));
}
Beispiel #9
0
/**
 * get data for all participants in a study and create a smarty $parts variable
 */
function smarty_function_parts($params, &$smarty)
{
    if (!Check::digits($params['study_id'], $empty = false)) {
        return;
    }
    if ($params['all']) {
        $active = null;
    } else {
        $active = 1;
    }
    $p = new Participant();
    $smarty->assign('parts', $p->studyparts($_SESSION['user']['researcher_id'], $params['study_id'], $active));
}
Beispiel #10
0
/**
 * get data for an individual study based on 
 * the user's researcher_id and a supplied study_id
 * creates $study smarty variable
 */
function smarty_function_study($params, &$smarty)
{
    if (!Check::digits($params['study_id'])) {
        $smarty->assign('study', array());
        return;
    }
    $s = new Study();
    $study = $s->study($_SESSION['user']['researcher_id'], $params['study_id']);
    $p = new Enrollment();
    $participants = $p->howmany(array(" where study_id=%u and active>0 ", $params['study_id']));
    $smarty->assign('study', $study);
    $smarty->assign('participants', $participants);
}
Beispiel #11
0
 public function downloaddata()
 {
     try {
         if (Check::digits($_REQUEST['study_id'], $empty = false)) {
             $study_id = $_REQUEST['study_id'];
         } else {
             throw new Exception("bad study id!");
         }
         global $studyname;
         $studyname = "study_{$study_id}";
         if (isset($_REQUEST['task_id'])) {
             if (Check::digits($_REQUEST['task_id'], $empty = false)) {
                 $task_id = $_REQUEST['task_id'];
             } else {
                 throw new Exception("bad task id!");
             }
             $studyname .= "-task_{$task_id}";
         }
         if (isset($_REQUEST['email'])) {
             if (Check::isemail($_REQUEST['email'], $empty = false)) {
                 $email = $_REQUEST['email'];
             } else {
                 throw new Exception("bad email!");
             }
             if (Check::ismd5($_REQUEST['password'])) {
                 $password = $_REQUEST['password'];
             } else {
                 throw new Exception("bad password!");
             }
             $studyname .= "-{$email}";
         }
         $d = new Data();
         View::assign('csv', $d->task2CSV($study_id, $task_id, $email, $password));
         View::assign('studyname', $studyname);
         global $contenttype;
         $contenttype = 'text-csv';
         return 'downloaddata.tpl';
     } catch (Exception $e) {
         $this->err($e);
         View::assign('error', $this->error);
         return 'error.tpl';
     }
 }
Beispiel #12
0
 public function tasklist($_id, $_extra = null)
 {
     try {
         $empty = false;
         if (!Check::digits($_id, $empty)) {
             if (!Check::isemail($_id, $empty)) {
                 throw new Exception("bad email!");
             }
             if (!Check::ismd5($_extra)) {
                 throw new Exception("bad pw!");
             }
             $where = "where participant.email='%s' and participant.password='******' ";
         } else {
             $where = "where study.study_id=%u ";
         }
         $this->run("select distinct task.task_id, task.task_title, schedule.* " . "from task join schedule using (task_id) " . "join study using (study_id) " . "join enrollment using (study_id) " . "join participant using (participant_id) " . $where . "and study.startdate <= schedule.startdate " . "and study.enddate >= schedule.enddate " . "and schedule.active = 1 " . "order by task.task_id", $_id, $_extra);
         return $this->resultarray();
     } catch (Exception $e) {
         $this->err($e);
         return false;
     }
 }