Skip to content
72 changes: 29 additions & 43 deletions modules/Data Updater/data_family.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@
*/

use Gibbon\Forms\Form;
use Gibbon\Domain\User\FamilyGateway;
use Gibbon\Forms\DatabaseFormFactory;
use Gibbon\Domain\DataUpdater\FamilyUpdateGateway;

//Module includes
// Module includes
require_once __DIR__ . '/moduleFunctions.php';

if (isActionAccessible($guid, $connection2, '/modules/Data Updater/data_family.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
//Get action with highest precendence
// Get action with highest precendence
$highestAction = getHighestGroupedAction($guid, $_GET['q'], $connection2);
if ($highestAction == false) {
$page->addError(__('The highest grouped action cannot be determined.'));
} else {
//Proceed!
// Proceed!
$page->breadcrumbs->add(__('Update Family Data'));

if ($highestAction == 'Update Personal Data_any') {
Expand All @@ -47,7 +49,7 @@
echo '</p>';
}

$customResponces = array();
$customResponces = [];
$error3 = __('Your request was successful, but some data was not properly saved. An administrator will process your request as soon as possible. You will not see the updated data in the system until it has been processed.');
if ($session->get('organisationDBAEmail') != '' and $session->get('organisationDBAName') != '') {
$error3 .= ' '.sprintf(__('Please contact %1$s if you have any questions.'), "<a href='mailto:".$session->get('organisationDBAEmail')."'>".$session->get('organisationDBAName').'</a>');
Expand All @@ -67,21 +69,20 @@
echo '</h2>';

$gibbonFamilyID = $_GET['gibbonFamilyID'] ?? null;
$familyGateway = $container->get(FamilyGateway::class);

$form = Form::create('selectFamily', $session->get('absoluteURL').'/index.php', 'get');
$form->addHiddenValue('q', '/modules/'.$session->get('module').'/data_family.php');

if ($highestAction == 'Update Family Data_any') {
$data = array();
$sql = "SELECT gibbonFamily.gibbonFamilyID as value, name FROM gibbonFamily ORDER BY name";
$results = $familyGateway->selectAllFamiliesIDAndName();
} else {
$data = array('gibbonPersonID' => $session->get('gibbonPersonID'));
$sql = "SELECT gibbonFamily.gibbonFamilyID as value, name FROM gibbonFamily JOIN gibbonFamilyAdult ON (gibbonFamilyAdult.gibbonFamilyID=gibbonFamily.gibbonFamilyID) WHERE gibbonPersonID=:gibbonPersonID AND childDataAccess='Y' ORDER BY name";
$results = $familyGateway->selectFamilyIDAndNameByAdultID($session->get('gibbonPersonID'));
}
$row = $form->addRow();
$row->addLabel('gibbonFamilyID', __('Family'));
$row->addSearchSelect('gibbonFamilyID')
->fromQuery($pdo, $sql, $data)
$row->addSelect('gibbonFamilyID')
->fromResults($results)
->required()
->selected($gibbonFamilyID)
->placeholder();
Expand All @@ -96,68 +97,53 @@
echo __('Update Data');
echo '</h2>';

//Check access to person
// Check access to person
if ($highestAction == 'Update Family Data_any') {

$dataCheck = array('gibbonFamilyID' => $gibbonFamilyID);
$sqlCheck = 'SELECT name, gibbonFamily.gibbonFamilyID FROM gibbonFamily WHERE gibbonFamilyID=:gibbonFamilyID';
$resultCheck = $connection2->prepare($sqlCheck);
$resultCheck->execute($dataCheck);
$resultCheck = $familyGateway->getByID($gibbonFamilyID, ['name', 'gibbonFamilyID']);
} else {
try {
$dataCheck = array('gibbonFamilyID' => $gibbonFamilyID, 'gibbonPersonID' => $session->get('gibbonPersonID'));
$sqlCheck = "SELECT name, gibbonFamily.gibbonFamilyID FROM gibbonFamily JOIN gibbonFamilyAdult ON (gibbonFamilyAdult.gibbonFamilyID=gibbonFamily.gibbonFamilyID) WHERE gibbonPersonID=:gibbonPersonID AND childDataAccess='Y' AND gibbonFamily.gibbonFamilyID=:gibbonFamilyID";
$resultCheck = $connection2->prepare($sqlCheck);
$resultCheck->execute($dataCheck);
} catch (PDOException $e) {
}
$resultCheck = $familyGateway->selectFamilyIDByAdultID($gibbonFamilyID, $session->get('gibbonPersonID'));
}

if ($resultCheck->rowCount() != 1) {
if (empty($resultCheck)) {
$page->addError(__('The selected record does not exist, or you do not have access to it.'));
} else {
//Check if there is already a pending form for this user
// Check if there is already a pending form for this family
$existing = false;
$proceed = false;
$values = [];

$result = $container->get(FamilyUpdateGateway::class)->selectBy(['gibbonFamilyID' => $gibbonFamilyID, 'gibbonPersonIDUpdater' => $session->get('gibbonPersonID'), 'status' => 'Pending']);

$data = array('gibbonFamilyID' => $gibbonFamilyID, 'gibbonPersonIDUpdater' => $session->get('gibbonPersonID'));
$sql = "SELECT * FROM gibbonFamilyUpdate WHERE gibbonFamilyID=:gibbonFamilyID AND gibbonPersonIDUpdater=:gibbonPersonIDUpdater AND status='Pending'";
$result = $connection2->prepare($sql);
$result->execute($data);
$pendingUpdates = $result->fetchAll();

if ($result->rowCount() > 1) {
if (count($pendingUpdates) > 1) {
$page->addError(__('Your request failed due to a database error.'));
} elseif ($result->rowCount() == 1) {
} elseif (count($pendingUpdates) == 1) {
$existing = true;
echo "<div class='warning'>";
echo __('You have already submitted a form, which is awaiting processing by an administrator. If you wish to make changes, please edit the data below, but remember your data will not appear in the system until it has been processed.');
echo '</div>';
$proceed = true;
$values = $pendingUpdates[0];
} else {
//Get user's data

$data = array('gibbonFamilyID' => $gibbonFamilyID);
$sql = 'SELECT * FROM gibbonFamily WHERE gibbonFamilyID=:gibbonFamilyID';
$result = $connection2->prepare($sql);
$result->execute($data);
if ($result->rowCount() != 1) {
// Get family's data
$result = $familyGateway->getByID($gibbonFamilyID);
if (empty($result)) {
$page->addError(__('The specified record cannot be found.'));
} else {
$proceed = true;
$values = $result;
}
}

if ($proceed == true) {
//Let's go!
$values = $result->fetch();

$required = ($highestAction != 'Update Family Data_any');

$form = Form::create('updateFamily', $session->get('absoluteURL').'/modules/'.$session->get('module').'/data_familyProcess.php?gibbonFamilyID='.$gibbonFamilyID);
$form->setFactory(DatabaseFormFactory::create($pdo));

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('existing', isset($values['gibbonFamilyUpdateID'])? $values['gibbonFamilyUpdateID'] : 'N');
$form->addHiddenValue('existing', isset($values['gibbonFamilyUpdateID']) ? $values['gibbonFamilyUpdateID'] : 'N');

$row = $form->addRow();
$row->addLabel('nameAddress', __('Address Name'))->description(__('Formal name to address parents with.'));
Expand Down Expand Up @@ -194,4 +180,4 @@
}
}
}
}
}
21 changes: 6 additions & 15 deletions modules/Data Updater/data_familyProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Comms\NotificationEvent;
use Gibbon\Data\Validator;
use Gibbon\Comms\NotificationEvent;
use Gibbon\Domain\User\FamilyGateway;

require_once '../../gibbon.php';

Expand Down Expand Up @@ -49,27 +50,17 @@
//Check access to person
if ($highestAction == 'Update Family Data_any') {
$URLSuccess = $session->get('absoluteURL').'/index.php?q=/modules/Data Updater/data_family.php&gibbonFamilyID='.$gibbonFamilyID;


$dataCheck = array('gibbonFamilyID' => $gibbonFamilyID);
$sqlCheck = 'SELECT gibbonFamily.* FROM gibbonFamily WHERE gibbonFamilyID=:gibbonFamilyID';
$resultCheck = $connection2->prepare($sqlCheck);
$resultCheck->execute($dataCheck);
$resultCheck = $container->get(FamilyGateway::class)->getByID($gibbonFamilyID);
} else {
$URLSuccess = $session->get('absoluteURL').'/index.php?q=/modules/Data Updater/data_updates.php&gibbonFamilyID='.$gibbonFamilyID;


$dataCheck = array('gibbonFamilyID' => $gibbonFamilyID, 'gibbonPersonID' => $session->get('gibbonPersonID'));
$sqlCheck = "SELECT gibbonFamily.* FROM gibbonFamily JOIN gibbonFamilyAdult ON (gibbonFamilyAdult.gibbonFamilyID=gibbonFamily.gibbonFamilyID) WHERE gibbonPersonID=:gibbonPersonID AND childDataAccess='Y' AND gibbonFamily.gibbonFamilyID=:gibbonFamilyID";
$resultCheck = $connection2->prepare($sqlCheck);
$resultCheck->execute($dataCheck);
$resultCheck = $container->get(FamilyGateway::class)->selectFamilyIDByAdultID($gibbonFamilyID, $session->get('gibbonPersonID'))->fetchAll();
}

if ($resultCheck->rowCount() != 1) {
if (empty($resultCheck)) {
$URL .= '&return=warning';
header("Location: {$URL}");
} else {
$values = $resultCheck->fetch();
$values = $resultCheck;

//Proceed!
$data = [
Expand Down
14 changes: 5 additions & 9 deletions modules/Data Updater/data_family_manage_delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

use Gibbon\Forms\Prefab\DeleteForm;
use Gibbon\Domain\DataUpdater\FamilyUpdateGateway;

//Module includes
require_once __DIR__ . '/moduleFunctions.php';
Expand All @@ -34,17 +35,12 @@
if ($gibbonFamilyUpdateID == '') {
$page->addError(__('You have not specified one or more required parameters.'));
} else {

$data = array('gibbonFamilyUpdateID' => $gibbonFamilyUpdateID);
$sql = 'SELECT * FROM gibbonFamilyUpdate WHERE gibbonFamilyUpdateID=:gibbonFamilyUpdateID';
$result = $connection2->prepare($sql);
$result->execute($data);

if ($result->rowCount() != 1) {
$result = $container->get(FamilyUpdateGateway::class)->getByID($gibbonFamilyUpdateID);

if (empty($result)) {
$page->addError(__('The selected record does not exist, or you do not have access to it.'));
} else {
//Let's go!

// Let's go!
$form = DeleteForm::createForm($session->get('absoluteURL').'/modules/'.$session->get('module')."/data_family_manage_deleteProcess.php");
$form->addHiddenValue('gibbonFamilyUpdateID', $gibbonFamilyUpdateID);
echo $form->getOutput();
Expand Down
38 changes: 12 additions & 26 deletions modules/Data Updater/data_family_manage_deleteProcess.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php

use Gibbon\Domain\DataUpdater\FamilyUpdateGateway;
/*
Gibbon: the flexible, open school platform
Founded by Ross Parker at ICHK Secondary. Built by Ross Parker, Sandra Kuipers and the Gibbon community (https://gibbonedu.org/about/)
Expand Down Expand Up @@ -31,40 +33,24 @@
$URL .= '&return=error0';
header("Location: {$URL}");
} else {
//Proceed!
// Proceed!
$partialFail = false;

if ($gibbonFamilyUpdateID == '') {
$URL .= '&return=error1';
header("Location: {$URL}");
} else {
try {
$data = array('gibbonFamilyUpdateID' => $gibbonFamilyUpdateID);
$sql = 'SELECT * FROM gibbonFamilyUpdate WHERE gibbonFamilyUpdateID=:gibbonFamilyUpdateID';
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$result = $container->get(FamilyUpdateGateway::class)->getByID($gibbonFamilyUpdateID);

if (empty($result)) {
$URL .= '&return=error2';
header("Location: {$URL}");
exit();
}

if ($result->rowCount() != 1) {
$URL .= '&return=error2';
header("Location: {$URL}");
} else {
//Write to database
try {
$data = array('gibbonFamilyUpdateID' => $gibbonFamilyUpdateID);
$sql = 'DELETE FROM gibbonFamilyUpdate WHERE gibbonFamilyUpdateID=:gibbonFamilyUpdateID';
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$URL .= '&return=error2';
header("Location: {$URL}");
exit();
}
$deleted = $container->get(FamilyUpdateGateway::class)->delete($gibbonFamilyUpdateID);
$partialFail &= !$deleted;

$URLDelete = $URLDelete.'&return=success0';
header("Location: {$URLDelete}");
}
$URLDelete .= $partialFail ? '&return=warning1' : '&return=success0';
header("Location: {$URLDelete}");
}
}
17 changes: 6 additions & 11 deletions modules/Data Updater/data_family_manage_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

use Gibbon\Forms\Form;
use Gibbon\Domain\DataUpdater\FamilyUpdateGateway;

//Module includes
require_once __DIR__ . '/moduleFunctions.php';
Expand All @@ -41,22 +42,16 @@
if ($gibbonFamilyUpdateID == 'Y') {
$page->addError(__('You have not specified one or more required parameters.'));
} else {
$result = $container->get(FamilyUpdateGateway::class)->getFamilyByFamilyUpdateID($gibbonFamilyUpdateID);

$data = array('gibbonFamilyUpdateID' => $gibbonFamilyUpdateID);
$sql = 'SELECT gibbonFamily.* FROM gibbonFamilyUpdate JOIN gibbonFamily ON (gibbonFamilyUpdate.gibbonFamilyID=gibbonFamily.gibbonFamilyID) WHERE gibbonFamilyUpdateID=:gibbonFamilyUpdateID';
$result = $connection2->prepare($sql);
$result->execute($data);

if ($result->rowCount() != 1) {
if (empty($result)) {
$page->addError(__('The selected record does not exist, or you do not have access to it.'));
} else {
$data = array('gibbonFamilyUpdateID' => $gibbonFamilyUpdateID);
$sql = 'SELECT gibbonFamilyUpdate.* FROM gibbonFamilyUpdate JOIN gibbonFamily ON (gibbonFamilyUpdate.gibbonFamilyID=gibbonFamily.gibbonFamilyID) WHERE gibbonFamilyUpdateID=:gibbonFamilyUpdateID';
$newResult = $pdo->executeQuery($data, $sql);
$newResult = $container->get(FamilyUpdateGateway::class)->getFamilyUpdateByFamilyUpdateID($gibbonFamilyUpdateID);

//Let's go!
$oldValues = $result->fetch();
$newValues = $newResult->fetch();
$oldValues = $result;
$newValues = $newResult;

// Provide a link back to edit the associated record
if (isActionAccessible($guid, $connection2, '/modules/User Admin/family_manage_edit.php')) {
Expand Down
18 changes: 5 additions & 13 deletions modules/Data Updater/data_family_manage_editProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Gibbon\Data\Validator;
use Gibbon\Domain\DataUpdater\FamilyUpdateGateway;

require_once '../../gibbon.php';

Expand All @@ -39,23 +40,14 @@
$URL .= '&return=error1';
header("Location: {$URL}");
} else {
try {
$data = array('gibbonFamilyUpdateID' => $gibbonFamilyUpdateID);
$sql = 'SELECT * FROM gibbonFamilyUpdate WHERE gibbonFamilyUpdateID=:gibbonFamilyUpdateID';
$result = $connection2->prepare($sql);
$result->execute($data);
} catch (PDOException $e) {
$URL .= '&return=error2';
header("Location: {$URL}");
exit();
}

if ($result->rowCount() != 1) {
$result = $container->get(FamilyUpdateGateway::class)->getByID($gibbonFamilyUpdateID);

if (empty($result)) {
$URL .= '&return=error2';
header("Location: {$URL}");
} else {
//Set values
$data = array();
$data = [];
$set = '';
if (isset($_POST['newnameAddressOn'])) {
if ($_POST['newnameAddressOn'] == 'on') {
Expand Down
Loading
Loading