$success = false; $error_msg = 'msg'; try { if (!($params = json_decode(file_get_contents('php://input')))) { throw new Exception("Couldn't decode incoming data!"); } 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 (!($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
$error_msg = ''; try { // Test Parameters if (!isset($_GET['group_id'])) { throw new Exception("Parameters not received!"); } 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 (!($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!"); } // Set Variables $group_id = $_GET['group_id']; $user_id = $loginSys->user['id']; if (!$groupSys->is_member($group_id, $user_id)) { throw new Exception("Not a member of group."); } if (!$groupSys->RemoveFromGroup($group_id, $user_id)) { throw new Exception("Couldn't remove from group!"); } if (!$postSys->RemoveAllUserPosts($group_id, $user_id)) { throw new Exception("Couldn't delete user's posts!"); } } catch (Exception $e) {
// Test Parameters if (!isset($_GET['group_id'], $_GET['oldest_post_id'], $_GET['last_update'])) { throw new Exception("Parameters not received!"); } 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();
$posts = array(); try { // Test Parameters if (!isset($_GET['post_id'], $_GET['last_loaded'])) { throw new Exception("Parameters not received!"); } $post_id = $_GET['post_id']; $last_loaded = $_GET['last_loaded']; // 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!"); } $group_id = $postSys->GetPost($post_id)['group_id']; // get group id directly from post to verify user's membership // 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 (!($comments = $postSys->GetCommentsUpdate($post_id, $last_loaded))) { throw new Exception($postSys->error); }
$success = false; $error_msg = 'msg'; try { if (!($params = json_decode(file_get_contents('php://input')))) { throw new Exception("Couldn't decode incoming data!"); } 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 (!($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) { throw new Exception("Missing parameters!"); } else { $user_id = $loginSys->user['id']; $post_id = $params->post_id; // Post message if (!$postSys->RemovePost($user_id, $post_id)) { throw new Exception("Unable to remove post!"); } else { $success = true; } } } catch (Exception $e) {
require_once '../php/Connection.php'; require_once '../php/LoginSystem.php'; require_once '../php/PostSystem.php'; $success = false; $error_msg = 'msg'; try { if (!($params = json_decode(file_get_contents('php://input')))) { throw new Exception("Couldn't decode incoming data!"); } 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 (!($params->post_id && $params->content)) { throw new Exception("Missing parameters!"); } else { $user_id = $loginSys->user['id']; $post_id = $params->post_id; $content = $params->content; // Edit message if (!$postSys->EditPost($user_id, $post_id, $content)) { throw new Exception("Unable to edit post!"); } else { $success = true; } }
$count = 0; try { // Test Parameters if (!isset($_GET['group_id'])) { throw new Exception("Request not received!"); } else { $group_id = $_GET['group_id']; } // 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 (!($count = $postSys->CountPosts($group_id))) { throw new Exception("Unable to count posts!"); } } catch (Exception $e) { $error_msg = $e->getMessage();
$error_msg = ''; $count = 0; try { // Test Parameters if (!isset($_GET['post_id'])) { throw new Exception("Request not received!"); } $post_id = $_GET['post_id']; // 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!"); } // Get group id from database $group_id = $postSys->GetPost($post_id)['group_id']; // 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 (!($count = $postSys->CountComments($post_id))) { throw new Exception("Unable to count posts!"); }
$success = false; $error_msg = 'msg'; try { if (!($params = json_decode(file_get_contents('php://input')))) { throw new Exception("Couldn't decode incoming data!"); } 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 (!($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->group_id && $params->content)) { throw new Exception("Missing parameters!"); } else { $user_id = $loginSys->user['id']; $group_id = $params->group_id; $content = $params->content; // 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->NewPost($user_id, $group_id, $content)) { throw new Exception("Unable to submit post!");
// Test Parameters if (!isset($_GET['post_id'], $_GET['offset'], $_GET['amount'])) { throw new Exception("Request not received!"); } else { $post_id = $_GET['post_id']; $offset = $_GET['offset']; $amount = $_GET['amount']; } // 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!"); } $group_id = $postSys->GetPost($post_id)['group_id']; // 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 (!($comments = $postSys->GetComments($post_id, $offset, $amount))) { throw new Exception("Unable to retreive comments!"); } } catch (Exception $e) {
// Test Parameters if (!isset($_GET['group_id'], $_GET['offset'], $_GET['amount'])) { throw new Exception("Request not received!"); } else { $group_id = $_GET['group_id']; $offset = $_GET['offset']; $amount = $_GET['amount']; } // 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->GetPosts($group_id, $offset, $amount))) { throw new Exception("Unable to retreive posts!"); } } catch (Exception $e) { $error_msg = $e->getMessage();
<?php require_once '../php/Connection.php'; require_once '../php/LoginSystem.php'; require_once '../php/PostSystem.php'; $db = new Connection(); $loginSys = new LoginSystem($db); $postSys = new PostSystem($db); $success = false; if (isset($_POST['content']) && $loginSys->user) { $success = $postSys->NewPost($loginSys->user['id'], $loginSys->group_id, $_POST['content']); } ?> <!doctype html> <html> <head> <title>Submit Post</title> <meta charset="utf-8"/> <meta http-equiv="refresh" content="2; url=index.php" /> <link rel="stylesheet" type="text/css" href="css/php.css"/> </head> <body> <div><!-- wrapper div --> <div id="message"> <?php if ($success) { ?> Post submitted!
<?php require_once '../php/Connection.php'; require_once '../php/LoginSystem.php'; require_once '../php/PostSystem.php'; $db = new Connection(); $loginSys = new LoginSystem($db); $postSys = new PostSystem($db); $success = false; if (isset($_GET['id']) && $loginSys->user) { $success = $postSys->RemovePost($loginSys->user['id'], $_GET['id']); } ?> <!doctype html> <html> <head> <title>Remove Post</title> <meta charset="utf-8"/> <meta http-equiv="refresh" content="2; url=index.php" /> <link rel="stylesheet" type="text/css" href="css/php.css"/> </head> <body> <div><!-- wrapper div --> <div id="message"> <?php if ($success) { ?> Post removed!
<?php require_once '../php/Connection.php'; require_once '../php/LoginSystem.php'; require_once '../php/GroupSystem.php'; require_once '../php/PostSystem.php'; require_once '../php/Time.php'; $db = new Connection(); $loginSys = new LoginSystem($db); $groupSys = new GroupSystem($db); $postSys = new PostSystem($db); // Not logged in if (!$loginSys->user) { ?> <!doctype html> <html> <head> <meta http-equiv="refresh" content="0; url=/"/> </head> <body></body> </html> <?php // Logged in } else { // Get Associated groups $groups = $groupSys->GetUserGroups($loginSys->user['id']); // Get Group Members $members = $loginSys->GetUsers($groupSys->GetMembers($loginSys->group_id)); // Get group posts