From 6ca0c410f0a82815719ba87ea4c4fbb3d7fb0546 Mon Sep 17 00:00:00 2001 From: Koala Yeung Date: Fri, 7 Oct 2022 01:27:51 +0800 Subject: [PATCH] Crowd Assessment: Url for url generation * Use Url class for url generations. * Fix require_once path with __DIR__. --- .../crowdAssess_view_discuss_post.php | 13 ++++++- .../crowdAssess_view_discuss_postProcess.php | 38 +++++++++---------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/modules/Crowd Assessment/crowdAssess_view_discuss_post.php b/modules/Crowd Assessment/crowdAssess_view_discuss_post.php index fb00166d76..b806e950e9 100644 --- a/modules/Crowd Assessment/crowdAssess_view_discuss_post.php +++ b/modules/Crowd Assessment/crowdAssess_view_discuss_post.php @@ -18,6 +18,7 @@ */ use Gibbon\Forms\Form; +use Gibbon\Http\Url; //Module includes require_once __DIR__ . '/moduleFunctions.php'; @@ -70,7 +71,17 @@ } // FORM - $form = Form::create('crowdAssessment', $gibbon->session->get('absoluteURL').'/modules/'.$session->get('module')."/crowdAssess_view_discuss_postProcess.php?gibbonPlannerEntryID=$gibbonPlannerEntryID&gibbonPlannerEntryHomeworkID=$gibbonPlannerEntryHomeworkID&address=".$_GET['q']."&gibbonPersonID=$gibbonPersonID&replyTo=$replyTo"); + $form = Form::create( + 'crowdAssessment', + Url::fromModuleRoute('Crowd Assessment', 'crowdAssess_view_discuss_postProcess') + ->withQueryParams([ + 'gibbonPlannerEntryID' => $gibbonPlannerEntryID, + 'gibbonPlannerEntryHomeworkID' => $gibbonPlannerEntryHomeworkID, + 'address' => $_GET['q'], + 'gibbonPersonID' => $gibbonPersonID, + 'replyTo' => $replyTo, + ]) + ); $form->addHiddenValue('address', $gibbon->session->get('address')); diff --git a/modules/Crowd Assessment/crowdAssess_view_discuss_postProcess.php b/modules/Crowd Assessment/crowdAssess_view_discuss_postProcess.php index 29949eec4c..a0b10876fd 100644 --- a/modules/Crowd Assessment/crowdAssess_view_discuss_postProcess.php +++ b/modules/Crowd Assessment/crowdAssess_view_discuss_postProcess.php @@ -20,8 +20,9 @@ use Gibbon\Data\Validator; use Gibbon\Comms\NotificationSender; use Gibbon\Domain\System\SettingGateway; +use Gibbon\Http\Url; -require_once '../../gibbon.php'; +require_once __DIR__ . '/../../gibbon.php'; $_POST = $container->get(Validator::class)->sanitize($_POST, ['comment' => 'HTML']); @@ -32,17 +33,20 @@ $gibbonPlannerEntryHomeworkID = $_GET['gibbonPlannerEntryHomeworkID'] ?? ''; $gibbonPersonID = $_GET['gibbonPersonID'] ?? ''; -$URL = $session->get('absoluteURL').'/index.php?q=/modules/'.getModuleName($_GET['address'])."/crowdAssess_view_discuss.php&gibbonPlannerEntryID=$gibbonPlannerEntryID&gibbonPlannerEntryHomeworkID=$gibbonPlannerEntryHomeworkID&gibbonPersonID=$gibbonPersonID"; +$URL = Url::fromModuleRoute('Crowd Assessment', 'crowdAssess_view_discuss') + ->withQueryParams([ + 'gibbonPlannerEntryID' => $gibbonPlannerEntryID, + 'gibbonPlannerEntryHomeworkID' => $gibbonPlannerEntryHomeworkID, + 'gibbonPersonID' => $gibbonPersonID, + ]); if (isActionAccessible($guid, $connection2, '/modules/Crowd Assessment/crowdAssess_view_discuss_post.php') == false) { - $URL .= '&return=error0'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error0')); } else { //Proceed! //Check if gibbonPlannerEntryID, gibbonPlannerEntryHomeworkID, and gibbonPersonID specified if ($gibbonPlannerEntryID == '' or $gibbonPlannerEntryHomeworkID == '' or $gibbonPersonID == '') { - $URL .= '&return=error1'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error1')); } else { $and = " AND gibbonPlannerEntryID=$gibbonPlannerEntryID"; $sql = getLessons($guid, $connection2, $and); @@ -50,14 +54,12 @@ $result = $connection2->prepare($sql[1]); $result->execute($sql[0]); } catch (PDOException $e) { - $URL .= '&return=error2'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error2')); exit(); } if ($result->rowCount() != 1) { - $URL .= '&return=error1'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error1')); } else { $row = $result->fetch(); @@ -65,8 +67,7 @@ $role = getCARole($guid, $connection2, $row['gibbonCourseClassID']); if ($role == '' or empty($comment)) { - $URL .= '&return=error2'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error2')); } else { $sqlList = getStudents($guid, $connection2, $role, $row['gibbonCourseClassID'], $row['homeworkCrowdAssessOtherTeachersRead'], $row['homeworkCrowdAssessOtherParentsRead'], $row['homeworkCrowdAssessSubmitterParentsRead'], $row['homeworkCrowdAssessClassmatesParentsRead'], $row['homeworkCrowdAssessOtherStudentsRead'], $row['homeworkCrowdAssessClassmatesRead'], " AND gibbonPerson.gibbonPersonID=$gibbonPersonID"); @@ -75,14 +76,12 @@ $resultList = $connection2->prepare($sqlList[1]); $resultList->execute($sqlList[0]); } catch (PDOException $e) { - $URL .= '&return=erorr2'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error2')); exit(); } if ($resultList->rowCount() != 1) { - $URL .= '&return=error2'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error2')); } else { //INSERT $replyTo = !empty($_GET['replyTo']) ? $_GET['replyTo'] : null; @@ -94,11 +93,9 @@ $result = $connection2->prepare($sql); $result->execute($data); } catch (PDOException $e) { - $URL .= '&return=erorr2'; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('error2')); exit(); } - $hash = '#'.$replyTo; //Work out who we are replying too @@ -140,8 +137,7 @@ $notificationSender->sendNotifications(); - $URL .= "&return=success0$hash"; - header("Location: {$URL}"); + header('Location: ' . $URL->withReturn('success0')->withFragment($replyTo)); } } }