<?php

include_once "../model/TeamModel.php";
include_once "../model/WebFunctions.php";
include_once "../model/ProjectModel.php";
require_once "../model/AuthenticateSession.php";
$teamId = $_GET['team_id'];
$team = TeamModel::getTeamById($teamId);
$projectID = $team['project_id'];
$classID = ProjectModel::getProjectClassById($projectID);
$listOfAvailableStudents = ProjectModel::getFreeStudents($classID);
$listOfTeamMembers = TeamModel::getTeamStudents($teamId);
$table1 = "";
// table 1  - available students
$table2 = "";
// table 2 - students already in team
$summary = $team['summary'];
$creatorId = $team['creator_id'];
if (count($listOfAvailableStudents) > 0) {
    for ($int = 0; $int < count($listOfAvailableStudents); $int++) {
        $table1 .= "<li id='" . $listOfAvailableStudents[$int]['student_id'] . "'class=\"list-group-item ui-state-default hand-cursor\">" . $listOfAvailableStudents[$int]['name'] . "</li>";
        // table 1  - available students
    }
}
if (count($listOfTeamMembers) > 0) {
    for ($int = 0; $int < count($listOfTeamMembers); $int++) {
        // table 2 - current students in team
        if ($listOfTeamMembers[$int]['student_id'] == $creatorId) {
            $table2 .= "<li id='" . $listOfTeamMembers[$int]['student_id'] . "' class=\"list-group-item ui-state-default ui-state-disabled\">" . $listOfTeamMembers[$int]['name'] . "<span class=\"badge\">Owner</span>" . "</li>";
        } else {
            $table2 .= "<li id='" . $listOfTeamMembers[$int]['student_id'] . "' class=\"list-group-item ui-state-default hand-cursor\">" . $listOfTeamMembers[$int]['name'] . "</li>";
<?php

include_once "../model/ProjectModel.php";
include_once "../model/WebFunctions.php";
require_once "../model/AuthenticateSession.php";
$id = $_GET['project_id'];
$project = ProjectModel::getProjectById($id);
$listOfTeams = ProjectModel::getProjectTeams($id);
$listOfFreeStudents = ProjectModel::getFreeStudents($project['class_id']);
$content = "";
foreach ($listOfTeams as $team) {
    $content .= "<a href=\"team-id-" . $team['team_id'] . "\"> Team " . $team['team_id'] . " <br> </a>";
}
$content_students = "";
foreach ($listOfFreeStudents as $student) {
    $content_students .= "<a href=\"student-id-" . $student['student_id'] . "\">" . $student['name'] . " <br> </a>";
}
if (!isset($_SESSION)) {
    session_start();
}
// Check right of the user for editing the project
if (array_key_exists('trainer_id', $_SESSION) and $project['trainer_id'] == $_SESSION['trainer_id']) {
    $edit_button = "<a href=\"project-edit-{$id}\"> \r\n\t\t<button type=\"button\" class=\"btn btn-default\">\tEdit project </button> </a>";
} else {
    $edit_button = "<button type=\"button\" class=\"btn btn-default\" disabled>\tEdit project </button>";
}
// add view
include_once "../view/project-detail.php";