-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrumun.module
executable file
·421 lines (381 loc) · 18.5 KB
/
drumun.module
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
<?php
function drumun_init() {
global $user;
if($user->uid > 0 && !db_result(db_query('SELECT COUNT(*) FROM {comments} WHERE uid = %d', $user->uid))) {
drupal_set_message('It looks like you haven\'t posted anything yet. Please take a minute to post an introduction for yourself at the topic for introductions in your section.', 'error');
}
}
function drumun_menu_alter(&$items) {
//remove the extremely unprofessional 'node' page
$items['node']['access callback'] = FALSE;
}
/*
* Realname module support for this module.
*/
function realname_drumun_get_fields($current) {
$fields = $links = array();
foreach($items as $name) {
$selected = array_key_exists($name, $current);
$fields[$name] = array(
'title' => $field['title'],
'weight' => $selected ? $current[$name] : 0,
'selected' => $selected,
);
}
return array('fields' => $fields, 'links' => $links);
}
function drumun_load_profile(&$user) {
static $cache = array();
if(!isset($cache[$user->uid])) {
$result = db_query('SELECT * FROM {drumun_information} WHERE uid = %d', $user->uid);
while ($ret = db_fetch_array($result)) {
$user->MUN = $ret;
$cache[$user->uid] = $ret;
}
} else {
$user->MUN = $cache[$user->uid];
}
}
function drumun_save_profile(&$edit, &$user, $register = FALSE) {
if ($edit['nickname'] == '') $edit['nickname'] = $edit['fname'];
$test->uid = $user->uid;
$test->fname = $edit['fname'];
$test->lname = $edit['lname'];
$test->nickname = $edit['nickname'];
$test->delegation = $edit['delegation'];
$test->committee = $edit['committee'];
if ($register || user_access('modify user information')) {
if ($register || !drupal_write_record('drumun_information', $test, 'uid')) {
drupal_write_record('drumun_information', $test);
}
//change role
$rid = db_result(db_query("SELECT rid FROM {role} WHERE name='%s'", $edit['committee']));
//checks range to make sure it's within the roles we want to update
for($i = 5; $i <= 14; $i++) {
unset($edit['roles'][$i]);
}
$edit['roles'][$rid] = TRUE;
// Mark fields as handled (prevents saving to user->data).
$edit['fname'] = NULL;
$edit['lname'] = NULL;
$edit['nickname'] = NULL;
$edit['committee'] = NULL;
$edit['delegation'] = NULL;
drumun_build_signature($user);
drumun_build_realname($user);
}
}
function drumun_build_realname($user) {
//can't use _once because the other one takes priority and this one gets skipped
//thus making $delegations and $committees equal to NULL
require('drumun.arrays.inc');
//build
drumun_load_profile($user);
if ($user->MUN['committee'] != 'NONE') {
$text = $user->MUN['committee'].' ';
}
if ($user->MUN['delegation'] != 'NONE') {
$text .= $user->MUN['delegation'].' ';
}
// Check for duplicate matches between people.
if (db_result(db_query("SELECT COUNT(*) FROM {drumun_realname} WHERE value = '%s'", $text.$user->MUN['fname']))) {
$text .= $user->MUN['nickname'];
} else {
$text .= $user->MUN['fname'];
}
if ($user->MUN['delegation'] == 'Forum Architect and Administrator' || $user->MUN['delegation'] == 'Tester' || $user->MUN['delegation'] == 'MUN Director' || $user->MUN['delegation'] == 'Board of Directors' || $user->MUN['delegation'] == 'Conference Management' || $user->MUN['delegation'] == 'Deputy Secretary General' || $user->MUN['delegation'] == 'Secretary General' || $user->MUN['delegation'] == 'President of the General Assembly') {
$text = $user->MUN['fname'].' '.$user->MUN['lname'];
}
//save to profile field
if (db_result(db_query("SELECT value FROM {drumun_realname} WHERE uid = %d", $user->uid)) != FALSE) {
db_query("UPDATE {drumun_realname} SET value='%s' WHERE uid = %d", array($text, $user->uid));
}
else {
db_query("INSERT INTO {drumun_realname} (uid, value) VALUES (%d, '%s')", array($user->uid, $text));
}
$result = db_query("SELECT u.uid, u.name, u.mail FROM {users} u WHERE uid >= %d ORDER BY uid ASC", $user->uid);
while ($row = db_fetch_object($result)) {
$realname->uid = $row->uid;
$realname->realname = realname_make_name($row);
// Try to update, if fail - try to insert.
if (!drupal_write_record('realname', $realname, 'uid')) {
drupal_write_record('realname', $realname);
}
}
}
function drumun_build_signature($user) {
//can't use _once because the other one takes priority and this one gets skipped
//thus making $delegations and $committees equal to NULL
require('drumun.arrays.inc');
$delegations = array_merge($delegations, $special);
//build
drumun_load_profile($user);
$del = $delegations[$user->MUN['delegation']];
$com = $committees[$user->MUN['committee']];
if($user->MUN['committee'] == 'Y1' || $user->MUN['committee'] == 'Y2') {
$arr = explode(' - ', $com);
$com = $arr[0];
$del = 'the Committee on ' . $arr[1];
}
$text = $user->MUN['fname'].' '.$user->MUN['lname'];
$text .= "\n";
if (!in_array($del, $special)) {
$text .= 'Delegate of '.$del;
$text .= "\n";
$text .= $com;
} elseif ($del == 'Deputy President' || $del == 'President' ||$del == 'Deputy Chair' || $del == 'Chair' || $del == 'President of the General Assembly' || $del == 'Coordinator' || $del == 'YA Adult Coordinator') {
$text .= $del;
if ($com != '(none)') {
$text .= ' of the ' . $com;
}
$text .= "\n";
$text .= 'Student Officer';
} else {
$text .= $del;
//Nicknames used as School field for MUN Directors
if ($del == 'MUN Director') $text .= "\n".$user->MUN['nickname'];
}
//save to signature database
if (db_result(db_query("SELECT uid FROM {users_signature} WHERE uid = %d", $user->uid)) != FALSE) {
db_query("UPDATE {users_signature} SET signature='%s' WHERE uid = %d", array($text, $user->uid));
}
else {
db_query("INSERT INTO {users_signature} (uid, signature) VALUES (%d, '%s')", array($user->uid, $text));
}
}
function drumun_form_profile($edit, $user, $register = FALSE) {
require_once('drumun.arrays.inc');
if (user_access('administer users')) {
$delegations = array_merge($delegations, $special);
}
$form = array();
$form['drumun'] = array(
'#title' => 'THIMUN Information',
'#type' => 'fieldset',
);
$form['drumun']['fname'] = array(
'#type' => 'textfield',
'#default_value' => isset($edit['drumun']['fname']) ? $edit['drumun']['fname'] : '',
'#title' => 'First Name',
'#maxlength' => '50',
'#required' => TRUE,
'#weight' => 1,
);
$form['drumun']['lname'] = array(
'#type' => 'textfield',
'#default_value' => isset($edit['drumun']['lname']) ? $edit['drumun']['lname'] : '',
'#title' => 'Last Name',
'#maxlength' => '50',
'#required' => TRUE,
'#weight' => 2,
);
$form['drumun']['nickname'] = array(
'#type' => 'textfield',
'#default_value' => isset($edit['drumun']['nickname']) ? $edit['drumun']['nickname'] : '',
'#title' => 'Nickname',
'#maxlength' => '50',
'#weight' => 3,
);
$form['drumun']['committee'] = array(
'#type' => 'select',
'#default_value' => isset($edit['drumun']['committee']) ? $edit['drumun']['committee'] : '',
'#title' => 'Committee',
'#options' => $committees,
'#required' => TRUE,
'#weight' => 4,
);
$form['drumun']['delegation'] = array(
'#type' => 'select',
'#default_value' => isset($edit['drumun']['delegation']) ? $edit['drumun']['delegation'] : '',
'#title' => 'Delegation',
'#options' => drupal_map_assoc(array_keys($delegations)),
'#required' => TRUE,
'#weight' => 5,
//ensure that it's not being filtered for the Ivory Coast one.
// ^^ that's being done in acquia_thimun's template.php
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function drumun_retrieve_fields($uid) {
$sql = 'SELECT * FROM {drumun_information} WHERE uid = %d';
$result = db_query($sql, $uid);
return db_fetch_array($result);
}
function drumun_perm() {
return array('modify user information');
}
function drumun_user($op, &$edit, &$account) {
switch ($op) {
case 'view':
if (user_access('modify user information')) {
$account->content['drumun_modify_info'] = array(
'#type' => 'markup',
'#value' => l(t('Modify this user\'s THIMUN information'), 'user/'.$account->uid.'/edit'),
'#weight' => 11,
'#prefix' => '<br />',
);
}
break;
case 'load':
$account->MUN = drumun_load_profile($account);
return;
case 'register':
return drumun_form_profile($edit, $account, TRUE);
case 'update':
return drumun_save_profile($edit, $account);
case 'insert':
return drumun_save_profile($edit, $account, TRUE);
/*case 'view':
return profile_view_profile($user);*/
case 'form':
return drumun_form_profile($edit, $account);
case 'validate':
return drumun_validate_profile($edit);
case 'delete':
db_query('DELETE FROM {drumun_information} WHERE uid = %d', $account->uid);
}
}
function drumun_form_alter(&$form, $form_state, $form_id) {
// Normally a switch is used because you may want to alter more than
// one form and it is easy to add a new case for each form.
switch ($form_id) {
// This is our form ID.
case 'user_profile_form':
//Prevent people from tampering with their profile after they have registered.
if (!user_access('modify user information')) {
unset($form['drumun']);
unset($form['signature_settings']);
$form['drumun'] = array(
'#title' => 'THIMUN Information',
'#type' => 'fieldset',
);
$form['drumun']['error'] = array(
'#value' => t('You may not change your THIMUN information. If the information we have is inaccurate, please request your MUN Director to send an email to [email protected] in order to verify the authenticity of the change.'),
);
unset($form['enable_pm_mail']);
}
break;
}
}
function drumun_switch_out_values($drumun) {
require_once 'drumun.arrays.inc';
foreach($drumun as $field => $values) {
if (is_array($values)) {
if($values['#type'] == 'select') {
switch($field) {
case variable_get('drumun_long_committee_field', NULL):
$values['#options'] = $committees;
break;
case variable_get('drumun_short_delegation_field', NULL):
$values['#options'] = array_keys($delegations);
break;
}
}
}
}
return $drumun;
}
function drumun_validate_profile($edit) {
$com = $edit['committee'];
$del = $edit['delegation'];
if (user_access('administer users')) {
require('drumun.arrays.inc');
// No checks for special people.
if (in_array($del, $special)) {
return $edit;
}
}
//check for nones
if($com == 'NONE') {
form_set_error('committee', t('All delegates must specify a committee. If you are not a delegate, please contact [email protected] to have your account created for you.'));
}
if(($com == 'Y1' || $com == 'Y2') && $del != 'NONE') {
form_set_error('delegation', t('Youth Assembly delegates may not specify a delegation. This field must be set to NONE.'));
} elseif (($com != 'Y1' && $com != 'Y2' && $com != 'NONE') && $del == 'NONE') {
form_set_error('delegation', t('Non Youth Assembly delegates must specify a delegation.'));
}
//check country allowances
$count = db_result(db_query('SELECT COUNT(*) FROM {drumun_information} WHERE committee="%s" AND delegation="%s" AND uid != %d', $com, $del, $edit['_account']->uid));
//all are in GA, but only 1 per country per delegation is allowed
if($com == '1' || $com == '2' || $com == '3' || $com == '5' || $com == '6') {
//for GA, the delegation arrays define who is denied.
$delegations_ga1 = array('Friends of the Earth','Greenpeace','FAO','IFAD','ILO','IMF','INSTRAW','OCHA','UNCTAD','UNCDF','UNDP','UNEP','UNESCO','UNFPA','UNICEF','UNIDO','WHO','World Bank','World Trade Organization');
if($com == '1' && in_array($del, $delegations_ga1)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the General Assembly First Committee.'));
}
$delegations_ga2 = array('Amnesty International','OCHA','UNFPA','WHO');
if($com == '2' && in_array($del, $delegations_ga2)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the General Assembly Second Committee.'));
}
$delegations_ga3 = array('Friends of the Earth','Greenpeace','IMF','UNEP','UNESCO','World Trade Organization');
if($com == '3' && in_array($del, $delegations_ga3)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the General Assembly Third Committee.'));
}
//TODO: check with JZ about ECA and GA4 misprint in handbook (pg11)
//that's right. no non-countries in GA5!
$delegations_ga5 = array('Holy See','Palestinian Authority','Amnesty International','Friends of the Earth','Greenpeace','Human Rights Watch','ECA','ESCAP','ESCWA','FAO','IFAD','ILO','IMF','INSTRAW','OCHA','UNCTAD','UNCDF','UNDP','UNEP','UNESCO','UNFPA','UNHCHR','UNICEF','UNIDO','WHO','World Bank','World Trade Organization');
if($com == '5' && in_array($del, $delegations_ga5)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the General Assembly Fifth Committee.'));
}
//same with GA6
$delegations_ga6 = array('Holy See','Palestinian Authority','Amnesty International','Friends of the Earth','Greenpeace','Human Rights Watch','ECA','ESCAP','ESCWA','FAO','IFAD','ILO','IMF','INSTRAW','OCHA','UNCTAD','UNCDF','UNDP','UNEP','UNESCO','UNFPA','UNHCHR','UNICEF','UNIDO','WHO','World Bank','World Trade Organization');
if($com == '6' && in_array($del, $delegations_ga6)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the General Assembly Sixth Committee.'));
}
if($count != 0) {
form_set_error('delegation', t('The delegation you have selected already has a person in that committee. If this is an error, please ask your MUN Director to contact [email protected].'));
}
}
//SC
$sc = array('Austria', 'Burkina Faso', 'Costa Rica', 'Croatia', 'Japan', 'Libya', 'Mexico', 'Turkey', 'Uganda', 'Viet Nam', 'China', 'France', 'Russia', 'United Kingdom', 'United States of America');
if($com == 'S') {
if(!in_array($del, $sc)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the Security Council.'));
}
if($count+1 > 2) {
form_set_error('delegation', t('The delegation that you have selected has reached the maximum number of members it can send to the Security Council.'));
}
}
//Eco
$countries_eco = array('Algeria', 'Barbados', 'Belarus', 'Bolivia', 'Brazil', 'Cameroon', 'Cape Verde', 'China', 'Congo', 'Côte d\'Ivoire', 'El Salvador', 'Estonia', 'France', 'Germany', 'Greece', 'Guatemala', 'Guinea-Bissau', 'India', 'Indonesia', 'Iraq', 'Japan', 'Kazakhstan', 'Liechtenstein', 'Luxembourg', 'Malawi', 'Malaysia', 'Mauritius', 'Moldova', 'Morocco', 'Mozambique', 'Namibia', 'Netherlands', 'New Zealand', 'Niger', 'Norway', 'Pakistan', 'Peru', 'Philippines', 'Poland', 'Portugal', 'Rep. Korea', 'Romania', 'Russia', 'Saint Kitts & Nevis', 'Saint Lucia', 'Saudi Arabia', 'Somalia', 'Sudan', 'Sweden', 'United Kingdom', 'United States of America', 'Uruguay', 'Venezuela');
if($com == 'E') {
if(!in_array($del, $countries_eco)) {
$delegations_eco = array('Holy See','Palestinian Authority','Amnesty International','Friends of the Earth','Greenpeace','Human Rights Watch','ECA','ESCAP','ESCWA','FAO','IFAD','ILO','IMF','INSTRAW','OCHA','UNCTAD','UNCDF','UNDP','UNEP','UNESCO','UNFPA','UNHCHR','UNICEF','UNIDO','WHO','World Bank','World Trade Organization');
if(!in_array($del, $delegations_eco)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the ECOSOC.'));
} elseif($count+1 > 1) {
form_set_error('delegation', t('The delegation that you have selected has reached the maximum number of members it can send to the ECOSOC.'));
}
} elseif($count+1 > 2) {
form_set_error('delegation', t('The delegation that you have selected has reached the maximum number of members it can send to the ECOSOC.'));
}
}
//csd
$countries_csd = array('Antigua & Barbuda', 'Australia', 'Bahrain', 'Belarus', 'Belgium', 'Belize', 'Bolivia', 'Cameroon', 'Canada', 'Cape Verde', 'Chile', 'China', 'Costa Rica', 'Croatia', 'Cuba', 'Czech Republic', 'DPR Korea', 'DR Congo', 'Djibouti', 'France', 'Gambia', 'Germany', 'Guatemala', 'Guinea', 'Haiti', 'India', 'Indonesia', 'Iran', 'Israel', 'Italy', 'Japan', 'Kuwait', 'Mexico', 'Monaco', 'Netherlands', 'Peru', 'Poland', 'Portugal', 'Rep. Korea', 'Russia', 'Saudi Arabia', 'Senegal', 'Serbia', 'South Africa', 'Spain', 'Sudan', 'Sweden', 'Thailand', 'Tunisia', 'United Kingdom', 'United States of America', 'Tanzania', 'Zambia', 'Zimbabwe');
if($com == 'C') {
if(!in_array($del, $countries_csd)) {
$delegations_csd = array('Holy See','Palestinian Authority','Amnesty International','Friends of the Earth','Greenpeace','ECA','ESCAP','ESCWA','FAO','IFAD','ILO','IMF','INSTRAW','OCHA','UNCTAD','UNCDF','UNDP','UNEP','UNFPA','UNIDO','WHO','World Bank','World Trade Organization');
if(!in_array($del, $delegations_csd)) {
form_set_error('delegation', t('The delegation that you have selected is not a member of the Commission on Sustainable Development.'));
} elseif($count+1 > 1) {
form_set_error('delegation', t('The delegation that you have selected has reached the maximum number of members it can send to the Commission on Sustainable Development.'));
}
} elseif($count+1 > 2) {
form_set_error('delegation', t('The delegation that you have selected has reached the maximum number of members it can send to the Commission on Sustainable Development.'));
}
}
//ICJ and APQ
if($com == 'I') {
form_get_errors();
form_set_error('committee', t('Delegates in the International Court of Justice should not use this forum as a tool for communicating with other delegates. Instead, they should enroll themselves in the mailing list for this committee by contacting their president.'));
}
if($com == 'A') {
form_get_errors();
form_set_error('committee', t('Delegates in the Advisory Panel on the Question of Central Asia should not use this forum as a tool for communicating with other delegates. Instead, they should enroll themselves in the mailing list for this committee by contacting their president.'));
}
return $edit;
}