Beispiel #1
0
function acceptInvitationExe()
{
    if (!is_numeric($_SESSION['userId'])) {
        print "Wrong way";
        exit;
    }
    if (!isset($_REQUEST['invitationId'])) {
        print "Wrong Invitation";
        exit;
    }
    $d = new Delegate();
    $loggedUser = $d->userGetById($_SESSION['userId']);
    $invitation = $d->invitationGetById($_REQUEST['invitationId']);
    if ($invitation->email == $loggedUser->email) {
        //a match made in stars...how lovely :)
        $diagram = $d->diagramGetById($invitation->diagramId);
        //create userdiagram
        $userdiagram = new Userdiagram();
        $userdiagram->diagramId = $diagram->id;
        $userdiagram->invitedDate = $invitation->createdDate;
        $userdiagram->level = Userdiagram::LEVEL_EDITOR;
        $userdiagram->status = Userdiagram::STATUS_ACCEPTED;
        $userdiagram->userId = $loggedUser->id;
        //store it in DB
        $d->userdiagramCreate($userdiagram);
        //delete invitation
        $d->invitationDelete($invitation->id);
        addMessage("Invitation accepted");
        redirect('../editor.php?diagramId=' . $diagram->id);
    } else {
        addError("Nope");
        redirect('../myDiagrams.php');
    }
}