/
PeopleFields.php
268 lines (223 loc) · 6.18 KB
/
PeopleFields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/**
* People Fields
*
* @package RosarioSIS
* @subpackage modules
*/
if ( isset( $_POST['tables'] )
&& is_array( $_POST['tables'] )
&& AllowEdit() )
{
$table = issetVal( $_REQUEST['table'] );
foreach ( (array) $_REQUEST['tables'] as $id => $columns )
{
// FJ fix SQL bug invalid sort order.
if ( ( empty( $columns['SORT_ORDER'] )
|| is_numeric( $columns['SORT_ORDER'] ) )
&& ( empty( $columns['COLUMNS'] )
|| is_numeric( $columns['COLUMNS'] ) ) )
{
// FJ added SQL constraint TITLE is not null.
if ( ! isset( $columns['TITLE'] )
|| ! empty( $columns['TITLE'] ) )
{
if ( isset( $columns['SELECT_OPTIONS'] )
&& $columns['SELECT_OPTIONS'] )
{
// @since 6.0 Trim select Options.
$columns['SELECT_OPTIONS'] = trim( $columns['SELECT_OPTIONS'] );
}
// Update Field / Category.
if ( $id !== 'new' )
{
if ( isset( $columns['CATEGORY_ID'] )
&& $columns['CATEGORY_ID'] != $_REQUEST['category_id'] )
{
$_REQUEST['category_id'] = $columns['CATEGORY_ID'];
}
$sql = 'UPDATE ' . DBEscapeIdentifier( $table ) . ' SET ';
foreach ( (array) $columns as $column => $value )
{
$sql .= DBEscapeIdentifier( $column ) . "='" . $value . "',";
}
$sql = mb_substr( $sql, 0, -1 ) . " WHERE ID='" . $id . "'";
$go = true;
}
// New Field / Category.
else
{
$sql = 'INSERT INTO ' . DBEscapeIdentifier( $table ) . ' ';
// New Field.
if ( $table === 'PEOPLE_FIELDS' )
{
if ( isset( $columns['CATEGORY_ID'] ) )
{
$_REQUEST['category_id'] = $columns['CATEGORY_ID'];
unset( $columns['CATEGORY_ID'] );
}
$_REQUEST['id'] = AddDBField( 'PEOPLE', 'people_fields_id_seq', $columns['TYPE'] );
$fields = 'ID,CATEGORY_ID,';
$values = $_REQUEST['id'] . ",'" . $_REQUEST['category_id'] . "',";
}
// New Category.
elseif ( $table === 'PEOPLE_FIELD_CATEGORIES' )
{
$id = DBSeqNextID( 'people_field_categories_id_seq' );
$fields = "ID,";
$values = $id . ",";
$_REQUEST['category_id'] = $id;
}
$go = false;
foreach ( (array) $columns as $column => $value )
{
if ( ! empty( $value )
|| $value == '0' )
{
$fields .= DBEscapeIdentifier( $column ) . ',';
$values .= "'" . $value . "',";
$go = true;
}
}
$sql .= '(' . mb_substr( $fields, 0, -1 ) . ') values(' . mb_substr( $values, 0, -1 ) . ')';
}
if ( $go )
{
DBQuery( $sql );
}
}
else
$error[] = _( 'Please fill in the required fields' );
}
else
$error[] = _( 'Please enter valid Numeric data.' );
}
// Unset tables & redirect URL.
RedirectURL( 'tables' );
}
// Delete Field / Category.
if ( $_REQUEST['modfunc'] === 'delete'
&& AllowEdit() )
{
if ( isset( $_REQUEST['id'] )
&& intval( $_REQUEST['id'] ) > 0 )
{
if ( DeletePrompt( _( 'Contact Field' ) ) )
{
DeleteDBField( 'PEOPLE', $_REQUEST['id'] );
// Unset modfunc & ID & redirect URL.
RedirectURL( [ 'modfunc', 'id' ] );
}
}
elseif ( isset( $_REQUEST['category_id'] )
&& intval( $_REQUEST['category_id'] ) > 0 )
{
if ( DeletePrompt( _( 'Contact Field Category' ) . ' ' .
_( 'and all fields in the category' ) ) )
{
DeleteDBFieldCategory( 'PEOPLE', $_REQUEST['category_id'] );
// Unset modfunc & category ID & redirect URL.
RedirectURL( [ 'modfunc', 'category_id' ] );
}
}
}
if ( ! $_REQUEST['modfunc'] )
{
echo ErrorMessage( $error );
// Category menu: student|address|contact.
DrawHeader( _fieldsCategoryMenu( $_REQUEST['category'] ) );
$RET = [];
// ADDING & EDITING FORM.
if ( $_REQUEST['id']
&& $_REQUEST['id'] !== 'new' )
{
$RET = DBGet( "SELECT ID,CATEGORY_ID,TITLE,TYPE,SELECT_OPTIONS,
DEFAULT_SELECTION,SORT_ORDER,REQUIRED,
(SELECT TITLE
FROM PEOPLE_FIELD_CATEGORIES
WHERE ID=CATEGORY_ID) AS CATEGORY_TITLE
FROM PEOPLE_FIELDS
WHERE ID='" . $_REQUEST['id'] . "'" );
$RET = $RET[1];
$title = ParseMLField( $RET['CATEGORY_TITLE'] ) . ' - ' . ParseMLField( $RET['TITLE'] );
}
elseif ( $_REQUEST['category_id']
&& $_REQUEST['category_id'] !== 'new'
&& $_REQUEST['id'] !== 'new' )
{
$RET = DBGet( "SELECT ID AS CATEGORY_ID,TITLE,CUSTODY,EMERGENCY,SORT_ORDER
FROM PEOPLE_FIELD_CATEGORIES
WHERE ID='" . $_REQUEST['category_id'] . "'" );
$RET = $RET[1];
$title = ParseMLField( $RET['TITLE'] );
}
elseif ( $_REQUEST['id'] === 'new' )
{
$title = _( 'New Contact Field' );
$RET['ID'] = 'new';
$RET['CATEGORY_ID'] = issetVal( $_REQUEST['category_id'] );
}
elseif ( $_REQUEST['category_id'] === 'new' )
{
$title = _( 'New Contact Field Category' );
$RET['CATEGORY_ID'] = 'new';
}
if ( $_REQUEST['category_id']
&& ! $_REQUEST['id'] )
{
$extra_fields = [
'<table class="width-100p cellspacing-0"><tr class="st"><td>' .
CheckboxInput(
issetVal( $RET['CUSTODY'], '' ),
'tables[' . $_REQUEST['category_id'] . '][CUSTODY]',
_( 'Custody' ),
'',
$_REQUEST['category_id'] === 'new',
button( 'check' ),
button( 'x' )
) . '</td><td>' .
CheckboxInput(
issetVal( $RET['EMERGENCY'], '' ),
'tables[' . $_REQUEST['category_id'] . '][EMERGENCY]',
_( 'Emergency' ),
'',
$_REQUEST['category_id'] === 'new',
button( 'check' ),
button( 'x' )
) . '</td></tr></table>' .
FormatInputTitle(
_( 'Note: All unchecked means applies to all contacts' ),
'',
false,
''
)
];
}
echo GetFieldsForm(
'PEOPLE',
$title,
$RET,
issetVal( $extra_fields, [] )
);
// CATEGORIES.
$categories_RET = DBGet( "SELECT ID,TITLE,SORT_ORDER
FROM PEOPLE_FIELD_CATEGORIES
ORDER BY SORT_ORDER,TITLE" );
// DISPLAY THE MENU.
echo '<div class="st">';
FieldsMenuOutput( $categories_RET, $_REQUEST['category_id'] );
echo '</div>';
// FIELDS.
if ( $_REQUEST['category_id']
&& $_REQUEST['category_id'] !=='new'
&& $categories_RET )
{
$fields_RET = DBGet( "SELECT ID,TITLE,TYPE,SORT_ORDER
FROM PEOPLE_FIELDS
WHERE CATEGORY_ID='" . $_REQUEST['category_id'] . "'
ORDER BY SORT_ORDER,TITLE", [ 'TYPE' => 'MakeFieldType' ] );
echo '<div class="st">';
FieldsMenuOutput( $fields_RET, $_REQUEST['id'], $_REQUEST['category_id'] );
echo '</div>';
}
}