diff --git a/main/admin/index.php b/main/admin/index.php index a27769e8d5..17f4acc74f 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -307,6 +307,7 @@ $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); +// The template contains the call to the AJAX version checker $admin_template = $tpl->get_template('admin/settings_index.tpl'); $content = $tpl->fetch($admin_template); $tpl->assign('content', $content); @@ -334,138 +335,4 @@ function register_site() { // Reload the settings. } - -/** - * 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 - * @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); -} +// Note: version checking mechanism has now been moved to main/inc/ajax/admin.ajax.php \ No newline at end of file diff --git a/main/admin/statistics/statistics.lib.php b/main/admin/statistics/statistics.lib.php index 6c2916ee94..210c659519 100644 --- a/main/admin/statistics/statistics.lib.php +++ b/main/admin/statistics/statistics.lib.php @@ -109,6 +109,23 @@ class Statistics { return $obj->number; } + /** + * Count sessions + * @return int Number of sessions counted + */ + static function count_sessions() { + $session_table = Database :: get_main_table(TABLE_MAIN_SESSION); + $access_url_rel_session_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + if (api_is_multiple_url_enabled()) { + $current_url_id = api_get_current_access_url_id(); + $sql = "SELECT COUNT(id) AS number FROM ".$session_table." as s, ".$access_url_rel_session_table." as u WHERE u.session_id=s.id AND access_url_id='".$current_url_id."'"; + } else { + $sql = "SELECT COUNT(id) AS number FROM ".$session_table." "; + } + $res = Database::query($sql); + $obj = Database::fetch_object($res); + return $obj->number; + } /** * Count activities from track_e_default_table * @return int Number of activities counted diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 132cc2013a..1cfa82abcd 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1229,7 +1229,7 @@ class Exercise { */ function processCreation($form, $type='') { - $this->updateTitle($form->getSubmitValue('exerciseTitle')); + $this->updateTitle(htmlentities($form->getSubmitValue('exerciseTitle'))); $this->updateDescription($form->getSubmitValue('exerciseDescription')); $this->updateAttempts($form->getSubmitValue('exerciseAttempts')); $this->updateFeedbackType($form->getSubmitValue('exerciseFeedbackType')); diff --git a/main/inc/ajax/admin.ajax.php b/main/inc/ajax/admin.ajax.php index 9c04bf3597..8259275add 100644 --- a/main/inc/ajax/admin.ajax.php +++ b/main/inc/ajax/admin.ajax.php @@ -91,6 +91,9 @@ function check_system_version() $number_of_users = Statistics::count_users(); $number_of_active_users = Statistics::count_users(null, null, null, true); + // The number of sessions + $number_of_sessions = Statistics::count_sessions(); + $data = array( 'url' => api_get_path(WEB_PATH), 'campus' => api_get_setting('siteName'), @@ -99,6 +102,7 @@ function check_system_version() 'numberofcourses' => $number_of_courses, 'numberofusers' => $number_of_users, 'numberofactiveusers' => $number_of_active_users, + 'numberofsessions' => $number_of_sessions, //The donotlistcampus setting recovery should be improved to make // it true by default - this does not affect numbers counting 'donotlistcampus' => api_get_setting('donotlistcampus'), @@ -137,7 +141,7 @@ function check_system_version() * @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) +function _http_request($ip, $port = 80, $uri = '/', $getdata = array(), $timeout = 5, $req_hdr = false, $res_hdr = false) { $verb = 'GET'; $ret = '';