Passed
Pull Request — master (#5567)
by David
09:04
created

handle_toggle_loc()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
// This file is part of BOINC.
4
// http://boinc.berkeley.edu
5
// Copyright (C) 2024 University of California
6
//
7
// BOINC is free software; you can redistribute it and/or modify it
8
// under the terms of the GNU Lesser General Public License
9
// as published by the Free Software Foundation,
10
// either version 3 of the License, or (at your option) any later version.
11
//
12
// BOINC is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
// See the GNU Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public License
18
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
19
20
// web interface for remote job submission:
21
// - links to job-submission pages
22
// - Admin (if privileged user)
23
// - manage batches
24
//      view status, get output files, abort, retire
25
// - toggle 'use only my computers'
26
27
require_once("../inc/submit_db.inc");
28
require_once("../inc/util.inc");
29
require_once("../inc/result.inc");
30
require_once("../inc/submit_util.inc");
31
require_once("../project/project.inc");
32
33
display_errors();
34
35
define("PAGE_SIZE", 20);
36
37
function state_count($batches, $state) {
38
    $n = 0;
39
    foreach ($batches as $batch) {
40
        if ($batch->state == $state) $n++;
41
    }
42
    return $n;
43
}
44
45
function show_all_link($batches, $state, $limit, $user, $app) {
46
    $n = state_count($batches, $state);
47
    if ($n > $limit) {
48
        if ($user) $userid = $user->id;
49
        else $userid = 0;
50
        if ($app) $appid = $app->id;
51
        else $appid = 0;
52
53
        echo "Showing the most recent $limit of $n batches.
54
            <a href=submit.php?action=show_all&state=$state&userid=$userid&appid=$appid>Show all $n</a>
55
            <p>
56
        ";
57
    }
58
}
59
60
function show_in_progress($batches, $limit, $user, $app) {
61
    $first = true;
62
    $n = 0;
63
    foreach ($batches as $batch) {
64
        if ($batch->state != BATCH_STATE_IN_PROGRESS) continue;
65
        if ($limit && $n == $limit) break;
66
        $n++;
67
        if ($first) {
68
            $first = false;
69
            echo "<h2>Batches in progress</h2>\n";
70
            if ($limit) {
71
                show_all_link($batches, BATCH_STATE_IN_PROGRESS, $limit, $user, $app);
72
            }
73
            start_table();
74
            table_header(
75
                "Name",
76
                "ID",
77
                "User",
78
                "App",
79
                "# jobs",
80
                "Progress",
81
                "Submitted",
82
                "Logical end time<br><small>Determines priority</small>"
83
            );
84
        }
85
        $pct_done = (int)($batch->fraction_done*100);
86
        table_row(
87
            "<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->name</a>",
88
            "<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->id</a>",
89
            $batch->user_name,
90
            $batch->app_name,
91
            $batch->njobs,
92
            "$pct_done%",
93
            local_time_str($batch->create_time),
94
            local_time_str($batch->logical_end_time)
95
        );
96
    }
97
    if ($first) {
98
        echo "<p>No in-progress batches.\n";
99
    } else {
100
        end_table();
101
    }
102
}
103
104
function show_complete($batches, $limit, $user, $app) {
105
    $first = true;
106
    $n = 0;
107
    foreach ($batches as $batch) {
108
        if ($batch->state != BATCH_STATE_COMPLETE) continue;
109
        if ($limit && $n == $limit) break;
110
        $n++;
111
        if ($first) {
112
            $first = false;
113
            echo "<h3>Completed batches</h3>\n";
114
            if ($limit) {
115
                show_all_link($batches, BATCH_STATE_COMPLETE, $limit, $user, $app);
116
            }
117
            start_table();
118
            table_header("name", "ID", "user", "app", "# jobs", "submitted");
119
        }
120
        table_row(
121
            "<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->name</a>",
122
            "<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->id</a>",
123
            $batch->user_name,
124
            $batch->app_name,
125
            $batch->njobs,
126
            local_time_str($batch->create_time)
127
        );
128
    }
129
    if ($first) {
130
        echo "<p>No completed batches.\n";
131
    } else {
132
        end_table();
133
    }
134
}
135
136
function show_aborted($batches, $limit, $user, $app) {
137
    $first = true;
138
    $n = 0;
139
    foreach ($batches as $batch) {
140
        if ($batch->state != BATCH_STATE_ABORTED) continue;
141
        if ($limit && $n == $limit) break;
142
        $n++;
143
        if ($first) {
144
            $first = false;
145
            echo "<h2>Aborted batches</h2>\n";
146
            if ($limit) {
147
                show_all_link($batches, BATCH_STATE_ABORTED, $limit, $user, $app);
148
            }
149
            start_table();
150
            table_header("name", "ID", "user", "app", "# jobs", "submitted");
151
        }
152
        table_row(
153
            "<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->name</a>",
154
            "<a href=submit.php?action=query_batch&batch_id=$batch->id>$batch->id</a>",
155
            $batch->user_name,
156
            $batch->app_name,
157
            $batch->njobs,
158
            local_time_str($batch->create_time)
159
        );
160
    }
161
    if (!$first) {
162
        end_table();
163
    }
164
}
165
166
// fill in the app and user names in list of batches
167
//
168
function fill_in_app_and_user_names(&$batches) {
169
    foreach ($batches as $batch) {
170
        $app = BoincApp::lookup_id($batch->app_id);
171
        if ($app) {
172
            $batch->app_name = $app->name;
173
        } else {
174
            $batch->app_name = "unknown";
175
        }
176
        $user = BoincUser::lookup_id($batch->user_id);
177
        if ($user) {
178
            $batch->user_name = $user->name;
179
        } else {
180
            $batch->user_name = "missing user $batch->user_id";
181
        }
182
    }
183
}
184
185
// show a set of batches
186
//
187
function show_batches($batches, $limit, $user, $app) {
188
    fill_in_app_and_user_names($batches);
189
    show_in_progress($batches, $limit, $user, $app);
190
    show_complete($batches, $limit, $user, $app);
191
    show_aborted($batches, $limit, $user, $app);
192
}
193
194
// the job submission "home page":
195
// show the user's in-progress and completed batches,
196
// and a button for creating a new batch
197
//
198
function handle_main($user) {
199
    global $submit_urls;
200
    $user_submit = BoincUserSubmit::lookup_userid($user->id);
201
    if (!$user_submit) {
202
        error_page("Ask the project admins for permission to submit jobs");
203
    }
204
205
    page_head("Job submission and control");
206
207
    if (isset($submit_urls)) {
208
        // show links to per-app job submission pages
209
        //
210
        echo "<h3>Submit jobs</h3>
211
            <ul>
212
        ";
213
        foreach ($submit_urls as $appname=>$submit_url) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "=>"; 0 found
Loading history...
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
214
            $appname = BoincDb::escape_string($appname);
215
            $app = BoincApp::lookup("name='$appname'");
216
            if (!$app) error_page("bad submit_url name: $appname");
217
            $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app->id");
218
            if ($usa || $user_submit->submit_all) {
219
                echo "<li> <a href=$submit_url> $app->user_friendly_name </a>";
220
            }
221
        }
222
        echo "</ul>\n";
223
    }
224
225
    echo '<h3>Where your jobs run</h3>';
226
    if ($user->seti_id) {
227
        echo "<p>
228
            Jobs you submit can run only on your computers.
229
            <p>
230
        ";
231
        show_button(
232
            'submit.php?action=toggle_loc',
233
            'Allow them to run on any computer.'
234
        );
235
    } else {
236
        echo "<p>
237
            Jobs you submit can run on any computer.
238
            <p>
239
        ";
240
        show_button(
241
            'submit.php?action=toggle_loc',
242
            'Allow them to run only on your computers.'
243
        );
244
    }
245
246
    // show links to admin pages if relevant
247
    //
248
    $usas = BoincUserSubmitApp::enum("user_id=$user->id");
249
    $app_admin = false;
250
    foreach ($usas as $usa) {
251
        if ($usa->manage) {
252
            $app_admin = true;
253
            break;
254
        }
255
    }
256
    if ($user_submit->manage_all || $app_admin) {
257
        echo "<h3>Administrative functions</h3><ul>\n";
258
        if ($user_submit->manage_all) {
259
            echo "<li>All applications<br>
260
                <a href=submit.php?action=admin&app_id=0>Batches</a>
261
                &middot;
262
                <a href=manage_project.php>Users</a>
263
            ";
264
            $apps = BoincApp::enum("deprecated=0");
265
            foreach ($apps as $app) {
266
                echo "<li>$app->user_friendly_name<br>
267
                    <a href=submit.php?action=admin&app_id=$app->id>Batches</a>
268
                    &middot;
269
                    <a href=manage_app.php?app_id=$app->id>Manage</a>
270
                ";
271
            }
272
        } else {
273
            foreach ($usas as $usa) {
274
                $app = BoincApp::lookup_id($usa->app_id);
275
                echo "<li>$app->user_friendly_name<br>
276
                    <a href=submit.php?action=admin&app_id=$app->id>Batches</a>
277
                ";
278
                if ($usa->manage) {
279
                    echo "&middot;
280
                        <a href=manage_app.php?app_id=$app->id&action=app_version_form>Versions</a>
281
                    ";
282
                }
283
            }
284
        }
285
        echo "</ul>\n";
286
    }
287
288
    $batches = BoincBatch::enum("user_id = $user->id order by id desc");
289
    show_batches($batches, PAGE_SIZE, $user, null);
290
291
    page_tail();
292
}
293
294
function handle_toggle_loc($user) {
295
    if ($user->seti_id) {
296
        $user->update('seti_id=0');
297
    } else {
298
        $user->update('seti_id=1');
299
    }
300
    handle_main($user);
301
}
302
303
function check_admin_access($user, $app_id) {
304
    $user_submit = BoincUserSubmit::lookup_userid($user->id);
305
    if (!$user_submit) error_page("no access");
306
    if ($app_id) {
307
        if (!$user_submit->manage_all) {
308
            $usa = BoincUserSubmitApp::lookup("user_id = $user->id and app_id=$app_id");
309
            if (!$usa) error_page("no access");
310
        }
311
    } else {
312
        if (!$user_submit->manage_all) error_page("no access");
313
    }
314
}
315
316
function handle_admin($user) {
317
    $app_id = get_int("app_id");
318
    check_admin_access($user, $app_id);
319
    if ($app_id) {
320
        $app = BoincApp::lookup_id($app_id);
321
        if (!$app) error_page("no such app");
322
        page_head("Administer batches for $app->user_friendly_name");
323
        $batches = BoincBatch::enum("app_id = $app_id order by id desc");
324
        show_batches($batches, PAGE_SIZE, null, $app);
325
    } else {
326
        page_head("Administer batches (all apps)");
327
        $batches = BoincBatch::enum("true order by id desc");
328
        show_batches($batches, PAGE_SIZE, null, null);
329
    }
330
    page_tail();
331
}
332
333
334
// show the statics of mem/disk usage of jobs in a batch
335
//
336
function handle_batch_stats($user) {
337
    $batch_id = get_int('batch_id');
338
    $batch = BoincBatch::lookup_id($batch_id);
339
    $results = BoincResult::enum("batch = $batch->id");
340
    page_head("Statistics for batch $batch_id");
341
    $n = 0;
342
    $wss_sum = 0;
343
    $swap_sum = 0;
344
    $disk_sum = 0;
345
    $wss_max = 0;
346
    $swap_max = 0;
347
    $disk_max = 0;
348
    foreach ($results as $r) {
349
        if ($r->outcome != RESULT_OUTCOME_SUCCESS) {
350
            continue;
351
        }
352
        // pre-7.3.16 clients don't report usage info
353
        //
354
        if ($r->peak_working_set_size == 0) {
355
            continue;
356
        }
357
        $n++;
358
        $wss_sum += $r->peak_working_set_size;
359
        if ($r->peak_working_set_size > $wss_max) {
360
            $wss_max = $r->peak_working_set_size;
361
        }
362
        $swap_sum += $r->peak_swap_size;
363
        if ($r->peak_swap_size > $swap_max) {
364
            $swap_max = $r->peak_swap_size;
365
        }
366
        $disk_sum += $r->peak_disk_usage;
367
        if ($r->peak_disk_usage > $disk_max) {
368
            $disk_max = $r->peak_disk_usage;
369
        }
370
    }
371
    if ($n == 0) {
372
        echo "No qualifying results.";
373
        page_tail();
374
        return;
375
    }
376
    start_table();
377
    row2("qualifying results", $n);
378
    row2("mean WSS", size_string($wss_sum/$n));
379
    row2("max WSS", size_string($wss_max));
380
    row2("mean swap", size_string($swap_sum/$n));
381
    row2("max swap", size_string($swap_max));
382
    row2("mean disk usage", size_string($disk_sum/$n));
383
    row2("max disk usage", size_string($disk_max));
384
    end_table();
385
386
    page_tail();
387
}
388
389
// return HTML for a color-coded batch progress bar
390
// green: successfully completed jobs
391
// red: failed
392
// light green: in progress
393
// light gray: unsent
394
//
395
function progress_bar($batch, $wus, $width) {
396
    $w_success = $width*$batch->fraction_done;
397
    $w_fail = $width*$batch->nerror_jobs/$batch->njobs;
398
    $nsuccess = $batch->njobs * $batch->fraction_done;
399
    $nsent = wus_nsent($wus);
400
    $nprog = $nsent - $nsuccess - $batch->nerror_jobs;
401
    $w_prog = $width*$nprog/$batch->njobs;
402
    $nunsent = $batch->njobs-$nsent;
403
    $w_unsent = $width*$nunsent/$batch->njobs;
404
    $x = '<table height=20><tr>';
405
    if ($w_fail) {
406
        $x .= "<td width=$w_fail bgcolor=red></td>";
407
    }
408
    if ($w_success) {
409
        $x .= "<td width=$w_success bgcolor=green></td>";
410
    }
411
    if ($w_prog) {
412
        $x .= "<td width=$w_prog bgcolor=lightgreen></td>";
413
    }
414
    if ($w_unsent) {
415
        $x .= "<td width=$w_unsent bgcolor=lightgray></td>";
416
    }
417
    $x .= "</tr></table>
418
        <strong>
419
        <font color=red>$batch->nerror_jobs fail</font> &middot;
420
        <font color=green>$nsuccess success</font> &middot;
421
        <font color=lightgreen>$nprog in progress</font> &middot;
422
        <font color=lightgray>$nunsent unsent</font>
423
        </strong>
424
    ";
425
    return $x;
426
}
427
428
// show the details of an existing batch
429
//
430
function handle_query_batch($user) {
431
    $batch_id = get_int('batch_id');
432
    $batch = BoincBatch::lookup_id($batch_id);
433
    $app = BoincApp::lookup_id($batch->app_id);
434
    $wus = BoincWorkunit::enum("batch = $batch->id");
435
    $batch = get_batch_params($batch, $wus);
436
437
    page_head("Batch $batch_id");
438
    start_table();
439
    row2("name", $batch->name);
440
    row2("application", $app?$app->name:'---');
441
    row2("state", batch_state_string($batch->state));
442
    //row2("# jobs", $batch->njobs);
443
    //row2("# error jobs", $batch->nerror_jobs);
444
    //row2("logical end time", time_str($batch->logical_end_time));
445
    if ($batch->expire_time) {
446
        row2("expiration time", time_str($batch->expire_time));
447
    }
448
    row2("progress", progress_bar($batch, $wus, 600));
449
    if ($batch->completion_time) {
450
        row2("completed", local_time_str($batch->completion_time));
451
    }
452
    row2("GFLOP/hours, estimated", number_format(credit_to_gflop_hours($batch->credit_estimate), 2));
453
    row2("GFLOP/hours, actual", number_format(credit_to_gflop_hours($batch->credit_canonical), 2));
454
    row2("Output File Size", size_string(batch_output_file_size($batch->id)));
455
    end_table();
456
    $url = "get_output2.php?cmd=batch&batch_id=$batch->id";
457
    show_button($url, "Get zipped output files");
458
    switch ($batch->state) {
459
    case BATCH_STATE_IN_PROGRESS:
460
        echo "<p></p>";
461
        show_button(
462
            "submit.php?action=abort_batch_confirm&batch_id=$batch_id",
463
            "Abort batch"
464
        );
465
        break;
466
    case BATCH_STATE_COMPLETE:
467
    case BATCH_STATE_ABORTED:
468
        echo "<p></p>";
469
        show_button(
470
            "submit.php?action=retire_batch_confirm&batch_id=$batch_id",
471
            "Retire batch"
472
        );
473
        break;
474
    }
475
    show_button("submit.php?action=batch_stats&batch_id=$batch_id",
476
        "Show memory/disk usage statistics"
477
    );
478
479
    echo "<h2>Jobs</h2>\n";
480
    start_table();
481
    table_header(
482
        "Job ID and name<br><small>click for details or to get output files</small>",
483
        "status",
484
        "Canonical instance<br><small>click to see result page on BOINC server</smallp>",
485
        "Download Results"
486
    );
487
    foreach($wus as $wu) {
488
        $resultid = $wu->canonical_resultid;
489
        if ($resultid) {
490
            $x = "<a href=result.php?resultid=$resultid>$resultid</a>";
491
            $y = '<font color="green">completed</font>';
492
            $text = "<a href=get_output2.php?cmd=workunit&wu_id=$wu->id>Download output files</a>";
493
        } else {
494
            $x = "---";
495
            $text = "---";
496
            if ($batch->state == BATCH_STATE_COMPLETE) {
497
                $y = '<font color="red">failed</font>';
498
            }   else {
499
                $y = "in progress";
500
            }
501
        }
502
        echo "<tr>
503
                <td><a href=submit.php?action=query_job&wuid=$wu->id>$wu->id &middot; $wu->name</a></td>
504
                <td>$y</td>
505
                <td>$x</td>
506
                <td>$text</td>
507
            </tr>
508
        ";
509
    }
510
    end_table();
511
    echo "<p><a href=submit.php>Return to job control page</a>\n";
512
    page_tail();
513
}
514
515
// show the details of a job, including links to see the output files
516
//
517
function handle_query_job($user) {
518
    $wuid = get_int('wuid');
519
    $wu = BoincWorkunit::lookup_id($wuid);
520
    if (!$wu) error_page("no such job");
521
522
    page_head("Job $wuid");
523
524
    echo "
525
        <a href=workunit.php?wuid=$wuid>Workunit details</a> &middot;
526
        <a href=submit.php?action=query_batch&batch_id=$wu->batch>Batch $wu->batch</a>
527
    ";
528
529
    // show input files
530
    //
531
    echo "<h2>Input files</h2>\n";
532
    $x = "<in>".$wu->xml_doc."</in>";
533
    $x = simplexml_load_string($x);
534
    start_table();
535
    table_header("Logical name<br><small>(click to view)</small>",
536
        "Size (bytes)", "MD5"
537
    );
538
    foreach ($x->workunit->file_ref as $fr) {
539
        $pname = (string)$fr->file_name;
540
        $lname = (string)$fr->open_name;
541
        foreach ($x->file_info as $fi) {
542
            if ((string)$fi->name == $pname) {
543
                table_row(
544
                    "<a href=$fi->url>$lname</a>",
545
                    $fi->nbytes,
546
                    $fi->md5_cksum
547
                );
548
                break;
549
            }
550
        }
551
    }
552
    end_table();
553
554
    echo "<h2>Instances</h2>\n";
555
    start_table();
556
    table_header(
557
        "Instance ID<br><small>click for result page</small>",
558
        "State", "Output files<br><small>click to view the file</small>"
559
    );
560
    $results = BoincResult::enum("workunitid=$wuid");
561
    $upload_dir = parse_config(get_config(), "<upload_dir>");
562
    $fanout = parse_config(get_config(), "<uldl_dir_fanout>");
563
    foreach($results as $result) {
564
        echo "<tr>
565
            <td><a href=result.php?resultid=$result->id>$result->id &middot; $result->name </a></td>
566
            <td>".state_string($result)."</td>
567
            <td>
568
";
569
        $i = 0;
570
        if ($result->server_state == 5) {
571
            $phys_names = get_outfile_names($result);
572
            $log_names = get_outfile_log_names($result);
573
            for ($i=0; $i<count($phys_names); $i++) {
0 ignored issues
show
Coding Style Performance introduced by
The use of count() inside a loop condition is not allowed; assign the return value to a variable and use the variable in the loop condition instead
Loading history...
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
574
                $url = sprintf(
575
                    'get_output2.php?cmd=result&result_id=%d&file_num=%d',
576
                    $result->id, $i
577
                );
578
                $path = dir_hier_path($phys_names[$i], $upload_dir, $fanout);
579
                $s = stat($path);
580
                $size = $s['size'];
581
                echo sprintf('<a href=%s>%s</a> (%s bytes)<br/>',
582
                    $url,
583
                    $log_names[$i],
584
                    number_format($size)
585
                );
586
            }
587
        }
588
        echo "</td></tr>\n";
589
    }
590
    end_table();
591
    echo "<p><a href=submit.php>Return to job control page</a>\n";
592
    page_tail();
593
}
594
595
function handle_abort_batch_confirm() {
596
    $batch_id = get_int('batch_id');
597
    page_head("Confirm abort batch");
598
    echo "
599
        Aborting a batch will cancel all unstarted jobs.
600
        Are you sure you want to do this?
601
        <p>
602
    ";
603
    show_button(
604
        "submit.php?action=abort_batch&batch_id=$batch_id",
605
        "Yes - abort batch"
606
    );
607
    echo "<p><a href=submit.php>Return to job control page</a>\n";
608
    page_tail();
609
}
610
611
function check_access($user, $batch) {
612
    if ($user->id == $batch->user_id) return;
613
    $user_submit = BoincUserSubmit::lookup_userid($user->id);
614
    if ($user_submit->manage_all) return;
615
    $usa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$batch->app_id");
616
    if ($usa->manage) return;
617
    error_page("no access");
618
}
619
620
function handle_abort_batch($user) {
621
    $batch_id = get_int('batch_id');
622
    $batch = BoincBatch::lookup_id($batch_id);
623
    if (!$batch) error_page("no such batch");
624
    check_access($user, $batch);
625
    abort_batch($batch);
626
    page_head("Batch aborted");
627
    echo "<p><a href=submit.php>Return to job control page</a>\n";
628
    page_tail();
629
}
630
631
function handle_retire_batch_confirm() {
632
    $batch_id = get_int('batch_id');
633
    page_head("Confirm retire batch");
634
    echo "
635
        Retiring a batch will remove all of its output files.
636
        Are you sure you want to do this?
637
        <p>
638
    ";
639
    show_button(
640
        "submit.php?action=retire_batch&batch_id=$batch_id",
641
        "Yes - retire batch"
642
    );
643
    echo "<p><a href=submit.php>Return to job control page</a>\n";
644
    page_tail();
645
}
646
647
function handle_retire_batch($user) {
648
    $batch_id = get_int('batch_id');
649
    $batch = BoincBatch::lookup_id($batch_id);
650
    if (!$batch) error_page("no such batch");
651
    check_access($user, $batch);
652
    retire_batch($batch);
653
    page_head("Batch retired");
654
    echo "<p><a href=submit.php>Return to job control page</a>\n";
655
    page_tail();
656
}
657
658
function show_batches_in_state($batches, $state) {
659
    switch ($state) {
660
    case BATCH_STATE_IN_PROGRESS:
661
        page_head("Batches in progress");
662
        show_in_progress($batches, 0, null, null);
663
        break;
664
    case BATCH_STATE_COMPLETE:
665
        page_head("Completed batches");
666
        show_complete($batches, 0, null, null);
667
        break;
668
    case BATCH_STATE_ABORTED:
669
        page_head("Aborted batches");
670
        show_aborted($batches, 0, null, null);
671
        break;
672
    }
673
    page_tail();
674
}
675
676
function handle_show_all($user) {
677
    $userid = get_int("userid");
678
    $appid = get_int("appid");
679
    $state = get_int("state");
680
    if ($userid) {
681
        // user looking at their own batches
682
        //
683
        if ($userid != $user->id) error_page("wrong user");
684
        $batches = BoincBatch::enum("user_id = $user->id and state=$state order by id desc");
685
        fill_in_app_and_user_names($batches);
686
        show_batches_in_state($batches, $state);
687
    } else {
688
        // admin looking at batches
689
        //
690
        check_admin_access($user, $appid);
691
        if ($appid) {
692
            $app = BoincApp::lookup_id($appid);
693
            if (!$app) error_page("no such app");
694
            $batches = BoincBatch::enum("app_id = $appid and state=$state order by id desc");
695
        } else {
696
            $batches = BoincBatch::enum("state=$state order by id desc");
697
        }
698
        fill_in_app_and_user_names($batches);
699
        show_batches_in_state($batches, $state);
700
    }
701
}
702
703
$user = get_logged_in_user();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $user is correct as get_logged_in_user() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
704
705
$action = get_str('action', true);
706
707
switch ($action) {
708
case '': handle_main($user); break;
709
case 'abort_batch': handle_abort_batch($user); break;
710
case 'abort_batch_confirm': handle_abort_batch_confirm(); break;
711
case 'admin': handle_admin($user); break;
712
case 'batch_stats': handle_batch_stats($user); break;
713
case 'query_batch': handle_query_batch($user); break;
714
case 'query_job': handle_query_job($user); break;
715
case 'retire_batch': handle_retire_batch($user); break;
716
case 'retire_batch_confirm': handle_retire_batch_confirm(); break;
717
case 'show_all': handle_show_all($user); break;
718
case 'toggle_loc': handle_toggle_loc($user);
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
719
default:
0 ignored issues
show
Coding Style introduced by
DEFAULT keyword must be indented 4 spaces from SWITCH keyword
Loading history...
Coding Style introduced by
DEFAULT case must have a breaking statement
Loading history...
720
    error_page("no such action $action");
721
}
722
723
?>
724