-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata_sharing.php
142 lines (116 loc) · 3.75 KB
/
data_sharing.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
<?php
/*
* data_sharing.php
*
* A place to define who you would like to share your data with
*
*/
include_once 'checkinstance.php';
$loginID = $_SESSION['loginID'];
$message = '';
include 'config.php';
include 'db.php';
// ini_set('display_errors', 'On');
// Update permits table if we submitted some data
if ( isset( $_POST['count'] ) )
{
$count = $_POST['count'];
$query = "DELETE FROM permits " .
"WHERE personID = $loginID " .
"AND instrumentID IS NULL "; // Only delete the collaborator records
mysqli_query($link, $query)
or die( "Query failed : $query<br/>\n" . mysqli_error($link) );
foreach ( $_POST[ 'cb' ] as $invID => $value )
{
if ( $value == 'on' )
{
$query = "INSERT INTO permits " .
"SET personID = $loginID, " .
"collaboratorID = $invID, " .
"instrumentID = NULL ";
mysqli_query($link, $query)
or die( "Query failed : $query<br/>\n" . mysqli_error($link) );
}
}
$message = "Your permit list has been updated.";
}
// Let's get a list of everyone in the database
$names = array();
$IDs = array();
$query = "SELECT personID, lname, fname FROM people " .
"ORDER BY lname, fname ";
$result = mysqli_query($link, $query)
or die( "Query failed : $query<br/>\n" . mysqli_error($link) );
$count = mysqli_num_rows( $result );
for ( $i = 0; $i < $count; $i++ )
{
list( $iID, $lname, $fname ) = mysqli_fetch_array( $result );
if ( $iID != $loginID ) // Skip ourself!
{
$names[ $i ] = "$lname, $fname";
$IDs [ $i ] = $iID;
}
}
// Let's get a current list of collaborators
$collaborators = array();
$query = "SELECT collaboratorID FROM permits " .
"WHERE personID = $loginID " .
"AND instrumentID IS NULL ";
$result = mysqli_query($link, $query)
or die( "Query failed : $query<br/>\n" . mysqli_error($link) );
while ( list( $cID ) = mysqli_fetch_array( $result ) )
{
$collaborators[] = $cID;
}
// Start displaying page
$page_title = "Share Data with Other Investigators";
$js = 'js/data_sharing.js';
include 'header.php';
?>
<!-- Begin page content -->
<div id='content'>
<h1 class="title">Share Data with Other Investigators</h1>
<!-- Place page content here -->
<p>Check other investigators who are permitted to view your reports.</p>
<?php echo "<p id='message' class='message'>$message</p>\n"; ?>
<form action='data_sharing.php' method='post'>
<table class='noborder'>
<?php
$count--; // Accounting for ourself
$rows = (int) ceil($count / 3.0);
$extra = $count % 3;
for ( $i = 0; $i < $rows; $i++ )
{
// Entry $e
$e = $i;
$inv = $IDs[$e];
$checked = ( in_array( $inv, $collaborators ) ) ? " checked='checked'" : "";
echo "<tr><td><input type='checkbox' name='cb[$inv]'$checked " .
" onclick='reset_message();' /> $names[$e]</td>\n";
/////////
$e = $rows + $i;
$inv = $IDs[$e];
$checked = ( in_array( $inv, $collaborators ) ) ? " checked='checked'" : "";
if ( $i < $rows-1 || $extra != 1 )
echo "<td><input type='checkbox' name='cb[$inv]'$checked " .
" onclick='reset_message();' /> $names[$e]</td>\n";
/////////
$e = $rows * 2 + $i;
if ( $extra == 1 ) $e--;
$inv = $IDs[$e];
$checked = ( in_array( $inv, $collaborators ) ) ? " checked='checked'" : "";
if ( $i < $rows-1 || $extra == 0 )
echo "<td><input type='checkbox' name='cb[$inv]'$checked " .
" onclick='reset_message();' /> $names[$e]</td>\n";
echo "</tr>\n";
}
?>
</table>
<p><input type='hidden' name='count' value='<?php echo $count;?>' />
<input type="submit" value="Update Settings"/></p>
</form>
</div>
<?php
include 'footer.php';
exit();
?>