function ageToYearBorn($db, &$params)
{
    $age = arrayExtract($params, "age");
    if (!$age) {
        return;
    }
    $age = explode(":", $age);
    $currentYear = date("Y");
    $years = array();
    foreach ($age as $a) {
        array_unshift($years, $a ? $currentYear - $a : $a);
    }
    $question = getFormQuestions($db, array("field_name" => "year_born"));
    if (!count($question)) {
        return;
    }
    debug("question", $question, true);
    $qid = $question[0]["id"];
    return $params["Q_{$qid}"] = implode(":", $years);
}
Beispiel #2
0
<?php

require_once "../include/includes.php";
setContentType("text", "plain");
session_start();
$db = new SqlManager($fpConfig);
$postJson = getJsonPostData();
$action = reqParam("action");
if (!$action) {
    $action = @$postJson["action"];
}
$username = fpCurrentUsername();
$response = array();
switch ($action) {
    case "saveForm":
        //save form: insert,update,delete user_answers for this user
        $user_answers = $postJson["formData"];
        $result = saveAnswers($db, $username, $user_answers);
        $response = array("answers" => count($user_answers), "result" => $result);
        break;
    case "form_questions":
    default:
        $response["questions"] = getFormQuestions($db, $_REQUEST);
        if ($username) {
            $response["user_answers"] = $db->selectWhere(array("table" => "user_answer", "username" => $username));
        }
}
$db->disconnect();
$response["queries"] = $db->getLog();
$response["time"] = getTimer(true);
echo jsValue($response);
Beispiel #3
0
session_start();
//get query parameters from request
//query database: upload, user and user_answer tables
//return list of uploads with image urls.
$params = getJsonPostData();
debugVar("params");
if (!$params) {
    $params = $_REQUEST;
}
$username = fpCurrentUsername();
$db = new SqlManager($fpConfig);
if ($db->offline) {
    echo file_get_contents("query.json");
    return;
}
$questions = getFormQuestions($db);
$questions = arrayIndexBy($questions, "id");
//debugVar("questions", true);
$portraitType = arrayExtract($params, "portrait");
//convert age to year_born
ageToYearBorn($db, $params);
$order = arrayExtract($params, "order");
$groupBy = arrayExtract($params, "group");
$interval = arrayExtract($params, "interval");
if (!$groupBy) {
    $results = demographicPortrait($db, $params, $portraitType);
    //$users = arrayDistinct($results, "username");
    $users = filterUsers($db, $params);
    arrayDistinct($results, "username");
    setExists($results);
    $results = array("all" => $results);