skala
Julio Montoya 16 years ago
commit 48949e1b0b
  1. 11
      main/inc/banner.inc.php
  2. 4
      main/inc/lib/message.lib.php
  3. 94
      main/inc/lib/online.inc.php
  4. 8
      main/inc/lib/social.lib.php
  5. 50
      main/inc/lib/sortabletable.class.php
  6. 2
      main/mySpace/myStudents.php
  7. 2
      main/social/group_members.php
  8. 2
      main/social/home.php
  9. 2
      main/social/profile.php
  10. 2
      main/user/userInfo.php
  11. 8
      tests/README.txt
  12. 110
      tests/datafiller/data_users.php
  13. 15
      tests/datafiller/fill_all.php
  14. 8
      tests/datafiller/fill_users.php
  15. 32
      tests/datafiller/fill_whoisonline.php
  16. 17
      tests/main/inc/lib/online.inc.test.php
  17. 249
      tests/test_manager.inc.php
  18. 10
      whoisonline.php

@ -93,14 +93,13 @@ if ((api_get_setting('showonline', 'world') == 'true' AND !$_user['user_id']) OR
if (api_get_setting('use_session_mode') == 'true' && isset($_user['user_id']) && api_is_coach()) {
echo '<li><a href="'.api_get_path(WEB_PATH).'whoisonlinesession.php?id_coach='.$_user['user_id'].'&amp;referer='.urlencode($_SERVER['REQUEST_URI']).'" target="_top">'.get_lang('UsersConnectedToMySessions').'</a></li>';
}
$number = count(WhoIsOnline(api_get_setting('time_limit_whosonline')));
$number = who_is_online_count(api_get_setting('time_limit_whosonline'));
$number_online_in_course = 0;
if(!empty($_course['id'])) {
$online_in_course = who_is_online_in_this_course(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_course['id']);
$number_online_in_course = count($online_in_course);
} else {
$number_online_in_course = 0;
$number_online_in_course = who_is_online_in_this_course_count(api_get_user_id(), api_get_setting('time_limit_whosonline'), $_course['id']);
}
echo '<li>';
// Display the who's online of the platform
if ((api_get_setting('showonline', 'world') == 'true' AND !$_user['user_id']) OR (api_get_setting('showonline', 'users') == 'true' AND $_user['user_id'])) {

@ -32,7 +32,7 @@ class MessageManager
public static function get_online_user_list($current_user_id) {
$min=30;
global $_configuration;
$userlist = WhoIsOnline($current_user_id,$_configuration['statistics_database'],$min);
$userlist = who_is_online($current_user_id,$_configuration['statistics_database'],$min);
foreach($userlist as $row) {
$receiver_id = $row[0];
$online_user_list[$receiver_id] = GetFullUserName($receiver_id).($current_user_id==$receiver_id?("&nbsp;(".get_lang('Myself').")"):(""));
@ -95,7 +95,7 @@ class MessageManager
public static function users_connected_by_id() {
global $_configuration, $_user;
$minute=30;
$user_connect = WhoIsOnline($_user['user_id'],$_configuration['statistics_database'],$minute);
$user_connect = who_is_online($_user['user_id'],$_configuration['statistics_database'],$minute);
for ($i=0; $i<count($user_connect); $i++) {
$user_id_list[$i]=$user_connect[$i][0];
}

@ -121,22 +121,22 @@ function LoginDelete($user_id) {
* @param bool optionally if it's set to true shows who friends from social network is online otherwise just shows all users online
* @return array For each line, a list of user IDs and login dates, or FALSE on error or empty results
*/
function WhoIsOnline($valid, $friends = false)
{
function who_is_online($valid, $friends = false) {
$valid = (int) $valid;
$current_date = date('Y-m-d H:i:s',time());
$track_online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
$friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$query = '';
if ($friends) {
// who friends from social network is online
$query = " SELECT distinct login_user_id,login_date
FROM $track_online_table
INNER JOIN $friend_user_table ON (friend_user_id = login_user_id)
WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' AND friend_user_id <> '".api_get_user_id()."' AND relation_type='".USER_RELATION_TYPE_FRIEND."' AND user_id = '".api_get_user_id()."' ";
$query = "SELECT DISTINCT login_user_id,login_date
FROM $track_online_table INNER JOIN $friend_user_table ON (friend_user_id = login_user_id)
WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' AND friend_user_id <> '".api_get_user_id()."' AND relation_type='".USER_RELATION_TYPE_FRIEND."' AND user_id = '".api_get_user_id()."' ";
} else {
// all users online
$query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ";
//$query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' "; //WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."'
$query = "SELECT login_user_id,login_date FROM ".$track_online_table ." e INNER JOIN ".$table_user ." u ON (u.user_id=e.login_user_id) WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ORDER BY picture_uri DESC";
}
global $_configuration;
@ -152,13 +152,14 @@ function WhoIsOnline($valid, $friends = false)
WHERE track.access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' AND friend_user_id <> '".api_get_user_id()."' AND relation_type='".USER_RELATION_TYPE_FRIEND."' ";
} else {
// all users online
$query = "SELECT login_user_id,login_date FROM ".$track_online_table ." track
WHERE track.access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ";
$query = "SELECT login_user_id,login_date FROM ".$track_online_table ." track INNER JOIN ".$table_user ." u ON (u.user_id=track.login_user_id)
WHERE track.access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ORDER BY picture_uri DESC ";
}
}
}
$result = @Database::query($query);
//@todo why we dont believe in db query results?
if (count($result)>0) {
$rtime = time();
$rdate = date("Y-m-d H:i:s",$rtime);
@ -166,9 +167,9 @@ function WhoIsOnline($valid, $friends = false)
$rarray = array();
while(list($login_user_id,$login_date)= Database::fetch_row($result)) {
$barray = array();
$barray = array();
array_push($barray,$login_user_id);
array_push($barray,$login_date);
array_push($barray,$login_date);
// YYYY-MM-DD HH:MM:SS, db date format
$hour = substr($login_date,11,2);
@ -179,17 +180,60 @@ function WhoIsOnline($valid, $friends = false)
$year = substr($login_date,0,4);
// db timestamp
$dbtime = mktime($hour,$minute,$secund,$month,$day,$year);
if ($dbtime>$validtime) {
array_push($rarray,$barray);
}
}
}
return $rarray;
} else {
return false;
}
}
function who_is_online_Count($valid, $friends = false) {
$valid = (int) $valid;
$current_date = date('Y-m-d H:i:s',time());
$track_online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
$friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$query = '';
if ($friends) {
// who friends from social network is online
$query = "SELECT DISTINCT count(login_user_id) as count
FROM $track_online_table INNER JOIN $friend_user_table ON (friend_user_id = login_user_id)
WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' AND friend_user_id <> '".api_get_user_id()."' AND relation_type='".USER_RELATION_TYPE_FRIEND."' AND user_id = '".api_get_user_id()."' ";
} else {
// all users online
$query = "SELECT count(login_id) FROM ".$track_online_table ." WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' "; //WHERE DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."'
}
global $_configuration;
if ($_configuration['multiple_access_urls']==true) {
$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
if ($friends) {
// friends from social network is online
$query = "SELECT DISTINCT count(login_user_id) as count
FROM $track_online_table track
INNER JOIN $friend_user_table ON (friend_user_id = login_user_id)
WHERE track.access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' AND friend_user_id <> '".api_get_user_id()."' AND relation_type='".USER_RELATION_TYPE_FRIEND."' ";
} else {
// all users online
$query = "SELECT count(login_id) as count FROM ".$track_online_table ." track
WHERE track.access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' ";
}
}
}
$result = Database::query($query);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
return $row['count'];
} else {
return false;
}
}
/**
@ -202,7 +246,7 @@ function GetFullUserName($uid)
$uid = (int) $uid;
$uid = Database::escape_string($uid);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$query = "SELECT firstname,lastname FROM ".$user_table." WHERE user_id='$uid'";
$query = "SELECT firstname, lastname FROM ".$user_table." WHERE user_id='$uid'";
$result = @Database::query($query);
if (count($result)>0) {
$str = '';
@ -311,4 +355,22 @@ function who_is_online_in_this_course($uid, $valid, $coursecode=null)
} else {
return false;
}
}
}
function who_is_online_in_this_course_count($uid, $valid, $coursecode=null)
{
if(empty($coursecode)) return false;
$track_online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
$coursecode = Database::escape_string($coursecode);
$valid = Database::escape_string($valid);
$query = "SELECT count(login_user_id) as count FROM ".$track_online_table ." WHERE course='".$coursecode."' AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() ";
$result = Database::query($query);
$result = Database::query($query);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
return $row['count'];
} else {
return false;
}
}

@ -790,7 +790,7 @@ class SocialManager extends UserManager {
$extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']);
$course_url = '&amp;cidReq='.Security::remove_XSS($_GET['cidReq']);
}
foreach ($user_list as $user) {
$uid = $user[0];
$user_info = api_get_user_info($uid);
@ -801,7 +801,7 @@ class SocialManager extends UserManager {
$url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$uid.$course_url;
} else {
$url = '?id='.$uid.$course_url;
}
}
} else {
$url = '#';
}
@ -826,8 +826,8 @@ class SocialManager extends UserManager {
if (api_get_setting('show_email_addresses') == 'true') {
$table_header[] = array(get_lang('Email'), true);
}
Display::display_sortable_table($table_header, $table_data, array(), array('per_page' => 20), $extra_params, array(),'grid');
}
Display::display_sortable_table($table_header, $table_data, array(), array('per_page' => 25), $extra_params, array(),'grid');
}
}
/**

@ -299,20 +299,24 @@ class SortableTable extends HTML_Table {
// @todo This style css must be moved to default.css only for dev
echo '<style>
.main-grid { width:100%;}
.sub-header { width:100%; padding-top: 10px; padding-right: 10px; padding-left: 10px; height:30px;}
.grid_container { width:100%;}
.grid_item { height: 120px; width:98px; border:1px dotted #ccc; float:left; padding:5px; margin:8px;}
.grid_element_0 { width:100px; float:left; text-align:center; margin-bottom:5px;}
.grid_element_1 { width:100px; float:left; text-align:center;margin-bottom:5px;}
.grid_element_2 { width:150px; float:left;}
.grid_selectbox { width:50%; float:left;}
.grid_selectbox { width:30%; float:left;}
.grid_title { width:30%; float:left;}
.grid_nav { float:right;}
.grid_nav { }
</style>';
// @todo This also must be moved
$html = '<div class="sub-header">';
$html .= '<div class="main-grid">';
$html .= '<div class="sub-header">';
$html .= '<div class="grid_selectbox">'.$form.'</div>';
$html .= '<div class="grid_title">'.$this->get_table_title().'</div>';
$html .= '<div class="grid_nav">'.$nav.'</div>';
@ -321,26 +325,28 @@ class SortableTable extends HTML_Table {
$html .= '<div class="clear"></div>';
if (count($this->form_actions) > 0) {
$script= '<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function setCheckbox(value) {
d = document.form_'.$this->table_name.';
for (i = 0; i < d.elements.length; i++) {
if (d.elements[i].type == "checkbox") {
d.elements[i].checked = value;
}
}
}
/*]]>*/
</script>';
/*<![CDATA[*/
function setCheckbox(value) {
d = document.form_'.$this->table_name.';
for (i = 0; i < d.elements.length; i++) {
if (d.elements[i].type == "checkbox") {
d.elements[i].checked = value;
}
}
}
/*]]>*/
</script>';
$params = $this->get_sortable_table_param_string().'&amp;'.$this->get_additional_url_paramstring();
$html .= '<form method="post" action="'.api_get_self().'?'.$params.'" name="form_'.$this->table_name.'">';
}
}
$items = $this->get_clean_html(); // Getting the items of the table
// Getting the items of the table
$items = $this->get_clean_html(false); //no sort
// Generation of style classes must be improved. Maybe we need a a table name to create style on the fly:
// i.e: .whoisonline_table_grid_container instead of .grid_container
// where whoisonline is the table's name like drupal's template engine
$html .= '<div class="grid_container">';
if (is_array($items) && count($items) > 0) {
foreach ($items as & $row) {
@ -351,9 +357,13 @@ class SortableTable extends HTML_Table {
$i++;
}
$html .= '</div>';
}
$html .= '</div>';
}
}
$html .= '</div>'; //close grid_container
$html .= '</div>'; //close main grid
$html .= '<div class="clear"></div>';
/*
if (!$empty_table) {
@ -528,8 +538,10 @@ class SortableTable extends HTML_Table {
$pager = $this->get_pager();
$val = $pager->getOffsetByPageId();
$offset = $pager->getOffsetByPageId();
$from = $offset[0] - 1;
$from = $offset[0] - 1;
$table_data = $this->get_table_data($from, $sort);
$new_table_data = array();
if (is_array($table_data)) {
foreach ($table_data as $index => & $row) {

@ -224,7 +224,7 @@ if (!empty ($_GET['student'])) {
// is the user online ?
$student_online = Security :: remove_XSS($_GET['student']);
$users_online = WhoIsOnline(30);
$users_online = who_is_online(30);
foreach ($users_online as $online) {
if (in_array($_GET['student'], $online)) {
$online = get_lang('Yes');

@ -53,7 +53,7 @@ if (empty($group_id)) {
Display :: display_header($tool_name, 'Groups');
$user_online_list = WhoIsOnline(api_get_setting('time_limit_whosonline'), true);
$user_online_list = who_is_online(api_get_setting('time_limit_whosonline'), true);
$user_online_count = count($user_online_list);
$show_message = '';

@ -68,7 +68,7 @@ if (api_get_setting('profile', 'picture') == 'true') {
Display :: display_header(get_lang('Home'));
$user_info = UserManager :: get_user_info_by_id(api_get_user_id());
$user_online_list = WhoIsOnline(api_get_setting('time_limit_whosonline'),true);
$user_online_list = who_is_online(api_get_setting('time_limit_whosonline'),true);
$user_online_count = count($user_online_list);
echo '<div id="social-content">';

@ -248,7 +248,7 @@ if (is_array($personal_course_list)) {
$course_list_code = array_unique_dimensional($course_list_code);
}
$user_online_list = WhoIsOnline(api_get_setting('time_limit_whosonline'), true);
$user_online_list = who_is_online(api_get_setting('time_limit_whosonline'), true);
$user_online_count = count($user_online_list);
echo '<div id="social-content">';

@ -461,7 +461,7 @@ elseif ($displayMode == "viewContentList") // default display
}
// is the user online ?
$users_online = WhoIsOnline(30);
$users_online = who_is_online(30);
foreach ($users_online as $online) {
if (in_array($userIdViewed, $online)) {

@ -1,2 +1,6 @@
This directory is used for automated testing through the use of the SimpleTest
framework..
/* For licensing terms, see /license.txt */
/* README */
This directory is used for automated testing through the use of the SimpleTest framework..
Run test_suite.php

