<?php require_once "../include/includes.php"; setContentType("text", "plain"); session_start(); $db = new SqlManager($fpConfig); $postData = $_POST; if (!$postData) { $postData = getJsonPostData(); } //$postData = array("action" => "login", "username" => "amy", "password" => "koKoBird" ); debugVar("postData"); $action = $postData ? @$postData["action"] : reqParam("action"); debugVar("action"); $response = array(); // POST: {action: login, username:, password: md5}, return user if successful or null if login fail // POST: {action: register, username, email, password: md5, first_name, last_name}, return user if successful or null if login already exists. // POST: {action: sendResetEmail, email}, return success or error if user not found // POST: {action: resetPassword, email, key, password}, return success or error if user not found or invalid key or empty password // GET/POST {} return current session["user"]; // GET/POST {action: logout} unset session["user"], return empty or null user object; // response: {success: true, user: {}, message: } //compare MD5 password in db with MD5 password submitted function validatePassword($dbUser, $postData) { if (!$dbUser || !isset($postData["password"])) { return false; } return $dbUser["password"] == $postData["password"]; } switch ($action) {
<?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);
<?php require_once "../include/includes.php"; setContentType("text", "plain"); 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");