Example #1
0
<?php

$base = "../../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
//uid, ruid, hash, message
if (!isset($_POST["ruid"]) && !isset($_POST["message"])) {
    add_return_data(0, 5, "ruid and message are must.");
}
if (!$_POST["ruid"] && !$_POST["message"]) {
    add_return_data(0, 6, "ruid and message can't be empty.");
}
$ruid = $_POST["ruid"];
$message = $_POST["message"];
$msg = new Message();
$retVal = $msg->addMessage($uid, $hash, $ruid, $message);
if ($retVal == 4 || $retVal == 3) {
    add_return_data(0, 7, "Receiver not found");
}
if ($retVal == 1) {
    add_return_data(1, 2, "Success sending message.");
}
add_return_data(0, 8, "Failure while sending.");
Example #2
0
<?php

$base = "../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
$noti = new Notification();
$data = $noti->getNotification($uid, $hash);
$returndata["data"] = $data;
add_return_data(1, 1, "Notifications Returned.");
Example #3
0
<?php

$base = "../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
//rating, itemId
if (!isset($_POST["rating"]) || !$_POST["rating"]) {
    add_return_data(0, 5, "Rating is a must.");
}
$rate = $_POST["rating"];
if (!isset($_POST["itemId"]) || !$_POST["itemId"]) {
    add_return_data(0, 6, "itemId is a must.");
}
$itemId = $_POST["itemId"];
$rating = new Rating();
if (!$rating->addRating($uid = $uid, $hash = $hash, $itemId = $itemId, $rate = $rate)) {
    add_return_data(0, 7, "Error while rating.");
}
add_return_data(1, 1, "Rating Added.");
Example #4
0
<?php

$base = "../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
//itemId, userId
if (!isset($_POST["itemId"]) || !$_POST["itemId"]) {
    add_return_data(0, 5, "itemId is a must.");
}
$itemId = $_POST["itemId"];
$lend = new Borrow();
if (!$lend->lendBook($uid = $uid, $hash = $hash, $itemId = $itemId)) {
    add_return_data(0, 7, "Accept Error.");
}
add_return_data(1, 1, "Book Lended.");
Example #5
0
<?php

$base = "../../";
require_once $base . "functions.php";
$returndata = array();
header('Content-type: text/html; charset=UTF-8');
// longitude, latitude
if (!isset($_POST["longitude"]) || !isset($_POST["latitude"])) {
    add_return_data(0, 2, "Longitude and Latitude needed.");
}
$longitude = -450;
$latitude = -450;
if (isset($_POST["longitude"]) && isset($_POST["latitude"])) {
    $longitude = $_POST["longitude"];
    $latitude = $_POST["latitude"];
}
$item = new Users();
$returndata["data"] = $item->getUsersByLocation($longitude, $latitude);
add_return_data(1, 1, "Success");
Example #6
0
<?php

$base = "../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
//itemId
if (!isset($_POST["itemId"]) || !$_POST["itemId"]) {
    add_return_data(0, 5, "itemId is a must.");
}
$itemId = $_POST["itemId"];
$return = new Borrow();
if (!$return->isBorrowedBy($uid = $uid, $itemId = $itemId)) {
    add_return_data(0, 6, "Uid haven't given this book to anyone");
}
if (!$return->returnBook($uid = $uid, $hash = $hash, $itemId = $itemId)) {
    add_return_data(0, 7, "Return Error.");
}
add_return_data(1, 1, "Book Returned.");
Example #7
0
if (!isset($_POST["itemId"]) || !$_POST["itemId"]) {
    add_return_data(0, 5, "itemId is a must.");
}
$itemId = $_POST["itemId"];
$message = "";
if (isset($_POST["message"])) {
    $message = $_POST["message"];
}
$borrow = new Borrow();
$user = new Items();
$ruid = $user->getUserId($itemId);
if ($borrow->isAlreadyBorrowed($itemId)) {
    add_return_data(0, 6, "Is Already Borrowed");
}
if ($ruid == -1 || $ruid == $uid) {
    add_return_data(0, 8, "Cannot borrow your own book");
}
if (!$borrow->borrowBook($uid = $uid, $hash = $hash, $itemId = $itemId, $message = $message)) {
    add_return_data(0, 7, "Borrow Error.");
}
$msg = new Message();
$ruid = $user->getUserId($itemId);
if ($ruid == -1) {
    add_return_data(1, 2, "Borrowed but cannot send message.");
}
$retVal = $msg->addMessage($uid, $hash, $ruid, $message);
if ($retVal != 1) {
    add_return_data(1, 3, "Borrowed but cannot send message");
}
add_return_data(1, 1, "Book Borrow Requested.");
Example #8
0
$longitude = $_POST["longitude"];
$latitude = $_POST["latitude"];
$expressType = "";
$itemIntroduction = "";
$itemImageSrc = "";
$address = "";
if (isset($_POST["address"])) {
    $address = $_POST["address"];
}
if (isset($_POST["expressType"])) {
    $expressType = $_POST["expressType"];
}
if (isset($_POST["itemIntroduction"])) {
    $itemIntroduction = $_POST["itemIntroduction"];
}
if (isset($_POST["itemImageSrc"])) {
    $itemImageSrc = $_POST["itemImageSrc"];
}
$arr = array("longitude" => $longitude, "latitude" => $latitude, "itemName" => $itemName, "money" => $money, "period" => $period, "expressType" => $expressType, "itemIntroduction" => $itemIntroduction, "itemImageSrc" => $itemImageSrc, "uid" => $uid, "address" => $address);
$item = new Item($data = $arr);
$iteId = $item->publish($uid, $hash);
if (!$iteId) {
    add_return_data(0, 7, "Error while updating.");
}
$returndata["data"] = array("itemId" => $iteId);
$iteImg = uploadPic("itemPic", $iteId, "itemImageSrc");
if ($item->updateItemImage($uid, $hash, $iteId, $iteImg)) {
    add_return_data(1, 1, "Success");
}
add_return_data(1, 2, "Success uploding data except Image");
Example #9
0
function render_404page()
{
    add_return_data(0, 1, "Page Not Found");
}
Example #10
0
<?php

