From 98a32fedf10088913a1b7e81ca3b4f7012c7f4c8 Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Mon, 1 Jul 2013 23:54:31 -0400 Subject: [PATCH 1/5] Added ajax call for Julio Montoya to check the code -refs #6216 --- main/admin/index.php | 90 +----------------- main/inc/ajax/admin.ajax.php | 91 +++++++++++++++++++ .../template/default/admin/settings_index.tpl | 20 +++- 3 files changed, 112 insertions(+), 89 deletions(-) diff --git a/main/admin/index.php b/main/admin/index.php index ddd0036805..bf590177f5 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -295,12 +295,14 @@ if (api_is_platform_admin()) { //Version check $blocks['version_check']['icon'] = Display::return_icon('logo.gif', 'Chamilo.org', array(), ICON_SIZE_SMALL, false); $blocks['version_check']['label'] = get_lang('VersionCheck'); - $blocks['version_check']['extra'] = version_check(); + //$blocks['version_check']['extra'] = version_check(); $blocks['version_check']['search_form'] = null; $blocks['version_check']['items'] = null; } +$admin_ajax_url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php'; $tpl = new Template(); +$tpl->assign('web_admin_ajax_url', $admin_ajax_url); $tpl->assign('blocks', $blocks); $admin_template = $tpl->get_template('admin/settings_index.tpl'); $content = $tpl->fetch($admin_template); @@ -308,35 +310,7 @@ $tpl->assign('content', $content); $tpl->assign('message', $message); $tpl->display_one_col_template(); -/** - * Displays either the text for the registration or the message that the installation is (not) up to date - * - * @return string html code - * @author Patrick Cool , Ghent University - * @version august 2006 - * @todo have a 6monthly re-registration - */ -function version_check() { - $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); - $sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable="registered" '; - $result = Database::query($sql); - $row = Database::fetch_array($result, 'ASSOC'); - - // The site has not been registered yet. - $return = ''; - if ($row['selected_value'] == 'false') { - $return .= get_lang('VersionCheckExplanation'); - $return .= '
'; - $return .= ''; - $return .= '
'; - check_system_version(); - } else { - // site not registered. Call anyway - $return .= check_system_version(); - } - return $return; -} + /** * This setting changes the registration status for the campus @@ -360,62 +334,6 @@ function register_site() { } -/** - * Check if the current installation is up to date - * The code is borrowed from phpBB and slighlty modified - * @author The phpBB Group (the code) - * @author Patrick Cool , Ghent University (the modifications) - * @author Yannick Warnier for the move to HTTP request - * @copyright (C) 2001 The phpBB Group - * @return language string with some layout (color) - */ -function check_system_version() { - global $_configuration; - $system_version = trim($_configuration['system_version']); // the chamilo version of your installation - - if (ini_get('allow_url_fopen') == 1) { - // The number of courses - $number_of_courses = statistics::count_courses(); - - // The number of users - $number_of_users = statistics::count_users(); - $number_of_active_users = statistics::count_users(null,null,null,true); - - $data = array( - 'url' => api_get_path(WEB_PATH), - 'campus' => api_get_setting('siteName'), - 'contact' => api_get_setting('emailAdministrator'), - 'version' => $system_version, - 'numberofcourses' => $number_of_courses, - 'numberofusers' => $number_of_users, - 'numberofactiveusers' => $number_of_active_users, - //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'), - 'language' => api_get_setting('platformLanguage'), - 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'), - ); - - $res = _http_request('version.chamilo.org', 80, '/version.php', $data); - - if ($res !== false) { - $version_info = $res; - - if ($system_version != $version_info) { - $output = '
' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' Chamilo '.$version_info.'. '.get_lang('YourVersionIs').' Chamilo '.$system_version. '. '.str_replace('http://www.chamilo.org', 'http://www.chamilo.org', get_lang('PleaseVisitOurWebsite')).''; - } else { - $output = '
'.get_lang('VersionUpToDate').': Chamilo '.$version_info.''; - } - } else { - $output = '' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . ''; - } - } else { - $output = '' . get_lang('AllowurlfopenIsSetToOff') . ''; - } - return $output; -} - /** * Function to make an HTTP request through fsockopen (specialised for GET) * Derived from Jeremy Saintot: http://www.php.net/manual/en/function.fsockopen.php#101872 diff --git a/main/inc/ajax/admin.ajax.php b/main/inc/ajax/admin.ajax.php index fd9c8a9ba0..0bba2011a8 100644 --- a/main/inc/ajax/admin.ajax.php +++ b/main/inc/ajax/admin.ajax.php @@ -28,4 +28,95 @@ switch ($action) { } } break; + + case 'version': + echo version_check(); + break; } + + +/** + * Displays either the text for the registration or the message that the installation is (not) up to date + * + * @return string html code + * @author Patrick Cool , Ghent University + * @version august 2006 + * @todo have a 6monthly re-registration + */ +function version_check() { + $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); + $sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable="registered" '; + $result = Database::query($sql); + $row = Database::fetch_array($result, 'ASSOC'); + + // The site has not been registered yet. + $return = ''; + if ($row['selected_value'] == 'false') { + $return .= get_lang('VersionCheckExplanation'); + $return .= '
'; + $return .= ''; + $return .= '
'; + check_system_version(); + } else { + // site not registered. Call anyway + $return .= check_system_version(); + } + return $return; +} + +/** + * Check if the current installation is up to date + * The code is borrowed from phpBB and slighlty modified + * @author The phpBB Group (the code) + * @author Patrick Cool , Ghent University (the modifications) + * @author Yannick Warnier for the move to HTTP request + * @copyright (C) 2001 The phpBB Group + * @return language string with some layout (color) + */ +function check_system_version() { + global $_configuration; + $system_version = trim($_configuration['system_version']); // the chamilo version of your installation + + if (ini_get('allow_url_fopen') == 1) { + // The number of courses + $number_of_courses = statistics::count_courses(); + + // The number of users + $number_of_users = statistics::count_users(); + $number_of_active_users = statistics::count_users(null,null,null,true); + + $data = array( + 'url' => api_get_path(WEB_PATH), + 'campus' => api_get_setting('siteName'), + 'contact' => api_get_setting('emailAdministrator'), + 'version' => $system_version, + 'numberofcourses' => $number_of_courses, + 'numberofusers' => $number_of_users, + 'numberofactiveusers' => $number_of_active_users, + //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'), + 'language' => api_get_setting('platformLanguage'), + 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'), + ); + + $res = _http_request('version.chamilo.org', 80, '/version.php', $data); + + if ($res !== false) { + $version_info = $res; + + if ($system_version != $version_info) { + $output = '
' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' Chamilo '.$version_info.'. '.get_lang('YourVersionIs').' Chamilo '.$system_version. '. '.str_replace('http://www.chamilo.org', 'http://www.chamilo.org', get_lang('PleaseVisitOurWebsite')).''; + } else { + $output = '
'.get_lang('VersionUpToDate').': Chamilo '.$version_info.''; + } + } else { + $output = '' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . ''; + } + } else { + $output = '' . get_lang('AllowurlfopenIsSetToOff') . ''; + } + return $output; +} \ No newline at end of file diff --git a/main/template/default/admin/settings_index.tpl b/main/template/default/admin/settings_index.tpl index 8578c79e17..6fd0966076 100644 --- a/main/template/default/admin/settings_index.tpl +++ b/main/template/default/admin/settings_index.tpl @@ -1,7 +1,13 @@
@@ -33,11 +39,19 @@ $(function() { {% endif %} + {% if block_item.label == 'VersionCheck'|get_lang %} +
+ {% endif %} + + {% if block_item.label == 'VersionCheck'|get_lang %} +
+ {% endif %} {% if block_item.extra is not null %}
{{ block_item.extra }}
- {% endif %} + {% endif %} +
{% endfor %} From 1297cda73b99dffe2b2b6785fe64ed20da6dfc0f Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Thu, 4 Jul 2013 14:44:22 -0400 Subject: [PATCH 2/5] Adding ajax call for check_version() function --- main/admin/index.php | 86 +++++++++++++++++++ main/inc/ajax/admin.ajax.php | 54 +++++++++++- .../template/default/admin/settings_index.tpl | 7 +- 3 files changed, 141 insertions(+), 6 deletions(-) diff --git a/main/admin/index.php b/main/admin/index.php index bf590177f5..a762fb10e0 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -334,6 +334,92 @@ function register_site() { } +/** + * Displays either the text for the registration or the message that the installation is (not) up to date + * + * @return string html code + * @author Patrick Cool , Ghent University + * @version august 2006 + * @todo have a 6monthly re-registration + */ +function version_check() { + $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); + $sql = 'SELECT selected_value FROM '.$tbl_settings.' WHERE variable="registered" '; + $result = Database::query($sql); + $row = Database::fetch_array($result, 'ASSOC'); + + // The site has not been registered yet. + $return = ''; + if ($row['selected_value'] == 'false') { + $return .= get_lang('VersionCheckExplanation'); + $return .= '
'; + $return .= ''; + $return .= '
'; + check_system_version(); + } else { + // site not registered. Call anyway + $return .= check_system_version(); + } + return $return; +} + +/** + * Check if the current installation is up to date + * The code is borrowed from phpBB and slighlty modified + * @author The phpBB Group (the code) + * @author Patrick Cool , Ghent University (the modifications) + * @author Yannick Warnier for the move to HTTP request + * @copyright (C) 2001 The phpBB Group + * @return language string with some layout (color) + */ +function check_system_version() { + global $_configuration; + $system_version = trim($_configuration['system_version']); // the chamilo version of your installation + + if (ini_get('allow_url_fopen') == 1) { + // The number of courses + $number_of_courses = statistics::count_courses(); + + // The number of users + $number_of_users = statistics::count_users(); + $number_of_active_users = statistics::count_users(null,null,null,true); + + $data = array( + 'url' => api_get_path(WEB_PATH), + 'campus' => api_get_setting('siteName'), + 'contact' => api_get_setting('emailAdministrator'), + 'version' => $system_version, + 'numberofcourses' => $number_of_courses, + 'numberofusers' => $number_of_users, + 'numberofactiveusers' => $number_of_active_users, + //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'), + 'language' => api_get_setting('platformLanguage'), + 'adminname' => api_get_setting('administratorName').' '.api_get_setting('administratorSurname'), + ); + + $res = _http_request('version.chamilo.org', 80, '/version.php', $data); + + if ($res != 0) { + $version_info = $res; + + if ($system_version != $version_info) { + $output = '
' . get_lang('YourVersionNotUpToDate') . '. '.get_lang('LatestVersionIs').' Chamilo '.$version_info.'. '.get_lang('YourVersionIs').' Chamilo '.$system_version. '. '.str_replace('http://www.chamilo.org', 'http://www.chamilo.org', get_lang('PleaseVisitOurWebsite')).''; + } else { + $output = '
'.get_lang('VersionUpToDate').': Chamilo '.$version_info.''; + } + } else { + $output = '' . get_lang('ImpossibleToContactVersionServerPleaseTryAgain') . ''; + } + } else { + $output = '' . get_lang('AllowurlfopenIsSetToOff') . ''; + } + return $output; +} + /** * Function to make an HTTP request through fsockopen (specialised for GET) * Derived from Jeremy Saintot: http://www.php.net/manual/en/function.fsockopen.php#101872 diff --git a/main/inc/ajax/admin.ajax.php b/main/inc/ajax/admin.ajax.php index 0bba2011a8..c7bd8a2eec 100644 --- a/main/inc/ajax/admin.ajax.php +++ b/main/inc/ajax/admin.ajax.php @@ -5,6 +5,7 @@ */ require_once '../global.inc.php'; +require_once api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php'; api_protect_admin_script(); @@ -104,7 +105,7 @@ function check_system_version() { $res = _http_request('version.chamilo.org', 80, '/version.php', $data); - if ($res !== false) { + if ($res != 0) { $version_info = $res; if ($system_version != $version_info) { @@ -119,4 +120,53 @@ function check_system_version() { $output = '' . get_lang('AllowurlfopenIsSetToOff') . ''; } return $output; -} \ No newline at end of file +} + +/** + * Function to make an HTTP request through fsockopen (specialised for GET) + * Derived from Jeremy Saintot: http://www.php.net/manual/en/function.fsockopen.php#101872 + * @param string IP or hostname + * @param int Target port + * @param string URI (defaults to '/') + * @param array GET data + * @param float Timeout + * @param bool Include HTTP Request headers? + * @param bool Include HTTP Response headers? + */ +function _http_request($ip, $port = 80, $uri = '/', $getdata = array(), $timeout = 1, $req_hdr = false, $res_hdr = false) { + $verb = 'GET'; + $ret = ''; + $getdata_str = count($getdata) ? '?' : ''; + + foreach ($getdata as $k => $v) { + $getdata_str .= urlencode($k) .'='. urlencode($v) . '&'; + } + + $crlf = "\r\n"; + $req = $verb .' '. $uri . $getdata_str .' HTTP/1.1' . $crlf; + $req .= 'Host: '. $ip . $crlf; + $req .= 'User-Agent: Mozilla/5.0 Firefox/3.6.12' . $crlf; + $req .= 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' . $crlf; + $req .= 'Accept-Language: en-us,en;q=0.5' . $crlf; + $req .= 'Accept-Encoding: deflate' . $crlf; + $req .= 'Accept-Charset: utf-8;q=0.7,*;q=0.7' . $crlf; + + $req .= $crlf; + + if ($req_hdr) { $ret .= $req; } + if (($fp = @fsockopen($ip, $port, $errno, $errstr, $timeout)) == false) { + return "Error $errno: $errstr\n"; + } + + stream_set_timeout($fp, $timeout); + $r = @fwrite($fp, $req); + $line = @fread($fp,512); + $ret .= $line; + fclose($fp); + + if (!$res_hdr) { + $ret = substr($ret, strpos($ret, "\r\n\r\n") + 4); + } + + return trim($ret); +} diff --git a/main/template/default/admin/settings_index.tpl b/main/template/default/admin/settings_index.tpl index 6fd0966076..c27bcaa612 100644 --- a/main/template/default/admin/settings_index.tpl +++ b/main/template/default/admin/settings_index.tpl @@ -2,12 +2,11 @@ $(document).ready(function() { $.ajax({ url:'{{web_admin_ajax_url}}?a=version', -     success:function(version){ - alert(version); + success:function(version){ + $(".admin-block-version").html(version); } }); -}); - +});
From 0a5df5f241338d09b7fed860af77ddec750f459f Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Thu, 4 Jul 2013 23:00:42 -0400 Subject: [PATCH 3/5] Removing special characters --- main/template/default/admin/settings_index.tpl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main/template/default/admin/settings_index.tpl b/main/template/default/admin/settings_index.tpl index c27bcaa612..0d3b7af3ce 100644 --- a/main/template/default/admin/settings_index.tpl +++ b/main/template/default/admin/settings_index.tpl @@ -1,11 +1,11 @@ From c35a1d3f79aae56b4b049ed57f246a5138935e66 Mon Sep 17 00:00:00 2001 From: Yoselyn Castillo Date: Thu, 4 Jul 2013 23:03:42 -0400 Subject: [PATCH 4/5] Fixing spaces --- main/template/default/admin/settings_index.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/template/default/admin/settings_index.tpl b/main/template/default/admin/settings_index.tpl index 0d3b7af3ce..d6ead9083d 100644 --- a/main/template/default/admin/settings_index.tpl +++ b/main/template/default/admin/settings_index.tpl @@ -1,9 +1,9 @@