Completed
Push — 1.10.x ( a9323e...dc10cd )
by Angel Fernando Quiroz
124:05 queued 70:15
created

main/admin/course_request_rejected.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * A list containing the rejected course requests
6
 * @package chamilo.admin
7
 * @author José Manuel Abuin Mosquera <[email protected]>, 2010
8
 * @author Bruno Rubio Gayo <[email protected]>, 2010
9
 * Centro de Supercomputacion de Galicia (CESGA)
10
 *
11
 * @author Ivan Tcholakov <[email protected]> (technical adaptation for Chamilo 1.8.8), 2010
12
 */
13
14
$cidReset = true;
15
16
require '../inc/global.inc.php';
17
18
$this_section = SECTION_PLATFORM_ADMIN;
19
20
api_protect_admin_script();
21
22
// A check whether the course validation feature is enabled.
23
$course_validation_feature = api_get_setting('course_validation') == 'true';
24
25
// Filltering passed to this page parameters.
26
$accept_course_request = isset($_GET['accept_course_request']) ? intval($_GET['accept_course_request']) : '';
27
$delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['delete_course_request']) : '';
28
$request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
29
$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
30
$is_error_message = !empty($_GET['is_error_message']);
31
32
if ($course_validation_feature) {
33
34
    /**
35
     * Acceptance and creation of the requested course.
36
     */
37
    if (!empty($accept_course_request)) {
38
        $course_request_code = CourseRequestManager::get_course_request_code($accept_course_request);
39
        $course_id = CourseRequestManager::accept_course_request($accept_course_request);
40 View Code Duplication
        if ($course_id) {
41
            $course_code = CourseManager::get_course_code_from_course_id($course_id);
42
            $message = sprintf(get_lang('CourseRequestAccepted'), $course_request_code, $course_code);
43
            $is_error_message = false;
44
        } else {
45
            $message = sprintf(get_lang('CourseRequestAcceptanceFailed'), $course_request_code);
46
            $is_error_message = true;
47
        }
48
    } elseif (!empty($request_info)) {
49
        /**
50
         * Sending to the teacher a request for additional information about the proposed course.
51
         */
52
        $course_request_code = CourseRequestManager::get_course_request_code($request_info);
53
        $result = CourseRequestManager::ask_for_additional_info($request_info);
54
        if ($result) {
55
            $message = sprintf(get_lang('CourseRequestInfoAsked'), $course_request_code);
56
            $is_error_message = false;
57
        } else {
58
            $message = sprintf(get_lang('CourseRequestInfoFailed'), $course_request_code);
59
            $is_error_message = true;
60
        }
61
    } elseif (!empty($delete_course_request)) {
62
        /**
63
         * Deletion of a course request.
64
         */
65
        $course_request_code = CourseRequestManager::get_course_request_code($delete_course_request);
66
        $result = CourseRequestManager::delete_course_request($delete_course_request);
67
        if ($result) {
68
            $message = sprintf(get_lang('CourseRequestDeleted'), $course_request_code);
69
            $is_error_message = false;
70
        } else {
71
            $message = sprintf(get_lang('CourseRequestDeletionFailed'), $course_request_code);
72
            $is_error_message = true;
73
        }
74 View Code Duplication
    } elseif (isset($_POST['action'])) {
75
        /**
76
         * Form actions: delete.
77
         */
78
        switch ($_POST['action']) {
79
            // Delete selected courses
80
            case 'delete_course_requests' :
81
                $course_requests = $_POST['course_request'];
82
                if (is_array($_POST['course_request']) && !empty($_POST['course_request'])) {
83
                    $success = true;
84
                    foreach ($_POST['course_request'] as $index => $course_request_id) {
85
                        $success &= CourseRequestManager::delete_course_request($course_request_id);
86
                    }
87
                    $message = $success ? get_lang('SelectedCourseRequestsDeleted') : get_lang('SomeCourseRequestsNotDeleted');
88
                    $is_error_message = !$success;
89
                }
90
                break;
91
        }
92
    }
93 View Code Duplication
} else {
94
    $link_to_setting = api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Platform#course_validation';
95
    $message = sprintf(get_lang('PleaseActivateCourseValidationFeature'), sprintf('<strong><a href="%s">%s</a></strong>', $link_to_setting, get_lang('EnableCourseValidation')));
96
    $is_error_message = true;
97
}
98
99
/**
100
 * Get the number of courses which will be displayed.
101
 */
102
function get_number_of_requests() {
0 ignored issues
show
The function get_number_of_requests() has been defined more than once; this definition is ignored, only the first definition in main/admin/course_request_accepted.php (L75-77) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
103
    return CourseRequestManager::count_course_requests(COURSE_REQUEST_REJECTED);
104
}
105
106
/**
107
 * Get course data to display
108
 */
