Activities.php 3.46 KB
Newer Older
François Jacquet's avatar
François Jacquet committed
1
<?php
2

François Jacquet's avatar
François Jacquet committed
3 4
DrawHeader( ProgramTitle() );

François Jacquet's avatar
François Jacquet committed
5 6
// Add eventual Dates to $_REQUEST['values'].
AddRequestedDates( 'values', 'post' );
François Jacquet's avatar
François Jacquet committed
7

François Jacquet's avatar
François Jacquet committed
8
if ( $_REQUEST['modfunc'] === 'update'
9
	&& ! empty( $_POST['values'] )
10
	&& AllowEdit() )
François Jacquet's avatar
François Jacquet committed
11
{
12
	foreach ( (array) $_REQUEST['values'] as $id => $columns )
13
	{
François Jacquet's avatar
François Jacquet committed
14
		if ( $id !== 'new' )
François Jacquet's avatar
François Jacquet committed
15 16
		{
			$sql = "UPDATE ELIGIBILITY_ACTIVITIES SET ";
17

18
			foreach ( (array) $columns as $column => $value )
François Jacquet's avatar
François Jacquet committed
19
			{
20
				$sql .= DBEscapeIdentifier( $column ) . "='" . $value . "',";
François Jacquet's avatar
François Jacquet committed
21
			}
22 23 24

			$sql = mb_substr( $sql, 0, -1 ) . " WHERE ID='" . $id . "'";
			DBQuery( $sql );
François Jacquet's avatar
François Jacquet committed
25
		}
26

François Jacquet's avatar
François Jacquet committed
27 28
		// New: check for Title
		elseif ( $columns['TITLE'] )
François Jacquet's avatar
François Jacquet committed
29 30 31 32
		{
			$sql = "INSERT INTO ELIGIBILITY_ACTIVITIES ";

			$fields = 'ID,SCHOOL_ID,SYEAR,';
33
			$values = db_seq_nextval( 'eligibility_activities_id_seq' ) . ",'" . UserSchool() . "','" . UserSyear() . "',";
François Jacquet's avatar
François Jacquet committed
34 35

			$go = 0;
36 37

			foreach ( (array) $columns as $column => $value )
François Jacquet's avatar
François Jacquet committed
38
			{
39
				if ( ! empty( $value ) || $value == '0' )
François Jacquet's avatar
François Jacquet committed
40
				{
41 42
					$fields .= DBEscapeIdentifier( $column ) . ',';
					$values .= "'" . $value . "',";
François Jacquet's avatar
François Jacquet committed
43 44 45
					$go = true;
				}
			}
46

47
			$sql .= '(' . mb_substr( $fields, 0, -1 ) . ') values(' . mb_substr( $values, 0, -1 ) . ')';
48

49 50 51 52
			if ( $go )
			{
				DBQuery( $sql );
			}
François Jacquet's avatar
François Jacquet committed
53 54 55
		}
	}

François Jacquet's avatar
François Jacquet committed
56 57 58
	// Unset modfunc & redirect URL.
	RedirectURL( 'modfunc' );
}
François Jacquet's avatar
François Jacquet committed
59

François Jacquet's avatar
François Jacquet committed
60 61
if ( $_REQUEST['modfunc'] === 'remove'
	&& AllowEdit() )
