Minor - partial merge from 1.11.x

pull/2487/merge
Julio Montoya 7 years ago
parent fc7cbbe51d
commit ff23224e88
  1. 2
      main/inc/ajax/agenda.ajax.php
  2. 2
      main/inc/ajax/chat.ajax.php
  3. 54
      main/inc/ajax/course.ajax.php
  4. 10
      main/inc/ajax/course_chat.ajax.php
  5. 24
      main/inc/ajax/course_home.ajax.php
  6. 110
      main/inc/ajax/exercise.ajax.php
  7. 4
      main/inc/ajax/message.ajax.php
  8. 130
      main/inc/ajax/model.ajax.php
  9. 6
      main/inc/ajax/online.ajax.php
  10. 38
      main/inc/ajax/record_audio_rtc.ajax.php
  11. 86
      main/inc/ajax/record_audio_wami.ajax.php
  12. 6
      main/inc/ajax/session.ajax.php
  13. 2
      main/inc/ajax/user_manager.ajax.php
  14. 1
      main/inc/lib/formvalidator/Element/DatePicker.php
  15. 3
      main/inc/lib/hook/HookUpdateUser.php
  16. 18
      main/inc/lib/pear/HTML/QuickForm.php
  17. 7
      main/inc/lib/pear/HTML/QuickForm/Rule/MinText.php
  18. 412
      main/inc/lib/pear/HTML/QuickForm/advmultiselect.php
  19. 4
      main/inc/lib/pear/HTML/QuickForm/button.php
  20. 12
      main/inc/lib/pear/HTML/QuickForm/checkbox.php
  21. 5
      main/inc/lib/pear/HTML/QuickForm/select.php
  22. 10
      main/inc/lib/webservices/Rest.php

