diff --git a/public/main/inc/lib/myspace.lib.php b/public/main/inc/lib/myspace.lib.php index 93c877949a..2a6140c9ce 100644 --- a/public/main/inc/lib/myspace.lib.php +++ b/public/main/inc/lib/myspace.lib.php @@ -53,10 +53,53 @@ class MySpace ], [ 'url' => api_get_path(WEB_CODE_PATH).'mySpace/survey_report.php', - 'content' => get_lang('SurveyReport'), + 'content' => get_lang('SurveysReport'), + ], + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/tc_report.php', + 'content' => get_lang('TCReport'), + ], + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/ti_report.php', + 'content' => get_lang('TIReport'), + ], + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/question_stats_global.php', + 'content' => get_lang('QuestionStats'), + ], + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/question_stats_global_detail.php', + 'content' => get_lang('QuestionStatsDetailedReport'), ], ]; + $field = new ExtraField('user'); + $companyField = $field->get_handler_field_info_by_field_variable('company'); + if (!empty($companyField)) { + $actions[] = + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=company', + 'content' => get_lang('UserByEntityReport'), + ]; + } + $field = new ExtraField('lp'); + $authorsField = $field->get_handler_field_info_by_field_variable('authors'); + if (!empty($authorsField)) { + $actions[] = + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=learningPath', + 'content' => get_lang('LpByAuthor'), + ]; + } + $field = new ExtraField('lp_item'); + $authorsItemField = $field->get_handler_field_info_by_field_variable('authorlpitem'); + if (!empty($authorsItemField)) { + $actions[] = + [ + 'url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=learningPathByItem', + 'content' => get_lang('LearningPathItemByAuthor'), + ]; + } return Display::actions($actions, null); } @@ -770,6 +813,637 @@ class MySpace } } + /** + * Export to cvs a list of users who were enrolled in the lessons. + * It is necessary that in the extra field, a company is defined. + * + * @param string|null $startDate + * @param string|null $endDate + * + * @return array + */ + public static function exportCompanyResumeCsv($startDate, $endDate) + { + $companys = self::getCompanyLearnpathSubscription($startDate, $endDate); + $csv_content = []; + // Printing table + $total = 0; + $displayText = get_lang('Company'); + // the first line of the csv file with the column headers + $csv_row = []; + $csv_row[] = $displayText; + + $csv_row[] = get_lang('CountOfSubscribedUsers'); + $csv_content[] = $csv_row; + + foreach ($companys as $entity => $student) { + $csv_row = []; + // user official code + $csv_row[] = $entity; + $csv_row[] = count($student); + $total += count($student); + $csv_content[] = $csv_row; + } + + $csv_row = []; + // user official code + $csv_row[] = get_lang('GeneralTotal'); + $csv_row[] = $total; + $csv_content[] = $csv_row; + Export::arrayToCsv($csv_content, 'reporting_company_resume'); + exit; + } + + /** + * Displays a list as a table of users who were enrolled in the lessons. + * It is necessary that in the extra field, a company is defined. + * + * @param string|null $startDate + * @param string|null $endDate + */ + public static function displayResumeCompany( + $startDate = null, + $endDate = null + ) { + $companys = self::getCompanyLearnpathSubscription($startDate, $endDate); + $tableHtml = ''; + // Printing table + $total = 0; + $table = '
'; + + $displayText = get_lang('Company'); + $table .= ""; + + foreach ($companys as $entity => $student) { + $table .= ""; + $total += count($student); + } + $table .= ""; + $table .= '
$displayText ".get_lang('CountOfSubscribedUsers')."
$entity".count($student)."
".get_lang('GeneralTotal')."$total
'; + + if (!empty($startDate) or !empty($endDate)) { + $tableHtml = $table; + } + + $form = new FormValidator('searchDate', 'get'); + $form->addHidden('display', 'company'); + $today = new DateTime(); + if (empty($startDate)) { + $startDate = api_get_local_time($today->modify('first day of this month')->format('Y-m-d')); + } + if (empty($endDate)) { + $endDate = api_get_local_time($today->modify('last day of this month')->format('Y-m-d')); + } + $form->addDatePicker( + 'startDate', + get_lang('DateStart'), + [ + 'value' => $startDate, + ]); + $form->addDatePicker( + 'endDate', + get_lang('DateEnd'), + [ + 'value' => $endDate, + ]); + $form->addButtonSearch(get_lang('Search')); + if (count($companys) != 0) { + //$form->addButtonSave(get_lang('Ok'), 'export'); + $form + ->addButton( + 'export_csv', + get_lang('ExportAsCSV'), + 'check', + 'primary', + null, + null, + [ + ] + ); + } + + $tableContent = $form->returnForm(); + $tableContent .= $tableHtml; + // $tableContent .= $table->return_table(); + + $tpl = new Template('', false, false, false, false, false, false); + $tpl->assign('table', $tableContent); + $templateName = $tpl->get_template('my_space/course_summary.tpl'); + $tpl->display($templateName); + } + + /** + * Displays a list as a table of teachers who are set authors by a extra_field authors. + * + * @param string|null $startDate + * @param string|null $endDate + * @param bool $csv + */ + public static function displayResumeLP( + $startDate = null, + $endDate = null, + $csv = false + ) { + $tableHtml = ''; + $tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD); + $tblExtraFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); + $tblCourse = Database::get_main_table(TABLE_MAIN_COURSE); + $query = " + SELECT + item_id AS lp_id, + REPLACE (s.value, ';', ',') AS users_id + FROM + $tblExtraFieldValue s + INNER JOIN $tblExtraField sf ON (s.field_id = sf.id) + WHERE + field_id IN ( + SELECT + id + FROM + $tblExtraField + WHERE + variable = 'authors' + ) + AND sf.extra_field_type = ".ExtraField::FIELD_TYPE_DATE." + AND (s.value != '' OR s.value IS NOT NULL) +"; + $queryResult = Database::query($query); + $data = []; + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + $lp_id = (int) $row['lp_id']; + $registeredUsers = self::getCompanyLearnpathSubscription($startDate, $endDate, $lp_id); + if (!empty($registeredUsers)) { + $lpInfo = []; + $teacherList = []; + $teachersId = explode(',', trim($row['users_id'], ",")); + $lp_table = Database::get_course_table(TABLE_LP_MAIN); + $query = " + SELECT $lp_table.*, + $tblCourse.title as courseTitle, + $tblCourse.code as courseCode + FROM + $lp_table + INNER JOIN $tblCourse ON $tblCourse.id = $lp_table.c_id + WHERE + $lp_table.iid = $lp_id + "; + $res = Database::query($query); + if (Database::num_rows($res)) { + $lpInfo = Database::fetch_array($res); + } + $studentUsers = []; + for ($i = 0; $i < count($registeredUsers); $i++) { + $studentUsers[] = api_get_user_info($registeredUsers[$i]); + } + $teacherList = []; + for ($i = 0; $i < count($teachersId); $i++) { + $teacherId = $teachersId[$i]; + $teacher = api_get_user_info($teacherId); + $data[$teacher['complete_name']][$lpInfo['name']] = [ + 'students' => count($studentUsers), + 'studentList' => $studentUsers, + 'lpInfo' => $lpInfo, + ]; + $teacherList[] = $teacher; + } + } + } + if ($csv == false) { + $table = "
". + "". + "". + "". + "". + "". + "". + "". + "". + "". + ""; + $index = 0; + //icons for show and hode + $iconAdd = Display::return_icon('add.png', get_lang('ShowOrHide'), '', ICON_SIZE_SMALL); + $iconRemove = Display::return_icon('error.png', get_lang('ShowOrHide'), '', ICON_SIZE_SMALL); + $teacherNameTemp = ''; + foreach ($data as $teacherName => $reportData) { + $lpCount = 0; + $totalStudent = 0; + foreach ($reportData as $lpName => $row) { + $hiddenField = 'student_show_'.$index; + $hiddenFieldLink = 'student_show_'.$index.'_'; + $printTeacherName = ($teacherName == $teacherNameTemp) ? '' : $teacherName; + $lpInfo = $row['lpInfo']; + $teacherNameTemp = $teacherName; + $table .= + "". + "". + "". + "". + "". + ""; + } + $table .= + "". + "". + "". + "". + "". + ""; + } + $table .= "". + "
".get_lang('Author')."".get_lang('LearningPathList')."".get_lang('CountOfSubscribedUsers')."".get_lang('StudentList')."
$printTeacherName$lpName".$row['students']."". + "". + "
$iconAdd
". + "". + "
". + "". + "
".get_lang('LearnpathsTotal')." $lpCount$totalStudent
". + "
"; + if (!empty($startDate) or !empty($endDate)) { + $tableHtml = $table; + } + + $form = new FormValidator('searchDate', 'get'); + $form->addHidden('display', 'learningPath'); + $today = new DateTime(); + if (empty($startDate)) { + $startDate = $today->modify('first day of this month')->format('Y-m-d'); + } + if (empty($endDate)) { + $endDate = $today->modify('last day of this month')->format('Y-m-d'); + } + $form->addDatePicker( + 'startDate', + get_lang('DateStart'), + [ + 'value' => $startDate, + ]); + $form->addDatePicker( + 'endDate', + get_lang('DateEnd'), + [ + 'value' => $endDate, + ]); + $form->addButtonSearch(get_lang('Search')); + if (count($data) != 0) { + //$form->addButtonSave(get_lang('Ok'), 'export'); + $form + ->addButton( + 'export_csv', + get_lang('ExportAsCSV'), + 'check', + 'primary', + null, + null, + [ + ] + ); + } + $tableContent = $form->returnForm(); + $tableContent .= $tableHtml; + $tpl = new Template('', false, false, false, false, false, false); + $tpl->assign('table', $tableContent); + $templateName = $tpl->get_template('my_space/course_summary.tpl'); + $tpl->display($templateName); + } else { + $csv_content = []; + $csv_row = []; + $csv_row[] = get_lang('Author'); + $csv_row[] = get_lang('LearningPathList'); + $csv_row[] = get_lang('CountOfSubscribedUsers'); + $csv_row[] = get_lang('StudentList'); + $csv_content[] = $csv_row; + foreach ($data as $teacherName => $reportData) { + foreach ($reportData as $lpName => $row) { + $csv_row = []; + $csv_row[] = $teacherName; + $csv_row[] = $lpName; + $csv_row[] = $row['students']; + $studentsName = ''; + foreach ($row['studentList'] as $student) { + $studentsName .= $student['complete_name']." / "; + } + $csv_row[] = trim($studentsName, " / "); + $csv_content[] = $csv_row; + } + } + Export::arrayToCsv($csv_content, 'reporting_lp_by_authors'); + } + } + + /** + * Displays a list as a table of teachers who are set authors of lp's item by a extra_field authors. + * + * @param string|null $startDate + * @param string|null $endDate + * @param bool $csv + */ + public static function displayResumeLpByItem( + $startDate = null, + $endDate = null, + $csv = false + ) { + $tableHtml = ''; + $table = ''; + $tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD); + $tblExtraFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); + $extraFieldLpByAutorName = 'authorlpitem'; + $extraFieldLpPrice = 'price'; + + $queryExtraFieldPrice = "SELECT id ". + " FROM $tblExtraField ". + " WHERE variable = '$extraFieldLpPrice'"; + $queryExtraFieldValue = "SELECT id ". + " FROM $tblExtraField ". + " WHERE variable = '$extraFieldLpByAutorName'"; + + // search items of lp + $cLpItemsQuery = "select item_id as lp_item_id ". + " from $tblExtraFieldValue ". + " where field_id IN ( $queryExtraFieldValue ) ". + " group by lp_item_id"; + $queryResult = Database::query($cLpItemsQuery); + $cLpItems = []; + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + $cLpItems[] = (int) $row['lp_item_id']; + } + if (count($cLpItems) == 0) { + $tableContent = "
". + "". + "". + "". + "". + "". + "". + "". + "". + "
".get_lang('NoDataAvailable')."
". + "
"; + $tableHtml = $tableContent; + } else { + $cLpItems = implode(',', $cLpItems); + // search by price + $cLpItemsPriceQuery = "select value as price, item_id as lp_item_id ". + " from $tblExtraFieldValue ". + " where field_id IN ( $queryExtraFieldPrice ) and item_id in ($cLpItems)"; + $queryResult = Database::query($cLpItemsPriceQuery); + $lpItemPrice = []; + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + $lpItemPrice[$row['lp_item_id']] = $row['price']; + } + // search authors of lp + $autorsStr = ''; + $autorsQuery = "select value as users_id ". + " from $tblExtraFieldValue ". + " where field_id IN ( $queryExtraFieldValue ) ". + " group by users_id "; + $queryResult = Database::query($autorsQuery); + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + $autorsStr .= " ".str_replace(';', ' ', $row['users_id']); + $autorsStr = trim($autorsStr); + } + $autorsStr = str_replace(' ', ',', $autorsStr); + + //search autors detailed + $authors = []; + if (!empty($autorsStr)) { + $autorsStr = explode(',', $autorsStr); + foreach ($autorsStr as $item) { + $authors[$item] = api_get_user_info($item); + } + } + unset($autorsStr); + + //search info of lp's items + $cLpItemsData = []; + if (!empty($cLpItems)) { + $query = "select * ". + " from c_lp_item ". + " where iid in ($cLpItems)"; + $queryResult = Database::query($query); + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + $row['price'] = isset($lpItemPrice[$row['iid']]) ? $lpItemPrice[$row['iid']] : 0; + $cLpItemsData[$row['iid']] = $row; + } + } + + $query = "select item_id as lp_item_id ,value as users_id ". + " from $tblExtraFieldValue ". + " where field_id IN ( $queryExtraFieldValue )"; + $queryResult = Database::query($query); + $printData = []; + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + $cLpItem = (int) $row['lp_item_id']; + // get full lp data + $cLpItemData = isset($cLpItemsData[$cLpItem]) ? $cLpItemsData[$cLpItem] : []; + $authorData = $row['users_id']; + if (!empty($authorData)) { + if (strpos($authorData, ";") === false) { + $printData[(int) $authorData][$cLpItem] = $cLpItemData; + } else { + foreach (explode(';', $authorData) as $item) { + $printData[$item][$cLpItem] = $cLpItemData; + } + } + } + } + $index = 0; + } + if ($csv == false) { + if (empty($tableHtml)) { + $table .= "
". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + "". + ""; + //Icon Constant + $iconAdd = Display::return_icon('add.png', get_lang('ShowOrHide'), '', ICON_SIZE_SMALL); + $iconRemove = Display::return_icon('error.png', get_lang('ShowOrHide'), '', ICON_SIZE_SMALL); + + $lastAuthor = ''; + $total = 0; + foreach ($printData as $authorId => $lpItemData) { + $autor = $authors[$authorId]; + $totalSudent = 0; + foreach ($lpItemData as $lpItemId => $lpitem) { + $title = $lpitem['title']; + $price = $lpitem['price']; + $hide = "class='author_$authorId hidden' "; + if ($lastAuthor != $autor) { + $table .= ""; + $table .= ""; + } else { + $table .= ""; + $table .= ""; + } + + $hiddenField = 'student_show_'.$index; + $hiddenFieldLink = 'student_show_'.$index.'_'; + if ($lastAuthor != $autor) { + $table .= ""; + } else { + $table .= ""; + } + $table .= ""; + $registeredUsers = self::getCompanyLearnpathSubscription($startDate, $endDate, $lpitem['lp_id'], true); + $studenRegister = count($registeredUsers); + $table .= ""; + $facturar = ($studenRegister * $price); + $table .= ""; + $total += $facturar; + $totalSudent += $studenRegister; + if ($studenRegister != 0) { + $table .= ""; + } else { + $table .= ""; + } + $table .= ""; + $lastAuthor = $autor; + } + //footer + $table .= "". + "". + "". + "". + "". + ""; + $total = 0; + } + $table .= "". + "
".get_lang('Author')."".get_lang('ContentList')."".get_lang('Tariff')."".get_lang('CountOfSubscribedUsers')."".get_lang('ToInvoice')."".get_lang('StudentList')."
".$autor['complete_name']. + "
$title". + "$title$price$studenRegister$facturar". + "". + "
$iconAdd
". + "". + "
". + "". + "
". + "". + "
$iconAdd
". + "". + "
"."
$totalSudent$total
". + "
"; + $tableHtml = $table; + } + + $form = new FormValidator('searchDate', 'get'); + $form->addHidden('display', 'learningPathByItem'); + $today = new DateTime(); + if (empty($startDate)) { + $startDate = $today->modify('first day of this month')->format('Y-m-d'); + } + if (empty($endDate)) { + $endDate = $today->modify('last day of this month')->format('Y-m-d'); + } + $form->addDatePicker( + 'startDate', + get_lang('DateStart'), + [ + 'value' => $startDate, + ]); + $form->addDatePicker( + 'endDate', + get_lang('DateEnd'), + [ + 'value' => $endDate, + ]); + $form->addButtonSearch(get_lang('Search')); + + if (count($printData) != 0) { + //$form->addButtonSave(get_lang('Ok'), 'export'); + $form + ->addButton( + 'export_csv', + get_lang('ExportAsCSV'), + 'check', + 'primary', + null, + null, + [ + ] + ); + } + $tableContent = $form->returnForm(); + $tableContent .= $tableHtml; + $tpl = new Template('', false, false, false, false, false, false); + $tpl->assign('table', $tableContent); + $templateName = $tpl->get_template('my_space/course_summary.tpl'); + $tpl->display($templateName); + } else { + $csv_content = []; + $csv_row = []; + + $csv_row[] = get_lang('Author'); + $csv_row[] = get_lang('ContentList'); + $csv_row[] = get_lang('Tariff'); + $csv_row[] = get_lang('CountOfSubscribedUsers'); + $csv_row[] = get_lang('ToInvoice'); + $csv_row[] = get_lang('StudentList'); + $csv_content[] = $csv_row; + foreach ($printData as $authorId => $lpItemData) { + $autor = $authors[$authorId]; + foreach ($lpItemData as $lpItemId => $lpitem) { + $title = $lpitem['title']; + $price = $lpitem['price']; + + $csv_row = []; + $csv_row[] = $autor['complete_name']; + $csv_row[] = $title; + $csv_row[] = $price; + $registeredUsers = self::getCompanyLearnpathSubscription($startDate, $endDate, $lpitem['lp_id'], true); + $studenRegister = count($registeredUsers); + $csv_row[] = $studenRegister; + $facturar = ($studenRegister * $price); + $csv_row[] = $facturar; + $totalSudent += $studenRegister; + if ($studenRegister != 0) { + $studentsName = ''; + for ($i = 0; $i < $studenRegister; $i++) { + $tempStudent = api_get_user_info($registeredUsers[$i]['id']); + $studentsName .= $tempStudent['complete_name']." (".$registeredUsers[$i]['company'].") / "; + + $totalStudent++; + } + $csv_row[] = trim($studentsName, " / "); + $csv_content[] = $csv_row; + $index++; + $lpCount++; + } + } + } + Export::arrayToCsv($csv_content, 'reporting_lp_by_authors'); + } + } + /** * Display a sortable table that contains an overview of all the reporting progress of all courses. */ @@ -2455,8 +3129,13 @@ class MySpace * @param int $sessionId * @param int $studentId */ - public static function displayTrackingAccessOverView($courseId, $sessionId, $studentId) - { + public static function displayTrackingAccessOverView( + $courseId, + $sessionId, + $studentId, + $perPage = 20, + $dates = null + ) { $courseId = (int) $courseId; $sessionId = (int) $sessionId; $studentId = (int) $studentId; @@ -2558,9 +3237,8 @@ class MySpace true, [ 'id' => 'date_range', - 'format' => 'YYYY-MM-DD', - 'timePicker' => 'false', - 'validate_format' => 'Y-m-d', + 'format' => 'YYYY-MM-DD HH:mm', + 'timePicker' => 'true', ] ); $form->addHidden('display', 'accessoverview'); @@ -2569,26 +3247,36 @@ class MySpace $form->addButton('submit', get_lang('Generate'), 'gear', 'primary'); $table = null; + if (!empty($dates)) { - if ($form->validate()) { $table = new SortableTable( 'tracking_access_overview', ['MySpace', 'getNumberOfTrackAccessOverview'], ['MySpace', 'getUserDataAccessTrackingOverview'], - 0 + 0, + $perPage + ); + $table->set_additional_parameters( + [ + 'course_id' => $courseId, + 'session_id' => $sessionId, + 'student_id' => $studentId, + 'date' => $dates, + 'tracking_access_overview_per_page' => $perPage, + 'display' => 'accessoverview', + ] ); - $table->set_header(0, get_lang('Login date'), true); + $table->set_header(0, get_lang('LoginDate'), true); $table->set_header(1, get_lang('Username'), true); if (api_is_western_name_order()) { - $table->set_header(2, get_lang('First name'), true); - $table->set_header(3, get_lang('Last name'), true); + $table->set_header(2, get_lang('FirstName'), true); + $table->set_header(3, get_lang('LastName'), true); } else { - $table->set_header(2, get_lang('Last name'), true); - $table->set_header(3, get_lang('First name'), true); + $table->set_header(2, get_lang('LastName'), true); + $table->set_header(3, get_lang('FirstName'), true); } - $table->set_header(4, get_lang('clicks'), false); - $table->set_header(5, get_lang('IP'), false); - $table->set_header(6, get_lang('Time connected (hh:mm)'), false); + $table->set_header(4, get_lang('IP'), false); + $table->set_header(5, get_lang('TimeLoggedIn'), false); } $template = new Template( @@ -2618,7 +3306,11 @@ class MySpace $result = Database::query($sql); $row = Database::fetch_assoc($result); - return $row['count']; + if ($row) { + return $row['count']; + } + + return 0; } /** @@ -2643,7 +3335,7 @@ class MySpace $user = Database::get_main_table(TABLE_MAIN_USER); $course = Database::get_main_table(TABLE_MAIN_COURSE); $track_e_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $track_e_course_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $trackCourseAccess = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); global $export_csv; $is_western_name_order = api_is_western_name_order(); @@ -2664,42 +3356,20 @@ class MySpace u.firstname AS col3, " )." + a.login_course_date, a.logout_course_date, c.title, c.code, - u.user_id - FROM $track_e_course_access a - INNER JOIN $user u ON a.user_id = u.user_id - INNER JOIN $course c ON a.c_id = c.id + u.id as user_id, + user_ip + FROM $trackCourseAccess a + INNER JOIN $user u + ON a.user_id = u.id + INNER JOIN $course c + ON a.c_id = c.id WHERE 1=1 "; - if (isset($_GET['course_id']) && !empty($_GET['course_id'])) { - $courseId = (int) $_GET['course_id']; - $sql .= " AND c.id = ".$courseId; - } - - if (isset($_GET['session_id']) && !empty($_GET['session_id'])) { - $sessionId = (int) $_GET['session_id']; - $sql .= " AND a.session_id = ".$sessionId; - } - - if (isset($_GET['student_id']) && !empty($_GET['student_id'])) { - $userId = (int) $_GET['student_id']; - $sql .= " AND u.user_id = ".$userId; - } - - if (isset($_GET['date']) && !empty($_GET['date'])) { - $dateRangePicker = new DateRangePicker('date'); - $dates = $dateRangePicker->parseDateRange($_GET['date']); - if (isset($dates['start']) && !empty($dates['start'])) { - $dates['start'] = Database::escape_string($dates['start']); - $sql .= " AND login_course_date >= '".$dates['start']."'"; - } - if (isset($dates['end']) && !empty($dates['end'])) { - $dates['end'] = Database::escape_string($dates['end']); - $sql .= " AND logout_course_date <= '".$dates['end']."'"; - } - } + $sql = self::getDataAccessTrackingFilters($sql); $sql .= " ORDER BY col$column $orderDirection "; $sql .= " LIMIT $from,$numberItems"; @@ -2714,33 +3384,16 @@ class MySpace $return = []; //TODO: Dont use numeric index foreach ($data as $key => $info) { - $start_date = $info['col0']; - $end_date = $info['logout_course_date']; - - $return[$info['user_id']] = [ - $start_date, + $return[] = [ + api_get_local_time($info['login_course_date']), $info['col1'], $info['col2'], $info['col3'], - $info['user_id'], - 'ip', - //TODO is not correct/precise, it counts the time not logged between two loggins - gmdate("H:i:s", strtotime($end_date) - strtotime($start_date)), + $info['user_ip'], + gmdate('H:i:s', strtotime($info['logout_course_date']) - strtotime($info['login_course_date'])), ]; } - foreach ($return as $key => $info) { - $ipResult = Database::select( - 'user_ip', - $track_e_login, - ['where' => [ - '? BETWEEN login_date AND logout_date' => $info[0], - ]], - 'first' - ); - - $return[$key][5] = $ipResult['user_ip']; - } return $return; } @@ -3098,4 +3751,176 @@ class MySpace ); } } + + /** + * Gets a list of users who were enrolled in the lessons. + * It is necessary that in the extra field, a company is defined. + * + * if lpId is different to 0, this search by lp id too + * + * @param string|null $startDate + * @param string|null $endDate + * @param int $lpId + * @param bool $whitCompany + * + * @return array + */ + protected static function getCompanyLearnpathSubscription( + $startDate = null, + $endDate = null, + $lpId = 0, + $whitCompany = false + ) { + $tblItemProperty = Database::get_course_table(TABLE_ITEM_PROPERTY); + $tblLp = Database::get_course_table(TABLE_LP_MAIN); + $tblExtraField = Database::get_main_table(TABLE_EXTRA_FIELD); + $tblExtraFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES); + + $whereCondition = ''; + + //Validating dates + if (!empty($startDate)) { + $startDate = new DateTime($startDate); + } + if (!empty($endDate)) { + $endDate = new DateTime($endDate); + } + if (!empty($startDate) and !empty($endDate)) { + if ($startDate > $endDate) { + $dateTemp = $endDate; + $endDate = $startDate; + $startDate = $dateTemp; + unset($dateTemp); + } + } + + // Settings condition and parametter GET to right date + if (!empty($startDate)) { + $startDate = api_get_utc_datetime($startDate->setTime(0, 0, 0)->format('Y-m-d H:i:s')); + $_GET['startDate'] = $startDate; + $whereCondition .= " + AND $tblItemProperty.lastedit_date >= '$startDate' "; + } + if (!empty($endDate)) { + $endDate = api_get_utc_datetime($endDate->setTime(23, 59, 59)->format('Y-m-d H:i:s')); + $_GET['endDate'] = $endDate; + $whereCondition .= " + AND $tblItemProperty.lastedit_date <= '$endDate' "; + } + if ($lpId != 0) { + $whereCondition .= " + AND c_item_property.ref = $lpId "; + } + + $companys = []; + if (!empty($startDate) or !empty($endDate)) { + // get Compnay data + $selectToCompany = " ( + SELECT + value + FROM + $tblExtraFieldValue + WHERE + field_id IN ( + SELECT + id + FROM + $tblExtraField + WHERE + variable = 'company' + ) + AND item_id = $tblItemProperty.to_user_id + ) "; + $query = " + SELECT + * , + $selectToCompany as company, + ( + SELECT + name + FROM + $tblLp + WHERE + $tblLp.iid = c_item_property.ref + ) as name_lp + FROM + $tblItemProperty + WHERE + c_id IN ( + SELECT + c_id + FROM + ".TABLE_MAIN_COURSE_USER." + WHERE + STATUS = 5 + ) + AND lastedit_type = 'LearnpathSubscription' + + "; + // -- AND $selectToCompany IS NOT NULL + if (strlen($whereCondition) > 2) { + $query .= $whereCondition; + } + $queryResult = Database::query($query); + while ($row = Database::fetch_array($queryResult, 'ASSOC')) { + // $courseId = (int)$row['c_id']; + $studentId = (int) $row['to_user_id']; + $company = isset($row['company']) ? $row['company'] : ''; + if ($company == '') { + $company = get_lang('NoEntity'); + } + // $lpId = $row['ref']; + if ($lpId != 0 && $studentId != 0) { + if ($whitCompany == true) { + $companys[] = [ + 'id' => $studentId, + 'company' => $company, + ]; + } else { + $companys[] = $studentId; + } + } else { + $companys[$company][] = $studentId; + $companys[$company] = array_unique($companys[$company]); + } + } + } + + return $companys; + } + + private static function getDataAccessTrackingFilters($sql) + { + if (isset($_GET['course_id']) && !empty($_GET['course_id'])) { + $courseId = (int) $_GET['course_id']; + $sql .= " AND c.id = ".$courseId; + } + + if (isset($_GET['session_id']) && !empty($_GET['session_id'])) { + $sessionId = (int) $_GET['session_id']; + $sql .= " AND a.session_id = ".$sessionId; + } + + if (isset($_GET['student_id']) && !empty($_GET['student_id'])) { + $userId = (int) $_GET['student_id']; + $sql .= " AND u.user_id = ".$userId; + } + + $sql .= " AND u.status <> ".ANONYMOUS; + + if (isset($_GET['date']) && !empty($_GET['date'])) { + $dateRangePicker = new DateRangePicker('date', '', ['timePicker' => 'true']); + $dates = $dateRangePicker->parseDateRange($_GET['date']); + if (isset($dates['start']) && !empty($dates['start'])) { + $dates['start'] = Database::escape_string(api_get_utc_datetime($dates['start'])); + $sql .= " AND login_course_date >= '".$dates['start']."'"; + } + if (isset($dates['end']) && !empty($dates['end'])) { + $dates['end'] = Database::escape_string(api_get_utc_datetime($dates['end'])); + $sql .= " AND logout_course_date <= '".$dates['end']."'"; + } + } + + return $sql; + } } diff --git a/public/main/inc/lib/pdf.lib.php b/public/main/inc/lib/pdf.lib.php index 3db1cce350..ab37dd2530 100644 --- a/public/main/inc/lib/pdf.lib.php +++ b/public/main/inc/lib/pdf.lib.php @@ -751,13 +751,12 @@ class PDF $this->pdf->showWatermarkImage = true; } } - if ($courseCode) { - $watermark_text = api_get_course_setting('pdf_export_watermark_text'); - if (empty($watermark_text)) { - $watermark_text = api_get_setting('pdf_export_watermark_text'); + $watermark_text = api_get_setting('pdf_export_watermark_text'); + if ($courseCode && 'true' === api_get_setting('pdf_export_watermark_by_course')) { + $courseWaterMark = api_get_course_setting('pdf_export_watermark_text'); + if (!empty($courseWaterMark) && -1 != $courseWaterMark) { + $watermark_text = $courseWaterMark; } - } else { - $watermark_text = api_get_setting('pdf_export_watermark_text'); } if (!empty($watermark_text)) { $this->pdf->SetWatermarkText( diff --git a/public/main/inc/lib/plugin.class.php b/public/main/inc/lib/plugin.class.php index 3e9963b46b..441be9c281 100644 --- a/public/main/inc/lib/plugin.class.php +++ b/public/main/inc/lib/plugin.class.php @@ -455,6 +455,37 @@ class Plugin return get_lang($name); } + /** + * @param string $variable + * @param string $language + * + * @return string + */ + public function getLangFromFile($variable, $language) + { + static $langStrings = []; + + if (empty($langStrings[$language])) { + $root = api_get_path(SYS_PLUGIN_PATH); + $pluginName = $this->get_name(); + + $englishPath = "$root$pluginName/lang/$language.php"; + + if (is_readable($englishPath)) { + $strings = []; + include $englishPath; + + $langStrings[$language] = $strings; + } + } + + if (isset($langStrings[$language][$variable])) { + return $langStrings[$language][$variable]; + } + + return $this->get_lang($variable); + } + /** * Caller for the install_course_fields() function. * diff --git a/public/main/inc/lib/plugin.lib.php b/public/main/inc/lib/plugin.lib.php index f206ee22a4..c3eecfa552 100644 --- a/public/main/inc/lib/plugin.lib.php +++ b/public/main/inc/lib/plugin.lib.php @@ -170,6 +170,111 @@ class AppPlugin return $installedPlugins; } + public function getInstalledPluginsInCurrentUrl() + { + $installedPlugins = []; + $urlId = api_get_current_access_url_id(); + $plugins = api_get_settings_params( + [ + 'variable = ? AND selected_value = ? AND category = ? AND access_url = ?' => ['status', 'installed', 'Plugins', $urlId], + ] + ); + + if (!empty($plugins)) { + foreach ($plugins as $row) { + $installedPlugins[$row['subkey']] = true; + } + $installedPlugins = array_keys($installedPlugins); + } + + return $installedPlugins; + } + + /** + * Returns a list of all official (delivered with the Chamilo package) + * plugins. This list is maintained manually and updated with every new + * release to avoid hacking. + * + * @return array + */ + public function getOfficialPlugins() + { + static $officialPlugins = null; + // Please keep this list alphabetically sorted + $officialPlugins = [ + 'add_cas_login_button', + 'add_cas_logout_button', + 'add_facebook_login_button', + 'add_shibboleth_login_button', + 'advanced_subscription', + 'azure_active_directory', + 'bbb', + 'before_login', + 'buycourses', + 'card_game', + 'check_extra_field_author_company', + 'cleandeletedfiles', + 'clockworksms', + 'courseblock', + 'coursehomenotify', + 'courselegal', + 'createdrupaluser', + 'customcertificate', + 'customfooter', + 'dashboard', + 'date', + 'dictionary', + 'embedregistry', + 'exercise_signature', + 'ext_auth_chamilo_logout_button_behaviour', + 'follow_buttons', + 'formLogin_hide_unhide', + 'google_maps', + 'google_meet', + 'grading_electronic', + 'h5p', + 'hello_world', + 'ims_lti', + 'jcapture', + 'justification', + 'kannelsms', + 'keycloak', + 'learning_calendar', + 'maintenancemode', + 'migrationmoodle', + 'mindmap', + 'nosearchindex', + 'notebookteacher', + 'oauth2', + 'olpc_peru_filter', + 'openmeetings', + 'pausetraining', + 'pens', + 'positioning', + 'questionoptionsevaluation', + 'redirection', + 'reports', + 'resubscription', + 'rss', + 'search_course', + 'sepe', + 'share_buttons', + 'show_regions', + 'show_user_info', + 'static', + 'studentfollowup', + 'surveyexportcsv', + 'surveyexporttxt', + 'test2pdf', + 'tour', + 'userremoteservice', + 'vchamilo', + 'whispeakauth', + 'zoom', + ]; + + return $officialPlugins; + } /** * @param string $pluginName * @param int $urlId @@ -489,13 +594,14 @@ class AppPlugin */ public function removeAllRegions($plugin) { + $access_url_id = api_get_current_access_url_id(); if (!empty($plugin)) { api_delete_settings_params( [ 'category = ? AND type = ? AND access_url = ? AND subkey = ? ' => [ 'Plugins', 'region', - api_get_current_access_url_id(), + $access_url_id, $plugin, ], ] @@ -641,6 +747,12 @@ class AppPlugin ); if (isset($setting['init_value']) && 1 == $setting['init_value']) { $element->setChecked(true); + } + } + } + + if (isset($setting['init_value']) && $setting['init_value'] == 1) { + $element->setChecked(true); } $form->addElement($element); diff --git a/public/main/inc/lib/sessionmanager.lib.php b/public/main/inc/lib/sessionmanager.lib.php index fa02f6430c..e9861f8449 100644 --- a/public/main/inc/lib/sessionmanager.lib.php +++ b/public/main/inc/lib/sessionmanager.lib.php @@ -2574,6 +2574,7 @@ class SessionManager * existing courses and users (true, default) or not (false) * @param bool $copyEvaluation from base course to session course * @param bool $copyCourseTeachersAsCoach + * @param bool $importAssignments * * @throws Exception * @@ -2584,7 +2585,8 @@ class SessionManager $courseList, $removeExistingCoursesWithUsers = true, $copyEvaluation = false, - $copyCourseTeachersAsCoach = false + $copyCourseTeachersAsCoach = false, + $importAssignments = false ) { $sessionId = (int) $sessionId; @@ -2592,6 +2594,10 @@ class SessionManager return false; } + if ($importAssignments) { + require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php'; + } + $session = api_get_session_entity($sessionId); if (!$session) { @@ -2773,6 +2779,34 @@ class SessionManager } } + if ($importAssignments) { + $workTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION); + $sql = " SELECT * FROM $workTable + WHERE active = 1 AND + c_id = $courseId AND + parent_id = 0 AND + (session_id IS NULL OR session_id = 0)"; + $result = Database::query($sql); + $workList = Database::store_result($result, 'ASSOC'); + + foreach ($workList as $work) { + $values = [ + 'work_title' => $work['title'], + 'new_dir' => $work['url'].'_session_'.$sessionId, + 'description' => $work['description'], + 'qualification' => $work['qualification'], + 'allow_text_assignment' => $work['allow_text_assignment'], + ]; + + addDir( + $values, + api_get_user_id(), + $courseInfo, + 0, + $sessionId + ); + } + } // If the course isn't subscribed yet $sql = "INSERT INTO $tbl_session_rel_course (session_id, c_id, nbr_users, position) VALUES ($sessionId, $courseId, 0, 0)"; @@ -3303,9 +3337,8 @@ class SessionManager foreach ($conditions as $field => $options) { $operator = strtolower($options['operator']); $value = Database::escape_string($options['value']); - $sql_query .= ' AND '; if (in_array($field, $availableFields) && in_array($operator, $availableOperator)) { - $sql_query .= $field." $operator '".$value."'"; + $sql_query .= ' AND '.$field." $operator '".$value."'"; } } } diff --git a/public/main/inc/lib/sortable_table.class.php b/public/main/inc/lib/sortable_table.class.php index 65a346f96e..8bf3ffec3a 100644 --- a/public/main/inc/lib/sortable_table.class.php +++ b/public/main/inc/lib/sortable_table.class.php @@ -142,7 +142,7 @@ class SortableTable extends HTML_Table if (empty($attributes)) { $attributes = []; - $attributes['class'] = 'table table-bordered data_table'; + $attributes['class'] = 'table table-hover table-striped table-bordered data_table'; $attributes['id'] = $table_id; } @@ -169,22 +169,30 @@ class SortableTable extends HTML_Table $this->per_page = Session::read($this->param_prefix.'per_page', $default_items_per_page); // If per page changed, then reset the page to 1 - if (!empty($this->per_page) && isset($_GET[$this->param_prefix.'per_page']) && $this->per_page != $_GET[$this->param_prefix.'per_page']) { + if (!empty($this->per_page) && isset($_GET[$this->param_prefix.'per_page']) && + $this->per_page != $_GET[$this->param_prefix.'per_page'] + ) { Session::erase($this->param_prefix.'page_nr'); $_GET[$this->param_prefix.'page_nr'] = 1; } - $this->per_page = isset($_GET[$this->param_prefix.'per_page']) ? (int) $_GET[$this->param_prefix.'per_page'] : $this->per_page; + $this->per_page = isset($_GET[$this->param_prefix.'per_page']) + ? (int) $_GET[$this->param_prefix.'per_page'] + : $this->per_page; if (isset($_GET[$this->param_prefix.'per_page'])) { Session::erase($this->param_prefix.'page_nr'); } $this->page_nr = Session::read($this->param_prefix.'page_nr', 1); - $this->page_nr = isset($_GET[$this->param_prefix.'page_nr']) ? (int) $_GET[$this->param_prefix.'page_nr'] : $this->page_nr; + $this->page_nr = isset($_GET[$this->param_prefix.'page_nr']) + ? (int) $_GET[$this->param_prefix.'page_nr'] + : $this->page_nr; $this->column = Session::read($this->param_prefix.'column', $default_column); - $this->column = isset($_GET[$this->param_prefix.'column']) ? (int) $_GET[$this->param_prefix.'column'] : $this->column; + $this->column = isset($_GET[$this->param_prefix.'column']) + ? (int) $_GET[$this->param_prefix.'column'] + : $this->column; // Default direction. if (in_array(strtoupper($default_order_direction), ['ASC', 'DESC'])) { @@ -215,6 +223,8 @@ class SortableTable extends HTML_Table $this->direction = 'DESC'; } } + } else { + $this->direction = 'ASC'; } Session::write($this->param_prefix.'per_page', $this->per_page); diff --git a/public/main/inc/lib/statistics.lib.php b/public/main/inc/lib/statistics.lib.php index f970d9dbf8..46d788d9c4 100644 --- a/public/main/inc/lib/statistics.lib.php +++ b/public/main/inc/lib/statistics.lib.php @@ -475,8 +475,8 @@ class Statistics $isFileSize = false ) { $total = 0; - $content = ' - '; + $content = '
'.$title.'
+ '; $i = 0; foreach ($stats as $subtitle => $number) { $total += $number; @@ -500,13 +500,16 @@ class Statistics $content .= ''; $i++; } + $content .= ''; if ($showTotal) { if (!$isFileSize) { $total_label = number_format($total, 0, ',', '.'); } else { $total_label = self::makeSizeString($total); } - $content .= ''; + $content .= ' + + '; } $content .= '
'.$title.'
'.get_lang('Total').': '.$total_label.'
'.get_lang('Total').': '.$total_label.'
'; diff --git a/public/main/inc/lib/system_announcements.lib.php b/public/main/inc/lib/system_announcements.lib.php index f002ee00a9..b12d3ee7ae 100644 --- a/public/main/inc/lib/system_announcements.lib.php +++ b/public/main/inc/lib/system_announcements.lib.php @@ -141,7 +141,7 @@ class SystemAnnouncementManager $user_id = '' ) { $user_selected_language = api_get_interface_language(); - $start = intval($start); + $start = (int) $start; $userGroup = new UserGroup(); $tbl_announcement_group = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(), 0); diff --git a/public/main/inc/lib/text.lib.php b/public/main/inc/lib/text.lib.php index 3ad067c8e0..28173026cf 100644 --- a/public/main/inc/lib/text.lib.php +++ b/public/main/inc/lib/text.lib.php @@ -417,14 +417,6 @@ function domesticate($input) } /** - * function make_clickable($string). - * - * @desc Completes url contained in the text with " 0) { + $value = Database::fetch_array($rs); + if (isset($value['max']) && !empty($value['max'])) { + $lastConnection = api_strtotime($value['max'], 'UTC'); + } + } + + if (!empty($lastConnection)) { + return $lastConnection; + } + } if (!empty($course)) { - $course_id = $course['real_id']; $lp_table = Database::get_course_table(TABLE_LP_MAIN); $t_lpv = Database::get_course_table(TABLE_LP_VIEW); $t_lpiv = Database::get_course_table(TABLE_LP_ITEM_VIEW); diff --git a/public/main/inc/lib/urlmanager.lib.php b/public/main/inc/lib/urlmanager.lib.php index 57a37caf5a..30d09562be 100644 --- a/public/main/inc/lib/urlmanager.lib.php +++ b/public/main/inc/lib/urlmanager.lib.php @@ -804,7 +804,7 @@ class UrlManager $count = self::relation_url_course_exist($courseId, $urlId); if (empty($count)) { $sql = "INSERT INTO $table - SET c_id = '".intval($courseId)."', access_url_id = ".intval($urlId); + SET c_id = ".intval($courseId).", access_url_id = ".intval($urlId); Database::query($sql); } @@ -1217,9 +1217,8 @@ class UrlManager ON (url_rel_user.access_url_id = u.id) WHERE user_id = ".intval($user_id); $result = Database::query($sql); - $url_list = Database::store_result($result, 'ASSOC'); - return $url_list; + return Database::store_result($result, 'ASSOC'); } /** @@ -1231,15 +1230,35 @@ class UrlManager { $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $table_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL); + $courseId = (int) $courseId; $sql = "SELECT url, access_url_id FROM $table c INNER JOIN $table_url u ON (c.access_url_id = u.id) - WHERE c_id = ".intval($courseId); + WHERE c_id = $courseId"; $result = Database::query($sql); - $url_list = Database::store_result($result, 'ASSOC'); - return $url_list; + return Database::store_result($result, 'ASSOC'); + } + + public static function getCountAccessUrlFromCourse($courseId) + { + $courseId = (int) $courseId; + $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $table_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT count(u.id) count FROM $table c + INNER JOIN $table_url u + ON (c.access_url_id = u.id) + WHERE c_id = $courseId "; + + $result = Database::query($sql); + if ($result) { + $row = Database::fetch_array($result, 'ASSOC'); + + return (int) $row['count']; + } + + return 0; } /** diff --git a/public/main/inc/lib/usermanager.lib.php b/public/main/inc/lib/usermanager.lib.php index 88b44d2b0f..d272da7aa5 100644 --- a/public/main/inc/lib/usermanager.lib.php +++ b/public/main/inc/lib/usermanager.lib.php @@ -813,6 +813,7 @@ class UserManager $extraFieldValue = new ExtraFieldValue('user'); $extraFieldValue->deleteValuesByItem($user_id); + UrlManager::deleteUserFromAllUrls($user_id); //UrlManager::deleteUserFromAllUrls($user_id); if ('true' === api_get_setting('allow_social_tool')) { @@ -1178,6 +1179,7 @@ class UserManager } $userManager->updateUser($user, true); + Event::addEvent(LOG_USER_UPDATE, LOG_USER_ID, $user_id); if (1 == $change_active) { if (1 == $active) { @@ -3054,30 +3056,34 @@ class UserManager $sessionData = []; // First fill $sessionData with student sessions + if (!empty($sessionDataStudent)) { foreach ($sessionDataStudent as $row) { $sessionData[$row['id']] = $row; } + } // Overwrite session data of the user as a student with session data // of the user as a coach. // There shouldn't be such duplicate rows, but just in case... + if (!empty($sessionDataCoach)) { foreach ($sessionDataCoach as $row) { $sessionData[$row['id']] = $row; + } } $collapsable = api_get_configuration_value('allow_user_session_collapsable'); $extraField = new ExtraFieldValue('session'); $collapsableLink = api_get_path(WEB_PATH).'user_portal.php?action=collapse_session'; + if (empty($sessionData)) { + return []; + } $categories = []; foreach ($sessionData as $row) { $session_id = $row['id']; $coachList = SessionManager::getCoachesBySession($session_id); $categoryStart = $row['session_category_date_start'] ? $row['session_category_date_start']->format('Y-m-d') : ''; $categoryEnd = $row['session_category_date_end'] ? $row['session_category_date_end']->format('Y-m-d') : ''; - $courseList = self::get_courses_list_by_session( - $user_id, - $session_id - ); + $courseList = self::get_courses_list_by_session($user_id, $session_id); $daysLeft = SessionManager::getDayLeftInSession($row, $user_id); // User portal filters: @@ -3462,10 +3468,12 @@ class UserManager session_rel_course_user table if there are courses registered to our user or not */ $sql = "SELECT DISTINCT + c.title, c.visibility, c.id as real_id, c.code as course_code, - sc.position + sc.position, + c.unsubscribe FROM $tbl_session_course_user as scu INNER JOIN $tbl_session_course sc ON (scu.session_id = sc.session_id AND scu.c_id = sc.c_id) @@ -3498,10 +3506,12 @@ class UserManager if (api_is_allowed_to_create_course()) { $sql = "SELECT DISTINCT + c.title, c.visibility, c.id as real_id, c.code as course_code, - sc.position + sc.position, + c.unsubscribe FROM $tbl_session_course_user as scu INNER JOIN $tbl_session as s ON (scu.session_id = s.id) @@ -4367,16 +4377,6 @@ class UserManager return $row['count']; } while ($row = Database::fetch_array($result, 'ASSOC')) { - if (isset($return[$row['id']]) && - !empty($return[$row['id']]['tag']) - ) { - $url = Display::url( - $row['tag'], - api_get_path(WEB_PATH).'main/social/search.php?q='.$row['tag'], - ['class' => 'tag'] - ); - $row['tag'] = $url; - } $return[$row['id']] = $row; } } @@ -5399,35 +5399,31 @@ class UserManager return $icon_link; } - public static function add_user_as_admin(User $user) + public static function addUserAsAdmin(User $user) { - $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN); if ($user) { $userId = $user->getId(); if (!self::is_admin($userId)) { - $sql = "INSERT INTO $table_admin SET user_id = $userId"; + $table = Database::get_main_table(TABLE_MAIN_ADMIN); + $sql = "INSERT INTO $table SET user_id = $userId"; Database::query($sql); } - $group = Container::$container->get('Chamilo\CoreBundle\Repository\GroupRepository')->findOneBy(['code' => 'ADMIN']); - if ($group) { - $user->addGroup($group); - } + $user->addRole('ROLE_SUPER_ADMIN'); self::getManager()->updateUser($user, true); } } - /** - * @param int $userId - */ - public static function remove_user_admin($userId) + public static function removeUserAdmin(User $user) { - $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN); - $userId = (int) $userId; + $userId = (int) $user->getId(); if (self::is_admin($userId)) { - $sql = "DELETE FROM $table_admin WHERE user_id = $userId"; + $table = Database::get_main_table(TABLE_MAIN_ADMIN); + $sql = "DELETE FROM $table WHERE user_id = $userId"; Database::query($sql); + $user->removeRole('ROLE_SUPER_ADMIN'); + self::getManager()->updateUser($user, true); } } @@ -5524,6 +5520,13 @@ class UserManager foreach ($bossList as $bossId) { $bossId = (int) $bossId; + $bossInfo = api_get_user_info($bossId); + + if (empty($bossInfo)) { + continue; + } + + $bossLanguage = $bossInfo['language']; $sql = "INSERT IGNORE INTO $userRelUserTable (user_id, friend_user_id, relation_type) VALUES ($studentId, $bossId, ".USER_RELATION_TYPE_BOSS.")"; $insertId = Database::query($sql);