function executeChange($userID, $recordID, $newRecordStatus) { if ($newRecordStatus !== "1" && $newRecordStatus !== "2" && $newRecordStatus !== "3") { return "Invalid status!"; } $userDAO = new UserDAO(); $user = $userDAO->getUserByID($userID); $recordDAO = new RecordDAO(); $record = $recordDAO->getRecordByID($recordID); if ($record === null) { return "Could not find this record!"; } if ($record->getDisplayStatus() === $newRecordStatus) { return "Old status is equal to new status, don't need to change!"; } if ($user->getRole()->getRoleID() === "3") { if ($record->getUser()->getUserID() !== $userID) { return "You have no right to change group status!"; } if ($newStatus === "3") { return "You have no right to delete this record!"; } } if ($newRecordStatus !== "3") { $record->setDisplayStatus($newRecordStatus); $recordDAO->updateRecord($record); // Do not have updateRecord function } else { $recordDAO->deleteRecord($record); //Do not have this function } return true; }
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; }
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 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; }
function changeRecordStatus($adminID, $recordID, $displayStatus) { $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 record status!"; } $recordDAO = new RecordDAO(); $record = $recordDAO->getRecordByID($recordID); //need function if ($record->getDisplayStatus() === $displayStatus) { return "Same Status, no need to change it!"; } $record->setDisplayStatus($displayStatus); $recordDAO->updateRecord($record); //need function }
function displayRecord($user, $tpl) { $tpl->define(array("record" => "settings/record.html", "record_tr" => "settings/record_tr.html", "record_td" => "settings/record_td.html", "record_delete" => "settings/record_delete.html")); $roleID = $user->getRole()->getRoleID(); $recordDAO = new RecordDAO(); if ($roleID === "1" || $roleID === "2") { $records = $recordDAO->getAllRecords(); //do not have this function $tpl->parse("SETTINGS_RECORD_TD_DELETE", "record_delete"); } elseif ($roleID === "3") { $records = $recordDAO->getRecordsByUser($user); // Do not have this function $tpl->assign("SETTINGS_RECORD_TD_DELETE", ""); } if ($records === null) { $tpl->assign("SETTINGS_RECORD_TR", ""); } else { foreach ($records as $record) { $currentRecordStatus = $record->getDisplayStatus(); if ($currentRecordStatus == "1") { $tpl->assign("SETTINGS_RECORD_TD_CURR_NAME", "Activated"); $tpl->assign("SETTINGS_RECORD_TD_CHAN_STATUS", "2"); $tpl->assign("SETTINGS_RECORD_TD_CHAN_NAME", "Block"); } elseif ($currentRecordStatus == "2") { $tpl->assign("SETTINGS_RECORD_TD_CURR_NAME", "Blocked"); $tpl->assign("SETTINGS_RECORD_TD_CHAN_STATUS", "1"); $tpl->assign("SETTINGS_RECORD_TD_CHAN_NAME", "Activate"); } $tpl->assign("SETTINGS_RECORD_RECORDID", $record->getRecordID()); $tpl->parse("SETTINGS_RECORD_TD", "record_td"); $tpl->assign("SETTINGS_RECORD_TR_RECORDID", $record->getRecordID()); $tpl->assign("SETTINGS_RECORD_TR_CONTENT", htmlentities($record->getContent())); $tpl->assign("SETTINGS_RECORD_TR_TIME", $record->getTime()); $tpl->parse("SETTINGS_RECORD_TR", ".record_tr"); } } $tpl->parse("SETTINGS_RECORD", "record"); }
function displayIndex($userID) { $tpl = new FastTemplate("templates/"); $tpl->define(array("web_main" => "web_main.html", "web_header" => "web_header.html", "head_script" => "index/head_script.html", "user" => "index/user.html", "department" => "index/department.html", "list_item" => "index/list_item.html", "group" => "index/group.html", "comment" => "index/comment.html", "link" => "index/link.html", "image" => "index/image.html", "invitation" => "index/invitation.html", "group_option" => "index/group_option.html", "body" => "index/body.html", "web_nav" => "web_nav.html", "web_footer" => "web_footer.html")); $userDAO = new UserDAO(); $user = $userDAO->getUserByID($userID); //initial owner group $groupDAO = new GroupDAO(); $groups = $groupDAO->getGroupsByOwner($user); if ($groups === null) { $tpl->assign("INDEX_GROUP_OPTION", ""); } else { foreach ($groups as $ownerGroup) { $tpl->assign("INDEX_GROUP_OPTIONID", $ownerGroup->getGroupID()); $tpl->assign("INDEX_GROUP_OPTIONNAME", $ownerGroup->getGroupName()); $tpl->parse("INDEX_GROUP_OPTION", ".group_option"); } } //initial list item $gmDAO = new GroupMemberDAO(); $gms = $gmDAO->getGroupMembersByUser($user); if ($gms !== null) { $i = 1; $hasoneaccept = false; foreach ($gms as $gm) { if ($gm->getAcceptStatus() == "2") { continue; } $group = $gm->getGroup(); $tpl->assign("INDEX_LIST_ITEM_GROUPID", $group->getGroupID()); if ($i == 1) { $tpl->assign("INDEX_GROUP_HEADER", $group->getGroupName()); $tpl->assign("INDEX_LIST_ITEM_ACTIVE", "active"); } else { $tpl->assign("INDEX_LIST_ITEM_ACTIVE", ""); } $tpl->assign("INDEX_LIST_ITEM_SEQ", $i); $tpl->assign("INDEX_LIST_ITEM_GROUPNAME", $group->getGroupName()); $tpl->parse("INDEX_LIST_ITEM_LI", ".list_item"); $hasoneaccept = true; $i++; } if ($hasoneaccept == false) { $tpl->assign("INDEX_LIST_ITEM_LI", ""); $tpl->assign("INDEX_GROUP_HEADER", ""); } } else { $tpl->assign("INDEX_LIST_ITEM_LI", ""); $tpl->assign("INDEX_GROUP_HEADER", ""); } //initial comments $recordDAO = new RecordDAO(); if ($gms !== null) { $hasGMSflag = false; $i = 1; foreach ($gms as $gm) { if ($gm->getAcceptStatus() == "2") { continue; } $group = $gm->getGroup(); if ($i == 1) { $tpl->assign("INDEX_GROUP_HIDE", ""); } else { $tpl->assign("INDEX_GROUP_HIDE", "hide"); } $tpl->assign("INDEX_GROUP_SEQ", $i); $records = $recordDAO->getRecordsByGroup($group); if ($records === null) { $tpl->assign("INDEX_GROUP_COMMENT", ""); } else { $hasOneFlag = false; $tpl->clear("INDEX_GROUP_COMMENT"); foreach ($records as $rec) { if ($rec->getDisplayStatus() === "2") { continue; } $commentUser = $rec->getUser(); $tpl->assign("INDEX_GROUP_COMMENT_USERPHOTO", $commentUser->getPhotoURL()); $tpl->assign("INDEX_GROUP_COMMENT_USERNAME", $commentUser->getFirstName() . " " . $commentUser->getLastName()); $tpl->assign("INDEX_GROUP_COMMENT_TIME", $rec->getTime()); $type = $rec->getMessageType(); $con = $rec->getContent(); if ($type == "1") { $tpl->assign("INDEX_GROUP_COMMENT_CONTENT", htmlentities($con)); } else { if ($type == "2") { $tpl->assign("INDEX_CONTENT_IMGURL", $con); $tpl->parse("INDEX_GROUP_COMMENT_CONTENT", "image"); } else { if ($type == "3") { $tpl->assign("INDEX_GROUP_CONTENT_LINKURL", $con); $baseName = pathinfo($con, PATHINFO_BASENAME); $pos = strpos($baseName, "_"); $oriName = substr($baseName, $pos + 1); $tpl->assign("INDEX_GROUP_CONTENT_LINKNAME", htmlentities($oriName)); $tpl->parse("INDEX_GROUP_COMMENT_CONTENT", "link"); } else { if ($type == "4") { $tpl->assign("INDEX_GROUP_CONTENT_LINKURL", "http://" . rawurlencode($con)); $tpl->assign("INDEX_GROUP_CONTENT_LINKNAME", htmlentities($con)); $tpl->parse("INDEX_GROUP_COMMENT_CONTENT", "link"); } } } } $tpl->parse("INDEX_GROUP_COMMENT", ".comment"); $hasOneFlag = true; } if ($hasOneFlag == false) { $tpl->assign("INDEX_GROUP_COMMENT", ""); } } $tpl->parse("INDEX_GROUP", ".group"); $hasGMSflag = true; $i++; } if ($hasGMSflag == false) { $tpl->assign("INDEX_GROUP_COMMENT", ""); $tpl->parse("INDEX_GROUP", "group"); } } else { $tpl->assign("INDEX_GROUP_COMMENT", ""); $tpl->parse("INDEX_GROUP", "group"); } //initial department and user $result = findDepartAndUser(1, $userID); if (count($result) === 0) { $tpl->assign("INDEX_DEPART_USER", ""); } else { foreach ($result as $node) { if ($node["type"] == 1) { $tpl->assign("INDEX_DEPARTID", $node["id"]); $tpl->assign("INDEX_DEPART_NAME", $node["name"]); $tpl->parse("INDEX_DEPART_USER", ".department"); } elseif ($node["type"] == 2) { $tpl->assign("INDEX_USERID", $node["id"]); $tpl->assign("INDEX_USER_NAME", $node["name"]); $tpl->parse("INDEX_DEPART_USER", ".user"); } } } //initial annocement $flag = false; $gmArr = $gmDAO->getGroupMembersByUser($user); if ($gmArr !== null) { foreach ($gmArr as $gmPend) { if ($gmPend->getAcceptStatus() == "2") { $gmGroup = $gmPend->getGroup(); $gmOwner = $gmGroup->getOwner(); $tpl->assign("INDEX_INVITATION_OWNER", $gmOwner->getFirstName() . " " . $gmOwner->getLastName()); $tpl->assign("INDEX_INVITATION_GROUPNAME", $gmGroup->getGroupName()); $tpl->assign("INDEX_INVITATION_GROUPID", $gmGroup->getGroupID()); $tpl->parse("INDEX_INVITATION", ".invitation"); $flag = true; } } } if ($flag === false) { $tpl->assign("INDEX_INVITATION", ""); } $tpl->assign("TITLE", "Home"); $tpl->parse("WEB_HEADER", "web_header"); $tpl->parse("HEAD_SCRIPT", "head_script"); $tpl->parse("WEB_NAV", "web_nav"); $tpl->parse("BODY", ".body"); $tpl->parse("WEB_FOOTER", "web_footer"); $tpl->parse("MAIN", "web_main"); $tpl->FastPrint(); }