예제 #1
0
function sessionInit()
{
    $rtnObj = new rtnObj();
    $rtnObj->setStatus(-1);
    try {
        //if (isset($_SESSION['isLoggedIn'])){
        //if ($_SESSION['isLoggedIn'] == true){ //do i need to check if this session variable exists first?
        if (loggedIn()) {
            $conn = dbConnect();
            $params = array($_SESSION['UserID']);
            $query = $conn->prepare("SELECT *\n\t\t                    FROM Accounts\n\t\t                    WHERE UserID = ?");
            $query->execute($params);
            $getUser = $query->fetch(PDO::FETCH_ASSOC);
            if ($getUser != null) {
                //user found
                //$userObj = new userObj($getUser['UserName'],$getUser['FirstName'],$getUser['LastName'],$getUser['EmailAddress'],$getUser['PhoneNumber'],$getUser['UserId'],$getUser['RoleID'],$getUser['LanguagePreference']);
                //get notifications
                //$rtnObj->setUser($userObj);
                $rtnObj->setStatus(0);
                $rtnObj->setSuccessStatus('LoggedIn');
                $rtnObj->setMessage('LoggedIn');
                $rtnObj->sessionUserID = $_SESSION['UserID'];
            }
            /**/
            //echo "is true";
        }
        //}
        //echo "is set";
        //}
        echo json_encode($rtnObj);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
예제 #2
0
function addBook()
{
    //process is:
    //1) check if book already exists in database
    //  --> if no, add to Book table
    //2) Add to inventory
    global $slimApp;
    $conn = dbConnect();
    $request = $slimApp->request();
    $body = $request->getBody();
    $input = json_decode($body);
    $ISBN = $input->ISBN;
    $Title = $input->Title;
    $Subtitle = $input->Subtitle;
    $Author = $input->Author;
    $UserID = $_SESSION['UserID'];
    //this may need to be fixed (login not in place yet)
    $rtnObj = new rtnObj();
    $checkQry = $conn->prepare("SELECT BookID FROM Book WHERE ISBN = :ISBN");
    $checkQry->bindParam(":ISBN", $ISBN, PDO::PARAM_STR);
    $checkQry->execute();
    $dataObj = $checkQry->fetch(PDO::FETCH_ASSOC);
    if ($dataObj == false) {
        //Add book to database
        createSpineImage($ISBN, $Title, $Author);
        $Image_Spine = $ISBN . ".png";
        $Image_Cover = "cover1.jpg";
        $query = $conn->prepare("INSERT INTO Book \n\t\t\t\t\t\t\t\t\t\t(Title, Subtitle, Author, ISBN, Image_Spine, Image_Cover)\n\t\t\t\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t\t\t\t\t(:Title ,:Subtitle ,:Author, :ISBN, :Image_Spine, :Image_Cover)");
        $query->bindParam(":Title", $Title, PDO::PARAM_STR);
        $query->bindParam(":Subtitle", $Subtitle, PDO::PARAM_STR);
        $query->bindParam(":Author", $Author, PDO::PARAM_STR);
        $query->bindParam(":ISBN", $ISBN, PDO::PARAM_STR);
        $query->bindParam(":Image_Spine", $Image_Spine, PDO::PARAM_STR);
        $query->bindParam(":Image_Cover", $Image_Cover, PDO::PARAM_STR);
        $query->execute();
        $BookID = $conn->lastInsertId();
        $rtnObj->setSuccessStatus($BookID);
        $rtnObj->setMessage('Added to database.');
    } else {
        $BookID = $dataObj['BookID'];
        $rtnObj->setMessage('Book already existed in database. Added to inventory');
    }
    //add to inventory
    $inventoryQry = $conn->prepare("INSERT INTO Inventory \n\t\t\t\t\t\t\t\t\t\t(BookID, OwnerID, SpecialNotes)\n\t\t\t\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t\t\t\t\t(:BookID ,:OwnerID ,:SpecialNotes)");
    //$BookID = 1; //test
    $OwnerID = $_SESSION['UserID'];
    $SpecialNotes = "";
    $inventoryQry->bindParam(":BookID", $BookID, PDO::PARAM_INT);
    $inventoryQry->bindParam(":OwnerID", $OwnerID, PDO::PARAM_INT);
    $inventoryQry->bindParam(":SpecialNotes", $SpecialNotes, PDO::PARAM_STR);
    $inventoryQry->execute();
    //return the book so it can be added to the shelf
    $params = array($BookID);
    $query = $conn->prepare("SELECT *\n\t\t\t\t\t\t\t\t\tFROM Book\n\t\t\t\t\t\t\t\t\tWHERE BookID = ?");
    $query->execute($params);
    $dataObj = $query->fetch(PDO::FETCH_ASSOC);
    $rtnObj->setStatus(0);
    $rtnObj->data = $dataObj;
    echo json_encode($rtnObj);
}