} 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!"); } else { $success = true; } } } catch (Exception $e) { $error_msg = $e->getMessage(); } echo json_encode(array('success' => $success, 'error_msg' => $error_msg));
<?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!