Exemple #1
0
 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');
         // Get instance of ProjectsDatabase
         $account_session = new AccountSession($database);
         $files_database = new FilesDatabase($database);
         $projects_database = new ProjectsDatabase($database);
         if ($account_session->check_login()) {
             // Attempt to create project folder
             $status = $files_database->create_new_folder(null, "Root Folder");
             if ($status !== FilesDatabase::NEW_ITEM_OKAY) {
                 $err = $this->send_error("Failed to create a project folder");
                 $err['details'] = $files_database->get_last_exception_message();
             }
             $root_folder_id = $files_database->get_last_inserted();
             // Attempt to add new project
             $status = $projects_database->add_new_project($_POST['group_id'], $root_folder_id, $_POST['name']);
             if ($status === ProjectsDatabase::NEW_PROJECT_OKAY) {
                 return array('status' => "okay");
             } else {
                 $response = array();
                 $response['status'] = "error";
                 if ($status == ProjectsDatabase::NEW_PROJECT_INVALID_NAME) {
                     $response['message'] = "Project 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'] = $projects_database->get_last_exception_message();
                     }
                     if (DEV_MODE) {
                         $response['status_code'] = $status;
                     }
                 }
                 return $response;
             }
         }
     } catch (PDOException $e) {
         $response = array('status' => "error", 'message' => "Could not connect to the database");
         if (DEV_MODE) {
             $response['details'] = $e->getMessage();
         }
         return $response;
     }
 }