예제 #1
0
function setUserGoesToEvent($idUser, $idEvent, $state)
{
    global $db;
    if (getUserByID($idUser) == FALSE) {
        return FALSE;
    }
    if (getEventByID($idEvent) == FALSE) {
        return FALSE;
    }
    if ($state) {
        if (getUserGoesToEvent($idUser, $idEvent)) {
            return FALSE;
        }
        if (!userIsInvited($idUser, $idEvent)) {
            inviteToEvent($idUser, $idEvent);
        }
        $result = createUserToEvent($idUser, $idEvent);
    } else {
        if (!getUserGoesToEvent($idUser, $idEvent) && userIsInvited($idUser, $idEvent)) {
            return FALSE;
        }
        if (!userIsInvited($idUser, $idEvent)) {
            inviteToEvent($idUser, $idEvent);
        }
        $result = deleteUserToEvent($idUser, $idEvent);
    }
    return $result;
}
예제 #2
0
<?php

session_start();
include_once '../database/connect.php';
include_once '../database/access_db.php';
include_once 'json_response.php';
$idUser = $_SESSION['user'];
$idEvent = $_POST['event'];
$request = $_POST['request'];
switch ($request) {
    case 'get':
        if (getUserGoesToEvent($idUser, $idEvent)) {
            printResponse("going", 'event');
        } elseif (userIsInvited($idUser, $idEvent)) {
            printResponse("not going", 'event');
        } else {
            printResponse("not invited", 'event');
        }
        break;
    case 'attend':
        $state = $_POST['state'];
        switch ($state) {
            case 'true':
                $state = true;
                break;
            case 'false':
                $state = false;
                break;
            default:
                printResponse(false, 'event');
                break;