Skip to content

Commit

Permalink
update activity settings
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharles committed Mar 14, 2023
1 parent 9ff3855 commit aeef05f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 30 deletions.
71 changes: 48 additions & 23 deletions src/Api/updatePortfolioActivitySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
$doenetId = mysqli_real_escape_string($conn, $_POST['doenetId']);
$imagePath = mysqli_real_escape_string($conn, $_POST['imagePath']);
$public = mysqli_real_escape_string($conn, $_POST['public']);
$isPublic = '0';
if ($public) {
$isPublic = '1';
}
$learningOutcomes = mysqli_real_escape_string(
$conn,
$_POST['learningOutcomes']
Expand Down Expand Up @@ -62,7 +66,6 @@
";
$result = $conn->query($sql);

$sqlresp = $sql;
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$portfolioCourseId = $row['courseId'];
Expand Down Expand Up @@ -117,11 +120,6 @@
$next = $row['sortOrder'] ?: '';
$sortOrder = SortOrder\getSortOrder($prev, $next);

$isPublic = '0';
if ($public) {
$isPublic = '1';
}

$sql = "
INSERT INTO course_content
(type,courseId,doenetId,parentDoenetId,label,creationDate,isPublic,
Expand All @@ -132,31 +130,58 @@
";
$conn->query($sql);
} else {
//Test if we are updating content or it's a hacker
// $sql = "
// SELECT doenetId
// FROM next_doenetId
// WHERE doenetId = '$doenetId'
// AND userId = '$userId'
// ";
// $result = $conn->query($sql);

// if ($result->num_rows > 0) {
//Test if the user has permission to update
$sql = "
SELECT courseId
FROM course_content
WHERE doenetId = '$doenetId'
";
$result = $conn->query($sql);
$courseId = '';

if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$courseId = $row['courseId'];
$permissions = permissionsAndSettingsForOneCourseFunction(
$conn,
$userId,
$courseId
);
if ($permissions['canEditContent'] != '1') {
$success = false;
$message = 'You need permission to edit content.';
}
} else {
$success = false;
$message = "Error: doenetId doesn't match.";
}

if ($success) {
$sql = "
UPDATE course_content
SET label = '$label',
imagePath = '$imagePath',
isPublic = '$isPublic',
learningOutcomes = '$learningOutcomes'
WHERE doenetId = '$doenetId'
AND courseId = '$courseId'
";
$conn->query($sql);
}
}

//Remove from next_doenetId to keep table small
// $sql = "
// DELETE FROM next_doenetId
// WHERE doenetId = '$doenetId'
// AND userId = '$userId'
// ";
// $conn->query($sql);
$sql = "
DELETE FROM next_doenetId
WHERE doenetId = '$doenetId'
AND userId = '$userId'
";
$conn->query($sql);
}

$response_arr = [
'success' => $success,
'message' => $message,
'sqlresp' => $sqlresp,
];

// set response code - 200 OK
Expand Down
22 changes: 15 additions & 7 deletions src/Tools/_framework/Paths/PortfolioActivitySettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function action({ request, params }) {
export async function loader({ params }){
const response = await fetch(`/api/getPortfolioActivityData.php?doenetId=${params.doenetId}`);
const data = await response.json();
console.log("loader",data)
// console.log("loader",data)
return data.activityData;
}

Expand Down Expand Up @@ -89,13 +89,13 @@ const Td = styled.td`

export function PortfolioActivitySettings(){
let data = useLoaderData();
// console.log("DATA",data)
const navigate = useNavigate();

return <>
<Form id="portfolioActivitySettings" method="post">
<MainGrid>
<Slot1>
<div><h1>Add Activity</h1></div>
<div>{data.isNew ? <h1>Add Activity</h1> : <h1>Activity Settings</h1>}</div>
</Slot1>
<Slot2>
<Table>
Expand Down Expand Up @@ -126,10 +126,18 @@ export function PortfolioActivitySettings(){
</Table>
</Slot2>
<Slot3>
<SideBySide>
<Button alert value="Cancel" onClick={() => navigate(-1)}/>
<Button type="submit" value="Create" />
</SideBySide>

{data.isNew ? <SideBySide>
<Button alert value="Cancel" onClick={() => navigate(-1)}/>
<Button type="submit" value="Create" />
</SideBySide>
:
<SideBySide>
<Button alert value="Cancel" onClick={() => navigate(-1)}/>
<Button type="submit" value="Update" />
</SideBySide>
}

</Slot3>
</MainGrid>
</Form>
Expand Down

0 comments on commit aeef05f

Please sign in to comment.