-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradebookapi.admin.inc
146 lines (130 loc) · 7.01 KB
/
gradebookapi.admin.inc
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
<?php
/**
* @file
* gradebookapi.admin.inc: Administration pages for gradebookapi
*/
function gradebookapi_admin_settings() {
$form = array();
drupal_set_title(t('Gradebook API configuration'));
node_type_cache_reset();
$default = array();
$node_types = gradebookapi_get_assignment_types();
if (!empty($node_types)) {
foreach ($node_types as $node_type) {
$default[$node_type] = $node_type;
}
}
$form['nodes'] = array(
'#type' => 'checkboxes',
'#title' => t('Assignment Types'),
'#multiple' => TRUE,
'#default_value' => $default,
'#options' => array_map('check_plain', node_type_get_names()),
'#description' => t('A list of node types you want to treat as assignments.'),
'#weight' => -10,
);
$intervals = array(
'+1 day' => t('1 day'),
'+1 week' => t('1 week'),
'+2 week' => t('2 weeks'),
'+1 month' => t('1 month'),
'+2 month' => t('2 months'),
'+3 month' => t('3 months'),
'+6 month' => t('6 months'),
'+1 year' => t('1 year'),
);
$form['gradebookapi_assignments_interval'] = array(
'#type' => 'radios',
'#options' => $intervals,
'#title' => t('Default time between creation of assignment node and due date'),
'#default_value' => variable_get('gradebookapi_assignments_interval', '+1 month'),
'#description' => t('This will be added to the current date to set the default due date.'),
'#required' => FALSE,
'#prefix' => '<div class="gradebookapi-radios">',
'#suffix' => '</div><div class="clear-block"></div>',
'#weight' => -8,
);
$usedateapi = module_exists('date_popup');
$form['gradebookapi_use_dateapi'] = array(
'#type' => 'checkbox',
'#title' => t('Use Date Popup for date selection'),
'#description' => $usedateapi ? t('The <em>Date Popup</em> module is enabled, check the box if you would like to use a Date Popup for date selection.') : t('The <em>Date Popup</em> module is not available. Install and enable it to access this feature.'),
'#default_value' => $usedateapi ? variable_get('gradebookapi_use_dateapi', FALSE) : FALSE,
'#disabled' => !$usedateapi,
'#weight' => -7,
);
$form['gradebookapi_assignments_date_format'] = array(
'#type' => 'textfield',
'#title' => t('Date format to use on gradebook page and block'),
'#default_value' => variable_get('gradebookapi_assignments_date_format', 'm/d/Y'),
'#description' => t('Define a php date format string like "m/d/Y". See <a href="@php-net-url">http://php.net/date</a> for more details.', array('@php-net-url' => url("http://php.net/date"))),
'#required' => FALSE,
'#weight' => -6,
);
$form['email'] = array(
'#type' => 'fieldset',
'#title' => t('Email Settings'),
'#description' => t('Email notifications sent to teachers and students.'),
'#weight' => 0,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['email']['gradebookapi_email_assignment'] = array(
'#type' => 'fieldset',
'#title' => t('Gradebook Assignments'),
'#description' => t('Send notification to teacher when a grade is entered or an assignment is posted.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['email']['gradebookapi_email_assignment']['gradebookapi_assignment_update_email_allowed'] = array(
'#type' => 'checkbox',
'#title' => t('Notify students by email when an assignment is published or modified.'),
'#default_value' => variable_get('gradebookapi_assignment_update_email_allowed', 0),
'#description' => t('Check this to send students an email whenever an assignment is published or modified. Note that students must must also enable the "Receive email notifications on assignment update" option on their user account page.')
);
$form['email']['gradebookapi_email_assignment']['gradebookapi_assignment_update_email_subject'] = array(
'#type' => 'textfield',
'#title' => t('Configure E-mail Subject'),
'#description' => t('This format will be used when sending the assignment update email notification.'),
'#default_value' => variable_get('gradebookapi_assignment_update_email_subject', gradebookapi_email_format('gradebookapi_assignment', 'subject')),
);
$form['email']['gradebookapi_email_assignment']['gradebookapi_assignment_update_email_body'] = array(
'#type' => 'textarea',
'#title' => t('Configure E-mail body'),
'#description' => t('This format will be used when sending the assignment update email notification. %assignment(assignment title), %sitename, %recipient(teacher username), %response(response title), %responseurl(url to the response page) and %gradebookurl(url to the gradebook page) are placeholders.'),
'#default_value' => variable_get('gradebookapi_assignment_update_email_body', gradebookapi_email_format('gradebookapi_assignment', 'body')),
);
$form['email']['gradebookapi_email_grade'] = array(
'#type' => 'fieldset',
'#title' => t('Gradebook Grades'),
'#description' => t('Send notification to teacher when a grade is entered or an assignment is posted.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['email']['gradebookapi_email_grade']['gradebookapi_grade_update_email_allowed'] = array(
'#type' => 'checkbox',
'#title' => t('Notify students by email when a grade has been updated.'),
'#default_value' => variable_get('gradebookapi_grade_update_email_allowed', 0),
'#description' => t('Check this to send students an email whenever an grade has been updated. Note that students must must also enable the "Receive email notifications on grade update" option on their user account page.')
);
$form['email']['gradebookapi_email_grade']['gradebookapi_grade_update_email_subject'] = array(
'#type' => 'textfield',
'#title' => t('Configure E-mail Subject'),
'#description' => t('This format will be used when sending the grade update email notification.'),
'#default_value' => variable_get('gradebookapi_grade_update_email_subject', gradebookapi_email_format('gradebookapi_grade', 'subject')),
);
$form['email']['gradebookapi_email_grade']['gradebookapi_grade_update_email_body'] = array(
'#type' => 'textarea',
'#title' => t('Configure E-mail body'),
'#description' => t('This format will be used when sending the grade update email notification. %assignment(assignment title), %sitename, %recipient(teacher username), %response(response title), %responseurl(url to the response page) and %gradebookurl(url to the gradebook page) are placeholders.'),
'#default_value' => variable_get('gradebookapi_grade_update_email_body', gradebookapi_email_format('gradebookapi_grade', 'body')),
);
$form['#submit'][]= 'gradebookapi_admin_settings_submit'; // custom submit handler
return system_settings_form($form);
}
function gradebookapi_admin_settings_submit($form, &$form_state) {
$vid = gradebookapi_get_vid(); // Ensures that the gradebook vocabulary and field have been created!
$node_types = array_filter($form_state['values']['nodes']);
gradebookapi_create_field_instance($node_types);
$form_state['redirect'] = 'admin/structure/gradebook/gradebookapi';
}