From 0c37a62a48721cbf555b4e53833ebf27d8d3ed65 Mon Sep 17 00:00:00 2001 From: Arthur Portugal Date: Wed, 17 Feb 2010 16:13:55 -0500 Subject: [PATCH 1/7] Added new path for the tests CT#191 --- main/inc/lib/main_api.lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index fb1f47a9bf..1c515f8856 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -224,6 +224,7 @@ define('LIBRARY_PATH', 'LIBRARY_PATH'); define('CONFIGURATION_PATH', 'CONFIGURATION_PATH'); define('WEB_LIBRARY_PATH', 'WEB_LIBRARY_PATH'); define('WEB_AJAX_PATH', 'WEB_AJAX_PATH'); +define('SYS_TEST_PATH', 'SYS_TEST_PATH'); // Constants for requesting path conversion. define('TO_WEB', 'TO_WEB'); @@ -313,6 +314,7 @@ require_once dirname(__FILE__).'/internationalization.lib.php'; * api_get_path(WEB_LIBRARY_PATH) http://www.mychamilo.org/chamilo/main/inc/lib/ * api_get_path(LIBRARY_PATH) /var/www/chamilo/main/inc/lib/ * api_get_path(CONFIGURATION_PATH) /var/www/chamilo/main/inc/conf/ + * api_get_path(SYS_TEST_PATH) /var/www/chamilo/tests/ * * This is how we retrieve paths of "registerd" resource files (scripts, players, etc.): * api_get_path(TO_WEB, FLASH_PLAYER_AUDIO) http://www.mychamilo.org/chamilo/main/inc/lib/mediaplayer/player.swf @@ -355,7 +357,8 @@ function api_get_path($path_type, $path = null) { LIBRARY_PATH => 'inc/lib/', CONFIGURATION_PATH => 'inc/conf/', WEB_LIBRARY_PATH => 'inc/lib/', - WEB_AJAX_PATH => 'inc/ajax/' + WEB_AJAX_PATH => 'inc/ajax/', + SYS_TEST_PATH => 'tests/' ); static $resource_paths = array( @@ -472,6 +475,7 @@ function api_get_path($path_type, $path = null) { $paths[WEB_PLUGIN_PATH] = $paths[WEB_PATH].$paths[WEB_PLUGIN_PATH]; $paths[SYS_ARCHIVE_PATH] = $paths[SYS_PATH].$paths[SYS_ARCHIVE_PATH]; $paths[WEB_ARCHIVE_PATH] = $paths[WEB_PATH].$paths[WEB_ARCHIVE_PATH]; + $paths[SYS_TEST_PATH] = $paths[SYS_PATH].$paths[SYS_TEST_PATH]; // A change as of Chamilo 1.8.6.2 // Calculation in the previous way does not rely on configuration settings and in some cases gives unexpected results. //$paths[INCLUDE_PATH] = $include_path_sys; // Old behaviour, Dokeos 1.8.6.1. From 8f8940e4cbbec081dff43c33ea1a6f12310bcdc3 Mon Sep 17 00:00:00 2001 From: Arthur Portugal Date: Wed, 17 Feb 2010 16:14:50 -0500 Subject: [PATCH 2/7] Added new file to load the settings in the constructor CT#191 --- tests/setup.inc.php | 197 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 tests/setup.inc.php diff --git a/tests/setup.inc.php b/tests/setup.inc.php new file mode 100644 index 0000000000..9868961f59 --- /dev/null +++ b/tests/setup.inc.php @@ -0,0 +1,197 @@ + $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']; + + From 465aa1c2060a8292bc1fd0ab52f90a63d3c51426 Mon Sep 17 00:00:00 2001 From: Arthur Portugal Date: Wed, 17 Feb 2010 16:15:24 -0500 Subject: [PATCH 3/7] Added new file to destroy the settings in the constructor CT#191 --- tests/teardown.inc.php | 165 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 tests/teardown.inc.php diff --git a/tests/teardown.inc.php b/tests/teardown.inc.php new file mode 100644 index 0000000000..91e9f42ab3 --- /dev/null +++ b/tests/teardown.inc.php @@ -0,0 +1,165 @@ +assertTrue(is_string($msg)); + } else { + $path = $dirname.'upload'; + $filemode = '0777'; + $res = api_chmod_R($path, $filemode); + unlink($path); + $this->assertTrue($res || IS_WINDOWS_OS); // We know, it does not work for Windows. + } + /* + function testApiIsAllowed(){ + global $_course, $_user; + $tool= 'full'; + $action = 'delete'; + $res=api_is_allowed($tool, $action, $task_id=0); + if(!is_bool($res)){ + $this->assertTrue(is_null($res)); + } + $this->assertTrue($action); + $this->assertTrue($_user['user_id']); + } + + + function testApiNotAllowed(){ + ob_start(); + //api_not_allowed($print_headers = false); + $res = ob_get_contents(); + $this->assertEqual($res,''); + ob_end_clean(); + } + + function testApiIsAllowedToCreateCourse() { + $res=api_is_allowed_to_create_course(); + if(!is_bool($res)){ + $this->assertTrue(is_null($res)); + } + } + + function testApiIsCoach(){ + global $_user; + global $sessionIsCoach; + $_user['user_id']=2; + $sessionIsCoach=Database::store_result($result=false); + $res=api_is_coach(); + $this->assertTrue(is_bool($res)); + //var_dump($res); + $this->assertTrue($_user['user_id']); + $this->assertTrue(is_array($sessionIsCoach)); + //var_dump($sessionIsCoach); + } + + function testApiIsSessionAdmin(){ + global $_user; + $_user['status']=true; + $res=api_is_session_admin(); + $this->assertTrue(is_bool($res)); + $this->assertTrue(is_array($_user)); + //var_dump($_user); + + } + + + function testApiIsCourseCoach() { + $res=api_is_course_coach(); + if(!is_bool($res)){ + $this->assertTrue(is_null($res)); + } + } + + function testApiIsSessionAdmin(){ + global $_user; + $_user['status']=true; + $res=api_is_session_admin(); + $this->assertTrue(is_bool($res)); + $this->assertTrue(is_array($_user)); + //var_dump($_user); + + } + + function testApiNotAllowed(){ + ob_start(); + //api_not_allowed($print_headers = false); + $res = ob_get_contents(); + $this->assertEqual($res,''); + ob_end_clean(); + } + + function testApiSessionDestroy(){ + if (!headers_sent()) { + $res=api_session_destroy(); + } + $this->assertTrue(is_null($res)); + //var_dump($res); + } + + function testApiSessionStart(){ + if (!headers_sent()) { + $res = api_session_start($already_sintalled=true); + } + $this->assertTrue(is_null($res)); + //var_dump($res); + } + */ \ No newline at end of file From ea76a547eccc99f407065dbacd28606d05454ea1 Mon Sep 17 00:00:00 2001 From: Arthur Portugal Date: Wed, 17 Feb 2010 16:19:44 -0500 Subject: [PATCH 4/7] Removed the settings to load in the test_suite.php CT#191 --- tests/test_suite.php | 165 ++++++++++--------------------------------- 1 file changed, 37 insertions(+), 128 deletions(-) diff --git a/tests/test_suite.php b/tests/test_suite.php index ce72a52850..02e26c4d8e 100755 --- a/tests/test_suite.php +++ b/tests/test_suite.php @@ -1,142 +1,52 @@ $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']); - } - - $course_table = Database::get_main_table(TABLE_MAIN_COURSE); - $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY); - $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'); - } - - $_SESSION['_user']['user_id'] = 1; - $_user['user_id'] = $_SESSION['_user']['user_id']; - $_SESSION['is_courseAdmin'] = 1; - $_SESSION['show'] = showall; - - } function TestsSuite() { - $this->setUp(); $this->TestSuite('All tests suite'); /* $this->addTestFile(dirname(__FILE__).'/main/inc/lib/database.lib.test.php'); $this->addTestFile(dirname(__FILE__).'/main/inc/lib/add_course.lib.inc.test.php'); @@ -241,9 +151,8 @@ class TestsSuite extends TestSuite { /**FORUM*/ $this->addTestFile(dirname(__FILE__).'/main/forum/forumfunction.inc.test.php'); - - $this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php');//this file delete the course,session and the use of api_allow - $this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php');//this file need be to the finish of the tests + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/main_api.lib.test.php'); + //$this->addTestFile(dirname(__FILE__).'/main/inc/lib/debug.lib.inc.test.php'); From e958de842e28b51534b3383dc329b461187e575e Mon Sep 17 00:00:00 2001 From: Arthur Portugal Date: Wed, 17 Feb 2010 16:26:00 -0500 Subject: [PATCH 5/7] Added a require_once gradebook_functions.inc.php for the tests CT#191 --- main/forum/forumfunction.inc.php | 509 ++++++++++++++++--------------- 1 file changed, 258 insertions(+), 251 deletions(-) diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 357ed1a6f3..91ce4f2787 100755 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -25,7 +25,7 @@ require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH).'text.lib.php'; require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; -require_once api_get_path(LIBRARY_PATH).'text.lib.php'; +require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; get_notifications_of_user(); /* @@ -112,25 +112,28 @@ function handle_forum_and_forumcategories() { /** * This function displays the form that is used to add a forum category. * -* @param -* @return +* @param array input values +* @return void HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function show_add_forumcategory_form($inputvalues=array()) { $gradebook=Security::remove_XSS($_GET['gradebook']); + // initiate the object $form = new FormValidator('forumcategory','post','index.php?&gradebook='.$gradebook.''); - + // settting the form elements $form->addElement('header', '', get_lang('AddForumCategory')); $form->addElement('text', 'forum_category_title', get_lang('Title'),'class="input_titles" id="category_title"'); + //$form->applyFilter('forum_category_title', 'html_filter'); $form->addElement('html_editor', 'forum_category_comment', get_lang('Comment'), null, array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')); + //$form->applyFilter('forum_category_comment', 'html_filter'); $form->addElement('style_submit_button', 'SubmitForumCategory', get_lang('CreateCategory'), 'class="add"'); - + // setting the rules $form->addRule('forum_category_title', '
'.get_lang('ThisFieldIsRequired'), 'required'); @@ -152,14 +155,15 @@ function show_add_forumcategory_form($inputvalues=array()) { /** * This function displays the form that is used to add a forum category. * -* @param -* @return +* @param array +* @return void HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function show_add_forum_form($inputvalues=array()) { global $_course; + $gradebook=Security::remove_XSS($_GET['gradebook']); // initiate the object $form = new FormValidator('forumcategory', 'post', 'index.php?gradebook='.$gradebook.''); @@ -180,9 +184,11 @@ function show_add_forum_form($inputvalues=array()) { } // The title of the forum $form->addElement('text', 'forum_title', get_lang('Title'),'class="input_titles" id="forum_title"'); + //$form->applyFilter('forum_title', 'html_filter'); // The comment of the forum $form->addElement('html_editor', 'forum_comment', get_lang('Comment'), null, array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')); + //$form->applyFilter('forum_comment', 'html_filter'); // dropdown list: Forum Categories $forum_categories=get_forum_categories(); @@ -310,7 +316,7 @@ function show_add_forum_form($inputvalues=array()) { $form->addElement('html','
'); // The OK button - if (isset($_GET['id']) && $_GET['action']=='edit'){ + if (isset($_GET['id']) && $_GET['action']=='edit') { $class='save'; $text=get_lang('ModifyForum'); }else{ @@ -352,7 +358,7 @@ function show_add_forum_form($inputvalues=array()) { } $form->setDefaults($defaults); // The validation or display - if( $form->validate() ) { + if( $form->validate()) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); @@ -361,12 +367,10 @@ function show_add_forum_form($inputvalues=array()) { } Security::clear_token(); } else { - $token = Security::get_token(); $form->addElement('hidden','sec_token'); $form->setConstants(array('sec_token' => $token)); $form->display(); - } } @@ -378,9 +382,9 @@ function show_add_forum_form($inputvalues=array()) { * @author Julio Montoya , Dokeos * @version february 2006, dokeos 1.8 */ -function delete_forum_image($forum_id) -{ +function delete_forum_image($forum_id) { $table_forums = Database::get_course_table(TABLE_FORUM); + $forum_id = Database::escape_string($forum_id); $sql="SELECT forum_image FROM $table_forums WHERE forum_id = '".$forum_id."' "; $result=Database::query($sql); @@ -391,7 +395,6 @@ function delete_forum_image($forum_id) } else { return false; } - } @@ -401,8 +404,8 @@ function delete_forum_image($forum_id) * some default values. I tried to have both in one function but this gave problems with the handle_forum_and_forumcategories function * (storing was done twice) * -* @param -* @return +* @param array +* @return void HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -416,14 +419,16 @@ function show_edit_forumcategory_form($inputvalues=array()) { $form->addElement('header', '', get_lang('EditForumCategory')); $form->addElement('hidden', 'forum_category_id'); $form->addElement('text', 'forum_category_title', get_lang('Title'),'class="input_titles"'); + //$form->applyFilter('forum_category_title', 'html_filter'); $form->addElement('html_editor', 'forum_category_comment', get_lang('Comment'), null, array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')); + //$form->applyFilter('forum_category_comment', 'html_filter'); $form->addElement('style_submit_button', 'SubmitEditForumCategory',get_lang('ModifyCategory'), 'class="save"'); + global $charset; // setting the default values $defaultvalues['forum_category_id']=$inputvalues['cat_id']; - $defaultvalues['forum_category_title']=prepare4display(api_html_entity_decode($inputvalues['cat_title'],ENT_QUOTES,$charset)); $defaultvalues['forum_category_comment']=prepare4display($inputvalues['cat_comment']); $form->setDefaults($defaultvalues); @@ -452,16 +457,17 @@ function show_edit_forumcategory_form($inputvalues=array()) { /** * This function stores the forum category in the database. The new category is added to the end. * -* @param -* @return +* @param array +* @return void HMTL language variable * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function store_forumcategory($values) { - global $table_categories; global $_course; global $_user; + + $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY); // find the max cat_order. The new forum category is added at the end => max cat_order + & $sql="SELECT MAX(cat_order) as sort_max FROM ".Database::escape_string($table_categories); @@ -487,15 +493,14 @@ function store_forumcategory($values) { } $return_message=get_lang('ForumCategoryAdded'); } - Display :: display_confirmation_message($return_message); } /** * This function stores the forum in the database. The new forum is added to the end. * -* @param -* @return +* @param array +* @return string language variable * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -516,13 +521,10 @@ function store_forum($values) { $new_max=$row['sort_max']+1; } - $session_id = api_get_session_id(); - $clean_title = Database::escape_string(Security::remove_XSS($values['forum_title'])); // forum images - $image_moved=false; if (!empty($_FILES['picture']['name'])) { $upload_ok = process_uploaded_file($_FILES['picture']); @@ -644,6 +646,7 @@ function store_forum($values) { */ function delete_forum_forumcategory_thread($content, $id) { global $_course; + $table_forums = Database::get_course_table(TABLE_FORUM); $table_forums_post = Database::get_course_table(TABLE_FORUM_POST); $table_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD); @@ -699,7 +702,7 @@ function delete_forum_forumcategory_thread($content, $id) { * * @param $post_id the id of the post that will be deleted * @todo write recursive function that deletes all the posts that have this message as parent -* +* @return string language variable * @author Patrick Cool , Ghent University * @author Hubert Borderiou Function cleanead and fixed * @version february 2006 @@ -748,7 +751,7 @@ function delete_post($post_id) { * This can be done by sorting the posts that have the field thread_id=$thread_id and sort them by post_date * * @param $thread_id the id of the thread we want to know the last post of. -* @return an array if there is a last post found, false if there is no post entry linked to that thread => thread will be deleted +* @return an array or bool if there is a last post found, false if there is no post entry linked to that thread => thread will be deleted * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -772,7 +775,7 @@ function check_if_last_post_of_thread($thread_id) { * @param $content what is it that we want to make (in)visible: forum category, forum, thread, post * @param $id the id of the content we want to make invisible * @param $current_visibility_status what is the current status of the visibility (0 = invisible, 1 = visible) -* @return +* @return void string HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -807,33 +810,26 @@ function display_visible_invisible_icon($content, $id, $current_visibility_statu * @param $content what is it that we want to (un)lock: forum category, forum, thread, post * @param $id the id of the content we want to (un)lock * @param $current_visibility_status what is the current status of the visibility (0 = invisible, 1 = visible) -* @return +* @return void display the lock HTML. * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ -function display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters='') -{ +function display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters='') { $id = Security::remove_XSS($id); - if ($current_lock_status=='1') - { + if ($current_lock_status=='1') { echo ''.icon('../img/lock.gif',get_lang('Unlock')).''; } - if ($current_lock_status=='0') - { + if ($current_lock_status=='0') { echo ''; // select the number of posts of the forum $sql3="SELECT count(*) AS number_of_posts, posts.forum_id FROM $table_posts posts, $table_threads threads, ".$table_item_property." item_properties - WHERE posts.thread_id=threads.thread_id - AND threads.thread_id=item_properties.ref - AND item_properties.visibility=1 - AND item_properties.tool='".TOOL_FORUM_THREAD."' - GROUP BY threads.forum_id"; + WHERE posts.thread_id=threads.thread_id + AND threads.thread_id=item_properties.ref + AND item_properties.visibility=1 + AND item_properties.tool='".TOOL_FORUM_THREAD."' + GROUP BY threads.forum_id"; //echo $sql3.'
'; } @@ -1236,27 +1232,35 @@ $table_users = Database :: get_main_table(TABLE_MAIN_USER); // We could do the splitup into student and course admin also but we want to have as much as information about a certain forum as possible // so we do not take too much information into account. This function (or this section of the function) is namely used to fill the forms // when editing a forum (and for the moment it is the only place where we use this part of the function) - else { - // select all the forum information of the given forum (that is not deleted) - $sql="SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties - WHERE forum.forum_id=item_properties.ref - AND forum_id='".Database::escape_string($id)."' - AND item_properties.visibility<>2 - AND item_properties.tool='".TOOL_FORUM."' - $condition_session - ORDER BY forum_order ASC"; - // select the number of threads of the forum - $sql2="SELECT count(*) AS number_of_threads, forum_id FROM $table_threads WHERE forum_id=".Database::escape_string($id)." GROUP BY forum_id"; - // select the number of posts of the forum - $sql3="SELECT count(*) AS number_of_posts, forum_id FROM $table_posts WHERE forum_id=".Database::escape_string($id)." GROUP BY forum_id"; - // select the last post and the poster (note: this is probably no longer needed) - $sql4="SELECT post.post_id, post.forum_id, post.poster_id, post.poster_name, post.post_date, users.lastname, users.firstname - FROM $table_posts post, $table_users users - WHERE forum_id=".Database::escape_string($id)." - AND post.poster_id=users.user_id - GROUP BY post.forum_id - ORDER BY post.post_id ASC"; - } + else { + // select all the forum information of the given forum (that is not deleted) + $sql="SELECT * FROM $table_forums forum , ".$table_item_property." item_properties + WHERE forum.forum_id=item_properties.ref + AND forum_id='".Database::escape_string($id)."' + AND item_properties.visibility<>2 + AND item_properties.tool='".TOOL_FORUM."' + $condition_session + ORDER BY forum_order ASC"; + + // select the number of threads of the forum + $sql2="SELECT count(*) AS number_of_threads, forum_id FROM $table_threads + WHERE forum_id=".Database::escape_string($id)." + GROUP BY forum_id"; + + // select the number of posts of the forum + $sql3="SELECT count(*) AS number_of_posts, forum_id FROM $table_posts + WHERE forum_id=".Database::escape_string($id)." + GROUP BY forum_id"; + + // select the last post and the poster (note: this is probably no longer needed) + $sql4="SELECT post.post_id, post.forum_id, post.poster_id, post.poster_name, post.post_date, users.lastname, users.firstname + FROM $table_posts post, $table_users users + WHERE forum_id=".Database::escape_string($id)." + AND post.poster_id=users.user_id + GROUP BY post.forum_id + ORDER BY post.post_id ASC"; + } + // handling all the forum information $result=Database::query($sql); while ($row=Database::fetch_array($result)) { @@ -1276,6 +1280,7 @@ $table_users = Database :: get_main_table(TABLE_MAIN_USER); $forum_list['number_of_threads']=$row2['number_of_threads'];; } } + // handling the postcount information $result3=Database::query($sql3); while ($row3=Database::fetch_array($result3)) { @@ -1342,6 +1347,7 @@ function get_last_post_information($forum_id, $show_invisibles=false) { AND forum_properties.tool='".TOOL_FORUM."' ORDER BY post.post_id DESC"; $result=Database::query($sql); + if ($show_invisibles==true) { $row=Database::fetch_array($result); $return_array['last_post_id']=$row['post_id']; @@ -1370,17 +1376,18 @@ function get_last_post_information($forum_id, $show_invisibles=false) { /** * Retrieve all the threads of a given forum * -* @param +* @param int forum id * @return an array containing all the information about the threads * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function get_threads($forum_id) { - global $table_item_property; - global $table_threads; - global $table_posts; - global $table_users; + $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $table_users = Database :: get_main_table(TABLE_MAIN_USER); + $thread_list=array(); // important note: it might seem a little bit awkward that we have 'thread.locked as locked' in the sql statement // because we also have thread.* in it. This is because thread has a field locked and post also has the same field @@ -1440,9 +1447,9 @@ function get_threads($forum_id) { * @version february 2006, dokeos 1.8 */ function get_posts($thread_id) { - global $table_posts; - global $table_users; - + $table_users = Database :: get_main_table(TABLE_MAIN_USER); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + // note: change these SQL so that only the relevant fields of the user table are used if (api_is_allowed_to_edit(null,true)) { $sql = "SELECT * FROM $table_posts posts @@ -1472,7 +1479,7 @@ function get_posts($thread_id) { * @param $image_url The url of the image (absolute or relative) * @param $alt The alt text (when the images cannot be displayed). http://www.w3.org/TR/html4/struct/objects.html#adef-alt * @param $title The title of the image. Most browsers display this as 'tool tip'. http://www.w3.org/TR/html4/struct/global.html#adef-title -* +* @return string url image * @todo this is the same as the Display::xxx function, so it can be removed => all calls have to be changed also * * @author Patrick Cool , Ghent University @@ -1487,9 +1494,6 @@ function icon($image_url,$alt='',$title='') { - - - /************************************************************************** NEW TOPIC FUNCTIONS **************************************************************************/ @@ -1506,6 +1510,7 @@ function icon($image_url,$alt='',$title='') { function get_post_information($post_id) { $table_posts = Database :: get_course_table(TABLE_FORUM_POST); $table_users = Database :: get_main_table(TABLE_MAIN_USER); + $sql="SELECT * FROM ".$table_posts."posts, ".$table_users." users WHERE posts.poster_id=users.user_id AND posts.post_id='".Database::escape_string($post_id)."'"; $result=Database::query($sql); $row=Database::fetch_array($result); @@ -1525,13 +1530,13 @@ function get_post_information($post_id) { function get_thread_information($thread_id) { $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); - $thread_id = intval($thread_id); + $sql="SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties WHERE item_properties.tool='".TOOL_FORUM_THREAD."' AND item_properties.ref='".Database::escape_string($thread_id)."' AND threads.thread_id='".Database::escape_string($thread_id)."'"; - $result = Database::query($sql); - $row = Database::fetch_array($result); + $result=Database::query($sql); + $row=Database::fetch_array($result); return $row; } @@ -1539,7 +1544,7 @@ function get_thread_information($thread_id) { * This function retrieves forum thread users details * @param int Thread ID * @param string Course DB name (optional) -* @return array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[]) +* @return resource array Array of type ([user_id=>w,lastname=>x,firstname=>y,thread_id=>z],[]) * @author Christian Fasanando , * @version octubre 2008, dokeos 1.8 */ @@ -1548,6 +1553,7 @@ function get_thread_users_details($thread_id, $db_name = null) { $t_posts = Database :: get_course_table(TABLE_FORUM_POST, (empty($db_name)?null:$db_name)); $t_users = Database :: get_main_table(TABLE_MAIN_USER); $t_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER); + $sql = "SELECT DISTINCT user.user_id, user.lastname, user.firstname, thread_id FROM $t_posts , $t_users user, $t_course_user course_user WHERE poster_id = user.user_id @@ -1556,7 +1562,6 @@ function get_thread_users_details($thread_id, $db_name = null) { AND thread_id = '".Database::escape_string($thread_id)."' AND course_user.status NOT IN('1') AND course_code = '".api_get_course_id()."'"; - $result = Database::query($sql); return $result; } @@ -1629,7 +1634,6 @@ function get_thread_users_not_qualify($thread_id, $db_name = null) { AND post.thread_id = '".Database::escape_string($thread_id)."' AND course_user.status not in('1') AND course_code = '".api_get_course_id()."'"; - $result = Database::query($sql); return $result; } @@ -1649,7 +1653,7 @@ function get_thread_users_not_qualify($thread_id, $db_name = null) { function get_forum_information($forum_id) { $table_forums = Database :: get_course_table(TABLE_FORUM); $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); - $forum_id = intval($forum_id); + $sql="SELECT * FROM ".$table_forums." forums, ".$table_item_property." item_properties WHERE item_properties.tool='".TOOL_FORUM."' AND item_properties.ref='".Database::escape_string($forum_id)."' @@ -1664,14 +1668,14 @@ function get_forum_information($forum_id) { * This function retrieves all the information of a given forumcategory id * * @param $forum_id integer that indicates the forum -* @return array returns -* +* @return array returns if there are category +* @return bool returns if there aren't category * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function get_forumcategory_information($cat_id) { - global $table_categories; - global $table_item_property; + $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY); + $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT * FROM ".$table_categories." forumcategories, ".$table_item_property." item_properties WHERE item_properties.tool='".TOOL_FORUM_CATEGORY."' @@ -1705,22 +1709,23 @@ function count_number_of_forums_in_category($cat_id) { * This function stores a new thread. This is done through an entry in the forum_thread table AND * in the forum_post table because. The threads are also stored in the item_property table. (forum posts are not (yet)) * -* @param -* @return +* @param array +* @return void HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function store_thread($values) { - global $table_threads; - global $table_posts; global $_user; global $_course; global $current_forum; global $origin; - global $forum_table_attachment; + + $forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $gradebook=Security::remove_XSS($_GET['gradebook']); - $upload_ok=1; $has_attachment=false; @@ -1869,7 +1874,6 @@ function show_add_post_form($action='', $id='', $form_values='') { global $charset; $gradebook=Security::remove_XSS($_GET['gradebook']); - // setting the class and text of the form title and submit button if ($_GET['action']=='quote'){ $class='save'; @@ -1921,13 +1925,12 @@ function show_add_post_form($action='', $id='', $form_values='') { $form->addElement('html', '
'); $form->addElement('html',''; - - } } } @@ -2040,11 +2041,10 @@ function show_add_post_form($action='', $id='', $form_values='') { **/ function store_theme_qualify($user_id,$thread_id,$thread_qualify=0,$qualify_user_id=0,$qualify_time,$session_id=null) { $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY,''); - $table_threads =Database::get_course_table(TABLE_FORUM_THREAD,''); + $table_threads = Database::get_course_table(TABLE_FORUM_THREAD,''); + if ($user_id==strval(intval($user_id)) && $thread_id==strval(intval($thread_id)) && $thread_qualify==strval(floatval($thread_qualify))) { - //testing - $sql_string="SELECT thread_qualify_max FROM ". $table_threads ." WHERE thread_id=".$thread_id.";"; $res_string=Database::query($sql_string); $row_string=Database::fetch_array($res_string); @@ -2069,10 +2069,8 @@ function store_theme_qualify($user_id,$thread_id,$thread_qualify=0,$qualify_user $row=Database::fetch_array($rs); $row[1]="update"; return $row; - } - - }else{ + } else { return null; } } @@ -2089,10 +2087,10 @@ function store_theme_qualify($user_id,$thread_id,$thread_qualify=0,$qualify_user * @author Isaac Flores , U.N.A.S University * @version October 2008, dokeos 1.8.6 */ - function show_qualify($option,$couser_id,$forum_id,$user_id,$thread_id){ - + function show_qualify($option,$couser_id,$forum_id,$user_id,$thread_id) { $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY,''); - $table_threads =Database::get_course_table(TABLE_FORUM_THREAD,''); + $table_threads = Database::get_course_table(TABLE_FORUM_THREAD,''); + if ($user_id==strval(intval($user_id)) && $thread_id==strval(intval($thread_id)) && $option==1) { $sql="SELECT qualify FROM ".$table_threads_qualify." WHERE user_id=".$user_id." and thread_id=".$thread_id.";"; @@ -2122,8 +2120,9 @@ function store_theme_qualify($user_id,$thread_id,$thread_qualify=0,$qualify_user * @version October 2008, dokeos 1.8.6 */ function get_historical_qualify($user_id,$thread_id,$opt) { - $my_qualify_log=array(); $table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG,''); + + $my_qualify_log=array(); $opt = Database::escape_string($opt); if ($opt=='false') { $sql="SELECT * FROM ".$table_threads_qualify_log." WHERE thread_id='".Database::escape_string($thread_id)."' and user_id='".Database::escape_string($user_id)."' ORDER BY qualify_time"; @@ -2183,7 +2182,7 @@ function store_qualify_historical($option,$couser_id,$forum_id,$user_id,$thread_ * This function show current thread qualify . * @param integer contains the information the current thread id * @param integer contains the information the current session id -* @return integer +* @return array or null if is empty * @author Isaac Flores , U.N.A.S University * @version December 2008, dokeos 1.8.6 */ @@ -2201,8 +2200,7 @@ function current_qualify_of_thread($thread_id,$session_id) { * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ -function store_reply($values) { - +function store_reply($values) { global $_user; global $_course; global $current_forum; @@ -2213,7 +2211,6 @@ function store_reply($values) { $table_posts = Database :: get_course_table(TABLE_FORUM_POST); $gradebook=Security::remove_XSS($_GET['gradebook']); - $post_date=date('Y-m-d H:i:s'); if ($current_forum['approval_direct_post']=='1' AND !api_is_allowed_to_edit(null,true)) { @@ -2244,7 +2241,6 @@ function store_reply($values) { $result=Database::query($sql); $new_post_id=Database::insert_id(); $values['new_post_id']=$new_post_id; - $message=get_lang('ReplyAdded'); if ($has_attachment) { @@ -2301,7 +2297,7 @@ function store_reply($values) { } send_notification_mails($values['thread_id'], $values); - + session_unregister('formelements'); session_unregister('origin'); session_unregister('breadcrumbs'); @@ -2402,13 +2398,12 @@ function show_edit_post_form($current_post, $current_thread, $current_forum, $fo $form->addElement('textarea','file_comment',get_lang('FileComment'),array ('rows' => 4, 'cols' => 34)); $form->applyFilter('file_comment', 'html_filter'); $form->addElement('html','

'); - if ($current_forum['allow_attachments']=='1' OR api_is_allowed_to_edit(null,true)) { if (empty($form_values) AND !isset($_POST['SubmitPost'])) { //edit_added_resources('forum_post',$current_post['post_id']); } //$form->add_resource_button(); - $values = $form->exportValues(); + $values = $form->exportValues(); } $form->addElement('style_submit_button', 'SubmitPost', get_lang('ModifyThread'), 'class="save"'); @@ -2457,11 +2452,10 @@ function show_edit_post_form($current_post, $current_thread, $current_forum, $fo */ function store_edit_post($values) { global $origin; - + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); $table_posts = Database :: get_course_table(TABLE_FORUM_POST); - $gradebook=Security::remove_XSS($_GET['gradebook']); // first we check if the change affects the thread and if so we commit the changes (sticky and post_title=thread_title are relevant) //if (array_key_exists('is_first_post_of_thread',$values) AND $values['is_first_post_of_thread']=='1') { @@ -2475,11 +2469,10 @@ function store_edit_post($values) { Database::query($sql); //} // update the post_title and the post_text - $sql="UPDATE $table_posts SET - post_title='".Database::escape_string($values['post_title'])."', - post_text='".Database::escape_string($values['post_text'])."', - post_notification='".Database::escape_string(isset($values['post_notification'])?$values['post_notification']:null)."' - WHERE post_id='".Database::escape_string($values['post_id'])."'"; + $sql="UPDATE $table_posts SET post_title='".Database::escape_string(Security::remove_XSS($values['post_title']))."', + post_text='".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['post_text'])),COURSEMANAGERLOWSECURITY))."', + post_notification='".Database::escape_string(isset($values['post_notification'])?$values['post_notification']:null)."' + WHERE post_id='".Database::escape_string($values['post_id'])."'"; Database::query($sql); if (!empty($values['remove_attach'])) { @@ -2571,15 +2564,15 @@ function display_user_image($user_id,$name, $origin='') { /** * The thread view counter gets increased every time someone looks at the thread * -* @param -* @return +* @param int +* @return void * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function increase_thread_view($thread_id) { - global $table_threads; - + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $sql="UPDATE $table_threads SET thread_views=thread_views+1 WHERE thread_id='".Database::escape_string($thread_id)."'"; // this needs to be cleaned first $result=Database::query($sql); } @@ -2594,8 +2587,8 @@ function increase_thread_view($thread_id) { * @version february 2006, dokeos 1.8 */ function update_thread($thread_id, $last_post_id,$post_date) { - global $table_threads; - + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $sql="UPDATE $table_threads SET thread_replies=thread_replies+1, thread_last_post='".Database::escape_string($last_post_id)."', thread_date='".Database::escape_string($post_date)."' WHERE thread_id='".Database::escape_string($thread_id)."'"; // this needs to be cleaned first @@ -2606,9 +2599,7 @@ function update_thread($thread_id, $last_post_id,$post_date) { /** * This function is called when the user is not allowed in this forum/thread/... -* -* @param -* @return +* @return bool display message of "not allowed" * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -2621,9 +2612,7 @@ function forum_not_allowed_here() { /** * This function is used to find all the information about what's new in the forum tool -* -* @param -* @return +* @return void * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -2631,8 +2620,10 @@ function forum_not_allowed_here() { function get_whats_new() { global $_user; global $_course; - global $table_posts; - + + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $tracking_last_tool_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); + // note this has later to be replaced by the tool constant. But temporarily bb_forum is used since this is the only thing that is in the tracking currently. //$tool=TOOL_FORUM; $tool=TOOL_FORUM; // @@ -2641,7 +2632,6 @@ function get_whats_new() { //session_unregister('whatsnew_post_info'); if (!$_SESSION['last_forum_access']) { - $tracking_last_tool_access=Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); $sql="SELECT * FROM ".$tracking_last_tool_access." WHERE access_user_id='".Database::escape_string($_user['user_id'])."' AND access_cours_code='".Database::escape_string($_course['sysCode'])."' AND access_tool='".Database::escape_string($tool)."'"; $result=Database::query($sql); $row=Database::fetch_array($result); @@ -2677,9 +2667,9 @@ function get_whats_new() { * @deprecated the counting mechanism is now inside the function get_forums */ function get_post_topics_of_forum($forum_id) { - global $table_posts; - global $table_threads; - global $table_item_property; + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $sql="SELECT count(*) as number_of_posts FROM $table_posts WHERE forum_id='".$forum_id."'"; if (api_is_allowed_to_edit(null,true)) { @@ -2746,6 +2736,7 @@ function get_post_topics_of_forum($forum_id) { */ function approve_post($post_id, $action) { $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + if ($action=='invisible') { $visibility_value=0; } @@ -2767,14 +2758,14 @@ function approve_post($post_id, $action) { * This is needed to display the icon that there are unapproved messages in that thread (only the courseadmin can see this) * * @param $forum_id the forum where we want to know the unapproved messages of -* @return +* @return array returns * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function get_unaproved_messages($forum_id) { - global $table_posts; - + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $return_array=array(); $sql="SELECT DISTINCT thread_id FROM $table_posts WHERE forum_id='".Database::escape_string($forum_id)."' AND visible='0'"; $result=Database::query($sql); @@ -2789,16 +2780,15 @@ function get_unaproved_messages($forum_id) { * This function sends the notification mails to everybody who stated that they wanted to be informed when a new post * was added to a given thread. * -* @param -* @return +* @param array reply information +* @return void * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function send_notification_mails($thread_id, $reply_info) { - global $table_posts; - global $table_user; - global $table_mailcue; + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $table_mailcue = Database :: get_course_table(TABLE_FORUM_MAIL_QUEUE); // First we need to check if // 1. the forum category is visible @@ -2818,6 +2808,7 @@ function send_notification_mails($thread_id, $reply_info) { if ($send_mails==true) { send_notifications($current_thread['forum_id'],$thread_id); /* + $table_user = Database :: get_main_table(TABLE_MAIN_USER); $sql="SELECT DISTINCT user.firstname, user.lastname, user.email, user.user_id FROM $table_posts post, $table_user user WHERE post.thread_id='".Database::escape_string($thread_id)."' @@ -2848,18 +2839,18 @@ function send_notification_mails($thread_id, $reply_info) { * This function is called whenever something is made visible because there might be new posts and the user might have indicated that (s)he wanted * to be informed about the new posts by mail. * -* @param -* @return +* @param int +* @return string language variable * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function handle_mail_cue($content, $id) { - global $table_mailcue; - global $table_forums; - global $table_threads; - global $table_posts; - global $table_users; + $table_mailcue = Database :: get_course_table(TABLE_FORUM_MAIL_QUEUE); + $table_forums = Database :: get_course_table(TABLE_FORUM); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $table_users = Database :: get_main_table(TABLE_MAIN_USER); // if the post is made visible we only have to send mails to the people who indicated that they wanted to be informed for that thread. if ($content=='post') { @@ -2916,8 +2907,9 @@ function handle_mail_cue($content, $id) { /** * This function sends the mails for the mail notification * -* @param -* @return +* @param array +* @param array +* @return void * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -2944,9 +2936,7 @@ function send_mail($user_info=array(), $thread_information=array()) { /** * This function displays the form for moving a thread to a different (already existing) forum -* -* @param -* @return +* @return void HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -3003,9 +2993,7 @@ function move_thread_form() { /** * This function displays the form for moving a post message to a different (already existing) or a new thread. -* -* @param -* @return +* @return void HTML * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 @@ -3049,17 +3037,18 @@ function move_post_form() { /** * -* @param -* @return +* @param array +* @return string HTML language variable * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function store_move_post($values) { - global $table_posts; - global $table_threads; - global $table_forums; global $_course; + + $table_forums = Database :: get_course_table(TABLE_FORUM); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); if ($values['thread']=='0') { $current_post=get_post_information($values['post_id']); @@ -3117,17 +3106,18 @@ function store_move_post($values) { /** * -* @param -* @return +* @param array +* @return string HTML language variable * * @author Patrick Cool , Ghent University * @version february 2006, dokeos 1.8 */ function store_move_thread($values) { - global $table_posts; - global $table_threads; - global $table_forums; global $_course; + + $table_forums = Database :: get_course_table(TABLE_FORUM); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); // change the thread table: setting the forum_id to the new forum $sql="UPDATE $table_threads SET forum_id='".Database::escape_string($_POST['forum'])."' WHERE thread_id='".Database::escape_string($_POST['thread_id'])."'"; @@ -3153,7 +3143,6 @@ function store_move_thread($values) { function prepare4display($input='') { $highlightcolors = array('yellow', '#33CC33','#3399CC', '#9999FF', '#33CC33'); if (!is_array($input)) { - //search for contents if (!empty($_GET['search'])) { if (strstr($_GET['search'],'+')) { $search_terms = explode('+',$_GET['search']); @@ -3166,7 +3155,6 @@ function prepare4display($input='') { $counter++; } } - return api_html_entity_decode(stripslashes($input)); } else { /*foreach ($input as $key=>$value) @@ -3187,6 +3175,7 @@ function prepare4display($input='') { */ function forum_search() { global $origin; + // initiate the object $form = new FormValidator('forumsearch','post','forumsearch.php?origin='.$origin.''); @@ -3220,12 +3209,13 @@ function forum_search() { * @version march 2008, dokeos 1.8.5 */ function display_forum_search_results($search_term) { + global $origin; + $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY); $table_forums = Database :: get_course_table(TABLE_FORUM); $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); $table_posts = Database :: get_course_table(TABLE_FORUM_POST); - global $origin; $gradebook=Security::remove_XSS($_GET['gradebook']); // defining the search strings as an array if (strstr($search_term,'+')) { @@ -3299,7 +3289,7 @@ function display_forum_search_results($search_term) { */ function search_link() { global $origin; - + $return = ''; if ($origin != 'learnpath') { @@ -3322,14 +3312,14 @@ function search_link() { * This function add a attachment file into forum * @param string a comment about file * @param int last id from forum_post table - * + * @return void */ function add_forum_attachment_file($file_comment,$last_id) { - global $_course; + $agenda_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT); + // Storing the attachments - if(!empty($_FILES['user_upload']['name'])) { $upload_ok = process_uploaded_file($_FILES['user_upload']); } @@ -3376,11 +3366,11 @@ function add_forum_attachment_file($file_comment,$last_id) { * @return void */ function edit_forum_attachment_file($file_comment,$post_id,$id_attach) { - global $_course; + $table_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT); + // Storing the attachments - if(!empty($_FILES['user_upload']['name'])) { $upload_ok = process_uploaded_file($_FILES['user_upload']); } @@ -3428,7 +3418,8 @@ function edit_forum_attachment_file($file_comment,$post_id,$id_attach) { */ function get_attachment($post_id) { - global $forum_table_attachment; + $forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT); + $row=array(); $post_id = intval($post_id); $sql = 'SELECT id, path, filename,comment FROM '. $forum_table_attachment.' WHERE post_id ="'.$post_id.'"'; @@ -3442,16 +3433,17 @@ function get_attachment($post_id) { * Delete the all the attachments from the DB and the file according to the post's id or attach id(optional) * @param post id * @param attach id (optional) + * @return void * @author Julio Montoya Dokeos * @version avril 2008, dokeos 1.8.5 */ function delete_attachment($post_id,$id_attach=0) { global $_course; + $forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT); $cond = (!empty($id_attach))?" id = ".(int)$id_attach."" : " post_id = ".(int)$post_id.""; - $sql="SELECT path FROM $forum_table_attachment WHERE $cond"; $res=Database::query($sql); $row=Database::fetch_array($res); @@ -3467,9 +3459,9 @@ function delete_attachment($post_id,$id_attach=0) { //Delete from forum_attachment table $sql="DELETE FROM $forum_table_attachment WHERE $cond "; - $result=Database::query($sql); $last_id_file=Database::insert_id(); + // update item_property api_item_property_update($_course, TOOL_FORUM_ATTACH, $id_attach ,'ForumAttachmentDelete', api_get_user_id()); @@ -3489,11 +3481,11 @@ function delete_attachment($post_id,$id_attach=0) { * @todo this is basically the same code as the get_forums function. Consider merging the two. */ function get_forums_of_group($group_id) { - global $table_forums; - global $table_threads; - global $table_posts; - global $table_item_property; - global $table_users; + $table_forums = Database :: get_course_table(TABLE_FORUM); + $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); + $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); + $table_users = Database :: get_main_table(TABLE_MAIN_USER); //-------------- Student -----------------// // select all the forum information of all forums (that are visible to students) @@ -3586,7 +3578,7 @@ function get_forums_of_group($group_id) { * * @param string $content does the user want to be notified about a forum or about a thread * @param integer $id the id of the forum or thread - * + * @return string language variable * @author Patrick Cool , Ghent University, Belgium * @version May 2008, dokeos 1.8.5 * @since May 2008, dokeos 1.8.5 @@ -3594,16 +3586,16 @@ function get_forums_of_group($group_id) { function set_notification($content,$id, $add_only = false) { global $_user; + // database table definition + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); + // which database field do we have to store the id in? if ($content == 'forum') { $database_field = 'forum_id'; } else { $database_field = 'thread_id'; } - - // database table definition - $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); - + // first we check if the notification is already set for this $sql = "SELECT * FROM $table_notification WHERE $database_field = '".Database::escape_string($id)."' AND user_id = '".Database::escape_string($_user['user_id'])."'"; $result=Database::query($sql); @@ -3634,13 +3626,15 @@ function set_notification($content,$id, $add_only = false) { * * @param string $content does the user want to be notified about a forum or about a thread * @param integer $id the id of the forum or thread - * + * @return array returns * @author Patrick Cool , Ghent University, Belgium * @version May 2008, dokeos 1.8.5 * @since May 2008, dokeos 1.8.5 */ function get_notifications($content,$id) { - global $table_users; + // database table definition + $table_users = Database :: get_main_table(TABLE_MAIN_USER); + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); // which database field contains the notification? if ($content == 'forum') { @@ -3648,13 +3642,14 @@ function get_notifications($content,$id) { } else { $database_field = 'thread_id'; } - // database table definition - $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); + $sql = "SELECT user.user_id, user.firstname, user.lastname, user.email, user.user_id user FROM $table_users user, $table_notification notification WHERE user.user_id = notification.user_id AND notification.$database_field= '".Database::escape_string($id)."'"; + $result=Database::query($sql); $return = array(); + while ($row=Database::fetch_array($result)) { $return['user'.$row['user_id']]=array('email' => $row['email'], 'user_id' => $row['user_id']); } @@ -3668,7 +3663,7 @@ function get_notifications($content,$id) { * @param integer $forum_id the id of the forum * @param integer $thread_id the id of the thread * @param integer $post_id the id of the post - * @return unknown + * @return bool * * @author Patrick Cool , Ghent University, Belgium * @version May 2008, dokeos 1.8.5 @@ -3721,13 +3716,17 @@ function send_notifications($forum_id=0, $thread_id=0, $post_id=0) { * * @param integer $user_id the user_id of a user (default = 0 => the current user) * @param boolean $force force get the notification subscriptions (even if the information is already in the session - * + * @return array returns * @author Patrick Cool , Ghent University, Belgium * @version May 2008, dokeos 1.8.5 * @since May 2008, dokeos 1.8.5 */ function get_notifications_of_user($user_id = 0, $force = false) { global $_course; + + // database table definition + $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); + $course = api_get_course_id(); if (empty($course) OR $course==-1) { return null; @@ -3736,10 +3735,9 @@ function get_notifications_of_user($user_id = 0, $force = false) { global $_user; $user_id = $_user['user_id']; } - - // database table definition - $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION); + $my_code = isset($_course['code']) ? $_course['code'] : ''; + if (!isset($_SESSION['forum_notification']) OR $_SESSION['forum_notification']['course'] <> $my_code OR $force=true) { $_SESSION['forum_notification']['course'] = $my_code; @@ -3765,6 +3763,7 @@ function get_notifications_of_user($user_id = 0, $force = false) { */ function count_number_of_post_in_thread($thread_id) { $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $sql = "SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' "; $result = Database::query($sql); return count(Database::store_result($result)); @@ -3780,6 +3779,7 @@ function count_number_of_post_in_thread($thread_id) { */ function count_number_of_post_for_user_thread($thread_id, $user_id) { $table_posts = Database :: get_course_table(TABLE_FORUM_POST); + $sql = "SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' AND poster_id = '".Database::escape_string($user_id)."' "; $result = Database::query($sql); @@ -3795,6 +3795,7 @@ function count_number_of_post_for_user_thread($thread_id, $user_id) { */ function count_number_of_user_in_course($course_id) { $table_course_rel_user = Database::get_main_table("course_rel_user"); + $sql = "SELECT * FROM $table_course_rel_user WHERE course_code ='".Database::escape_string($course_id)."' "; $result = Database::query($sql); return count(Database::store_result($result)); @@ -3814,6 +3815,7 @@ function get_statistical_information($thread_id, $user_id, $course_id) { $stadistic['user_course'] = count_number_of_user_in_course($course_id); $stadistic['post'] = count_number_of_post_in_thread($thread_id); $stadistic['user_post'] = count_number_of_post_for_user_thread($thread_id, $user_id); + //$stadistic['average'] = get_average_of_thread_post_user(); return $stadistic; } @@ -3827,10 +3829,9 @@ function get_statistical_information($thread_id, $user_id, $course_id) { * @author Jhon Hinojosa , * @version octubre 2008, dokeos 1.8 */ -function get_thread_user_post($course_db, $thread_id, $user_id ) -{ +function get_thread_user_post($course_db, $thread_id, $user_id ) { $table_posts = Database::get_course_table(TABLE_FORUM_POST, $course_db); - global $table_users; + $table_users = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT * FROM $table_posts posts LEFT JOIN $table_users users @@ -3860,13 +3861,14 @@ function get_thread_user_post($course_db, $thread_id, $user_id ) return $post_list; } -/* This function get the name of an user by id +/** This function get the name of an user by id * @param user_id int * return String * @author Christian Fasanando */ function get_name_user_by_id($user_id) { $t_users = Database :: get_main_table(TABLE_MAIN_USER); + $sql = "SELECT firstname, lastname FROM ".$t_users." WHERE user_id = '".$user_id."' "; $result = Database::query($sql); $row = Database::fetch_array($result); @@ -3892,8 +3894,7 @@ function get_thread_user_post($course_db, $thread_id, $user_id ) * @return string */ - function get_all_post_from_user($user_id, $course_db) - { + function get_all_post_from_user($user_id, $course_db) { $j=0; $forums = get_forums(); krsort($forums); @@ -3943,10 +3944,16 @@ function get_thread_user_post($course_db, $thread_id, $user_id ) return $forum_results; } -function get_thread_user_post_limit($course_db, $thread_id, $user_id, $limit=10) -{ +/** + * @param string + * @param int + * @param int + * @param int + * @return void + */ +function get_thread_user_post_limit($course_db, $thread_id, $user_id, $limit=10) { $table_posts = Database::get_course_table(TABLE_FORUM_POST, $course_db); - global $table_users; + $table_users = Database::get_main_table(TABLE_MAIN_USER); $sql = "SELECT * FROM $table_posts posts LEFT JOIN $table_users users From fcc5a3766f78a00f8bd29ba82e4645697e05a7b8 Mon Sep 17 00:00:00 2001 From: Guillaume Viguier Date: Wed, 17 Feb 2010 16:32:46 -0500 Subject: [PATCH 6/7] Timezone management (see CT#599) --- main/admin/calendar.lib.php | 9 ++++- main/admin/statistics/statistics.lib.php | 4 +-- main/admin/system_announcements.php | 4 +-- main/calendar/agenda.inc.php | 1 + main/calendar/myagenda.inc.php | 4 +-- main/inc/lib/attendance.lib.php | 5 ++- main/inc/lib/main_api.lib.php | 1 + main/inc/lib/notebook.lib.php | 8 +++-- main/inc/lib/tracking.lib.php | 31 ++++++++++------- main/wiki/index.php | 43 ++++++------------------ main/work/work.lib.php | 6 ++-- 11 files changed, 58 insertions(+), 58 deletions(-) diff --git a/main/admin/calendar.lib.php b/main/admin/calendar.lib.php index 80b07dc911..9e59b7e45d 100755 --- a/main/admin/calendar.lib.php +++ b/main/admin/calendar.lib.php @@ -738,6 +738,7 @@ function display_agenda_items() while($myrow=Database::fetch_array($result)) { $is_repeated = !empty($myrow['parent_event_id']); + $myrow["start_date"] = api_get_local_time($myrow["start_date"], null, null, date_default_timezone_get()); echo '',"\n"; /*-------------------------------------------------- display: the month bar @@ -822,6 +823,7 @@ function display_agenda_items() echo "\t\t\n"; // highlight: if a date in the small calendar is clicked we highlight the relevant items + $myrow["start_date"] = api_get_local_time($myrow["start_date"], null, null, date_default_timezone_get()); $db_date=(int)date("d",strtotime($myrow["start_date"])).date("n",strtotime($myrow["start_date"])).date("Y",strtotime($myrow["start_date"])); if ($_GET["day"].$_GET["month"].$_GET["year"] <>$db_date) { @@ -1065,6 +1068,7 @@ function display_one_agenda_item($agenda_id) echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["start_date"]))).""; echo "\n"; echo "\t\t\n"; @@ -1674,6 +1678,7 @@ function get_agendaitems($month, $year) $result = Database::query($sqlquery); while ($item = Database::fetch_array($result)) { + $item['start_date'] = api_get_local_time($item['start_date'], null, null, date_default_timezone_get()); $agendaday = date('j',strtotime($item['start_date'])); $time= date('H:i',strtotime($item['start_date'])); $URL = $portal_url.'main/admin/agenda.php?day='.$agendaday."&month=".$month."&year=".$year; // RH //Patrick Cool: to highlight the relevant agenda item @@ -1996,6 +2001,7 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour // we want to know for each agenda item for this day to wich halfhour it must be assigned + $item['start_date'] = api_get_local_time($item['start_date'], null, null, date_default_timezone_get()); list ($datepart, $timepart) = split(" ", $item['start_date']); list ($year, $month, $day) = explode("-", $datepart); list ($hours, $minutes, $seconds) = explode(":", $timepart); @@ -2105,6 +2111,7 @@ function get_week_agendaitems($courses_dbs, $month, $year, $week = '') while ($item = Database::fetch_array($result)) { + $item['start_date'] = api_get_local_time($item['start_date'], null, null, date_default_timezone_get()); $agendaday = date("j",strtotime($item['start_date'])); $time= date("H:i",strtotime($item['start_date'])); @@ -2191,7 +2198,7 @@ function get_repeated_events_day_view($course_info,$start=0,$end=0,$params) while($row = Database::fetch_array($res)) { $orig_start = $row['orig_start']; - $orig_end = $row['orig_end']; + $orig_end = $row['orig_start']; $repeat_type = $row['cal_type']; switch($repeat_type) { diff --git a/main/admin/statistics/statistics.lib.php b/main/admin/statistics/statistics.lib.php index ab8d0d6322..ac2a8d3280 100755 --- a/main/admin/statistics/statistics.lib.php +++ b/main/admin/statistics/statistics.lib.php @@ -116,7 +116,7 @@ class Statistics $res = Database::query($sql); $activities = array (); while ($row = Database::fetch_row($res)) { - $row[4] = api_format_date(DATE_TIME_FORMAT_LONG, strtotime($row[4])); + $row[4] = api_get_local_time($row[4], DATE_TIME_FORMAT_LONG, null, date_default_timezone_get()); $activities[] = $row; } return $activities; @@ -419,7 +419,7 @@ class Statistics { $course = array (); $course[]= ''.$obj->access_cours_code.' '; - $course[] = $obj->access_date; + $course[] = api_get_local_time($obj->access_date, null, null, date_default_timezone_get()); $courses[] = $course; } $parameters['action'] = 'courselastvisit'; diff --git a/main/admin/system_announcements.php b/main/admin/system_announcements.php index 479a5b7726..c57a6be2a3 100755 --- a/main/admin/system_announcements.php +++ b/main/admin/system_announcements.php @@ -284,8 +284,8 @@ if ($show_announcement_list) $row = array (); $row[] = $announcement->id; $row[] = Display::return_icon(($announcement->visible ? 'accept.png' : 'exclamation.png'), ($announcement->visible ? get_lang('AnnouncementAvailable') : get_lang('AnnouncementNotAvailable'))); - $row[] = $announcement->date_start; - $row[] = $announcement->date_end; + $row[] = api_get_local_time($announcement->date_start, null, null, date_default_timezone_get()); + $row[] = api_get_local_time($announcement->date_end, null, null, date_default_timezone_get()); $row[] = "id."&person=".VISIBLE_TEACHER."&action=". ($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'visible.gif' : 'invisible.gif'), get_lang('show_hide')).""; $row[] = "id."&person=".VISIBLE_STUDENT."&action=". ($announcement->visible_student ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_student ? 'visible.gif' : 'invisible.gif'), get_lang('show_hide')).""; $row[] = "id."&person=".VISIBLE_GUEST."&action=". ($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'visible.gif' : 'invisible.gif'), get_lang('show_hide')).""; diff --git a/main/calendar/agenda.inc.php b/main/calendar/agenda.inc.php index b1e337a16d..929c210132 100755 --- a/main/calendar/agenda.inc.php +++ b/main/calendar/agenda.inc.php @@ -3477,6 +3477,7 @@ function get_day_agendaitems($courses_dbs, $month, $year, $day) { // in the display_daycalendar function we use $i (ranging from 0 to 47) for each halfhour // we want to know for each agenda item for this day to wich halfhour it must be assigned + $item['start_date'] = api_get_local_time($item['start_date'], null, null, date_default_timezone_get()); list ($datepart, $timepart) = split(" ", $item['start_date']); list ($year, $month, $day) = explode("-", $datepart); list ($hours, $minutes, $seconds) = explode(":", $timepart); diff --git a/main/calendar/myagenda.inc.php b/main/calendar/myagenda.inc.php index f2011f2399..95d98e799d 100755 --- a/main/calendar/myagenda.inc.php +++ b/main/calendar/myagenda.inc.php @@ -117,8 +117,8 @@ function get_myagendaitems($courses_dbs, $month, $year) $agendaday = date("j",strtotime($item['start_date'])); if(!isset($items[$agendaday])){$items[$agendaday]=array();} - $time= date("H:i",strtotime($item['start_date'])); - $end_time= date("H:i",strtotime($item['end_date'])); + $time = api_get_local_time($item['start_date'], "H:i", null, date_default_timezone_get()); + $end_time = api_get_local_time($item['end_date'], "H:i", null, date_default_timezone_get()); $URL = api_get_path(WEB_PATH)."main/calendar/agenda.php?cidReq=".urlencode($array_course_info["code"])."&day=$agendaday&month=$month&year=$year#$agendaday"; // RH //Patrick Cool: to highlight the relevant agenda item if ($setting_agenda_link == 'coursecode') { $title=$array_course_info['title']; diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php index 4fe1ad3420..5806dca779 100755 --- a/main/inc/lib/attendance.lib.php +++ b/main/inc/lib/attendance.lib.php @@ -600,7 +600,8 @@ class Attendance $res = Database::query($sql); if (Database::num_rows($res) > 0) { while ($row = Database::fetch_array($res)) { - $row['date_time'] = api_format_date($dateTimeFormatLong, strtotime($row['date_time'])); + $row['date_time'] = api_get_local_time($row['date_time'], $dateTimeFormatLong, null, date_default_timezone_get()); + //$row['date_time'] = api_format_date($dateTimeFormatLong, strtotime($row['date_time'])); $data[$user_id][] = $row; } } @@ -660,6 +661,7 @@ class Attendance $data = array(); if (Database::num_rows($rs) > 0) { while ($row = Database::fetch_array($rs)) { + $row['date_time'] = api_get_local_time($row['date_time'], null, null, date_default_timezone_get()); $data = $row; } } @@ -680,6 +682,7 @@ class Attendance $data = array(); if (Database::num_rows($rs) > 0) { while ($row = Database::fetch_array($rs)) { + $row['date_time'] = api_get_local_time($row['date_time'], null, null, date_default_timezone_get()); $row['date'] = api_format_date($dateFormatShort, strtotime($row['date_time'])); $row['time'] = api_format_date($timeNoSecFormat, strtotime($row['date_time'])); $data[] = $row; diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 1c515f8856..7e63c4bd2f 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -4518,6 +4518,7 @@ function api_get_local_time($time, $format=null, $to_timezone=null, $from_timezo $use_users_timezone = api_get_setting('use_users_timezone', 'timezones'); if ($use_users_timezone == 'true') { // Get the timezone based on user preference, if it exists + require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; $timezone_user = UserManager::get_extra_user_data_by_field($_user['user_id'],'timezone'); if ($timezone_user['timezone'] != null) { $to_timezone = $timezone_user['timezone']; diff --git a/main/inc/lib/notebook.lib.php b/main/inc/lib/notebook.lib.php index 9f7da9f308..16ac813587 100644 --- a/main/inc/lib/notebook.lib.php +++ b/main/inc/lib/notebook.lib.php @@ -197,10 +197,12 @@ class NotebookManager while ($row = Database::fetch_array($result)) { //validacion when belongs to a session $session_img = api_get_session_image($row['session_id'], $_user['status']); + $creation_date = api_get_local_time($row['creation_date'], null, null, date_default_timezone_get()); + $update_date = api_get_local_time($row['update_date'], null, null, date_default_timezone_get()); echo '
'; - echo ' ('.get_lang('CreationDate').': '.date_to_str_ago($row['creation_date']).'  '.$row['creation_date'].''; + echo ' ('.get_lang('CreationDate').': '.date_to_str_ago($creation_date).'  '.$creation_date.''; if ($row['update_date'] <> $row['creation_date']) { - echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($row['update_date']).'  '.$row['update_date'].''; + echo ', '.get_lang('UpdateDate').': '.date_to_str_ago($update_date).'  '.$update_date.''; } echo ')'; echo $row['title'] . $session_img; @@ -214,4 +216,4 @@ class NotebookManager //return $return; } } -?> \ No newline at end of file +?> diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 9b4a754a8a..008ded7b3a 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -103,7 +103,8 @@ class Tracking { if(Database::num_rows($rs)>0) { if ($first_login_date = Database::result($rs, 0, 0)) { - return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date)); + $first_login_date_local = api_get_local_time($first_login_date, null, null, date_default_timezone_get()); + return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date_local)); } } return false; @@ -120,6 +121,7 @@ class Tracking { { if ($last_login_date = Database::result($rs, 0, 0)) { + $last_login_date = api_get_local_time($last_login_date, null, null, date_default_timezone_get()); if ($return_timestamp) { return strtotime($last_login_date); @@ -163,6 +165,7 @@ class Tracking { if(Database::num_rows($rs)>0) { if ($first_login_date = Database::result($rs, 0, 0)) { + $first_login_date = api_get_local_time($first_login_date, null, null, date_default_timezone_get()); return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date)); } } @@ -180,6 +183,7 @@ class Tracking { if(Database::num_rows($rs)>0) { if ($last_login_date = Database::result($rs, 0, 0)) { + $last_login_date = api_get_local_time($last_login_date, null, null, date_default_timezone_get()); $timestamp = strtotime($last_login_date); $currentTimestamp = mktime(); //If the last connection is > than 7 days, the text is red @@ -1048,7 +1052,7 @@ class Tracking { $rs = Database::query($sql); $row = Database::fetch_array($rs); - $last_connection = $row['access_date']; + $last_connection = api_get_local_time($row['access_date'], null, null, date_default_timezone_get()); if (!empty($last_connection)) { $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection)); $time = explode(' ',$last_connection); @@ -1343,7 +1347,7 @@ class TrackingCourseLog { $row[1] = get_lang($row[1]); - $row[5] = api_ucfirst(format_locale_date($dateTimeFormatLong, strtotime($row['col5']))); + $row[5] = api_ucfirst(api_get_local_time($row['col5'], $dateTimeFormatLong, null, date_default_timezone_get())); $row[4] = ''; if ($table_name['table_name'] == 'document') { @@ -1724,7 +1728,7 @@ class TrackingUserLog { */ function display_exercise_tracking_info($view, $user_id, $course_id) { - global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES; + global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $dateTimeFormatLong; if(substr($view,1,1) == '1') { $new_view = substr_replace($view,'0',1,1); @@ -1770,7 +1774,7 @@ class TrackingUserLog { if (is_array($results)) { for($i = 0; $i < sizeof($results); $i++) { - $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]); + $display_date = api_get_local_time($results[$i][3], $dateTimeFormatLong, null, date_default_timezone_get()); echo "
\n"; echo "\n"; echo "\n"; @@ -1788,7 +1792,7 @@ class TrackingUserLog { $title = GetQuizName($hpresults[$i][0],''); if ($title == '') $title = basename($hpresults[$i][0]); - $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]); + $display_date = api_get_local_time($hpresults[$i][3], $dateTimeFormatLong, null, date_default_timezone_get()); ?> @@ -1856,7 +1860,8 @@ class TrackingUserLog { if (is_array($results)) { for($j = 0 ; $j < count($results) ; $j++) { $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3]; - $timestamp = strtotime($results[$j][0]); + $upload_date = api_get_local_time($results[$j][0], null, null, date_default_timezone_get()); + $timestamp = strtotime($upload_date); $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp); echo ""; echo "
"; if ($myrow["end_date"]<>"0000-00-00 00:00:00") { + $myrow["end_date"] = api_get_local_time($myrow["end_date"], null, null, date_default_timezone_get()); echo get_lang("EndTimeWindow").": "; echo api_ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["end_date"])))."   "; echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["end_date"]))).""; @@ -1009,6 +1011,7 @@ function display_one_agenda_item($agenda_id) echo "\t
".get_lang("EndTime").": "; + $myrow["end_date"] = api_get_local_time($myrow["end_date"], null, null, date_default_timezone_get()); echo api_ucfirst(format_locale_date($dateFormatLong,strtotime($myrow["end_date"])))."   "; echo ucfirst(strftime($timeNoSecFormat,strtotime($myrow["end_date"]))).""; echo "
".$results[$i][0]."".$display_date."
" @@ -2055,7 +2060,7 @@ class TrackingUserLogCSV { */ function display_exercise_tracking_info($view, $user_id, $course_id) { - global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES; + global $TABLECOURSE_EXERCICES, $TABLETRACK_EXERCICES, $TABLETRACK_HOTPOTATOES, $dateTimeFormatLong; if(substr($view,1,1) == '1') { $new_view = substr_replace($view,'0',1,1); @@ -2087,7 +2092,7 @@ class TrackingUserLogCSV { { for($i = 0; $i < sizeof($results); $i++) { - $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $results[$i][3]); + $display_date = api_get_local_time($results[$i][3], $dateTimeFormatLong, null, date_default_timezone_get()); $line .= $results[$i][0].";".$display_date.";".$results[$i][1]." / ".$results[$i][2]."\n"; } } @@ -2105,8 +2110,9 @@ class TrackingUserLogCSV { if ($title == '') $title = basename($hpresults[$i][0]); + + $display_date = api_get_local_time($hpresults[$i][3], $dateTimeFormatLong, null, date_default_timezone_get()); - $display_date = format_locale_date(get_lang('dateTimeFormatLong'), $hpresults[$i][3]); $line .= $title.';'.$display_date.';'.$hpresults[$i][1].'/'.$hpresults[$i][2]."\n"; } } @@ -2155,7 +2161,8 @@ class TrackingUserLogCSV { for($j = 0 ; $j < count($results) ; $j++) { $pathToFile = api_get_path(WEB_COURSE_PATH).$_course['path']."/".$results[$j][3]; - $timestamp = strtotime($results[$j][0]); + $upload_date = api_get_local_time($results[$j][0], null, null, date_default_timezone_get()); + $timestamp = strtotime($upload_date); $beautifulDate = format_locale_date($dateTimeFormatLong,$timestamp); $line .= $results[$j][1].";".$results[$j][2].";".$beautifulDate."\n"; } @@ -2252,4 +2259,4 @@ class TrackingUserLogCSV { return array($title_line, $line); } } -?> \ No newline at end of file +?> diff --git a/main/wiki/index.php b/main/wiki/index.php index dd04903ed6..99b83f9e51 100755 --- a/main/wiki/index.php +++ b/main/wiki/index.php @@ -1362,7 +1362,7 @@ if ($_GET['action']=='edit') //check tasks if (!empty($row['startdate_assig']) && $row['startdate_assig']!='0000-00-00 00:00:00' && time()strtotime($row['enddate_assig']) && $row['enddate_assig']!='0000-00-00 00:00:00' && $row['delayedsubmit']==0) { - $message=get_lang('TheDeadlineHasBeenCompleted').': '.$row['enddate_assig']; + $message=get_lang('TheDeadlineHasBeenCompleted').': '.api_get_local_time($row['enddate_assig'], null, null, date_default_timezone_get()); Display::display_warning_message($message); if(!api_is_allowed_to_edit(false,true)) { @@ -1414,7 +1414,7 @@ if ($_GET['action']=='edit') } else { - $message_task_startdate=$row['startdate_assig']; + $message_task_startdate=api_get_local_time($row['startdate_assig'], null, null, date_default_timezone_get()); } if ($row['enddate_assig']=='0000-00-00 00:00:00') @@ -1423,7 +1423,7 @@ if ($_GET['action']=='edit') } else { - $message_task_endate=$row['enddate_assig']; + $message_task_endate=api_get_local_time($row['enddate_assig'], null, null, date_default_timezone_get()); } if ($row['delayedsubmit']==0) @@ -1767,13 +1767,6 @@ if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifference { $userinfo=Database::get_user_info_from_id($row['user_id']); - $year = substr($row['dtime'], 0, 4); - $month = substr($row['dtime'], 5, 2); - $day = substr($row['dtime'], 8, 2); - $hours=substr($row['dtime'], 11,2); - $minutes=substr($row['dtime'], 14,2); - $seconds=substr($row['dtime'], 17,2); - echo '
  • '; ($counter==0) ? $oldstyle='style="visibility: hidden;"':$oldstyle=''; ($counter==0) ? $newchecked=' checked':$newchecked=''; @@ -1784,7 +1777,7 @@ if ($_GET['action']=='history' or Security::remove_XSS($_POST['HistoryDifference echo ''; echo ''; - echo $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; + echo api_get_local_time($row['dtime'], null, null, date_default_timezone_get()); echo ''; echo ' ('.get_lang('Version').' '.$row['version'].')'; echo ' '.get_lang('By').' '; @@ -1957,14 +1950,6 @@ if ($_GET['action']=='recentchanges') //get author $userinfo=Database::get_user_info_from_id($obj->user_id); - //get time - $year = substr($obj->dtime, 0, 4); - $month = substr($obj->dtime, 5, 2); - $day = substr($obj->dtime, 8, 2); - $hours = substr($obj->dtime, 11,2); - $minutes = substr($obj->dtime, 14,2); - $seconds = substr($obj->dtime, 17,2); - //get type assignment icon if($obj->assignment==1) { @@ -1991,7 +1976,7 @@ if ($_GET['action']=='recentchanges') $row = array (); - $row[] = $year.'-'.$month.'-'.$day.' '.$hours.':'.$minutes.":".$seconds; + $row[] = api_get_local_time($obj->dtime, null, null, date_default_timezone_get()); $row[] = $ShowAssignment.$icon_task; $row[] = ''.$obj->title.''; $row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy'); @@ -2047,14 +2032,6 @@ if ($_GET['action']=='allpages') //get author $userinfo=Database::get_user_info_from_id($obj->user_id); - //get time - $year = substr($obj->dtime, 0, 4); - $month = substr($obj->dtime, 5, 2); - $day = substr($obj->dtime, 8, 2); - $hours = substr($obj->dtime, 11,2); - $minutes = substr($obj->dtime, 14,2); - $seconds = substr($obj->dtime, 17,2); - //get type assignment icon if($obj->assignment==1) { @@ -2083,7 +2060,7 @@ if ($_GET['action']=='allpages') $row[] =$ShowAssignment.$icon_task; $row[] = ''.Security::remove_XSS($obj->title).''; $row[] = $obj->user_id <>0 ? ''.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'' : get_lang('Anonymous').' ('.$obj->user_ip.')'; - $row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds; + $row[] = api_get_local_time($obj->dtime, null, null, date_default_timezone_get()); if(api_is_allowed_to_edit(false,true)|| api_is_platform_admin()) { @@ -2125,7 +2102,7 @@ if ($_GET['action']=='discuss') $sql='SELECT * FROM '.$tbl_wiki.'WHERE reflink="'.html_entity_decode(Database::escape_string(stripslashes(urldecode($page)))).'" AND '.$groupfilter.$condition_session.' ORDER BY id DESC'; $result=Database::query($sql); $row=Database::fetch_array($result); - $lastversiondate=$row['dtime']; + $lastversiondate=api_get_local_time($row['dtime'], null, null, date_default_timezone_get()); $lastuserinfo=Database::get_user_info_from_id($row['user_id']); //select page to discuss @@ -2408,7 +2385,7 @@ if ($_GET['action']=='discuss') echo '

    '; echo ''; echo ''; - echo ''; + echo ''; echo ''; echo ''; echo ''; @@ -2452,4 +2429,4 @@ FOOTER */ //$_SESSION['_gid']; Display::display_footer(); -?> \ No newline at end of file +?> diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 440e893e4c..f3b7067928 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -718,6 +718,7 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou } if ($direc_date!='' && $direc_date!='0000-00-00 00:00:00') { + $direc_date = api_get_local_time($direc_date, null, null, date_default_timezone_get()); $my_direc_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($direc_date))).'    '; $my_direc_date .= ucfirst(strftime($timeNoSecFormat,strtotime($direc_date))); $row[]= date_to_str_ago($direc_date).'
    '.$my_direc_date.''.''; @@ -779,8 +780,9 @@ function display_student_publications_list($work_dir,$sub_course_dir,$currentCou $row[]= build_document_icon_tag('file',$work->url); $row[]= ''.get_lang('Save').''.$work->title.'
    '.$work->description; $row[]= display_user_link_work($row2['insert_user_id'],$work->author).$qualification_string;// $work->author; - $sent_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($work->sent_date))).'    '; - $sent_date .= ucfirst(strftime($timeNoSecFormat,strtotime($work->sent_date))); + $work_sent_date = api_get_local_time($work->sent_date, null, null, date_default_timezone_get()); + $sent_date = api_ucfirst(format_locale_date($dateFormatShort,strtotime($work_sent_date))).'    '; + $sent_date .= ucfirst(strftime($timeNoSecFormat,strtotime($work_sent_date))); $row[]= date_to_str_ago($work->sent_date).$add_string.'
    '.$sent_date.''.''; if( $is_allowed_to_edit) { From 2b79ce8ec248538cb199925d22ff6df223498551 Mon Sep 17 00:00:00 2001 From: Carlos Vargas Date: Wed, 17 Feb 2010 16:38:50 -0500 Subject: [PATCH 7/7] Create scorm.class.test.php CT#191 --- tests/main/newscorm/scorm.class.test.php | 184 +++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 tests/main/newscorm/scorm.class.test.php diff --git a/tests/main/newscorm/scorm.class.test.php b/tests/main/newscorm/scorm.class.test.php new file mode 100644 index 0000000000..b0e02bba50 --- /dev/null +++ b/tests/main/newscorm/scorm.class.test.php @@ -0,0 +1,184 @@ +scorm($course_code=null,$resource_id=null,$user_id=null); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + }*/ + + function testOpen() { + //ob_start(); + $id = 1; + $res = scorm::open($id); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testParseManifest() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->parse_manifest($file=''); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testImportManifest() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->import_manifest($course_code = 'COURSETEST'); + $this->assertTrue(is_null($res)); + //ob_end_clean(); + //var_dump($res); + } + /* + function testImportLocalPackage() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->import_local_package($file_path,$current_dir=''); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testImportPackage() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->import_package($zip_file_info,$current_dir = ''); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + }*/ + + function testSetProximity() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->set_proximity($proxy=''); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testSetTheme() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->set_theme($theme='Chamilo'); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testSetPreviewImage() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->set_preview_image($preview_image=''); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testSetAuthor() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->set_author($author=''); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testSetMaker() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->set_maker($maker=''); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testExportZip() { + //ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->export_zip($lp_id=null); + $this->assertTrue(is_bool($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testGetResPath() { + //ob_start(); + $res = scorm::get_res_path($id=1); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testGetResType() { + //ob_start(); + $res = scorm::get_res_type($id = 1); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testGetTitle() { + //ob_start(); + $res = scorm::get_title(); + $this->assertTrue(is_string($res)); + //ob_end_clean(); + //var_dump($res); + } + + function testReimportManifest() { + ob_start(); + $course_code = 'COURSETEST'; + $resource_id = 1; + $user_id = 1; + $obj = new scorm($course_code, $resource_id, $user_id); + $res = $obj->reimport_manifest($course = 'COURSETEST',$lp_id=null,$imsmanifest_path=''); + $this->assertTrue(is_bool($res)); + ob_end_clean(); + //var_dump($res); + } +} +?> \ No newline at end of file
    '.$author_photo.''.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).' ('.$author_status.') '.$row['dtime'].' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.' '.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).' ('.$author_status.') '.api_get_local_time($row['dtime'], null, null, date_default_timezone_get()).' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.'
    '.$row['comment'].'