Issues (150)

src/app/controllers/ajax.php (7 issues)

1
<?php
2
3
class ajax extends Controller {
4
5
    function __construct() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
6
        $this->load_library("http_lib", "http");
7
        $this->load_library("auth_lib", "auth");
8
9
        $this->load_model("jugaad_model");
10
        $this->load_model("perms_model");
11
        $this->load_model("auth_model");
12
13
        $this->user = $this->auth->get_user() ?: "";
0 ignored issues
show
Bug Best Practice introduced by
The property auth does not exist on ajax. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
14
    }
15
16
    /**
17
     * @param string $param Get GET parameter called $param
18
     * @return mixed GET parameter or false if not found
19
     */
20
    private function get_param($param) {
21
        if (isset($_GET[$param])) {
22
            return $_GET[$param];
23
        }
24
        return false;
25
    }
26
27
    function latest_version_id() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
        $file_id = $this->get_param("file_id");
29
30
        $file = $this->jugaad_model->get_file($file_id);
0 ignored issues
show
Bug Best Practice introduced by
The property jugaad_model does not exist on ajax. Did you maybe forget to declare it?
Loading history...
31
32
        if ($file === false || $file["type"] != "file") {
33
            $this->http->response_code(404);
0 ignored issues
show
Bug Best Practice introduced by
The property http does not exist on ajax. Did you maybe forget to declare it?
Loading history...
34
        }
35
36
        $user_can = $this->perms_model->get_permissions($file_id, $this->user);
0 ignored issues
show
Bug Best Practice introduced by
The property perms_model does not exist on ajax. Did you maybe forget to declare it?
Loading history...
37
38
        if (!$user_can['read_file']) {
39
            $this->http->response_code(403);
40
        }
41
42
        $version_id = $this->jugaad_model->get_latest_version_id($file_id);
43
44
        echo $version_id;
45
    }
46
47
}
48