';
// A registration can be cancelled by the registrant or by
// the person who registered them or by the booking owner or
// if ordinary users are allowed to delete other users' registrations.
if (getWritable($registrant['username'], $row['room_id']) ||
getWritable($registrant['create_by'], $row['room_id']) ||
getWritable($row['create_by'], $row['room_id']) ||
(isset($mrbs_user) && $auth['users_can_delete_others_registrations']))
{
generate_cancel_registration_button(
$row,
$registrant,
get_vocab('delete'),
$previous_page
);
}
echo '
';
// Registrant and Registered by
foreach(['username', 'create_by'] as $key)
{
// Default values
$display_name = '';
$email = null;
// Only show a name if it's the registrant or the creator is someone other than the registrant
if (($key != 'create_by') || ($registrant['create_by'] !== $registrant['username']))
{
if (can_see_email_addresses())
{
$user = auth()->getUser($registrant[$key]);
if (isset($user))
{
$display_name = $user->display_name;
$email = $user->email;
}
else
{
$display_name = $registrant[$key];
}
}
else
{
// Can be faster sometimes if we don't need the email address
$display_name = auth()->getDisplayName($registrant[$key]);
}
}
$sort_name = get_sortable_name($display_name);
echo '
';
$display_name_html = escape_html($display_name);
// Add a mailto: link if we've got an email address
if (isset($email) && ($email !== ''))
{
$display_name_html = '' . $display_name_html . '';
}
echo $display_name_html;
echo '
';
}
// Time of registration
$time = time_date_string($registrant['registered']);
echo '
' . escape_html($time) . '
';
echo "
\n";
}
echo "\n";
echo "
\n";
echo "\n";
}
function get_returl(?string $previous_page=null) : string
{
global $server;
static $returl=null;
if (!isset($returl))
{
// Add the previous_page (ie the one we were on before view_entry) to the query string
// so that it is preserved.
$returl = this_page();
$query_string = $server['QUERY_STRING'] ?? '';
parse_str($query_string, $query_string_parts);
if (isset($previous_page))
{
$query_string_parts['previous_page'] = $previous_page;
}
if (!empty($query_string_parts))
{
$returl .= '?' . http_build_query($query_string_parts, '', '&');
}
}
return $returl;
}
function generate_cancel_registration_button(array $row, array $registrant, string $label_text, ?string $previous_page=null, bool $as_field=false) : void
{
global $area, $room;
// Check that it is not too late for ordinary users to cancel
if (!getWritable($row['create_by'], $row['room_id']) && entry_registration_cancellation_has_closed($row))
{
return;
}
$form = new Form(Form::METHOD_POST);
$form->setAttributes(array('action' => multisite('registration_handler.php')));
if ($as_field)
{
$form->setAttribute('class', 'standard');
}
// Hidden inputs
$form->addHiddenInputs(array(
'action' => 'cancel',
'registration_id' => $registrant['id'],
'returl' => get_returl($previous_page),
'area' => $area,
'room' => $room
));
// Submit button
$button = new ElementInputSubmit();
$display_name = auth()->getDisplayName($registrant['username']);
$message = get_vocab("confirm_del_registrant", $display_name);
$button->setAttributes(array(
'value' => $label_text,
'onclick' => "return confirm('" . escape_js($message) . "');"
));
if ($as_field)
{
$fieldset = new ElementFieldset();
$field = new FieldDiv();
$field->addControl($button);
$fieldset->addElement($field);
$form->addElement($fieldset);
}
else
{
$form->addElement($button);
}
$form->render();
}
function generate_register_button(array $row, ?string $previous_page=null) : void
{
global $area, $room;
// Check that the user is an admin or else that the entry is open for registration
if (!getWritable($row['create_by'], $row['room_id']) && !entry_registration_is_open($row))
{
return;
}
$mrbs_user = session()->getCurrentUser();
$can_register_others = can_register_others($row['room_id']);
$form = new Form(Form::METHOD_POST);
$form->setAttributes(array('action' => multisite('registration_handler.php'),
'class' => 'standard'));
// Hidden inputs
$form->addHiddenInputs(array(
'action' => 'register',
'event_id' => $row['id'],
'returl' => get_returl($previous_page),
'area' => $area,
'room' => $room
));
if (!$can_register_others)
{
$form->addHiddenInput('username', $mrbs_user->username);
}
else
{
$fieldset = new ElementFieldset();
$params = array(
'value' => $mrbs_user->username,
'disabled' => false,
'required' => true,
'field' => 'participants.username',
'label' => get_vocab('name'),
'name' => 'username',
);
$fieldset->addElement(get_user_field($params, true));
$form->addElement($fieldset);
}
// Submit button
$fieldset = new ElementFieldset();
$field = new FieldDiv();
$element = new ElementInputSubmit();
$element->setAttribute('value', get_vocab('register'));
$field->addControl($element);
$fieldset->addElement($field);
$form->addElement($fieldset);
$form->render();
}
function generate_event_registration(array $row, ?string $previous_page=null) : void
{
global $auth;
if (empty($row['allow_registration']))
{
return;
}
$can_register_others = can_register_others($row['room_id']);
$can_see_others = $can_register_others || $auth['show_registrant_names'] || getWritable($row['create_by'], $row['room_id']);
$n_registered = count($row['registrants']);
echo '
' . get_vocab('event_registration') . "
\n";
echo "
\n";
echo "
\n";
echo "\n";
if ($row['registration_opens_enabled'])
{
echo '
\n";
// Display the list of registrants, if the user is allowed to see it, which is if
// they have write access for this booking.
// Display it as a table because in the future we might want to (a) add more columns,
// eg date and time of registration and (b) use DataTables to make the list searchable
// and exportable.
if (($n_registered > 0) && $can_see_others)
{
generate_registrant_table($row, $previous_page);
}
// Display registration information and buttons for this user
$mrbs_user = session()->getCurrentUser();
// Doesn't make sense to have anonymous registration at the moment.
// You'd have to have a different kind of registration form - and
// also think about who is allowed to cancel.
if (isset($mrbs_user) && ($mrbs_user->username !== ''))
{
if (!$can_register_others && in_arrayi($mrbs_user->username,
array_column($row['registrants'], 'username')))
{
echo '
\n";
foreach ($row['registrants'] as $registrant)
{
if (compare_usernames($mrbs_user->username, $registrant['username']) === 0)
{
$this_registrant = $registrant;
break;
}
}
// If they can see others they'll have a delete button against their name. Otherwise
// we'll need to provide one for them.
if (!$can_see_others)
{
generate_cancel_registration_button(
$row,
$this_registrant,
get_vocab('cancel_registration'),
$previous_page,
true
);
}
}
else
{
if (empty($row['registrant_limit_enabled']) ||
($row['registrant_limit'] > $n_registered))
{
generate_register_button($row, $previous_page);
}
else
{
echo '
' . escape_html(get_vocab('event_full')) . "
\n";
}
}
}
echo "
\n";
}
// Generates a single button. Parameters in the array $params
//
// Mandatory parameters
// action The form action attribute
// value The value of the button
// inputs An array of hidden form inputs
//
// Optional parameters
// button_attributes An array of attributes to be used for the button.
function generate_button(array $params, array $button_attributes=array()) : void
{
// Note that until IE supports the form attribute on the button tag, we can't
// use a