forked from davidpanderson/science_united
-
Notifications
You must be signed in to change notification settings - Fork 0
/
su_projects_edit.php
168 lines (153 loc) · 4.47 KB
/
su_projects_edit.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
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2017 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// admin interface for add/remove/edit projects
require_once("../inc/util.inc");
require_once("../inc/su_db.inc");
require_once("../inc/su.inc");
require_once("../inc/su_project_infos.inc");
require_once("../inc/keywords.inc");
function show_projects() {
$projects = SUproject::enum("");
if ($projects) {
start_table('table-striped');
row_heading_array(array(
'Name<br><small>click for details</small>',
'URL',
'Science keywords',
'Location keywords',
'Created',
'Share',
'Status'
));
foreach ($projects as $p) {
table_row(
'<a href="su_show_project.php?id='.$p->id.'">'.$p->name.'</a>',
$p->url,
project_kw_string($p->id, SCIENCE),
project_kw_string($p->id, LOCATION),
date_str($p->create_time),
$p->share,
project_status_string($p->status)
);
}
end_table();
} else {
echo 'No projects yet';
}
}
// Return array of keywords of given category
// Entries are of the form id=>word
//
function keyword_subset($category) {
global $job_keywords;
$x = array();
foreach ($job_keywords as $id=>$k) {
if ($k->category != $category) continue;
$x[$id] = $k->name;
}
return $x;
}
// given keyword array of the form above,
// return a corresponding array of ones a project has
// (fraction, or -1 if not present)
//
function keyword_fracs($keywords, $category, $project_id) {
global $project_infos;
$x = array();
foreach ($keywords as $id=>$word) {
$x[$id] = -1;
}
$pks = $project_infos[$project_id]->kws;
foreach ($pks as $pk) {
$x[$pk->keyword_id] = $pk->fraction;
}
return $x;
}
// generate checkboxes for the given keywords.
// names are of the form kw_ID
//
function keyword_checkboxes($kws, $fracs=null) {
start_table();
$i = 0;
foreach ($kws as $id=>$word) {
$checked = $fracs?($fracs[$id]>=0?"checked":""):"";
$frac = $fracs?($fracs[$id]>=0?$fracs[$id]*100:""):"";
row2($word,
sprintf('<input type="checkbox" name="kw_%s" %s> %% of work: <input name="kwf_%s" size=6 value="%s">',
$id,
$checked,
$id,
$frac
)
);
$i++;
}
end_table();
}
function edit_project_form() {
$id = get_int('id');
$p = SUProject::lookup_id($id);
page_head("Edit project $p->name");
form_start('su_projects_edit.php');
form_input_hidden('action', 'edit_project_action');
form_input_hidden('id', $id);
form_input_text('Share', 'share', $p->share, 'number');
form_radio_buttons('Status', 'status',
array(
array('0', 'hidden'),
array('2', 'normal')
),
$p->status
);
form_submit('OK');
form_end();
page_tail();
}
function edit_project_action() {
$id = get_int('id');
$share = get_str('share');
$status = get_int('status');
$p = SUProject::lookup_id($id);
if (!$p) {
error_page("no such project");
}
if ($p->share != $share || $p->status != $status) {
$p->update("share=$share, status=$status");
}
Header("Location: su_projects_edit.php");
}
admin_only();
$action = get_str('action', true);
switch($action) {
case null:
case 'show_projects':
page_head('Projects');
show_projects();
echo '<p></p><a href="su_manage.php">Return to Admin page</a>';
page_tail();
break;
case 'edit_project_form':
edit_project_form();
break;
case 'edit_project_action':
edit_project_action();
break;
default:
error_page("no such action $action");
}
?>