From ff23224e880bbfdd9b129a97af0005002050af16 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 7 Aug 2018 14:50:55 +0200 Subject: [PATCH] Minor - partial merge from 1.11.x --- main/inc/ajax/agenda.ajax.php | 2 +- main/inc/ajax/chat.ajax.php | 2 +- main/inc/ajax/course.ajax.php | 54 ++- main/inc/ajax/course_chat.ajax.php | 10 +- main/inc/ajax/course_home.ajax.php | 24 +- main/inc/ajax/exercise.ajax.php | 148 +++--- main/inc/ajax/message.ajax.php | 4 +- main/inc/ajax/model.ajax.php | 130 ++++-- main/inc/ajax/online.ajax.php | 6 +- main/inc/ajax/record_audio_rtc.ajax.php | 116 ++--- main/inc/ajax/record_audio_wami.ajax.php | 190 ++++---- main/inc/ajax/session.ajax.php | 6 +- main/inc/ajax/user_manager.ajax.php | 2 +- .../lib/formvalidator/Element/DatePicker.php | 1 - main/inc/lib/hook/HookUpdateUser.php | 3 +- main/inc/lib/pear/HTML/QuickForm.php | 18 +- .../lib/pear/HTML/QuickForm/Rule/MinText.php | 7 +- .../pear/HTML/QuickForm/advmultiselect.php | 430 +++++------------- main/inc/lib/pear/HTML/QuickForm/button.php | 4 + main/inc/lib/pear/HTML/QuickForm/checkbox.php | 12 +- main/inc/lib/pear/HTML/QuickForm/select.php | 5 + main/inc/lib/webservices/Rest.php | 58 ++- 22 files changed, 599 insertions(+), 633 deletions(-) diff --git a/main/inc/ajax/agenda.ajax.php b/main/inc/ajax/agenda.ajax.php index fc2a274c7c..390623f605 100755 --- a/main/inc/ajax/agenda.ajax.php +++ b/main/inc/ajax/agenda.ajax.php @@ -120,7 +120,7 @@ switch ($action) { $DaysShort = api_get_week_days_short(); $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); if (!is_array($my_course_list)) { // this is for the special case if the user has no courses (otherwise you get an error) diff --git a/main/inc/ajax/chat.ajax.php b/main/inc/ajax/chat.ajax.php index 56a003ea51..028348446f 100755 --- a/main/inc/ajax/chat.ajax.php +++ b/main/inc/ajax/chat.ajax.php @@ -71,7 +71,7 @@ switch ($action) { exit; break; case 'set_status': - $status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0; + $status = isset($_REQUEST['status']) ? (int) $_REQUEST['status'] : 0; $chat->setUserStatus($status); break; case 'create_room': diff --git a/main/inc/ajax/course.ajax.php b/main/inc/ajax/course.ajax.php index ab7d385625..b753de48c6 100755 --- a/main/inc/ajax/course.ajax.php +++ b/main/inc/ajax/course.ajax.php @@ -13,8 +13,8 @@ $user_id = api_get_user_id(); switch ($action) { case 'add_course_vote': - $course_id = intval($_REQUEST['course_id']); - $star = intval($_REQUEST['star']); + $course_id = (int) $_REQUEST['course_id']; + $star = (int) $_REQUEST['star']; if (!api_is_anonymous()) { CourseManager::add_course_vote($user_id, $star, $course_id, 0); @@ -40,7 +40,7 @@ switch ($action) { case 'get_user_courses': // Only search my courses 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( $userId, false @@ -125,8 +125,8 @@ switch ($action) { } break; case 'search_course': - if (api_is_teacher()) { - if (!empty($_GET['session_id']) && intval($_GET['session_id'])) { + if (api_is_teacher() || api_is_platform_admin()) { + if (isset($_GET['session_id']) && !empty($_GET['session_id'])) { //if session is defined, lets find only courses of this session $courseList = SessionManager::get_course_list_by_session_id( $_GET['session_id'], @@ -231,27 +231,41 @@ switch ($action) { if (api_is_platform_admin()) { $user = Database::get_main_table(TABLE_MAIN_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']); $json = [ 'items' => [], ]; - $sql = "SELECT u.user_id as id, u.username, u.lastname, u.firstname - FROM $user u - INNER JOIN $session_course_user r - ON u.user_id = r.user_id - 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); + $keyword = Database::escape_string($_GET['q']); + $status = 0; + if (empty($sessionId)) { + $status = STUDENT; + } - $result = Database::query($sql_query); - while ($user = Database::fetch_assoc($result)) { + $userList = CourseManager::get_user_list_from_course_code( + $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']); $json['items'][] = [ - 'id' => $user['id'], + 'id' => $user['user_id'], 'text' => "{$user['username']} ($userCompleteName)", ]; } @@ -262,7 +276,7 @@ switch ($action) { case 'search_exercise_by_course': if (api_is_platform_admin()) { $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( $course, $session_id, @@ -296,8 +310,8 @@ switch ($action) { $sql_query = sprintf( $sql, - intval($_GET['course_id']), - intval($_GET['session_id']), + (int) $_GET['course_id'], + (int) $_GET['session_id'], '%'.Database::escape_string($_GET['q']).'%' ); $result = Database::query($sql_query); @@ -316,7 +330,7 @@ switch ($action) { } break; case 'display_sessions_courses': - $sessionId = intval($_GET['session']); + $sessionId = (int) $_GET['session']; $userTable = Database::get_main_table(TABLE_MAIN_USER); $coursesData = SessionManager::get_course_list_by_session_id($sessionId); diff --git a/main/inc/ajax/course_chat.ajax.php b/main/inc/ajax/course_chat.ajax.php index ba05cacbe3..4dbf193f89 100644 --- a/main/inc/ajax/course_chat.ajax.php +++ b/main/inc/ajax/course_chat.ajax.php @@ -22,12 +22,12 @@ switch ($_REQUEST['action']) { $courseChatUtils->keepUserAsConnected(); $courseChatUtils->disconnectInactiveUsers(); - $friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; + $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; $filePath = $courseChatUtils->getFileName(true, $friend); $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(); - $oldUsersOnline = isset($_GET['users_online']) ? intval($_GET['users_online']) : 0; + $oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; $json = [ 'status' => true, @@ -50,7 +50,7 @@ switch ($_REQUEST['action']) { ]; break; case 'reset': - $friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; + $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; $json = [ 'status' => true, @@ -58,7 +58,7 @@ switch ($_REQUEST['action']) { ]; break; case 'write': - $friend = isset($_REQUEST['friend']) ? intval($_REQUEST['friend']) : 0; + $friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; $writed = $courseChatUtils->saveMessage($_POST['message'], $friend); $json = [ diff --git a/main/inc/ajax/course_home.ajax.php b/main/inc/ajax/course_home.ajax.php index 863b597f2a..8cf18d82b4 100755 --- a/main/inc/ajax/course_home.ajax.php +++ b/main/inc/ajax/course_home.ajax.php @@ -174,16 +174,16 @@ switch ($action) { */ require_once __DIR__.'/../global.inc.php'; $now = time(); - $page = intval($_REQUEST['page']); //page - $limit = intval($_REQUEST['rows']); // quantity of rows + $page = (int) $_REQUEST['page']; //page + $limit = (int) $_REQUEST['rows']; // quantity of rows //index to filter $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id'; $sord = $_REQUEST['sord']; //asc or desc if (!in_array($sord, ['asc', 'desc'])) { $sord = 'desc'; } - $session_id = intval($_REQUEST['session_id']); - $course_id = intval($_REQUEST['course_id']); + $session_id = (int) $_REQUEST['session_id']; + $course_id = (int) $_REQUEST['course_id']; //Filter users that does not belong to the session if (!api_is_platform_admin()) { @@ -302,8 +302,8 @@ switch ($action) { case 'session_courses_lp_by_week': require_once __DIR__.'/../global.inc.php'; $now = time(); - $page = intval($_REQUEST['page']); //page - $limit = intval($_REQUEST['rows']); // quantity of rows + $page = (int) $_REQUEST['page']; //page + $limit = (int) $_REQUEST['rows']; // quantity of rows $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'course'; $sidx = str_replace(['week desc,', ' '], '', $sidx); $sord = $_REQUEST['sord']; //asc or desc @@ -311,8 +311,8 @@ switch ($action) { $sord = 'desc'; } - $session_id = intval($_REQUEST['session_id']); - $course_id = intval($_REQUEST['course_id']); + $session_id = (int) $_REQUEST['session_id']; + $course_id = (int) $_REQUEST['course_id']; //Filter users that does not belong to the session if (!api_is_platform_admin()) { @@ -445,8 +445,8 @@ switch ($action) { case 'session_courses_lp_by_course': require_once __DIR__.'/../global.inc.php'; $now = time(); - $page = intval($_REQUEST['page']); //page - $limit = intval($_REQUEST['rows']); // quantity of rows + $page = (int) $_REQUEST['page']; //page + $limit = (int) $_REQUEST['rows']; // quantity of rows $sidx = isset($_REQUEST['sidx']) && !empty($_REQUEST['sidx']) ? $_REQUEST['sidx'] : 'id'; $sidx = str_replace(['course asc,', ' '], '', $sidx); @@ -454,8 +454,8 @@ switch ($action) { if (!in_array($sord, ['asc', 'desc'])) { $sord = 'desc'; } - $session_id = intval($_REQUEST['session_id']); - $course_id = intval($_REQUEST['course_id']); + $session_id = (int) $_REQUEST['session_id']; + $course_id = (int) $_REQUEST['course_id']; //Filter users that does not belong to the session if (!api_is_platform_admin()) { diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 77e0bc3030..59021acbc5 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -11,14 +11,15 @@ $debug = false; api_protect_course_script(true); $action = $_REQUEST['a']; -$course_id = api_get_course_int_id(); + if ($debug) { - error_log("-----------------"); + error_log('-----------------------------------------------------'); 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(); switch ($action) { @@ -34,7 +35,7 @@ switch ($action) { if (empty($exeId)) { if ($debug) { - error_log("Exe id not provided."); + error_log('Exe id not provided.'); } exit; } @@ -44,7 +45,7 @@ switch ($action) { if (empty($exerciseInSession)) { if ($debug) { - error_log("Exercise obj not provided."); + error_log('Exercise obj not provided.'); } exit; } @@ -85,7 +86,7 @@ switch ($action) { if ($attempt->getStatus() != 'incomplete') { if ($debug) { - error_log("Cannot update exercise is already completed."); + error_log('Cannot update exercise is already completed.'); } exit; } @@ -105,10 +106,6 @@ switch ($action) { ) { $sessionTime = $previousTime[$key]; $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)) { $duration += $durationFromObject; } @@ -150,9 +147,9 @@ switch ($action) { // 1. Setting variables needed by jqgrid $action = $_GET['a']; - $exercise_id = intval($_GET['exercise_id']); - $page = intval($_REQUEST['page']); //page - $limit = intval($_REQUEST['rows']); //quantity of rows + $exercise_id = (int) $_GET['exercise_id']; + $page = (int) $_REQUEST['page']; //page + $limit = (int) $_REQUEST['rows']; //quantity of rows $sidx = $_REQUEST['sidx']; //index to filter $sord = $_REQUEST['sord']; //asc or desc @@ -169,7 +166,7 @@ switch ($action) { $user_table = Database::get_main_table(TABLE_MAIN_USER); $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $minutes = intval($_REQUEST['minutes']); + $minutes = (int) $_REQUEST['minutes']; $now = time() - 60 * $minutes; $now = api_get_utc_datetime($now); @@ -271,18 +268,20 @@ switch ($action) { $response->rows[$i]['id'] = $row['exe_id']; 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); $m = floor(($remaining - ($h * 3600)) / 60); $s = ($remaining - ($h * 3600) - ($m * 60)); - $timeInfo = api_format_date( - $row['start_date'], - DATE_TIME_FORMAT_LONG - ).' ['.($h > 0 ? $h.':' : '').sprintf("%02d", $m).':'.sprintf("%02d", $s).']'; - } else { $timeInfo = api_format_date( $row['start_date'], DATE_TIME_FORMAT_LONG + ).' ['.($h > 0 ? $h.':' : '').sprintf("%02d", $m).':'.sprintf("%02d", $s).']'; + } else { + $timeInfo = api_format_date( + $row['start_date'], + DATE_TIME_FORMAT_LONG ); } $array = [ @@ -313,7 +312,7 @@ switch ($action) { [ 'exercise_order' => $counter, 'session_id' => $session_id, - 'exercise_id' => intval($new_order_id), + 'exercise_id' => (int) $new_order_id, 'c_id' => $course_id, ] ); @@ -325,7 +324,7 @@ switch ($action) { case 'update_question_order': $course_info = api_get_course_info_by_id($course_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)) { return Display::return_message(get_lang('Error'), 'error'); @@ -340,9 +339,7 @@ switch ($action) { ['question_order' => $counter], [ 'question_id = ? AND c_id = ? AND exercice_id = ? ' => [ - intval( - $new_order_id - ), + (int) $new_order_id, $course_id, $exercise_id, ], @@ -399,18 +396,23 @@ switch ($action) { // Questions choices. $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 = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : null; // 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. - $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0; - $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0; + $learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0; + $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0; // Attempt id. - $exeId = $_REQUEST['exe_id']; + $exeId = isset($_REQUEST['exe_id']) ? (int) $_REQUEST['exe_id'] : 0; if ($debug) { error_log("exe_id = $exeId"); @@ -418,6 +420,7 @@ switch ($action) { error_log("choice = ".print_r($choice, 1)." "); error_log("hot_spot_coordinates = ".print_r($hot_spot_coordinates, 1)); error_log("remind_list = ".print_r($remind_list, 1)); + error_log("--------------------------------"); } // Exercise information. @@ -484,7 +487,7 @@ switch ($action) { // Fires an error. echo 'error'; if ($debug) { - error_log("exe_id is empty"); + error_log('exe_id is empty'); } exit; } @@ -520,6 +523,13 @@ switch ($action) { // Creates a temporary Question object $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. 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]) @@ -538,6 +548,7 @@ switch ($action) { ) { $hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id]; } + if ($type == 'simple') { // Getting old attempt in order to decrees the total score. $old_result = $objExercise->manage_answer( @@ -560,7 +571,7 @@ switch ($action) { // Deleting old attempt if (isset($attemptList) && !empty($attemptList[$my_question_id])) { if ($debug) { - error_log("delete_attempt exe_id : $exeId, my_question_id: $my_question_id"); + error_log("delete_attempt exe_id : $exeId, my_question_id: $my_question_id"); } Event::delete_attempt( $exeId, @@ -569,7 +580,7 @@ switch ($action) { $session_id, $my_question_id ); - if ($objQuestionTmp->type == HOT_SPOT) { + if ($objQuestionTmp->type === HOT_SPOT) { Event::delete_attempt_hotspot( $exeId, api_get_user_id(), @@ -587,18 +598,36 @@ switch ($action) { } // We're inside *one* question. Go through each possible answer for this question - $result = $objExercise->manage_answer( - $exeId, - $my_question_id, - $my_choice, - 'exercise_result', - $hot_spot_coordinates, - true, - false, - false, - $objExercise->selectPropagateNeg(), - $hotspot_delineation_result - ); + 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( + $exeId, + $my_question_id, + $my_choice, + 'exercise_result', + $hot_spot_coordinates, + true, + false, + false, + $objExercise->selectPropagateNeg(), + $hotspot_delineation_result + ); + } // Adding the new score. $total_score += $result['score']; @@ -610,7 +639,6 @@ switch ($action) { $duration = 0; $now = time(); - if ($type == 'all') { $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]); - Event::updateEventExercise( $exeId, $objExercise->selectId(), @@ -661,18 +688,28 @@ switch ($action) { // Destruction of the Question object unset($objQuestionTmp); 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 ($debug) { + error_log("result: one_per_page"); + error_log(" ------ end ajax call ------- "); + } echo 'one_per_page'; exit; } + if ($debug) { + error_log("result: ok"); + error_log(" ------ end ajax call ------- "); + } echo 'ok'; break; case 'show_question': @@ -692,17 +729,22 @@ switch ($action) { $objExercise = new Exercise(); $objExercise->read($exerciseId); - $objQuestion = Question::read($questionId); echo '

'.$objQuestion->get_question_type_name().'

'; - if ($objQuestion->type == FILL_IN_BLANKS) { + if ($objQuestion->type === FILL_IN_BLANKS) { echo ''; } + + // Allows render MathJax elements in a ajax call + if (api_get_setting('include_asciimathml_script') === 'true') { + echo ''; + } + ExerciseLib::showQuestion( $objExercise, $questionId, diff --git a/main/inc/ajax/message.ajax.php b/main/inc/ajax/message.ajax.php index 4c00accd0d..5cf5421099 100755 --- a/main/inc/ajax/message.ajax.php +++ b/main/inc/ajax/message.ajax.php @@ -96,9 +96,7 @@ switch ($action) { break; } - /** @var UserRepository $repo */ - $repo = Database::getManager()->getRepository('ChamiloUserBundle:User'); - + $repo = UserManager::getRepository(); $users = $repo->findUsersToSendMessage( api_get_user_id(), $_REQUEST['q'], diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 9a2f90a26a..c255dcf23a 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -53,6 +53,7 @@ if (!in_array( 'get_work_user_list_all', 'get_timelines', 'get_user_skill_ranking', + 'get_usergroups', 'get_usergroups_teacher', 'get_user_course_report_resumed', 'get_user_course_report', @@ -60,6 +61,9 @@ if (!in_array( 'get_sessions', 'get_course_announcements', 'course_log_events', + 'get_learning_path_calendars', + 'get_usergroups_users', + 'get_calendar_users', ] ) && !isset($_REQUEST['from_course_session'])) { api_protect_admin_script(true); @@ -228,13 +232,27 @@ if (!$sidx) { //@todo rework this 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': $courseId = api_get_course_int_id(); if (empty($courseId)) { exit; } $sessionId = api_get_session_id(); - if (!api_is_allowed_to_edit()) { exit; } @@ -262,9 +280,8 @@ switch ($action) { if ($userNotAllowed) { exit; } - $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 = []; $userIdList = []; $sessionIdList = []; @@ -732,15 +749,16 @@ switch ($action) { break; case 'get_usergroups': $obj = new UserGroup(); + $obj->protectScript(); $count = $obj->get_count(); break; case 'get_usergroups_teacher': $obj = new UserGroup(); + $obj->protectScript(); $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(); - if ($type == 'registered') { + if ($type === 'registered') { $count = $obj->getUserGroupByCourseWithDataCount( $course_id, $groupFilter @@ -780,9 +798,37 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit $columns = []; 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': $columns = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; - $result = Statistics::getActivitiesData( $start, $limit, @@ -791,7 +837,6 @@ switch ($action) { $courseId, $sessionId ); - break; case 'get_programmed_announcements': $columns = ['subject', 'date', 'sent', 'actions']; @@ -1239,6 +1284,8 @@ switch ($action) { ]; $extraFieldsToAdd = []; $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'])) { $extraField = new ExtraField('user'); foreach ($extraFields['fields'] as $variable) { @@ -1257,7 +1304,7 @@ switch ($action) { $columns[] = 'exe_date'; $columns[] = 'score'; - if ($operation == 'excel') { + if ($operation === 'excel') { $columns = [ 'firstname', 'lastname', @@ -1320,7 +1367,8 @@ switch ($action) { true, true, $extraFieldsToAdd, - true + true, + $roundValues ); break; case 'get_hotpotatoes_exercise_results': @@ -1435,20 +1483,13 @@ switch ($action) { 0, 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_date[] = get_lang('Until').' '.api_format_date($session['access_end_date'], DATE_FORMAT_SHORT); - } - - if (empty($session_date)) { - $session_date_string = '-'; - } else { - $session_date_string = implode(' ', $session_date); - } + $session['display_start_date'] = ''; + $session['display_end_date'] = ''; + $session['coach_access_start_date'] = ''; + $session['coach_access_end_date'] = ''; + $dateData = SessionManager::parseSessionDates($session, true); + $dateToString = $dateData['access']; $detailButtons = []; $detailButtons[] = Display::url( @@ -1465,7 +1506,7 @@ switch ($action) { $session['name'], 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, 'student_per_session' => $count_users_in_session, 'details' => implode(' ', $detailButtons), @@ -1535,9 +1576,9 @@ switch ($action) { */ break; case 'get_exercise_progress': - $sessionId = intval($_GET['session_id']); - $courseId = intval($_GET['course_id']); - $exerciseId = intval($_GET['exercise_id']); + $sessionId = (int) $_GET['session_id']; + $courseId = (int) $_GET['course_id']; + $exerciseId = (int) $_GET['exercise_id']; $date_from = $_GET['date_from']; $date_to = $_GET['date_to']; @@ -1572,8 +1613,8 @@ switch ($action) { case 'get_session_lp_progress': $sessionId = 0; if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) { - $sessionId = intval($_GET['session_id']); - $courseId = intval($_GET['course_id']); + $sessionId = (int) $_GET['session_id']; + $courseId = (int) $_GET['course_id']; $course = api_get_course_info_by_id($courseId); } @@ -1914,6 +1955,7 @@ switch ($action) { $result = $new_result; break; case 'get_usergroups': + $obj->protectScript(); $columns = ['name', 'users', 'courses', 'sessions', 'group_type', 'actions']; $result = $obj->getUsergroupsPagination($sidx, $sord, $start, $limit); break; @@ -2075,19 +2117,29 @@ switch ($action) { switch ($type) { 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); break; case 'registered': - $options['where'] = [" usergroup.course_id = ? " => $course_id]; + $options['where'] = [' usergroup.course_id = ? ' => $course_id]; $result = $obj->getUserGroupInCourse($options, $groupFilter); break; } $new_result = []; if (!empty($result)) { + $urlUserGroup = api_get_path(WEB_CODE_PATH).'admin/usergroup_users.php?'.api_get_cidreq(); 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)) { $url = 'class.php?action=remove_class_from_course&id='.$group['id'].'&'.api_get_cidreq(); $icon = Display::return_icon('delete.png', get_lang('Remove')); @@ -2107,7 +2159,16 @@ switch ($action) { $role = $obj->getUserRoleToString(api_get_user_id(), $group['id']); $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'] + ).' '; + } + + $group['actions'] .= Display::url($icon, $url); $new_result[] = $group; } $result = $new_result; @@ -2159,6 +2220,9 @@ $allowed_actions = [ 'get_course_announcements', 'get_programmed_announcements', 'course_log_events', + 'get_learning_path_calendars', + 'get_usergroups_users', + 'get_calendar_users', ]; //5. Creating an obj to return a json diff --git a/main/inc/ajax/online.ajax.php b/main/inc/ajax/online.ajax.php index d8ad05a07b..9a5e29afb2 100755 --- a/main/inc/ajax/online.ajax.php +++ b/main/inc/ajax/online.ajax.php @@ -12,11 +12,15 @@ switch ($action) { echo returnNotificationMenu(); break; case 'load_online_user': + $access = accessToWhoIsOnline(); + + if (!$access) { + exit; + } $images_to_show = MAX_ONLINE_USERS; $page = intval($_REQUEST['online_page_nr']); $max_page = ceil(who_is_online_count() / $images_to_show); $page_rows = ($page - 1) * MAX_ONLINE_USERS; - if (!empty($max_page) && $page <= $max_page) { if (isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) { $user_list = who_is_online_in_this_course( diff --git a/main/inc/ajax/record_audio_rtc.ajax.php b/main/inc/ajax/record_audio_rtc.ajax.php index c50e12b073..283808ec35 100644 --- a/main/inc/ajax/record_audio_rtc.ajax.php +++ b/main/inc/ajax/record_audio_rtc.ajax.php @@ -6,12 +6,17 @@ use ChamiloSession as Session; require_once __DIR__.'/../global.inc.php'; // Add security from Chamilo -api_protect_course_script(); api_block_anonymous_users(); $courseInfo = api_get_course_info(); /** @var string $tool document or exercise */ $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(); if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) { @@ -33,57 +38,64 @@ if (!isset($_FILES['audio_blob'], $_REQUEST['audio_dir'])) { } $file = isset($_FILES['audio_blob']) ? $_FILES['audio_blob'] : []; -$audioDir = Security::remove_XSS($_REQUEST['audio_dir']); - -$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'; -$saveDir = $dirBaseDocuments.$audioDir; - -if (!is_dir($saveDir)) { - mkdir($saveDir, api_get_permissions_for_new_directories(), true); -} - $file['file'] = $file; +$audioDir = Security::remove_XSS($_REQUEST['audio_dir']); -$uploadedDocument = DocumentManager::upload_document( - $file, - $audioDir, - $file['name'], - null, - 0, - 'overwrite', - false, - in_array($tool, ['document', 'exercise']) -); - -$error = empty($uploadedDocument) || !is_array($uploadedDocument); - -if (!$error) { - $newDocId = $uploadedDocument['id']; - $courseId = $uploadedDocument['c_id']; - - /** @var learnpath $lp */ - $lp = Session::read('oLP'); - $lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null; - if (!empty($lp) && empty($lpItemId)) { - $lp->set_modified_on(); - - $lpItem = new learnpathItem($lpItemId); - $lpItem->add_audio_from_documents($newDocId); - } - - $data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']); - - if ($tool === 'exercise') { - header('Content-Type: application/json'); - echo json_encode([ - 'error' => $error, - 'message' => Display::getFlashToString(), - 'fileUrl' => $data['document_url'], - ]); - - Display::cleanFlashMessages(); - exit; - } - - echo $data['document_url']; +switch ($type) { + case 'document': + $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document'; + $saveDir = $dirBaseDocuments.$audioDir; + if (!is_dir($saveDir)) { + mkdir($saveDir, api_get_permissions_for_new_directories(), true); + } + $uploadedDocument = DocumentManager::upload_document( + $file, + $audioDir, + $file['name'], + null, + 0, + 'overwrite', + false, + in_array($tool, ['document', 'exercise']) + ); + + $error = empty($uploadedDocument) || !is_array($uploadedDocument); + + if (!$error) { + $newDocId = $uploadedDocument['id']; + $courseId = $uploadedDocument['c_id']; + + /** @var learnpath $lp */ + $lp = Session::read('oLP'); + $lpItemId = isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id']) ? $_REQUEST['lp_item_id'] : null; + if (!empty($lp) && empty($lpItemId)) { + $lp->set_modified_on(); + + $lpItem = new learnpathItem($lpItemId); + $lpItem->add_audio_from_documents($newDocId); + } + + $data = DocumentManager::get_document_data_by_id($newDocId, $courseInfo['code']); + + if ($tool === 'exercise') { + header('Content-Type: application/json'); + echo json_encode([ + 'error' => $error, + 'message' => Display::getFlashToString(), + 'fileUrl' => $data['document_url'], + ]); + + Display::cleanFlashMessages(); + exit; + } + + 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; } diff --git a/main/inc/ajax/record_audio_wami.ajax.php b/main/inc/ajax/record_audio_wami.ajax.php index 9a17e32a2a..629c09ca4b 100755 --- a/main/inc/ajax/record_audio_wami.ajax.php +++ b/main/inc/ajax/record_audio_wami.ajax.php @@ -6,7 +6,6 @@ use ChamiloSession as Session; require_once __DIR__.'/../global.inc.php'; // Add security from Chamilo -api_protect_course_script(); api_block_anonymous_users(); $_course = api_get_course_info(); @@ -28,6 +27,12 @@ if (empty($wamiuserid)) { die(); } +$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'document'; // can be document or message + +if ($type === 'document') { + api_protect_course_script(); +} + // Clean $waminame = Security::remove_XSS($waminame); $waminame = Database::escape_string($waminame); @@ -47,95 +52,104 @@ if ($ext != 'wav') { die(); } -// Do not use here check Fileinfo method because return: text/plain - -$dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; -$saveDir = $dirBaseDocuments.$wamidir; +switch ($type) { + case 'document': + // Do not use here check Fileinfo method because return: text/plain + $dirBaseDocuments = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; + $saveDir = $dirBaseDocuments.$wamidir; -if (!is_dir($saveDir)) { - DocumentManager::createDefaultAudioFolder($_course); -} + if (!is_dir($saveDir)) { + 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; - -// Add to disk -$fh = fopen($documentPath, 'w') or die("can't open file"); -fwrite($fh, $content); -fclose($fh); - -$fileInfo = pathinfo($documentPath); -$courseInfo = api_get_course_info(); - -$file = [ - 'file' => [ - 'name' => $fileInfo['basename'], - 'tmp_name' => $documentPath, - 'size' => filesize($documentPath), - 'type' => 'audio/wav', - 'from_file' => true, - ], -]; -$output = true; -ob_start(); - -// Strangely the file path changes with a double extension -copy($documentPath, $documentPath.'.wav'); - -$documentData = DocumentManager::upload_document( - $file, - $wamidir, - $fileInfo['basename'], - 'wav', - 0, - 'overwrite', - false, - $output -); -$contents = ob_get_contents(); - -if (!empty($documentData)) { - $newDocId = $documentData['id']; - $documentData['comment'] = 'mp3'; - $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3( - $documentData, - $courseInfo, - api_get_session_id(), - api_get_user_id(), - 'overwrite', - true - ); - - if ($newMp3DocumentId) { - $newDocId = $newMp3DocumentId; - } - - if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) { - $lpItemId = $_REQUEST['lp_item_id']; - /** @var learnpath $lp */ - $lp = Session::read('oLP'); - - if (!empty($lp)) { - $lp->set_modified_on(); - $lpItem = new learnpathItem($lpItemId); - $lpItem->add_audio_from_documents($newDocId); - echo Display::return_message(get_lang('Updated'), 'info'); + // Avoid duplicates + $waminame_to_save = $waminame; + $documentPath = $saveDir.'/'.$waminame_to_save; + + // Add to disk + $fh = fopen($documentPath, 'w') or die("can't open file"); + fwrite($fh, $content); + fclose($fh); + + $fileInfo = pathinfo($documentPath); + $courseInfo = api_get_course_info(); + + $file = [ + 'file' => [ + 'name' => $fileInfo['basename'], + 'tmp_name' => $documentPath, + 'size' => filesize($documentPath), + 'type' => 'audio/wav', + 'from_file' => true, + ], + ]; + $output = true; + ob_start(); + + // Strangely the file path changes with a double extension + copy($documentPath, $documentPath.'.wav'); + + $documentData = DocumentManager::upload_document( + $file, + $wamidir, + $fileInfo['basename'], + 'wav', + 0, + 'overwrite', + false, + $output + ); + $contents = ob_get_contents(); + + if (!empty($documentData)) { + $newDocId = $documentData['id']; + $documentData['comment'] = 'mp3'; + $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3( + $documentData, + $courseInfo, + api_get_session_id(), + api_get_user_id(), + 'overwrite', + true + ); + + if ($newMp3DocumentId) { + $newDocId = $newMp3DocumentId; + } + + if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) { + $lpItemId = $_REQUEST['lp_item_id']; + /** @var learnpath $lp */ + $lp = Session::read('oLP'); + + if (!empty($lp)) { + $lp->set_modified_on(); + $lpItem = new learnpathItem($lpItemId); + $lpItem->add_audio_from_documents($newDocId); + echo Display::return_message(get_lang('Updated'), 'info'); + } + } + + // Strangely the file path changes with a double extension + // Remove file with one extension + unlink($documentPath); + } else { + echo $contents; } - } - // Strangely the file path changes with a double extension - // Remove file with one extension - unlink($documentPath); -} else { - 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; } diff --git a/main/inc/ajax/session.ajax.php b/main/inc/ajax/session.ajax.php index ae90361b45..c10f831804 100755 --- a/main/inc/ajax/session.ajax.php +++ b/main/inc/ajax/session.ajax.php @@ -14,7 +14,7 @@ $action = $_REQUEST['a']; switch ($action) { case 'get_user_sessions': 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); if (!empty($list_sessions)) { foreach ($list_sessions as $session_item) { @@ -187,9 +187,7 @@ switch ($action) { 'items' => [], ]; - $entityManager = Database::getManager(); - /** @var UserRepository $usersRepo */ - $usersRepo = $entityManager->getRepository('ChamiloUserBundle:User'); + $usersRepo = UserManager::getRepository(); $users = $usersRepo->searchUsersByStatus($_GET['q'], COURSEMANAGER, api_get_current_access_url_id()); /** @var User $user */ foreach ($users as $user) { diff --git a/main/inc/ajax/user_manager.ajax.php b/main/inc/ajax/user_manager.ajax.php index 66aee22231..ff42ce54c0 100755 --- a/main/inc/ajax/user_manager.ajax.php +++ b/main/inc/ajax/user_manager.ajax.php @@ -20,7 +20,7 @@ switch ($action) { 'firstname' => $query, 'lastname' => $query, ]; - $users = UserManager::get_user_list_like($conditions, [], false, 'OR'); + $users = UserManager::getUserListLike($conditions, [], false, 'OR'); $result = []; if (!empty($users)) { foreach ($users as $user) { diff --git a/main/inc/lib/formvalidator/Element/DatePicker.php b/main/inc/lib/formvalidator/Element/DatePicker.php index 6f09de03f2..81eac23a7e 100644 --- a/main/inc/lib/formvalidator/Element/DatePicker.php +++ b/main/inc/lib/formvalidator/Element/DatePicker.php @@ -82,7 +82,6 @@ class DatePicker extends HTML_QuickForm_text public function getTemplate($layout) { $size = $this->getColumnsSize(); - $id = $this->getAttribute('id'); $value = $this->getValue(); if (empty($size)) { diff --git a/main/inc/lib/hook/HookUpdateUser.php b/main/inc/lib/hook/HookUpdateUser.php index ec2895e396..6d5443e568 100644 --- a/main/inc/lib/hook/HookUpdateUser.php +++ b/main/inc/lib/hook/HookUpdateUser.php @@ -25,8 +25,9 @@ class HookUpdateUser extends HookEvent implements HookUpdateUserEventInterface */ public function notifyUpdateUser($type) { - /** @var \HookUpdateUserObserverInterface $observer */ $this->eventData['type'] = $type; + + /** @var HookUpdateUserObserverInterface $observer */ foreach ($this->observers as $observer) { $observer->hookUpdateUser($this); } diff --git a/main/inc/lib/pear/HTML/QuickForm.php b/main/inc/lib/pear/HTML/QuickForm.php index ca8ae4ef2c..f99904d26d 100755 --- a/main/inc/lib/pear/HTML/QuickForm.php +++ b/main/inc/lib/pear/HTML/QuickForm.php @@ -674,14 +674,23 @@ class HTML_QuickForm extends HTML_Common * @access public * @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; if (0 == strlen($name)) { - $name = 'qf_group_' . $anonGroups++; + $name = 'qf_group_'.$anonGroups++; $appendName = false; } + if ($createElement) { + return $this->createElement('group', $name, $groupLabel, $elements, $separator, $appendName); + } $group = & $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName); return $group; } @@ -1431,8 +1440,7 @@ class HTML_QuickForm extends HTML_Common */ public function validate() { - if (count($this->_rules) == 0 && count($this->_formRules) == 0 && - $this->isSubmitted()) { + if (count($this->_rules) == 0 && count($this->_formRules) == 0 && $this->isSubmitted()) { return (0 == count($this->_errors)); } elseif (!$this->isSubmitted()) { diff --git a/main/inc/lib/pear/HTML/QuickForm/Rule/MinText.php b/main/inc/lib/pear/HTML/QuickForm/Rule/MinText.php index 39bb07394c..d66b792a39 100755 --- a/main/inc/lib/pear/HTML/QuickForm/Rule/MinText.php +++ b/main/inc/lib/pear/HTML/QuickForm/Rule/MinText.php @@ -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 * @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); } } diff --git a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php index f9d0e4b9be..82246c24af 100755 --- a/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php +++ b/main/inc/lib/pear/HTML/QuickForm/advmultiselect.php @@ -50,6 +50,8 @@ 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. * * 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 { - /** - * 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 * @@ -92,7 +76,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_tableAttributes; + public $_tableAttributes; /** * Associative array of the add button attributes @@ -101,7 +85,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_addButtonAttributes; + public $_addButtonAttributes; /** * Associative array of the remove button attributes @@ -110,7 +94,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_removeButtonAttributes; + public $_removeButtonAttributes; /** * Associative array of the select all button attributes @@ -119,7 +103,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 1.1.0 */ - var $_allButtonAttributes; + public $_allButtonAttributes; /** * Associative array of the select none button attributes @@ -128,7 +112,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 1.1.0 */ - var $_noneButtonAttributes; + public $_noneButtonAttributes; /** * Associative array of the toggle selection button attributes @@ -137,7 +121,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 1.1.0 */ - var $_toggleButtonAttributes; + public $_toggleButtonAttributes; /** * Associative array of the move up button attributes @@ -146,7 +130,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.5.0 */ - var $_upButtonAttributes; + public $_upButtonAttributes; /** * Associative array of the move up button attributes @@ -155,7 +139,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.5.0 */ - var $_downButtonAttributes; + public $_downButtonAttributes; /** * Associative array of the move top button attributes @@ -164,7 +148,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 1.5.0 */ - var $_topButtonAttributes; + public $_topButtonAttributes; /** * Associative array of the move bottom button attributes @@ -173,7 +157,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 1.5.0 */ - var $_bottomButtonAttributes; + public $_bottomButtonAttributes; /** * 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 * @since 0.5.0 */ - var $_sort; + public $_sort; /** * Associative array of the unselected item box attributes @@ -196,7 +180,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_attributesUnselected; + public $_attributesUnselected; /** * Associative array of the selected item box attributes @@ -205,7 +189,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_attributesSelected; + public $_attributesSelected; /** * Associative array of the internal hidden box attributes @@ -214,8 +198,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_attributesHidden; - + public $_attributesHidden; public $selectAllCheckBox = false; /** @@ -225,7 +208,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_elementTemplate; + public $_elementTemplate; /** * Default Element stylesheet string @@ -234,15 +217,11 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @access private * @since 0.4.0 */ - var $_elementCSS = ''; + public $_elementCSS = ''; /** * 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 mixed $elementLabel Label(s) for the select boxes * @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 parent::__construct($elementName, $elementLabel, $options, $attributes); - $this->selectAllCheckBox = isset($attributes['select_all_checkbox']) ? $attributes['select_all_checkbox'] : false; // 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 $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->setAttribute('class','form-control'); @@ -315,9 +284,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $this->setButtonAttributes('movetop'); // set default move bottom button attributes $this->setButtonAttributes('movebottom'); - // defines javascript functions names - $this->_jsPrefix = 'QFAMS.'; - $this->_jsPostfix = 'moveSelection'; // set select boxes sort order (none by default) 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 * Custom example 1: screenshot */ - function setButtonAttributes($button, $attributes = null) + public function setButtonAttributes($button, $attributes = null) { if (!is_string($button)) { return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . @@ -509,13 +475,13 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * Sets element template * * @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 * @return string * @since version 0.4.0 (2005-06-25) */ - function setElementTemplate($html = null, $js = true) + public function setElementTemplate($html = null, $js = true) { $oldTemplate = $this->_elementTemplate; @@ -531,7 +497,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select '; } - if ($js == false) { + if ($js === false) { $this->_elementTemplate = str_replace('{javascript}', '', $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 * Custom example 4: screenshot */ - function getElementCss($raw = true) + public function getElementCss($raw = true) { $id = $this->getAttribute('name'); $css = str_replace('{id}', $id, $this->_elementCSS); @@ -587,17 +553,17 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $tabs = $this->_getTabs(); $tab = $this->_getTab(); - $selectId = $this->getName(); - $selectName = $this->getName() . '[]'; - $selectNameFrom = $this->getName() . '-f[]'; - $selectNameTo = $this->getName() . '-t[]'; + $selectId = $this->getName(); + $selectName = $this->getName().'[]'; + $selectNameFrom = $this->getName().'-f[]'; + $selectNameTo = $this->getName().'[]'; $selected_count = 0; + $rightAll = ''; + $leftAll = ''; // placeholder {unselected} existence determines if we will render if (strpos($this->_elementTemplate, '{unselected}') === false) { // ... a single multi-select with checkboxes - $this->_jsPostfix = 'editSelection'; - $id = $this->getAttribute('name'); $strHtmlSelected = $tab . '
' . PHP_EOL; @@ -615,8 +581,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select } } - if (is_array($this->_values) - && in_array((string)$option['attr']['value'], $this->_values)) { + if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) { // The items is *selected* $checked = ' checked="checked"'; $selected_count++; @@ -626,89 +591,75 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select } $checkbox_id_suffix++; $strHtmlSelected .= $tab - . '_getAttrString($labelAttributes) .'>' - . '_getAttrString($option['attr']) - . ' />' . $option['text'] . '' - . PHP_EOL; + .'_getAttrString($labelAttributes).'>' + .'_getAttrString($option['attr']) + .' />'.$option['text'].'' + .PHP_EOL; } $strHtmlSelected .= $tab . '
'. PHP_EOL; - $strHtmlHidden = ''; + $strHtmlHidden = ''; $strHtmlUnselected = ''; - $strHtmlAdd = ''; - $strHtmlRemove = ''; + $strHtmlAdd = ''; + $strHtmlRemove = ''; // build the select all button with all its attributes - $jsName = $this->_jsPrefix . $this->_jsPostfix; - $attributes = array('onclick' => $jsName ."('". $selectId ."', 1);"); + $attributes = []; $this->_allButtonAttributes = array_merge($this->_allButtonAttributes, $attributes); $attrStrAll = $this->_getAttrString($this->_allButtonAttributes); $strHtmlAll = "". PHP_EOL; // build the select none button with all its attributes - $attributes = array('onclick' => $jsName ."('". $selectId ."', 0);"); + $attributes = []; $this->_noneButtonAttributes = array_merge($this->_noneButtonAttributes, $attributes); $attrStrNone = $this->_getAttrString($this->_noneButtonAttributes); $strHtmlNone = "". PHP_EOL; // build the toggle selection button with all its attributes - $attributes = array('onclick' => $jsName . - "('". $selectId ."', 2);"); + $attributes = []; $this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes); $attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes); $strHtmlToggle = "". PHP_EOL; - $strHtmlMoveUp = ''; - $strHtmlMoveDown = ''; - $strHtmlMoveTop = ''; - $strHtmlMoveBottom = ''; + $strHtmlMoveUp = ''; + $strHtmlMoveDown = ''; + $strHtmlMoveTop = ''; + $strHtmlMoveBottom = ''; // default selection counters $strHtmlSelectedCount = $selected_count . '/' . $unselected_count; } else { - // ... or a dual multi-select - $this->_jsPostfix = 'moveSelection'; - $jsName = $this->_jsPrefix . $this->_jsPostfix; - // set name of Select From Box $this->_attributesUnselected - = array('id' => $selectId . '-f', + = array( + 'id' => $selectId.'', 'name' => $selectNameFrom, - 'ondblclick' => $jsName . - "('{$selectId}', ". - "this.form.elements['" . $selectNameFrom . "'], " . - "this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "'], " . - "'add', '{$this->_sort}')"); + ); $this->_attributesUnselected = array_merge($this->_attributes, $this->_attributesUnselected); $attrUnselected = $this->_getAttrString($this->_attributesUnselected); // set name of Select To Box $this->_attributesSelected - = array('id' => $selectId . '-t', + = array( + 'id' => $selectId.'_to', 'name' => $selectNameTo, - 'ondblclick' => $jsName . - "('{$selectId}', " . - "this.form.elements['" . $selectNameFrom . "'], " . - "this.form.elements['" . $selectNameTo . "'], ". - "this.form.elements['" . $selectName . "'], " . - "'remove', '{$this->_sort}')"); + ); $this->_attributesSelected = array_merge($this->_attributes, $this->_attributesSelected); $attrSelected = $this->_getAttrString($this->_attributesSelected); // set name of Select hidden Box $this->_attributesHidden - = array('name' => $selectName, - 'style' => 'overflow: hidden; visibility: hidden; ' . - 'width: 1px; height: 0;'); + = array( + 'name' => $selectName, + 'style' => 'overflow: hidden; visibility: hidden; width: 1px; height: 0;', + ); $this->_attributesHidden = array_merge($this->_attributes, $this->_attributesHidden); $attrHidden = $this->_getAttrString($this->_attributesHidden); @@ -721,18 +672,17 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $arrHtmlSelected = array(); } - $options = count($this->_options); + $options = count($this->_options); $arrHtmlUnselected = array(); if ($options > 0) { $arrHtmlHidden = array_fill(0, $options, ' '); - foreach ($this->_options as $option) { - if (is_array($this->_values) - && in_array((string)$option['attr']['value'], - $this->_values)) { + if (is_array($this->_values) && in_array((string) $option['attr']['value'], $this->_values)) { // Get the post order - $key = array_search($option['attr']['value'], - $this->_values); + $key = array_search( + $option['attr']['value'], + $this->_values + ); /** The items is *selected* so we want to put it in the 'selected' multi-select */ @@ -753,40 +703,29 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $append++; } } - } else { - $arrHtmlHidden = array(); } // The 'unselected' multi-select which appears on the left $unselected_count = count($arrHtmlUnselected); - 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); } $strHtmlUnselected = "". PHP_EOL; if ($unselected_count > 0) { foreach ($arrHtmlUnselected as $data) { $strHtmlUnselected - .= $tabs . $tab - . '_getAttrString($data['attr']) . '>' - . $data['text'] . '' . PHP_EOL; + .= $tabs.$tab + .'_getAttrString($data['attr']).'>' + .$data['text'].''.PHP_EOL; } - } else { - $strHtmlUnselected .= ''; } $strHtmlUnselected .= ''; - $strHtmlUnselected = '
'.$strHtmlUnselected; // The 'selected' multi-select which appears on the right $selected_count = count($arrHtmlSelected); - 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); } $strHtmlSelected = ""; @@ -802,139 +741,77 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $text = $data['text']; } $strHtmlSelected - .= $tabs . $tab - . '' - . $text . ''; + .= $tabs.$tab + .'' + .$text.''; } - } else { - $strHtmlSelected .= ''; } $strHtmlSelected .= ''; - - $strHtmlSelected = '
'.$strHtmlSelected; - - // The 'hidden' multi-select - $strHtmlHidden = "". 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 - . '' - . $text . '' . PHP_EOL; - } - } - $strHtmlHidden .= ''; - - // 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;"); + $strHtmlHidden = ''; + $attributes = array('id' => $selectId.'_leftSelected'); $this->_removeButtonAttributes = array_merge($this->_removeButtonAttributes, $attributes); $attrStrRemove = $this->_getAttrString($this->_removeButtonAttributes); $strHtmlRemove = ""; // build the add button with all its attributes - $attributes - = array('onclick' => $jsName . - "('{$selectId}', " . - "this.form.elements['" . $selectNameFrom . "'], " . - "this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "'], " . - "'add', '{$this->_sort}'); return false;"); + $attributes = array('id' => $selectId.'_rightSelected'); $this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); $attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); $strHtmlAdd = "

"; + if ($this->selectAllCheckBox) { + $attributes = array('id' => $selectId.'_rightAll'); + $this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); + $attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); + $rightAll = "

"; + + $attributes = array('id' => $selectId.'_leftAll'); + $this->_addButtonAttributes = array_merge($this->_addButtonAttributes, $attributes); + $attrStrAdd = $this->_getAttrString($this->_addButtonAttributes); + $leftAll = "

"; + } + // build the select all button with all its attributes - $attributes - = 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 = "". PHP_EOL; + $strHtmlAll = ''; // build the select none button with all its attributes - $attributes - = array('onclick' => $jsName . - "('{$selectId}', " . - "this.form.elements['" . $selectNameFrom . "'], " . - "this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "'], " . - "'none', '{$this->_sort}'); return false;"); + $attributes = []; $this->_noneButtonAttributes = array_merge($this->_noneButtonAttributes, $attributes); $attrStrNone = $this->_getAttrString($this->_noneButtonAttributes); $strHtmlNone = "". PHP_EOL; // build the toggle button with all its attributes - $attributes - = array('onclick' => $jsName . - "('{$selectId}', " . - "this.form.elements['" . $selectNameFrom . "'], " . - "this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "'], " . - "'toggle', '{$this->_sort}'); return false;"); + $attributes = []; $this->_toggleButtonAttributes = array_merge($this->_toggleButtonAttributes, $attributes); $attrStrToggle = $this->_getAttrString($this->_toggleButtonAttributes); $strHtmlToggle = "". PHP_EOL; // build the move up button with all its attributes - $attributes - = array('onclick' => "{$this->_jsPrefix}moveUp" . - "(this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "']); " . - "return false;"); + $attributes = []; $this->_upButtonAttributes = array_merge($this->_upButtonAttributes, $attributes); $attrStrUp = $this->_getAttrString($this->_upButtonAttributes); $strHtmlMoveUp = "". PHP_EOL; // build the move down button with all its attributes - $attributes - = array('onclick' => "{$this->_jsPrefix}moveDown" . - "(this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "']); " . - "return false;"); + $attributes = []; $this->_downButtonAttributes = array_merge($this->_downButtonAttributes, $attributes); $attrStrDown = $this->_getAttrString($this->_downButtonAttributes); $strHtmlMoveDown = "". PHP_EOL; // build the move top button with all its attributes - $attributes - = array('onclick' => "{$this->_jsPrefix}moveTop" . - "(this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "']); " . - "return false;"); + $attributes = []; $this->_topButtonAttributes = array_merge($this->_topButtonAttributes, $attributes); $attrStrTop = $this->_getAttrString($this->_topButtonAttributes); $strHtmlMoveTop = "". PHP_EOL; // build the move bottom button with all its attributes - $attributes - = array('onclick' => "{$this->_jsPrefix}moveBottom" . - "(this.form.elements['" . $selectNameTo . "'], " . - "this.form.elements['" . $selectName . "']); " . - "return false;"); + $attributes = []; $this->_bottomButtonAttributes = array_merge($this->_bottomButtonAttributes, $attributes); $attrStrBottom = $this->_getAttrString($this->_bottomButtonAttributes); @@ -944,7 +821,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $strHtmlSelectedCount = $selected_count; } $strHtmlUnselectedCount = $unselected_count; - $strHtmlSelectedCountId = $selectId .'_selected'; $strHtmlUnselectedCountId = $selectId .'_unselected'; @@ -959,7 +835,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select // render extra labels, if any if (is_array($labels)) { 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("", '', $strHtml); $strHtml = str_replace("", '', $strHtml); @@ -1003,8 +879,8 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $strHtmlSelectedCount, $strHtmlUnselected, $strHtmlSelected.$strHtmlHidden, - $strHtmlAdd, - $strHtmlRemove, + $rightAll.$strHtmlAdd, + $strHtmlRemove.$leftAll, $strHtmlAll, $strHtmlNone, $strHtmlToggle, @@ -1014,14 +890,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $strHtmlMoveBottom, ); - if ($this->selectAllCheckBox) { - $strHtml .= '
- -
'; - } - $strHtml = str_replace($placeHolders, $htmlElements, $strHtml); $comment = $this->getComment(); @@ -1029,7 +897,6 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select $strHtml = $tabs . '" . PHP_EOL . $strHtml; } - return $strHtml; } @@ -1043,20 +910,26 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @return string * @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; - $js .= 'qfamsHandler.js'; - - if (file_exists($js)) { - $js = file_get_contents($js); - } else { - $js = ''; - } - - if ($raw !== true) { - $js = ''.PHP_EOL; - } + $name = $this->getName(); + $js = api_get_asset('multiselect-two-sides/dist/js/multiselect.js'); + $search = + '
'; + + $js .= ''.PHP_EOL; return $js; } @@ -1079,7 +952,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @throws PEAR_Error * @see loadArray() */ - function load(&$options, + public function load(&$options, $param1 = null, $param2 = null, $param3 = null, $param4 = null) { if (is_array($options)) { @@ -1105,7 +978,7 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select * @throws PEAR_Error * @see load() */ - function loadArray($arr, $values = null) + public function loadArray($arr, $values = null) { if (!is_array($arr)) { return PEAR::throwError('Argument 1 of HTML_QuickForm_advmultiselect::' . @@ -1127,71 +1000,4 @@ class HTML_QuickForm_advmultiselect extends HTML_QuickForm_select } 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; - } } diff --git a/main/inc/lib/pear/HTML/QuickForm/button.php b/main/inc/lib/pear/HTML/QuickForm/button.php index 82c3a99667..9c496d47ca 100755 --- a/main/inc/lib/pear/HTML/QuickForm/button.php +++ b/main/inc/lib/pear/HTML/QuickForm/button.php @@ -136,6 +136,10 @@ class HTML_QuickForm_button extends HTML_QuickForm_input */ 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; } diff --git a/main/inc/lib/pear/HTML/QuickForm/checkbox.php b/main/inc/lib/pear/HTML/QuickForm/checkbox.php index c645367358..af96986b12 100755 --- a/main/inc/lib/pear/HTML/QuickForm/checkbox.php +++ b/main/inc/lib/pear/HTML/QuickForm/checkbox.php @@ -140,13 +140,11 @@ class HTML_QuickForm_checkbox extends HTML_QuickForm_input } elseif ($this->_flagFrozen) { $label = $this->_text; } else { - $labelClass = $this->labelClass; - $checkboxClass = $this->checkboxClass; - - $label =' -
-