$base = "../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
//cid, itemId, reply
if (!isset($_POST["reply"]) || !$_POST["reply"]) {
    add_return_data(0, 5, "Comment reply is a must.");
}
$reply = $_POST["reply"];
if (!isset($_POST["itemId"]) || !$_POST["itemId"]) {
    add_return_data(0, 6, "itemId is a must.");
}
$itemId = $_POST["itemId"];
if (!isset($_POST["cid"]) || !$_POST["cid"]) {
    add_return_data(0, 6, "cid is a must.");
}
$cid = $_POST["cid"];
$comment = new ReplyComment();
if (!$comment->addReply($uid = $uid, $hash = $hash, $itemId = $itemId, $cid = $cid, $reply = $reply)) {
    add_return_data(0, 7, "Error while replying to a comment.");
}
add_return_data(1, 1, "Replied to a comment");
Example #11
0
function checkCookieHash($uid, $hash)
{
    if (!checkCookies($uid, $hash)) {
        add_return_data(0, 4, "Uid, Hash Combination didn't match.");
    }
}
Example #12
0
<?php

$base = "../../";
require_once $base . "functions.php";
require_once $base . "loginCheck.php";
header('Content-type: text/html; charset=UTF-8');
$uid = getUid();
$hash = getCookieHash();
checkCookieHash($uid, $hash);
//comment, itemId
if (!isset($_POST["comment"]) || !$_POST["comment"]) {
    add_return_data(0, 5, "Comment is a must.");
}
$com = $_POST["comment"];
if (!isset($_POST["itemId"]) || !$_POST["itemId"]) {
    add_return_data(0, 6, "itemId is a must.");
}
$itemId = $_POST["itemId"];
$comment = new Comment();
if (!$comment->addComment($uid = $uid, $hash = $hash, $itemId = $itemId, $com = $com)) {
    add_return_data(0, 7, "Error while commenting.");
}
add_return_data(1, 1, "Commented");
Example #13
0
}
if (!isset($_POST["email"])) {
    add_return_data(0, 5, "E-mail required");
}
$email = $_POST["email"];
if (!$email) {
    add_return_data(0, 5, "E-mail required");
}
if (isset($_POST["contact"])) {
    $contact = $_POST['contact'];
}
if (isset($_POST["role"]) && $_POST["role"]) {
    $role = $_POST['role'];
}
$user = new User($uname);
if ($user->getuser()) {
    add_return_data(0, 2, "User already exists");
}
$data = array("uname" => $uname, "password" => $password, "gender" => $gender, "fname" => $fname, "email" => $email, "contact" => $contact, "role" => $role);
$useId = $user->insert($data);
$cookies = array("uid" => $useId, "hash" => getCookies($useId));
$returndata["cookies"] = $cookies;
if ($useId) {
    $picId = uploadPic("profilePic", $useId, "userFace");
    if ($picId) {
        if ($user->updateProfileImage($useId, $picId)) {
            add_return_data(1, 1, "User successfully created");
        }
    }
    add_return_data(1, 2, "User successfully created but picture cannot be added.");
}
Example #14
0
<?php

$base = "../../";
require_once $base . "users.php";
$returndata = array();
//uname, password
if (!isset($_POST['uname']) || !isset($_POST['password'])) {
    add_return_data(0, 2, "Both Username and Password need to be posted.");
} else {
    $uname = $_POST['uname'];
    $password = $_POST['password'];
    $user = new User($uname);
    if (!$user->checklogin($uname, $password)) {
        //Username password incorrect send that json.
        add_return_data(0, 3, "Incorrect username or password");
    } else {
        //Username and password is correct send json to say username password correct and send cookies
        $userdata = $user->get_user_data();
        $returndata["user"] = $userdata;
        $cookies = array("uid" => $user->get_userid(), "hash" => getCookies($user->get_userid()));
        $returndata["cookies"] = $cookies;
        add_return_data(1, 1, "Logged In!");
    }
}