Example #1
0
<?php

include "../util/session.php";
include_once "../util/mysql.php";
include "../mail/send.php";
include "../util/status.php";
include "../util/constants.php";
$dao = new DAO(false);
$user_id = $_POST["user_id"];
$group_id = $_POST["group_id"];
$member = DataObject::select_one($dao, "user", array("user_id", "user_email", "user_name"), array("user_id" => $user_id));
$group = DataObject::select_one($dao, "user_group", array("group_id", "group_name"), array("group_id" => $group_id));
if ($group != NULL) {
    if ($member != NULL) {
        if (NULL == DataObject::select_one($dao, "grouping_request", array("gr_id"), array("group_id" => $group_id, "user_id" => $user_id))) {
            $body = "<p>Hello " . $member->user_name . ",</p>\n\t\t\t\t<p>" . $user->user_name . " has asked you to join the group \"" . $group->group_name . "\".\n\t\t\t\t\tIf you would like to join, please click on this link: \n\t\t\t\t\t<a href=\"" . $SITE_URL . "script/grouping/confirm.php?group_id=" . $group_id . "\">Click here to join</a>.</p>\n\t\t\t\t<p>Best Wishes,<br>The Unify Team</p>";
            $request = DataObject::create($dao, "grouping_request", array("group_id" => $group_id, "user_id" => $user_id));
            $request->commit();
            //Put the request in the database. So long as this is here, the user can accept (only when logged in)
            mail_message($member->user_email, "Group Join Request", $body);
            echo Status::json(0, "Request sent :)");
        } else {
            echo Status::json(3, "Member has already been requested to join");
        }
    } else {
        echo Status::json(1, "Member not found");
    }
} else {
    echo Status::json(2, "Group not found");
}
Example #2
0
<?php

//Delete a comment from a post
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
$dao = new DAO(false);
if (isset($_GET["comment_id"])) {
    $comment_id = $_GET["comment_id"];
    $comment = DataObject::select_one($dao, "comment", array("comment_id"), array("comment_id" => $comment_id, "user_id" => $user->user_id));
    $success = $comment->delete();
    if ($success) {
        echo Status::json(0, "Comment deleted");
    } else {
        echo Status::json(1, "Comment could not be deleted from database");
    }
} else {
    echo Status::json(2, "No comment id");
}
Example #3
0
    if ($post_vote) {
        echo Status::json(1, "User has already voted");
    } else {
        $post = DataObject::select_one($dao, "post", array("post_id", "post_rating_up", "post_rating_dn"), array("post_id" => $post_id));
        if ($post) {
            if ($direction == "u") {
                $post->post_rating_up++;
            } else {
                $post->post_rating_dn++;
            }
            if ($post->commit()) {
                $post_vote = DataObject::create($dao, "post_vote", array("user_id" => $user->user_id, "post_id" => $post_id));
                if ($post_vote) {
                    if ($post_vote->commit()) {
                        echo Status::json(0, "Vote added");
                    } else {
                        echo Status::json(2, "Failed to prevent future votes");
                    }
                } else {
                    echo Status::json(3, "Failed to insert post_vote");
                }
            } else {
                echo Status::json(4, "Failed to commit change post rating");
            }
        } else {
            echo Status::json(5, "Failed to select post");
        }
    }
} else {
    echo Status::json(6, "d or post_id not set");
}
Example #4
0
<?php

//Determine the status of a connection: requested/connected/non existant
include "../util/session.php";
include "../util/session_var.php";
include_once "../util/mysql.php";
include_once "../util/status.php";
$dao = new DAO(false);
$connection = array("user_id1" => $user->user_id, "user_id2" => $selected_user->user_id);
$connection_rev = array("user_id2" => $user->user_id, "user_id1" => $selected_user->user_id);
//Has it been requested?
$request = DataObject::select_one($dao, "friend_request", array("req_id"), $connection);
if ($request == NULL) {
    //Check if they are friends
    $friendship = DataObject::select_one($dao, "connection", array("connection_id"), $connection_rev);
    if ($friendship != NULL) {
        echo Status::json(0, "Unification complete: <a href=\"javascript:;\" onclick=\"location.reload()\">refresh page?</a>");
    } else {
        echo Status::json(1, "Unification failed!");
    }
} else {
    echo Status::json(1, "Unification requested");
}
Example #5
0
    $group_id = $_POST["group_id"];
}
if (isset($_POST["post_content"]) && trim($_POST["post_content"]) != "") {
    $post_content = $_POST["post_content"];
    $post_time = date("Y-m-d H:i:s", time() + 3600);
    $post = DataObject::create($dao, "post", array("user_id" => $user->user_id, "group_id" => $group_id, "post_content" => $post_content, "post_time" => $post_time));
    if ($post) {
        $success = $post->commit();
        if ($success) {
            //Notify the group of students
            if ($group_id != -1) {
                $notification_users = DataObject::select_all($dao, "grouping", array("grouping_id", "user_id"), array("group_id" => $group_id));
                $notification_title = "New post in your group.";
                $notification_message = "{$user->user_name} has posted in your group.";
                $notification_link = "post/" . $post->get_primary_id();
                foreach ($notification_users as $notification_user) {
                    if ($notification_user->user_id != $user->user_id) {
                        echo notify($dao, $notification_user->user_id, $notification_title, $notification_message, $notification_link);
                    }
                }
            }
            echo Status::json(0, "Added post");
        } else {
            echo Status::json(1, "Failed to add post");
        }
    } else {
        echo Status::json(2, "Failed to create post");
    }
} else {
    echo Status::json(3, "No post content");
}
Example #6
0
<?php

