-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
382 lines (333 loc) · 15.3 KB
/
install.php
File metadata and controls
382 lines (333 loc) · 15.3 KB
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
<?php
use \Vanderbilt\FlightTrackerExternalModule\CareerDev;
use \Vanderbilt\CareerDevLibrary\Download;
use \Vanderbilt\CareerDevLibrary\Upload;
use \Vanderbilt\CareerDevLibrary\REDCapManagement;
require_once(dirname(__FILE__)."/CareerDev.php");
require_once(dirname(__FILE__)."/small_base.php");
require_once(dirname(__FILE__)."/classes/Download.php");
require_once(dirname(__FILE__)."/classes/REDCapManagement.php");
require_once(dirname(__FILE__)."/classes/Upload.php");
if (isset($_POST['departments']) && isset($_POST['resources'])) {
$module = CareerDev::getModule();
if ($module) {
require_once(dirname(__FILE__)."/small_base.php");
$token = CareerDev::getSetting("token");
$server = CareerDev::getSetting("server");
$pid = CareerDev::getSetting("pid");
$tokenName = CareerDev::getSetting("tokenName");
$installCoeus = CareerDev::getSetting("hasCoeus");
$institutions = CareerDev::getInstitutions();
displayInstallHeaders($module, $token, $server, $pid, $tokenName);
if ($_POST['resources'] && $_POST['departments']) {
$lists = array(
"departments" => $_POST['departments'],
"resources" => $_POST['resources'],
"institutions" => implode("\n", $institutions),
);
$feedback = \Vanderbilt\FlightTrackerExternalModule\addLists($token, $server, $lists, $installCoeus);
redirectToAddScholars();
} else {
echo "<p class='red centered'>You must supply at least one resource and one department!</p>\n";
}
} else {
throw new \Exception("Could not find module!");
}
}
if (isset($_POST['token']) && isset($_POST['title'])) {
$requiredFields = array("title", "token", "institution", "short_institution", "timezone", "email", "cities");
foreach ($requiredFields as $field) {
if (!$_POST[$field]) {
sendErrorMessage("Please provide a value for the field '".$field."'!");
}
}
$newToken = $_POST['token'];
$newServer = APP_PATH_WEBROOT_FULL."api/";
if (isValidToken($newToken)) {
$feedback = uploadProjectSettings($newToken, $newServer, $_POST['title']);
$projectId = getPIDFromToken($newToken, $newServer);
$eventId = getEventIdForClassical($projectId);
displayInstallHeaders(CareerDev::getModule(), $newToken, $newServer, $projectId, $_POST['title']);
echo "<h1>Academic Departments</h1>\n";
$formsAndLabels = array(
"custom_grant" => "[custom_number]",
"followup" => "",
"position_change" => "",
"reporter" => "[reporter_projectnumber]",
"exporter" => "[exporter_full_project_num]",
"citation" => "[citation_pmid] [citation_title]",
"resources" => "[resources_resource]: [resources_date]",
"honors_and_awards" => "[honor_name]: [honor_date]",
);
if ($_POST['coeus']) {
$formsAndLabels["coeus"] = "[coeus_sponsor_award_number]";
}
setupRepeatingForms($eventId, $formsAndLabels);
$settingFields = array(
'institution' => $_POST['institution'],
'short_institution' => $_POST['short_institution'],
'other_institutions' => $_POST['other_institutions'],
'token' => $newToken,
'event_id' => $eventId,
'pid' => $projectId,
'server' => $newServer,
'admin_email' => $_POST['email'],
'tokenName' => $_POST['title'],
'timezone' => $_POST['timezone'],
'cities' => $_POST['cities'],
'hasCoeus' => $_POST['coeus'],
'internal_k_length' => '3',
'k12_kl2_length' => '3',
'individual_k_length' => '5',
'run_tonight' => FALSE,
'grant_class' => $_POST['grant_class'],
'grant_number' => $_POST['grant_number'],
);
setupModuleSettings($projectId, $settingFields);
$surveysAndLabels = array(
"initial_survey" => "Flight Tracker Initial Survey",
"followup" => "Flight Tracker Followup Survey",
);
setupSurveys($projectId, $surveysAndLabels);
echo makeDepartmentPrompt($projectId);
echo makeInstallFooter();
} else {
sendErrorMessage("Invalid token: $token");
}
} else {
displayInstallHeaders();
echo makeIntroPage($_GET['pid']);
echo makeInstallFooter();
}
function redirectToAddScholars() {
header("Location: ".CareerDev::link("add.php")."&headers=false");
}
function isValidToken($token) {
return REDCapManagement::isValidToken($token);
}
function uploadProjectSettings($token, $server, $title) {
$redcapData = array(
"is_longitudinal" => 0,
"surveys_enabled" => 1,
"record_autonumbering_enabled" => 1,
"project_title" => "Flight Tracker - ".$title,
"custom_record_label" => "[identifier_first_name] [identifier_last_name]",
);
$feedback = Upload::projectSettings($redcapData, $token, $server);
return $feedback;
}
function getPIDFromToken($token, $server) {
return REDCapManagement::getPIDFromToken($token, $server);
}
function getEventIdForClassical($projectId) {
return REDCapManagement::getEventIdForClassical($projectId);
}
function getExternalModuleId($prefix) {
return REDCapManagement::getExternalModuleId($prefix);
}
function setupRepeatingForms($eventId, $formsAndLabels) {
REDCapManagement::setupRepeatingForms($eventId, $formsAndLabels);
}
function setupModuleSettings($projectId, $fields) {
foreach ($fields as $field => $value) {
CareerDev::setSetting($field, $value);
}
}
function setupSurveys($projectId, $surveysAndLabels) {
REDCapManagement::setupSurveys($projectId, $surveysAndLabels);
}
function sendErrorMessage($mssg) {
header("Location: ".CareerDev::link("install.php")."?mssg=".urlencode($mssg));
}
function makeDepartmentPrompt($projectId) {
$html = "";
$html .= "<style>\n";
$html .= getCSS();
$html .= "</style>\n";
$html .= "<form method='POST' action='".preg_replace("/pid=\d+/", "pid=$projectId", CareerDev::getLink("install.php"))."'>\n";
$html .= "<p class='centered'>Please enter a list of your academic departments.<br>(One per line.)<br>\n";
$html .= "<textarea name='departments' class='config'></textarea></p>\n";
$html .= "<p class='centered'>Please enter a list of resources your scholars may use (e.g., workshops, tools).<br>(One per line.)<br>\n";
$html .= "<textarea name='resources' class='config'></textarea></p>\n";
$html .= "<p class='centered'><button>Configure Fields</button></p>\n";
$html .= "</form>\n";
return $html;
}
function makeIntroPage($projectId) {
$warnings = array();
$rights = \REDCap::getUserRights(USERID);
$defaultToken = "";
if ($rights[USERID]['api_token'] && $rights[USERID]['api_import'] && $rights[USERID]['api_export']) {
$defaultToken = $rights[USERID]['api_token'];
}
if (!$rights[USERID]['api_import']) {
array_push($warnings, "This user must have <a href='".APP_PATH_WEBROOT."UserRights/index.php?pid=$projectId'>API Import rights</a> for this project in order to install ".CareerDev::getProgramName());
}
if (!$rights[USERID]['api_export']) {
array_push($warnings, "This user must have <a href='".APP_PATH_WEBROOT."UserRights/index.php?pid=$projectId'>API Export rights</a> for this project in order to install ".CareerDev::getProgramName());
}
if (!$rights[USERID]['design']) {
array_push($warnings, "This user must have <a href='".APP_PATH_WEBROOT."UserRights/index.php?pid=$projectId'>Design rights</a> for this project in order to install ".CareerDev::getProgramName());
}
if ((!$rights[USERID]['api_import']) || (!$rights[USERID]['api_export'])) {
array_push($warnings, "To assign API rights, follow the link; select your username from the list; select 'Edit user priviledges;' and check API Import rights, API Export rights.");
}
$html = "";
$html .= "<script>\n";
$html .= "function changeGrantClass(name) {\n";
$html .= "\tvar val = $('[name='+name+']:checked').val();\n";
$html .= "\tif ((val == 'K') || (val == 'T')) {\n";
$html .= "\t\t$('grant_number_row').show();\n";
$html .= "\t} else {\n";
$html .= "\t\t$('grant_number_row').hide();\n";
$html .= "\t}\n";
$html .= "}\n";
$html .= "</script>\n";
$html .= "<p class='small centered recessed'>(Not expecting this page? <a class='recessed' href='".ExternalModules::$BASE_URL."manager/project.php?pid=$projectId'>Click Here</a> to Disable Flight Tracker)</p>\n";
$html .= "<style>\n";
$html .= getCSS();
$html .= "</style>\n";
$html .= "<h1>Flight Tracker Installation</h1>\n";
if (!empty($warnings)) {
foreach ($warnings as $warning) {
$html .= "<p class='centered red'>$warning</p>\n";
}
return $html;
}
if (isset($_GET['mssg'])) {
$html .= "<p class='centered red'>{$_GET['mssg']}</p>";
}
$html .= "<form method='POST' action='".CareerDev::link("install.php")."'>\n";
$html .= "<table style='margin-left: auto; margin-right: auto; max-width: 800px;'>\n";
$html .= "<tr>\n";
$html .= "<td colspan='2'>\n";
$html .= "<h2>Software Mission</h2>\n";
$html .= "<p class='centered'>Providing a tool for insight that tracks the career development of a population of scholars through following publications, resource use, mentoring, and federal grants.</p>\n";
$html .= "<h2><a href='".CareerDev::link("help/install.php")."'>Installation Video</a></h2>\n";
$html .= "<h2>What You'll Need</h2>\n";
$html .= "<ol>\n";
$html .= "<li>Ten minutes (or less)</li>\n";
$html .= "<li>Your REDCap Administrator handy via email or phone.</li>\n";
$html .= "<li>A <a href='".APP_PATH_WEBROOT."API/project_api.php?pid=".$projectId."'>REDCap API Token</a> (32 characters) to this project. (You may need to contact your REDCap Administrator to generate this for you.)</li>\n";
$html .= "<li>REDCap Design User Rights. (The API token can be shared among all the project's users, but each Flight Tracker user needs Design rights.)</li>\n";
$html .= "<li>Basic configuration information (see below)</li>\n";
$html .= "<li>A list of primary academic departments for all institutions represented - at the very least, those that your scholars are part of</li>\n";
$html .= "<li>A list of institutional resources you offer for help (e.g., workshops, seminars)</li>\n";
$html .= "<li>A list of names, emails, and institutions</li>\n";
$html .= "</ol>\n";
$html .= "<h2>Federal Data Sources Consulted</h2>\n";
$html .= "<p class='centered'>The following data sources need to be accessible (white-listed) from your REDCap server in order for Flight Tracker to work.</p>\n";
$html .= CareerDev::getSiteListHTML();
$html .= "<h2>What You'll Get</h2>\n";
$html .= "<ol>\n";
$html .= "<li>A REDCap project filled with your scholars.</li>\n";
$html .= "<li>Background processes that update your project every week or every day, provided that your REDCap instance has the Cron enabled.</li>\n";
$html .= "<li>Downloads of all of your scholars' federal grants and publications.</li>\n";
$html .= "<li>Lots of ways to 'slice and dice' your data.</li>\n";
$html .= "</ol>\n";
$html .= "</td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td colspan='2'><h2>Please Supply the Following</h2></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Title:<br><span class='small'>(i.e., Name of Project)</span></td>\n";
$html .= "<td><input type='text' name='title'></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'><a href='".APP_PATH_WEBROOT."API/project_api.php?pid=".$projectId."'>REDCap Token</a> (32 characters):<br><span class='small'>with API Import/Export rights<br>(<b>overwrites entire project</b>)</span></td>\n";
$html .= "<td><input type='text' name='token' value='$defaultToken'></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Full Institution Name:<br><span class='small'>(e.g., Vanderbilt University Medical Center)</span></td>\n";
$html .= "<td><input type='text' name='institution'></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Short Institution Name:<br><span class='small'>(e.g., Vanderbilt)<br>This is the institution name that your scholars will be searched under in the NIH.</span></td>\n";
$html .= "<td><input type='text' name='short_institution'></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Other Affiliated Institutions:<br><span class='small'>(Short Names, List Separated by Commas)<br>E.g., Vanderbilt pools resources to track scholars from Meharry and Tennessee State. These names will be searched from the NIH as well.<br>Optional.</span></td>\n";
$html .= "<td><input type='text' name='other_institutions'></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Class of Project:<br><span class='small'>If the project is affiliated with a grant, specify what type of grant. Small variations exist for these grant classes.</span></td>\n";
$html .= "<td>";
$grantClasses = CareerDev::getGrantClasses();
$grantClassRadios = array();
$grantClassName = "grant_class";
foreach ($grantClasses as $value => $label) {
$id = $grantClassName."_".$value;
array_push($grantClassRadios, "<input type='radio' id='$id' name='$grantClassName' value='$value' onclick='changeGrantClass(\"$grantClassName\");'><label for='$id'> $label</label>");
}
$html .= implode("<br>", $grantClassRadios);
$html .= "</td>\n";
$html .= "</tr>\n";
$html .= "<tr id='grant_number_row' style='display: none;'>\n";
$html .= "<td style='text-align: right;'>Grant Number (e.g., R01CA654321):</td>\n";
$html .= "<td><input type='text' name='grant_number'></td>\n";
$html .= "</tr>\n";
$zones = timezone_identifiers_list();
$currZone = date_default_timezone_get();
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Timezone:</td>\n";
$html .= "<td>\n";
$html .= "<select name='timezone'>\n";
foreach ($zones as $zone) {
$html .= "<option value='$zone'";
if ($zone == $currZone) {
$html .= " selected";
}
$html .= ">$zone</option>\n";
}
$html .= "</select>\n";
$html .= "</td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Admin Email(s):<br><span class='small'>(List Separated by Commas)</span></td>\n";
$html .= "<td><input type='text' name='email'></td>\n";
$html .= "</tr>\n";
$html .= "<tr>\n";
$html .= "<td style='text-align: right;'>Home Cities of Institutions:<br><span class='small'>(No States, just Cities)<br>(List Separated by Commas)</span></td>\n";
$html .= "<td><input type='text' name='cities'></td>\n";
$html .= "</tr>\n";
// turn off COEUS since few use it
$html .= "<input type='hidden' value='0' name='coeus'>\n";
$html .= "<tr>\n";
$html .= "<td colspan='2' style='text-align: center;' ><button>Transform My Project!</button></td>\n";
$html .= "</tr>\n";
$html .= "</table>\n";
$html .= "</form>\n";
return $html;
}
function makeInstallHeaders() {
$html = "";
$html .= "<head>\n";
$html .= "<title>Flight Tracker for Scholars</title>\n";
$html .= "<link rel='icon' href='".CareerDev::link("img/flight_tracker_icon.png")."'>\n";
$html .= "<link rel='stylesheet' type='text/css' href='".CareerDev::link("css/career_dev.css")."'>\n";
$html .= "</head>\n";
$html .= "<body>\n";
$html .= "<p class='centered'>".CareerDev::makeLogo()."</p>\n";
return $html;
}
function makeInstallFooter() {
return "</body>\n";
}
function displayInstallHeaders($module = NULL, $token = NULL, $server = NULL, $pid = NULL, $tokenName = NULL) {
if (isset($_GET['headers'])) {
require_once(dirname(__FILE__)."/charts/baseWeb.php");
if ($module) {
echo $module->makeHeaders($token, $server, $pid, $tokenName);
}
} else {
echo makeInstallHeaders();
}
}
function getCSS() {
$html = "";
$html .= "td { padding: 8px; }\n";
$html .= "input[type=text],select { width: 200px; }\n";
$html .= "button { font-size: 20px; color: white; background-color: black; }\n";
return $html;
}