/
record_RD.php
365 lines (324 loc) · 13.7 KB
/
record_RD.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
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
<?php include "utils/config.php";
//File: record_RD.php
//Authors: Gordon Doore, Parth Parth
//Last modified: 07/24/2023
//Purpose: Record Research Data to operational drive
/**
* Inserts a new record into the `C3DataMasterTest` table in the database using the data from a form submission.
*
* @param MySQLi $conn The MySQLi connection object to the database.
* @param array $post_data The array of form data to be inserted into the database.
* @param string $user_id The user's id.
*
* @return string $error The error message, if any error occurred while inserting the data into the database. Empty if no errors occurred.
*
* @throws PDOException If there is an error executing the SQL statement.
*/
function fieldsToDataMasterSQL($conn, $post_data, $user_id)
{
$error = "";
// Retrieve variables from session
$unique_name = $post_data['unique_name'];
$dataset_name = $post_data['dataset_name'];
$dataset_description = $post_data['dataset_description'];
$social_science = $post_data['social_science_data'];
$natural_science_in_vivo = $post_data['natural_science_in_vivo'];
$natural_science_in_vitro = $post_data['natural_science_in_vitro'];
$published_dataset = $post_data['published_dataset'];
$irb = $post_data['irb'];
$data_dictionary = $post_data['data_dictionary'];
$publication = $post_data['dataset_publication'];
$free_download = $post_data['free_download'];
$agree_terms = $post_data['agree_terms'];
$email = $post_data['email'];
$last_name = $post_data['primary_last_name'];
$first_name = $post_data['primary_first_name'];
$institution = $post_data['institution'];
$file_id = null;
$keywords = $post_data['keywords'];
$num_files_set = $post_data['num_files_set'];
$link_github_repo = $post_data['link_github_repo'];
$sql = "INSERT INTO `C3DataMasterTest` (`unique_name`, `dataset_name`, `dataset_description`, `social_science`,
`natural_science_in_vivo`, `natural_science_in_vitro`, `published_dataset`, `irb`, `data_dictionary`, `publication`,
`free_download`,`keywords`,`num_files_set`,`link_github_repo`,`agree_terms`, `email`, `last_name`, `first_name`, `institution`, `file_id`) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
try {
$stmt->execute([
$unique_name, //
$dataset_name, //
$dataset_description, //
$social_science, //
$natural_science_in_vivo,
$natural_science_in_vitro, //
$published_dataset, //
$irb, //
$data_dictionary, //
$publication, //
$free_download, //
$keywords,
$num_files_set,
$link_github_repo,
$agree_terms,
$email,
$last_name,
$first_name,
$institution,
$file_id
]);
} catch (PDOException $e) {
$error = "Error submitting dataset. Please try again.";
$error = $e->getMessage();
error_log($error);
}
return $error;
}
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$_SESSION['session_name'] = session_name();
$_SESSION['update'] = [];
$error = "";
$metaSubmitted = false;
$user_id = $_SESSION['user_id'];
$U_Id = substr($user_id, 2);
$sql = "SELECT * FROM C3SignUp WHERE U_Id = ?";
$stmt = $conn->prepare($sql);
$stmt->execute([$U_Id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user) {
$email = $user['Email'];
$_SESSION['email'] = $email;
$last_name = $user['LastName'];
$first_name = $user['FirstName'];
}
if (isset($_POST['submitMeta'])) {
$_SESSION['submitMeta'] = true;
$post_data = $_POST;
// create unique name for dataset based on dataset name
$unique_name = preg_replace('/[^A-Za-z0-9\-]/', '', $post_data['dataset_name']);
$unique_name = strtolower($unique_name);
$unique_name = str_replace(' ', '-', $unique_name);
$unique_name = $unique_name . '-' . uniqid();
// save unique name as session variable
$_SESSION['unique_name'] = $unique_name;
$post_data['unique_name'] = $unique_name;
// check if dataset name already exists
$sql = "SELECT * FROM C3DataMasterTest WHERE unique_name = ?";
$stmt = $conn->prepare($sql);
$stmt->execute([$unique_name]);
if ($stmt->rowCount() > 0) {
$error = "Dataset name already exists. Please try again.";
} else {
$_SESSION['file_link'] = null;
$metaSubmitted = true;
$error = fieldsToDataMasterSQL($conn, $post_data, $user_id);
$_SESSION['update'][] = "Sucessfully Recorded Metadata. An email will be sent to you to confirm this submission";
$_SESSION['update'][] = $error;
}
if (isset($_POST['free_download']) && $_POST['free_download'] == 0 && $metaSubmitted) {
$_SESSION['confirmation_file'] = true;
header('Location: confirmation.php');
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cross-Origin-Opener-Policy" content="unsafe-none">
<meta http-equiv="Cross-Origin-Embedder-Policy" content="unsafe-none">
<title>C3 | Record</title>
<link rel="stylesheet" href="utils/css/dashboard-common.css">
<link rel="stylesheet" href="utils/css/record_RD.css">
</head>
<body>
<?php if (!empty($error)): ?>
<div class="error-div">
<p id="error-message">
<?php echo $error; ?>
</p>
</div>
<?php endif; ?>
<div class="wrapper-background">
<p> </p>
</div>
<div class="wrapper">
<?php include "loader.php"; ?>
<?php include "navbar.php"; ?>
<div class="content-wrapper">
<div class="content">
<h1>Record Research Data</h1>
<div class="dataset-submission">
<div class="enter-data">
<div class="dataset-submission">
<div class="enter-data" style="<?php echo $metaSubmitted ? 'display: none;' : ''; ?>">
<form id="intake-form" action="" method="POST">
<h2>C3 Data Master Intake Form</h2>
<p><em>* Indicates required question</em></p>
<label for="email">Email *</label>
<input type="email" id="email" name="email" value="<?php echo $email ?>" required>
<label for="primary_last_name">Primary Contact Last Name *</label>
<input type="text" id="primary_last_name" name="primary_last_name" value="<?php echo $last_name ?>"
required>
<label for="primary_first_name">Primary Contact First Name *</label>
<input type="text" id="primary_first_name" name="primary_first_name" value="<?php echo $first_name ?>"
required>
<label for="institution">Institution of Primary Contact *</label>
<select id="institution" name="institution" required>
<option value="">Select an option</option>
<option value="Bigelow">Bigelow</option>
<option value="Clarkson University">Clarkson University</option>
<option value="Colby College">Colby College</option>
<option value="Cornell University">Cornell University</option>
<option value="Syracuse University">Syracuse University</option>
<option value="Miner Institute">Miner Institute</option>
<option value="UNH">UNH</option>
<option value="UVM">UVM</option>
<option value="Wolf's Neck Center">Wolf's Neck Center</option>
</select>
<label for="dataset_name">Dataset Name (year_month_type_brief-description) *</label>
<input type="text" id="dataset_name" name="dataset_name" required>
<label for="dataset_description">Dataset Description *</label>
<textarea id="dataset_description" name="dataset_description" rows="6" required></textarea>
<label for="keywords">Keywords *</label>
<input type="text" id="keywords" name="keywords" required>
<label for="num_files_set">Number of Files *</label>
<input type="number" id="num_files_set" name="num_files_set" min="1" required>
<label for="link_github_repo" class="repo">GitHub Repository Link </label>
<input type="text" id="link_github_repo" name="link_github_repo">
<div>
<p>Is the data classified as Social Science data? *</p>
<div>
<label>
<input type="radio" name="social_science_data" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="social_science_data" value=0 required> No
</label>
</div>
</div>
<div>
<p>Is the data classified as Natural Science and represents in vivo experiments? *</p>
<div>
<label>
<input type="radio" name="natural_science_in_vivo" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="natural_science_in_vivo" value=0 required> No
</label>
</div>
</div>
<div>
<p>Is the data classified as Natural Science and represents in vitro experiments? *</p>
<div>
<label>
<input type="radio" name="natural_science_in_vitro" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="natural_science_in_vitro" value=0 required> No
</label>
</div>
</div>
<div>
<p>Published Dataset? *</p>
<div>
<label>
<input type="radio" name="published_dataset" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="published_dataset" value=0 required> No
</label>
</div>
</div>
<div>
<p>IRB? *</p>
<div>
<label>
<input type="radio" name="irb" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="irb" value=0 required> No
</label>
</div>
</div>
<div>
<p>Data Dictionary? *</p>
<div>
<label>
<input type="radio" name="data_dictionary" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="data_dictionary" value=0 required> No
</label>
</div>
</div>
<div>
<p>Dataset related to publication? *</p>
<div>
<label>
<input type="radio" name="dataset_publication" value=1 required> Yes
</label>
</div>
<div>
<label>
<input type="radio" name="dataset_publication" value=0 required> No
</label>
</div>
</div>
<div>
<p>Do you want to make a submit your data to the database or make a record of your data? *</p>
<div>
<label>
<input type="radio" name="free_download" value=1 required> Submit data into the database for
sharing
</label>
</div>
<div>
<label>
<input type="radio" name="free_download" value=0 required> Record metadata only, contributors
must contact you to access data
</div>
</div>
<p>By checking this box I am confirming that I am providing a ReadMe file with my data (submit or
contact)*</p>
<input type="checkbox" id="agree_terms" name="agree_terms" required>
<label for="agree_terms">I agree</label>
<input type="submit" name="submitMeta" value="Submit">
</form>
</div>
<div class="upload-file" style="<?php echo $metaSubmitted ? 'display: initial;' : 'display: none;'; ?>">
<form id="upload_form" enctype="multipart/form-data" method = "POST">
<input type="file" id="file_input" name="file_input">
<div>
<label>
<input type="radio" name="folder_selection" value="research" > Confirm you wish to upload research data
</label>
</div>
<input type="button" value="Upload" onclick="handleFileUpload()">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="utils/js/submit.js"></script>
</body>
</html>