Skip to content

Commit

Permalink
Messenger: added new Mailing List feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Parker committed Oct 17, 2024
1 parent 8585561 commit 4675919
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGEDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,4 +832,6 @@
UPDATE gibbonCountry SET iddCountryCode='850' WHERE printable_name='Korea, Democratic People\'s Republic of';end
UPDATE `gibboni18n` SET `active` = 'Y' WHERE `code` = 'el_GR';end
UPDATE gibbonModule SET author='Gibbon Foundation', url='https://gibbonedu.org' WHERE type='Core';end
";
CREATE TABLE `gibbonMessengerMailingList` ( `gibbonMessengerMailingListID` int(8) unsigned NOT NULL AUTO_INCREMENT, `surname` varchar(60) DEFAULT NULL, `preferredName` varchar(60) DEFAULT NULL, `email` varchar(75) NOT NULL, `timestampCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`gibbonMessengerMailingListID`), UNIQUE KEY `email` (`email`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;end
INSERT IGNORE INTO `gibbonAction` (`gibbonModuleID`, `name`, `precedence`, `category`, `description`, `URLList`, `entryURL`, `entrySidebar`, `menuShow`, `defaultPermissionAdmin`, `defaultPermissionTeacher`, `defaultPermissionStudent`, `defaultPermissionParent`, `defaultPermissionSupport`, `categoryPermissionStaff`, `categoryPermissionStudent`, `categoryPermissionParent`, `categoryPermissionOther`) VALUES((SELECT gibbonModuleID FROM gibbonModule WHERE name='Messenger'), 'Manage Mailing List', 0, 'Targets', 'Manage users within the schools\' external mailing list.', 'mailingList_manage.php, mailingList_manage_add.php, mailingList_manage_edit.php, mailingList_manage_delete.php', 'mailingList_manage.php', 'Y', 'Y', 'Y', 'N', 'N', 'N', 'N', 'Y', 'N', 'N', 'N');end
INSERT IGNORE INTO `gibbonPermission` (`gibbonRoleID` ,`gibbonActionID`) VALUES ('001', (SELECT gibbonActionID FROM gibbonAction JOIN gibbonModule ON (gibbonAction.gibbonModuleID=gibbonModule.gibbonModuleID) WHERE gibbonModule.name='Messenger' AND gibbonAction.name='Manage Mailing List'));end
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ v28.0.00
--------

Headlines
Messenger: added new Mailing List feature

Changes With Important Notices

Expand Down
67 changes: 67 additions & 0 deletions modules/Messenger/mailingList_manage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/*
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/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


use Gibbon\Services\Format;
use Gibbon\Tables\DataTable;
use Gibbon\Domain\Messenger\MailingListGateway;

$page->breadcrumbs->add(__('Manage Mailing List'));

if (isActionAccessible($guid, $connection2, '/modules/Messenger/mailingList_manage.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
//Proceed!

// QUERY
$mailingListGateway = $container->get(MailingListGateway::class);
$criteria = $mailingListGateway->newQueryCriteria(true)
->sortBy('surname', 'preferredName')
->fromPOST();

$mailingLists = $mailingListGateway->queryMailingList($criteria);

// TABLE
$table = DataTable::createPaginated('mailingLists', $criteria);

$table->addHeaderAction('add', __('Add'))
->displayLabel()
->setURL('/modules/Messenger/mailingList_manage_add.php');

$table->addColumn('surname', __('Surname'));

$table->addColumn('preferredName', __('Preferred Name'));

$table->addColumn('email', __('Email'));

$table->addActionColumn()
->addParam('gibbonMessengerMailingListID')
->format(function ($mailingList, $actions) {
$actions->addAction('edit', __('Edit'))
->setURL('/modules/Messenger/mailingList_manage_edit.php');

$actions->addAction('delete', __('Delete'))
->setURL('/modules/Messenger/mailingList_manage_delete.php');
});

echo $table->render($mailingLists);
}
60 changes: 60 additions & 0 deletions modules/Messenger/mailingList_manage_add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*
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/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Forms\Form;

$page->breadcrumbs
->add(__('Manage Mailing Lists'), 'mailingList_manage.php')
->add(__('Add Recipient'));

if (isActionAccessible($guid, $connection2, '/modules/Messenger/mailingList_manage_add.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
//Proceed!
$editLink = '';
if (isset($_GET['editID'])) {
$editLink = $session->get('absoluteURL').'/index.php?q=/modules/Messenger/mailingList_manage_edit.php&gibbonMessengerMailingListID='.$_GET['editID'];
}
$page->return->setEditLink($editLink);

$form = Form::create('mailingList', $session->get('absoluteURL').'/modules/'.$session->get('module').'/mailingList_manage_addProcess.php');

$form->addHiddenValue('address', $session->get('address'));

$row = $form->addRow();
$row->addLabel('surname', __('Surname'));
$row->addTextField('surname')->required()->maxLength(60);

$row = $form->addRow();
$row->addLabel('preferredName', __('Preferred Name'));
$row->addTextField('preferredName')->required()->maxLength(60);

$row = $form->addRow();
$row->addLabel('email', __('Email'))->description(__('Must be unique.'));
$row->addEmail('email')->required()->maxLength(75);

$row = $form->addRow();
$row->addFooter();
$row->addSubmit();

echo $form->getOutput();
}
71 changes: 71 additions & 0 deletions modules/Messenger/mailingList_manage_addProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/*
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/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Data\Validator;
use Gibbon\Services\Format;
use Gibbon\Domain\Messenger\MailingListGateway;

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

$_POST = $container->get(Validator::class)->sanitize($_POST);

$URL = $session->get('absoluteURL')."/index.php?q=/modules/Messenger/mailingList_manage_add.php";

if (isActionAccessible($guid, $connection2, '/modules/Messenger/mailingList_manage_add.php') == false) {
$URL .= '&return=error0';
header("Location: {$URL}");
exit;
} else {
// Proceed!
$mailingListGateway = $container->get(MailingListGateway::class);

$data = [
'surname' => $_POST['surname'] ?? '',
'preferredName' => $_POST['preferredName'] ?? '',
'email' => $_POST['email'] ?? ''
];

// Validate the required values are present
if (empty($data['surname']) || empty($data['preferredName']) || empty($data['email'])) {
$URL .= '&return=error1';
header("Location: {$URL}");
exit;
}

// Validate that this record is unique
if (!$mailingListGateway->unique($data, ['email'])) {
$URL .= '&return=error7';
header("Location: {$URL}");
exit;
}

// Create the record
$gibbonMessengerMailingListID = $mailingListGateway->insert($data);

if ($gibbonMessengerMailingListID) {
$URL .= "&return=success0&editID=$gibbonMessengerMailingListID";
}
else {
$URL .= "&return=error2";
}

header("Location: {$URL}");
}
46 changes: 46 additions & 0 deletions modules/Messenger/mailingList_manage_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/*
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/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Forms\Prefab\DeleteForm;
use Gibbon\Domain\Messenger\MailingListGateway;

if (isActionAccessible($guid, $connection2, '/modules/Messenger/mailingList_manage_delete.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
// Proceed!
$gibbonMessengerMailingListID = $_GET['gibbonMessengerMailingListID'] ?? '';

if (empty($gibbonMessengerMailingListID)) {
$page->addError(__('You have not specified one or more required parameters.'));
return;
}

$values = $container->get(MailingListGateway::class)->getByID($gibbonMessengerMailingListID);

if (empty($values)) {
$page->addError(__('The specified record cannot be found.'));
return;
}

$form = DeleteForm::createForm($session->get('absoluteURL').'/modules/Messenger/mailingList_manage_deleteProcess.php');
echo $form->getOutput();
}
59 changes: 59 additions & 0 deletions modules/Messenger/mailingList_manage_deleteProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
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/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Data\Validator;
use Gibbon\Domain\Messenger\MailingListGateway;

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

$_POST = $container->get(Validator::class)->sanitize($_POST);

$gibbonMessengerMailingListID = $_POST['gibbonMessengerMailingListID'] ?? '';

$URL = $session->get('absoluteURL').'/index.php?q=/modules/Messenger/mailingList_manage.php';

if (isActionAccessible($guid, $connection2, '/modules/Messenger/mailingList_manage_delete.php') == false) {
$URL .= '&return=error0';
header("Location: {$URL}");
exit;
} elseif (empty($gibbonMessengerMailingListID)) {
$URL .= '&return=error1';
header("Location: {$URL}");
exit;
} else {
// Proceed!
$mailingListGateway = $container->get(MailingListGateway::class);
$values = $mailingListGateway->getByID($gibbonMessengerMailingListID);

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

$deleted = $mailingListGateway->delete($gibbonMessengerMailingListID);

$URL .= !$deleted
? '&return=error2'
: '&return=success0';

header("Location: {$URL}");
}
72 changes: 72 additions & 0 deletions modules/Messenger/mailingList_manage_edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/*
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/)
Copyright © 2010, Gibbon Foundation
Gibbon™, Gibbon Education Ltd. (Hong Kong)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

use Gibbon\Forms\Form;
use Gibbon\Domain\Messenger\MailingListGateway;

if (isActionAccessible($guid, $connection2, '/modules/Messenger/mailingList_manage_edit.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
// Proceed!
$gibbonMessengerMailingListID = $_GET['gibbonMessengerMailingListID'] ?? '';

$page->breadcrumbs
->add(__m('Manage Mailing List'), 'mailingList_manage.php')
->add(__m('Edit Recipient'));

if (empty($gibbonMessengerMailingListID)) {
$page->addError(__('You have not specified one or more required parameters.'));
return;
}

$values = $container->get(MailingListGateway::class)->getByID($gibbonMessengerMailingListID);

if (empty($values)) {
$page->addError(__('The specified record cannot be found.'));
return;
}

$form = Form::create('category', $session->get('absoluteURL').'/modules/'.$session->get('module').'/mailingList_manage_editProcess.php');

$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('gibbonMessengerMailingListID', $gibbonMessengerMailingListID);

$row = $form->addRow();
$row->addLabel('surname', __('Surname'));
$row->addTextField('surname')->required()->maxLength(60);

$row = $form->addRow();
$row->addLabel('preferredName', __('Preferred Name'));
$row->addTextField('preferredName')->required()->maxLength(60);

$row = $form->addRow();
$row->addLabel('email', __('Email'))->description(__('Must be unique.'));
$row->addEmail('email')->required()->maxLength(75);

$row = $form->addRow();
$row->addFooter();
$row->addSubmit();

$form->loadAllValuesFrom($values);

echo $form->getOutput();
}
Loading

0 comments on commit 4675919

Please sign in to comment.