Commit 28e6a2b5 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I349d2dde,If087014f,Ic4db2073,I22c8876a,Iaa686c8a

* changes:
  Remove unnecessary global declaration
  Fix error messages for group access dates (bug #894592)
  Fix warnings when rendering access type after error (bug #894592)
  Display stopdate fields which have errors in them (bug #894592)
  Fix display of view access rows after error on submission (bug #894592)
parents a4cf5280 49def28d
......@@ -51,24 +51,26 @@ function pieform_element_viewacl(Pieform $form, $element) {
else if (get_config('allowpublicprofiles') && $element['viewtype'] == 'profile') {
$public = true;
}
$presets = array();
$allpresets = array('public', 'loggedin', 'friends');
$allowedpresets = array();
$loggedinindex = 0;
if ($public) {
$presets[] = 'public';
$allowedpresets[] = 'public';
$loggedinindex = 1;
}
$presets[] = 'loggedin';
$allowedpresets[] = 'loggedin';
if ($form->get_property('userview')) {
$presets[] = 'friends';
$allowedpresets[] = 'friends';
}
$accesslist = array();
if ($value) {
foreach ($value as $key => &$item) {
foreach ($value as $item) {
if (is_array($item)) {
if ($item['accesstype'] == 'public') {
if ($item['type'] == 'public') {
$item['publicallowed'] = (int)$public;
}
if (in_array($item['type'], $presets)) {
if (in_array($item['type'], $allpresets)) {
$item['name'] = get_string($item['type'], 'view');
$item['preset'] = true;
}
......@@ -79,13 +81,10 @@ function pieform_element_viewacl(Pieform $form, $element) {
$item['shortname'] = str_shorten_text($item['name'], 30, true);
}
// only show access that is still current. Expired access will be deleted if the form is saved
if($item['stopdate'] && (time() > strtotime($item['stopdate']))) {
unset($value[$key]);
if ($form->is_submitted() || empty($item['stopdate']) || (time() <= strtotime($item['stopdate']))) {
$accesslist[] = $item;
}
}
else {
unset($value[$key]);
}
}
}
......@@ -101,8 +100,7 @@ function pieform_element_viewacl(Pieform $form, $element) {
);
}
$potentialpresets = $presets;
foreach ($potentialpresets as &$preset) {
foreach ($allowedpresets as &$preset) {
$preset = array(
'type' => $preset,
'id' => $preset,
......@@ -154,9 +152,9 @@ function pieform_element_viewacl(Pieform $form, $element) {
}
$smarty->assign('viewtype', $element['viewtype']);
$smarty->assign('potentialpresets', json_encode($potentialpresets));
$smarty->assign('potentialpresets', json_encode($allowedpresets));
$smarty->assign('loggedinindex', $loggedinindex);
$smarty->assign('accesslist', json_encode($value));
$smarty->assign('accesslist', json_encode($accesslist));
$smarty->assign('viewid', $form->get_property('viewid'));
$smarty->assign('formname', $form->get_property('name'));
$smarty->assign('myinstitutions', json_encode($myinstitutions));
......
......@@ -30,8 +30,6 @@ define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'editaccess');
global $CFG;
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('pieforms/pieform/elements/calendar.php');
......@@ -421,6 +419,16 @@ function editaccess_validate(Pieform $form, $values) {
if ($values['startdate'] && $values['stopdate'] && $values['startdate'] > $values['stopdate']) {
$form->set_error('startdate', get_string('newstartdatemustbebeforestopdate', 'view', 'Overriding'));
}
$accesstypestrings = array(
'public' => get_string('public', 'view'),
'loggedin' => get_string('loggedin', 'view'),
'friends' => get_string('friends', 'view'),
'user' => get_string('user', 'group'),
'group' => get_string('group', 'group'),
'institution' => get_string('institution'),
);
$loggedinaccess = false;
if ($values['accesslist']) {
$dateformat = get_string('strftimedatetimeshort');
......@@ -446,12 +454,12 @@ function editaccess_validate(Pieform $form, $values) {
}
$now = strptime(date('Y/m/d H:i'), $dateformat);
if ($item['stopdate'] && ptimetotime($now) > ptimetotime($item['stopdate'])) {
$SESSION->add_error_msg(get_string('newstopdatecannotbeinpast', 'view', get_string($item['type'], 'view')));
$SESSION->add_error_msg(get_string('newstopdatecannotbeinpast', 'view', $accesstypestrings[$item['type']]));
$form->set_error('accesslist', '');
break;
}
if ($item['startdate'] && $item['stopdate'] && ptimetotime($item['startdate']) > ptimetotime($item['stopdate'])) {
$SESSION->add_error_msg(get_string('newstartdatemustbebeforestopdate', 'view', get_string($item['type'], 'view')));
$SESSION->add_error_msg(get_string('newstartdatemustbebeforestopdate', 'view', $accesstypestrings[$item['type']]));
$form->set_error('accesslist', '');
break;
}
......
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