@ -120,7 +120,7 @@ switch ($action) {
$DaysShort = api_get_week_days_short(); $DaysShort = api_get_week_days_short();
$MonthsLong = api_get_months_long(); $MonthsLong = api_get_months_long();
$user_id = intval($_REQUEST['user_id']); $user_id = (int) $_REQUEST['user_id'];
$my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true); $my_course_list = CourseManager::get_courses_list_by_user_id($user_id, true);
if (!is_array($my_course_list)) { if (!is_array($my_course_list)) {
// this is for the special case if the user has no courses (otherwise you get an error) // this is for the special case if the user has no courses (otherwise you get an error)

@ -71,7 +71,7 @@ switch ($action) {
exit; exit;
break; break;
case 'set_status': case 'set_status':
$status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0; $status = isset($_REQUEST['status']) ? (int) $_REQUEST['status'] : 0;
$chat->setUserStatus($status); $chat->setUserStatus($status);
break; break;
case 'create_room': case 'create_room':

@ -13,8 +13,8 @@ $user_id = api_get_user_id();
switch ($action) { switch ($action) {
case 'add_course_vote': case 'add_course_vote':
$course_id = intval($_REQUEST['course_id']); $course_id = (int) $_REQUEST['course_id'];
$star = intval($_REQUEST['star']); $star = (int) $_REQUEST['star'];
if (!api_is_anonymous()) { if (!api_is_anonymous()) {
CourseManager::add_course_vote($user_id, $star, $course_id, 0); CourseManager::add_course_vote($user_id, $star, $course_id, 0);
@ -40,7 +40,7 @@ switch ($action) {
case 'get_user_courses': case 'get_user_courses':
// Only search my courses // Only search my courses
if (api_is_platform_admin() || api_is_session_admin()) { if (api_is_platform_admin() || api_is_session_admin()) {
$userId = intval($_REQUEST['user_id']); $userId = (int) $_REQUEST['user_id'];
$list = CourseManager::get_courses_list_by_user_id( $list = CourseManager::get_courses_list_by_user_id(
$userId, $userId,
false false
@ -125,8 +125,8 @@ switch ($action) {
} }
break; break;
case 'search_course': case 'search_course':
if (api_is_teacher()) { if (api_is_teacher() || api_is_platform_admin()) {
if (!empty($_GET['session_id']) && intval($_GET['session_id'])) { if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {
//if session is defined, lets find only courses of this session //if session is defined, lets find only courses of this session
$courseList = SessionManager::get_course_list_by_session_id( $courseList = SessionManager::get_course_list_by_session_id(
$_GET['session_id'], $_GET['session_id'],
@ -231,27 +231,41 @@ switch ($action) {
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$user = Database::get_main_table(TABLE_MAIN_USER); $user = Database::get_main_table(TABLE_MAIN_USER);
$session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sessionId = $_GET['session_id'];
$course = api_get_course_info_by_id($_GET['course_id']); $course = api_get_course_info_by_id($_GET['course_id']);
$json = [ $json = [
'items' => [], 'items' => [],
]; ];
$sql = "SELECT u.user_id as id, u.username, u.lastname, u.firstname $keyword = Database::escape_string($_GET['q']);
FROM $user u $status = 0;
INNER JOIN $session_course_user r if (empty($sessionId)) {
ON u.user_id = r.user_id $status = STUDENT;
WHERE session_id = %d AND c_id = '%s' }
AND (u.firstname LIKE '%s' OR u.username LIKE '%s' OR u.lastname LIKE '%s')";
$needle = '%'.$_GET['q'].'%';
$sql_query = sprintf($sql, $_GET['session_id'], $course['real_id'], $needle, $needle, $needle);
$result = Database::query($sql_query); $userList = CourseManager::get_user_list_from_course_code(
while ($user = Database::fetch_assoc($result)) { $course['code'],
$sessionId,
null,
null,
$status,
false,
false,
false,
[],
[],
[],
true,
[],
$_GET['q']
);
foreach ($userList as $user) {
$userCompleteName = api_get_person_name($user['firstname'], $user['lastname']); $userCompleteName = api_get_person_name($user['firstname'], $user['lastname']);
$json['items'][] = [ $json['items'][] = [
'id' => $user['id'], 'id' => $user['user_id'],
'text' => "{$user['username']} ($userCompleteName)", 'text' => "{$user['username']} ($userCompleteName)",
]; ];
} }
@ -262,7 +276,7 @@ switch ($action) {
case 'search_exercise_by_course': case 'search_exercise_by_course':
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$course = api_get_course_info_by_id($_GET['course_id']); $course = api_get_course_info_by_id($_GET['course_id']);
$session_id = (!empty($_GET['session_id'])) ? intval($_GET['session_id']) : 0; $session_id = (!empty($_GET['session_id'])) ? (int) $_GET['session_id'] : 0;
$exercises = ExerciseLib::get_all_exercises( $exercises = ExerciseLib::get_all_exercises(
$course, $course,
$session_id, $session_id,
@ -296,8 +310,8 @@ switch ($action) {
$sql_query = sprintf( $sql_query = sprintf(
$sql, $sql,
intval($_GET['course_id']), (int) $_GET['course_id'],
intval($_GET['session_id']), (int) $_GET['session_id'],
'%'.Database::escape_string($_GET['q']).'%' '%'.Database::escape_string($_GET['q']).'%'
); );
$result = Database::query($sql_query); $result = Database::query($sql_query);
@ -316,7 +330,7 @@ switch ($action) {
} }
break; break;
case 'display_sessions_courses': case 'display_sessions_courses':
$sessionId = intval($_GET['session']); $sessionId = (int) $_GET['session'];
$userTable = Database::get_main_table(TABLE_MAIN_USER); $userTable = Database::get_main_table(TABLE_MAIN_USER);
$coursesData = SessionManager::get_course_list_by_session_id($sessionId); $coursesData = SessionManager::get_course_list_by_session_id($sessionId);

@ -22,12 +22,12 @@ switch ($_REQUEST['action']) {
$courseChatUtils->keepUserAsConnected(); $courseChatUtils->keepUserAsConnected();
$courseChatUtils->disconnectInactiveUsers(); $courseChatUtils->disconnectInactiveUsers();
$friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0;
$filePath = $courseChatUtils->getFileName(true, $friend); $filePath = $courseChatUtils->getFileName(true, $friend);
$newFileSize = file_exists($filePath) ? filesize($filePath) : 0; $newFileSize = file_exists($filePath) ? filesize($filePath) : 0;
$oldFileSize = isset($_GET['size']) ? intval($_GET['size']) : -1; $oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1;
$newUsersOnline = $courseChatUtils->countUsersOnline(); $newUsersOnline = $courseChatUtils->countUsersOnline();
$oldUsersOnline = isset($_GET['users_online']) ? intval($_GET['users_online']) : 0; $oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0;
$json = [ $json = [
'status' => true, 'status' => true,
@ -50,7 +50,7 @@ switch ($_REQUEST['action']) {
]; ];
break; break;
case 'reset': case 'reset':
$friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0;
$json = [ $json = [
'status' => true, 'status' => true,
@ -58,7 +58,7 @@ switch ($_REQUEST['action']) {
]; ];
break; break;
case 'write': case 'write':
$friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0;
$writed = $courseChatUtils->saveMessage($_POST['message'], $friend); $writed = $courseChatUtils->saveMessage($_POST['message'], $friend);
$json = [ $json = [

@ -174,16 +174,16 @@ switch ($action) {
*/ */
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
$now = time(); $now = time();
$page = intval($_REQUEST['page']); //page $page = (int) $_REQUEST['page']; //page
$limit = intval($_REQUEST['rows']); // quantity of rows $limit = (int) $_REQUEST['rows']; // quantity of rows
//index to filter //index to filter
$sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id'; $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
$sord = $_REQUEST['sord']; //asc or desc $sord = $_REQUEST['sord']; //asc or desc
if (!in_array($sord, ['asc', 'desc'])) { if (!in_array($sord, ['asc', 'desc'])) {
$sord = 'desc'; $sord = 'desc';
} }
$session_id = intval($_REQUEST['session_id']); $session_id = (int) $_REQUEST['session_id'];
$course_id = intval($_REQUEST['course_id']); $course_id = (int) $_REQUEST['course_id'];
//Filter users that does not belong to the session //Filter users that does not belong to the session
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
@ -302,8 +302,8 @@ switch ($action) {
case 'session_courses_lp_by_week': case 'session_courses_lp_by_week':
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
$now = time(); $now = time();
$page = intval($_REQUEST['page']); //page $page = (int) $_REQUEST['page']; //page
$limit = intval($_REQUEST['rows']); // quantity of rows $limit = (int) $_REQUEST['rows']; // quantity of rows
$sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course'; $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course';
$sidx = str_replace(['week desc,', ' '], '', $sidx); $sidx = str_replace(['week desc,', ' '], '', $sidx);
$sord = $_REQUEST['sord']; //asc or desc $sord = $_REQUEST['sord']; //asc or desc
@ -311,8 +311,8 @@ switch ($action) {
$sord = 'desc'; $sord = 'desc';
} }
$session_id = intval($_REQUEST['session_id']); $session_id = (int) $_REQUEST['session_id'];
$course_id = intval($_REQUEST['course_id']); $course_id = (int) $_REQUEST['course_id'];
//Filter users that does not belong to the session //Filter users that does not belong to the session
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
@ -445,8 +445,8 @@ switch ($action) {
case 'session_courses_lp_by_course': case 'session_courses_lp_by_course':
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
$now = time(); $now = time();
$page = intval($_REQUEST['page']); //page $page = (int) $_REQUEST['page']; //page
$limit = intval($_REQUEST['rows']); // quantity of rows $limit = (int) $_REQUEST['rows']; // quantity of rows
$sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id'; $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id';
$sidx = str_replace(['course asc,', ' '], '', $sidx); $sidx = str_replace(['course asc,', ' '], '', $sidx);
@ -454,8 +454,8 @@ switch ($action) {
if (!in_array($sord, ['asc', 'desc'])) { if (!in_array($sord, ['asc', 'desc'])) {
$sord = 'desc'; $sord = 'desc';
} }
$session_id = intval($_REQUEST['session_id']); $session_id = (int) $_REQUEST['session_id'];
$course_id = intval($_REQUEST['course_id']); $course_id = (int) $_REQUEST['course_id'];
//Filter users that does not belong to the session //Filter users that does not belong to the session
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {

@ -11,14 +11,15 @@ $debug = false;
api_protect_course_script(true); api_protect_course_script(true);
$action = $_REQUEST['a']; $action = $_REQUEST['a'];
$course_id = api_get_course_int_id();
if ($debug) { if ($debug) {
error_log("-----------------"); error_log('-----------------------------------------------------');
error_log("$action ajax call"); error_log("$action ajax call");
error_log("-----------------"); error_log('-----------------------------------------------------');
} }
$session_id = isset($_REQUEST['session_id']) ? intval($_REQUEST['session_id']) : api_get_session_id(); $course_id = api_get_course_int_id();
$session_id = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : api_get_session_id();
$course_code = isset($_REQUEST['cidReq']) ? $_REQUEST['cidReq'] : api_get_course_id(); $course_code = isset($_REQUEST['cidReq']) ? $_REQUEST['cidReq'] : api_get_course_id();
switch ($action) { switch ($action) {
@ -34,7 +35,7 @@ switch ($action) {
if (empty($exeId)) { if (empty($exeId)) {
if ($debug) { if ($debug) {
error_log("Exe id not provided."); error_log('Exe id not provided.');
} }
exit; exit;
} }
@ -44,7 +45,7 @@ switch ($action) {
if (empty($exerciseInSession)) { if (empty($exerciseInSession)) {
if ($debug) { if ($debug) {
error_log("Exercise obj not provided."); error_log('Exercise obj not provided.');
} }
exit; exit;
} }
@ -85,7 +86,7 @@ switch ($action) {
if ($attempt->getStatus() != 'incomplete') { if ($attempt->getStatus() != 'incomplete') {
if ($debug) { if ($debug) {
error_log("Cannot update exercise is already completed."); error_log('Cannot update exercise is already completed.');
} }
exit; exit;
} }
@ -105,10 +106,6 @@ switch ($action) {
) { ) {
$sessionTime = $previousTime[$key]; $sessionTime = $previousTime[$key];
$duration = $sessionTime = $now - $sessionTime; $duration = $sessionTime = $now - $sessionTime;
/*if ($debug) {
error_log("Now in UTC: ".$nowObject->format('Y-m-d H:i:s'));
error_log("Session time in UTC: ".api_get_utc_datetime($sessionTime));
}*/
if (!empty($durationFromObject)) { if (!empty($durationFromObject)) {
$duration += $durationFromObject; $duration += $durationFromObject;
} }
@ -150,9 +147,9 @@ switch ($action) {
// 1. Setting variables needed by jqgrid // 1. Setting variables needed by jqgrid
$action = $_GET['a']; $action = $_GET['a'];
$exercise_id = intval($_GET['exercise_id']); $exercise_id = (int) $_GET['exercise_id'];
$page = intval($_REQUEST['page']); //page $page = (int) $_REQUEST['page']; //page
$limit = intval($_REQUEST['rows']); //quantity of rows $limit = (int) $_REQUEST['rows']; //quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter $sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc $sord = $_REQUEST['sord']; //asc or desc
@ -169,7 +166,7 @@ switch ($action) {
$user_table = Database::get_main_table(TABLE_MAIN_USER); $user_table = Database::get_main_table(TABLE_MAIN_USER);
$track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$minutes = intval($_REQUEST['minutes']); $minutes = (int) $_REQUEST['minutes'];
$now = time() - 60 * $minutes; $now = time() - 60 * $minutes;
$now = api_get_utc_datetime($now); $now = api_get_utc_datetime($now);
@ -271,7 +268,9 @@ switch ($action) {
$response->rows[$i]['id'] = $row['exe_id']; $response->rows[$i]['id'] = $row['exe_id'];
if (!empty($oExe->expired_time)) { if (!empty($oExe->expired_time)) {
$remaining = strtotime($row['start_date']) + ($oExe->expired_time * 60) - strtotime(api_get_utc_datetime(time())); $remaining = strtotime($row['start_date']) +
($oExe->expired_time * 60) -
strtotime(api_get_utc_datetime(time()));
$h = floor($remaining / 3600); $h = floor($remaining / 3600);
$m = floor(($remaining - ($h * 3600)) / 60); $m = floor(($remaining - ($h * 3600)) / 60);
$s = ($remaining - ($h * 3600) - ($m * 60)); $s = ($remaining - ($h * 3600) - ($m * 60));
@ -313,7 +312,7 @@ switch ($action) {
[ [
'exercise_order' => $counter, 'exercise_order' => $counter,
'session_id' => $session_id, 'session_id' => $session_id,
'exercise_id' => intval($new_order_id), 'exercise_id' => (int) $new_order_id,
'c_id' => $course_id, 'c_id' => $course_id,
] ]
); );
@ -325,7 +324,7 @@ switch ($action) {
case 'update_question_order': case 'update_question_order':
$course_info = api_get_course_info_by_id($course_id); $course_info = api_get_course_info_by_id($course_id);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$exercise_id = isset($_REQUEST['exercise_id']) ? $_REQUEST['exercise_id'] : null; $exercise_id = isset($_REQUEST['exercise_id']) ? (int) $_REQUEST['exercise_id'] : null;
if (empty($exercise_id)) { if (empty($exercise_id)) {
return Display::return_message(get_lang('Error'), 'error'); return Display::return_message(get_lang('Error'), 'error');
@ -340,9 +339,7 @@ switch ($action) {
['question_order' => $counter], ['question_order' => $counter],
[ [
'question_id = ? AND c_id = ? AND exercice_id = ? ' => [ 'question_id = ? AND c_id = ? AND exercice_id = ? ' => [
intval( (int) $new_order_id,
$new_order_id
),
$course_id, $course_id,
$exercise_id, $exercise_id,
], ],
@ -399,18 +396,23 @@ switch ($action) {
// Questions choices. // Questions choices.
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null; $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
// certainty degree choice
$choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty'])
? $_REQUEST['choiceDegreeCertainty'] : null;
// Hot spot coordinates from all questions. // Hot spot coordinates from all questions.
$hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : null; $hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : null;
// There is a reminder? // There is a reminder?
$remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list']) ? array_keys($_REQUEST['remind_list']) : null; $remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list'])
? array_keys($_REQUEST['remind_list']) : null;
// Needed in manage_answer. // Needed in manage_answer.
$learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0; $learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0; $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
// Attempt id. // Attempt id.
$exeId = $_REQUEST['exe_id']; $exeId = isset($_REQUEST['exe_id']) ? (int) $_REQUEST['exe_id'] : 0;
if ($debug) { if ($debug) {
error_log("exe_id = $exeId"); error_log("exe_id = $exeId");
@ -418,6 +420,7 @@ switch ($action) {
error_log("choice = ".print_r($choice, 1)." "); error_log("choice = ".print_r($choice, 1)." ");
error_log("hot_spot_coordinates = ".print_r($hot_spot_coordinates, 1)); error_log("hot_spot_coordinates = ".print_r($hot_spot_coordinates, 1));
error_log("remind_list = ".print_r($remind_list, 1)); error_log("remind_list = ".print_r($remind_list, 1));
error_log("--------------------------------");
} }
// Exercise information. // Exercise information.
@ -484,7 +487,7 @@ switch ($action) {
// Fires an error. // Fires an error.
echo 'error'; echo 'error';
if ($debug) { if ($debug) {
error_log("exe_id is empty"); error_log('exe_id is empty');
} }
exit; exit;
} }
@ -520,6 +523,13 @@ switch ($action) {
// Creates a temporary Question object // Creates a temporary Question object
$objQuestionTmp = Question::read($my_question_id, $course_id); $objQuestionTmp = Question::read($my_question_id, $course_id);
$myChoiceDegreeCertainty = null;
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
if (isset($choiceDegreeCertainty[$my_question_id])) {
$myChoiceDegreeCertainty = $choiceDegreeCertainty[$my_question_id];
}
}
// Getting free choice data. // Getting free choice data.
if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION]) && $type == 'all') { if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION]) && $type == 'all') {
$my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id]) $my_choice = isset($_REQUEST['free_choice'][$my_question_id]) && !empty($_REQUEST['free_choice'][$my_question_id])
@ -538,6 +548,7 @@ switch ($action) {
) { ) {
$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id]; $hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id];
} }
if ($type == 'simple') { if ($type == 'simple') {
// Getting old attempt in order to decrees the total score. // Getting old attempt in order to decrees the total score.
$old_result = $objExercise->manage_answer( $old_result = $objExercise->manage_answer(
@ -569,7 +580,7 @@ switch ($action) {
$session_id, $session_id,
$my_question_id $my_question_id
); );
if ($objQuestionTmp->type == HOT_SPOT) { if ($objQuestionTmp->type === HOT_SPOT) {
Event::delete_attempt_hotspot( Event::delete_attempt_hotspot(
$exeId, $exeId,
api_get_user_id(), api_get_user_id(),
@ -587,6 +598,23 @@ switch ($action) {
} }
// We're inside *one* question. Go through each possible answer for this question // We're inside *one* question. Go through each possible answer for this question
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
$myChoiceTmp = [];
$myChoiceTmp['choice'] = $my_choice;
$myChoiceTmp['choiceDegreeCertainty'] = $myChoiceDegreeCertainty;
$result = $objExercise->manage_answer(
$exeId,
$my_question_id,
$myChoiceTmp,
'exercise_result',
$hot_spot_coordinates,
true,
false,
false,
$objExercise->selectPropagateNeg(),
$hotspot_delineation_result
);
} else {
$result = $objExercise->manage_answer( $result = $objExercise->manage_answer(
$exeId, $exeId,
$my_question_id, $my_question_id,
@ -599,6 +627,7 @@ switch ($action) {
$objExercise->selectPropagateNeg(), $objExercise->selectPropagateNeg(),
$hotspot_delineation_result $hotspot_delineation_result
); );
}
// Adding the new score. // Adding the new score.
$total_score += $result['score']; $total_score += $result['score'];
@ -610,7 +639,6 @@ switch ($action) {
$duration = 0; $duration = 0;
$now = time(); $now = time();
if ($type == 'all') { if ($type == 'all') {
$exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId); $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exeId);
} }
@ -642,7 +670,6 @@ switch ($action) {
} }
Session::write('duration_time', [$key => $now]); Session::write('duration_time', [$key => $now]);
Event::updateEventExercise( Event::updateEventExercise(
$exeId, $exeId,
$objExercise->selectId(), $objExercise->selectId(),
@ -661,18 +688,28 @@ switch ($action) {
// Destruction of the Question object // Destruction of the Question object
unset($objQuestionTmp); unset($objQuestionTmp);
if ($debug) { if ($debug) {
error_log(" -- end question -- "); error_log("---------- end question ------------");
} }
} }
if ($debug) {
error_log(" ------ end ajax call ------- ");
} }
if ($type == 'all') {
echo 'ok';
exit;
} }
if ($objExercise->type == ONE_PER_PAGE) { if ($objExercise->type == ONE_PER_PAGE) {
if ($debug) {
error_log("result: one_per_page");
error_log(" ------ end ajax call ------- ");
}
echo 'one_per_page'; echo 'one_per_page';
exit; exit;
} }
if ($debug) {
error_log("result: ok");
error_log(" ------ end ajax call ------- ");
}
echo 'ok'; echo 'ok';
break; break;
case 'show_question': case 'show_question':
@ -692,17 +729,22 @@ switch ($action) {
$objExercise = new Exercise(); $objExercise = new Exercise();
$objExercise->read($exerciseId); $objExercise->read($exerciseId);
$objQuestion = Question::read($questionId); $objQuestion = Question::read($questionId);
echo '<p class="lead">'.$objQuestion->get_question_type_name().'</p>'; echo '<p class="lead">'.$objQuestion->get_question_type_name().'</p>';
if ($objQuestion->type == FILL_IN_BLANKS) { if ($objQuestion->type === FILL_IN_BLANKS) {
echo '<script> echo '<script>
$(function() { $(function() {
$(".selectpicker").selectpicker({}); $(".selectpicker").selectpicker({});
}); });
</script>'; </script>';
} }
// Allows render MathJax elements in a ajax call
if (api_get_setting('include_asciimathml_script') === 'true') {
echo '<script> MathJax.Hub.Queue(["Typeset",MathJax.Hub]);</script>';
}
ExerciseLib::showQuestion( ExerciseLib::showQuestion(
$objExercise, $objExercise,
$questionId, $questionId,

@ -96,9 +96,7 @@ switch ($action) {
break; break;
} }
/** @var UserRepository $repo */ $repo = UserManager::getRepository();
$repo = Database::getManager()->getRepository('ChamiloUserBundle:User');
$users = $repo->findUsersToSendMessage( $users = $repo->findUsersToSendMessage(
api_get_user_id(), api_get_user_id(),
$_REQUEST['q'], $_REQUEST['q'],

@ -53,6 +53,7 @@ if (!in_array(
'get_work_user_list_all', 'get_work_user_list_all',
'get_timelines', 'get_timelines',
'get_user_skill_ranking', 'get_user_skill_ranking',
'get_usergroups',
'get_usergroups_teacher', 'get_usergroups_teacher',
'get_user_course_report_resumed', 'get_user_course_report_resumed',
'get_user_course_report', 'get_user_course_report',
@ -60,6 +61,9 @@ if (!in_array(
'get_sessions', 'get_sessions',
'get_course_announcements', 'get_course_announcements',
'course_log_events', 'course_log_events',
'get_learning_path_calendars',
'get_usergroups_users',
'get_calendar_users',
] ]
) && !isset($_REQUEST['from_course_session'])) { ) && !isset($_REQUEST['from_course_session'])) {
api_protect_admin_script(true); api_protect_admin_script(true);
@ -228,13 +232,27 @@ if (!$sidx) {
//@todo rework this //@todo rework this
switch ($action) { switch ($action) {
case 'get_calendar_users':
$calendarPlugin = LearningCalendarPlugin::create();
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$count = $calendarPlugin->getUsersPerCalendarCount($id);
break;
case 'get_usergroups_users':
$usergroup = new UserGroup();
$usergroup->protectScript();
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$count = $usergroup->getUserGroupUsers($id, true);
break;
case 'get_learning_path_calendars':
$calendarPlugin = LearningCalendarPlugin::create();
$count = $calendarPlugin->getCalendarCount();
break;
case 'course_log_events': case 'course_log_events':
$courseId = api_get_course_int_id(); $courseId = api_get_course_int_id();
if (empty($courseId)) { if (empty($courseId)) {
exit; exit;
} }
$sessionId = api_get_session_id(); $sessionId = api_get_session_id();
if (!api_is_allowed_to_edit()) { if (!api_is_allowed_to_edit()) {
exit; exit;
} }
@ -262,9 +280,8 @@ switch ($action) {
if ($userNotAllowed) { if ($userNotAllowed) {
exit; exit;
} }
$userId = api_get_user_id(); $userId = api_get_user_id();
$sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0; $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
$courseCodeList = []; $courseCodeList = [];
$userIdList = []; $userIdList = [];
$sessionIdList = []; $sessionIdList = [];
@ -732,15 +749,16 @@ switch ($action) {
break; break;
case 'get_usergroups': case 'get_usergroups':
$obj = new UserGroup(); $obj = new UserGroup();
$obj->protectScript();
$count = $obj->get_count(); $count = $obj->get_count();
break; break;
case 'get_usergroups_teacher': case 'get_usergroups_teacher':
$obj = new UserGroup(); $obj = new UserGroup();
$obj->protectScript();
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered'; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'registered';
$groupFilter = isset($_REQUEST['group_filter']) ? intval($_REQUEST['group_filter']) : 0; $groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
if ($type == 'registered') { if ($type === 'registered') {
$count = $obj->getUserGroupByCourseWithDataCount( $count = $obj->getUserGroupByCourseWithDataCount(
$course_id, $course_id,
$groupFilter $groupFilter
@ -780,9 +798,37 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit
$columns = []; $columns = [];
switch ($action) { switch ($action) {
case 'get_calendar_users':
$columns = ['firstname', 'lastname', 'exam'];
$result = $calendarPlugin->getUsersPerCalendar($id);
break;
case 'get_usergroups_users':
$columns = ['name', 'actions'];
if (api_get_plugin_setting('learning_calendar', 'enabled') === 'true') {
$columns = [
'name',
'calendar',
'gradebook_items',
'time_spent',
'lp_day_completed',
'days_diff',
'actions',
'calendar_id',
];
}
$result = $usergroup->getUserGroupUsers($id);
break;
case 'get_learning_path_calendars':
$columns = ['title', 'total_hours', 'minutes_per_day', 'actions'];
$result = $calendarPlugin->getCalendars(
$start,
$limit,
$sidx,
$sord
);
break;
case 'course_log_events': case 'course_log_events':
$columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; $columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
$result = Statistics::getActivitiesData( $result = Statistics::getActivitiesData(
$start, $start,
$limit, $limit,
@ -791,7 +837,6 @@ switch ($action) {
$courseId, $courseId,
$sessionId $sessionId
); );
break; break;
case 'get_programmed_announcements': case 'get_programmed_announcements':
$columns = ['subject', 'date', 'sent', 'actions']; $columns = ['subject', 'date', 'sent', 'actions'];
@ -1239,6 +1284,8 @@ switch ($action) {
]; ];
$extraFieldsToAdd = []; $extraFieldsToAdd = [];
$extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields'); $extraFields = api_get_configuration_value('exercise_category_report_user_extra_fields');
$roundValues = api_get_configuration_value('exercise_category_round_score_in_export');
if (!empty($extraFields) && isset($extraFields['fields'])) { if (!empty($extraFields) && isset($extraFields['fields'])) {
$extraField = new ExtraField('user'); $extraField = new ExtraField('user');
foreach ($extraFields['fields'] as $variable) { foreach ($extraFields['fields'] as $variable) {
@ -1257,7 +1304,7 @@ switch ($action) {
$columns[] = 'exe_date'; $columns[] = 'exe_date';
$columns[] = 'score'; $columns[] = 'score';
if ($operation == 'excel') { if ($operation === 'excel') {
$columns = [ $columns = [
'firstname', 'firstname',
'lastname', 'lastname',
@ -1320,7 +1367,8 @@ switch ($action) {
true, true,
true, true,
$extraFieldsToAdd, $extraFieldsToAdd,
true true,
$roundValues
); );
break; break;
case 'get_hotpotatoes_exercise_results': case 'get_hotpotatoes_exercise_results':
@ -1435,20 +1483,13 @@ switch ($action) {
0, 0,
true true
); );
$session_date = [];
if (!empty($session['access_start_date'])) {
$session_date[] = get_lang('From').' '.api_format_date($session['access_start_date'], DATE_FORMAT_SHORT);
}
if (!empty($session['access_end_date'])) { $session['display_start_date'] = '';
$session_date[] = get_lang('Until').' '.api_format_date($session['access_end_date'], DATE_FORMAT_SHORT); $session['display_end_date'] = '';
} $session['coach_access_start_date'] = '';
$session['coach_access_end_date'] = '';
if (empty($session_date)) { $dateData = SessionManager::parseSessionDates($session, true);
$session_date_string = '-'; $dateToString = $dateData['access'];
} else {
$session_date_string = implode(' ', $session_date);
}
$detailButtons = []; $detailButtons = [];
$detailButtons[] = Display::url( $detailButtons[] = Display::url(
@ -1465,7 +1506,7 @@ switch ($action) {
$session['name'], $session['name'],
api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'] api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id']
), ),
'date' => $session_date_string, 'date' => $dateToString,
'course_per_session' => $count_courses_in_session, 'course_per_session' => $count_courses_in_session,
'student_per_session' => $count_users_in_session, 'student_per_session' => $count_users_in_session,
'details' => implode(' ', $detailButtons), 'details' => implode(' ', $detailButtons),
@ -1535,9 +1576,9 @@ switch ($action) {
*/ */
break; break;
case 'get_exercise_progress': case 'get_exercise_progress':
$sessionId = intval($_GET['session_id']); $sessionId = (int) $_GET['session_id'];
$courseId = intval($_GET['course_id']); $courseId = (int) $_GET['course_id'];
$exerciseId = intval($_GET['exercise_id']); $exerciseId = (int) $_GET['exercise_id'];
$date_from = $_GET['date_from']; $date_from = $_GET['date_from'];
$date_to = $_GET['date_to']; $date_to = $_GET['date_to'];
@ -1572,8 +1613,8 @@ switch ($action) {
case 'get_session_lp_progress': case 'get_session_lp_progress':
$sessionId = 0; $sessionId = 0;
if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) { if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
$sessionId = intval($_GET['session_id']); $sessionId = (int) $_GET['session_id'];
$courseId = intval($_GET['course_id']); $courseId = (int) $_GET['course_id'];
$course = api_get_course_info_by_id($courseId); $course = api_get_course_info_by_id($courseId);
} }
@ -1914,6 +1955,7 @@ switch ($action) {
$result = $new_result; $result = $new_result;
break; break;
case 'get_usergroups': case 'get_usergroups':
$obj->protectScript();
$columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions']; $columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions'];
$result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit); $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit);
break; break;
@ -2075,19 +2117,29 @@ switch ($action) {
switch ($type) { switch ($type) {
case 'not_registered': case 'not_registered':
$options['where'] = [" (course_id IS NULL OR course_id != ?) " => $course_id]; $options['where'] = [' (course_id IS NULL OR course_id != ?) ' => $course_id];
$result = $obj->getUserGroupNotInCourse($options, $groupFilter); $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
break; break;
case 'registered': case 'registered':
$options['where'] = [" usergroup.course_id = ? " => $course_id]; $options['where'] = [' usergroup.course_id = ? ' => $course_id];
$result = $obj->getUserGroupInCourse($options, $groupFilter); $result = $obj->getUserGroupInCourse($options, $groupFilter);
break; break;
} }
$new_result = []; $new_result = [];
if (!empty($result)) { if (!empty($result)) {
$urlUserGroup = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq();
foreach ($result as $group) { foreach ($result as $group) {
$group['users'] = count($obj->get_users_by_usergroup($group['id'])); $count = count($obj->get_users_by_usergroup($group['id']));
$group['users'] = $count;
if ($obj->allowTeachers()) {
$group['users'] = Display::url(
$count,
$urlUserGroup.'&id='.$group['id']
);
}
if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) { if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
$url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq(); $url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq();
$icon = Display::return_icon('delete.png', get_lang('Remove')); $icon = Display::return_icon('delete.png', get_lang('Remove'));
@ -2107,7 +2159,16 @@ switch ($action) {
$role = $obj->getUserRoleToString(api_get_user_id(), $group['id']); $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']);
$group['status'] = $role; $group['status'] = $role;
$group['actions'] = Display::url($icon, $url); $group['actions'] = '';
if ($obj->allowTeachers()) {
$group['actions'] .= Display::url(
Display::return_icon('stats.png'),
$urlUserGroup.'&id='.$group['id']
).'&nbsp;';
}
$group['actions'] .= Display::url($icon, $url);
$new_result[] = $group; $new_result[] = $group;
} }
$result = $new_result; $result = $new_result;
@ -2159,6 +2220,9 @@ $allowed_actions = [
'get_course_announcements', 'get_course_announcements',
'get_programmed_announcements', 'get_programmed_announcements',
'course_log_events', 'course_log_events',
'get_learning_path_calendars',
'get_usergroups_users',
'get_calendar_users',
]; ];
//5. Creating an obj to return a json //5. Creating an obj to return a json

@ -12,11 +12,15 @@ switch ($action) {
echo returnNotificationMenu(); echo returnNotificationMenu();
break; break;
case 'load_online_user': case 'load_online_user':
$access = accessToWhoIsOnline();
if (!$access) {
exit;
}
$images_to_show = MAX_ONLINE_USERS; $images_to_show = MAX_ONLINE_USERS;
$page = intval($_REQUEST['online_page_nr']); $page = intval($_REQUEST['online_page_nr']);
$max_page = ceil(who_is_online_count() / $images_to_show); $max_page = ceil(who_is_online_count() / $images_to_show);
$page_rows = ($page - 1) * MAX_ONLINE_USERS; $page_rows = ($page - 1) * MAX_ONLINE_USERS;
if (!empty($max_page) && $page <= $max_page) { if (!empty($max_page) && $page <= $max_page) {
if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
$user_list = who_is_online_in_this_course( $user_list = who_is_online_in_this_course(

@ -6,12 +6,17 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo // Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users(); api_block_anonymous_users();
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
/** @var string $tool document or exercise */ /** @var string $tool document or exercise */
$tool = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : ''; $tool = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : '';
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
if ($type == 'document') {
api_protect_course_script();
}
$userId = api_get_user_id(); $userId = api_get_user_id();
if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) { if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
@ -33,18 +38,17 @@ if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) {
} }
$file = isset($_FILES['audio_blob']) ? $_FILES['audio_blob'] : []; $file = isset($_FILES['audio_blob']) ? $_FILES['audio_blob'] : [];
$file['file'] = $file;
$audioDir = Security::remove_XSS($_REQUEST['audio_dir']); $audioDir = Security::remove_XSS($_REQUEST['audio_dir']);
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'; switch ($type) {
$saveDir = $dirBaseDocuments.$audioDir; case 'document':
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
if (!is_dir($saveDir)) { $saveDir = $dirBaseDocuments.$audioDir;
if (!is_dir($saveDir)) {
mkdir($saveDir, api_get_permissions_for_new_directories(), true); mkdir($saveDir, api_get_permissions_for_new_directories(), true);
} }
$uploadedDocument = DocumentManager::upload_document(
$file['file'] = $file;
$uploadedDocument = DocumentManager::upload_document(
$file, $file,
$audioDir, $audioDir,
$file['name'], $file['name'],
@ -53,11 +57,11 @@ $uploadedDocument = DocumentManager::upload_document(
'overwrite', 'overwrite',
false, false,
in_array($tool, ['document', 'exercise']) in_array($tool, ['document', 'exercise'])
); );
$error = empty($uploadedDocument) || !is_array($uploadedDocument); $error = empty($uploadedDocument) || !is_array($uploadedDocument);
if (!$error) { if (!$error) {
$newDocId = $uploadedDocument['id']; $newDocId = $uploadedDocument['id'];
$courseId = $uploadedDocument['c_id']; $courseId = $uploadedDocument['c_id'];
@ -86,4 +90,12 @@ if (!$error) {
} }
echo $data['document_url']; echo $data['document_url'];
}
break;
case 'message':
Session::write('current_audio_id', $file['name']);
api_upload_file('audio_message', $file, api_get_user_id());
break;
} }

@ -6,7 +6,6 @@ use ChamiloSession as Session;
require_once __DIR__.'/../global.inc.php'; require_once __DIR__.'/../global.inc.php';
// Add security from Chamilo // Add security from Chamilo
api_protect_course_script();
api_block_anonymous_users(); api_block_anonymous_users();
$_course = api_get_course_info(); $_course = api_get_course_info();
@ -28,6 +27,12 @@ if (empty($wamiuserid)) {
die(); die();
} }
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message
if ($type === 'document') {
api_protect_course_script();
}
// Clean // Clean
$waminame = Security::remove_XSS($waminame); $waminame = Security::remove_XSS($waminame);
$waminame = Database::escape_string($waminame); $waminame = Database::escape_string($waminame);
@ -47,37 +52,29 @@ if ($ext != 'wav') {
die(); die();
} }
// Do not use here check Fileinfo method because return: text/plain switch ($type) {
case 'document':
$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; // Do not use here check Fileinfo method because return: text/plain
$saveDir = $dirBaseDocuments.$wamidir; $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$saveDir = $dirBaseDocuments.$wamidir;
if (!is_dir($saveDir)) { if (!is_dir($saveDir)) {
DocumentManager::createDefaultAudioFolder($_course); DocumentManager::createDefaultAudioFolder($_course);
} }
//avoid duplicates
$waminame_to_save = $waminame;
//$waminame_noex = basename($waminame, ".wav");
//if (file_exists($saveDir.'/'.$waminame_noex.'.'.$ext)) {
// $i = 1;
// while (file_exists($saveDir.'/'.$waminame_noex.'_'.$i.'.'.$ext)) {
// $i++;
// }
// $waminame_to_save = $waminame_noex.'_'.$i.'.'.$ext;
//}
$documentPath = $saveDir.'/'.$waminame_to_save; // Avoid duplicates
$waminame_to_save = $waminame;
$documentPath = $saveDir.'/'.$waminame_to_save;
// Add to disk // Add to disk
$fh = fopen($documentPath, 'w') or die("can't open file"); $fh = fopen($documentPath, 'w') or die("can't open file");
fwrite($fh, $content); fwrite($fh, $content);
fclose($fh); fclose($fh);
$fileInfo = pathinfo($documentPath); $fileInfo = pathinfo($documentPath);
$courseInfo = api_get_course_info(); $courseInfo = api_get_course_info();
$file = [ $file = [
'file' => [ 'file' => [
'name' => $fileInfo['basename'], 'name' => $fileInfo['basename'],
'tmp_name' => $documentPath, 'tmp_name' => $documentPath,
@ -85,14 +82,14 @@ $file = [
'type' => 'audio/wav', 'type' => 'audio/wav',
'from_file' => true, 'from_file' => true,
], ],
]; ];
$output = true; $output = true;
ob_start(); ob_start();
// Strangely the file path changes with a double extension // Strangely the file path changes with a double extension
copy($documentPath, $documentPath.'.wav'); copy($documentPath, $documentPath.'.wav');
$documentData = DocumentManager::upload_document( $documentData = DocumentManager::upload_document(
$file, $file,
$wamidir, $wamidir,
$fileInfo['basename'], $fileInfo['basename'],
@ -101,10 +98,10 @@ $documentData = DocumentManager::upload_document(
'overwrite', 'overwrite',
false, false,
$output $output
); );
$contents = ob_get_contents(); $contents = ob_get_contents();
if (!empty($documentData)) { if (!empty($documentData)) {
$newDocId = $documentData['id']; $newDocId = $documentData['id'];
$documentData['comment'] = 'mp3'; $documentData['comment'] = 'mp3';
$newMp3DocumentId = DocumentManager::addAndConvertWavToMp3( $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
@ -136,6 +133,23 @@ if (!empty($documentData)) {
// Strangely the file path changes with a double extension // Strangely the file path changes with a double extension
// Remove file with one extension // Remove file with one extension
unlink($documentPath); unlink($documentPath);
} else { } else {
echo $contents; echo $contents;
}
break;
case 'message':
$tempFile = api_get_path(SYS_ARCHIVE_PATH).$waminame;
file_put_contents($tempFile, $content);
Session::write('current_audio_id', $waminame);
$file = [
'name' => basename($tempFile),
'tmp_name' => $tempFile,
'size' => filesize($tempFile),
'type' => 'audio/wav',
'move_file' => true,
];
api_upload_file('audio_message', $file, api_get_user_id());
break;
} }

@ -14,7 +14,7 @@ $action = $_REQUEST['a'];
switch ($action) { switch ($action) {
case 'get_user_sessions': case 'get_user_sessions':
if (api_is_platform_admin() || api_is_session_admin()) { if (api_is_platform_admin() || api_is_session_admin()) {
$user_id = intval($_POST['user_id']); $user_id = (int) $_POST['user_id'];
$list_sessions = SessionManager::get_sessions_by_user($user_id, true); $list_sessions = SessionManager::get_sessions_by_user($user_id, true);
if (!empty($list_sessions)) { if (!empty($list_sessions)) {
foreach ($list_sessions as $session_item) { foreach ($list_sessions as $session_item) {
@ -187,9 +187,7 @@ switch ($action) {
'items' => [], 'items' => [],
]; ];
$entityManager = Database::getManager(); $usersRepo = UserManager::getRepository();
/** @var UserRepository $usersRepo */
$usersRepo = $entityManager->getRepository('ChamiloUserBundle:User');
$users = $usersRepo->searchUsersByStatus($_GET['q'], COURSEMANAGER, api_get_current_access_url_id()); $users = $usersRepo->searchUsersByStatus($_GET['q'], COURSEMANAGER, api_get_current_access_url_id());
/** @var User $user */ /** @var User $user */
foreach ($users as $user) { foreach ($users as $user) {

@ -20,7 +20,7 @@ switch ($action) {
'firstname' => $query, 'firstname' => $query,
'lastname' => $query, 'lastname' => $query,
]; ];
$users = UserManager::get_user_list_like($conditions, [], false, 'OR'); $users = UserManager::getUserListLike($conditions, [], false, 'OR');
$result = []; $result = [];
if (!empty($users)) { if (!empty($users)) {
foreach ($users as $user) { foreach ($users as $user) {

@ -82,7 +82,6 @@ class DatePicker extends HTML_QuickForm_text
public function getTemplate($layout) public function getTemplate($layout)
{ {
$size = $this->getColumnsSize(); $size = $this->getColumnsSize();
$id = $this->getAttribute('id');
$value = $this->getValue(); $value = $this->getValue();
if (empty($size)) { if (empty($size)) {

@ -25,8 +25,9 @@ class HookUpdateUser extends HookEvent implements HookUpdateUserEventInterface
*/ */
public function notifyUpdateUser($type) public function notifyUpdateUser($type)
{ {
/** @var \HookUpdateUserObserverInterface $observer */
$this->eventData['type'] = $type; $this->eventData['type'] = $type;
/** @var HookUpdateUserObserverInterface $observer */
foreach ($this->observers as $observer) { foreach ($this->observers as $observer) {
$observer->hookUpdateUser($this); $observer->hookUpdateUser($this);
} }

@ -674,14 +674,23 @@ class HTML_QuickForm extends HTML_Common
* @access public * @access public
* @throws HTML_QuickForm_Error * @throws HTML_QuickForm_Error
*/ */
public function &addGroup($elements, $name=null, $groupLabel='', $separator=null, $appendName = true) public function &addGroup(
{ $elements,
$name = null,
$groupLabel = '',
$separator = null,
$appendName = true,
$createElement = false
) {
static $anonGroups = 1; static $anonGroups = 1;
if (0 == strlen($name)) { if (0 == strlen($name)) {
$name = 'qf_group_' . $anonGroups++; $name = 'qf_group_'.$anonGroups++;
$appendName = false; $appendName = false;
} }
if ($createElement) {
return $this->createElement('group', $name, $groupLabel, $elements, $separator, $appendName);
}
$group = & $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName); $group = & $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
return $group; return $group;
} }
@ -1431,8 +1440,7 @@ class HTML_QuickForm extends HTML_Common
*/ */
public function validate() public function validate()
{ {
if (count($this->_rules) == 0 && count($this->_formRules) == 0 && if (count($this->_rules) == 0 && count($this->_formRules) == 0 && $this->isSubmitted()) {
$this->isSubmitted()) {
return (0 == count($this->_errors)); return (0 == count($this->_errors));
} elseif (!$this->isSubmitted()) { } elseif (!$this->isSubmitted()) {

@ -14,9 +14,12 @@ class Html_Quickform_Rule_MinText extends HTML_QuickForm_Rule
* @param int $count The minimum number of characters that the text should contain * @param int $count The minimum number of characters that the text should contain
* @return boolean True if text has the minimum number of chars required * @return boolean True if text has the minimum number of chars required
*/ */
function validate($text, $count) public function validate($text, $count)
{ {
$checkMinText = create_function('$a,$b', 'return strlen(utf8_decode($a)) >= $b;'); $checkMinText = function($a, $b) {
return strlen(utf8_decode($a)) >= $b;
};
return $checkMinText($text, $count); return $checkMinText($text, $count);
} }
} }

@ -50,6 +50,8 @@
define('HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT', 1); define('HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT', 1);
/** /**
* @todo clean class to use only with the multiselect.js library
*
* Element for HTML_QuickForm that emulate a multi-select. * Element for HTML_QuickForm that emulate a multi-select.
* *
* The HTML_QuickForm_advmultiselect package adds an element to the * The HTML_QuickForm_advmultiselect package adds an element to the
@ -67,24 +69,6 @@ define('HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT', 1);
*/ */
class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
{ {
/**
* Prefix function name in javascript move selections
*
* @var string
* @access private
* @since 0.4.0
*/
var $_jsPrefix;
/**
* Postfix function name in javascript move selections
*
* @var string
* @access private
* @since 0.4.0
*/
var $_jsPostfix;
/** /**
* Associative array of the multi select container attributes * Associative array of the multi select container attributes
* *
@ -92,7 +76,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_tableAttributes; public $_tableAttributes;
/** /**
* Associative array of the add button attributes * Associative array of the add button attributes
@ -101,7 +85,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_addButtonAttributes; public $_addButtonAttributes;
/** /**
* Associative array of the remove button attributes * Associative array of the remove button attributes
@ -110,7 +94,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_removeButtonAttributes; public $_removeButtonAttributes;
/** /**
* Associative array of the select all button attributes * Associative array of the select all button attributes
@ -119,7 +103,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 1.1.0 * @since 1.1.0
*/ */
var $_allButtonAttributes; public $_allButtonAttributes;
/** /**
* Associative array of the select none button attributes * Associative array of the select none button attributes
@ -128,7 +112,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 1.1.0 * @since 1.1.0
*/ */
var $_noneButtonAttributes; public $_noneButtonAttributes;
/** /**
* Associative array of the toggle selection button attributes * Associative array of the toggle selection button attributes
@ -137,7 +121,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 1.1.0 * @since 1.1.0
*/ */
var $_toggleButtonAttributes; public $_toggleButtonAttributes;
/** /**
* Associative array of the move up button attributes * Associative array of the move up button attributes
@ -146,7 +130,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.5.0 * @since 0.5.0
*/ */
var $_upButtonAttributes; public $_upButtonAttributes;
/** /**
* Associative array of the move up button attributes * Associative array of the move up button attributes
@ -155,7 +139,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.5.0 * @since 0.5.0
*/ */
var $_downButtonAttributes; public $_downButtonAttributes;
/** /**
* Associative array of the move top button attributes * Associative array of the move top button attributes
@ -164,7 +148,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 1.5.0 * @since 1.5.0
*/ */
var $_topButtonAttributes; public $_topButtonAttributes;
/** /**
* Associative array of the move bottom button attributes * Associative array of the move bottom button attributes
@ -173,7 +157,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 1.5.0 * @since 1.5.0
*/ */
var $_bottomButtonAttributes; public $_bottomButtonAttributes;
/** /**
* Defines if both list (unselected, selected) will have their elements be * Defines if both list (unselected, selected) will have their elements be
@ -187,7 +171,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.5.0 * @since 0.5.0
*/ */
var $_sort; public $_sort;
/** /**
* Associative array of the unselected item box attributes * Associative array of the unselected item box attributes
@ -196,7 +180,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_attributesUnselected; public $_attributesUnselected;
/** /**
* Associative array of the selected item box attributes * Associative array of the selected item box attributes
@ -205,7 +189,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_attributesSelected; public $_attributesSelected;
/** /**
* Associative array of the internal hidden box attributes * Associative array of the internal hidden box attributes
@ -214,8 +198,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_attributesHidden; public $_attributesHidden;
public $selectAllCheckBox = false; public $selectAllCheckBox = false;
/** /**
@ -225,7 +208,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_elementTemplate; public $_elementTemplate;
/** /**
* Default Element stylesheet string * Default Element stylesheet string
@ -234,15 +217,11 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @access private * @access private
* @since 0.4.0 * @since 0.4.0
*/ */
var $_elementCSS = ''; public $_elementCSS = '';
/** /**
* Class constructor * Class constructor
* *
* Class constructors :
* Zend Engine 1 uses HTML_QuickForm_advmultiselect, while
* Zend Engine 2 uses __construct
*
* @param string $elementName Dual Select name attribute * @param string $elementName Dual Select name attribute
* @param mixed $elementLabel Label(s) for the select boxes * @param mixed $elementLabel Label(s) for the select boxes
* @param mixed $options Data to be used to populate options * @param mixed $options Data to be used to populate options
@ -267,7 +246,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$options = null; // prevent to use the default select element load options $options = null; // prevent to use the default select element load options
parent::__construct($elementName, $elementLabel, $options, $attributes); parent::__construct($elementName, $elementLabel, $options, $attributes);
$this->selectAllCheckBox = isset($attributes['select_all_checkbox']) ? $attributes['select_all_checkbox'] : false; $this->selectAllCheckBox = isset($attributes['select_all_checkbox']) ? $attributes['select_all_checkbox'] : false;
// allow to load options at once and take care of fancy attributes // allow to load options at once and take care of fancy attributes
@ -284,16 +262,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
// default width of each select box // default width of each select box
$this->updateAttributes(array('class' => 'form-control')); $this->updateAttributes(array('class' => 'form-control'));
} }
/* $this->_tableAttributes = $this->getAttribute('class');
$attr = null;
if (is_null($this->_tableAttributes)) {
$this->updateAttributes(array('class' => 'col-md-4'));
} else {
$attr = array('class' => $this->_tableAttributes);
$this->_removeAttr('class', $this->_attributes);
}*/
//$this->_tableAttributes = $this->_getAttrString($attr);
$this->removeAttribute('class'); $this->removeAttribute('class');
$this->setAttribute('class','form-control'); $this->setAttribute('class','form-control');
@ -315,9 +284,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$this->setButtonAttributes('movetop'); $this->setButtonAttributes('movetop');
// set default move bottom button attributes // set default move bottom button attributes
$this->setButtonAttributes('movebottom'); $this->setButtonAttributes('movebottom');
// defines javascript functions names
$this->_jsPrefix = 'QFAMS.';
$this->_jsPostfix = 'moveSelection';
// set select boxes sort order (none by default) // set select boxes sort order (none by default)
if (!isset($sort)) { if (!isset($sort)) {
@ -381,7 +347,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom1.png * @link http://www.laurent-laville.org/img/qfams/screenshot/custom1.png
* Custom example 1: screenshot * Custom example 1: screenshot
*/ */
function setButtonAttributes($button, $attributes = null) public function setButtonAttributes($button, $attributes = null)
{ {
if (!is_string($button)) { if (!is_string($button)) {
return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' .
@ -509,13 +475,13 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* Sets element template * Sets element template
* *
* @param string $html (optional) The HTML surrounding select boxes and buttons * @param string $html (optional) The HTML surrounding select boxes and buttons
* @param string $js (optional) if we need to include qfams javascript handler * @param bool $js (optional) if we need to include qfams javascript handler
* *
* @access public * @access public
* @return string * @return string
* @since version 0.4.0 (2005-06-25) * @since version 0.4.0 (2005-06-25)
*/ */
function setElementTemplate($html = null, $js = true) public function setElementTemplate($html = null, $js = true)
{ {
$oldTemplate = $this->_elementTemplate; $oldTemplate = $this->_elementTemplate;
@ -531,7 +497,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
</div> </div>
'; ';
} }
if ($js == false) { if ($js === false) {
$this->_elementTemplate = str_replace('{javascript}', '', $this->_elementTemplate = str_replace('{javascript}', '',
$this->_elementTemplate); $this->_elementTemplate);
} }
@ -558,7 +524,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom4.png * @link http://www.laurent-laville.org/img/qfams/screenshot/custom4.png
* Custom example 4: screenshot * Custom example 4: screenshot
*/ */
function getElementCss($raw = true) public function getElementCss($raw = true)
{ {
$id = $this->getAttribute('name'); $id = $this->getAttribute('name');
$css = str_replace('{id}', $id, $this->_elementCSS); $css = str_replace('{id}', $id, $this->_elementCSS);
@ -588,16 +554,16 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$tab = $this->_getTab(); $tab = $this->_getTab();
$selectId = $this->getName(); $selectId = $this->getName();
$selectName = $this->getName() . '[]'; $selectName = $this->getName().'[]';
$selectNameFrom = $this->getName() . '-f[]'; $selectNameFrom = $this->getName().'-f[]';
$selectNameTo = $this->getName() . '-t[]'; $selectNameTo = $this->getName().'[]';
$selected_count = 0; $selected_count = 0;
$rightAll = '';
$leftAll = '';
// placeholder {unselected} existence determines if we will render // placeholder {unselected} existence determines if we will render
if (strpos($this->_elementTemplate, '{unselected}') === false) { if (strpos($this->_elementTemplate, '{unselected}') === false) {
// ... a single multi-select with checkboxes // ... a single multi-select with checkboxes
$this->_jsPostfix = 'editSelection';
$id = $this->getAttribute('name'); $id = $this->getAttribute('name');
$strHtmlSelected = $tab . '<div id="qfams_'.$id.'">' . PHP_EOL; $strHtmlSelected = $tab . '<div id="qfams_'.$id.'">' . PHP_EOL;
@ -615,8 +581,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
} }
} }
if (is_array($this->_values) if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) {
&& in_array((string)$option['attr']['value'], $this->_values)) {
// The items is *selected* // The items is *selected*
$checked = ' checked="checked"'; $checked = ' checked="checked"';
$selected_count++; $selected_count++;
@ -626,15 +591,14 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
} }
$checkbox_id_suffix++; $checkbox_id_suffix++;
$strHtmlSelected .= $tab $strHtmlSelected .= $tab
. '<label' .'<label'
. $this->_getAttrString($labelAttributes) .'>' .$this->_getAttrString($labelAttributes).'>'
. '<input type="checkbox"' .'<input type="checkbox"'
. ' id="'.$selectId . $checkbox_id_suffix.'"' .' id="'.$selectId.$checkbox_id_suffix.'"'
. ' name="'.$selectName.'"' .' name="'.$selectName.'"'
. $checked .$checked.$this->_getAttrString($option['attr'])
. $this->_getAttrString($option['attr']) .' />'.$option['text'].'</label>'
. ' />' . $option['text'] . '</label>' .PHP_EOL;
. PHP_EOL;
} }
$strHtmlSelected .= $tab . '</div>'. PHP_EOL; $strHtmlSelected .= $tab . '</div>'. PHP_EOL;
@ -644,22 +608,20 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$strHtmlRemove = ''; $strHtmlRemove = '';
// build the select all button with all its attributes // build the select all button with all its attributes
$jsName = $this->_jsPrefix . $this->_jsPostfix; $attributes = [];
$attributes = array('onclick' => $jsName ."('". $selectId ."', 1);");
$this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes); $this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes);
$attrStrAll = $this->_getAttrString($this->_allButtonAttributes); $attrStrAll = $this->_getAttrString($this->_allButtonAttributes);
$strHtmlAll = "<input$attrStrAll />". PHP_EOL; $strHtmlAll = "<input$attrStrAll />". PHP_EOL;
// build the select none button with all its attributes // build the select none button with all its attributes
$attributes = array('onclick' => $jsName ."('". $selectId ."', 0);"); $attributes = [];
$this->_noneButtonAttributes $this->_noneButtonAttributes
= array_merge($this->_noneButtonAttributes, $attributes); = array_merge($this->_noneButtonAttributes, $attributes);
$attrStrNone = $this->_getAttrString($this->_noneButtonAttributes); $attrStrNone = $this->_getAttrString($this->_noneButtonAttributes);
$strHtmlNone = "<input$attrStrNone />". PHP_EOL; $strHtmlNone = "<input$attrStrNone />". PHP_EOL;
// build the toggle selection button with all its attributes // build the toggle selection button with all its attributes
$attributes = array('onclick' => $jsName . $attributes = [];
"('". $selectId ."', 2);");
$this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes); $this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes);
$attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes); $attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes);
$strHtmlToggle = "<input$attrStrToggle />". PHP_EOL; $strHtmlToggle = "<input$attrStrToggle />". PHP_EOL;
@ -672,43 +634,32 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
// default selection counters // default selection counters
$strHtmlSelectedCount = $selected_count . '/' . $unselected_count; $strHtmlSelectedCount = $selected_count . '/' . $unselected_count;
} else { } else {
// ... or a dual multi-select
$this->_jsPostfix = 'moveSelection';
$jsName = $this->_jsPrefix . $this->_jsPostfix;
// set name of Select From Box // set name of Select From Box
$this->_attributesUnselected $this->_attributesUnselected
= array('id' => $selectId . '-f', = array(
'id' => $selectId.'',
'name' => $selectNameFrom, 'name' => $selectNameFrom,
'ondblclick' => $jsName . );
"('{$selectId}', ".
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "'], " .
"'add', '{$this->_sort}')");
$this->_attributesUnselected $this->_attributesUnselected
= array_merge($this->_attributes, $this->_attributesUnselected); = array_merge($this->_attributes, $this->_attributesUnselected);
$attrUnselected = $this->_getAttrString($this->_attributesUnselected); $attrUnselected = $this->_getAttrString($this->_attributesUnselected);
// set name of Select To Box // set name of Select To Box
$this->_attributesSelected $this->_attributesSelected
= array('id' => $selectId . '-t', = array(
'id' => $selectId.'_to',
'name' => $selectNameTo, 'name' => $selectNameTo,
'ondblclick' => $jsName . );
"('{$selectId}', " .
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], ".
"this.form.elements['" . $selectName . "'], " .
"'remove', '{$this->_sort}')");
$this->_attributesSelected $this->_attributesSelected
= array_merge($this->_attributes, $this->_attributesSelected); = array_merge($this->_attributes, $this->_attributesSelected);
$attrSelected = $this->_getAttrString($this->_attributesSelected); $attrSelected = $this->_getAttrString($this->_attributesSelected);
// set name of Select hidden Box // set name of Select hidden Box
$this->_attributesHidden $this->_attributesHidden
= array('name' => $selectName, = array(
'style' => 'overflow: hidden; visibility: hidden; ' . 'name' => $selectName,
'width: 1px; height: 0;'); 'style' => 'overflow: hidden; visibility: hidden; width: 1px; height: 0;',
);
$this->_attributesHidden $this->_attributesHidden
= array_merge($this->_attributes, $this->_attributesHidden); = array_merge($this->_attributes, $this->_attributesHidden);
$attrHidden = $this->_getAttrString($this->_attributesHidden); $attrHidden = $this->_getAttrString($this->_attributesHidden);
@ -725,14 +676,13 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$arrHtmlUnselected = array(); $arrHtmlUnselected = array();
if ($options > 0) { if ($options > 0) {
$arrHtmlHidden = array_fill(0, $options, ' '); $arrHtmlHidden = array_fill(0, $options, ' ');
foreach ($this->_options as $option) { foreach ($this->_options as $option) {
if (is_array($this->_values) if (is_array($this->_values) && in_array((string) $option['attr']['value'], $this->_values)) {
&& in_array((string)$option['attr']['value'],
$this->_values)) {
// Get the post order // Get the post order
$key = array_search($option['attr']['value'], $key = array_search(
$this->_values); $option['attr']['value'],
$this->_values
);
/** The items is *selected* so we want to put it /** The items is *selected* so we want to put it
in the 'selected' multi-select */ in the 'selected' multi-select */
@ -753,40 +703,29 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$append++; $append++;
} }
} }
} else {
$arrHtmlHidden = array();
} }
// The 'unselected' multi-select which appears on the left // The 'unselected' multi-select which appears on the left
$unselected_count = count($arrHtmlUnselected); $unselected_count = count($arrHtmlUnselected);
if ($unselected_count == 0) { if ($unselected_count == 0) {
$this->_attributesUnselected['disabled'] = 'disabled'; $this->_attributesUnselected = array_merge($this->_attributes, $this->_attributesUnselected);
$this->_attributesUnselected
= array_merge($this->_attributes, $this->_attributesUnselected);
$attrUnselected = $this->_getAttrString($this->_attributesUnselected); $attrUnselected = $this->_getAttrString($this->_attributesUnselected);
} }
$strHtmlUnselected = "<select$attrUnselected>". PHP_EOL; $strHtmlUnselected = "<select$attrUnselected>". PHP_EOL;
if ($unselected_count > 0) { if ($unselected_count > 0) {
foreach ($arrHtmlUnselected as $data) { foreach ($arrHtmlUnselected as $data) {
$strHtmlUnselected $strHtmlUnselected
.= $tabs . $tab .= $tabs.$tab
. '<option' . $this->_getAttrString($data['attr']) . '>' .'<option'.$this->_getAttrString($data['attr']).'>'
. $data['text'] . '</option>' . PHP_EOL; .$data['text'].'</option>'.PHP_EOL;
} }
} else {
$strHtmlUnselected .= '<option value="">&nbsp;</option>';
} }
$strHtmlUnselected .= '</select>'; $strHtmlUnselected .= '</select>';
$strHtmlUnselected = '<input placeholder="'.get_lang('Search').'" id="'.$selectId.'-f-filter" type="text" class="form-control search-query select_class_filter"><br />'.$strHtmlUnselected;
// The 'selected' multi-select which appears on the right // The 'selected' multi-select which appears on the right
$selected_count = count($arrHtmlSelected); $selected_count = count($arrHtmlSelected);
if ($selected_count == 0) { if ($selected_count == 0) {
$this->_attributesSelected['disabled'] = 'disabled'; $this->_attributesSelected = array_merge($this->_attributes, $this->_attributesSelected);
$this->_attributesSelected
= array_merge($this->_attributes, $this->_attributesSelected);
$attrSelected = $this->_getAttrString($this->_attributesSelected); $attrSelected = $this->_getAttrString($this->_attributesSelected);
} }
$strHtmlSelected = "<select$attrSelected>"; $strHtmlSelected = "<select$attrSelected>";
@ -802,139 +741,77 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$text = $data['text']; $text = $data['text'];
} }
$strHtmlSelected $strHtmlSelected
.= $tabs . $tab .= $tabs.$tab
. '<option' . $attribute. '>' .'<option'.$attribute.'>'
. $text . '</option>'; .$text.'</option>';
} }
} else {
$strHtmlSelected .= '<option value="">&nbsp;</option>';
} }
$strHtmlSelected .= '</select>'; $strHtmlSelected .= '</select>';
$strHtmlHidden = '';
$strHtmlSelected = '<input placeholder="'.get_lang('Search').'" id="'.$selectId.'-t-filter" type="text" class="form-control search-query select_class_filter"><br />'.$strHtmlSelected; $attributes = array('id' => $selectId.'_leftSelected');
// The 'hidden' multi-select
$strHtmlHidden = "<select$attrHidden>". PHP_EOL;
if (count($arrHtmlHidden) > 0) {
foreach ($arrHtmlHidden as $data) {
$attribute = null;
if (isset($data['attr'])) {
$attribute = $this->_getAttrString($data['attr']);
}
$text = null;
if (isset($data['text'])) {
$text = $data['text'];
}
$strHtmlHidden
.= $tabs . $tab
. '<option' . $attribute . '>'
. $text . '</option>' . PHP_EOL;
}
}
$strHtmlHidden .= '</select>';
// build the remove button with all its attributes
$attributes
= array('onclick' => $jsName .
"('{$selectId}', " .
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "'], " .
"'remove', '{$this->_sort}'); return false;");
$this->_removeButtonAttributes $this->_removeButtonAttributes
= array_merge($this->_removeButtonAttributes, $attributes); = array_merge($this->_removeButtonAttributes, $attributes);
$attrStrRemove = $this->_getAttrString($this->_removeButtonAttributes); $attrStrRemove = $this->_getAttrString($this->_removeButtonAttributes);
$strHtmlRemove = "<button $attrStrRemove /> <em class='fa fa-arrow-left'></em></button>"; $strHtmlRemove = "<button $attrStrRemove /> <em class='fa fa-arrow-left'></em></button>";
// build the add button with all its attributes // build the add button with all its attributes
$attributes $attributes = array('id' => $selectId.'_rightSelected');
= array('onclick' => $jsName .
"('{$selectId}', " .
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "'], " .
"'add', '{$this->_sort}'); return false;");
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); $this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes);
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); $attrStrAdd = $this->_getAttrString($this->_addButtonAttributes);
$strHtmlAdd = "<button $attrStrAdd /> <em class='fa fa-arrow-right'></em></button><br /><br />"; $strHtmlAdd = "<button $attrStrAdd /> <em class='fa fa-arrow-right'></em></button><br /><br />";
if ($this->selectAllCheckBox) {
$attributes = array('id' => $selectId.'_rightAll');
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes);
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes);
$rightAll = "<button $attrStrAdd /> <em class='fa fa-forward'></em></button><br /><br />";
$attributes = array('id' => $selectId.'_leftAll');
$this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes);
$attrStrAdd = $this->_getAttrString($this->_addButtonAttributes);
$leftAll = "<br /><br /><button $attrStrAdd /> <em class='fa fa-backward'></em></button>";
}
// build the select all button with all its attributes // build the select all button with all its attributes
$attributes $strHtmlAll = '';
= array('onclick' => $jsName .
"('{$selectId}', " .
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "'], " .
"'all', '{$this->_sort}'); return false;");
$this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes);
$attrStrAll = $this->_getAttrString($this->_allButtonAttributes);
$strHtmlAll = "<input$attrStrAll />". PHP_EOL;
// build the select none button with all its attributes // build the select none button with all its attributes
$attributes $attributes = [];
= array('onclick' => $jsName .
"('{$selectId}', " .
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "'], " .
"'none', '{$this->_sort}'); return false;");
$this->_noneButtonAttributes $this->_noneButtonAttributes
= array_merge($this->_noneButtonAttributes, $attributes); = array_merge($this->_noneButtonAttributes, $attributes);
$attrStrNone = $this->_getAttrString($this->_noneButtonAttributes); $attrStrNone = $this->_getAttrString($this->_noneButtonAttributes);
$strHtmlNone = "<input$attrStrNone />". PHP_EOL; $strHtmlNone = "<input$attrStrNone />". PHP_EOL;
// build the toggle button with all its attributes // build the toggle button with all its attributes
$attributes $attributes = [];
= array('onclick' => $jsName .
"('{$selectId}', " .
"this.form.elements['" . $selectNameFrom . "'], " .
"this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "'], " .
"'toggle', '{$this->_sort}'); return false;");
$this->_toggleButtonAttributes $this->_toggleButtonAttributes
= array_merge($this->_toggleButtonAttributes, $attributes); = array_merge($this->_toggleButtonAttributes, $attributes);
$attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes); $attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes);
$strHtmlToggle = "<input$attrStrToggle />". PHP_EOL; $strHtmlToggle = "<input$attrStrToggle />". PHP_EOL;
// build the move up button with all its attributes // build the move up button with all its attributes
$attributes $attributes = [];
= array('onclick' => "{$this->_jsPrefix}moveUp" .
"(this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "']); " .
"return false;");
$this->_upButtonAttributes $this->_upButtonAttributes
= array_merge($this->_upButtonAttributes, $attributes); = array_merge($this->_upButtonAttributes, $attributes);
$attrStrUp = $this->_getAttrString($this->_upButtonAttributes); $attrStrUp = $this->_getAttrString($this->_upButtonAttributes);
$strHtmlMoveUp = "<input$attrStrUp />". PHP_EOL; $strHtmlMoveUp = "<input$attrStrUp />". PHP_EOL;
// build the move down button with all its attributes // build the move down button with all its attributes
$attributes $attributes = [];
= array('onclick' => "{$this->_jsPrefix}moveDown" .
"(this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "']); " .
"return false;");
$this->_downButtonAttributes $this->_downButtonAttributes
= array_merge($this->_downButtonAttributes, $attributes); = array_merge($this->_downButtonAttributes, $attributes);
$attrStrDown = $this->_getAttrString($this->_downButtonAttributes); $attrStrDown = $this->_getAttrString($this->_downButtonAttributes);
$strHtmlMoveDown = "<input$attrStrDown />". PHP_EOL; $strHtmlMoveDown = "<input$attrStrDown />". PHP_EOL;
// build the move top button with all its attributes // build the move top button with all its attributes
$attributes $attributes = [];
= array('onclick' => "{$this->_jsPrefix}moveTop" .
"(this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "']); " .
"return false;");
$this->_topButtonAttributes $this->_topButtonAttributes
= array_merge($this->_topButtonAttributes, $attributes); = array_merge($this->_topButtonAttributes, $attributes);
$attrStrTop = $this->_getAttrString($this->_topButtonAttributes); $attrStrTop = $this->_getAttrString($this->_topButtonAttributes);
$strHtmlMoveTop = "<input$attrStrTop />". PHP_EOL; $strHtmlMoveTop = "<input$attrStrTop />". PHP_EOL;
// build the move bottom button with all its attributes // build the move bottom button with all its attributes
$attributes $attributes = [];
= array('onclick' => "{$this->_jsPrefix}moveBottom" .
"(this.form.elements['" . $selectNameTo . "'], " .
"this.form.elements['" . $selectName . "']); " .
"return false;");
$this->_bottomButtonAttributes $this->_bottomButtonAttributes
= array_merge($this->_bottomButtonAttributes, $attributes); = array_merge($this->_bottomButtonAttributes, $attributes);
$attrStrBottom = $this->_getAttrString($this->_bottomButtonAttributes); $attrStrBottom = $this->_getAttrString($this->_bottomButtonAttributes);
@ -944,7 +821,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$strHtmlSelectedCount = $selected_count; $strHtmlSelectedCount = $selected_count;
} }
$strHtmlUnselectedCount = $unselected_count; $strHtmlUnselectedCount = $unselected_count;
$strHtmlSelectedCountId = $selectId .'_selected'; $strHtmlSelectedCountId = $selectId .'_selected';
$strHtmlUnselectedCountId = $selectId .'_unselected'; $strHtmlUnselectedCountId = $selectId .'_unselected';
@ -959,7 +835,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
// render extra labels, if any // render extra labels, if any
if (is_array($labels)) { if (is_array($labels)) {
foreach ($labels as $key => $text) { foreach ($labels as $key => $text) {
$key = is_int($key)? $key + 2: $key; $key = is_int($key) ? $key + 2 : $key;
$strHtml = str_replace("{label_{$key}}", $text, $strHtml); $strHtml = str_replace("{label_{$key}}", $text, $strHtml);
$strHtml = str_replace("<!-- BEGIN label_{$key} -->", '', $strHtml); $strHtml = str_replace("<!-- BEGIN label_{$key} -->", '', $strHtml);
$strHtml = str_replace("<!-- END label_{$key} -->", '', $strHtml); $strHtml = str_replace("<!-- END label_{$key} -->", '', $strHtml);
@ -1003,8 +879,8 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$strHtmlSelectedCount, $strHtmlSelectedCount,
$strHtmlUnselected, $strHtmlUnselected,
$strHtmlSelected.$strHtmlHidden, $strHtmlSelected.$strHtmlHidden,
$strHtmlAdd, $rightAll.$strHtmlAdd,
$strHtmlRemove, $strHtmlRemove.$leftAll,
$strHtmlAll, $strHtmlAll,
$strHtmlNone, $strHtmlNone,
$strHtmlToggle, $strHtmlToggle,
@ -1014,14 +890,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$strHtmlMoveBottom, $strHtmlMoveBottom,
); );
if ($this->selectAllCheckBox) {
$strHtml .= '<div class="col-sm-8">
<label >'.get_lang('SelectAll').'
<input type="checkbox" class="advmultiselect_checkbox" id="'.$selectId.'_select_all'.'">
</label>
</div>';
}
$strHtml = str_replace($placeHolders, $htmlElements, $strHtml); $strHtml = str_replace($placeHolders, $htmlElements, $strHtml);
$comment = $this->getComment(); $comment = $this->getComment();
@ -1029,7 +897,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
$strHtml = $tabs . '<!-- ' . $comment . " //-->" . PHP_EOL . $strHtml; $strHtml = $tabs . '<!-- ' . $comment . " //-->" . PHP_EOL . $strHtml;
} }
return $strHtml; return $strHtml;
} }
@ -1043,20 +910,26 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @return string * @return string
* @since version 0.4.0 (2005-06-25) * @since version 0.4.0 (2005-06-25)
*/ */
function getElementJs($raw = true, $min = true) public function getElementJs($raw = true, $min = true)
{ {
$js = api_get_path(LIBRARY_PATH).'javascript'.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR; $name = $this->getName();
$js .= 'qfamsHandler.js'; $js = api_get_asset('multiselect-two-sides/dist/js/multiselect.js');
$search =
if (file_exists($js)) { '<input type="text" name="q" class="form-control" placeholder="'.addslashes(get_lang('Search')).'" /><br />';
$js = file_get_contents($js);
} else { $js .= '<script>
$js = ''; $(document).ready(function() {
} $(\'#'.$name.'\').multiselect({
search: {
if ($raw !== true) { left: \''.$search.'\',
$js = '<script>'.PHP_EOL.$js.PHP_EOL.'</script>'.PHP_EOL; right: \''.$search.'\'
} },
fireSearch: function(value) {
return value.length > 2;
}
});
});
</script>'.PHP_EOL;
return $js; return $js;
} }
@ -1079,7 +952,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @throws PEAR_Error * @throws PEAR_Error
* @see loadArray() * @see loadArray()
*/ */
function load(&$options, public function load(&$options,
$param1 = null, $param2 = null, $param3 = null, $param4 = null) $param1 = null, $param2 = null, $param3 = null, $param4 = null)
{ {
if (is_array($options)) { if (is_array($options)) {
@ -1105,7 +978,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
* @throws PEAR_Error * @throws PEAR_Error
* @see load() * @see load()
*/ */
function loadArray($arr, $values = null) public function loadArray($arr, $values = null)
{ {
if (!is_array($arr)) { if (!is_array($arr)) {
return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' .
@ -1127,71 +1000,4 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select
} }
return true; return true;
} }
/**
* Sets which items should be persistant
*
* Sets which items should have the disabled attribute
* to keep it persistant
*
* @param mixed $optionValues Options (key-values) that should be persistant
* @param bool $persistant (optional) TRUE if persistant, FALSE otherwise
*
* @since version 1.5.0 (2009-02-15)
* @access public
* @return PEAR_Error on error and TRUE on success
* @throws PEAR_Error
*/
function setPersistantOptions($optionValues, $persistant = true)
{
if (!is_bool($persistant)) {
return PEAR::throwError('Argument 2 of HTML_QuickForm_advmultiselect::' .
'setPersistantOptions is not a boolean',
HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT,
array('level' => 'exception'));
}
if (is_string($optionValues)) {
$optionValues = array($optionValues);
}
if (!is_array($optionValues)) {
return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' .
'setPersistantOptions is not a valid array',
HTML_QUICKFORM_ADVMULTISELECT_ERROR_INVALID_INPUT,
array('level' => 'exception'));
}
foreach ($this->_options as $k => $v) {
if (in_array($v['attr']['value'], $optionValues)) {
if ($persistant) {
$this->_options[$k]['attr']['disabled'] = 'disabled';
} else {
unset($this->_options[$k]['attr']['disabled']);
}
}
}
return true;
}
/**
* Returns list of persistant options
*
* Returns list of persistant options (key-values) that could not
* be selected or unselected.
*
* @since version 1.5.0 (2009-02-15)
* @access public
* @return array
*/
function getPersistantOptions()
{
$options = array();
foreach ($this->_options as $k => $v) {
if (isset($v['attr']['disabled'])) {
$options[] = $this->_options[$k]['attr']['value'];
}
}
return $options;
}
} }

@ -136,6 +136,10 @@ class HTML_QuickForm_button extends HTML_QuickForm_input
*/ */
public function setIcon($icon) public function setIcon($icon)
{ {
// Try and sanitize $icon in case it's an array (take the first element and consider it's a string)
if (is_array($icon)) {
$icon = @strval($icon[0]);
}
$this->icon = !empty($icon) ? 'fa fa-'.$icon : null; $this->icon = !empty($icon) ? 'fa fa-'.$icon : null;
} }

@ -140,13 +140,11 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input
} elseif ($this->_flagFrozen) { } elseif ($this->_flagFrozen) {
$label = $this->_text; $label = $this->_text;
} else { } else {
$labelClass = $this->labelClass; $className = $this->checkboxClass;
$checkboxClass = $this->checkboxClass; $name = $this->_attributes['name'];
$label ='<div id="'.$name.'" class="'.$className.'_'.$name.'">
$label =' <label>' .
<div class="'.$checkboxClass.'"> HTML_QuickForm_input::toHtml().' '.$this->_text.
<label class="'.$labelClass.'">' .
HTML_QuickForm_input::toHtml().$this->_text.
'</label> '</label>
</div> </div>
'; ';

@ -83,6 +83,11 @@ class HTML_QuickForm_select extends HTML_QuickForm_element
$attributes['class'] = $oldClass . ' selectpicker show-tick form-control'; $attributes['class'] = $oldClass . ' selectpicker show-tick form-control';
$attributes['data-live-search'] = 'true'; $attributes['data-live-search'] = 'true';
if (isset($attributes['disable_js']) && $attributes['disable_js']) {
$attributes['class'] = 'form-control';
$attributes['data-live-search'] = '';
}
if (isset($attributes['placeholder'])) { if (isset($attributes['placeholder'])) {
$addBlank = $attributes['placeholder']; $addBlank = $attributes['placeholder'];
} }

@ -220,7 +220,7 @@ class Rest extends WebService
'title' => $course->getTitle(), 'title' => $course->getTitle(),
'code' => $course->getCode(), 'code' => $course->getCode(),
'directory' => $course->getDirectory(), 'directory' => $course->getDirectory(),
'urlPicture' => $course->getPicturePath(true), 'urlPicture' => CourseManager::getPicturePath($course, true),
'teachers' => $teachers, 'teachers' => $teachers,
]; ];
} }
@ -247,7 +247,7 @@ class Rest extends WebService
'title' => $this->course->getTitle(), 'title' => $this->course->getTitle(),
'code' => $this->course->getCode(), 'code' => $this->course->getCode(),
'directory' => $this->course->getDirectory(), 'directory' => $this->course->getDirectory(),
'urlPicture' => $this->course->getPicturePath(true), 'urlPicture' => CourseManager::getPicturePath($this->course, true),
'teachers' => $teachers, 'teachers' => $teachers,
'tools' => array_map( 'tools' => array_map(
function ($tool) { function ($tool) {
@ -798,7 +798,6 @@ class Rest extends WebService
'course' => $this->course->getId(), 'course' => $this->course->getId(),
'session' => $sessionId, 'session' => $sessionId,
]), ]),
]),
]; ];
} }
@ -955,8 +954,7 @@ class Rest extends WebService
*/ */
public function getMessageUsers($search) public function getMessageUsers($search)
{ {
/** @var UserRepository $repo */ $repo = UserManager::getRepository();
$repo = Database::getManager()->getRepository('ChamiloUserBundle:User');
$users = $repo->findUsersToSendMessage($this->user->getId(), $search); $users = $repo->findUsersToSendMessage($this->user->getId(), $search);
@ -1160,8 +1158,6 @@ class Rest extends WebService
$results = []; $results = [];
$orig_user_id_value = []; $orig_user_id_value = [];
$userManager = UserManager::getManager(); $userManager = UserManager::getManager();
$userRepository = UserManager::getRepository();
$firstName = $user_param['firstname']; $firstName = $user_param['firstname'];
$lastName = $user_param['lastname']; $lastName = $user_param['lastname'];
$status = $user_param['status']; $status = $user_param['status'];

Loading…
Cancel
Save