예제 #1
0
    public function register($data)
    {
        $db = new Database();
        $db->update('JudgeInvitations', array('Replied' => date('Y-m-d H:i:s'), 'Response' => 1), "id ='" . $data->id . "'");
        $res = $db->getResult();
        if ($res[0] !== 1) {
            return "Invalid invitation link.";
        }
        $db->insert('Judges', array('Title' => $data->Title, 'Affiliation' => $data->Affiliation));
        $res = $db->getResult();
        $id = $res[0];
        foreach ($data->Conflicts as $studentId) {
            $db->insert('JudgeStudentConflicts', array('JudgeId' => $id, 'StudentId' => $studentId));
        }
        $db->select('Settings', 'StudentsPerJudge,Subject,Date,Time,Location');
        $res = $db->getResult();
        $maxStudents = $res['StudentsPerJudge'];
        $db->sql('insert into JudgeStudentGrade (JudgeId, StudentId)
                select ' . $id . ' as JudgeId, s.id as StudentId
                from Students as s
                left outer join JudgeStudentGrade as g on g.StudentId = s.id
                where s.id not in (select StudentId from JudgeStudentConflicts where JudgeId = ' . $id . ')
                group by s.id
                order by count(g.JudgeId), rand()
                limit ' . $maxStudents);
        $db->select('Users', 'Email,FirstName,LastName,StudentId,JudgeId,Roles,DefaultRole', null, "Email ='" . $data->Email . "'");
        $studentUser = $db->getResult();
        if (count($studentUser) > 0) {
            $newRoles = "";
            $defaultRole = "judge";
            if ($studentUser['Roles'] == "admin;student") {
                $newRoles = "admin;judge;student";
            } else {
                if ($studentUser['Roles'] == "student") {
                    $newRoles = "judge;student";
                } else {
                    if ($studentUser['Roles'] == "") {
                        $newRoles = "judge";
                    }
                }
            }
            $success = $db->update('Users', array('Roles' => $newRoles), "Email ='" . $data->Email . "';");
            if (!$success) {
                return "Roles update failed";
            }
            $success = $db->update('Users', array('DefaultRole' => $defaultRole), "Email ='" . $data->Email . "';");
            if (!$success) {
                return "Default update failed";
            }
            $success = $db->sql("UPDATE Users SET Password=password('" . $data->Password . "') WHERE Email ='" . $data->Email . "';");
            // and Password=NULL;");
            if (!$success) {
                return "Password update failed";
            }
            $success = $db->update('Users', array('JudgeId' => ".{$id}."), "Email ='" . $data->Email . "';");
            if (!$success) {
                return "ID update failed";
            }
        } else {
            $db->sql("insert into Users (Email, FirstName, LastName, Password, JudgeId, Roles, DefaultRole) VALUES ('" . $data->Email . "', '" . $data->FirstName . "', '" . $data->LastName . "', password('" . $data->Password . "'), " . $id . ", 'judge', 'judge');");
        }
        $date = date_format(DateTime::createFromFormat('Y-m-d', $res['Date']), "l, F j");
        $sent = mail($data->Email, 'Confirmation: ' . $res['Subject'], '<html>
<body>
    <div style="width: 600px; border: 2px solid #E9EBF6; margin: auto; font-size: 16px; color: #555555;">
        <h1 style="margin: 0; padding: 8px; background-color: #E9EBF6; text-align: center;">
            Dear ' . $data->FirstName . ' ' . $data->LastName . ',
        </h1>
        <div style="overflow: hidden; padding: 8px; padding-top: 0; background-color: #F5F6FB;">
            <p>We are pleased to confirm your participation in the FIU Computer Science Senior Project Event!</p>
			<p>The day of the event will be ' . $date . ' ' . $res['Time'] . ' at ' . $res['Location'] . '.<br /> You will be able to login on this <a href="' . Invites::getRSVPUrl() . '">Web Application</a> with the following credentials:</p>
			<p>Username: '******' <br />Password: '******' <p>
			<p>Keep this information safe for the day of the event.</p>
            <br />
            <p>Sincerely,</p>
            <p>Masoud Sadjadi</p>
        </div>
    </div>
</body>
</html>', "From: Masoud Sadjadi <*****@*****.**>\r\nMIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n");
        return $sent;
    }
예제 #2
0
require_once 'Invites.php';
//ini_set('display_errors', 1);
//error_reporting(E_ALL ^ E_NOTICE);
if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $db = new Database();
    $db->select('JudgeInvitations', 'Replied,Response', null, "id = '" . $id . "'");
    $res = $db->getResult();
    if (count($res) == 0) {
        http_response_code(404);
    } else {
        if ($res['Response'] == null) {
            switch ($_GET['rsvp']) {
                case 'accept':
                    header('Location: ' . Invites::getRSVPUrl() . '#/rsvp=' . $id);
                    break;
                case 'decline':
                    $db->update('JudgeInvitations', array('Replied' => date('Y-m-d H:i:s'), 'Response' => 0), "id ='" . $id . "'");
                    $res = $db->getResult();
                    if ($res[0] == 1) {
                        echo "You have successfully declined the invitation";
                    } else {
                        http_response_code(404);
                    }
                    break;
                default:
                    $body = Invites::getEmailBody($id);
                    if ($body == '') {
                        http_response_code(404);
                    } else {