function generate_page() { $account_session = new AccountSession(null); $user_template = $this->get_page_template(); $user_template->set_template_file(SITE_PATH . "/templates/user.template.php"); try { $database_connection = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini'); } catch (PDOException $e) { $this->error_response("The following internal error occured: " . $e->getMessage()); return SitePage::PAGE_OKAY; } // Get PageID from page request $pageID = $this->request->get_parameter(0); $pageID = intval($pageID); // Instantiate needed data managers $users_database = new UsersDatabase($database_connection); $groups_database = new GroupsDatabase($database_connection); if ($_SERVER["REQUEST_METHOD"] === "POST") { $this->do_post($users_database, $pageID); } // Get the page user $page_user = $users_database->get_user_by_id($pageID); // Check for case that user doesn't exist if ($page_user === false) { $this->error_response("The user you're looking for does not exist :/"); return SitePage::PAGE_OKAY; } // Set values of user template $user_template->page_id = $pageID; $user_template->user_name = $page_user->get_username(); $user_template->facebook = $page_user->get_facebook(); $user_template->twitter = $page_user->get_twitter(); $user_template->linkedin = $page_user->get_linkedin(); $user_template->email = $page_user->get_email(); $user_template->bio = $page_user->get_bio(); // Attempt to add groups to template try { $user_template->groups = $groups_database->get_groups_by_owner($pageID); } catch (PDOException $e) { $user_template->groups_fetch_error = $e->getMessage(); } if ($account_session->check_login()) { $user_template->login = true; // compare loged in userID to userID of page if ($account_session->get_account_id() == $pageID) { $user_template->is_own_page = true; } else { $user_template->is_own_page = false; } } return SitePage::PAGE_OKAY; }
function generate_page() { // Get PageID from page request $pageID = $this->request->get_parameter(0); $pageID = intval($pageID); $group_template = $this->get_page_template(); $group_template->set_template_file(SITE_PATH . "/templates/group.template.php"); // Instantiate AccountSession without database $account_session = new AccountSession(null); // Attempt database connection try { $database_connection = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini'); } catch (PDOException $e) { $this->error_response("The following internal error occured: " . $e->getMessage); return SitePage::PAGE_OKAY; } // Instantiate needed data managers $users_database = new UsersDatabase($database_connection); $groups_database = new GroupsDatabase($database_connection); $projects_database = new ProjectsDatabase($database_connection); // Get the page group try { $page_group = $groups_database->get_group_by_id($pageID); // Check for case that group doesn't exist if ($page_group === false) { $this->error_response("The group you're looking for does not exist :/"); return SitePage::PAGE_OKAY; } // Get a list of group projects $group_projects = $projects_database->get_projects_by_group($pageID); } catch (PDOException $e) { $this->error_response("The following internal error occured: " . $e->getMessage()); return SitePage::PAGE_OKAY; } // Set values of group template $group_template->group_id = $pageID; $group_template->group_name = $page_group->get_name(); $group_template->group_projects = $group_projects; if ($account_session->check_login()) { $group_template->login = true; // compare loged in userID to userID of page if ($account_session->get_account_id() == $page_group->get_owner()) { $group_template->is_own_group = true; } else { $group_template->is_own_group = false; } } return SitePage::PAGE_OKAY; }
function main() { if ($_SERVER['REQUEST_METHOD'] !== "POST") { return array('status' => "error", 'message' => "Only POST requests accepted"); } // Attempt to get database connection try { $database = \Application\DatabaseConnection::create_from_ini(SITE_PATH . '/config/database.ini'); } catch (PDOException $e) { $response = array('status' => "error", 'message' => "Could not connect to the database"); if (DEV_MODE) { $response['details'] = $e->getMessage(); } return $response; } // Get instance of UsersDatabase $account_session = new AccountSession($database); $groups_database = new GroupsDatabase($database); if ($account_session->check_login()) { // Attempt to register user $status = $groups_database->add_new_group($account_session->get_account_id(), $_POST['name']); if ($status === GroupsDatabase::NEW_GROUP_OKAY) { return array('status' => "okay"); } else { $response = array(); $response['status'] = "error"; if ($status == GroupsDatabase::NEW_GROUP_INVALID_NAME) { $response['message'] = "Group names must contain only A-z0-9'. and must be between 2 and 40 characters"; } else { $response['message'] = "An error occured on our end D: we'll get it fixed; in the meantime, try something else!"; if (DEV_MODE) { $response['details'] = $users_database->get_last_exception_message(); } if (DEV_MODE) { $response['status_code'] = $status; } } return $response; } } }