109 View Code Duplication
function get_request_data($from, $number_of_items, $column, $direction)
0 ignored issues
show
The function get_request_data() has been defined more than once; this definition is ignored, only the first definition in main/admin/course_request_accepted.php (L82-121) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
110
{
111
    $keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
112
    $course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
113
114
    $from = intval($from);
115
    $number_of_items = intval($number_of_items);
116
    $column = intval($column);
117
    $direction = !in_array(strtolower(trim($direction)), ['asc','desc']) ? 'asc' : $direction;
118
119
    $sql = "SELECT
120
                id AS col0,
121
               code AS col1,
122
               title AS col2,
123
               category_code AS col3,
124
               tutor_name AS col4,
125
               request_date AS col5,
126
               id  AS col6
127
           FROM $course_request_table
128
           WHERE status = ".COURSE_REQUEST_REJECTED;
129
130
    if ($keyword != '') {
131
        $sql .= " AND (
132
            title LIKE '%".$keyword."%' OR
133
            code LIKE '%".$keyword."%' OR
134
            visual_code LIKE '%".$keyword."%'
135
        )";
136
    }
137
    $sql .= " ORDER BY col$column $direction ";
138
    $sql .= " LIMIT $from,$number_of_items";
139
    $res = Database :: query($sql);
140
141
    $course_requests = array();
142
    while ($course_request = Database :: fetch_row($res)) {
143
        $course_request[5] = api_get_local_time($course_request[5]);
144
        $course_requests[] = $course_request;
145
    }
146
147
    return $course_requests;
148
}
149
150
/**
151
 * Actions in the list: edit, accept, delete, request additional information.
152
 */
153
function modify_filter($id) {
154
    $code = CourseRequestManager::get_course_request_code($id);
155
    $result = '<a href="course_request_edit.php?id='.$id.'&caller=2">'.Display::return_icon('edit.png', get_lang('Edit'), array('style' => 'vertical-align: middle;')).'</a>'.
156
        '&nbsp;<a href="?accept_course_request='.$id.'">'.Display::return_icon('accept.png', get_lang('AcceptThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ANewCourseWillBeCreated'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
157 View Code Duplication
    if (!CourseRequestManager::additional_info_asked($id)) {
158
        $result .= '&nbsp;<a href="?request_info='.$id.'">'.Display::return_icon('request_info.gif', get_lang('AskAdditionalInfo'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('AdditionalInfoWillBeAsked'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
159
    }
160
    $result .= '&nbsp;<a href="?delete_course_request='.$id.'">'.Display::return_icon('delete.png', get_lang('DeleteThisCourseRequest'), array('style' => 'vertical-align: middle;', 'onclick' => 'javascript: if (!confirm(\''.addslashes(api_htmlentities(sprintf(get_lang('ACourseRequestWillBeDeleted'), $code), ENT_QUOTES)).'\')) return false;')).'</a>';
161
162
    return $result;
163
}
164
165
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
166
$interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
167
168
169
$tool_name = get_lang('RejectedCourseRequests');
170
Display :: display_header($tool_name);
171
172
// Display confirmation or error message.
173 View Code Duplication
if (!empty($message)) {
174
    if ($is_error_message) {
175
        Display::display_error_message($message, false);
176
    } else {
177
        Display::display_normal_message($message, false);
178
    }
179
}
180
181
if (!$course_validation_feature) {
182
    Display :: display_footer();
183
    exit;
184
}
185
186
// Create a simple search-box.
187
$form = new FormValidator('search_simple', 'get', '', '', 'width=200px', false);
188
$renderer = $form->defaultRenderer();
189
$renderer->setCustomElementTemplate('<span>{element}</span> ');
190
$form->addElement('text', 'keyword', get_lang('Keyword'));
191
$form->addButtonSearch(get_lang('Search'));
192
193
// The action bar.
194
echo '<div style="float: right; margin-top: 5px; margin-right: 5px;">';
195
echo ' <a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests')).get_lang('ReviewCourseRequests').'</a>';
196
echo ' <a href="course_request_accepted.php">'.Display::return_icon('course_request_accepted.gif', get_lang('AcceptedCourseRequests')).get_lang('AcceptedCourseRequests').'</a>';
197
echo '</div>';
198
echo '<div class="actions">';
199
$form->display();
200
echo '</div>';
201
202
// Create a sortable table with the course data.
203
$table = new SortableTable('course_requests_rejected', 'get_number_of_requests', 'get_request_data', 5, 20, 'DESC');
204
$table->set_header(0, '', false);
205
$table->set_header(1, get_lang('Code'));
206
$table->set_header(2, get_lang('Title'));
207
$table->set_header(3, get_lang('Category'));
208
$table->set_header(4, get_lang('Teacher'));
209
$table->set_header(5, get_lang('CourseRequestDate'));
210
$table->set_header(6, '', false);
211
$table->set_column_filter(6, 'modify_filter');
212
$table->set_form_actions(array('delete_course_requests' => get_lang('DeleteCourseRequests')), 'course_request');
213
$table->display();
214
215
/* FOOTER */
216
217
Display :: display_footer();
218