//Delete a notification
include_once "../util/session.php";
include_once "../util/status.php";
include_once "../util/mysql.php";
$dao = new DAO(false);
$notification = DataObject::select_one($dao, "notification", array("notif_id"), array("user_id" => $user->user_id, "notif_id" => $_POST["notif_id"]));
if ($notification != NULL) {
    if ($notification->delete()) {
        echo Status::json(0, "Notification deleted");
    } else {
        echo Status::json(1, "Could not delete notification");
    }
} else {
    echo Status::json(2, "Could not find notification");
}
Example #7
0
<?php

//Unhide a post that has been hidden
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
$dao = new DAO(false);
if (isset($_GET["post_id"])) {
    $post_id = $dao->escape($_GET["post_id"]);
    $hidden_post = DataObject::select_one($dao, "hidden_post", array("hide_id"), array("post_id" => $post_id, "user_id" => $user->user_id));
    if ($hidden_post) {
        $result = $hidden_post->delete();
        if ($result) {
            echo Status::json(0, "Post unhidden");
        } else {
            echo Status::json(1, "Post could not be unhidden");
        }
    } else {
        echo Status::json(2, "Post not hidden");
    }
} else {
    echo Status::json(3, "No post id");
}
Example #8
0
<?php

//Add a comment to a post on a cohort/user's feed
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
include "../notification/add.php";
$dao = new DAO(false);
$post_id = $_POST["post_id"];
$comment_content = $_POST["comment_content"];
if ($comment_content != "") {
    $comment = DataObject::create($dao, "comment", array("user_id" => $user->user_id, "post_id" => $post_id, "comment_content" => $comment_content, "comment_time" => date("Y-m-d H:i:s", time() + 3600)));
    if ($comment->commit()) {
        //Comment has been added, notifier the orignal poster
        //Find the original poster
        $post = DataObject::select_one($dao, "post", array("post_id", "user_id"), array("post_id" => $post_id));
        if ($post->user_id != $user->user_id) {
            $notification_user = $post->user_id;
            $notification_title = "New comment on your post";
            $notification_message = "{$user->user_name} has commented on one of your posts.";
            $notification_link = "post/" . $post->post_id;
            notify($dao, $notification_user, $notification_title, $notification_message, $notification_link);
        }
        echo Status::json(0, "Comment added");
    } else {
        echo Status::json(2, "Comment could not be added");
    }
} else {
    echo Status::json(1, "No comment content");
}
Example #9
0
            $lng2 = $my_lng;
            $lat1 = $row["lat"];
            $lat2 = $my_lat;
            $dlng = $lng1 - $lng2;
            $distance = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($dlng));
            $distance = acos($distance);
            $distance = rad2deg($distance);
            $distance = $distance * 60 * 1.1515 * 1.609344;
            $threshold = 0.01 + 0.01;
            //20m!
            if ($distance < $threshold) {
                $new_connection = DataObject::create($dao, "connection", $connection_properties);
                $new_connection->commit();
                echo Status::json(0, "You are now unified!");
            } else {
                echo Status::json(3, "You were not close enough");
            }
            $query = "DELETE FROM friend_request WHERE req_id=\"{$req_id}\";";
            //Whether successful or not
            $dao->myquery($query);
        } else {
            $query = "INSERT INTO friend_request VALUES(NULL,\"{$user->user_id}\",\"{$selected_user->user_id}\",\"{$my_lat}\",\"{$my_lng}\");";
            $dao->myquery($query);
            echo Status::json(0, "Friend request made");
        }
    } else {
        echo Status::json(1, "You are already unified!");
    }
} else {
    echo Status::json(2, "Request for unification already exists!");
}
Example #10
0
$dao = new DAO(false);
if (isset($_GET["post_id"])) {
    $post_id = $_GET["post_id"];
    $post = DataObject::select_one($dao, "post", array("post_id", "user_id"), array("post_id" => $post_id));
    if ($post) {
        if ($user->user_id == $post->user_id) {
            //User's own post, so delete it
            if ($post->delete()) {
                echo Status::json(0, "Post deleted");
            } else {
                echo Status::json(5, "Failed to delete post");
            }
        } else {
            //Not the user's own post, so hide it from them
            $hidden_post = DataObject::create($dao, "hidden_post", array("user_id" => $user->user_id, "post_id" => $post_id));
            if ($hidden_post) {
                if ($hidden_post->commit()) {
                    echo Status::json(0, "Post hidden");
                } else {
                    echo Status::json(1, "Failed to commit hidden_post");
                }
            } else {
                echo Status::json(2, "Failed to create hidden_post");
            }
        }
    } else {
        echo Status::json(3, "Failed to select post");
    }
} else {
    echo Status::json(4, "post_id not set");
}
Example #11
0
<?php

//Send a message in chat
include "../util/session.php";
include_once "../util/mysql.php";
include "../util/status.php";
$dao = new DAO();
$user_id = $_POST["user_id"];
$msg_content = trim($_POST["msg_content"], chr(0xc2) . chr(0xa0) . chr(0x20));
$msg_content = trim($msg_content);
if ($msg_content != "") {
    $chat_msg = DataObject::create($dao, "chat_msg", array("user_id1" => $user->user_id, "user_id2" => $user_id, "msg_content" => $msg_content));
    $chat_msg->commit();
    echo Status::json(0, "Message added");
    // {code:0,message:"message added"}
} else {
    echo Status::json(1, "No message content");
}