Passed
Push — master ( 2cac25...98ba30 )
by Vitalii
09:23 queued 14s
created

main_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2011 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
// app-specific management interface
20
21
require_once("../inc/submit_util.inc");
22
require_once("../inc/util.inc");
23
24
function app_version_form($app) {
25
    page_head("Manage app versions");
26
    echo "
27
        <form action=manage_app.php>
28
        <input type=hidden name=action value=app_version_action>
29
        <input type=hidden name=app_id value=$app->id>
30
    ";
31
    $avs = BoincAppVersion::enum("appid=$app->id");
32
    start_table();
33
    table_header("platform", "plan class", "version#", "deprecated");
34
    foreach ($avs as $av) {
35
        $platform = BoincPlatform::lookup_id($av->platformid);
36
        $c = $av->deprecated?"checked":"";
37
        echo "
38
            <tr>
39
            <td>$platform->name</td>
40
            <td>$av->plan_class</td>
41
            <td>$av->version_num</td>
42
            <td><input type=checkbox name=dep_$av->id $c></td>
43
            </tr>
44
        ";
45
    }
46
    echo "
47
        <tr>
48
        <td><br></td>
49
        <td><br></td>
50
        <td><br></td>
51
        <td><input class=\"btn btn-default\" type=submit value=Update></td>
52
        </tr>
53
    ";
54
    end_table();
55
    echo "<form>\n";
56
    page_tail();
57
}
58
59
function app_version_action($app) {
60
    $avs = BoincAppVersion::enum("appid=$app->id");
61
    foreach ($avs as $av) {
62
        $x = get_str("dep_$av->id", true);
63
        if ($x) {
64
            if (!$av->deprecated) {
65
                $av->update("deprecated=1");
66
            }
67
        } else {
68
            if ($av->deprecated) {
69
                $av->update("deprecated=0");
70
            }
71
        }
72
    }
73
    page_head("Update successful");
74
    echo "
75
        <a href=submit.php>Return to job submission page</a>
76
    ";
77
    page_tail();
78
}
79
80
function permissions_form($app) {
81
    page_head("Manage user permissions for $app->name");
82
    echo "
83
        <form action=manage_app.php>
84
        <input type=hidden name=action value=permissions_action>
85
        <input type=hidden name=app_id value=$app->id>
86
    ";
87
    $busas = BoincUserSubmitApp::enum("app_id=$app->id");
88
    start_table();
89
    table_header("User", "Allowed to submit jobs to $app->name");
90
    foreach ($busas as $busa) {
91
        $user = BoincUser::lookup_id($busa->user_id);
92
        echo "
93
            <tr>
94
            <td>$user->name (ID: $user->id)</td>
95
            <td><input type=checkbox name=user_$user->id checked></td>
96
            </tr>
97
        ";
98
    }
99
    echo "
100
        <tr>
101
        <td>Add new user</td>
102
        <td>User ID: <input name=new_user_id></td>
103
        </tr>
104
        <tr>
105
        <td><br></td>
106
        <td><input class=\"btn btn-default\" type=submit value=OK></td>
107
        </tr>
108
    ";
109
    end_table();
110
    echo "<form>\n";
111
    page_tail();
112
}
113
114
function permissions_action($app) {
115
    $busas = BoincUserSubmitApp::enum("app_id=$app->id");
116
    foreach ($busas as $busa) {
117
        if (!get_str("user_$busa->user_id", true)) {
118
            BoincUserSubmitApp::delete_user($busa->user_id);
119
        }
120
    }
121
    $userid = get_int("new_user_id", true);
122
    if ($userid) {
123
        BoincUserSubmitApp::insert("(user_id, app_id) values ($userid, $app->id)");
124
    }
125
    page_head("Update successful");
126
    echo "
127
        <a href=submit.php>Return to job submission page</a>
128
    ";
129
    page_tail();
130
}
131
132
function batches_form($app) {
133
    page_head("Manage jobs for $app->name");
134
    echo "
135
        <form action=manage_app.php>
136
        <input type=hidden name=action value=batches_action>
137
        <input type=hidden name=app_id value=$app->id>
138
    ";
139
    start_table();
140
    table_header("Batch ID", "Submitter", "Submitted", "State", "# jobs", "Abort?");
141
    $batches = BoincBatch::enum("app_id=$app->id");
142
    foreach ($batches as $batch) {
143
        $user = BoincUser::lookup_id($batch->user_id);
144
        echo "<tr>
145
            <td>$batch->id</td>
146
            <td>$user->name</td>
147
            <td>".time_str($batch->create_time)."</td>
148
            <td>".batch_state_string($batch->state)."
149
            <td>$batch->njobs</td>
150
            <td><input type=checkbox name=abort_$batch->id></td>
151
            </tr>
152
        ";
153
    }
154
    echo "<tr>
155
        <td colspan=5>Abort all jobs for $app->name?</td>
156
        <td><input type=checkbox name=abort_all></td>
157
        </tr>
158
    ";
159
    echo "<tr>
160
        <td><br></td>
161
        <td><br></td>
162
        <td><br></td>
163
        <td><input class=\"btn btn-default\" type=submit value=OK></td>
164
        </tr>
165
    ";
166
    end_table();
167
    page_tail();
168
}
169
170
function batches_action($app) {
171
    $batches = BoincBatch::enum("app_id=$app->id");
172
    $abort_all = (get_str("abort_all", true));
173
    foreach ($batches as $batch) {
174
        if ($abort_all || get_str("abort_$batch->id", true)) {
175
            abort_batch($batch);
176
        }
177
    }
178
    page_head("Update successful");
179
    echo "
180
        <a href=submit.php>Return to job submission page</a>
181
    ";
182
    page_tail();
183
}
184
185
$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...
186
$app_id = get_int("app_id");
187
$app = BoincApp::lookup_id($app_id);
188
if (!$app) error_page("no such app");
189
$bus = BoincUserSubmit::lookup_userid($user->id);
190
if (!$bus) error_page("no access");
191
if (!$bus->manage_all) {
192
    $busa = BoincUserSubmitApp::lookup("user_id=$user->id and app_id=$app_id");
193
    if (!$busa || !$busa->manage) error_page("no access");
194
}
195
196
$action = get_str("action", true);
197
switch ($action) {
198
case "app_version_form":
199
    app_version_form($app); break;
200
case "app_version_action":
201
    app_version_action($app); break;
202
case "permissions_form":
203
    permissions_form($app); break;
204
case "permissions_action":
205
    permissions_action($app); break;
206
case "batches_form":
207
    batches_form($app); break;
208
case "batches_action":
209
    batches_action($app); break;
210
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...
211
    error_page("unknown action $action");
212
}
213
?>
214