Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}