This repository has been archived by the owner on Aug 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
profile.case.php
236 lines (198 loc) · 6.47 KB
/
profile.case.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
<?php
require_once 'functions.php';
require_once 'functions.profile.php';
$sub_page = 4;
$info = $profile_info;
$case = (int)$_GET['paper'];
$info = $db->record("SELECT
papers.*, case_studies.name
FROM people_papers
JOIN papers ON people_papers.paper = papers.id
JOIN case_studies ON case_studies.paper = papers.id
WHERE people_papers.people = $people_id AND case_studies.id = $case");
if (!$info->id) {
kill("No publications found", "critical");
}
if ($_GET['delete']) {
$delete = (int)$_GET['delete'];
$db->query("DELETE FROM analysis WHERE id = $delete AND case_study = $case LIMIT 1");
$print = "Data point was deleted";
$message =
"New data point was deleted.
{$info->title}
{$info->name}
{$profile_info->firstname} {$profile_info->lastname}
{$profile_info->access_email}
DATA POINT $delete
TECH DETAILS:
" . getinfo();
mailadmins($message, "Data point deleted");
peoplelog("User deleted a data point");
}
if ($_POST) {
$post = array(
'result' => $_POST['result'] ? (float)$_POST['result'] : NULL,
'analysis_option' => (int)$_POST['option'],
'case_study' => $case,
'year' => $_POST['year'] ? (int)$_POST['year'] : NULL,
'notes' => $_POST['notes'] ? html($_POST['notes']) : NULL,
);
$db->insert("analysis",$post);
$print = "Data point has been added successfully";
$message =
"New data point was added.
{$info->title}
{$info->name}
{$profile_info->firstname} {$profile_info->lastname}
{$profile_info->access_email}
DATA POINT:
Year: " . (int)$_POST['year'] . "
Value: " . (float)$_POST['result'] . "
TECH DETAILS:
" . getinfo();
mailadmins($message, "New data point added");
peoplelog("User added a new data point");
}
$indicators = $db->query("SELECT *, analysis.id
FROM analysis
JOIN analysis_options o ON analysis.analysis_option = o.id
WHERE analysis.case_study = $case
ORDER BY o.name, analysis.year");
foreach ($indicators as $row) {
if ($row['year']) {
$show_table[$row['name']] = true;
$table[$row['name']][$row['year']] = $row['result'];
$table[$row['name']][$row['year']] = $row['result'];
}
if ($row['notes']) {
$infolist[$row['name']][] = $row['notes'];
}
$previous = $row['name'];
}
$list = $db->query("SELECT
o.*, t.name AS type
FROM
analysis_options o
JOIN analysis_options_types t ON o.type = t.id
ORDER BY o.type, o.name");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php echo $header ?>
<title>Data Entry | <?php echo SITENAME ?></title>
<style type="text/css">
.fa-info-circle{float:left;margin-right:10px;font-size:40px}
.jumbotron{margin-bottom:50px}
</style>
<script type="text/javascript">
$(function(){
<?php foreach ($list as $row) { ?>
measure[<?php echo $row['id'] ?>] = "<?php echo $row['measure'] ?>";
<?php } ?>
$("select[name='option']").change(function(){
var info = $(this).val();
getmeasure = measure[info];
$("#measure").html(getmeasure);
});
});
</script>
</head>
<body class="profile">
<?php require_once 'include.header.php'; ?>
<h1>Data Entry</h1>
<?php if ($print) { echo "<div class=\"alert alert-success\">$print</div>"; } ?>
<p><strong>Publication: </strong><?php echo $info->title ?></p>
<p><strong>City: </strong> <?php echo $info->name ?></p>
<form method="post" class="form form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">Type</label>
<div class="col-sm-10">
<select name="option" class="form-control" required>
<option value=""></option>
<?php foreach ($list as $row) { ?>
<?php if ($row['type'] != $type) { ?>
<?php if ($type) { ?></optgroup><?php } ?>
<optgroup label="<?php echo $row['type'] ?>">
<?php } $type = $row['type']; ?>
<option value="<?php echo $row['id'] ?>"<?php if ($row['id'] == $info->name) { echo ' selected'; } ?>><?php echo $row['name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Year</label>
<div class="col-sm-10">
<input class="form-control" type="number" name="year" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Value</label>
<div class="col-sm-10">
<div class="input-group">
<input class="form-control" type="number" step="0.01" name="result" />
<span class="input-group-addon" id="measure"></span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Comments</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="notes" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</div>
</form>
<?php if (!count($indicators)) { ?>
<div class="alert alert-info">
No data points found.
</div>
<?php } else { ?>
<table class="table table-striped">
<tr>
<th>Data category</th>
<th>Year</th>
<th>Value</th>
<th>Comments</th>
<th>Delete</th>
</tr>
<?php foreach ($indicators as $row) { ?>
<?php
if ((int)$row['result'] == $row['result']) {
$decimals = 0;
} else {
$decimals = 2;
}
?>
<tr>
<?php if ($row['name'] == $name) { ?>
<td></td>
<?php } else { ?>
<td><?php echo $row['name'] ?></td>
<?php } ?>
<?php $name = $row['name']; ?>
<td><?php echo $row['year'] ?></td>
<td><?php echo number_format($row['result'],$decimals) ?> <?php echo $row['measure'] ?></td>
<td><?php echo $row['notes'] ?></td>
<td>
<a href="profile.case.php?id=<?php echo $profile_id ?>&paper=<?php echo $case ?>&delete=<?php echo $row['id'] ?>"
class="btn btn-danger"
onclick="javascript:return confirm('Are you sure?')"
>
Delete
</a>
</td>
</tr>
<?php } ?>
</table>
<?php } ?>
<div class="alert alert-warning">
Questions or comments? Let us know at <a href="mailto:<?php echo EMAIL ?>"><?php echo EMAIL ?></a>
</div>
<?php require_once 'include.footer.php'; ?>
</body>
</html>