Skip to content

Commit

Permalink
Merge pull request #85 from powertashton/master
Browse files Browse the repository at this point in the history
Helpdesk Reply Templates
  • Loading branch information
raynichc authored Oct 17, 2021
2 parents f967d73 + d6835e1 commit 8670512
Show file tree
Hide file tree
Showing 17 changed files with 711 additions and 199 deletions.
8 changes: 8 additions & 0 deletions Help Desk/CHANGEDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,11 @@
$sql[$count][0]="2.0.02";
$sql[$count][1]="
";

$count++;
$sql[$count][0]="2.1.00";
$sql[$count][1]="
CREATE TABLE `helpDeskReplyTemplate` (`helpDeskReplyTemplateID` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `body` text NOT NULL, PRIMARY KEY (`helpDeskReplyTemplateID`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;end
INSERT INTO gibbonAction SET name='Help Desk Reply Templates', precedence=0, category='Settings', description='Manage Help Desk Reply Templates.', URLList='helpDesk_manageReplyTemplates.php', entryURL='helpDesk_manageReplyTemplates.php', defaultPermissionAdmin='Y', defaultPermissionTeacher='N', defaultPermissionStudent='N', defaultPermissionParent='N', defaultPermissionSupport='N', categoryPermissionStaff='Y', categoryPermissionStudent='N', categoryPermissionParent='N', categoryPermissionOther='N', gibbonModuleID=(SELECT gibbonModuleID FROM gibbonModule WHERE name='Help Desk');end
INSERT INTO `gibbonPermission` (`permissionID` ,`gibbonRoleID` ,`gibbonActionID`) VALUES (NULL , '1', (SELECT gibbonActionID FROM gibbonAction JOIN gibbonModule ON (gibbonAction.gibbonModuleID=gibbonModule.gibbonModuleID) WHERE gibbonModule.name='Help Desk' AND gibbonAction.name='Help Desk Reply Templates'));end
";
4 changes: 4 additions & 0 deletions Help Desk/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
CHANGELOG
=========
v2.1.00
-------
Introduced reply templates.

v2.0.02
-------
Refactored session variables and null coalesce.
Expand Down
58 changes: 58 additions & 0 deletions Help Desk/helpDesk_addReplyTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/*
Gibbon, Flexible & Open School System
Copyright (C) 2010, Ross Parker
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(__('Reply Templates'), 'helpDesk_manageReplyTemplates.php')
->add(__('Add Template'));

if (!isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
//Acess denied
$page->addError(__('You do not have access to this action.'));
} else {
if(isset($_GET['helpDeskReplyTemplateID'])) {
$page->return->setEditLink($session->get('absoluteURL') . '/index.php?q=/modules/' . $session->get('module') . '/helpDesk_editReplyTemplate.php&helpDeskReplyTemplateID=' . $_GET['helpDeskReplyTemplateID']);
}

$form = Form::create('addReplyTemplate', $session->get('absoluteURL') . '/modules/' . $session->get('module') . '/helpDesk_addReplyTemplateProcess.php');
$form->addHiddenValue('address', $session->get('address'));
$form->setTitle('Add Reply Template');

$row = $form->addRow();
$row->addLabel('name', 'Name');
$row->addTextfield('name')
->setRequired(true)
->maxLength(30)
->uniqueField('./modules/' . $session->get('module') . '/helpDesk_addReplyTemplateAjax.php');

$row = $form->addRow();
$column = $row->addColumn();
$column->addLabel('body', 'Body');
$column->addEditor('body', $guid)
->showMedia()
->setRequired(true);

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

print $form->getOutput();
}
?>
41 changes: 41 additions & 0 deletions Help Desk/helpDesk_addReplyTemplateAjax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
Gibbon, Flexible & Open School System
Copyright (C) 2010, Ross Parker
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/>.
*/

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

if (!$session->has('gibbonPersonID') || !$session->has('gibbonRoleIDPrimary')
|| !isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
die(__('Your request failed because you do not have access to this action.'));
} else {
$currentTemplateName = $_POST['currentTemplateName'] ?? null;
$templateName = $_POST['name'] ?? '';

if ($currentTemplateName != null && $currentTemplateName == $templateName) {
echo 0;
die();
}

$data = array('name' => $templateName);
$sql = 'SELECT COUNT(*) FROM helpDeskReplyTemplate WHERE name=:name';
$result = $pdo->executeQuery($data, $sql);

echo ($result && $result->rowCount() == 1)? $result->fetchColumn(0) : -1;
}

?>
41 changes: 41 additions & 0 deletions Help Desk/helpDesk_addReplyTemplateProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Gibbon\Module\HelpDesk\Domain\ReplyTemplateGateway;

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

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

if (!isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
//Acess denied
$URL .= '/issues_view.php&return=error0';
header("Location: {$URL}");
exit();
} else {
$URL .= '/helpDesk_manageReplyTemplates.php';

$replyTemplateGateway = $container->get(ReplyTemplateGateway::class);

$data = [
'name' => $_POST['name'] ?? '',
'body' => $_POST['body'] ?? '',
];

if (empty($data['name']) || empty($data['body']) || !$replyTemplateGateway->unique($data, ['name'])) {
$URL .= '&return=error1';
header("Location: {$URL}");
exit();
} else {
$helpDeskReplyTemplateID = $replyTemplateGateway->insert($data);

if ($helpDeskReplyTemplateID === false) {
$URL .= '&return=error2';
} else {
$URL .= '&return=success0&helpDeskReplyTemplateID=' . $helpDeskReplyTemplateID;
}

header("Location: {$URL}");
exit();
}
}
?>
41 changes: 41 additions & 0 deletions Help Desk/helpDesk_deleteReplyTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
Gibbon, Flexible & Open School System
Copyright (C) 2010, Ross Parker
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\Module\HelpDesk\Domain\ReplyTemplateGateway;

if (!isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
//Acess denied
$page->addError(__('You do not have access to this action.'));
} else {
$replyTemplateGateway = $container->get(ReplyTemplateGateway::class);

$helpDeskReplyTemplateID = $_GET['helpDeskReplyTemplateID'] ?? '';

if (empty($helpDeskReplyTemplateID) || !$replyTemplateGateway->exists($helpDeskReplyTemplateID)) {
$page->addError(__('Invalid Template.'));
} else {
$form = DeleteForm::createForm($session->get('absoluteURL') . '/modules/' . $session->get('module') . "/helpDesk_deleteReplyTemplateProcess.php");
$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('helpDeskReplyTemplateID', $helpDeskReplyTemplateID);

echo $form->getOutput();
}
}
?>
36 changes: 36 additions & 0 deletions Help Desk/helpDesk_deleteReplyTemplateProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Gibbon\Module\HelpDesk\Domain\ReplyTemplateGateway;

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

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

if (!isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
//Acess denied
$URL .= '/issues_view.php&return=error0';
header("Location: {$URL}");
exit();
} else {
$URL .= '/helpDesk_manageReplyTemplates.php';

$replyTemplateGateway = $container->get(ReplyTemplateGateway::class);

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

if (empty($helpDeskReplyTemplateID) || !$replyTemplateGateway->exists($helpDeskReplyTemplateID)) {
$URL .= '&return=error1';
header("Location: {$URL}");
exit();
} else {
if ($replyTemplateGateway->delete($helpDeskReplyTemplateID)) {
$URL .= '&return=success0';
} else {
$URL .= '&return=error2';
}

header("Location: {$URL}");
exit();
}
}
?>
67 changes: 67 additions & 0 deletions Help Desk/helpDesk_editReplyTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/*
Gibbon, Flexible & Open School System
Copyright (C) 2010, Ross Parker
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\Module\HelpDesk\Domain\ReplyTemplateGateway;
use Gibbon\Forms\Form;

$page->breadcrumbs
->add(__('Reply Templates'), 'helpDesk_manageReplyTemplates.php')
->add(__('Edit Template'));

if (!isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
//Acess denied
$page->addError(__('You do not have access to this action.'));
} else {
$replyTemplateGateway = $container->get(ReplyTemplateGateway::class);

$helpDeskReplyTemplateID = $_GET['helpDeskReplyTemplateID'] ?? '';
$replyTemplate = $replyTemplateGateway->getByID($helpDeskReplyTemplateID);

if (empty($replyTemplate)) {
$page->addError(__('Invalid Reply Template.'));
} else {
$form = Form::create('editRiskTemplate', $session->get('absoluteURL') . '/modules/' . $session->get('module') . '/helpDesk_editReplyTemplateProcess.php');
$form->addHiddenValue('address', $session->get('address'));
$form->addHiddenValue('helpDeskReplyTemplateID', $helpDeskReplyTemplateID);
$form->setTitle('Edit Reply Template');

$row = $form->addRow();
$row->addLabel('name', 'Name');
$row->addTextfield('name')
->setRequired(true)
->maxLength(30)
->uniqueField('./modules/' . $session->get('module') . '/helpDesk_addReplyTemplateAjax.php', ['currentTemplateName' => $replyTemplate['name']])
->setValue($replyTemplate['name']);

$row = $form->addRow();
$column = $row->addColumn();
$column->addLabel('body', 'Body');
$column->addEditor('body', $guid)
->setRequired(true)
->showMedia()
->setValue($replyTemplate['body']);

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

print $form->getOutput();
}
}
?>
46 changes: 46 additions & 0 deletions Help Desk/helpDesk_editReplyTemplateProcess.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use Gibbon\Module\HelpDesk\Domain\ReplyTemplateGateway;

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

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

if (!isActionAccessible($guid, $connection2, '/modules/Help Desk/helpDesk_manageReplyTemplates.php')) {
//Acess denied
$URL .= '/issues_view.php&return=error0';
header("Location: {$URL}");
exit();
} else {

$replyTemplateGateway = $container->get(ReplyTemplateGateway::class);

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

if (empty($helpDeskReplyTemplateID) || !$replyTemplateGateway->exists($helpDeskReplyTemplateID)) {
$URL .= '/helpDesk_manageReplyTemplates.php&return=error1';
header("Location: {$URL}");
exit();
} else {
$URL .= '/helpDesk_editReplyTemplate.php';
$data = [
'name' => $_POST['name'] ?? '',
'body' => $_POST['body'] ?? '',
];
if (empty($data['name']) || empty($data['body']) || !$replyTemplateGateway->unique($data, ['name'], $helpDeskReplyTemplateID)) {
$URL .= '&return=error1';
header("Location: {$URL}");
exit();
} else {
if (!$replyTemplateGateway->update($helpDeskReplyTemplateID, $data)) {
$URL .= '&return=error2';
} else {
$URL .= '&return=success0&helpDeskReplyTemplateID=' . $helpDeskReplyTemplateID;
}

header("Location: {$URL}");
exit();
}
}
}
?>
Loading

0 comments on commit 8670512

Please sign in to comment.