François Jacquet's avatar
François Jacquet committed
62
{
63
	if ( DeletePrompt( _( 'Activity' ) ) )
François Jacquet's avatar
François Jacquet committed
64
	{
François Jacquet's avatar
François Jacquet committed
65 66
		DBQuery( "DELETE FROM ELIGIBILITY_ACTIVITIES
			WHERE ID='" . $_REQUEST['id'] . "'" );
67

François Jacquet's avatar
François Jacquet committed
68 69
		// Unset modfunc & ID & redirect URL.
		RedirectURL( array( 'modfunc', 'id' ) );
François Jacquet's avatar
François Jacquet committed
70 71 72
	}
}

François Jacquet's avatar
François Jacquet committed
73
if ( ! $_REQUEST['modfunc'] )
François Jacquet's avatar
François Jacquet committed
74
{
75
	$sql = "SELECT ID,TITLE,START_DATE,END_DATE,COMMENT
76 77 78 79
	FROM ELIGIBILITY_ACTIVITIES
	WHERE SYEAR='" . UserSyear() . "'
	AND SCHOOL_ID='" . UserSchool() . "'
	ORDER BY TITLE";
80

François Jacquet's avatar
François Jacquet committed
81 82 83 84 85 86
	$activities_RET = DBGet(
		DBQuery( $sql ),
		array(
			'TITLE' => '_makeTextInput',
			'START_DATE' => '_makeDateInput',
			'END_DATE' => '_makeDateInput',
87
			'COMMENT' => '_makeTextInput',
François Jacquet's avatar
François Jacquet committed
88 89 90 91 92 93 94
		)
	);

	$columns = array(
		'TITLE' => _( 'Title' ),
		'START_DATE' => _( 'Begins' ),
		'END_DATE' => _( 'Ends' ),
95
		'COMMENT' => _( 'Comment' ),
François Jacquet's avatar
François Jacquet committed
96 97 98 99 100 101
	);

	$link['add']['html'] = array(
		'TITLE' => _makeTextInput( '', 'TITLE' ),
		'START_DATE' => _makeDateInput( '', 'START_DATE' ),
		'END_DATE' => _makeDateInput( '', 'END_DATE' ),
102
		'COMMENT' => _makeTextInput( '', 'COMMENT' ),
François Jacquet's avatar
François Jacquet committed
103 104
	);

105
	$link['remove']['link'] = 'Modules.php?modname=' . $_REQUEST['modname'] . '&modfunc=remove';
François Jacquet's avatar
François Jacquet committed
106

107
	$link['remove']['variables'] = array( 'id' => 'ID' );
108

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

111
	DrawHeader( '', SubmitButton() );
112

113
	ListOutput( $activities_RET, $columns, 'Activity', 'Activities', $link );
114 115

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

118 119 120 121
/**
 * @param $value
 * @param $name
 */
François Jacquet's avatar
François Jacquet committed
122 123 124 125
function _makeTextInput( $value, $name )
{
	global $THIS_RET;

126
	$extra = 'maxlength=100';
127

128
	if ( ! empty( $THIS_RET['ID'] ) )
François Jacquet's avatar
François Jacquet committed
129
	{
François Jacquet's avatar
François Jacquet committed
130
		$id = $THIS_RET['ID'];
François Jacquet's avatar
François Jacquet committed
131 132 133 134 135 136

		if ( $name === 'TITLE' )
		{
			$extra .= ' required';
		}
	}
François Jacquet's avatar
François Jacquet committed
137
	else
François Jacquet's avatar
François Jacquet committed
138
	{
François Jacquet's avatar
François Jacquet committed
139
		$id = 'new';
140
	}
141

142
	if ( $name === 'COMMENT' )
143 144
	{
		$extra .= ' size=20';
François Jacquet's avatar
François Jacquet committed
145
	}
146

François Jacquet's avatar
François Jacquet committed
147
	return TextInput( $value, 'values[' . $id . '][' . $name . ']', '', $extra );
François Jacquet's avatar
François Jacquet committed
148 149
}

150 151 152 153
/**
 * @param $value
 * @param $name
 */
François Jacquet's avatar
François Jacquet committed
154 155 156
function _makeDateInput( $value, $name )
{
	global $THIS_RET;
157

158
	if ( ! empty( $THIS_RET['ID'] ) )
François Jacquet's avatar
François Jacquet committed
159
	{
François Jacquet's avatar
François Jacquet committed
160
		$id = $THIS_RET['ID'];
François Jacquet's avatar
François Jacquet committed
161
	}
François Jacquet's avatar
François Jacquet committed
162
	else
François Jacquet's avatar
François Jacquet committed
163
	{
François Jacquet's avatar
François Jacquet committed
164
		$id = 'new';
François Jacquet's avatar
François Jacquet committed
165
	}
166

François Jacquet's avatar
François Jacquet committed
167
	return DateInput( $value, 'values[' . $id . '][' . $name . ']', '', true, ( $id === 'new' ) );
François Jacquet's avatar
François Jacquet committed
168
}