Esempio n. 1
0
<?php

require_once '../php/Connection.php';
require_once '../php/GroupSystem.php';
$db = new Connection();
$groupSys = new GroupSystem($db);
echo $groupSys->is_member(1, 60);
echo '<hr>' . $groupSys->error;
Esempio n. 2
0
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    if (!($postSys = new PostSystem($db))) {
        throw new Exception("Couldn't connect to post system!");
    }
    if (!($params->post_id && $params->content)) {
        throw new Exception("Missing parameters!");
    } else {
        $user_id = $loginSys->user['id'];
        $post_id = $params->post_id;
        $content = $params->content;
        $group_id = $postSys->GetPost($post_id)['group_id'];
        // get group id directly from post to verify user's membership
        // Verify that user is a member of group
        if (!$groupSys->is_member($group_id, $user_id)) {
            throw new Exception("User is not a member of the group!");
        }
        // Post message
        if (!$postSys->NewComment($user_id, $post_id, $group_id, $content)) {
            throw new Exception($postSys->error);
        } else {
            $success = true;
        }
    }
} catch (Exception $e) {
    $error_msg = $e->getMessage();
}
echo json_encode(array('success' => $success, 'error_msg' => $error_msg));
Esempio n. 3
0
    } else {
        $group_id = $_GET['group_id'];
        $oldest_post_id = $_GET['oldest_post_id'];
        $last_update = $_GET['last_update'];
    }
    // Setup API
    if (!($db = new Connection())) {
        throw new Exception("Couldn't connect to database!");
    }
    if (!($loginSys = new LoginSystem($db))) {
        throw new Exception("Couldn't connect to login system!");
    }
    if (!($postSys = new PostSystem($db))) {
        throw new Exception("Couldn't connect to post system!");
    }
    if (!($groupSys = new GroupSystem($db))) {
        throw new Exception("Couldn't connect to group system!");
    }
    // Verify that user is member of group
    if (!$groupSys->is_member($group_id, $loginSys->user['id'])) {
        throw new Exception("User isn't a member of requested group!");
    }
    // Get Posts
    if (!($posts = $postSys->GetPostUpdate($group_id, $oldest_post_id, $last_update))) {
        throw new Exception($postSys->error);
    }
} catch (Exception $e) {
    $error_msg = $e->getMessage();
    $success = false;
}
echo json_encode(array('success' => $success, 'error_msg' => $error_msg, 'posts' => $posts));