Commit 39d7fd43 authored by Nigel McNie's avatar Nigel McNie
Browse files

A fix for bug #736 - now validation of dates is done server side.

The javascript calendar integration appears to have some bugs, some in the calendar and some in the hook-in javascript I wrote. I did manage to get the date inserting when you clicked 'today', but other problems with the behaviour (like not being able to select certain dates from the calendar under certain conditions) have led me to remove the javascript handling of valid dates and implement it server-side (as it should have already been anyway).

Maybe later, someone can come back and do the javascript properly.
parent ffe30a0c
...@@ -40,7 +40,7 @@ $string['title'] = 'View Title'; ...@@ -40,7 +40,7 @@ $string['title'] = 'View Title';
$string['description'] = 'View Description'; $string['description'] = 'View Description';
$string['startdate'] = 'Access Start Date/Time'; $string['startdate'] = 'Access Start Date/Time';
$string['stopdate'] = 'Access End Date/Time'; $string['stopdate'] = 'Access End Date/Time';
$string['stopdate'] = 'Access End Date/Time'; $string['startdatemustbebeforestopdate'] = 'The start date must be before the stop date';
$string['ownerformat'] = 'Name display format'; $string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'This field controls what appears in the author field for the template you select in step 2'; $string['ownerformatdescription'] = 'This field controls what appears in the author field for the template you select in step 2';
$string['nochildren'] = 'no artefacts'; $string['nochildren'] = 'no artefacts';
......
...@@ -91,8 +91,6 @@ $createview1 = pieform(array( ...@@ -91,8 +91,6 @@ $createview1 = pieform(array(
'title' => get_string('startdate','view'), 'title' => get_string('startdate','view'),
'defaultvalue' => isset($data['startdate']) ? $data['startdate'] : null, 'defaultvalue' => isset($data['startdate']) ? $data['startdate'] : null,
'caloptions' => array( 'caloptions' => array(
//'dateStatusFunc' => 'startDateDisallowed',
//'onSelect' => 'startSelected',
'showsTime' => true, 'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M' 'ifFormat' => '%Y/%m/%d %H:%M'
), ),
...@@ -103,8 +101,6 @@ $createview1 = pieform(array( ...@@ -103,8 +101,6 @@ $createview1 = pieform(array(
'title' => get_string('stopdate','view'), 'title' => get_string('stopdate','view'),
'defaultvalue' => isset($data['stopdate']) ? $data['stopdate'] : null, 'defaultvalue' => isset($data['stopdate']) ? $data['stopdate'] : null,
'caloptions' => array( 'caloptions' => array(
//'dateStatusFunc' => 'stopDateDisallowed',
//'onSelect' => 'stopSelected',
'showsTime' => true, 'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M' 'ifFormat' => '%Y/%m/%d %H:%M'
), ),
...@@ -150,6 +146,12 @@ function createview1_cancel_submit() { ...@@ -150,6 +146,12 @@ function createview1_cancel_submit() {
redirect('/view/'); redirect('/view/');
} }
function createview1_validate(Pieform $form, $values) {
if ($values['startdate'] > $values['stopdate']) {
$form->set_error('startdate', get_string('startdatemustbebeforestopdate', 'view'));
}
}
function createview1_submit(Pieform $form, $values) { function createview1_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
...@@ -173,63 +175,6 @@ function createview1_submit(Pieform $form, $values) { ...@@ -173,63 +175,6 @@ function createview1_submit(Pieform $form, $values) {
$smarty = smarty(); $smarty = smarty();
$smarty->assign('createview1', $createview1); $smarty->assign('createview1', $createview1);
// NOTE: this javascript shows an idea of how you might make it so that you can't select invalid dates.
// However, it's broken (try selecting a start date and then an end date). Perhaps it can be improved
// later...
/*$smarty->assign('INLINEJAVASCRIPT', <<<EOF
function startDateDisallowed(date) {
var stopDate = $('createview1_stopdate').value;
if (stopDate != '') {
stopDate = stopDate.substr(0, 10).replace(/\//g, '-');
stopDate = isoDate(stopDate);
if (!stopDate) {
stopDate = Date();
}
if (stopDate.getTime() < date.getTime()) {
return true;
}
}
return false;
}
function stopDateDisallowed(date) {
var startDate = $('createview1_startdate').value;
if (startDate != '') {
startDate = startDate.substr(0, 10).replace(/\//g, '-');
startDate = isoDate(startDate);
if (!startDate) {
startDate = Date();
}
if (startDate.getTime() > date.getTime()) {
return true;
}
}
return false;
}
function startSelected(calendar, date) {
if (calendar.dateClicked) {
var stopDate = $('createview1_stopdate').value;
if (stopDate != '' && stopDateDisallowed(isoDate(stopDate))) {
$('createview1_stopdate').value = date;
}
$('createview1_startdate').value = date;
calendar.callCloseHandler();
}
}
function stopSelected(calendar, date) {
if (calendar.dateClicked) {
var startDate = $('createview1_startdate').value.replace(/\//g, '-');
if (startDate != '' && startDateDisallowed(isoDate(startDate))) {
$('createview1_startdate').value = date;
}
$('createview1_stopdate').value = date;
calendar.callCloseHandler();
}
}
EOF
);*/
$smarty->display('view/create1.tpl'); $smarty->display('view/create1.tpl');
?> ?>
...@@ -90,8 +90,6 @@ $createview1 = pieform(array( ...@@ -90,8 +90,6 @@ $createview1 = pieform(array(
'title' => get_string('startdate','view'), 'title' => get_string('startdate','view'),
'defaultvalue' => $data->startdate, 'defaultvalue' => $data->startdate,
'caloptions' => array( 'caloptions' => array(
'dateStatusFunc' => 'startDateDisallowed',
'onSelect' => 'startSelected',
'showsTime' => true, 'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M' 'ifFormat' => '%Y/%m/%d %H:%M'
), ),
...@@ -102,8 +100,6 @@ $createview1 = pieform(array( ...@@ -102,8 +100,6 @@ $createview1 = pieform(array(
'title' => get_string('stopdate','view'), 'title' => get_string('stopdate','view'),
'defaultvalue' => $data->stopdate, 'defaultvalue' => $data->stopdate,
'caloptions' => array( 'caloptions' => array(
'dateStatusFunc' => 'stopDateDisallowed',
'onSelect' => 'stopSelected',
'showsTime' => true, 'showsTime' => true,
'ifFormat' => '%Y/%m/%d %H:%M' 'ifFormat' => '%Y/%m/%d %H:%M'
), ),
...@@ -144,6 +140,12 @@ function createview1_cancel_submit() { ...@@ -144,6 +140,12 @@ function createview1_cancel_submit() {
redirect('/view/'); redirect('/view/');
} }
function createview1_validate(Pieform $form, $values) {
if ($values['startdate'] > $values['stopdate']) {
$form->set_error('startdate', get_string('startdatemustbebeforestopdate', 'view'));
}
}
function createview1_submit(Pieform $form, $values) { function createview1_submit(Pieform $form, $values) {
global $SESSION; global $SESSION;
global $view_id; global $view_id;
...@@ -173,60 +175,6 @@ function createview1_submit(Pieform $form, $values) { ...@@ -173,60 +175,6 @@ function createview1_submit(Pieform $form, $values) {
$smarty = smarty(); $smarty = smarty();
$smarty->assign('createview1', $createview1); $smarty->assign('createview1', $createview1);
$smarty->assign('INLINEJAVASCRIPT', <<<EOF
function startDateDisallowed(date) {
var stopDate = $('createview1_stopdate').value;
if (stopDate != '') {
stopDate = stopDate.substr(0, 10).replace(/\//g, '-');
stopDate = isoDate(stopDate);
if (!stopDate) {
stopDate = Date();
}
if (stopDate.getTime() < date.getTime()) {
return true;
}
}
return false;
}
function stopDateDisallowed(date) {
var startDate = $('createview1_startdate').value;
if (startDate != '') {
startDate = startDate.substr(0, 10).replace(/\//g, '-');
startDate = isoDate(startDate);
if (!startDate) {
startDate = Date();
}
if (startDate.getTime() > date.getTime()) {
return true;
}
}
return false;
}
function startSelected(calendar, date) {
if (calendar.dateClicked) {
var stopDate = $('createview1_stopdate').value;
if (stopDate != '' && stopDateDisallowed(isoDate(stopDate))) {
$('createview1_stopdate').value = date;
}
$('createview1_startdate').value = date;
calendar.callCloseHandler();
}
}
function stopSelected(calendar, date) {
if (calendar.dateClicked) {
var startDate = $('createview1_startdate').value.replace(/\//g, '-');
if (startDate != '' && startDateDisallowed(isoDate(startDate))) {
$('createview1_startdate').value = date;
}
$('createview1_stopdate').value = date;
calendar.callCloseHandler();
}
}
EOF
);
$smarty->assign('EDITMODE', true); $smarty->assign('EDITMODE', true);
$smarty->display('view/create1.tpl'); $smarty->display('view/create1.tpl');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment