Ejemplo n.º 1
0
function execEditGroup($userID, $groupID, $checkedUser)
{
    if (gettype($checkedUser) != "array") {
        return "Wrong type of group member!";
    }
    $checkedUser[] = $userID;
    $userDAO = new UserDAO();
    $user = $userDAO->getUserByID($userID);
    if (!isValidID($groupID)) {
        return "Invalid group ID!";
    }
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return "Group doesn't exist!";
    }
    if ($group->getOwner()->getUserID() !== $userID) {
        return "You are not the owner of this group!";
    }
    $gmDAO = new GroupMemberDAO();
    $gms = $gmDAO->getGroupMembersByGroup($group);
    foreach ($gms as $gm) {
        $alreadyUser = $gm->getUser();
        if (in_array($alreadyUser->getUserID(), $checkedUser)) {
            continue;
        }
        $gmDAO->deleteGroupMember($gm);
    }
    return true;
}
Ejemplo n.º 2
0
function verify()
{
    if (isset($_GET["groupid"]) && isset($_GET["accept"])) {
        $groupID = $_GET["groupid"];
        if (!isValidID($groupID)) {
            return;
        }
        $groupDAO = new GroupDAO();
        $group = $groupDAO->getGroupByID($groupID);
        if ($group === null) {
            return;
        }
        $userDAO = new UserDAO();
        $user = $userDAO->getUserByID($_SESSION["userID"]);
        $gmDAO = new GroupMemberDAO();
        $gm = $gmDAO->getGroupMember($group, $user);
        if ($gm === null) {
            return;
        }
        $status = $gm->getAcceptStatus();
        if ($status == "1") {
            return;
        }
        if ($_GET["accept"] == "1") {
            $gm->setAcceptStatus("1");
            $gmDAO->updateGroupMember($gm);
        } elseif ($_GET["accept"] == "3") {
            $gmDAO->deleteGroupMember($gm);
        }
    }
}
Ejemplo n.º 3
0
function uploadFile($userID, $groupID, $file)
{
    $userDAO = new UserDAO();
    $user = $userDAO->getUserByID($userID);
    if ($user->getRole()->getRoleID() == "4") {
        return "This user was forbidden to upload file!";
    }
    if (!isValidID($groupID)) {
        return "Group id is not valid!";
    }
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return "Can not find this group!";
    }
    if ($group->getActivateStatus() === "2") {
        return "Group is not activated!";
    }
    $groupMemberDAO = new GroupMemberDAO();
    $groupMember = $groupMemberDAO->getGroupMember($group, $user);
    if ($groupMember === null) {
        return "User didn't belong to this group!";
    }
    if (gettype($file["error"]) == "array") {
        return "Only accept one file!";
    }
    $res = isValidUploadFile($file["error"]);
    if ($res !== true) {
        return $res;
    }
    $fileType = -1;
    $res = isValidImage($file["name"]);
    if ($res === true) {
        $fileType = "2";
    }
    $res = isValidFile($file["name"]);
    if ($res === true) {
        $fileType = "3";
    }
    if ($fileType === -1) {
        return "Only accepts jpeg/jpg/gif/png/zip file!";
    }
    $record = new Record($group, $user, $fileType, "temp", "1");
    $recordDAO = new RecordDAO();
    $recordDAO->insertRecord($record);
    $fileDir = "upload/";
    $filePath = $fileDir . $record->getRecordID() . "_" . $file["name"];
    $record->setContent($filePath);
    $recordDAO->updateRecord($record);
    if (file_exists($filePath)) {
        unlink($filePath);
    }
    if (!move_uploaded_file($file['tmp_name'], $filePath)) {
        return "Fail to move file, please contact administrator!";
    }
    return true;
}
Ejemplo n.º 4
0
function postRecord($userID, $groupID, $messageType, $content)
{
    $userDAO = new UserDAO();
    $user = $userDAO->getUserByID($userID);
    if ($user->getRole()->getRoleID() == "4") {
        return "This user was forbidden to post!";
    }
    if (!isValidID($groupID)) {
        return "Group id is not valid!";
    }
    if (!isValidMessageType($messageType)) {
        return "Message type is not valid!";
    }
    if (gettype($content) != "string" || strlen($content) > 1000) {
        return "Wrong type content or exceed max length(1000)!";
    }
    if ($messageType == "4") {
        if (!preg_match("/^http:\\/\\//i", $content)) {
            return "Only accept http url!";
        }
        $content = substr($content, 7);
        if ($content === "") {
            return "Invalid url!";
        }
    }
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return "Can not find this group!";
    }
    if ($group->getActivateStatus() === "2") {
        return "Group is not activated!";
    }
    $groupMemberDAO = new GroupMemberDAO();
    $groupMember = $groupMemberDAO->getGroupMember($group, $user);
    if ($groupMember === null) {
        return "User didn't belong to this group!";
    }
    $record = new Record($group, $user, $messageType, $content, "1");
    $recordDAO = new RecordDAO();
    $recordDAO->insertRecord($record);
    return true;
}
function execAddToGroup($userID, $groupID, $adduserIDs)
{
    $userDAO = new UserDAO();
    $user = $userDAO->getUserByID($userID);
    if (!isValidID($groupID)) {
        return "Invalid group ID!";
    }
    if (gettype($adduserIDs) != "array") {
        return "Wrong type of user id!";
    }
    if (count($adduserIDs) === 0) {
        return "You have to choose users to add to this group!";
    }
    foreach ($adduserIDs as $adduserID) {
        if (!isValidID($adduserID)) {
            return "Invalid user ID!";
        }
    }
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return "Group doesn't exist!";
    }
    if ($group->getOwner()->getUserID() !== $userID) {
        return "You are not the owner of this group!";
    }
    $gmDAO = new GroupMemberDAO();
    foreach ($adduserIDs as $auID) {
        $aduser = $userDAO->getUserByID($auID);
        if ($aduser === null) {
            continue;
        }
        $gm = $gmDAO->getGroupMember($group, $aduser);
        if ($gm !== null) {
            continue;
        }
        $gm = new GroupMember($group, $aduser, "2");
        $gmDAO->insertGroupMember($gm);
    }
    return true;
}
function executeChange($userID, $groupID, $newStatus)
{
    $newStatus = $newStatus;
    if ($newStatus !== "1" && $newStatus !== "2" && $newStatus !== "3") {
        return "Invalid status!";
    }
    $userDAO = new UserDAO();
    $user = $userDAO->getUserByID($userID);
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return "Could not find this group!";
    }
    if ($group->getActivateStatus() === $newStatus) {
        return "Old status is equal to new status, don't need to change!";
    }
    if ($user->getRole()->getRoleID() === "3") {
        if ($group->getOwner()->getUserID() !== $userID) {
            return "You have no right to change group status!";
        }
        if ($newStatus === "3") {
            return "You have no right to delete this group!";
        }
    }
    if ($newStatus !== "3") {
        $group->setActivateStatus($newStatus);
        $groupDAO->updateGroup($group);
    } else {
        //delete records
        $recordDAO = new RecordDAO();
        $recordDAO->deleteRecordsByGroup($group);
        //delete groupmember
        $gmDAO = new GroupMemberDAO();
        $gmDAO->deleteGroupMembersByGroup($group);
        //delete group
        $groupDAO->deleteGroup($group);
    }
    return true;
}
Ejemplo n.º 7
0
function changeGroupStatus($adminID, $groupID, $activateStatus)
{
    $userDAO = new UserDAO();
    $admin = $userDAO->getUserByID($adminID);
    if ($admin->getRole()->getRoleID !== 1 || $admin->getRole()->getRoleID !== 2) {
        return "You do not have the right to change group status!";
    }
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    //need function
    if ($group->getActivateStatus() === $actuvateStatus) {
        return "Same Status, no need to change it!";
    }
    $group->setActivateStatus($activateStatis);
    $groupDAO->updateGroup($group);
    //need function
}
Ejemplo n.º 8
0
require_once "libraries/head.php";
require_once "libraries/class.FastTemplate.php";
if (!isLogin()) {
    exit;
}
$tpl = new FastTemplate("templates/");
$tpl->define(array("group_checked_member" => "index/group_checked_member.html"));
if (isset($_POST["groupid"])) {
    $groupID = $_POST["groupid"];
    if (!isValidID($groupID)) {
        return;
    }
    $userID = $_SESSION["userID"];
    $groupDAO = new GroupDAO();
    $group = $groupDAO->getGroupByID($groupID);
    if ($group === null) {
        return;
    }
    $gmDAO = new GroupMemberDAO();
    $gms = $gmDAO->getGroupMembersByGroup($group);
    $flag = false;
    foreach ($gms as $gm) {
        if ($gm->getUser()->getUserID() === $userID) {
            continue;
        }
        $tpl->assign("INDEX_GROUP_CHECKED_USERID", $gm->getUser()->getUserID());
        $tpl->assign("INDEX_GROUP_CHECKED_USERNAME", $gm->getUser()->getFirstName() . " " . $gm->getUser()->getLastName());
        $tpl->parse("MAIN", ".group_checked_member");
        $flag = true;
    }