Added a new value by default at the variable $status, created a new variable $status_filter and fixed the sql consultance. In the index.php modified the function check_system_version2 declarated a new varibles $number_of_course and deleted the sql query's

skala
Ricardo Rodriguez 15 years ago
parent 37a2bf9711
commit fa3d3046cb
  1. 16
      main/admin/index.php
  2. 28
      main/admin/statistics/statistics.lib.php

@ -14,6 +14,9 @@ $cidReset=true;
// including some necessary chamilo files
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'security.lib.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
require_once api_get_path(SYS_CODE_PATH).'admin/statistics/statistics.lib.php';
require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
// setting the section (for the tabs)
$this_section=SECTION_PLATFORM_ADMIN;
@ -360,6 +363,7 @@ function register_site()
// reload the settings
}
/**
* Check if the current installation is up to date
* The code is borrowed from phpBB and slighlty modified
@ -376,18 +380,24 @@ function check_system_version2()
if (ini_get('allow_url_fopen')==1)
{
// the number of courses
$sql="SELECT count(code) FROM ".Database::get_main_table(TABLE_MAIN_COURSE);
/* $sql="SELECT count(code) FROM ".Database::get_main_table(TABLE_MAIN_COURSE);
$result=Database::query($sql);
$row = Database::fetch_array($result);
$number_of_courses = $row[0];
*/ $number_of_courses = statistics::count_courses();
// the number of users
$sql="SELECT count(user_id) FROM ".Database::get_main_table(TABLE_MAIN_USER);
/* $sql="SELECT count(user_id) FROM ".Database::get_main_table(TABLE_MAIN_USER);
$result=Database::query($sql);
$row = Database::fetch_array($result);
$number_of_users = $row[0];
*/
$number_of_users = statistics::count_users();
$version_url= 'http://version.chamilo.org/version.php?url='.urlencode(api_get_path(WEB_PATH)).'&campus='.urlencode(api_get_setting('siteName')).'&contact='.urlencode(api_get_setting('emailAdministrator')).'&version='.urlencode($system_version).'&numberofcourses='.urlencode($number_of_courses).'&numberofusers='.urlencode($number_of_users).'&donotlistcampus='.api_get_setting('donotlistcampus').'&organisation='.urlencode(api_get_setting('Institution')).'&adminname='.urlencode(api_get_setting('administratorName').' '.api_get_setting('administratorSurname'));
die($version_url);
$handle=@fopen($version_url,'r');
if ($handle !== false) {
$version_info=trim(@fread($handle, 1024));

@ -43,14 +43,15 @@ class Statistics {
$obj = Database::fetch_object($res);
return $obj->number;
}
/**
* Count users
* @param int $status COURSEMANAGER or STUDENT
* @param string $category_code Code of a course category. Default: count
* all users.
* @param int optional, user status (COURSEMANAGER or STUDENT), if it's not setted it'll count all users.
* @param string optional, code of a course category. Default: count only users without filtering category
* @todo count invisible courses
* @return int Number of users counted
*/
function count_users($status, $category_code = NULL, $count_invisible_courses = true) {
function count_users($status = null, $category_code = null, $count_invisible_courses = true) {
global $_configuration;
// Database table definitions
@ -59,17 +60,24 @@ class Statistics {
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
if ($_configuration['multiple_access_urls'] == true){
$sql = "SELECT COUNT(DISTINCT(u.user_id)) AS number FROM $user_table as u, $access_url_rel_user_table as url WHERE status = ".intval(Database::escape_string($status))." AND u.user_id=url.user_id AND access_url_id='".$current_url_id."'";
$status_filter = isset($status)?' AND status = '.intval($status):'';
$sql = "SELECT COUNT(DISTINCT(u.user_id)) AS number FROM $user_table as u, $access_url_rel_user_table as url WHERE u.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter ";
if (isset ($category_code)) {
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url WHERE cu.status = ".intval(Database::escape_string($status))." AND c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."'";
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter ";
}
} else {
$sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table WHERE status = ".intval(Database::escape_string($status))." ";
} else {
$status_filter = isset($status)?' WHERE status = '.intval($status):'';
$sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table $status_filter ";
if (isset ($category_code)) {
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE cu.status = ".intval(Database::escape_string($status))." AND c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' ";
}
$status_filter = isset($status)?' AND status = '.intval($status):'';
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' $status_filter ";
}
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->number;

Loading…
Cancel
Save