<?php

require_once "./result_crud.php";
//require_once("./execStep1_crud.php");
require_once "./ipStep1_crud.php";
$committee = $_POST['committee'];
$username = $_POST['username'];
$status = $_POST['status'];
$vares = new result_crud();
//$stats = "InProgress";
if ($committee == "InternationalPress") {
    $com = new ipStep1_crud();
    $find = $com->read($username);
    foreach ($find as $doc) {
        $pos = $doc['positionAvailable'];
    }
    $stats = $vares->ipInsert($username, $committee, $pos, $status);
} else {
    if ($committee == "ExecutiveBoard") {
        $stats = $vares->execInsert($username, $committee, $status);
    } else {
        if ($committee == "Delegates") {
        }
    }
}
echo $stats;
echo "<div class='table-responsive'>";
if ($committee == "InternationalPress") {
    echo "<table id ='usertable' class='table table-striped'><thead><tr><th>Username</th><th>Name</th><th>Phone No.</th><th>Email ID</th><th>Institute</th><th>Position Selected</th><th>Status</th><th>View</th></tr></thead><tbody>";
} else {
    if ($committee == "ExecutiveBoard") {
        echo "<table id ='usertable' class='table table-striped'><thead><tr><th>Username</th><th>Name</th><th>Phone No.</th><th>Email ID</th><th>Institute</th><th>Status</th><th>View</th></tr></thead><tbody>";
    } else {
        if ($committee == "Delegates") {
            echo "<table id ='usertable' class='table table-striped'><thead><tr><th>Username</th><th>Name</th><th>Phone No.</th><th>Email ID</th><th>Institute</th><th>Status</th><th>View</th></tr></thead><tbody>";
        }
    }
}
echo "<table id ='usertable' class='table table-striped'><thead><tr><th>Username</th><th>Name</th><th>Phone No.</th><th>Email ID</th><th>Institute</th><th>Status</th><th>View</th></tr></thead><tbody>";
$show = new info_crud();
$info = $show->readGeneral();
$res = new result_crud();
foreach ($info as $doc) {
    $status = (new ipEssayAns_crud())->readStatus($doc['username']);
    if ($status) {
        echo "<tr>\n\t\t\t\t  <td>" . $doc['username'] . "</td>\n\t\t\t\t  <td>" . $doc['name'] . "</td>\n\t\t\t\t  <td>" . $doc['countryCode'] . $doc['phoneNumber'] . "</td>\n\t\t\t\t  <td>" . $doc['email'] . "</td>\n\t\t\t\t  <td>" . $doc['institute'] . "</td>";
        if ($committee == "InternationalPress") {
            echo "<td>Reporter</td>";
        }
        $result = $res->read($doc['username']);
        $arg1 = $doc['username'];
        $arg2 = $doc['name'];
        $arg = $arg1 . $committee;
        $argw = $arg . "view";
        $status = "InProgress";
        if ($result->count() == 0) {
            $btnclass = 'btn-primary';