Registration.php 4.5 KB
Newer Older
François Jacquet's avatar
François Jacquet committed
1
<?php
2 3 4 5
/**
 * Registration
 * Admin can customize form for Parents.
 */
François Jacquet's avatar
François Jacquet committed
6

7
require_once 'ProgramFunctions/MarkDownHTML.fnc.php';
8
require_once 'ProgramFunctions/Fields.fnc.php';
François Jacquet's avatar
François Jacquet committed
9
require_once 'modules/Custom/includes/Registration.fnc.php';
10 11

$_REQUEST['student_id'] = UserStudentID();
12 13 14

DrawHeader( ProgramTitle() );

15
if ( User( 'PROFILE' ) === 'admin' )
16
{
François Jacquet's avatar
François Jacquet committed
17
	require_once 'modules/Custom/includes/RegistrationAdmin.fnc.php';
18

19 20 21 22 23 24 25 26
	if ( $_REQUEST['modfunc'] === 'save' )
	{
		$values = array(
			'parent' => $_REQUEST['parent'],
			'address' => issetVal( $_REQUEST['address'], array() ),
			'contact' => issetVal( $_REQUEST['contact'], array() ),
			'student' => issetVal( $_REQUEST['student'], array() ),
		);
27

28 29 30 31
		if ( RegistrationFormConfigSave( $values ) )
		{
			$note[] = button( 'check' ) . '&nbsp;' . _( 'The Registration form was saved.' );
		}
32

33 34 35
		// Delete modfunc, values & redirect URL.
		RedirectURL( array( 'modfunc', 'parent', 'address', 'contact', 'student' ) );
	}
36

37 38 39 40
	if ( $_REQUEST['modfunc'] === 'preview' )
	{
		// Back header.
		DrawHeader( RegistrationAdminPreviewHeader() );
François Jacquet's avatar
François Jacquet committed
41

42
		DrawHeader( RegistrationIntroHeader() );
43

44
		echo '<br />';
45

46
		echo PopTable( 'header', _( 'Registration' ) );
47

48
		$config = RegistrationFormConfig();
François Jacquet's avatar
François Jacquet committed
49

50
		RegistrationFormOutput( $config );
François Jacquet's avatar
François Jacquet committed
51

52 53
		echo PopTable( 'footer' );
	}
54

55
	if ( ! $_REQUEST['modfunc'] )
François Jacquet's avatar
François Jacquet committed
56
	{
57
		echo ErrorMessage( $note, 'note' );
58

59
		echo ErrorMessage( $error );
60

61
		echo '<form action="' . URLEscape( 'Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=save' ) . '" method="POST">';
62

63 64
		// Preview header.
		DrawHeader( RegistrationAdminPreviewHeader(), SubmitButton() );
65

66
		echo '<br />';
67

68
		PopTable( 'header', _( 'Configuration' ) );
69

70
		$config = RegistrationFormConfig();
71

72
		RegistrationAdminFormOutput( $config );
73

74
		PopTable( 'footer' );
75

76
		echo '<br /><div class="center">' . SubmitButton() . '</div></form>';
François Jacquet's avatar
François Jacquet committed
77
	}
78
}
François Jacquet's avatar
François Jacquet committed
79

80 81 82
else
{
	if ( $_REQUEST['modfunc'] === 'save' )
François Jacquet's avatar
François Jacquet committed
83
	{
François Jacquet's avatar
François Jacquet committed
84
		require_once 'modules/Custom/includes/RegistrationSave.fnc.php';
François Jacquet's avatar
François Jacquet committed
85

86 87
		// Add eventual Dates to $_REQUEST['parent'].
		AddRequestedDates( 'parent' );
François Jacquet's avatar
François Jacquet committed
88

89 90
		// Add eventual Dates to $_REQUEST['address'].
		AddRequestedDates( 'address' );
François Jacquet's avatar
François Jacquet committed
91

92 93
		// Add eventual Dates to $_REQUEST['contact'].
		AddRequestedDates( 'contact' );
François Jacquet's avatar
François Jacquet committed
94

95 96
		// Add eventual Dates to $_REQUEST['students'].
		AddRequestedDates( 'students' );
97

98 99 100 101 102 103
		$values = array(
			'parent' => issetVal( $_REQUEST['parent'], array() ),
			'address' => issetVal( $_REQUEST['address'], array() ),
			'contact' => issetVal( $_REQUEST['contact'], array() ),
			'student' => issetVal( $_REQUEST['students'], array() ),
		);
104

105
		$config = RegistrationFormConfig();
106

107 108
		if ( ! empty( $_REQUEST['sibling_use_contacts_address'] )
			&& ! empty( $_REQUEST['sibling_id'] ) )
109
		{
110
			$save_ok = RegistrationSaveSibling( $config, $values, $_REQUEST['sibling_id'] );
111 112 113
		}
		else
		{
114
			$save_ok = RegistrationSave( $config, $values );
115 116
		}

117
		if ( $save_ok )
118
		{
119 120 121
			// @todo Move to ProgramFunctions/SendNotification.fnc.php.
			// Send New Registration email to Notify.
			if ( filter_var( $RosarioNotifyAddress, FILTER_VALIDATE_EMAIL ) )
122
			{
123
				require_once 'ProgramFunctions/SendEmail.fnc.php';
124

125 126 127
				$student_name = DBGetOne( "SELECT " . DisplayNameSQL() . " AS FULL_NAME
					FROM STUDENTS
					WHERE STUDENT_ID='" . UserStudentID() . "'" );
128

129 130 131 132 133 134
				$message = sprintf(
					_( 'New Registration %s (%d) has been registered by %s.' ),
					$student_name,
					UserStudentID(),
					User( 'NAME' )
				);
135

136
				SendEmail( $RosarioNotifyAddress, _( 'New Registration' ), $message );
137
			}
François Jacquet's avatar
François Jacquet committed
138 139
		}

140 141
		// Delete modfunc, values & redirect URL.
		RedirectURL( array( 'modfunc', 'parent', 'address', 'contact', 'student' ) );
François Jacquet's avatar
François Jacquet committed
142 143
	}

144 145 146
	$registration_done = DBGetOne( "SELECT 1
		FROM STUDENTS_JOIN_ADDRESS
		WHERE STUDENT_ID='" . UserStudentID() . "'" );
147

148 149
	// Registration check.
	if ( $registration_done )
150
	{
151 152 153 154
		$note[] = button( 'check' ) . ' ' .
			( User( 'STAFF_ID' ) ?
				_( 'Your child has been registered.' ) :
				_( 'Your parents have been registered.' ) );
155

156
		echo ErrorMessage( $note, 'note' );
157 158
	}

159 160
	if ( ! $_REQUEST['modfunc']
		&& ! $registration_done )
161
	{
162
		$_ROSARIO['allow_edit'] = true;
163

164
		echo ErrorMessage( $error );
165

166
		echo '<form action="' . URLEscape( 'Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=save' ) . '" method="POST">';
167

168
		DrawHeader( RegistrationIntroHeader(), SubmitButton() );
169

170
		echo '<br />';
171

172
		echo PopTable( 'header', _( 'Registration' ) );
François Jacquet's avatar
François Jacquet committed
173

174
		$config = RegistrationFormConfig();
175

176
		RegistrationFormOutput( $config );
177

178
		echo PopTable( 'footer' );
179

180
		echo '<br /><div class="center">' . SubmitButton() . '</div></form>';
François Jacquet's avatar
François Jacquet committed
181 182
	}
}