-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsu_user_projects.php
179 lines (168 loc) · 5.74 KB
/
su_user_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
<?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/>.
// show project(s) user is attached to
require_once("../inc/util.inc");
require_once("../inc/su.inc");
require_once("../inc/su_schedule.inc");
function project_row($p, $ukws, $a) {
if ($a) {
$checked = $a->opt_out?"checked":"";
$d = date_str($a->create_time);
$c = $a->cpu_time/3600.;
$g = $a->gpu_time/3600.;
$njs = $a->njobs_success;
$njf = $a->njobs_fail;
$excluded = $a->opt_out?"; excluded":"";
} else {
$checked = "";
$d = "---";
$c = 0;
$g = 0;
$njs = 0;
$njf = 0;
$excluded = "";
}
row_array(array(
sprintf('<a href=su_user_projects.php?project_id=%d>%s</a>',
$p->id,
$p->name
),
$d,
show_num($c),
show_num($g),
$njs,
$njf,
(keywd_score($p->kws, $ukws)<0)?"no":"yes".$excluded
));
}
// show all the projects, with the ones user has contributed to at top.
//
function show_projects($user) {
page_head(tra("Science projects"));
$accounts = SUAccount::enum("user_id = $user->id", "order by cpu_time desc");
$project_infos = unserialize(file_get_contents("projects.ser"));
foreach ($project_infos as $id=>$p) {
$p->id = $id;
$p->done = false;
}
$first = true;
start_table('table-striped');
row_heading_array(array(
tra("Name")."<br><small>".tra("Click for details")."</small>",
tra("You've contributed since"),
tra("CPU hours"),
tra("GPU hours"),
tra("# successful jobs"),
tra("# failed jobs"),
tra("Allowed by prefs?"),
));
$ukws = SUUserKeyword::enum("user_id=$user->id");
// show projects w/ accounts
//
foreach ($accounts as $a) {
if (!array_key_exists($a->project_id, $project_infos)) continue;
if ($a->opt_out) continue;
$p = $project_infos[$a->project_id];
project_row($p, $ukws, $a);
$p->done = true;
}
foreach ($accounts as $a) {
if (!array_key_exists($a->project_id, $project_infos)) continue;
if (!$a->opt_out) continue;
$p = $project_infos[$a->project_id];
project_row($p, $ukws, $a);
$p->done = true;
}
// show other projects
//
foreach ($project_infos as $id=>$p) {
if ($p->done) continue;
project_row($p, $ukws, null);
}
end_table();
page_tail();
}
function su_show_project($user, $project_id) {
$project = SUProject::lookup_id($project_id);
if (!$project) die("no such project");
$acct = SUAccount::lookup("user_id=$user->id and project_id=$project_id");
page_head($project->name);
start_table();
row2(tra("Web site"), "<a href=$project->url>$project->url</a>");
row2(tra("Science keywords"), project_kw_string($project->id, SCIENCE));
row2(tra("Location keywords"), project_kw_string($project->id, LOCATION));
if ($acct) {
//row2(tra("First contribution"), date_str($acct->create_time));
row2(tra("CPU computing"), $acct->cpu_ec);
row2(tra("CPU time"), $acct->cpu_time);
if ($acct->gpu_ec) {
row2(tra("GPU computing"), $acct->gpu_ec);
row2(tra("GPU time"), $acct->gpu_time);
}
row2(tra("# jobs succeeded"), $acct->njobs_success);
row2(tra("# jobs failed"), $acct->njobs_fail);
if ($acct->opt_out) {
$x = tra("Yes")." ".button_text("su_user_projects.php?action=include&project_id=$project_id", tra("Include"));
} else {
$x = tra("No")." ".button_text("su_user_projects.php?action=exclude&project_id=$project_id", tra("Exclude"));
}
row2(
tra("Excluded?")."<br><small>".tra("Use if this project causes problems on your computer")."</small>",
$x
);
}
row2("", "<a href=su_user_projects.php>".tra("Return to project list")."</a>");
end_table();
page_tail();
}
function do_opt_out($user, $project_id, $exclude) {
$a = SUAccount::lookup("user_id=$user->id and project_id=$project_id");
$x = $exclude?1:0;
if ($a) {
$ret = $a->update("opt_out = $x");
if (!$ret) {
error_page("SUAccount::update() failed");
}
} else {
// opting out of a project w/ no account.
// create one just for this purpose.
//
$ret = SUAccount::insert(
sprintf("(project_id, user_id, create_time, state, opt_out) values (%d, %d, %f, %d, 1)",
$p->id, $user->id, time(), ACCT_INIT, 1
)
);
if (!$ret) {
error_page("SUAccount::insert() failed");
}
}
su_show_project($user, $project_id);
}
$user = get_logged_in_user();
$project_id = get_int("project_id", true);
$action = get_str("action", true);
if ($action == "exclude") {
do_opt_out($user, $project_id, true);
} else if ($action == "include") {
do_opt_out($user, $project_id, false);
} else if ($project_id) {
su_show_project($user, $project_id);
} else {
show_projects($user);
}
?>