From de0d2ae6f7b7bd94cf0b17c9d87e642eb88706c4 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Mar 2010 10:53:39 -0500 Subject: [PATCH 1/6] Minor - Run test message --- tests/README.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/README.txt b/tests/README.txt index 5c2d7885c3..6393ae107c 100755 --- a/tests/README.txt +++ b/tests/README.txt @@ -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 From e46110cb39362a7d58f9dca3cfce6b6308941eef Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Mar 2010 12:20:15 -0500 Subject: [PATCH 2/6] Tests: Adding users + fixing fill_all.php --- tests/datafiller/data_users.php | 110 +++++++++++++++++++++++++++++++- tests/datafiller/fill_all.php | 15 +++-- tests/datafiller/fill_users.php | 8 ++- 3 files changed, 123 insertions(+), 10 deletions(-) diff --git a/tests/datafiller/data_users.php b/tests/datafiller/data_users.php index fa907539ee..ce7b790c0d 100755 --- a/tests/datafiller/data_users.php +++ b/tests/datafiller/data_users.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' => '', diff --git a/tests/datafiller/fill_all.php b/tests/datafiller/fill_all.php index 5a49ba0a38..484a003574 100755 --- a/tests/datafiller/fill_all.php +++ b/tests/datafiller/fill_all.php @@ -8,10 +8,13 @@ * on your system and t launch this script manually using: php5 fill_all.php * @author Yannick Warnier */ + /** * 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 diff --git a/tests/datafiller/fill_users.php b/tests/datafiller/fill_users.php index aa6e759f19..521c19c07b 100755 --- a/tests/datafiller/fill_users.php +++ b/tests/datafiller/fill_users.php @@ -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; From d57544be5e1270e9f0a60dd38c5e55f567a927b4 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Mar 2010 12:20:37 -0500 Subject: [PATCH 3/6] Adding fill_whoisonline.php --- tests/datafiller/fill_whoisonline.php | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 tests/datafiller/fill_whoisonline.php diff --git a/tests/datafiller/fill_whoisonline.php b/tests/datafiller/fill_whoisonline.php new file mode 100755 index 0000000000..d59fdbf0ac --- /dev/null +++ b/tests/datafiller/fill_whoisonline.php @@ -0,0 +1,32 @@ + + * + */ + +/** + * 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','0')"; + $rs = Database::query($sql); + } +} \ No newline at end of file From 025671435f3359428ab7be3254c536a61a14a438 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Mar 2010 12:31:31 -0500 Subject: [PATCH 4/6] Minor - sql query fixed --- tests/datafiller/fill_whoisonline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datafiller/fill_whoisonline.php b/tests/datafiller/fill_whoisonline.php index d59fdbf0ac..69775a306e 100755 --- a/tests/datafiller/fill_whoisonline.php +++ b/tests/datafiller/fill_whoisonline.php @@ -26,7 +26,7 @@ function fill_whoisonline() { 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','0')"; + VALUES ('$i', '$i', '$date', '127.0.0.1', '', '0','1')"; $rs = Database::query($sql); } } \ No newline at end of file From 5f8bc0710b0bd523b92682108a07e1b913ee2c13 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Mar 2010 13:15:02 -0500 Subject: [PATCH 5/6] Who is online improvements, calls a \"SELECT count(*)\" query instead of retrieving all the info from the database WhoIsOnline also rename to who_is__online --- main/inc/banner.inc.php | 11 ++-- main/inc/lib/message.lib.php | 4 +- main/inc/lib/online.inc.php | 94 +++++++++++++++++++++++----- main/inc/lib/social.lib.php | 8 +-- main/inc/lib/sortabletable.class.php | 50 +++++++++------ main/mySpace/myStudents.php | 2 +- main/social/group_members.php | 2 +- main/social/home.php | 2 +- main/social/profile.php | 2 +- main/user/userInfo.php | 2 +- 10 files changed, 125 insertions(+), 52 deletions(-) diff --git a/main/inc/banner.inc.php b/main/inc/banner.inc.php index 2627ad7407..fe6e85dc05 100755 --- a/main/inc/banner.inc.php +++ b/main/inc/banner.inc.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 '
  • '.get_lang('UsersConnectedToMySessions').'
  • '; } - $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 '
  • '; // 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'])) { diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index db14c3bead..8b47321e24 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -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?(" (".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 '".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; } -} \ No newline at end of file +} + +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; + } +} diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index b2a757dcc4..2996c36ffc 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -790,7 +790,7 @@ class SocialManager extends UserManager { $extra_params['cidReq'] = Security::remove_XSS($_GET['cidReq']); $course_url = '&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'); } } /** diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index 6d235b83ac..fd035f7d00 100755 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -299,20 +299,24 @@ class SortableTable extends HTML_Table { // @todo This style css must be moved to default.css only for dev echo ''; // @todo This also must be moved - $html = '
    '; + + $html .= '
    '; + $html .= '
    '; $html .= '
    '.$form.'
    '; $html .= '
    '.$this->get_table_title().'
    '; $html .= '
    '.$nav.'
    '; @@ -321,26 +325,28 @@ class SortableTable extends HTML_Table { $html .= '
    '; if (count($this->form_actions) > 0) { $script= ''; + /*table_name.'; + for (i = 0; i < d.elements.length; i++) { + if (d.elements[i].type == "checkbox") { + d.elements[i].checked = value; + } + } + } + /*]]>*/ + '; $params = $this->get_sortable_table_param_string().'&'.$this->get_additional_url_paramstring(); $html .= '
    '; } } - $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 .= '
    '; if (is_array($items) && count($items) > 0) { foreach ($items as & $row) { @@ -351,9 +357,13 @@ class SortableTable extends HTML_Table { $i++; } $html .= '
    '; - } - $html .= '
    '; + } } + $html .= '
    '; //close grid_container + + $html .= '
    '; //close main grid + + $html .= '
    '; /* 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) { diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 30c1cdd4a3..c0e3fd8a99 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -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'); diff --git a/main/social/group_members.php b/main/social/group_members.php index 891c851070..73de55649a 100755 --- a/main/social/group_members.php +++ b/main/social/group_members.php @@ -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 = ''; diff --git a/main/social/home.php b/main/social/home.php index b820e43cc9..be76ab9f2e 100755 --- a/main/social/home.php +++ b/main/social/home.php @@ -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 '
    '; diff --git a/main/social/profile.php b/main/social/profile.php index 50b1924b7d..5557b70797 100755 --- a/main/social/profile.php +++ b/main/social/profile.php @@ -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 '
    '; diff --git a/main/user/userInfo.php b/main/user/userInfo.php index e38d5e1720..e763eff30b 100755 --- a/main/user/userInfo.php +++ b/main/user/userInfo.php @@ -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)) { From d831a332f2b55290c8633597df485081dac2ed76 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 18 Mar 2010 13:15:50 -0500 Subject: [PATCH 6/6] Tests also were modified + the whoisonline.php --- tests/main/inc/lib/online.inc.test.php | 46 ++++- tests/test_manager.inc.php | 249 ++++++++++--------------- whoisonline.php | 10 +- 3 files changed, 143 insertions(+), 162 deletions(-) diff --git a/tests/main/inc/lib/online.inc.test.php b/tests/main/inc/lib/online.inc.test.php index d3c4ac0ffc..9974a8e810 100755 --- a/tests/main/inc/lib/online.inc.test.php +++ b/tests/main/inc/lib/online.inc.test.php @@ -21,8 +21,8 @@ class TestOnline extends UnitTestCase { ."

    "; $res=chatcall(); - if(!empty($message)){ - $this->assertTrue(is_string($message)); + if (!empty($message)) { + $this->assertTrue(is_string($message)); //var_dump($message); } else { @@ -76,8 +76,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 +90,43 @@ 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); + } + + + function testwho_is_online_in_this_course_count() { + /* $uid=''; + $valid=''; + $rarray = array(); + $barray = array(); + $login_user_id= ''; + $login_date= ''; + array_push($rarray,$barray); + array_push($barray,$login_user_id); + array_push($barray,$login_date); + + $res=who_is_online_in_this_course_count($uid, $valid, $coursecode=null); + if(!empty($barray)){ + $this->assertTrue(is_array($barray)); + //var_dump($str); + } else { + $this->assertTrue(is_bool($barray)); + //var_dump($rarray); + } + //var_dump($rarray);*/ + } + + function testwho_is_online_count() { + /* $valid=''; + $res=who_is_online_count($valid); + $this->assertTrue(is_array($res)); + //var_dump($res);*/ } + + } ?> diff --git a/tests/test_manager.inc.php b/tests/test_manager.inc.php index 52bba703ba..c073f8a80d 100755 --- a/tests/test_manager.inc.php +++ b/tests/test_manager.inc.php @@ -1,38 +1,30 @@ $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(); + } } } - -} diff --git a/whoisonline.php b/whoisonline.php index 945b6e875c..6ea4381322 100755 --- a/whoisonline.php +++ b/whoisonline.php @@ -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 '
    '; @@ -139,7 +137,7 @@ if ((api_get_setting('showonline', 'world') == 'true' && !$_user['user_id']) || if ($_GET['id'] == '') { - echo '

    '.get_lang('Refresh').'

    '; + //echo '

    '.get_lang('Refresh').'

    '; } /*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 '
    '; } else {