Issues (2160)

main/survey/link.php (1 issue)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
require_once __DIR__.'/../inc/global.inc.php';
5
6
$surveyId = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : 0;
7
$sessionId = isset($_REQUEST['s']) ? (int) $_REQUEST['s'] : 0;
8
$courseId = isset($_REQUEST['c']) ? (int) $_REQUEST['c'] : 0;
9
10
if (empty($surveyId)) {
11
    api_not_allowed(true);
12
}
13
if (!SurveyManager::survey_generation_hash_available()) {
14
    api_not_allowed(true);
15
}
16
$courseInfo = api_get_course_info_by_id($courseId);
17
$hashIsValid = SurveyManager::validate_survey_hash(
18
    $surveyId,
19
    $courseId,
20
    $sessionId,
21
    $_REQUEST['g'],
22
    $_REQUEST['h']
23
);
24
if ($hashIsValid && $courseInfo) {
25
    $survey_data = SurveyManager::get_survey(
26
        $surveyId,
27
        null,
28
        $courseInfo['code']
29
    );
30
31
    $invitation_code = api_get_unique_id();
32
    $params = [
33
        'c_id' => $courseId,
34
        'session_id' => $sessionId,
35
        'user' => $invitation_code,
36
        'survey_code' => $survey_data['code'],
37
        'invitation_code' => $invitation_code,
38
        'invitation_date' => api_get_utc_datetime(),
39
    ];
40
    $invitation_id = SurveyUtil::save_invitation($params);
41
42
    if ($invitation_id) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $invitation_id of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
43
        $link = SurveyUtil::generateFillSurveyLink($invitation_code, $courseInfo['code'], $sessionId);
44
        header('Location: '.$link);
45
        exit;
46
    }
47
} else {
48
    api_not_allowed(true);
49
}
50