You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
268 lines
10 KiB
268 lines
10 KiB
![]()
14 years ago
|
<?php
|
||
|
/* For licensing terms, see /license.txt */
|
||
![]()
7 years ago
|
|
||
|
use Chamilo\CoreBundle\Entity\BranchSync;
|
||
|
use Chamilo\CoreBundle\Entity\Repository\BranchSyncRepository;
|
||
![]()
7 years ago
|
use Chamilo\CoreBundle\Framework\Container;
|
||
![]()
7 years ago
|
use GuzzleHttp\Client;
|
||
![]()
7 years ago
|
use League\Flysystem\Filesystem;
|
||
![]()
7 years ago
|
|
||
![]()
14 years ago
|
/**
|
||
![]()
8 years ago
|
* Responses to AJAX calls.
|
||
![]()
14 years ago
|
*/
|
||
![]()
9 years ago
|
require_once __DIR__.'/../global.inc.php';
|
||
![]()
14 years ago
|
|
||
|
api_protect_admin_script();
|
||
|
|
||
|
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
|
||
|
|
||
|
switch ($action) {
|
||
![]()
12 years ago
|
case 'update_changeable_setting':
|
||
![]()
13 years ago
|
$url_id = api_get_current_access_url_id();
|
||
![]()
12 years ago
|
|
||
|
if (api_is_global_platform_admin() && $url_id == 1) {
|
||
|
if (isset($_GET['id']) && !empty($_GET['id'])) {
|
||
![]()
8 years ago
|
$params = ['variable = ? ' => [$_GET['id']]];
|
||
![]()
12 years ago
|
$data = api_get_settings_params($params);
|
||
![]()
14 years ago
|
if (!empty($data)) {
|
||
![]()
12 years ago
|
foreach ($data as $item) {
|
||
![]()
8 years ago
|
$params = ['id' => $item['id'], 'access_url_changeable' => $_GET['changeable']];
|
||
![]()
12 years ago
|
api_set_setting_simple($params);
|
||
![]()
14 years ago
|
}
|
||
![]()
12 years ago
|
}
|
||
![]()
14 years ago
|
echo '1';
|
||
![]()
12 years ago
|
}
|
||
![]()
14 years ago
|
}
|
||
|
break;
|
||
![]()
12 years ago
|
case 'version':
|
||
![]()
8 years ago
|
// Fix session block when loading admin/index.php and changing page
|
||
|
session_write_close();
|
||
![]()
12 years ago
|
echo version_check();
|
||
|
break;
|
||
![]()
11 years ago
|
case 'get_extra_content':
|
||
![]()
11 years ago
|
$blockName = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
|
||
![]()
11 years ago
|
|
||
![]()
11 years ago
|
if (empty($blockName)) {
|
||
![]()
11 years ago
|
die;
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
/** @var Filesystem $fileSystem */
|
||
|
$fileSystem = Container::$container->get('home_filesystem');
|
||
|
$dir = 'admin/';
|
||
|
|
||
![]()
11 years ago
|
if (api_is_multiple_url_enabled()) {
|
||
|
$accessUrlId = api_get_current_access_url_id();
|
||
|
|
||
![]()
7 years ago
|
if ($accessUrlId != -1) {
|
||
|
$urlInfo = api_get_access_url($accessUrlId);
|
||
|
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
|
||
|
$cleanUrl = str_replace('/', '-', $url);
|
||
|
$dir = "$cleanUrl/admin/";
|
||
![]()
11 years ago
|
}
|
||
![]()
11 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
$filePath = $dir.$blockName.'_extra.html';
|
||
![]()
11 years ago
|
|
||
![]()
7 years ago
|
if ($fileSystem->has($filePath)) {
|
||
|
echo $fileSystem->read($dir.$blockName.'_extra.html');
|
||
![]()
11 years ago
|
}
|
||
|
|
||
![]()
7 years ago
|
break;
|
||
|
case 'get_latest_news':
|
||
|
if (api_get_configuration_value('admin_chamilo_announcements_disable') === true) {
|
||
|
break;
|
||
|
}
|
||
|
|
||
![]()
7 years ago
|
try {
|
||
|
$latestNews = getLatestNews();
|
||
|
$latestNews = json_decode($latestNews, true);
|
||
![]()
7 years ago
|
|
||
![]()
7 years ago
|
echo Security::remove_XSS($latestNews['text'], COURSEMANAGER);
|
||
|
break;
|
||
|
} catch (Exception $e) {
|
||
|
break;
|
||
|
}
|
||
![]()
14 years ago
|
}
|
||
![]()
12 years ago
|
|
||
![]()
12 years ago
|
/**
|
||
![]()
8 years ago
|
* Displays either the text for the registration or the message that the installation is (not) up to date.
|
||
![]()
12 years ago
|
*
|
||
|
* @return string html code
|
||
![]()
8 years ago
|
*
|
||
![]()
12 years ago
|
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
|
||
![]()
8 years ago
|
*
|
||
![]()
12 years ago
|
* @version august 2006
|
||
![]()
8 years ago
|
*
|
||
![]()
12 years ago
|
* @todo have a 6 monthly re-registration
|
||
![]()
12 years ago
|
*/
|
||
![]()
12 years ago
|
function version_check()
|
||
|
{
|
||
![]()
9 years ago
|
$tbl_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
|
||
![]()
12 years ago
|
$sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable = "registered" ';
|
||
![]()
12 years ago
|
$result = Database::query($sql);
|
||
|
$row = Database::fetch_array($result, 'ASSOC');
|
||
|
|
||
|
// The site has not been registered yet.
|
||
|
$return = '';
|
||
|
if ($row['selected_value'] == 'false') {
|
||
![]()
6 years ago
|
$return .= get_lang('In order to enable the automatic version checking you have to register your portal on chamilo.org. The information obtained by clicking this button is only for internal use and only aggregated data will be publicly available (total number of portals, total number of chamilo course, total number of chamilo users, ...) (see <a href="http://www.chamilo.org/stats/">http://www.chamilo.org/stats/</a>. When registering you will also appear on the worldwide list (<a href="http://www.chamilo.org/community.php">http://www.chamilo.org/community.php</a>. If you do not want to appear in this list you have to check the checkbox below. The registration is as easy as it can be: you only have to click this button: <br />');
|
||
![]()
10 years ago
|
$return .= '<form class="version-checking" action="'.api_get_path(WEB_CODE_PATH).'admin/index.php" id="VersionCheck" name="VersionCheck" method="post">';
|
||
![]()
6 years ago
|
$return .= '<label class="checkbox"><input type="checkbox" name="donotlistcampus" value="1" id="checkbox" />'.get_lang('Hide campus from public platforms list');
|
||
|
$return .= '</label><button type="submit" class="btn btn-primary btn-block" name="Register" value="'.get_lang('Enable version check').'" id="register" >'.get_lang('Enable version check').'</button>';
|
||
![]()
12 years ago
|
$return .= '</form>';
|
||
|
check_system_version();
|
||
|
} else {
|
||
|
// site not registered. Call anyway
|
||
|
$return .= check_system_version();
|
||
|
}
|
||
![]()
8 years ago
|
|
||
![]()
12 years ago
|
return $return;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Check if the current installation is up to date
|
||
![]()
8 years ago
|
* The code is borrowed from phpBB and slighlty modified.
|
||
|
*
|
||
![]()
7 years ago
|
* @throws \Exception
|
||
|
* @throws \InvalidArgumentException
|
||
![]()
8 years ago
|
*
|
||
![]()
12 years ago
|
* @return string language string with some layout (color)
|
||
![]()
12 years ago
|
*/
|
||
![]()
12 years ago
|
function check_system_version()
|
||
|
{
|
||
![]()
8 years ago
|
// Check if curl is available.
|
||
|
if (!in_array('curl', get_loaded_extensions())) {
|
||
![]()
6 years ago
|
return '<span style="color:red">'.get_lang('Impossible to contact the version server right now. Please try again later.').'</span>';
|
||
![]()
8 years ago
|
}
|
||
|
|
||
|
$url = 'https://version.chamilo.org';
|
||
|
$options = [
|
||
![]()
8 years ago
|
'verify' => false,
|
||
![]()
8 years ago
|
];
|
||
|
|
||
|
$urlValidated = false;
|
||
![]()
8 years ago
|
|
||
|
try {
|
||
|
$client = new GuzzleHttp\Client();
|
||
|
$res = $client->request('GET', $url, $options);
|
||
|
if ($res->getStatusCode() == '200' || $res->getStatusCode() == '301') {
|
||
|
$urlValidated = true;
|
||
|
}
|
||
|
} catch (Exception $e) {
|
||
![]()
8 years ago
|
}
|
||
![]()
8 years ago
|
|
||
![]()
10 years ago
|
// the chamilo version of your installation
|
||
|
$system_version = trim(api_get_configuration_value('system_version'));
|
||
![]()
12 years ago
|
|
||
![]()
8 years ago
|
if ($urlValidated) {
|
||
![]()
12 years ago
|
// The number of courses
|
||
![]()
11 years ago
|
$number_of_courses = Statistics::countCourses();
|
||
![]()
12 years ago
|
|
||
|
// The number of users
|
||
![]()
11 years ago
|
$number_of_users = Statistics::countUsers();
|
||
![]()
8 years ago
|
$number_of_active_users = Statistics::countUsers(
|
||
|
null,
|
||
|
null,
|
||
|
null,
|
||
|
true
|
||
|
);
|
||
![]()
12 years ago
|
|
||
![]()
12 years ago
|
// The number of sessions
|
||
![]()
7 years ago
|
$number_of_sessions = SessionManager::count_sessions(api_get_current_access_url_id());
|
||
![]()
9 years ago
|
$packager = api_get_configuration_value('packager');
|
||
|
if (empty($packager)) {
|
||
|
$packager = 'chamilo';
|
||
|
}
|
||
![]()
12 years ago
|
|
||
![]()
7 years ago
|
$uniqueId = '';
|
||
|
$entityManager = Database::getManager();
|
||
|
/** @var BranchSyncRepository $branch */
|
||
|
$repository = $entityManager->getRepository('ChamiloCoreBundle:BranchSync');
|
||
|
/** @var BranchSync $branch */
|
||
|
$branch = $repository->getTopBranch();
|
||
|
if (is_a($branch, '\Chamilo\CoreBundle\Entity\BranchSync')) {
|
||
|
$uniqueId = $branch->getUniqueId();
|
||
|
}
|
||
|
|
||
![]()
8 years ago
|
$data = [
|
||
![]()
12 years ago
|
'url' => api_get_path(WEB_PATH),
|
||
|
'campus' => api_get_setting('siteName'),
|
||
![]()
10 years ago
|
'contact' => api_get_setting('emailAdministrator'), // the admin's e-mail, with the only purpose of being able to contact admins to inform about critical security issues
|
||
![]()
12 years ago
|
'version' => $system_version,
|
||
![]()
10 years ago
|
'numberofcourses' => $number_of_courses, // to sum up into non-personal statistics - see https://version.chamilo.org/stats/
|
||
|
'numberofusers' => $number_of_users, // to sum up into non-personal statistics
|
||
|
'numberofactiveusers' => $number_of_active_users, // to sum up into non-personal statistics
|
||
![]()
12 years ago
|
'numberofsessions' => $number_of_sessions,
|
||
![]()
12 years ago
|
//The donotlistcampus setting recovery should be improved to make
|
||
|
// it true by default - this does not affect numbers counting
|
||
|
'donotlistcampus' => api_get_setting('donotlistcampus'),
|
||
|
'organisation' => api_get_setting('Institution'),
|
||
![]()
10 years ago
|
'language' => api_get_setting('platformLanguage'), //helps us know the spread of language usage for campuses, by main language
|
||
|
'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'), //not sure this is necessary...
|
||
|
'ip' => $_SERVER['REMOTE_ADDR'], //the admin's IP address, with the only purpose of trying to geolocate portals around the globe to draw a map
|
||
![]()
9 years ago
|
// Reference to the packager system or provider through which
|
||
|
// Chamilo is installed/downloaded. Packagers can change this in
|
||
|
// the default config file (main/install/configuration.dist.php)
|
||
|
// or in the installed config file. The default value is 'chamilo'
|
||
|
'packager' => $packager,
|
||
![]()
7 years ago
|
'unique_id' => $uniqueId,
|
||
![]()
8 years ago
|
];
|
||
![]()
8 years ago
|
|
||
![]()
11 years ago
|
$version = null;
|
||
![]()
8 years ago
|
$client = new GuzzleHttp\Client();
|
||
|
$url .= '?';
|
||
|
foreach ($data as $k => $v) {
|
||
|
$url .= urlencode($k).'='.urlencode($v).'&';
|
||
![]()
11 years ago
|
}
|
||
![]()
8 years ago
|
$res = $client->request('GET', $url, $options);
|
||
|
if ($res->getStatusCode() == '200') {
|
||
|
$versionData = $res->getHeader('X-Chamilo-Version');
|
||
|
if (isset($versionData[0])) {
|
||
|
$version = trim($versionData[0]);
|
||
![]()
11 years ago
|
}
|
||
![]()
8 years ago
|
}
|
||
![]()
12 years ago
|
|
||
![]()
8 years ago
|
if (version_compare($system_version, $version, '<')) {
|
||
![]()
6 years ago
|
$output = '<span style="color:red">'.get_lang('Your version is not up-to-date').'<br />
|
||
|
'.get_lang('The latest version is').' <b>Chamilo '.$version.'</b>. <br />
|
||
|
'.get_lang('Your version is').' <b>Chamilo '.$system_version.'</b>. <br />'.str_replace('http://www.chamilo.org', '<a href="http://www.chamilo.org">http://www.chamilo.org</a>', get_lang('Please visit our website: http://www.chamilo.org')).'</span>';
|
||
![]()
12 years ago
|
} else {
|
||
![]()
6 years ago
|
$output = '<span style="color:green">'.get_lang('Your version is up-to-date').': Chamilo '.$version.'</span>';
|
||
![]()
12 years ago
|
}
|
||
![]()
12 years ago
|
|
||
![]()
8 years ago
|
return $output;
|
||
![]()
12 years ago
|
}
|
||
|
|
||
![]()
6 years ago
|
return '<span style="color:red">'.get_lang('Impossible to contact the version server right now. Please try again later.').'</span>';
|
||
![]()
12 years ago
|
}
|
||
![]()
7 years ago
|
|
||
|
/**
|
||
|
* Display the latest news from the Chamilo Association for admins.
|
||
|
*
|
||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||
![]()
7 years ago
|
* @throws Exception
|
||
![]()
7 years ago
|
*
|
||
|
* @return string|void
|
||
|
*/
|
||
|
function getLatestNews()
|
||
|
{
|
||
|
$url = 'https://version.chamilo.org/news/latest.php';
|
||
|
|
||
|
$client = new Client();
|
||
|
$response = $client->request(
|
||
|
'GET',
|
||
|
$url,
|
||
|
[
|
||
|
'query' => [
|
||
![]()
7 years ago
|
'language' => api_get_interface_language(),
|
||
![]()
7 years ago
|
],
|
||
|
]
|
||
|
);
|
||
|
|
||
|
if ($response->getStatusCode() !== 200) {
|
||
![]()
6 years ago
|
throw new Exception(get_lang('Deny access'));
|
||
![]()
7 years ago
|
}
|
||
|
|
||
|
return $response->getBody()->getContents();
|
||
|
}
|