Commit 166bedd0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

More checking on view access date formatting (bug 3072)

parent 61836039
...@@ -41,6 +41,7 @@ $string['description'] = 'View Description'; ...@@ -41,6 +41,7 @@ $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['startdatemustbebeforestopdate'] = 'The start date must be before the stop date'; $string['startdatemustbebeforestopdate'] = 'The start date must be before the stop date';
$string['unrecogniseddateformat'] = 'Unrecognised date format';
$string['ownerformat'] = 'Name display format'; $string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'How do you want people who look at your View to see your name?'; $string['ownerformatdescription'] = 'How do you want people who look at your View to see your name?';
$string['profileviewtitle'] = 'Profile view'; $string['profileviewtitle'] = 'Profile view';
......
...@@ -241,13 +241,21 @@ function editaccess_validate(Pieform $form, $values) { ...@@ -241,13 +241,21 @@ function editaccess_validate(Pieform $form, $values) {
} }
$loggedinaccess = false; $loggedinaccess = false;
if ($values['accesslist']) { if ($values['accesslist']) {
foreach ($values['accesslist'] as $item) { foreach ($values['accesslist'] as &$item) {
if (!isset($item['startdate'])) { if (!isset($item['startdate'])) {
$item['startdate'] = null; $item['startdate'] = null;
} }
else if (!$item['startdate'] = strtotime($item['startdate'])) {
$form->set_error('accesslist', get_string('unrecogniseddateformat', 'view'));
break;
}
if (!isset($item['stopdate'])) { if (!isset($item['stopdate'])) {
$item['stopdate'] = null; $item['stopdate'] = null;
} }
else if (!$item['stopdate'] = strtotime($item['stopdate'])) {
$form->set_error('accesslist', get_string('invaliddate', 'view'));
break;
}
if ($item['type'] == 'loggedin' && !$item['startdate'] && !$item['stopdate']) { if ($item['type'] == 'loggedin' && !$item['startdate'] && !$item['stopdate']) {
$loggedinaccess = true; $loggedinaccess = true;
} }
...@@ -285,6 +293,16 @@ function editaccess_submit(Pieform $form, $values) { ...@@ -285,6 +293,16 @@ function editaccess_submit(Pieform $form, $values) {
redirect('/view/blocks.php?id=' . $view->get('id') . '&new=' . $new); redirect('/view/blocks.php?id=' . $view->get('id') . '&new=' . $new);
} }
if ($values['accesslist']) {
foreach ($values['accesslist'] as &$item) {
if (isset($item['startdate'])) {
$item['startdate'] = strtotime($item['startdate']);
}
if (isset($item['stopdate'])) {
$item['stopdate'] = strtotime($item['stopdate']);
}
}
}
$view->set_access($values['accesslist']); $view->set_access($values['accesslist']);
$view->set('startdate', $values['startdate']); $view->set('startdate', $values['startdate']);
......
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