/** Submits the e-mail and redirects based on validation. */
 public function submit($language = L::Dutch)
 {
     // E-mail = NOT OK -> return to index with error message
     if (!$this->validate_email($language)) {
         $this->index($language);
     } else {
         $email = $this->input->post('email');
         $code = $language . '/' . bin2hex(openssl_random_pseudo_bytes(8));
         $update = array('selfservicecode' => $code, 'selfservicetime' => input_datetime('+1 day'));
         $participants = $this->participantModel->get_participants_by_email($email);
         foreach ($participants as $p) {
             $this->participantModel->update_participant($p->id, $update);
             $parent_name = parent_name($p);
         }
         $message_data['name_parent'] = $parent_name;
         $message_data['url'] = 'selfservice/auth/' . $code;
         $message = $this->load->view('mail/selfservice', $message_data, TRUE);
         $this->email->clear();
         $this->email->from(FROM_EMAIL, FROM_EMAIL_NAME);
         $this->email->to(in_development() ? TO_EMAIL_OVERRIDE : $email);
         $this->email->subject(lang('selfservice_mail_subject'));
         $this->email->message($message);
         $this->email->send();
         flashdata(sprintf(lang('selfservice_mail_sent'), $email));
         redirect('selfservice');
     }
 }
echo form_open('testinvite/manual_reminder_submit/' . $testinvite->id, array('class' => 'pure-form'));
?>

<p>
	U gaat een herinnering versturen aan <strong><?php 
echo name($participant);
?>
</strong> voor de vragenlijst <strong><?php 
echo testsurvey_name($testsurvey);
?>
</strong>.
</p>
<p>
	Alvorens een handmatige herinnering te sturen is het te prefereren de ouder van de proefpersoon te bellen.
	<?php 
echo sprintf(lang('call_contact'), $participant->firstname, parent_name($participant));
?>
</p>
<table class="pure-table">
	<tr>
		<th><?php 
echo lang('phone');
?>
</th>
		<td><?php 
echo $participant->phone;
?>
</td>
	</tr>
	<?php 