@ -43,8 +43,116 @@ $users[] = array(
'email' => 'michel.lanoix@testdokeos.com',
'status' => 1,
'creator_id' => 1,
'active' => 1,
'active' => 1
);
$users[] = array(
'username' => 'jmontoya',
'pass' => 'jmontoya',
'firstname' => 'Julio',
'lastname' => 'Montoya',
'status' => 1,
'auth_source' => 'platform',
'email' => 'julio.montoya@beeznest.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'agarcia',
'pass' => 'agarcia',
'firstname' => 'Alan',
'lastname' => 'Garcia',
'status' => 1,
'auth_source' => 'platform',
'email' => 'agarcia@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'pperez',
'pass' => 'pperez',
'firstname' => 'Pedro',
'lastname' => 'Perez',
'status' => 5,
'auth_source' => 'platform',
'email' => 'pperez@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'ggomez',
'pass' => 'ggomez',
'firstname' => 'Gabriela',
'lastname' => 'Gomez',
'status' => 5,
'auth_source' => 'platform',
'email' => 'ggomez@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'norizales',
'pass' => 'norizales',
'firstname' => 'Noa',
'lastname' => 'Orizales',
'status' => 5,
'auth_source' => 'platform',
'email' => 'norizales@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'jbrion',
'pass' => 'jbrion',
'firstname' => 'Jon',
'lastname' => 'Brion',
'status' => 5,
'auth_source' => 'platform',
'email' => 'jbrion@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'fapple',
'pass' => 'fapple',
'firstname' => 'Fiona',
'lastname' => 'Apple Maggart',
'status' => 5,
'auth_source' => 'platform',
'email' => 'fapple@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array(
'username' => 'acalabaza',
'pass' => 'acalabaza',
'firstname' => 'Aldo',
'lastname' => 'Calabaza',
'status' => 5,
'auth_source' => 'platform',
'email' => 'acalabaza@example.com',
'creator_id' => 1,
'active' => 1
);
$users[] = array('username' => 'mhalles','pass' => 'mhalles','firstname' => 'Maria','lastname' => 'Halles','status' => 5,'auth_source' => 'platform','email' => 'mhalles@example.com','creator_id' => 1,'active' => 1);
$users[] = array('username' => 'adaniel','pass' => 'adaniel','firstname' => 'Annaa','lastname' => 'Daniel','status' => 5,'auth_source' => 'platform','email' => 'adaniel@example.com','creator_id' => 1,'active' => 1);
$users[] = array('username' => 'ppiedra','pass' => 'ppiedra','firstname' => 'Pirot','lastname' => 'Piedra','status' => 5,'auth_source' => 'platform','email' => 'ppiedra@example.com','creator_id' => 1,'active' => 1);
$users[] = array('username' => 'amartin','pass' => 'amartin','firstname' => 'Angel','lastname' => 'Martin','status' => 5,'auth_source' => 'platform','email' => 'amartin@example.com','creator_id' => 1,'active' => 1);
$users[] = array('username' => 'mhingis','pass' => 'mhingis','firstname' => 'Marsi','lastname' => 'Hingis','status' => 5,'auth_source' => 'platform','email' => 'mhingis@example.com','creator_id' => 1,'active' => 1);
$users[] = array('username' => 'jlennon','pass' => 'jlennon','firstname' => 'Johny','lastname' => 'Lennon','status' => 5,'auth_source' => 'platform','email' => 'jlennon@example.com','creator_id' => 1,'active' => 1);
$users[] = array('username' => 'pchavez','pass' => 'pchavez','firstname' => 'Parol','lastname' => 'Chavez','status' => 5,'auth_source' => 'platform','email' => 'pchavez@example.com','creator_id' => 1,'active' => 1);
/*
$users[] = array(
'username' => '',

@ -8,10 +8,13 @@
* on your system and t launch this script manually using: php5 fill_all.php
* @author Yannick Warnier <yannick.warnier@dokeos.com>
*/
/**
* Initialisation section
*/
require_once '../../main/inc/global.inc.php';
$incdir = dirname(__FILE__).'/../../main/inc/';
require $incdir.'global.inc.php';
/**
* Code logic
*/
@ -19,18 +22,18 @@ require_once '../../main/inc/global.inc.php';
if (PHP_SAPI != 'cli') { die('This demo-data filling script can only be run from the command line. Please launch it from the command line using: php5 fill_all.php. To enable it from your browser (very highly dangerous), remove the first line of code from the "logic" section of this file.'); }
$eol = PHP_EOL;
$output = '';
$files = scandir('.');
$files = scandir(dirname(__FILE__));
foreach ($files as $file) {
if (substr($file,0,1) == '.' or substr($file,0,5) != 'fill_') { ; } //skip
else {
else {
if ($file == basename(__FILE__)) {
; //skip, this is the current file
//skip, this is the current file
} else {
$output .= $file.$eol;
$output .= $eol.'Reading file: '.$file.$eol;
require_once $file;
$function = basename($file,'.php');
if (function_exists($function)) {
$output .= 'Executing function '.$function.$eol;
$output .= $eol.'Executing function '.$function.$eol;
$function();
} else {
//function not found

@ -7,20 +7,22 @@
/**
* Initialisation section
*/
require_once '../../main/inc/global.inc.php';
require_once '../../main/inc/lib/usermanager.lib.php';
//require_once '../../main/inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
/**
* Loads the data and injects it into the Dokeos database, using the Dokeos
* internal functions.
* @return array List of user IDs for the users that have just been inserted
*/
function fill_users() {
global $eol;
$users = array(); //declare only to avoid parsing notice
require_once 'data_users.php'; //fill the $users array
$output = array();
echo $eol.'Users created:'.$eol.$eol;
foreach ($users as $i => $user) {
//first check that the first item doesn't exist already
echo $user['firstname'];
echo $user['firstname'].$eol;
$output[] = UserManager::create_user($user['firstname'],$user['lastname'],$user['status'],$user['email'],$user['username'],$user['pass'],null,null,null,null,$user['auth_source'],null,$user['active']);
}
return $output;

@ -0,0 +1,32 @@
<?php //$id$
/**
* This script contains a data filling procedure for users
* @author Julio Montoya <gugli100@gmail.com>
*
*/
/**
* Initialisation section
*/
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
/**
* Loads the data and injects it into the Dokeos database, using the Dokeos
* internal functions.
* @return array List of user IDs for the users that have just been inserted
*/
function fill_whoisonline() {
$table_e_online = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
$max = 100;
//Cleaning the table
$sql = "TRUNCATE $table_e_online";
$rs = Database::query($sql);
//filling the table
for ($i=1;$i <=$max;$i++) {
$date = api_get_local_time();
$sql = "INSERT INTO $table_e_online (login_id, login_user_id, login_date, login_ip, course, session_id, access_url_id)
VALUES ('$i', '$i', '$date', '127.0.0.1', '', '0','1')";
$rs = Database::query($sql);
}
}

@ -21,10 +21,9 @@ class TestOnline extends UnitTestCase {
."</p>";
$res=chatcall();
if(!empty($message)){
$this->assertTrue(is_string($message));
//var_dump($message);
if (!empty($message)) {
$this->assertTrue(is_string($message));
//var_dump($message);
} else {
$this->assertTrue(is_bool($message));
//var_dump($message);
@ -76,8 +75,8 @@ class TestOnline extends UnitTestCase {
$login_user_id= '';
$login_date= '';
array_push($rarray,$barray);
array_push($barray,$login_user_id);
array_push($barray,$login_date);
array_push($barray,$login_user_id);
array_push($barray,$login_date);
$res=who_is_online_in_this_course($uid, $valid, $coursecode=null);
if(!empty($barray)){
@ -90,11 +89,11 @@ class TestOnline extends UnitTestCase {
//var_dump($rarray);
}
function testWhoIsOnline() {
function testwho_is_online() {
$valid='';
$res=WhoIsOnline($valid);
$res=who_is_online($valid);
$this->assertTrue(is_array($res));
//var_dump($res);
//var_dump($res);
}
}
?>

@ -1,38 +1,30 @@
<?php
// $Id: test_manager.inc.php 2010-02-17 12:07:00Z aportugal $
/* For licensing terms, see /license.txt */
/* For licensing terms, see /chamilo_license.txt */
/**
==============================================================================
* Code library for load functions than are needed to test
*
* @author Arthur Portugal, Principal author
* @package chamilo.tests
==============================================================================
*/
/**
* @todo shouldn't these settings be moved to the test_suite.php
* if these are really configuration then we can make require_once in each tests
* file.
* if these are really configuration then we can make require_once in each tests file.
* @todo use this file to load in the setup in each file test.
* @todo use this file to destroy in the teardown in each file test.
* @todo check for duplication of "require_once" files with test_suite.php
* @author aportugal
* @author Arthur Portugal
*/
/*
==============================================================================
INIT SECTION
==============================================================================
*/
ini_set('memory_limit','256M');
ini_set('max_execution_time','0');
/*
-----------------------------------------------------------
Included libraries
-----------------------------------------------------------
*/
$maindir = dirname(__FILE__).'/../main/';
$incdir = dirname(__FILE__).'/../main/inc/';
@ -100,11 +92,7 @@ ob_end_clean();
class TestManager {
/**
==============================================================================
MAIN CODE
==============================================================================
*/
/* MAIN CODE */
/**
* This function create in the database a test course and will also load sessions.
@ -114,111 +102,86 @@ class TestManager {
*/
function create_test_course($course_code = 'COURSETEST') {
/* Table definitions */
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
/*
-----------------------------------------------------------
Table definitions
-----------------------------------------------------------
*/
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
global $_configuration, $_user, $_course, $cidReq;
$cidReq = $course_code;
/*
-----------------------------------------------------------
Check if the course exists
-----------------------------------------------------------
*/
$sql = "SELECT code FROM $table_course WHERE code = '$cidReq' ";
$rs = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_row($rs);
/*
-----------------------------------------------------------
Create the course in the database
-----------------------------------------------------------
*/
if (empty($row[0])) {
// create a course
$course_datos = array(
'wanted_code'=> $cidReq,
'title'=>$cidReq,
'tutor_name'=>'John Doe',
'category_code'=>'LANG',
'course_language'=>'spanish',
'course_admin_id'=>'001',
'db_prefix'=> $_configuration['db_prefix'],
'firstExpirationDelay'=>'999'
);
$res = create_course($course_datos['wanted_code'], $course_datos['title'],
$course_datos['tutor_name'], $course_datos['category_code'],
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName
FROM $course_table
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$cidReq'";
$result = Database::query($sql,__FILE__,__LINE__);
/*
-----------------------------------------------------------
Create the session
-----------------------------------------------------------
*/
if (Database::num_rows($result)>0) {
$cData = Database::fetch_array($result);
$_cid = $cData['code' ];
$_course = array();
$_course['id' ] = $cData['code' ]; //auto-assigned integer
$_course['name' ] = $cData['title' ];
$_course['official_code'] = $cData['visual_code' ]; // use in echo
$_course['sysCode' ] = $cData['code' ]; // use as key in db
$_course['path' ] = $cData['directory' ]; // use as key in path
$_course['dbName' ] = $cData['db_name' ]; // use as key in db list
$_course['dbNameGlu' ] = $_configuration['table_prefix'] . $cData['db_name'] . $_configuration['db_glue']; // use in all queries
$_course['titular' ] = $cData['tutor_name' ];
$_course['language' ] = $cData['course_language' ];
$_course['extLink' ]['url' ] = $cData['department_url' ];
$_course['extLink' ]['name'] = $cData['department_name' ];
$_course['categoryCode'] = $cData['faCode' ];
$_course['categoryName'] = $cData['faName' ];
$_course['visibility' ] = $cData['visibility' ];
$_course['subscribe_allowed'] = $cData['subscribe' ];
$_course['unubscribe_allowed'] = $cData['unsubscribe' ];
api_session_register('_cid');
api_session_register('_course');
}
/*
-----------------------------------------------------------
Load the session
-----------------------------------------------------------
*/
$_SESSION['_user']['user_id'] = 1;
$_SESSION['is_courseAdmin'] = 1;
$_SESSION['show'] = showall;
/*
-----------------------------------------------------------
Load the user
-----------------------------------------------------------
*/
$_user['user_id'] = $_SESSION['_user']['user_id'];
global $_configuration, $_user, $_course, $cidReq;
$cidReq = $course_code;
/* Check if the course exists */
$sql = "SELECT code FROM $table_course WHERE code = '$cidReq' ";
$rs = Database::query($sql, __FILE__, __LINE__);
$row = Database::fetch_row($rs);
/* Create the course in the database */
if (empty($row[0])) {
// Create a course
$course_datos = array(
'wanted_code'=> $cidReq,
'title'=>$cidReq,
'tutor_name'=>'John Doe',
'category_code'=>'LANG',
'course_language'=>'spanish',
'course_admin_id'=>'001',
'db_prefix'=> $_configuration['db_prefix'],
'firstExpirationDelay'=>'999'
);
$res = create_course($course_datos['wanted_code'], $course_datos['title'],
$course_datos['tutor_name'], $course_datos['category_code'],
$course_datos['course_language'],$course_datos['course_admin_id'],
$course_datos['db_prefix'], $course_datos['firstExpirationDelay']);
}
$sql = "SELECT course.*, course_category.code faCode, course_category.name faName
FROM $course_table
LEFT JOIN $course_cat_table
ON course.category_code = course_category.code
WHERE course.code = '$cidReq'";
$result = Database::query($sql,__FILE__,__LINE__);
/* Create the session */
if (Database::num_rows($result)>0) {
$cData = Database::fetch_array($result);
$_cid = $cData['code' ];
$_course = array();
$_course['id' ] = $cData['code' ]; //auto-assigned integer
$_course['name' ] = $cData['title' ];
$_course['official_code'] = $cData['visual_code' ]; // use in echo
$_course['sysCode' ] = $cData['code' ]; // use as key in db
$_course['path' ] = $cData['directory' ]; // use as key in path
$_course['dbName' ] = $cData['db_name' ]; // use as key in db list
$_course['dbNameGlu' ] = $_configuration['table_prefix'] . $cData['db_name'] . $_configuration['db_glue']; // use in all queries
$_course['titular' ] = $cData['tutor_name' ];
$_course['language' ] = $cData['course_language' ];
$_course['extLink' ]['url' ] = $cData['department_url' ];
$_course['extLink' ]['name'] = $cData['department_name' ];
$_course['categoryCode'] = $cData['faCode' ];
$_course['categoryName'] = $cData['faName' ];
$_course['visibility' ] = $cData['visibility' ];
$_course['subscribe_allowed'] = $cData['subscribe' ];
$_course['unubscribe_allowed'] = $cData['unsubscribe' ];
api_session_register('_cid');
api_session_register('_course');
}
/* Load the session */
$_SESSION['_user']['user_id'] = 1;
$_SESSION['is_courseAdmin'] = 1;
$_SESSION['show'] = showall;
/* Load the user */
$_user['user_id'] = $_SESSION['_user']['user_id'];
}
/**
@ -228,37 +191,25 @@ $_user['user_id'] = $_SESSION['_user']['user_id'];
*/
function delete_test_course($course_code) {
$code = $course_code;
$code = $course_code;
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
/*
-----------------------------------------------------------
Delete the course
-----------------------------------------------------------
*/
$res = CourseManager::delete_course($code);
$path = api_get_path(SYS_PATH).'archive';
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (strpos($file,$code)!==false) {
if (is_dir($path.'/'.$file)) {
rmdirr($path.'/'.$file);
}
}
}
closedir($handle);
}
closedir($handle);
}
/*
-----------------------------------------------------------
Check api session destroy
-----------------------------------------------------------
*/
if (!headers_sent() && session_id() != "") {
$res=api_session_destroy();
// Check api session destroy
if (!headers_sent() && session_id() != "") {
$res=api_session_destroy();
}
}
}
}

@ -119,16 +119,14 @@ if ($_GET['chatid'] != '') {
if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || ((api_get_setting('showonline', 'users') == 'true' || api_get_setting('showonline', 'course') == 'true') && $_user['user_id'])) {
if(isset($_GET['cidReq']) && strlen($_GET['cidReq']) > 0) {
$user_list = Who_is_online_in_this_course($_user['user_id'], api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
$user_list = who_is_online_in_this_course($_user['user_id'], api_get_setting('time_limit_whosonline'), $_GET['cidReq']);
} else {
$user_list = WhoIsOnline(api_get_setting('time_limit_whosonline'));
$user_list = who_is_online(api_get_setting('time_limit_whosonline'));
}
$total = count($user_list);
if (!isset($_GET['id'])) {
Display::display_header(get_lang('UsersOnLineList'));
if (api_get_setting('allow_social_tool') == 'true') {
if (!api_is_anonymous()) {
echo '<div id="social-content-left">';
@ -139,7 +137,7 @@ if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) ||
if ($_GET['id'] == '') {
echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
//echo '<p><a class="refresh" href="javascript:window.location.reload()">'.get_lang('Refresh').'</a></p>';
} /*else {
if (0) {
// if ($_user['user_id'] && $_GET["id"] != $_user['user_id']) {
@ -161,7 +159,7 @@ if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) ||
if (!api_is_anonymous()) {
echo UserManager::get_search_form($_GET['q']);
}
}
}
SocialManager::display_user_list($user_list);
echo '</div>';
} else {

Loading…
Cancel
Save