-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadmin_edit_projects.php
615 lines (521 loc) · 20.8 KB
/
admin_edit_projects.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
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
<?php
/*
* admin_edit_projects.php
*
* A place for the admin to edit/update user projects
*
*/
include_once 'checkinstance.php';
if ( ( $_SESSION['userlevel'] != 3 ) &&
( $_SESSION['userlevel'] != 4 ) &&
( $_SESSION['userlevel'] != 5 ) ) // super, admin and superadmin only
{
header('Location: index.php');
exit();
}
include 'config.php';
include 'db.php';
include 'lib/utility.php';
// ini_set('display_errors', 'On');
// Are we being directed here from a push button?
if (isset($_POST['prior']))
{
do_prior($link);
exit();
}
else if (isset($_POST['next']))
{
do_next($link);
exit();
}
else if (isset($_POST['new']))
{
do_new($link);
exit();
}
else if (isset($_POST['update']))
{
do_update($link);
exit();
}
// Start displaying page
$page_title = 'Edit User Projects';
$js = 'js/admin_edit_projects.js';
include 'header.php';
include 'lib/selectboxes.php';
?>
<!-- Begin page content -->
<div id='content'>
<h1 class="title">Edit User Projects</h1>
<!-- Place page content here -->
<?php
if ( isset( $_POST['personID'] ) )
{
$_SESSION['currentID'] = $_POST['personID'];
$text = person_select( $link, 'personID', $_POST['personID'] );
}
else if ( isset( $_SESSION['currentID'] ) )
$text = person_select( $link, 'personID', $_SESSION['currentID'] );
else
$text = person_select( $link, 'personID' );
// Display what we have
echo $text;
// Edit or display a record
if ( isset($_POST['edit']) || isset($_GET['edit']) )
edit_record($link);
else if ( isset($_SESSION['currentID']) ) // We need the currentID there
display_record($link);
?>
</div>
<?php
include 'footer.php';
exit();
// Function to redirect to prior record
function do_prior($link)
{
$ID = $_SESSION['currentID'];
$projectID = $_POST['projectID'];
$query = "SELECT j.projectID " .
"FROM project j, projectPerson p " .
"WHERE p.personID = $ID " .
"AND p.projectID = j.projectID " .
"ORDER BY description ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
// Find prior record
$current = null;
list($current) = mysqli_fetch_array($result);
while ($current != null && $projectID != $current)
{
$prior = $current;
list($current) = mysqli_fetch_array($result);
}
$redirect = ($prior == null) ? "" : "?ID=$prior";
header("Location: $_SERVER[PHP_SELF]$redirect");
exit();
}
// Function to redirect to next record
function do_next($link)
{
$ID = $_SESSION['currentID'];
$projectID = $_POST['projectID'];
$query = "SELECT j.projectID " .
"FROM project j, projectPerson p " .
"WHERE p.personID = $ID " .
"AND p.projectID = j.projectID " .
"ORDER BY description ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
// Find next record
$next = null;
while ($projectID != $next)
list($next) = mysqli_fetch_array($result);
list($next) = mysqli_fetch_array($result);
$redirect = ($next == null) ? "?ID=$projectID" : "?ID=$next";
header("Location: $_SERVER[PHP_SELF]$redirect");
exit();
}
// Function to create a new record
function do_new($link)
{
$ID = $_SESSION['currentID'];
$uuid = uuid();
// Insert an ID
$query = "INSERT INTO project ( projectGUID ) " .
"VALUES ( '$uuid' ) ";
mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
$new = mysqli_insert_id($link);
// Add the ownership record
$query = "INSERT INTO projectPerson SET " .
"projectID = $new, " .
"personID = $ID ";
mysqli_query( $link, $query )
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
header("Location: $_SERVER[PHP_SELF]?edit=$new");
exit();
}
// Function to update the current record
function do_update($link)
{
$projectID = $_POST['projectID'];
// Since we always send out emails here, and the user could press the
// Update button even though nothing has changed, let's check
$query = "SELECT goals, molecules, purity, expense, " .
"bufferComponents, saltInformation, AUC_questions, " .
"expDesign, notes, description, status " .
"FROM project " .
"WHERE projectID = $projectID ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// Create local variables
foreach ($row as $key => $value)
{
$$key = (empty($value)) ? "" : $value ;
}
if ( $goals == $_POST['goals'] &&
$molecules == $_POST['molecules'] &&
$purity == $_POST['purity'] &&
$expense == $_POST['expense'] &&
$bufferComponents == $_POST['bufferComponents'] &&
$saltInformation == $_POST['saltInformation'] &&
$AUC_questions == $_POST['AUC_questions'] &&
$expDesign == $_POST['expDesign'] &&
$notes == $_POST['notes'] &&
$description == $_POST['description'] &&
$status == $_POST['status'] )
{
header("Location: $_SERVER[PHP_SELF]?ID=$projectID");
exit();
}
// Ok, we're still here, so something has changed. Let's create a diff
$diff = '';
$diff .= get_xdiff( $goals, $_POST['goals'], "Goals" );
$diff .= get_xdiff( $molecules, $_POST['molecules'], "Molecules" );
$diff .= get_xdiff( $purity, $_POST['purity'], "Purity" );
$diff .= get_xdiff( $expense, $_POST['expense'], "Expense" );
$diff .= get_xdiff( $bufferComponents, $_POST['bufferComponents'], "Buffer Components" );
$diff .= get_xdiff( $AUC_questions, $_POST['AUC_questions'], "AUC Questions" );
$diff .= get_xdiff( $expDesign, $_POST['expDesign'], "Experiment Design" );
$diff .= get_xdiff( $notes, $_POST['notes'], "Notes" );
$diff .= get_xdiff( $description, $_POST['description'], "Description" );
$diff_text = '';
if ( ! empty( $diff ) )
{
$diff_text = <<<HTML
Differences are as follows:
$diff
HTML;
}
// Now update the database with the new information
$goals = addslashes(htmlentities($_POST['goals']));
$molecules = addslashes(htmlentities($_POST['molecules']));
$purity = substr(addslashes(htmlentities($_POST['purity'])), 0,10);
$expense = addslashes(htmlentities($_POST['expense']));
$bufferComponents = addslashes(htmlentities($_POST['bufferComponents']));
$saltInformation = addslashes(htmlentities($_POST['saltInformation']));
$AUC_questions = addslashes(htmlentities($_POST['AUC_questions']));
$expDesign = addslashes(htmlentities($_POST['expDesign']));
$notes = addslashes(htmlentities($_POST['notes']));
$description = addslashes(htmlentities($_POST['description']));
$status = $_POST['status'];
$query = "UPDATE project " .
"SET goals = '$goals', " .
"molecules = '$molecules', " .
"purity = '$purity', " .
"expense = '$expense', " .
"bufferComponents = '$bufferComponents', " .
"saltInformation = '$saltInformation', " .
"AUC_questions = '$AUC_questions', " .
"expDesign = '$expDesign', " .
"notes = '$notes', " .
"description = '$description', " .
"status = '$status' " .
"WHERE projectID = $projectID ";
mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
// The project is new or has changed, so let's mail the user
global $org_name, $org_site, $dbname, $admin_email;
$db_abbrev = substr( $dbname, strrpos( $dbname, "uslims3_" ) + 8 );
// We have to get info about the project owner, not ourselves here
$query = "SELECT lname, fname, email " .
"FROM projectPerson, people " .
"WHERE projectID = $projectID " .
"AND projectPerson.personID = people.personID ";
$result = mysqli_query( $link, $query )
or die("Query failed : $query<br />\n" . mysqli_error($link));
list($lname, $fname, $email) = mysqli_fetch_array($result);
$email .= ",$admin_email";
$subject = "$lname project ($db_abbrev): {$_POST['description']}";
$subject = ( strlen( $subject ) > 50 )
? ( substr( $subject, 0, 50 ) . '...' )
: ( $subject );
$message = "Dear $fname $lname,
You have entered/updated a project in your $org_name account at $org_site.
$diff_text
The complete/new project information is:
Goals:
{$_POST['goals']}
Molecules:
{$_POST['molecules']}
Purity
{$_POST['purity']}
Expense:
{$_POST['expense']}
Buffer Components:
{$_POST['bufferComponents']}
Sample Handling:
{$_POST['saltInformation']}
AUC Questions:
{$_POST['AUC_questions']}
Experiment Design:
{$_POST['expDesign']}
Notes:
{$_POST['notes']}
Description:
{$_POST['description']}
Please save this message for your reference.
Thanks!
The $org_name Admins.
This is an automated response, do not reply!";
LIMS_mailer($email, $subject, $message);
header("Location: $_SERVER[PHP_SELF]?ID=$projectID");
exit();
}
// Function to make getting xdiff information a little easier
function get_xdiff( $old, $new, $label )
{
$a1 = array();
$a2 = array();
$a1[ 0 ] = $old;
$a2[ 0 ] = $new;
$sdiff = array_diff( $a1, $a2 );
if ( empty( $sdiff ) )
return '';
$diff = "- " . $old . "\n+ " . $new . "\n";
return "$label:\n$diff";
}
// Function to display and navigate records
function display_record($link)
{
// Find a record to display
$projectID = get_id($link);
if ($projectID === false)
return;
$query = "SELECT projectGUID, goals, molecules, purity, expense, " .
"bufferComponents, saltInformation, AUC_questions, expDesign, notes, description, status " .
"FROM project " .
"WHERE projectID = $projectID ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
// Create local variables; make sure IE displays empty cells properly
foreach ($row as $key => $value)
{
$$key = (empty($value)) ? " " : html_entity_decode( stripslashes( nl2br($value) ) );
}
global $project_status; // From lib/selectboxes.php
$status = $project_status[ $status ];
$ID = $_SESSION['currentID'];
// Populate a list box to allow user to jump to another record
$nav_listbox = "<select name='nav_box' id='nav_box' " .
" onchange='get_project(this);' >" .
" <option value='null'>None selected...</option>\n";
$query = "SELECT j.projectID, description " .
"FROM project j, projectPerson p " .
"WHERE p.personID = $ID " .
"AND p.projectID = j.projectID " .
"ORDER BY lastUpdated DESC ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
while (list($t_id, $t_description) = mysqli_fetch_array($result))
{
$selected = ($projectID == $t_id) ? " selected='selected'" : "";
$nav_listbox .= " <option$selected value='$t_id'>$t_description</option>\n";
}
$nav_listbox .= "</select>\n";
echo<<<HTML
<form action="{$_SERVER['PHP_SELF']}" method='post'>
<table cellspacing='0' cellpadding='10' class='style1' id='fixed'>
<thead>
<tr><th style="width: 16%;"></th>
<th style="width: 98%;">Edit User Projects</th></tr>
</thead>
<tfoot>
<tr><td colspan='2'>Jump to: $nav_listbox
<input type='submit' name='prior' value='<' />
<input type='submit' name='next' value='>' />
<input type='submit' name='new' value='New' />
<input type='submit' name='edit' value='Edit' />
<input type='hidden' name='projectID' value='$projectID' />
</td></tr>
</tfoot>
<tbody>
<tr><th>Project Description:</th>
<td>$description</td></tr>
<tr><th>Project GUID:</th>
<td>$projectGUID</td></tr>
<tr><th>Goals:</th>
<td>$goals</td></tr>
<tr><th>Molecules:</th>
<td>$molecules</td></tr>
<tr><th>Purity:</th>
<td>$purity</td></tr>
<tr><th>Expense:</th>
<td>$expense</td></tr>
<tr><th>Buffer Components:</th>
<td>$bufferComponents</td></tr>
<tr><th>Sample Handling:</th>
<td>$saltInformation</td></tr>
<tr><th>AUC Questions:</th>
<td>$AUC_questions</td></tr>
<tr><th>Experimental Design:</th>
<td>$expDesign</td></tr>
<tr><th>Notes:</th>
<td>$notes</td></tr>
<tr><th>Status:</th>
<td>$status</td></tr>
</tbody>
</table>
</form>
HTML;
}
// Function to figure out which record to display
function get_id($link)
{
// See if we are being directed to a particular record
if (isset($_GET['ID']))
return( $_GET['ID'] );
$ID = $_SESSION['currentID'];
// We don't know which record, so just find the first one
$query = "SELECT p.projectID " .
"FROM project j, projectPerson p " .
"WHERE p.personID = $ID " .
"AND p.projectID = j.projectID " .
"ORDER BY description " .
"LIMIT 1 ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
if (mysqli_num_rows($result) == 1)
{
list($projectID) = mysqli_fetch_array($result);
return( $projectID );
}
// If we're here, there aren't any records
echo<<<HTML
<form action='{$_SERVER[PHP_SELF]}' method='post'>
<table cellspacing='0' cellpadding='0' class='style1'>
<thead>
<tr><th colspan='2'>Edit User Projects</th></tr>
</thead>
<tfoot>
<tr><td colspan='2'><input type='submit' name='new' value='New' />
</td></tr>
</tfoot>
<tbody>
<tr><th>Status:</th>
<td>There are no records to display</td></tr>
</tbody>
</table>
</form>
HTML;
return( false );
}
// Function to edit a record
function edit_record($link)
{
// Get the record we need to edit
if ( isset( $_POST['edit'] ) )
$projectID = $_POST['projectID'];
else if ( isset( $_GET['edit'] ) )
$projectID = $_GET['edit'];
else
{
// How did we get here?
echo "<p>There was a problem with the edit request.</p>\n";
return;
}
$query = "SELECT goals, molecules, purity, expense, bufferComponents, " .
"saltInformation, AUC_questions, expDesign, notes, description, status, lastUpdated " .
"FROM project " .
"WHERE projectID = $projectID ";
$result = mysqli_query($link, $query)
or die("Query failed : $query<br />\n" . mysqli_error($link));
$row = mysqli_fetch_array($result);
$goals = html_entity_decode( stripslashes( $row['goals'] ) );
$molecules = html_entity_decode( stripslashes( $row['molecules'] ) );
$purity = html_entity_decode( stripslashes( $row['purity'] ) );
$expense = html_entity_decode( stripslashes( $row['expense'] ) );
$bufferComponents = html_entity_decode( stripslashes( $row['bufferComponents'] ) );
$saltInformation = html_entity_decode( stripslashes( $row['saltInformation'] ) );
$AUC_questions = html_entity_decode( stripslashes( $row['AUC_questions'] ) );
$expDesign = html_entity_decode( stripslashes( $row['expDesign'] ) );
$notes = html_entity_decode( stripslashes( $row['notes'] ) );
$description = html_entity_decode( stripslashes( $row['description'] ) );
$status = $row['status'];
$status_text = project_status_select( 'status', $status );
$lastUpdated = $row['lastUpdated'];
// Let's see if we're coming from the New Record or the Update button
$rec_status = ( isset( $_GET['edit'] ) )
? "<input type='hidden' name='rec_status' value='new' />"
: "<input type='hidden' name='rec_status' value='update' />";
echo<<<HTML
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table cellspacing='0' cellpadding='10' class='style1'>
<thead>
<tr><th colspan='8'>Edit $description</th></tr>
</thead>
<tfoot>
<tr><td colspan='2'><input type='submit' name='update' value='Update' />
<input type='hidden' name='projectID' value='$projectID' />
$rec_status
<input type='reset' /></td></tr>
</tfoot>
<tbody>
<tr><th>Please enter a brief title for your project. Later, you will be
able to retrieve your project by this description:</th></tr>
<tr><td><textarea name='description' rows='6' cols='65'
wrap='virtual'>$description</textarea></td></tr>
<tr><th>Please provide a detailed description of your research. Include an
abstract and explain the goals of your research. We will use this
this information to optimally design your experiment: </th></tr>
<tr><td><textarea name='goals' rows='6' cols='65'
wrap='virtual'>$goals</textarea></td></tr>
<tr><th>For each analyte to be measured, please provide a name, appropriate
molar mass, partial specific volume (if it was measured), and,
for proteins, the sequence in single-letter code. For each submitted
sample, please enter a detailed sample description key for the label
used on each tube: </th></tr>
<tr><td><textarea name='molecules' rows='6' cols='65'
wrap='virtual'>$molecules</textarea></td></tr>
<tr><th>Please indicate the approximate purity of your sample(s).
You can express it in percent:</th></tr>
<tr><td><input type='text' name='purity' size='40'
maxlength='10' value='$purity' /></td></tr>
<tr><th>How much material (volume, concentration) is available for your
research? Please identify concentration in absorbance units,
wavelength, or type of fluorescense label and its molar
concentration. For samples to be measured with UV/visible absorbance
optics, provide an absorbance scan against buffer from 215-700 nm
for each sample: </th></tr>
<tr><td><textarea name='expense' rows='6' cols='65'
wrap='virtual'>$expense</textarea></td></tr>
<tr><th>Please list the molar concentrations of each component in your
buffer, including reductants and nucleotides. Provide a buffer scan
against ddH2O from 215-700 nm. To minimize absorbance, we prefer to
use phosphate or optically pure TRIS. To avoid hydrodynamic
non-ideality, a minimum salt concentration of 20 mM is desired.
Please explain if this is not possible. If reductants are required,
please use TCEP which can be measured at wavelengths > 260 nm:
</th></tr>
<tr><td><textarea name='bufferComponents' rows='6' cols='65'
wrap='virtual'>$bufferComponents</textarea></td></tr>
<tr><th>Please indicate the ideal storage conditions (room temperature, 4,
-20, and/or -80 degrees Celcius), the shelf life of your sample,
any health/safety concerns (is it toxic if ingested or injected,
etc.) and, if so, proper care to be taken when working with and
disposing of sample. State if you would like to have the remaining
used or unused sample returned to you (you will need to pay for
return shipment) and indicate how to properly dispose of the sample:
</th></tr>
<tr><td><textarea name='saltInformation' rows='6' cols='65'
wrap='virtual'>$saltInformation</textarea></td></tr>
<tr><th>What questions are you trying to answer with AUC? How do you propose
to approach the research with AUC experiments?</th></tr>
<tr><td><textarea name='AUC_questions' rows='6' cols='65'
wrap='virtual'>$AUC_questions</textarea></td></tr>
<tr><th>The AUC experimental design:</th></tr>
<tr><td><textarea name='expDesign' rows='6' cols='65'
wrap='virtual'>$expDesign</textarea></td></tr>
<tr><th>Special instructions, questions, and notes (optional):</th></tr>
<tr><td><textarea name='notes' rows='6' cols='65'
wrap='virtual'>$notes</textarea></td></tr>
<tr><th>Status:</th></tr>
<tr><td>$status_text   (last updated: $lastUpdated)</td></tr>
</tbody>
</table>
</form>
HTML;
}
?>