if (!empty($participant->phonealt)) {
 /** Submits the registration of a participant */
 public function register_submit($language)
 {
     // Reset the language
     reset_language($language);
     // Run validation
     if (!$this->validate_participant(TRUE)) {
         // If not succeeded, show form again with error messages
         $this->register($language);
     } else {
         // If succeeded, create the pariticipant
         $participant = $this->post_participant();
         $participant_id = $this->participantModel->add_participant($participant);
         // Add the (possible) comment
         $comment = $this->post_comment($participant_id);
         if ($comment) {
             $this->commentModel->add_comment($comment);
         }
         // Don't activate on registration (let admins decide)
         $this->participantModel->deactivate($participant_id, DeactivateReason::NewParticipant);
         $p = $this->participantModel->get_participant_by_id($participant_id);
         // Send confirmation e-mail to participant
         $this->email->clear();
         $this->email->from(FROM_EMAIL, FROM_EMAIL_NAME);
         $this->email->to(in_development() ? TO_EMAIL_OVERRIDE : $p->email);
         $this->email->subject(lang('reg_subject'));
         $message = '<p>' . sprintf(lang('mail_heading'), parent_name($p)) . '</p>';
         $message .= sprintf(lang('reg_thanks'), name($p));
         $message .= sprintf(lang('reg_body'), gender_child($p->gender), $p->firstname);
         $message .= lang('reg_ending');
         $message .= lang('mail_disclaimer');
         $this->email->message($message);
         $this->email->send();
         // Send an e-mail to all admins to activate
         $url = $this->config->site_url() . 'participant/get/' . $participant_id;
         $users = $this->userModel->get_all_admins();
         foreach ($users as $user) {
             reset_language(user_language($user));
             $this->email->clear();
             $this->email->from(FROM_EMAIL, FROM_EMAIL_NAME);
             $this->email->to(in_development() ? TO_EMAIL_OVERRIDE : $user->email);
             $this->email->subject(lang('reg_pp_subject'));
             $message = sprintf(lang('mail_heading'), $user->username);
             $message .= br(2);
             $message .= sprintf(lang('reg_pp_body'), name($p), $p->phone, $url, $url);
             $message .= br(2);
             $message .= lang('mail_ending');
             $message .= br(2);
             $message .= lang('mail_disclaimer');
             $this->email->message($message);
             $this->email->send();
         }
         // Display success
         $url = $language === L::English ? '/signup_finished/' : '/aanmelden_afgerond/';
         redirect($url, 'refresh');
     }
 }
 /**
  * This method creates an e-mail by referring to a view and replacing the variables. 
  * TODO: refactor to use less parameters (all in one array)?
  */
 function email_replace($view, $participant = NULL, $participation = NULL, $experiment = NULL, $testinvite = NULL, $comb_experiment = NULL, $auto = FALSE, $message = "", $language = L::Dutch)
 {
     $CI =& get_instance();
     $user = $CI->userModel->get_user_by_id(current_user_id());
     reset_language($language);
     $message_data = array();
     $message_data['auto'] = $auto;
     $message_data['message'] = $message;
     $message_data['combination'] = FALSE;
     $message_data['longitudinal'] = FALSE;
     $message_data['survey_link'] = FALSE;
     if ($user) {
         $message_data['user_username'] = $user->username;
         $message_data['user_email'] = $user->email;
     }
     if ($participant) {
         $message_data['name'] = name($participant);
         $message_data['name_first'] = $participant->firstname;
         $message_data['name_parent'] = parent_name($participant);
         $message_data['gender'] = gender_child($participant->gender);
         $message_data['gender_pos'] = gender_pos($participant->gender);
         $message_data['gender_plural'] = gender_sex($participant->gender) . 's';
         $message_data['phone'] = $participant->phone;
     }
     if ($participation) {
         $leader = $CI->userModel->get_user_by_id($participation->user_id_leader);
         $message_data['appointment'] = format_datetime($participation->appointment);
         if ($leader) {
             $message_data['leader_name'] = $leader->firstname;
         }
     }
     if ($experiment) {
         $location = $CI->locationModel->get_location_by_experiment($experiment);
         $message_data['exp_name'] = $experiment->name;
         $message_data['type'] = $experiment->type;
         $message_data['duration'] = $experiment->duration;
         $message_data['duration_total'] = $experiment->duration + INSTRUCTION_DURATION;
         $message_data['description'] = $experiment->description;
         $message_data['location'] = sprintf('%s (%s)', $location->name, $location->roomnumber);
         $message_data['caller_contacts'] = extract_callers($experiment, $comb_experiment);
     }
     if ($comb_experiment) {
         $location = $CI->locationModel->get_location_by_experiment($comb_experiment);
         $comb_participation = $CI->participationModel->get_participation($comb_experiment->id, $participant->id);
         $relation = $CI->relationModel->get_relation_by_experiments($experiment->id, $comb_experiment->id);
         $message_data['combination'] = $relation->relation === RelationType::Combination;
         $message_data['longitudinal'] = $relation->relation === RelationType::Prerequisite;
         $message_data['comb_exp_name'] = $comb_experiment->name;
         $message_data['comb_type'] = $comb_experiment->type;
         $message_data['comb_duration'] = $comb_experiment->duration;
         $message_data['comb_duration_total'] = $comb_experiment->duration + INSTRUCTION_DURATION;
         $message_data['comb_description'] = $comb_experiment->description;
         $message_data['comb_location'] = sprintf('%s (%s)', $location->name, $location->roomnumber);
         $message_data['comb_appointment'] = format_datetime($comb_participation->appointment);
     }
     if ($participant && $experiment) {
         $data = get_min_max_days($participant, $experiment);
         $message_data['min_date'] = format_date($data['min_date_js']);
         $message_data['max_date'] = format_date($data['max_date_js']);
     }
     if ($testinvite) {
         $test = $CI->testInviteModel->get_test_by_testinvite($testinvite);
         $testsurvey = $CI->testInviteModel->get_testsurvey_by_testinvite($testinvite);
         $message_data['survey_name'] = testsurvey_name($testsurvey);
         $message_data['survey_link'] = survey_link($testsurvey->limesurvey_id, $testinvite->token);
         $message_data['results_link'] = results_link($test->code, $testinvite->token);
         $message_data['whennr'] = $testsurvey->whennr;
     }
     return $CI->load->view($view, $message_data, TRUE);
 }
		</div>
	</div>

	<!-- Contact details -->
	<?php 
echo heading(lang('contact_details'), 3);
?>
	<div>
		<table class="pure-table">
			<tr>
				<th><?php 
echo lang('parent_name');
?>
</th>
				<td><?php 
echo parent_name($participant);
?>
</td>
			</tr>
			<tr>
				<th><?php 
echo lang('phone');
?>
</th>
				<td><?php 
echo $participant->phone;
?>
</td>
			</tr>
			<tr>
				<th><?php 
			<th><?php 
echo lang('participant');
?>
</th>
			<td><?php 
echo is_leader() ? $participant->firstname : participant_get_link($participant);
?>
</td>
		</tr>
		<tr>
			<th><?php 
echo lang('parent');
?>
</th>
			<td><?php 
echo is_leader() ? $participant->parentfirstname : parent_name($participant);
?>
</td>
		</tr>
		<tr>
			<th><?php 
echo lang('experiment');
?>
</th>
			<td><?php 
echo experiment_get_link($experiment);
?>
</td>
		</tr>
		<?php 
if ($leader) {