Internal - update from 1.11.x

pull/3544/head
Julio Montoya 5 years ago
parent 3245a3750e
commit a02707f649
  1. 965
      public/main/inc/lib/myspace.lib.php
  2. 11
      public/main/inc/lib/pdf.lib.php
  3. 31
      public/main/inc/lib/plugin.class.php
  4. 114
      public/main/inc/lib/plugin.lib.php
  5. 39
      public/main/inc/lib/sessionmanager.lib.php
  6. 20
      public/main/inc/lib/sortable_table.class.php
  7. 9
      public/main/inc/lib/statistics.lib.php
  8. 2
      public/main/inc/lib/system_announcements.lib.php
  9. 8
      public/main/inc/lib/text.lib.php
  10. 35
      public/main/inc/lib/tracking.lib.php
  11. 31
      public/main/inc/lib/urlmanager.lib.php
  12. 63
      public/main/inc/lib/usermanager.lib.php

File diff suppressed because it is too large Load Diff

@ -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(

@ -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.
*

@ -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);

@ -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."'";
}
}
}

@ -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);

@ -475,8 +475,8 @@ class Statistics
$isFileSize = false
) {
$total = 0;
$content = '<table class="data_table" cellspacing="0" cellpadding="3" width="90%">
<tr><th colspan="'.($showTotal ? '4' : '3').'">'.$title.'</th></tr>';
$content = '<table class="table table-hover table-striped data_table" cellspacing="0" cellpadding="3" width="90%">
<thead><tr><th colspan="'.($showTotal ? '4' : '3').'">'.$title.'</th></tr></thead><tbody>';
$i = 0;
foreach ($stats as $subtitle => $number) {
$total += $number;
@ -500,13 +500,16 @@ class Statistics
$content .= '</tr>';
$i++;
}
$content .= '</tbody>';
if ($showTotal) {
if (!$isFileSize) {
$total_label = number_format($total, 0, ',', '.');
} else {
$total_label = self::makeSizeString($total);
}
$content .= '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>';
$content .= '
<tfoot><tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr></tfoot>
';
}
$content .= '</table>';

@ -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);

@ -417,14 +417,6 @@ function domesticate($input)
}
/**
* function make_clickable($string).
*
* @desc Completes url contained in the text with "<a href ...".
* However the function simply returns the submitted text without any
* transformation if it already contains some "<a href:" or "<img src=".
*
* @return text after conversion
*
* @author Rewritten by Nathan Codding - Feb 6, 2001.
* completed by Hugues Peeters - July 22, 2002
*

@ -3346,7 +3346,7 @@ class Tracking
* @param int $lp_id Learning path id
* @param int $session_id
*
* @return int Total time
* @return int last connection timestamp
*/
public static function get_last_connection_time_in_lp(
$student_id,
@ -3355,13 +3355,44 @@ class Tracking
$session_id = 0
) {
$course = api_get_course_info($course_code);
if (empty($course)) {
return 0;
}
$course_id = $course['real_id'];
$student_id = (int) $student_id;
$lp_id = (int) $lp_id;
$session_id = (int) $session_id;
$lastTime = 0;
if (self::minimumTimeAvailable($session_id, $course_id)) {
$sql = "SELECT MAX(date_reg) max
FROM track_e_access_complete
WHERE
user_id = $student_id AND
c_id = $course_id AND
session_id = $session_id AND
tool = 'learnpath' AND
tool_id = $lp_id AND
action = 'view' AND
login_as = 0
ORDER BY date_reg ASC
LIMIT 1";
$rs = Database::query($sql);
$lastConnection = 0;
if (Database::num_rows($rs) > 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);

@ -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;
}
/**

@ -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);

Loading…
Cancel
Save