|
1
|
|
|
<?php |
|
2
|
|
|
// This file is part of BOINC. |
|
3
|
|
|
// http://boinc.berkeley.edu |
|
4
|
|
|
// Copyright (C) 2008 University of California |
|
5
|
|
|
// |
|
6
|
|
|
// BOINC is free software; you can redistribute it and/or modify it |
|
7
|
|
|
// under the terms of the GNU Lesser General Public License |
|
8
|
|
|
// as published by the Free Software Foundation, |
|
9
|
|
|
// either version 3 of the License, or (at your option) any later version. |
|
10
|
|
|
// |
|
11
|
|
|
// BOINC is distributed in the hope that it will be useful, |
|
12
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
// See the GNU Lesser General Public License for more details. |
|
15
|
|
|
// |
|
16
|
|
|
// You should have received a copy of the GNU Lesser General Public License |
|
17
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
require_once("../inc/util.inc"); |
|
20
|
|
|
require_once("../inc/boinc_db.inc"); |
|
21
|
|
|
require_once("../inc/forum_db.inc"); |
|
22
|
|
|
require_once("../inc/forum.inc"); |
|
23
|
|
|
require_once("../inc/sanitize_html.inc"); |
|
24
|
|
|
require_once("../inc/countries.inc"); |
|
25
|
|
|
require_once("../inc/credit.inc"); |
|
26
|
|
|
require_once("../inc/team_types.inc"); |
|
27
|
|
|
require_once("../inc/time.inc"); |
|
28
|
|
|
require_once("../inc/stats_sites.inc"); |
|
29
|
|
|
|
|
30
|
|
|
function team_search_form($params) { |
|
31
|
|
|
if (!$params) { |
|
32
|
|
|
$params = new StdClass; |
|
33
|
|
|
$params->keywords = ""; |
|
34
|
|
|
$params->country = ""; |
|
35
|
|
|
$params->type = ""; |
|
36
|
|
|
$params->active = false; |
|
37
|
|
|
} |
|
38
|
|
|
echo '<form name="form" action="team_search.php">'; |
|
39
|
|
|
start_table(); |
|
40
|
|
|
row2('<b>'.tra('Search criteria (use one or more)').'</b>', ''); |
|
41
|
|
|
row2( |
|
42
|
|
|
tra('Key words').'<br><small>'.tra('Find teams with these words in their names or descriptions').'</small>', |
|
43
|
|
|
'<input class="form-control" type="text" name="keywords" value="' . htmlspecialchars($params->keywords) . '">'); |
|
44
|
|
|
row2_init(tra('Country')); |
|
45
|
|
|
echo '<select class="form-control" name="country"><option value="" selected>---</option>'; |
|
46
|
|
|
$country = $params->country; |
|
47
|
|
|
if (!$country || $country == 'None') $country = "XXX"; |
|
48
|
|
|
echo country_select_options($country); |
|
49
|
|
|
echo "</select></td></tr>\n"; |
|
50
|
|
|
row2(tra('Type of team'), team_type_select($params->type, true)); |
|
51
|
|
|
$checked = $params->active?"checked":""; |
|
52
|
|
|
row2(tra('Show only active teams'), "<input type=checkbox name=active $checked>"); |
|
53
|
|
|
row2("", "<input class=\"btn btn-primary\" type=submit name=submit value=\"".tra('Search')."\">"); |
|
54
|
|
|
end_table(); |
|
55
|
|
|
echo '</form>'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
function foundership_transfer_link($user, $team) { |
|
59
|
|
|
$now = time(); |
|
60
|
|
|
if ($team->ping_user == $user->id) { |
|
61
|
|
|
if (transfer_ok($team, $now)) { |
|
62
|
|
|
return tra('Requested by you, and founder response deadline has passed.').' |
|
63
|
|
|
<br> |
|
64
|
|
|
<a href="team_founder_transfer_form.php">'.tra('Complete foundership transfer').'</a>. |
|
65
|
|
|
'; |
|
66
|
|
|
} else { |
|
67
|
|
|
$deadline = date_str(transfer_ok_time($team)); |
|
68
|
|
|
return '<a href="team_founder_transfer_form.php">'.tra('Requested by you').'</a>; '.tra('founder response deadline is %1', $deadline); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
if (new_transfer_request_ok($team, $now)) { |
|
72
|
|
|
if ($team->userid == $user->id) { |
|
73
|
|
|
return tra('None'); |
|
74
|
|
|
} else { |
|
75
|
|
|
return '<a href="team_founder_transfer_form.php">'.tra('Initiate request').'</a>'; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
return '<a href="team_founder_transfer_form.php">'.tra('Deferred').'</a>'; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// $team is the team record with a bunch of additional data |
|
82
|
|
|
// (see team_display.php) |
|
83
|
|
|
// $user is viewer (not necessarily team founder) or null |
|
84
|
|
|
// |
|
85
|
|
|
function display_team_page($team, $user) { |
|
86
|
|
|
global $team_name_sites; |
|
87
|
|
|
page_head("$team->name"); |
|
88
|
|
|
|
|
89
|
|
|
echo "<p>"; |
|
90
|
|
|
start_table(); |
|
91
|
|
|
row1(tra('Team info')); |
|
92
|
|
|
if (strlen($team->description)) { |
|
93
|
|
|
row2(tra('Description'), sanitize_html($team->description)); |
|
94
|
|
|
} |
|
95
|
|
|
row2("Created", date_str($team->create_time)); |
|
96
|
|
|
if (defined("SHOW_NONVALIDATED_TEAMS")) { |
|
97
|
|
|
$founder = $team->founder; |
|
98
|
|
|
row2("Founder email validated", $founder->email_validated?"Yes":"No (team will not be exported)"); |
|
99
|
|
|
} |
|
100
|
|
|
if (strlen($team->url)) {; |
|
101
|
|
|
if (strstr($team->url, "http://")) { |
|
102
|
|
|
$x = $team->url; |
|
103
|
|
|
} else { |
|
104
|
|
|
$x = "http://$team->url"; |
|
105
|
|
|
} |
|
106
|
|
|
row2(tra('Web site'), "<a href=$x>$x</a>"); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if (!NO_STATS) { |
|
110
|
|
|
row2(tra('Total credit'), format_credit_large($team->total_credit)); |
|
111
|
|
|
row2(tra('Recent average credit'), format_credit_large($team->expavg_credit)); |
|
112
|
|
|
if (function_exists('project_team_credit')) { |
|
113
|
|
|
project_team_credit($team); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
show_badges_row(false, $team); |
|
117
|
|
|
if (!NO_STATS) { |
|
118
|
|
|
$x = ""; |
|
119
|
|
|
shuffle($team_name_sites); |
|
120
|
|
|
foreach ($team_name_sites as $t) { |
|
121
|
|
|
$url = $t[0]; |
|
122
|
|
|
$site_name = $t[1]; |
|
123
|
|
|
$encoding = $t[2]; |
|
124
|
|
|
if ($encoding == "hashlc") { |
|
125
|
|
|
$key = md5(strtolower($team->name)); |
|
126
|
|
|
} else if ($encoding == 'hash') { |
|
127
|
|
|
$key = md5($team->name); |
|
128
|
|
|
} else { |
|
129
|
|
|
$key = urlencode($team->name); |
|
130
|
|
|
} |
|
131
|
|
|
$x .= "<a href=$url".$key.">$site_name</a><br>\n"; |
|
132
|
|
|
} |
|
133
|
|
|
row2(tra('Cross-project stats'), $x); |
|
134
|
|
|
} |
|
135
|
|
|
row2(tra('Country'), $team->country); |
|
136
|
|
|
row2(tra('Type'), team_type_name($team->type)); |
|
137
|
|
|
|
|
138
|
|
|
if ($team->forum && is_forum_visible_to_user($team->forum, $user)) { |
|
139
|
|
|
$f = $team->forum; |
|
140
|
|
|
row2('<a href="team_forum.php?teamid='.$team->id.'">'.tra('Message board').'</a>', |
|
141
|
|
|
tra('Threads').': '.$f->threads.'<br>'.tra('Posts').': '.$f->posts.'<br>'.tra('Last post').': '.time_diff_str($f->timestamp, time()) |
|
142
|
|
|
); |
|
143
|
|
|
} |
|
144
|
|
|
if ($user) { |
|
145
|
|
|
if ($user->teamid != $team->id) { |
|
146
|
|
|
if ($team->joinable) { |
|
147
|
|
|
$tokens = url_tokens($user->authenticator); |
|
148
|
|
|
row2("", |
|
149
|
|
|
'<a class="btn btn-success" href="team_join.php?'.$tokens.'&teamid='.$team->id.'">'.tra('Join this team').'</a> |
|
150
|
|
|
<br><p class=\"text-muted\">'.tra('Note: if \'OK to email\' is set in your project preferences, joining a team gives its founder access to your email address.').'</p>' |
|
151
|
|
|
); |
|
152
|
|
|
} else { |
|
153
|
|
|
row2(tra("Not accepting new members"), ""); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
if (($user->teamid == $team->id)) { |
|
157
|
|
|
if (($user->id == $team->userid)) { |
|
158
|
|
|
if ($team->ping_user) { |
|
159
|
|
|
$deadline = date_str(transfer_ok_time($team)); |
|
160
|
|
|
row2(tra('Foundership change requested'), |
|
161
|
|
|
'<a href="team_change_founder_form.php?teamid='.$team->id.'">'.tra('Respond by %1', $deadline).'</a>' |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
} else { |
|
165
|
|
|
row2(tra('Team foundership change'), foundership_transfer_link($user, $team)); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
row1(tra('Members')); |
|
170
|
|
|
row2(tra('Founder'), |
|
171
|
|
|
$team->founder?user_links($team->founder, BADGE_HEIGHT_MEDIUM):"---" |
|
172
|
|
|
); |
|
173
|
|
|
if (count($team->admins)) { |
|
174
|
|
|
$first = true; |
|
175
|
|
|
$x = ""; |
|
176
|
|
|
foreach ($team->admins as $a) { |
|
177
|
|
|
if ($first) { |
|
178
|
|
|
$first = false; |
|
179
|
|
|
} else { |
|
180
|
|
|
$x .= " · "; |
|
181
|
|
|
} |
|
182
|
|
|
$x .= user_links($a, BADGE_HEIGHT_MEDIUM); |
|
183
|
|
|
} |
|
184
|
|
|
row2(tra('Admins'), $x); |
|
185
|
|
|
} |
|
186
|
|
|
$x = "0"; |
|
187
|
|
|
if (count($team->new_members)) { |
|
188
|
|
|
$first = true; |
|
189
|
|
|
$x = ""; |
|
190
|
|
|
foreach ($team->new_members as $id) { |
|
191
|
|
|
$u = BoincUser::lookup_id($id); |
|
192
|
|
|
if (!$u) continue; |
|
193
|
|
|
if ($first) { |
|
194
|
|
|
$first = false; |
|
195
|
|
|
} else { |
|
196
|
|
|
$x .= " · "; |
|
197
|
|
|
} |
|
198
|
|
|
$x .= user_links($u, BADGE_HEIGHT_MEDIUM); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
row2(tra('New members in last day'), $x); |
|
202
|
|
|
row2(tra('Total members'), "$team->nusers (<a href=team_members.php?teamid=$team->id&offset=0&sort_by=expavg_credit>".tra('view')."</a>)"); |
|
203
|
|
|
if (!NO_STATS) { |
|
204
|
|
|
row2(tra('Active members'), "$team->nusers_active (<a href=team_members.php?teamid=$team->id&offset=0&sort_by=expavg_credit>".tra('view')."</a>)"); |
|
205
|
|
|
row2(tra('Members with credit'), "$team->nusers_worked (<a href=team_members.php?teamid=$team->id&offset=0&sort_by=total_credit>".tra('view')."</a>)"); |
|
206
|
|
|
} |
|
207
|
|
|
end_table(); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
function display_team_members($team, $offset, $sort_by) { |
|
211
|
|
|
$n = 20; |
|
212
|
|
|
|
|
213
|
|
|
$admins = BoincTeamAdmin::enum("teamid=$team->id"); |
|
214
|
|
|
|
|
215
|
|
|
// there aren't indices to support sorting by credit. |
|
216
|
|
|
// set the following variable to disable sorted output. |
|
217
|
|
|
// (though since caching is generally used this shouldn't be needed) |
|
218
|
|
|
// |
|
219
|
|
|
$nosort = false; |
|
220
|
|
|
|
|
221
|
|
|
if ($sort_by == "total_credit") { |
|
222
|
|
|
$sort_clause = "total_credit desc"; |
|
223
|
|
|
} else { |
|
224
|
|
|
$sort_clause = "expavg_credit desc"; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
start_table(); |
|
228
|
|
|
$x = array(); |
|
229
|
|
|
$a = array(); |
|
230
|
|
|
$x[] = tra('Name'); |
|
231
|
|
|
$a[] = ""; |
|
232
|
|
|
if (!NO_STATS) { |
|
233
|
|
|
if ($nosort) { |
|
|
|
|
|
|
234
|
|
|
$x[] = tra('Total credit'); |
|
235
|
|
|
$x[] = tra('Recent average credit'); |
|
236
|
|
|
} else { |
|
237
|
|
|
if ($sort_by == "total_credit") { |
|
238
|
|
|
$x[] = tra('Total credit'); |
|
239
|
|
|
} else { |
|
240
|
|
|
$x[] = "<href=team_members.php?teamid=$team->id&sort_by=total_credit&offset=$offset>".tra('Total credit')."</a>"; |
|
241
|
|
|
} |
|
242
|
|
|
if ($sort_by == "expavg_credit") { |
|
243
|
|
|
$x[] = tra('Recent average credit'); |
|
244
|
|
|
} else { |
|
245
|
|
|
$x[] = "<href=team_members.php?teamid=$team->id&sort_by=expavg_credit&offset=$offset>".tra('Recent average credit').'</a>'; |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
$a[] = ALIGN_RIGHT; |
|
249
|
|
|
$a[] = ALIGN_RIGHT; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
$x[] = tra('Country'); |
|
253
|
|
|
$a[] = ""; |
|
254
|
|
|
row_heading_array($x, $a); |
|
255
|
|
|
|
|
256
|
|
|
$cache_args = "teamid=".$team->id."&mosort=".$nosort."&order=".$sort_clause."&limit=".$offset."_".$n; |
|
|
|
|
|
|
257
|
|
|
$users = unserialize(get_cached_data(TEAM_PAGE_TTL, $cache_args)); |
|
|
|
|
|
|
258
|
|
|
if (!$users) { |
|
259
|
|
|
if ($nosort) { |
|
|
|
|
|
|
260
|
|
|
$users = BoincUser::enum("teamid=$team->id limit $offset,$n"); |
|
261
|
|
|
} else { |
|
262
|
|
|
$users = BoincUser::enum("teamid=$team->id order by $sort_clause limit $offset,$n"); |
|
263
|
|
|
} |
|
264
|
|
|
set_cached_data(TEAM_PAGE_TTL, serialize($users), $cache_args); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
$j = $offset + 1; |
|
268
|
|
|
foreach ($users as $user) { |
|
269
|
|
|
$user_total_credit = format_credit_large($user->total_credit); |
|
270
|
|
|
$user_expavg_credit = format_credit($user->expavg_credit); |
|
271
|
|
|
$x = user_links($user, BADGE_HEIGHT_MEDIUM); |
|
272
|
|
|
if ($user->id == $team->userid) { |
|
273
|
|
|
$x .= ' ['.tra('Founder').']'; |
|
274
|
|
|
} else if (is_team_admin_aux($user, $admins)) { |
|
275
|
|
|
$x .= ' ['.tra('Admin').']'; |
|
276
|
|
|
} |
|
277
|
|
|
echo "<tr class=row1> |
|
278
|
|
|
<td align=left>$j) $x |
|
279
|
|
|
</td>"; |
|
280
|
|
|
if (!NO_STATS) { |
|
281
|
|
|
echo " |
|
282
|
|
|
<td align=right>$user_total_credit</td> |
|
283
|
|
|
<td align=right>$user_expavg_credit</td> |
|
284
|
|
|
"; |
|
285
|
|
|
} |
|
286
|
|
|
echo " |
|
287
|
|
|
<td>$user->country</td> |
|
288
|
|
|
</tr> |
|
289
|
|
|
"; |
|
290
|
|
|
$j++; |
|
291
|
|
|
} |
|
292
|
|
|
echo "</table>"; |
|
293
|
|
|
|
|
294
|
|
|
if ($offset > 0) { |
|
295
|
|
|
$new_offset = $offset - $n; |
|
296
|
|
|
echo "<a href=team_members.php?teamid=$team->id&sort_by=$sort_by&offset=$new_offset>".tra('Previous %1', $n)."</a> · "; |
|
297
|
|
|
} |
|
298
|
|
|
if ($j == $offset + $n + 1) { |
|
299
|
|
|
$new_offset = $offset + $n; |
|
300
|
|
|
echo "<a href=team_members.php?teamid=$team->id&sort_by=$sort_by&offset=$new_offset>".tra('Next %1', $n)."</a>"; |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
// check that the team exists |
|
305
|
|
|
// |
|
306
|
|
|
function require_team($team) { |
|
307
|
|
|
if (!$team) { |
|
308
|
|
|
error_page(tra('No such team.')); |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
function is_team_founder($user, $team) { |
|
313
|
|
|
return $user->id == $team->userid; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
// check that the user is founder of the team |
|
317
|
|
|
// |
|
318
|
|
|
function require_founder_login($user, $team) { |
|
319
|
|
|
require_team($team); |
|
320
|
|
|
if ($user->id != $team->userid) { |
|
321
|
|
|
error_page(tra('This operation requires foundership.')); |
|
322
|
|
|
} |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
function is_team_admin($user, $team) { |
|
326
|
|
|
if (!$user) return false; |
|
327
|
|
|
if ($user->id == $team->userid) return true; |
|
328
|
|
|
$admin = BoincTeamAdmin::lookup($team->id, $user->id); |
|
329
|
|
|
if ($admin) return true; |
|
330
|
|
|
return false; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
// use this when you're displaying a long list of users |
|
334
|
|
|
// and don't want to do a lookup for each one |
|
335
|
|
|
// |
|
336
|
|
|
function is_team_admin_aux($user, $admins) { |
|
337
|
|
|
foreach ($admins as $a) { |
|
338
|
|
|
if ($a->userid == $user->id) return true; |
|
339
|
|
|
} |
|
340
|
|
|
return false; |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
function require_admin($user, $team) { |
|
344
|
|
|
if (!is_team_admin($user, $team)) { |
|
345
|
|
|
error_page(tra('This operation requires team admin privileges')); |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
// return list of ID of user who joined team in last day |
|
350
|
|
|
// |
|
351
|
|
|
function new_member_list($teamid) { |
|
352
|
|
|
$new_members = array(); |
|
353
|
|
|
$yesterday = time() - 86400; |
|
354
|
|
|
$deltas = BoincTeamDelta::enum("teamid=$teamid and timestamp>$yesterday and joining=1"); |
|
355
|
|
|
foreach ($deltas as $delta) { |
|
356
|
|
|
$u = BoincUser::lookup_id($delta->userid); |
|
357
|
|
|
if ($u->teamid == $teamid) { |
|
358
|
|
|
$new_members[] = $u->id; // they might have later quit |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
return array_unique($new_members); |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
function admin_list($teamid) { |
|
365
|
|
|
$u = array(); |
|
366
|
|
|
$admins = BoincTeamAdmin::enum("teamid=$teamid"); |
|
367
|
|
|
foreach ($admins as $admin) { |
|
368
|
|
|
$user = BoincUser::lookup_id($admin->userid); |
|
369
|
|
|
if (!$user) continue; |
|
370
|
|
|
$u[] = $user; |
|
371
|
|
|
} |
|
372
|
|
|
return $u; |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
function team_table_start($sort_by, $type_url) { |
|
376
|
|
|
$x = array(); |
|
377
|
|
|
$x[] = tra('Rank'); |
|
378
|
|
|
$x[] = tra('Name'); |
|
379
|
|
|
$x[] = tra('Members'); |
|
380
|
|
|
$a = array("", "", ALIGN_RIGHT); |
|
381
|
|
|
if (!NO_STATS) { |
|
382
|
|
|
if ($sort_by == "total_credit") { |
|
383
|
|
|
$x[] = "<a href=top_teams.php?sort_by=expavg_credit".$type_url.">".tra('Recent average credit')."</a>"; |
|
384
|
|
|
$x[] = tra('Total credit'); |
|
385
|
|
|
} else { |
|
386
|
|
|
$x[] = tra('Recent average credit'); |
|
387
|
|
|
$x[] = "<a href=top_teams.php?sort_by=total_credit".$type_url.">".tra('Total credit')."</a>"; |
|
388
|
|
|
} |
|
389
|
|
|
$a[] = ALIGN_RIGHT; |
|
390
|
|
|
$a[] = ALIGN_RIGHT; |
|
391
|
|
|
} |
|
392
|
|
|
$x[] = tra('Country'); |
|
393
|
|
|
$x[] = tra("Type"); |
|
394
|
|
|
$a[] = ""; |
|
395
|
|
|
$a[] = ""; |
|
396
|
|
|
|
|
397
|
|
|
row_heading_array($x, $a); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
function team_links($team) { |
|
401
|
|
|
$b = badges_string(false, $team, BADGE_HEIGHT_MEDIUM); |
|
402
|
|
|
return "<a href=team_display.php?teamid=$team->id>$team->name</a> $b"; |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
function show_team_row($team, $i) { |
|
406
|
|
|
$team_expavg_credit = format_credit_large($team->expavg_credit); |
|
407
|
|
|
$team_total_credit = format_credit_large($team->total_credit); |
|
408
|
|
|
echo "<tr> |
|
409
|
|
|
<td>$i</td> |
|
410
|
|
|
<td>".team_links($team)."</td> |
|
411
|
|
|
<td align=right>".$team->nusers."</td> |
|
412
|
|
|
"; |
|
413
|
|
|
if (!NO_STATS) { |
|
414
|
|
|
echo " |
|
415
|
|
|
<td align=right>$team_expavg_credit</td> |
|
416
|
|
|
<td align=right>$team_total_credit</td> |
|
417
|
|
|
"; |
|
418
|
|
|
} |
|
419
|
|
|
echo " |
|
420
|
|
|
<td>$team->country</td> |
|
421
|
|
|
<td>".team_type_name($team->type)."</td> |
|
422
|
|
|
</tr> |
|
423
|
|
|
"; |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
|
function user_join_team($team, $user) { |
|
427
|
|
|
user_quit_team($user); |
|
428
|
|
|
$res = $user->update("teamid=$team->id"); |
|
429
|
|
|
if ($res) { |
|
430
|
|
|
$now = time(); |
|
431
|
|
|
BoincTeamDelta::insert("(userid, teamid, timestamp, joining, total_credit) values ($user->id, $team->id, $now, 1, $user->total_credit)"); |
|
432
|
|
|
return true; |
|
433
|
|
|
} |
|
434
|
|
|
return false; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
function user_quit_team($user) { |
|
438
|
|
|
if (!$user->teamid) return; |
|
439
|
|
|
$user->update("teamid=0"); |
|
440
|
|
|
$team = BoincTeam::lookup_id($user->teamid); |
|
441
|
|
|
if ($team && $team->ping_user==$user->id) { |
|
442
|
|
|
$team->update("ping_user=-ping_user"); |
|
443
|
|
|
} |
|
444
|
|
|
BoincTeamAdmin::delete("teamid=$user->teamid and userid=$user->id"); |
|
445
|
|
|
$now = time(); |
|
446
|
|
|
BoincTeamDelta::insert("(userid, teamid, timestamp, joining, total_credit) values ($user->id, $user->teamid, $now, 0, $user->total_credit)"); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
function user_erase_team_owner($user) { |
|
450
|
|
|
if ($user->teamid) { |
|
451
|
|
|
$team = BoincTeam::lookup_id($user->teamid); |
|
452
|
|
|
if ($team && $team->userid == $user->id) { |
|
453
|
|
|
$team->update("userid=0"); |
|
454
|
|
|
} |
|
455
|
|
|
} |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
function user_erase_team_delta($user) { |
|
459
|
|
|
BoincTeamDelta::delete_for_user($user->id); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
function team_edit_form($team, $label, $url) { |
|
463
|
|
|
global $team_types; |
|
464
|
|
|
echo "<form method=post action=$url>\n"; |
|
465
|
|
|
if ($team) { |
|
466
|
|
|
echo "<input type=hidden name=teamid value=$team->id>\n"; |
|
467
|
|
|
if ($team->seti_id) { |
|
468
|
|
|
echo "<p class=\"text-danger\">".tra("WARNING: this is a BOINC-wide team. If you make changes here, they will soon be overwritten. Edit the %1 BOINC-wide team %2 instead.", "<a href=https://boinc.berkeley.edu/teams/>", "</a>") |
|
469
|
|
|
."</p>"; |
|
470
|
|
|
} |
|
471
|
|
|
} |
|
472
|
|
|
echo ' |
|
473
|
|
|
<p> |
|
474
|
|
|
'.tra('%1 Privacy note %2: if you create a team, your project preferences (resource share, graphics preferences) will be visible to the public.', '<b>', '</b>').' |
|
475
|
|
|
<p> |
|
476
|
|
|
'; |
|
477
|
|
|
start_table(); |
|
478
|
|
|
row2(tra('Team name, text version').' |
|
479
|
|
|
<br><p class=\"text-muted\">'.tra('Don\'t use HTML tags.').'</p>', |
|
480
|
|
|
'<input class="form-control" name="name" type="text" size="50" value="'.($team?$team->name:"").'">' |
|
481
|
|
|
); |
|
482
|
|
|
row2(tra('Team name, HTML version').' |
|
483
|
|
|
<br><p class=\"text-muted\"> |
|
484
|
|
|
'.tra('You may use %1 limited HTML tags %2.', '<a href="html.php" target="_new">', '</a>').' |
|
485
|
|
|
'.tra('If you don\'t know HTML, leave this box blank.').'</p>', |
|
486
|
|
|
'<input class="form-control" name="name_html" type="text" size="50" value="'.str_replace('"',"'",($team?$team->name_html:"")).'">' |
|
487
|
|
|
); |
|
488
|
|
|
row2(tra('URL of team web page, if any').':<br><font size=-2>('.tra('without "http://"').') |
|
489
|
|
|
'.tra('This URL will be linked to from the team\'s page on this site.'), |
|
490
|
|
|
'<input class="form-control" type="text" name="url" size="60" value="'.($team?$team->url:"").'">' |
|
491
|
|
|
); |
|
492
|
|
|
row2(tra('Description of team').': |
|
493
|
|
|
<br><p class=\"text-muted\"> |
|
494
|
|
|
'.tra('You may use %1 limited HTML tags %2.', '<a href="html.php" target="_new">', '</a>').' |
|
495
|
|
|
</p>', |
|
496
|
|
|
'<textarea class="form-control" name="description" rows=10>'.($team?$team->description:"").'</textarea>' |
|
497
|
|
|
); |
|
498
|
|
|
|
|
499
|
|
|
row2(tra('Type of team').':', team_type_select($team?$team->type:null)); |
|
500
|
|
|
|
|
501
|
|
|
row2_init(tra('Country')); |
|
502
|
|
|
echo '<select class="form-control" name="country">'; |
|
503
|
|
|
echo country_select_options($team?$team->country:null); |
|
504
|
|
|
echo "</select></td></tr>\n"; |
|
505
|
|
|
|
|
506
|
|
|
$x = (!$team || $team->joinable)?"checked":""; |
|
507
|
|
|
row2(tra("Accept new members?"), "<input type=checkbox name=joinable $x>"); |
|
508
|
|
|
// Check if we're using reCaptcha to prevent spam accounts |
|
509
|
|
|
// |
|
510
|
|
|
if (!$team && recaptcha_public_key()) { |
|
511
|
|
|
row2( |
|
512
|
|
|
"", |
|
513
|
|
|
boinc_recaptcha_get_html(recaptcha_public_key()) |
|
514
|
|
|
); |
|
515
|
|
|
} |
|
516
|
|
|
row2("", |
|
517
|
|
|
sprintf( |
|
518
|
|
|
'<input class="btn" %s type=submit name=new value="%s">', |
|
519
|
|
|
button_style(), |
|
520
|
|
|
$label |
|
521
|
|
|
) |
|
522
|
|
|
); |
|
523
|
|
|
end_table(); |
|
524
|
|
|
echo "</form>\n"; |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
// decay a team's average credit |
|
528
|
|
|
// |
|
529
|
|
|
function team_decay_credit($team) { |
|
530
|
|
|
$avg = $team->expavg_credit; |
|
531
|
|
|
$avg_time = $team->expavg_time; |
|
532
|
|
|
$now = time(); |
|
533
|
|
|
update_average($now, 0, 0, $avg, $avg_time); |
|
534
|
|
|
$team->update("expavg_credit=$avg, expavg_time=$now"); |
|
535
|
|
|
|
|
536
|
|
|
} |
|
537
|
|
|
// if the team hasn't received new credit for ndays, |
|
538
|
|
|
// decay its average and return true |
|
539
|
|
|
// |
|
540
|
|
|
function team_inactive_ndays($team, $ndays) { |
|
541
|
|
|
$diff = time() - $team->expavg_time; |
|
542
|
|
|
if ($diff > $ndays*86400) { |
|
543
|
|
|
team_decay_credit($team); |
|
544
|
|
|
return true; |
|
545
|
|
|
} |
|
546
|
|
|
return false; |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
function team_count_members($teamid) { |
|
550
|
|
|
return BoincUser::count("teamid=$teamid"); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
// These functions determine the rules for foundership transfer, namely: |
|
554
|
|
|
// - A transfer request is allowed if either: |
|
555
|
|
|
// - there is no active request, and it's been at least 60 days |
|
556
|
|
|
// since the last request (this protects the founder from |
|
557
|
|
|
// being bombarded with frequest requests) |
|
558
|
|
|
// - there's an active request older than 90 days |
|
559
|
|
|
// (this lets a 2nd requester eventually get a chance) |
|
560
|
|
|
// - Suppose someone (X) requests foundership at time T. |
|
561
|
|
|
// An email is sent to the founder (Y). |
|
562
|
|
|
// The request is "active" (ping_user is set to X's ID) |
|
563
|
|
|
// - If Y declines the change, an email is sent to X, |
|
564
|
|
|
// and the request is cleared. |
|
565
|
|
|
// - If Y accepts the change, an email is sent to X |
|
566
|
|
|
// and the request is cleared. |
|
567
|
|
|
// - After T + 60 days, X can become founder |
|
568
|
|
|
// - After T + 90 days, new requests are allowed even if there's |
|
569
|
|
|
// an active request, i.e. after the 60 days elapse X has another |
|
570
|
|
|
// 30 days to assume foundership before someone elase can request it |
|
571
|
|
|
// |
|
572
|
|
|
function new_transfer_request_ok($team, $now) { |
|
573
|
|
|
if ($team->ping_user <= 0) { |
|
574
|
|
|
if ($team->ping_time < $now - 60 * 86400) { |
|
575
|
|
|
return true; |
|
576
|
|
|
} |
|
577
|
|
|
return false; |
|
578
|
|
|
} |
|
579
|
|
|
if ($team->ping_time < $now - 90 * 86400) { |
|
580
|
|
|
return true; |
|
581
|
|
|
} |
|
582
|
|
|
return false; |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
// the time at which we can actually change foundership |
|
586
|
|
|
// if the founder hasn't responded |
|
587
|
|
|
// |
|
588
|
|
|
function transfer_ok_time($team) { |
|
589
|
|
|
return $team->ping_time + 60*86400; |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
function transfer_ok($team, $now) { |
|
593
|
|
|
if ($now > transfer_ok_time($team)) return true; |
|
594
|
|
|
return false; |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
// Make a team; args are untrusted, so cleanse and validate them |
|
598
|
|
|
// |
|
599
|
|
|
function make_team( |
|
600
|
|
|
$userid, $name, $url, $type, $name_html, $description, $country |
|
601
|
|
|
) { |
|
602
|
|
|
$name = BoincDb::escape_string(sanitize_tags($name)); |
|
603
|
|
|
if (strlen($name) == 0) return null; |
|
604
|
|
|
$name_lc = strtolower($name); |
|
605
|
|
|
$url = BoincDb::escape_string(sanitize_tags($url)); |
|
606
|
|
|
if (strstr($url, "http://")) { |
|
607
|
|
|
$url = substr($url, 7); |
|
608
|
|
|
} |
|
609
|
|
|
$name_html = BoincDb::escape_string($name_html); |
|
610
|
|
|
$description = BoincDb::escape_string($description); |
|
611
|
|
|
if (!is_valid_country($country)) { |
|
612
|
|
|
$country = tra('None'); |
|
613
|
|
|
} |
|
614
|
|
|
$country = BoincDb::escape_string($country); // for Cote d'Ivoire |
|
615
|
|
|
|
|
616
|
|
|
$clause = sprintf( |
|
617
|
|
|
"(userid, create_time, name, name_lc, url, type, name_html, description, country, nusers, expavg_time) values(%d, %d, '%s', '%s', '%s', %d, '%s', '%s', '%s', %d, unix_timestamp())", |
|
618
|
|
|
$userid, |
|
619
|
|
|
time(), |
|
620
|
|
|
$name, |
|
621
|
|
|
$name_lc, |
|
622
|
|
|
$url, |
|
623
|
|
|
$type, |
|
624
|
|
|
$name_html, |
|
625
|
|
|
$description, |
|
626
|
|
|
$country, |
|
627
|
|
|
0 |
|
628
|
|
|
); |
|
629
|
|
|
$id = BoincTeam::insert($clause); |
|
630
|
|
|
if ($id) { |
|
631
|
|
|
return BoincTeam::lookup_id($id); |
|
632
|
|
|
} else { |
|
633
|
|
|
return null; |
|
634
|
|
|
} |
|
635
|
|
|
} |
|
636
|
|
|
|
|
637
|
|
|
|
|
638
|
|
|
?> |
|
639
|
|
|
|