diff --git a/main/inc/banner.inc.php b/main/inc/banner.inc.php index 04c9b23b3d..debec0f2dd 100644 --- a/main/inc/banner.inc.php +++ b/main/inc/banner.inc.php @@ -13,7 +13,7 @@ - '; + '; echo ''; - + echo '
'; } - + /** * Displays edit task form @@ -1803,10 +1803,10 @@ class Blog { // form echo '
'; - + // form title echo '
'.get_lang('AssignTask').'
'; - + // user echo '
@@ -1816,7 +1816,7 @@ class Blog { '.$select_user_list.'
'; - + // task echo '
@@ -1869,10 +1869,10 @@ class Blog { echo "\t\t\t\t\n"; } echo ' - '; + '; echo '
-
'; - + '; + // submit echo '
@@ -1882,9 +1882,9 @@ class Blog {
-
'; - - + '; + + echo '
'; echo '
'; @@ -1927,7 +1927,7 @@ class Blog { $arrUserTasks[] = $row['task_id']; } */ - + // Get assignd date; $sql = " SELECT target_date @@ -2126,7 +2126,7 @@ class Blog { task_id = " . (int)$old_task_id . " AND target_date = '" . Database::escape_string($old_target_date) . "' "; - + $result = @api_sql_query($sql, __FILE__, __LINE__); } } @@ -2165,7 +2165,7 @@ class Blog { // Display echo '' . get_lang('SelectTaskArticle') . ' "' . stripslashes($row['title']) . '"'; echo ''.stripslashes($row['description']) . '

'; - + if(Database::num_rows($result) > 0) { @@ -2239,9 +2239,9 @@ class Blog { $tbl_users = Database::get_main_table(TABLE_MAIN_USER); $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); - + echo '
'.get_lang('SubscribeMembers').'
'; - + $properties["width"] = "100%"; // Get blog members' id. @@ -2250,7 +2250,7 @@ class Blog { ON user.user_id = blogs_rel_user.user_id WHERE blogs_rel_user.blog_id = '".intval($blog_id)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - + $blog_member_ids = array (); while($user = Database::fetch_array($result)) { @@ -2268,20 +2268,20 @@ class Blog { } $column_header[] = array (get_lang('Email'), true, ''); $column_header[] = array (get_lang('Register'), false, ''); - + include_once (api_get_path(LIBRARY_PATH)."/course.lib.php"); include_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php"); - + if(isset($_SESSION['session_id'])){ $session_id = intval($_SESSION['session_id']); } else{ $session_id = 0; } - - $student_list = CourseManager :: get_student_list_from_course_code($currentCourse, true, $session_id); + + $student_list = CourseManager :: get_student_list_from_course_code($currentCourse, true, $session_id); $user_data = array (); - + // Add users that are not in this blog to the list. foreach($student_list as $key=>$user) { if(isset($user['id_user'])) { @@ -2314,13 +2314,13 @@ class Blog { // Display $query_vars['action'] = 'manage_members'; - $query_vars['blog_id'] = $blog_id; + $query_vars['blog_id'] = $blog_id; echo '
'; Display::display_sortable_table($column_header, $user_data,null,null,$query_vars); $link = ''; $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']) . '&' : ''; $link .= "blog_id=$blog_id&"; - + echo '' . get_lang('SelectAll') . ' - '; echo '' . get_lang('UnSelectAll') . ' '; echo get_lang('WithSelected') . ' : '; @@ -2423,8 +2423,8 @@ class Blog { Display::display_sortable_table($column_header, $user_data,null,null,$query_vars); $link = ''; $link .= isset ($_GET['action']) ? 'action=' . Security::remove_XSS($_GET['action']). '&' : ''; - $link .= "blog_id=$blog_id&"; - + $link .= "blog_id=$blog_id&"; + echo '' . get_lang('SelectAll') . ' - '; echo '' . get_lang('UnSelectAll') . ' '; echo get_lang('WithSelected') . ' : '; @@ -2462,12 +2462,12 @@ class Blog { */ public static function display_new_comment_form ($blog_id, $post_id, $title) { echo ''; - + // form title echo '
'; echo (isset($_GET['task_id']) ? get_lang('ExecuteThisTask') : get_lang('AddNewComment')); echo '
'; - + // comment title echo '
@@ -2479,7 +2479,7 @@ class Blog {
'; // comment text - $oFCKeditor = new FCKeditor('comment_text') ; + $oFCKeditor = new FCKeditor('comment_text') ; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '200'; if(!api_is_allowed_to_edit()) @@ -2489,7 +2489,7 @@ class Blog { else { $oFCKeditor->ToolbarSet = 'ProjectComment'; - } + } $oFCKeditor->Value = isset($_POST['comment_text'])?stripslashes($_POST['comment_text']):''; echo '
@@ -2498,8 +2498,8 @@ class Blog {
'; echo $oFCKeditor->Create() ; echo '
-
'; - +
'; + // attachment echo '
@@ -2519,7 +2519,7 @@ class Blog {
'; - + // attachment comment echo '
@@ -2577,7 +2577,7 @@ class Blog { $numberofdays[2] = 29; //Get the first day of the month - $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); + $dayone = getdate(mktime(0, 0, 0, $month, 1, $year)); $monthName = $MonthsLong[$month-1]; //Start the week on monday @@ -2682,10 +2682,10 @@ class Blog { echo '' . $curday . ''; else echo $dayheader; - - if (count($tasks) > 0) + + if (count($tasks) > 0) { - if (is_array($tasks[$curday])) + if (is_array($tasks[$curday])) { // Add tasks to calendar foreach ($tasks[$curday] as $task) @@ -2694,7 +2694,7 @@ class Blog { } } } - + echo "\n"; $curday ++; @@ -2720,7 +2720,7 @@ class Blog { ' . get_lang('AddBlog') . '
- +
*' . get_lang('Title') . ' @@ -2729,7 +2729,7 @@ class Blog {
- +
' . get_lang('Subtitle') . ' @@ -2737,8 +2737,8 @@ class Blog {
-
- +
+
@@ -2747,11 +2747,11 @@ class Blog {
-
+
'; - + } /** @@ -2777,8 +2777,8 @@ class Blog {
' . get_lang('EditBlog') . '
- - + +
*' . get_lang('Title') . ' @@ -2787,7 +2787,7 @@ class Blog {
- +
' . get_lang('Subtitle') . ' @@ -2795,8 +2795,8 @@ class Blog {
-
- +
+
@@ -2806,7 +2806,7 @@ class Blog {
- +
'; @@ -2827,21 +2827,21 @@ class Blog { while ($row_project=Database::fetch_row($result)) { $list_info[]=$row_project; } - + $list_content_blog = array(); $list_body_blog = array(); - + if (is_array($list_info)) { foreach($list_info as $key => $info_log) { - + $url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&".api_get_cidreq(); $title = $info_log[0]; $image = '' . $title . ''."\n"; $list_name = '
' . $image . '
' .$title. '' ."\n"; - + $list_body_blog[] = $list_name; $list_body_blog[] = $info_log[1]; - + $visibility_icon=($info_log[2]==0) ? 'invisible' : 'visible'; $visibility_info=($info_log[2]==0) ? 'Visible' : 'Invisible'; $my_image.=''; @@ -2854,16 +2854,16 @@ class Blog { $my_image.=''; $my_image.=''; $my_image.="\n"; - + $list_body_blog[]=$my_image; $my_image=''; - + $list_content_blog[]=$list_body_blog; $list_body_blog = array(); - + } $parameters=''; - //$parameters=array('action'=>Security::remove_XSS($_GET['action'])); + //$parameters=array('action'=>Security::remove_XSS($_GET['action'])); $table = new SortableTableFromArrayConfig($list_content_blog, 1,20,'project'); //$table->set_additional_parameters($parameters); $table->set_header(0, get_lang('Title')); @@ -2871,7 +2871,7 @@ class Blog { $table->set_header(2, get_lang('Modify')); $table->display(); } - + /*$sql = "SELECT blog_id, blog_name, blog_subtitle, visibility FROM $tbl_blogs ORDER BY blog_name"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -2905,35 +2905,35 @@ class Blog { } /** - * + * * END CLASS BLOG - * + * */ /** * Show a list with all the attachments according the parameter's * @param the blog's id - * @param the post's id + * @param the post's id * @param the comment's id - * @return array with the post info according the parameters + * @return array with the post info according the parameters * @author Julio Montoya Dokeos * @version avril 2008, dokeos 1.8.5 - */ + */ function get_blog_attachment($blog_id, $post_id=null,$comment_id=null) -{ +{ global $blog_table_attachment; $blog_id = Database::escape_string($blog_id); $comment_id = Database::escape_string($comment_id); - $post_id = Database::escape_string($post_id); - + $post_id = Database::escape_string($post_id); + $row=array(); $where=''; - + if (!empty ($post_id) && is_numeric($post_id)) { $where.=' AND post_id ="'.$post_id.'" '; } - + if (!empty ($comment_id) && is_numeric($comment_id) ) { if (!empty ($post_id) ) @@ -2941,42 +2941,42 @@ function get_blog_attachment($blog_id, $post_id=null,$comment_id=null) $where.= ' AND '; } $where.=' comment_id ="'.$comment_id.'" '; - } - + } + $sql = 'SELECT path, filename, comment FROM '. $blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where; - + $result=api_sql_query($sql, __FILE__, __LINE__); if (Database::num_rows($result)!=0) { $row=Database::fetch_array($result); } - return $row; + return $row; } /** * Delete the all the attachments according the parameters. * @param the blog's id - * @param the post's id + * @param the post's id * @param the comment's id * @author Julio Montoya Dokeos * @version avril 2008, dokeos 1.8.5 - */ + */ function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null) -{ +{ global $blog_table_attachment; global $_course; - + $blog_id = Database::escape_string($blog_id); $comment_id = Database::escape_string($comment_id); - $post_id = Database::escape_string($post_id); - - // delete files in DB + $post_id = Database::escape_string($post_id); + + // delete files in DB if (!empty ($post_id) && is_numeric($post_id) ) { $where.=' AND post_id ="'.$post_id.'" '; } - + if (!empty ($comment_id) && is_numeric($comment_id) ) { if (!empty ($post_id) ) @@ -2985,44 +2985,44 @@ function delete_all_blog_attachment($blog_id,$post_id=null,$comment_id=null) } $where.=' comment_id ="'.$comment_id.'" '; } - + // delete all files in directory $courseDir = $_course['path'].'/upload/blog'; - $sys_course_path = api_get_path(SYS_COURSE_PATH); + $sys_course_path = api_get_path(SYS_COURSE_PATH); $updir = $sys_course_path.$courseDir; - - $sql= 'SELECT path FROM '.$blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where; + + $sql= 'SELECT path FROM '.$blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where; $result=api_sql_query($sql, __FILE__, __LINE__); - + while ($row=Database::fetch_row($result)) { - $file=$updir.'/'.$row[0]; + $file=$updir.'/'.$row[0]; if (Security::check_abs_path($file,$updir) ) - { + { @ unlink($file); - } - } - $sql = 'DELETE FROM '. $blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where; + } + } + $sql = 'DELETE FROM '. $blog_table_attachment.' WHERE blog_id ="'.intval($blog_id).'" '.$where; api_sql_query($sql, __FILE__, __LINE__); } /** * Gets all the post from a given user id - * @param string db course name + * @param string db course name * @param int user id */ function get_blog_post_from_user($course_db_name, $user_id) { - + $tbl_blogs = Database::get_course_table(TABLE_BLOGS,$course_db_name); $tbl_blog_post = Database::get_course_table(TABLE_BLOGS_POSTS,$course_db_name); $sql = "SELECT DISTINCT blog.blog_id, post_id, title, full_text, post.date_creation - FROM $tbl_blogs blog INNER JOIN $tbl_blog_post post + FROM $tbl_blogs blog INNER JOIN $tbl_blog_post post ON (blog.blog_id = post.blog_id) - WHERE author_id = $user_id AND visibility = 1 + WHERE author_id = $user_id AND visibility = 1 ORDER BY post.date_creation DESC "; $result = api_sql_query($sql, __FILE__, __LINE__); $return_data = ''; //$my_course_info=explode('_',$course_db_name); - $my_course_id=CourseManager::get_course_id_by_database_name($course_db_name); + $my_course_id=CourseManager::get_course_id_by_database_name($course_db_name); if (Database::num_rows($result)!=0) { while ($row=Database::fetch_array($result)) { $return_data.= '

'; @@ -3030,7 +3030,7 @@ function get_blog_post_from_user($course_db_name, $user_id) { $return_data.= '
'; //$return_data.= ''.$row['title'].''; echo '
'; $return_data.= $row['full_text']; - $return_data.= '

'; + $return_data.= '

'; } } return $return_data; @@ -3038,19 +3038,19 @@ function get_blog_post_from_user($course_db_name, $user_id) { /** * Gets all the post comments from a given user id - * @param string db course name + * @param string db course name * @param int user id */ function get_blog_comment_from_user($course_db_name, $user_id) { - + $tbl_blogs = Database::get_course_table(TABLE_BLOGS,$course_db_name); $tbl_blog_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS,$course_db_name); $user_id = Database::escape_string($user_id); - + $sql = "SELECT DISTINCT blog.blog_id, comment_id, title, comment, comment.date_creation - FROM $tbl_blogs blog INNER JOIN $tbl_blog_comment comment + FROM $tbl_blogs blog INNER JOIN $tbl_blog_comment comment ON (blog.blog_id = comment.blog_id) - WHERE author_id = $user_id AND visibility = 1 + WHERE author_id = $user_id AND visibility = 1 ORDER BY blog_name"; $result = api_sql_query($sql, __FILE__, __LINE__); $return_data = ''; @@ -3059,13 +3059,13 @@ function get_blog_comment_from_user($course_db_name, $user_id) { while ($row=Database::fetch_array($result)) { $return_data.= '

'; $return_data.= '
'.$row['title'].'        
'.get_lang('SeeBlog').'
'; - $return_data.= '
'; + $return_data.= '
'; //$return_data.= ''.$row['title'].''; echo '
';*/ $return_data.= $row['comment']; $return_data.= '
'; } } - return $return_data; + return $return_data; } ?> diff --git a/main/inc/lib/classmanager.lib.php b/main/inc/lib/classmanager.lib.php index e71776496e..377c3d1756 100644 --- a/main/inc/lib/classmanager.lib.php +++ b/main/inc/lib/classmanager.lib.php @@ -1,32 +1,32 @@ '; echo 'LIBRARY_PATH :'.api_get_path(LIBRARY_PATH).'
'; echo 'CONFIGURATION_PATH :'.api_get_path(CONFIGURATION_PATH).'
'; - + } diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 3812bc746c..0238fcae79 100644 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -2,27 +2,27 @@ /* ============================================================================== Dokeos - elearning and course management software - + Copyright (c) 2004-2008 Dokeos SPRL Copyright (c) 2003 Ghent University (UGent) Copyright (c) Roan Embrechts, Vrije Universiteit Brussel - + For a full list of contributors, see "credits.txt". The full license can be read in "license.txt". - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + See the GNU General Public License for more details. - + Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium Mail: info@dokeos.com ============================================================================== */ /** -============================================================================== +============================================================================== * This is the document library for Dokeos. * It is / will be used to provide a service layer to all document-using tools. * and eliminate code duplication fro group documents, scorm documents, main documents. @@ -30,20 +30,20 @@ * * @version 1.1, January 2005 * @package dokeos.library -============================================================================== +============================================================================== */ /* -============================================================================== +============================================================================== DOCUMENTATION use the functions like this: DocumentManager::get_course_quota() -============================================================================== +============================================================================== */ /* -============================================================================== +============================================================================== CONSTANTS -============================================================================== +============================================================================== */ define("DISK_QUOTA_FIELD", "disk_quota"); //name of the database field @@ -51,9 +51,9 @@ define("DISK_QUOTA_FIELD", "disk_quota"); //name of the database field define("DEFAULT_DOCUMENT_QUOTA", api_get_setting('default_document_quotum')); /* -============================================================================== +============================================================================== VARIABLES -============================================================================== +============================================================================== */ $sys_course_path = api_get_path(SYS_COURSE_PATH); @@ -62,10 +62,10 @@ $baseServUrl = $_configuration['url_append']."/"; $baseWorkDir = $sys_course_path.(!empty($courseDir)?$courseDir:''); /* -============================================================================== +============================================================================== DocumentManager CLASS the class and its functions -============================================================================== +============================================================================== */ /** @@ -73,7 +73,7 @@ $baseWorkDir = $sys_course_path.(!empty($courseDir)?$courseDir:''); */ class DocumentManager { private function __construct() { - + } /** * @return the document folder quuta of the current course, in bytes @@ -148,7 +148,7 @@ class DocumentManager { "ez" => "application/andrew-inset", "gif" => "image/gif", "gtar" => "application/x-gtar", - "gz" => "application/x-gzip", + "gz" => "application/x-gzip", "hdf" => "application/x-hdf", "hqx" => "application/mac-binhex40", "htm" => "text/html", @@ -259,8 +259,8 @@ class DocumentManager { "wmlc" => "application/vnd.wap.wmlc", "wmls" => "text/vnd.wap.wmlscript", "wmlsc" => "application/vnd.wap.wmlscriptc", - "wma" => "video/x-ms-wma", - "wmv" => "audio/x-ms-wmv", + "wma" => "video/x-ms-wma", + "wmv" => "audio/x-ms-wmv", "wrl" => "model/vrml", "xbm" => "image/x-xbitmap", "xht" => "application/xhtml+xml", @@ -273,12 +273,12 @@ class DocumentManager { "xyz" => "chemical/x-xyz", "zip" => "application/zip" ); - - if ($filename === TRUE) + + if ($filename === TRUE) { return $mime_types; } - + //get the extension of the file $extension = explode('.', $filename); @@ -317,7 +317,7 @@ class DocumentManager { $tbl_item_property = $this_course.'item_property'; $doc_url = Database::escape_string($doc_url); //$doc_url = addslashes($doc_url); - $query = "SELECT 1 FROM $tbl_document AS docs,$tbl_item_property AS props + $query = "SELECT 1 FROM $tbl_document AS docs,$tbl_item_property AS props WHERE props.tool = 'document' AND docs.id=props.ref AND props.visibility <> '1' AND docs.path = '$doc_url'"; //echo $query; $result = api_sql_query($query, __FILE__, __LINE__); @@ -479,7 +479,7 @@ class DocumentManager { * @param int $to_group_id * @param int $to_user_id * @param boolean $can_see_invisible - * @return array with all document data + * @return array with all document data */ public static function get_all_document_data ($_course, $path = '/', $to_group_id = 0, $to_user_id = NULL, $can_see_invisible = false) { $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']); @@ -520,9 +520,9 @@ class DocumentManager { WHERE docs.id = last.ref AND docs.path LIKE '".$path.$added_slash."%' AND docs.path NOT LIKE '".$path.$added_slash."%/%' - AND last.tool = '".TOOL_DOCUMENT."' + AND last.tool = '".TOOL_DOCUMENT."' AND ".$to_field." = ".$to_value." - AND last.visibility".$visibility_bit; + AND last.visibility".$visibility_bit; $result = api_sql_query($sql); @@ -531,13 +531,13 @@ class DocumentManager { while ($row = Database::fetch_array($result,'ASSOC')) //while ($row = Database::fetch_array($result,MYSQL_NUM)) { - + if($row['filetype']=='file' && pathinfo($row['path'],PATHINFO_EXTENSION)=='html'){ - + //Templates management $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES); - $sql_is_template = "SELECT id FROM $table_template - WHERE course_code='".$_course['id']."' + $sql_is_template = "SELECT id FROM $table_template + WHERE course_code='".$_course['id']."' AND user_id='".api_get_user_id()."' AND ref_doc='".$row['id']."'"; $template_result = api_sql_query($sql_is_template); @@ -548,7 +548,7 @@ class DocumentManager { $row['is_template'] = 0; } } - + $document_data[$row['id']] = $row; //$document_data[] = $row; } @@ -577,19 +577,19 @@ class DocumentManager { } else { $to_group_id = Database::escape_string($to_group_id); }*/ - + if (!empty($to_group_id)) { $to_group_id = intval($to_group_id); } - + if ($can_see_invisible) { $sql = "SELECT path FROM ".$TABLE_ITEMPROPERTY." AS last, ".$TABLE_DOCUMENT." AS docs WHERE docs.id = last.ref - AND docs.filetype = 'folder' - AND last.tool = '".TOOL_DOCUMENT."' - AND last.to_group_id = ".$to_group_id." + AND docs.filetype = 'folder' + AND last.tool = '".TOOL_DOCUMENT."' + AND last.to_group_id = ".$to_group_id." AND last.visibility <> 2"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -619,9 +619,9 @@ class DocumentManager { $visible_sql = "SELECT path FROM ".$TABLE_ITEMPROPERTY." AS last, ".$TABLE_DOCUMENT." AS docs WHERE docs.id = last.ref - AND docs.filetype = 'folder' - AND last.tool = '".TOOL_DOCUMENT."' - AND last.to_group_id = ".$to_group_id." + AND docs.filetype = 'folder' + AND last.tool = '".TOOL_DOCUMENT."' + AND last.to_group_id = ".$to_group_id." AND last.visibility = 1"; $visibleresult = api_sql_query($visible_sql, __FILE__, __LINE__); while ($all_visible_folders = Database::fetch_array($visibleresult,'ASSOC')) @@ -630,25 +630,25 @@ class DocumentManager { //echo "visible folders: ".$all_visible_folders['path']."
"; } //get invisible folders - $invisible_sql = "SELECT path + $invisible_sql = "SELECT path FROM ".$TABLE_ITEMPROPERTY." AS last, ".$TABLE_DOCUMENT." AS docs WHERE docs.id = last.ref - AND docs.filetype = 'folder' - AND last.tool = '".TOOL_DOCUMENT."' - AND last.to_group_id = ".$to_group_id." + AND docs.filetype = 'folder' + AND last.tool = '".TOOL_DOCUMENT."' + AND last.to_group_id = ".$to_group_id." AND last.visibility = 0"; $invisibleresult = api_sql_query($invisible_sql, __FILE__, __LINE__); while ($invisible_folders = Database::fetch_array($invisibleresult,'ASSOC')) { //get visible folders in the invisible ones -> they are invisible too //echo "invisible folders: ".$invisible_folders['path']."
"; - $folder_in_invisible_sql = "SELECT path + $folder_in_invisible_sql = "SELECT path FROM ".$TABLE_ITEMPROPERTY." AS last, ".$TABLE_DOCUMENT." AS docs WHERE docs.id = last.ref - AND docs.path LIKE '".Database::escape_string($invisible_folders['path'])."/%' - AND docs.filetype = 'folder' - AND last.tool = '".TOOL_DOCUMENT."' - AND last.to_group_id = ".$to_group_id." + AND docs.path LIKE '".Database::escape_string($invisible_folders['path'])."/%' + AND docs.filetype = 'folder' + AND last.tool = '".TOOL_DOCUMENT."' + AND last.to_group_id = ".$to_group_id." AND last.visibility = 1"; $folder_in_invisible_result = api_sql_query($folder_in_invisible_sql, __FILE__, __LINE__); while ($folders_in_invisible_folder = Database::fetch_array($folder_in_invisible_result,'ASSOC')) @@ -681,26 +681,26 @@ class DocumentManager { return false; } } - } + } /** * This check if a document has the readonly property checked, then see if the user * is the owner of this file, if all this is true then return true. - * + * * @param array $_course * @param int $user_id id of the current user * @param string $file path stored in the database * @param int $document_id in case you dont have the file path ,insert the id of the file here and leave $file in blank '' - * @return boolean true/false + * @return boolean true/false **/ public static function check_readonly ($_course,$user_id,$file,$document_id='',$to_delete=false) { if(!(!empty($document_id) && is_numeric($document_id))) - { + { $document_id = self::get_document_id($_course, $file); - } - + } + $TABLE_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY, $_course['dbName']); $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']); - + if ($to_delete) { if (self::is_folder($_course, $document_id)) @@ -708,83 +708,83 @@ class DocumentManager { if (!empty($file)) { $path = Database::escape_string($file); - $what_to_check_sql = "SELECT td.id, readonly, tp.insert_user_id FROM ".$TABLE_DOCUMENT." td , $TABLE_PROPERTY tp + $what_to_check_sql = "SELECT td.id, readonly, tp.insert_user_id FROM ".$TABLE_DOCUMENT." td , $TABLE_PROPERTY tp WHERE tp.ref= td.id and (path='".$path."' OR path LIKE BINARY '".$path."/%' ) "; //get all id's of documents that are deleted $what_to_check_result = api_sql_query($what_to_check_sql, __FILE__, __LINE__); - + if ($what_to_check_result && Database::num_rows($what_to_check_result) != 0) { // file with readonly set to 1 exist? $readonly_set=false; while ($row = Database::fetch_array($what_to_check_result)) { - //query to delete from item_property table + //query to delete from item_property table //echo $row['id']; echo "
"; - if ($row['readonly']==1) - { + if ($row['readonly']==1) + { if (!($row['insert_user_id'] == $user_id)) - { + { $readonly_set=true; break; - } - + } + } } - + if ($readonly_set) { return true; } } - } - return false; + } + return false; } } - - - + + + if (!empty($document_id)) - { + { $sql= 'SELECT a.insert_user_id, b.readonly FROM '.$TABLE_PROPERTY.' a,'.$TABLE_DOCUMENT.' b WHERE a.ref = b.id and a.ref='.$document_id.' LIMIT 1'; $resultans = api_sql_query($sql, __FILE__, __LINE__); $doc_details = Database ::fetch_array($resultans,'ASSOC'); - + if($doc_details['readonly']==1) - { - if ( $doc_details['insert_user_id'] == $user_id || api_is_platform_admin() ) - { - return false; + { + if ( $doc_details['insert_user_id'] == $user_id || api_is_platform_admin() ) + { + return false; } else - { - return true; - } - } + { + return true; + } + } } return false; } - + /** - * This check if a document is a folder or not + * This check if a document is a folder or not * @param array $_course * @param int $document_id of the item - * @return boolean true/false + * @return boolean true/false **/ - public static function is_folder ($_course, $document_id) { + public static function is_folder ($_course, $document_id) { $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']); //if (!empty($document_id)) $document_id = Database::escape_string($document_id); - $resultans = api_sql_query('SELECT filetype FROM '.$TABLE_DOCUMENT.' WHERE id='.$document_id.'', __FILE__, __LINE__); + $resultans = api_sql_query('SELECT filetype FROM '.$TABLE_DOCUMENT.' WHERE id='.$document_id.'', __FILE__, __LINE__); $result= Database::fetch_array($resultans,'ASSOC'); if ($result['filetype']=='folder') { - return true; + return true; } else { return false; - } + } } - + /** * This deletes a document by changing visibility to 2, renaming it to filename_DELETED_#id * Files/folders that are inside a deleted folder get visibility 2 @@ -808,7 +808,7 @@ class DocumentManager { $what_to_delete_sql = "SELECT id FROM ".$TABLE_DOCUMENT." WHERE path='".$path."' OR path LIKE BINARY '".$path."/%'"; //get all id's of documents that are deleted $what_to_delete_result = api_sql_query($what_to_delete_sql, __FILE__, __LINE__); - + if ($what_to_delete_result && Database::num_rows($what_to_delete_result) != 0) { //needed to deleted medadata @@ -821,10 +821,10 @@ class DocumentManager { { //query to delete from item_property table //avoid wrong behavior - + //$remove_from_item_property_sql = "DELETE FROM ".$TABLE_ITEMPROPERTY." WHERE ref = ".$row['id']." AND tool='".TOOL_DOCUMENT."'"; api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'delete', api_get_user_id()); - + //query to delete from document table $remove_from_document_sql = "DELETE FROM ".$TABLE_DOCUMENT." WHERE id = ".$row['id'].""; self::unset_document_as_template($row['id'],$_course, api_get_user_id()); @@ -855,13 +855,13 @@ class DocumentManager { else //set visibility to 2 and rename file/folder to qsdqsd_DELETED_#id { if (api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'delete', api_get_user_id())) - { + { //echo('item_property_update OK'); if (is_file($base_work_dir.$path) || is_dir($base_work_dir.$path) ) { if(rename($base_work_dir.$path, $base_work_dir.$new_path)) { - self::unset_document_as_template($document_id, api_get_course_id(), api_get_user_id()); + self::unset_document_as_template($document_id, api_get_course_id(), api_get_user_id()); $sql = "UPDATE $TABLE_DOCUMENT set path='".$new_path."' WHERE id='".$document_id."'"; if (api_sql_query($sql, __FILE__, __LINE__)) { @@ -875,7 +875,7 @@ class DocumentManager { //echo('to delete also: id '.$deleted_items['id']); api_item_property_update($_course, TOOL_DOCUMENT, $deleted_items['id'], 'delete', api_get_user_id()); //Change path of subfolders and documents in database - $old_item_path = $deleted_items['path']; + $old_item_path = $deleted_items['path']; $new_item_path = $new_path.substr($old_item_path, strlen($path)); /*/ * trying to fix this bug FS#2681 @@ -887,18 +887,18 @@ class DocumentManager { */ self::unset_document_as_template($deleted_items['id'], api_get_course_id(), api_get_user_id()); $sql = "UPDATE $TABLE_DOCUMENT set path = '".$new_item_path."' WHERE id = ".$deleted_items['id']; - - api_sql_query($sql, __FILE__, __LINE__); + + api_sql_query($sql, __FILE__, __LINE__); } } - + self::delete_document_from_search_engine(api_get_course_id(), $document_id); return true; } } else { - //Couldn't rename - file permissions problem? + //Couldn't rename - file permissions problem? error_log(__FILE__.' '.__LINE__.': Error renaming '.$base_work_dir.$path.' to '.$base_work_dir.$new_path.'. This is probably due to file permissions',0); } } @@ -914,13 +914,13 @@ class DocumentManager { self::delete_document_from_search_engine(api_get_course_id(), $document_id); - while ( $row = Database::fetch_array($res) ) + while ( $row = Database::fetch_array($res) ) { $sqlipd = "DELETE FROM $TABLE_ITEMPROPERTY WHERE ref = ".$row['id']." AND tool='".TOOL_DOCUMENT."'"; $resipd = Database::query($sqlipd,__FILE__,__LINE__); self::unset_document_as_template($row['id'],api_get_course_id(), api_get_user_id()); $sqldd = "DELETE FROM $TABLE_DOCUMENT WHERE id = ".$row['id']; - $resdd = Database::query($sqldd,__FILE__,__LINE__); + $resdd = Database::query($sqldd,__FILE__,__LINE__); } } } @@ -949,7 +949,7 @@ class DocumentManager { require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php'); $di = new DokeosIndexer(); $di->remove_document((int)$row2['search_did']); - } + } $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_DOCUMENT, $document_id); api_sql_query($sql, __FILE__, __LINE__); @@ -969,7 +969,7 @@ class DocumentManager { */ public static function get_document_id ($_course, $path) { $TABLE_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT, $_course['dbName']); - $path = Database::escape_string($path); + $path = Database::escape_string($path); $sql = "SELECT id FROM $TABLE_DOCUMENT WHERE path LIKE BINARY '$path'"; $result = api_sql_query($sql, __FILE__, __LINE__); if ($result && Database::num_rows($result) == 1) { @@ -979,8 +979,8 @@ class DocumentManager { return false; } } - - + + /** * Allow to set a specific document as a new template for FCKEditor for a particular user in a particular course * @@ -993,8 +993,8 @@ class DocumentManager { public static function set_document_as_template ($title, $description, $document_id_for_template, $couse_code, $user_id, $image) { // Database table definition $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES); - - // creating the sql statement + + // creating the sql statement $sql = "INSERT INTO ".$table_template." (title, description, course_code, user_id, ref_doc, image) VALUES ( @@ -1003,13 +1003,13 @@ class DocumentManager { '".Database::escape_string($couse_code)."', '".Database::escape_string($user_id)."', '".Database::escape_string($document_id_for_template)."', - '".Database::escape_string($image)."')"; + '".Database::escape_string($image)."')"; api_sql_query($sql); - + return true; } - - + + /** * Unset a document as template * @@ -1018,23 +1018,23 @@ class DocumentManager { * @param int $user_id */ public static function unset_document_as_template ($document_id, $course_code, $user_id) { - + $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES); $course_code = Database::escape_string($course_code); $user_id = Database::escape_string($user_id); $document_id = Database::escape_string($document_id); - + $sql = 'SELECT id FROM '.$table_template.' WHERE course_code="'.$course_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"'; $result = api_sql_query($sql); $template_id = Database::result($result,0,0); - + include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'); my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg'); - + $sql = 'DELETE FROM '.$table_template.' WHERE course_code="'.$course_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"'; - + api_sql_query($sql); - + } /** * return true if the documentpath have visibility=1 as item_property @@ -1048,7 +1048,7 @@ class DocumentManager { //note the extra / at the end of doc_path to match every path in the // document table that is part of the document path $doc_path = Database::escape_string($doc_path); - + $sql = "SELECT path FROM $docTable d, $propTable ip " . "where d.id=ip.ref AND ip.tool='".TOOL_DOCUMENT."' AND d.filetype='file' AND visibility=0 AND ". "locate(concat(path,'/'),'".$doc_path."/')=1"; @@ -1058,10 +1058,10 @@ class DocumentManager { //echo "$row[0] not visible"; return false; } - + //improved protection of documents viewable directly through the url: incorporates the same protections of the course at the url of documents: access allowed for the whole world Open, access allowed for users registered on the platform Private access, document accessible only to course members (see the Users list), Completely closed; the document is only accessible to the course admin and teaching assistants. if ($_SESSION ['is_allowed_in_course'] || api_is_platform_admin()) - { + { return true; // ok, document is visible } else diff --git a/main/inc/lib/events.lib.inc.php b/main/inc/lib/events.lib.inc.php index 19342d5207..0d175494bc 100644 --- a/main/inc/lib/events.lib.inc.php +++ b/main/inc/lib/events.lib.inc.php @@ -134,7 +134,7 @@ function event_access_course() if(api_get_setting('use_session_mode')=='true' && isset($_SESSION['id_session'])) { $id_session = intval($_SESSION['id_session']); - } + } else { $id_session = 0; @@ -364,7 +364,7 @@ function event_link($link_id) // anonymous $user_id = "0"; } - + $sql = "INSERT INTO ".$TABLETRACK_LINKS." ( links_user_id, links_cours_id, @@ -405,7 +405,7 @@ function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$l exe_result = '".Database::escape_string($score)."', exe_weighting = '".Database::escape_string($weighting)."', session_id = '".Database::escape_string($session_id)."', - orig_lp_id = '".Database::escape_string($learnpath_id)."', + orig_lp_id = '".Database::escape_string($learnpath_id)."', orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."', exe_duration = '".Database::escape_string($duration)."', exe_date= FROM_UNIXTIME(".$reallyNow."),status = '', data_tracking='',start_date =FROM_UNIXTIME(".Database::escape_string($_SESSION['exercice_start_date']).") @@ -472,7 +472,7 @@ function exercise_attempt($score,$answer,$quesId,$exeId,$j) $quesId = Database::escape_string($quesId); $exeId = Database::escape_string($exeId); $j = Database::escape_string($j); - + global $_configuration, $_user, $_cid; $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); @@ -542,7 +542,7 @@ function exercise_attempt($score,$answer,$quesId,$exeId,$j) * @param int Whether this answer is correct (1) or not (0) * @param string Coordinates of this point (e.g. 123;324) * @return boolean Result of the insert query - * @uses Course code and user_id from global scope $_cid and $_user + * @uses Course code and user_id from global scope $_cid and $_user */ function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords) { @@ -581,14 +581,14 @@ function event_system($event_type, $event_value_type, $event_value, $timestamp = global $_configuration; global $_user; global $TABLETRACK_DEFAULT; - + $event_type = Database::escape_string($event_type); $event_value_type = Database::escape_string($event_value_type); $event_value = Database::escape_string($event_value); $timestamp = Database::escape_string($timestamp); $user_id = Database::escape_string($user_id); $course_code = Database::escape_string($course_code); - + // if tracking is disabled record nothing if (!$_configuration['tracking_enabled']) diff --git a/main/inc/lib/export.lib.inc.php b/main/inc/lib/export.lib.inc.php index e250c6bbd7..7cad14c370 100644 --- a/main/inc/lib/export.lib.inc.php +++ b/main/inc/lib/export.lib.inc.php @@ -35,34 +35,34 @@ require_once ('document.lib.php'); class Export { private function __construct() { - + } /** * Export tabular data to CSV-file * @param array $data * @param string $filename */ - public static function export_table_csv ($data, $filename = 'export') { + public static function export_table_csv ($data, $filename = 'export') { $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.csv'; - $handle = @fopen($file, 'a+'); - + $handle = @fopen($file, 'a+'); + if(is_array($data)) { foreach ($data as $index => $row) { $line=''; if(is_array($row)) - { - foreach($row as $value) - { + { + foreach($row as $value) + { $line .= '"'.str_replace('"','""',$value).'";'; } } - @fwrite($handle, $line."\n"); + @fwrite($handle, $line."\n"); } } - @fclose($handle); - DocumentManager :: file_send_for_download($file, true, $filename.'.csv'); + @fclose($handle); + DocumentManager :: file_send_for_download($file, true, $filename.'.csv'); exit(); } /** @@ -72,11 +72,11 @@ class Export { */ public static function export_table_xls ($data, $filename = 'export') { $file = api_get_path(SYS_ARCHIVE_PATH).uniqid('').'.xls'; - $handle = @fopen($file, 'a+'); - foreach ($data as $index => $row) - { - @fwrite($handle, implode("\t", $row)."\n"); - } + $handle = @fopen($file, 'a+'); + foreach ($data as $index => $row) + { + @fwrite($handle, implode("\t", $row)."\n"); + } @fclose($handle); DocumentManager :: file_send_for_download($file, true, $filename.'.xls'); exit(); @@ -132,7 +132,7 @@ class Export { $file = api_get_path(SYS_ARCHIVE_PATH).'/'.uniqid('').'.xml'; $handle = fopen($file, 'a+'); fwrite($handle, ''."\n"); - + if (!is_null($wrapper_tagname)) { fwrite($handle, '<'.$wrapper_tagname.'>'); diff --git a/main/inc/lib/fileDisplay.lib.php b/main/inc/lib/fileDisplay.lib.php index cd7b267c18..9fee9f052a 100644 --- a/main/inc/lib/fileDisplay.lib.php +++ b/main/inc/lib/fileDisplay.lib.php @@ -1,40 +1,40 @@ 2' : '= 1'); $sql = << diff --git a/main/inc/lib/fileManage.lib.php b/main/inc/lib/fileManage.lib.php index 3cb9d86592..c201caf81c 100644 --- a/main/inc/lib/fileManage.lib.php +++ b/main/inc/lib/fileManage.lib.php @@ -819,7 +819,7 @@ class FileManager else { FileManager :: mkdirs(dirname($path), $mode); - //mkdir($path, $mode); + //mkdir($path, $mode); return true; } } diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index efbf3fb068..f14394aa7b 100644 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -74,7 +74,7 @@ function api_replace_parameter($upload_path, $buffer, $param_name="src") /** * Replaces all accentuated characters by non-accentuated characters for filenames, as * well as special HTML characters by their HTML entity's first letter. - * + * * Although this method is not absolute, it gives good results in general. It first * transforms the string to HTML entities (ô, @oslash;, etc) then removes the * HTML character part to result in simple characters (o, o, etc). @@ -253,10 +253,10 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload Display::display_error_message(get_lang('UplNotEnoughSpace')); return false; } - + //if the want to unzip, check if the file has a .zip (or ZIP,Zip,ZiP,...) extension if ($unzip == 1 && preg_match("/.zip$/", strtolower($uploaded_file['name'])) ) - { + { return unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $maxFilledSpace, $output, $to_group_id); //display_message("Unzipping file"); } @@ -305,16 +305,16 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload $document_name = get_document_title($uploaded_file['name']); //size of the uploaded file (in bytes) $file_size = $uploaded_file['size']; - + $files_perm = api_get_setting('permissions_for_new_files'); $files_perm = octdec(!empty($files_perm)?$files_perm:'0770'); - + //what to do if the target file exists switch ($what_if_file_exists) { //overwrite the file if it exists case 'overwrite': - + //check if the target file exists, so we can give another message if (file_exists($store_path)) { @@ -368,17 +368,17 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload return false; } break; - + //rename the file if it exists case 'rename': $new_name = unique_name($where_to_save, $clean_name); $store_path = $where_to_save.$new_name; $new_file_path = $upload_path.$new_name; - + if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) { chmod($store_path,$files_perm); - + //put the document data in the database $document_id = add_document($_course,$new_file_path,'file',$file_size,$document_name); if ($document_id) @@ -400,7 +400,7 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload return false; } break; - + //only save the file if it doesn't exist or warn user if it does exist default: if (file_exists($store_path)) @@ -410,9 +410,9 @@ function handle_uploaded_document($_course,$uploaded_file,$base_work_dir,$upload else { if (@move_uploaded_file($uploaded_file['tmp_name'], $store_path)) - { + { chmod($store_path,$files_perm); - + //put the document data in the database $document_id = add_document($_course,$file_path,'file',$file_size,$document_name); if ($document_id) @@ -903,13 +903,13 @@ function unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $ global $_user; global $to_user_id; global $to_group_id; - + $zip_file = new pclZip($uploaded_file['tmp_name']); // Check the zip content (real size and file extension) $zip_content_array = $zip_file->listContent(); - + foreach((array) $zip_content_array as $this_content) { $real_filesize += $this_content['size']; @@ -935,7 +935,7 @@ function unzip_uploaded_document($uploaded_file, $upload_path, $base_work_dir, $ $save_dir = getcwd(); chdir($base_work_dir.$upload_path); //we extract using a callback function that "cleans" the path - $unzipping_state = $zip_file->extract(PCLZIP_CB_PRE_EXTRACT, 'clean_up_files_in_zip'); + $unzipping_state = $zip_file->extract(PCLZIP_CB_PRE_EXTRACT, 'clean_up_files_in_zip'); // Add all documents in the unzipped folder to the database add_all_documents_in_folder_to_database($_course,$_user['user_id'],$base_work_dir,$upload_path == '/' ? '' : $upload_path, $to_group_id); //Display::display_normal_message(get_lang('UplZipExtractSuccess')); @@ -1081,7 +1081,7 @@ function clean_up_path(&$path) /** * Check if the file is dangerous, based on extension and/or mimetype. - * The list of extensions accepted/rejected can be found from + * The list of extensions accepted/rejected can be found from * api_get_setting('upload_extensions_exclude') and api_get_setting('upload_extensions_include') * @param string filename passed by reference. The filename will be modified if filter rules say so! (you can include path but the filename should look like 'abc.html') * @return int 0 to skip file, 1 to keep file @@ -1193,7 +1193,7 @@ function get_document_id() moved to document.lib.php * @return boolean true /false */ function update_existing_document($_course,$document_id,$filesize,$readonly=0) -{ +{ $document_table = Database::get_course_table(TABLE_DOCUMENT,$_course['dbName']); $sql="UPDATE $document_table SET size = '$filesize' , readonly = '$readonly' WHERE id='$document_id'"; if(api_sql_query($sql,__FILE__,__LINE__)) @@ -1838,7 +1838,7 @@ function build_missing_files_form($missing_files,$upload_path,$file_name) } $form .= "\n" ."" - ."" + ."" ."\n"; return $form; } @@ -1856,7 +1856,7 @@ function add_all_documents_in_folder_to_database($_course,$user_id,$base_work_di { $path = $base_work_dir.$current_path; - + //open dir $handle=opendir($path); //run trough @@ -1866,7 +1866,7 @@ function add_all_documents_in_folder_to_database($_course,$user_id,$base_work_di $completepath="$path/$file"; //directory? - + if (is_dir($completepath)) { $title=get_document_title($file); @@ -1889,7 +1889,7 @@ function add_all_documents_in_folder_to_database($_course,$user_id,$base_work_di //rename $safe_file=disable_dangerous_file(replace_dangerous_char($file)); @rename($base_work_dir.$current_path.'/'.$file,$base_work_dir.$current_path.'/'.$safe_file); - + if(!DocumentManager::get_document_id($_course, $current_path.'/'.$safe_file)) { $title=get_document_title($file); diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index 0a7758d806..2821a72267 100644 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -90,7 +90,7 @@ class GroupManager { * GROUP FUNCTIONS ==============================================================================*/ private function __construct() { - + } /** * Get list of groups for current course. @@ -118,7 +118,7 @@ class GroupManager { $session_id=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : 0; $session_condition = intval($session_id)==0 ? '' : ' g.session_id = '.intval($session_id).' '; $my_status_of_user_in_course=CourseManager::get_user_in_course_status($my_user_id,$my_course_code); - + $is_student_in_session=false; if (is_null($my_status_of_user_in_course) || $my_status_of_user_in_course=='') {//into session if ($session_id>0) { @@ -144,7 +144,7 @@ class GroupManager { ON `ug`.`group_id` = `g`.`id` AND `ug`.`user_id` = '".$_user['user_id']."' LEFT JOIN ".$table_group_user." `ug2` ON `ug2`.`group_id` = `g`.`id`"; - + } elseif ($my_status_of_user_in_course==STUDENT || $is_student_in_session===true || $_SESSION['studentview'] == 'studentview') { $sql = "SELECT g.id , g.name , @@ -163,7 +163,7 @@ class GroupManager { LEFT JOIN ".$table_group_user." `ug2` ON `ug2`.`group_id` = `g`.`id`"; } - + if ($category != null){ $sql .= " WHERE g.category_id = '".Database::escape_string($category)."' "; if(!empty($session_condition)) @@ -214,12 +214,12 @@ class GroupManager { $table_group = Database :: get_course_table(TABLE_GROUP); $table_forum = Database :: get_course_table(TABLE_FORUM); $category = self :: get_category($category_id); - + if (intval($places) == 0) //if the amount of users per group is not filled in, use the setting from the category { $places = $category['max_student']; } - $sql = "INSERT INTO ".$table_group." SET + $sql = "INSERT INTO ".$table_group." SET category_id='".Database::escape_string($category_id)."', max_student = '".$places."', doc_state = '".$category['doc_state']."', calendar_state = '".$category['calendar_state']."', work_state = '".$category['work_state']."', announcements_state = '".$category['announcements_state']."', forum_state = '".$category['forum_state']."', wiki_state = '".$category['wiki_state']."', self_registration_allowed = '".$category['self_reg_allowed']."', self_unregistration_allowed = '".$category['self_unreg_allowed']."', session_id='".Database::escape_string($my_id_session)."'"; api_sql_query($sql,__FILE__,__LINE__); @@ -236,12 +236,12 @@ class GroupManager { /* Stores the directory path into the group table */ $sql = "UPDATE ".$table_group." SET name = '".Database::escape_string($name)."', secret_directory = '".$dir_name."' WHERE id ='".$lastId."'"; api_sql_query($sql,__FILE__,__LINE__); - + // create a forum if needed if ($category['forum_state'] >= 0) { include_once(api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php'); include_once(api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'); - + $forum_categories = get_forum_categories(); $values['forum_title'] = $name; $counter = 0; @@ -262,7 +262,7 @@ class GroupManager { $values['allow_attachments_group']['allow_attachments'] = 1; $values['allow_new_threads_group']['allow_new_threads'] = 1; $values['default_view_type_group']['default_view_type']=api_get_setting('default_forum_view'); - $values['group_forum'] = $lastId; + $values['group_forum'] = $lastId; if ($category['forum_state'] == '1') { $values['public_private_group_forum_group']['public_private_group_forum']='public'; } elseif ($category['forum_state'] == '2') { @@ -382,7 +382,7 @@ class GroupManager { { $course = api_get_course_info(); } - + // Database table definitions $group_table = Database :: get_course_table(TABLE_GROUP, $course_db); $group_user_table = Database :: get_course_table(TABLE_GROUP_USER, $course_db); @@ -390,9 +390,9 @@ class GroupManager { $forum_post_table = Database :: get_course_table(TABLE_FORUM_POST, $course_db); //$forum_post_text_table = Database :: get_course_table(TOOL_FORUM_POST_TEXT_TABLE, $course_db); $forum_topic_table = Database :: get_course_table(TABLE_FORUM_POST, $course_db); - + $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); - + if(api_is_course_coach()) { //a coach can only delete courses from his session for($i=0 ; $i 0) { $userToken[$this_user['user_id']] = $this_user['number_groups_left']; @@ -874,7 +874,7 @@ class GroupManager { $changed = true; while ($changed) { - + $changed = false; reset($group_available_place); arsort($group_available_place); @@ -886,7 +886,7 @@ class GroupManager { { if (self :: can_user_subscribe($user_id, $group_id)) { - + self :: subscribe_users($user_id, $group_id); $group_available_place[$group_id]--; $userToken[$user_id]--; @@ -941,7 +941,7 @@ class GroupManager { $table_group = Database :: get_course_table(TABLE_GROUP); $user_id = Database::escape_string($user_id); $cat_id = Database::escape_string($cat_id); - + $sql = 'SELECT COUNT(*) AS number_of_groups FROM '.$table_group_user.' gu, '.$table_group.' g WHERE gu.user_id = \''.$user_id.'\' AND g.id = gu.group_id AND g.category_id= \''.$cat_id.'\''; $db_result = api_sql_query($sql,__FILE__,__LINE__); $db_object = Database::fetch_object($db_result); @@ -1066,7 +1066,7 @@ class GroupManager { * (user_id, firstname, lastname, email) */ public static function get_subscribed_tutors ($group_id,$id_only=false) { - $table_user = Database :: get_main_table(TABLE_MAIN_USER); + $table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $order_clause = api_sort_by_first_name() ? ' ORDER BY `u`.`firstname`, `u`.`lastname`' : ' ORDER BY `u`.`lastname`, `u`.`firstname`'; $group_id = Database::escape_string($group_id); @@ -1129,7 +1129,7 @@ class GroupManager { $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $user_id = Database::escape_string($user_id); $group_id = Database::escape_string($group_id); - + $sql = "INSERT INTO ".$table_group_tutor." (user_id, group_id) VALUES ('".$user_id."', '".$group_id."')"; $result &= api_sql_query($sql,__FILE__,__LINE__); } @@ -1157,7 +1157,7 @@ class GroupManager { $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); if( count($group_ids) > 0) { - + if(api_is_course_coach()) { for($i=0 ; $i0) @@ -1285,8 +1285,8 @@ class GroupManager { public static function is_tutor ($user_id) { global $_course; $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); - $user_id = Database::escape_string($user_id); - + $user_id = Database::escape_string($user_id); + $sql = "SELECT tutor_id FROM ".$course_user_table." WHERE `user_id`='".$user_id."' AND `course_code`='".$_course['sysCode']."'"."AND tutor_id=1"; @@ -1478,7 +1478,7 @@ class GroupManager { break; case GROUP_TOOL_WIKI : $state_key = 'wiki_state'; - break; + break; default: return false; } @@ -1508,13 +1508,13 @@ class GroupManager { * Get all groups where a specific user is subscribed */ public static function get_user_group_name ($user_id) { - + $table_group_user=Database::get_course_table(TABLE_GROUP_USER); $table_group=Database::get_course_table(TABLE_GROUP); - $user_id = Database::escape_string($user_id); + $user_id = Database::escape_string($user_id); $sql_groups = 'SELECT name FROM '.$table_group.' g,'.$table_group_user.' gu WHERE gu.user_id="'.$user_id.'" AND gu.group_id=g.id'; $res = api_sql_query($sql_groups,__FILE__,__LINE__); - + $groups=array(); while($group = Database::fetch_array($res)) { diff --git a/main/inc/lib/image.lib.php b/main/inc/lib/image.lib.php index 1455683819..d286678bdf 100644 --- a/main/inc/lib/image.lib.php +++ b/main/inc/lib/image.lib.php @@ -9,20 +9,20 @@ class image { var $bgx; var $bgy; var $fontfile='./verdana'; - + var $color; function image($bgfile='') { - + image::addbackground($bgfile); - + } function createimagefromtype($file,$handler) { $size = @getimagesize(api_url_to_local_path($file)); $type=$size[2]; - + switch ($type) { case 2 : $imhandler = @imagecreatefromjpeg($file); break; @@ -35,7 +35,7 @@ class image { $xtmpstr=$handler.'x'; $ytmpstr=$handler.'y'; - + $this->$xtmpstr=$size[0]; $this->$ytmpstr=$size[1]; @@ -63,7 +63,7 @@ class image { $scale = ($size[0] > 0 && $size[1] >0)?min($thumbw/$size[0], $thumbh/$size[1]):0; $width = (int)($size[0]*$scale); $height = (int)($size[1]*$scale); - + $deltaw = 0; $deltah = 0; $dst_img = @ImageCreateTrueColor($width, $height); @@ -81,8 +81,8 @@ class image { } function addbackground($bgfile) { - - + + if ( !empty($bgfile) && file_exists($bgfile) ) { $this->bg = image::createimagefromtype($bgfile,'bg'); @imagealphablending( $this->bg ,TRUE ); } @@ -115,7 +115,7 @@ class image { putenv('GDFONTPATH=' . realpath('.')); $this->fontfile='verdana'; $text= preg_replace('`(?fontfile, $text ); if ($x<0) { $x=$this->bgx - max($box[2],$box[4]) + $x; @@ -127,9 +127,9 @@ class image { } else { $y=max(-$box[7],-$box[5]) + $y; } - + @imagettftext($this->bg, $size, $angle, $x, $y, $this->color, $this->fontfile , $text ); - + } function send_image($type,$file='',$compress=-1) { @@ -154,7 +154,7 @@ class image { break; default: return 0; } - + // TODO: Occupied memory is not released, because the following fragment of code is actually dead. @imagedestroy($this->bg); @imagedestroy($this->logo); diff --git a/main/inc/lib/import.lib.php b/main/inc/lib/import.lib.php index 72a1b833a4..b478acfa3e 100644 --- a/main/inc/lib/import.lib.php +++ b/main/inc/lib/import.lib.php @@ -1,45 +1,45 @@ $value) { diff --git a/main/inc/lib/legal.lib.php b/main/inc/lib/legal.lib.php index ff07dd966c..0aeed87ca0 100644 --- a/main/inc/lib/legal.lib.php +++ b/main/inc/lib/legal.lib.php @@ -7,7 +7,7 @@ * @package dokeos.legal * */ - + class LegalManager { private function __construct () { //void @@ -17,12 +17,12 @@ class LegalManager { * @param int language id * @param string the content * @param int term and condition type (0 or 1) - * @param string explain changes + * @param string explain changes * @return boolean sucess */ public function add ($language, $content, $type, $changes) { - $legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); - $last = self::get_last_condition($language); + $legal_table = Database::get_main_table(TABLE_MAIN_LEGAL); + $last = self::get_last_condition($language); $language = Database::escape_string($language); $content = Database::escape_string($content); $type = intval($type); @@ -50,7 +50,7 @@ class LegalManager { date = '".$time."' WHERE legal_id= $id "; $result = Database::query($sql, __FILE__, __LINE__); - return true; + return true; } else { return false; } @@ -63,13 +63,13 @@ class LegalManager { $sql = "DELETE FROM $legal_table WHERE legal_id = '".$id."'"; */ } - + /** * Gets the last version of a Term and condition by language - * @param int the language id - * @return array all the info of a Term and condition - */ - + * @param int the language id + * @return array all the info of a Term and condition + */ + public function get_last_condition_version ($language) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); $language= Database::escape_string($language); @@ -77,16 +77,16 @@ class LegalManager { $result = Database::query($sql, __FILE__, __LINE__); $row = Database::fetch_array($result); if (Database::num_rows($result)>0) { - return $row['version']; + return $row['version']; } else { return 0; } } /** * Gets the data of a Term and condition by language - * @param int the language id - * @return array all the info of a Term and condition - */ + * @param int the language id + * @return array all the info of a Term and condition + */ public function get_last_condition ($language) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); $language= Database::escape_string($language); @@ -94,11 +94,11 @@ class LegalManager { $result = Database::query($sql, __FILE__, __LINE__); return Database::fetch_array($result); } - + /** * Gets the last version of a Term and condition by language - * @param int the language id - * @return boolean | int the version or false if does not exist + * @param int the language id + * @return boolean | int the version or false if does not exist */ public function get_last_version ($language) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); @@ -107,15 +107,15 @@ class LegalManager { $result = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($result)>0){ $version = Database::fetch_array($result); - $version = explode(':',$version[0]); + $version = explode(':',$version[0]); return $version[0]; - } else { + } else { return false; - } + } } - + /** - * Show the last condition + * Show the last condition * @param array with type and content i.e array('type'=>'1', 'content'=>'hola'); * @return string html preview */ @@ -144,15 +144,15 @@ class LegalManager { '.get_lang('TermsAndConditions').' - '; + '; break;*/ // html - case 0: + case 0: $preview = ''; $preview .= '
'.get_lang('ByClickingRegisterYouAgreeTermsAndConditions'); break; - // page link - case 1: + // page link + case 1: $preview ='
'.get_lang('TermsAndConditions').''; $preview .= '
'; break; - default: - break; + default: + break; } - return $preview; + return $preview; } - + /** * Get the terms and condition table (only for maintenance) - * @param int offset + * @param int offset * @param int number of items * @param int column - * @return array + * @return array */ public function get_legal_data ($from, $number_of_items, $column) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); $lang_table = Database::get_main_table(TABLE_MAIN_LANGUAGE); $from = intval($from); - $number_of_items = intval($number_of_items); + $number_of_items = intval($number_of_items); $column = intval($column); - - $sql = "SELECT version, original_name as language, content, changes, type, FROM_UNIXTIME(date) - FROM $legal_conditions_table inner join $lang_table l on(language_id = l.id) "; + + $sql = "SELECT version, original_name as language, content, changes, type, FROM_UNIXTIME(date) + FROM $legal_conditions_table inner join $lang_table l on(language_id = l.id) "; $sql .= "ORDER BY language, version ASC "; $sql .= "LIMIT $from,$number_of_items "; - - $result = Database::query($sql, __FILE__, __LINE__); + + $result = Database::query($sql, __FILE__, __LINE__); $legals = array (); $versions = array (); while ($legal = Database::fetch_array($result)) { - // max 2000 chars + // max 2000 chars //echo strlen($legal[1]); echo '
'; $versions[]=$legal[0]; $languages[]=$legal[1]; if (strlen($legal[2])>2000) - $legal[2]= substr($legal[2],0,2000).' ... '; + $legal[2]= substr($legal[2],0,2000).' ... '; if ($legal[4]==0) $legal[4]= get_lang('HTMLText'); elseif($legal[4]==1) - $legal[4]=get_lang('PageLink'); + $legal[4]=get_lang('PageLink'); $legals[] = $legal; } - return $legals; + return $legals; } - + /** - * Gets the number of terms and conditions available - * @return int + * Gets the number of terms and conditions available + * @return int */ public function count() { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); $sql = "SELECT count(*) as count_result FROM $legal_conditions_table ORDER BY legal_id DESC "; $result = Database::query($sql, __FILE__, __LINE__); - $url = Database::fetch_array($result,'ASSOC'); - $result = $url['count_result']; - return $result; + $url = Database::fetch_array($result,'ASSOC'); + $result = $url['count_result']; + return $result; } - + /** * Get type of terms and conditions * @param int The legal id @@ -230,8 +230,8 @@ class LegalManager { */ public function get_type_of_terms_and_conditions ($legal_id,$language_id) { $legal_conditions_table = Database::get_main_table(TABLE_MAIN_LEGAL); - $legal_id=Database::escape_string($legal_id); - $language_id=Database::escape_string($language_id); + $legal_id=Database::escape_string($legal_id); + $language_id=Database::escape_string($language_id); $sql='SELECT type FROM '.$legal_conditions_table.' WHERE legal_id="'.$legal_id.'" AND language_id="'.$language_id.'"'; $rs=Database::query($sql,__FILE__,__LINE__); return Database::result($rs,0,'type'); diff --git a/main/inc/lib/mail.lib.inc.php b/main/inc/lib/mail.lib.inc.php index 0d165cf8d9..c3cae3acfb 100644 --- a/main/inc/lib/mail.lib.inc.php +++ b/main/inc/lib/mail.lib.inc.php @@ -30,7 +30,7 @@ function api_mail($recipient_name, $recipient_email, $subject, $message, $sender $mail->Mailer = $platform_email['SMTP_MAILER']; $mail->Host = $platform_email['SMTP_HOST']; $mail->Port = $platform_email['SMTP_PORT']; - $mail->CharSet = $platform_email['SMTP_CHARSET']; + $mail->CharSet = $platform_email['SMTP_CHARSET']; $mail->WordWrap = 200; // stay far below SMTP protocol 980 chars limit if($platform_email['SMTP_AUTH']) diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index dad5032bb5..b8fcead97f 100644 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -18,7 +18,7 @@ Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium Mail: info@dokeos.com - + ============================================================================== */ @@ -32,16 +32,16 @@ function inbox_display() { echo ''.Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).api_xml_http_response_encode(get_lang('ComposeMessage')).''; echo ''.api_convert_encoding(get_lang('Refresh'),'UTF-8',$charset).''; echo ''; - echo ''; + echo ''; $charset = api_get_setting('platform_charset'); - $table_message = Database::get_main_table(TABLE_MESSAGE); + $table_message = Database::get_main_table(TABLE_MESSAGE); $request=api_is_xml_http_request(); if ($_SESSION['social_exist']===true) { - $redirect="#remote-tab-2"; + $redirect="#remote-tab-2"; if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') { $success= get_lang('SelectedMessagesDeleted'); } else { - $success= get_lang('SelectedMessagesDeleted'); + $success= get_lang('SelectedMessagesDeleted'); } } else { $success= get_lang('SelectedMessagesDeleted'); @@ -82,7 +82,7 @@ function inbox_display() { echo ''.api_xml_http_response_encode(get_lang('SelectAll')).'   '; echo ''.api_xml_http_response_encode(get_lang('UnSelectAll')).'   '; echo ''; - + } } else { $table->set_form_actions(array ('delete' => get_lang('DeleteSelectedMessages'))); @@ -95,23 +95,23 @@ function get_number_of_messages_mask() { } function get_message_data_mask($from, $number_of_items, $column, $direction) { $column='3'; - $direction='desc'; - //non set by SortableTable ? + $direction='desc'; + //non set by SortableTable ? $number_of_items=get_number_of_messages_mask(); return MessageManager::get_message_data($from, $number_of_items, $column, $direction); } function outbox_display() { - $table_message = Database::get_main_table(TABLE_MESSAGE); + $table_message = Database::get_main_table(TABLE_MESSAGE); $request=api_is_xml_http_request(); global $charset; if ($_SESSION['social_exist']===true) { - $redirect="#remote-tab-3"; + $redirect="#remote-tab-3"; if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') { $success= get_lang('SelectedMessagesDeleted')." 
".get_lang('BackToOutbox').""; }else { - $success=get_lang('SelectedMessagesDeleted')." 
".get_lang('BackToOutbox').""; + $success=get_lang('SelectedMessagesDeleted')." 
".get_lang('BackToOutbox').""; } - + } else { $success= get_lang('SelectedMessagesDeleted')." "."
".get_lang('BackToOutbox').""; } @@ -121,15 +121,15 @@ if (isset ($_REQUEST['action'])) { $number_of_selected_messages = count($_POST['id']); if ($number_of_selected_messages!=0) { foreach ($_POST['id'] as $index => $message_id) { - MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id); + MessageManager::delete_message_by_user_receiver(api_get_user_id(), $message_id); } - } + } Display::display_normal_message(api_xml_http_response_encode($success),false); break; case 'deleteone' : MessageManager::delete_message_by_user_receiver(api_get_user_id(), $_GET['id']); Display::display_confirmation_message(api_xml_http_response_encode($success),false); - echo '
'; + echo '
'; break; } } @@ -168,7 +168,7 @@ function get_message_data_send_mask($from, $number_of_items, $column, $direction $column='3'; $direction='desc'; //non set by SortableTable ? - $number_of_items=get_number_of_messages_send_mask(); + $number_of_items=get_number_of_messages_send_mask(); return MessageManager::get_message_data_sent($from, $number_of_items, $column, $direction); } ?> diff --git a/main/inc/lib/online.inc.php b/main/inc/lib/online.inc.php index 543be82b44..724648de9b 100644 --- a/main/inc/lib/online.inc.php +++ b/main/inc/lib/online.inc.php @@ -1,27 +1,27 @@ 0 && !empty($_course['id'])) @@ -59,7 +59,7 @@ function LoginCheck($uid) } else { - $query = "REPLACE INTO ".$online_table ." (login_id,login_user_id,login_date,login_ip) VALUES ($uid,$uid,'$login_date','$login_ip')"; + $query = "REPLACE INTO ".$online_table ." (login_id,login_user_id,login_date,login_ip) VALUES ($uid,$uid,'$login_date','$login_ip')"; } @api_sql_query($query,__FILE__,__LINE__); @@ -90,19 +90,19 @@ function online_logout() { if (Database::num_rows($q_last_connection)>0) { $i_id_last_connection=Database::result($q_last_connection,0,"login_id"); } - + if (!isset($_SESSION['login_as'])) { $current_date=date('Y-m-d H:i:s',time()); $s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'"; api_sql_query($s_sql_update_logout_date); } LoginDelete($uid, $_configuration['statistics_database']); //from inc/lib/online.inc.php - removes the "online" status - + //the following code enables the use of an external logout function. //example: define a $extAuthSource['ldap']['logout']="file.php" in configuration.php - // then a function called ldap_logout() inside that file - // (using *authent_name*_logout as the function name) and the following code - // will find and execute it + // then a function called ldap_logout() inside that file + // (using *authent_name*_logout as the function name) and the following code + // will find and execute it $uinfo = api_get_user_info($uid); if (($uinfo['auth_source'] != PLATFORM_AUTH_SOURCE) && is_array($extAuthSource)) { if (is_array($extAuthSource[$uinfo['auth_source']])) { @@ -133,7 +133,7 @@ function online_logout() { */ function LoginDelete($user_id) { - $online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE); + $online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE); $user_id = (int) $user_id; $query = "DELETE FROM ".$online_table ." WHERE login_user_id = '".Database::escape_string($user_id)."'"; @api_sql_query($query,__FILE__,__LINE__); @@ -148,34 +148,34 @@ function LoginDelete($user_id) * @todo remove parameter $statistics_database which is no longer necessary */ function WhoIsOnline($uid=0,$statistics_database='',$valid) -{ +{ $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); $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." 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); + + 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){ - $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." track + $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." track INNER JOIN $tbl_user_rel_access_url user_rel_url - ON (user_rel_url.user_id = track.login_user_id) - WHERE access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' "; + ON (user_rel_url.user_id = track.login_user_id) + WHERE access_url_id = $access_url_id AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= '".$current_date."' "; } - } - - $result = @api_sql_query($query,__FILE__,__LINE__); + } + + $result = @api_sql_query($query,__FILE__,__LINE__); if (count($result)>0) { $rtime = time(); $rdate = date("Y-m-d H:i:s",$rtime); $validtime = mktime(date("H"),date("i")-$valid,date("s"),date("m"),date("d"),date("Y")); $rarray = array(); - + while(list($login_user_id,$login_date)= Database::fetch_row($result)) - { + { $barray = array(); array_push($barray,$login_user_id); array_push($barray,$login_date); @@ -189,15 +189,15 @@ function WhoIsOnline($uid=0,$statistics_database='',$valid) $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 + else { return false; } @@ -234,7 +234,7 @@ function GetFullUserName($uid) function chatcall() { global $_user, $_cid; - + if (!$_user['user_id']) { return (false); @@ -270,10 +270,10 @@ function chatcall() { . get_lang("No") ."" ."

"; - + return($message); } - else + else { return(false); } @@ -288,23 +288,23 @@ function chatcall() { * @return array Each line gives a user id and a login time */ function who_is_online_in_this_course($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 login_user_id,login_date FROM ".$track_online_table ." WHERE course='".$coursecode."' AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() "; - $result = api_sql_query($query,__FILE__,__LINE__); + + $query = "SELECT login_user_id,login_date FROM ".$track_online_table ." WHERE course='".$coursecode."' AND DATE_ADD(login_date,INTERVAL $valid MINUTE) >= NOW() "; + $result = api_sql_query($query,__FILE__,__LINE__); if (count($result)>0) { $rtime = time(); $rdate = date("Y-m-d H:i:s",$rtime); $validtime = mktime(date("H"),date("i")-$valid,date("s"),date("m"),date("d"),date("Y")); $rarray = array(); - + while(list($login_user_id,$login_date)= mysql_fetch_row($result)) - { + { $barray = array(); array_push($barray,$login_user_id); array_push($barray,$login_date); @@ -322,10 +322,10 @@ function who_is_online_in_this_course($uid, $valid, $coursecode=null) { array_push($rarray,$barray); } - } + } return $rarray; } - else + else { return false; } diff --git a/main/inc/lib/security.lib.php b/main/inc/lib/security.lib.php index 42acb86e41..2bd198a74c 100755 --- a/main/inc/lib/security.lib.php +++ b/main/inc/lib/security.lib.php @@ -1,23 +1,23 @@ filter($new_var,[more options]) - * and then using $secure->clean['var'] as a filtered equivalent, although + * a new Security object and using $secure->filter($new_var,[more options]) + * and then using $secure->clean['var'] as a filtered equivalent, although * this is *not* mandatory at all. - * + * * @author Yannick Warnier */ class Security { public static $clean = array(); /** - * Checks if the absolute path (directory) given is really under the + * Checks if the absolute path (directory) given is really under the * checker path (directory) * @param string Absolute path to be checked (with trailing slash) * @param string Checker path under which the path should be (absolute path, with trailing slash, get it from api_get_path(SYS_COURSE_PATH)) @@ -62,9 +62,9 @@ class Security { */ public static function check_abs_path ($abs_path,$checker_path) { if (empty($checker_path)) {return false;} //checker path must be set - + $true_path=str_replace("\\", "/", realpath($abs_path)); - + $found = strpos($true_path.'/',$checker_path); if ($found===0) { return true; @@ -72,7 +72,7 @@ class Security { return false; } /** - * Checks if the relative path (directory) given is really under the + * Checks if the relative path (directory) given is really under the * checker path (directory) * @param string Relative path to be checked (relative to the current directory) (with trailing slash) * @param string Checker path under which the path should be (absolute path, with trailing slash, get it from api_get_path(SYS_COURSE_PATH)) @@ -119,7 +119,7 @@ class Security { case 'post': if (isset($_SESSION['sec_token']) && isset($_POST['sec_token']) && $_SESSION['sec_token'] === $_POST['sec_token']) { return true; - } + } return false; default: if (isset($_SESSION['sec_token']) && isset($array) && $_SESSION['sec_token'] === $array) { @@ -130,7 +130,7 @@ class Security { return false; //just in case, don't let anything slip } /** - * Checks the user agent of the client as recorder by get_ua() to prevent + * Checks the user agent of the client as recorder by get_ua() to prevent * most session hijacking attacks. * @return bool True if the user agent is the same, false otherwise */ @@ -186,7 +186,7 @@ class Security { $_SESSION['sec_ua_seed'] = uniqid(rand(),TRUE); $_SESSION['sec_ua'] = $_SERVER['HTTP_USER_AGENT'].$_SESSION['sec_ua_seed']; } - /** + /** * This function filters a variable to the type given, with the options given * @param mixed The variable to be filtered * @param string The type of variable we expect (bool,int,float,string) @@ -212,7 +212,7 @@ class Security { $result = (float) $var; break; case 'string': - + break; case 'array': //an array variable shouldn't be given to the filter @@ -241,18 +241,18 @@ class Security { * This function tackles the XSS injections. * Filtering for XSS is very easily done by using the htmlentities() function. * This kind of filtering prevents JavaScript snippets to be understood as such. - * @param mixed The variable to filter for XSS, this params can be a string or an array (example : array(x,y)) + * @param mixed The variable to filter for XSS, this params can be a string or an array (example : array(x,y)) * @param integer The user status,constant allowed(STUDENT,COURSEMANAGER,ANONYMOUS,COURSEMANAGERLOWSECURITY) * @return mixed Filtered string or array */ public static function remove_XSS ($var,$user_status=ANONYMOUS) { global $charset; - $purifier = new HTMLPurifier(null,$user_status); + $purifier = new HTMLPurifier(null,$user_status); if (is_array($var)) { - return $purifier->purifyArray($var); + return $purifier->purifyArray($var); } else { - return $purifier->purify($var); + return $purifier->purify($var); } - + } } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index d18b99cfbd..c6032c5986 100755 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -8,10 +8,10 @@ define(SOCIALGOODFRIEND,4); define(SOCIALENEMY,5); define(SOCIALDELETED,6); -class UserFriend extends UserManager { - +class UserFriend extends UserManager { + private function __construct() { - + } /** * Allow to register contact to social network @@ -28,8 +28,8 @@ class UserFriend extends UserManager { $result = Database::query($sql, __FILE__, __LINE__); $row = Database :: fetch_array($result, 'ASSOC'); if ($row['count'] == 0) { - $current_date=date('Y-m-d H:i:s'); - $sql_i = 'INSERT INTO ' . $tbl_my_friend . '(friend_user_id,user_id,relation_type,last_edit)values(' . ((int)$friend_id) . ','.((int)$my_user_id).','.((int)$relation_type).',"'.$current_date.'");'; + $current_date=date('Y-m-d H:i:s'); + $sql_i = 'INSERT INTO ' . $tbl_my_friend . '(friend_user_id,user_id,relation_type,last_edit)values(' . ((int)$friend_id) . ','.((int)$my_user_id).','.((int)$relation_type).',"'.$current_date.'");'; Database::query($sql_i, __FILE__, __LINE__); } else { $sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' . ((int)$friend_id) . ' AND user_id='.((int)$my_user_id); @@ -41,7 +41,7 @@ class UserFriend extends UserManager { } } } - + /** * Allow to delete contact to social network *@author isaac flores paz @@ -61,11 +61,11 @@ class UserFriend extends UserManager { $sql_j = 'UPDATE ' . $tbl_my_message . ' SET msg_status=7 WHERE user_receiver_id=' . ((int)$user_id).' AND user_sender_id='.((int)$friend_id); //Delete user $sql_ij = 'UPDATE ' . $tbl_my_friend . ' SET relation_type=6 WHERE user_id=' . ((int)$friend_id).' AND friend_user_id='.((int)$user_id); - $sql_ji = 'UPDATE ' . $tbl_my_message . ' SET msg_status=7 WHERE user_receiver_id=' . ((int)$friend_id).' AND user_sender_id='.((int)$user_id); + $sql_ji = 'UPDATE ' . $tbl_my_message . ' SET msg_status=7 WHERE user_receiver_id=' . ((int)$friend_id).' AND user_sender_id='.((int)$user_id); Database::query($sql_i, __FILE__, __LINE__); Database::query($sql_j, __FILE__, __LINE__); Database::query($sql_ij, __FILE__, __LINE__); - Database::query($sql_ji, __FILE__, __LINE__); + Database::query($sql_ji, __FILE__, __LINE__); } } /** @@ -88,12 +88,12 @@ class UserFriend extends UserManager { } else { return $friend_relation_list; } - + } /** * Get relation type contact by name * @author isaac flores paz - * @param string names of the kind of relation + * @param string names of the kind of relation * @return int */ public static function get_relation_type_by_name ($relation_type_name) { @@ -103,7 +103,7 @@ class UserFriend extends UserManager { if (strtolower($value_type_friend['title'])==$relation_type_name) { return $value_type_friend['id']; } - } + } } /** * Get the kind of relation between contacts @@ -120,7 +120,7 @@ class UserFriend extends UserManager { $res=Database::query($sql,__FILE__,__LINE__); $row=Database::fetch_array($res,'ASSOC'); if (Database::num_rows($res)>0) { - return $row['id']; + return $row['id']; } else { return USERUNKNOW; } @@ -136,7 +136,7 @@ class UserFriend extends UserManager { public static function get_list_id_friends_by_user_id ($user_id,$id_group=null,$search_name=null) { $list_ids_friends=array(); $tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND); - $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER); + $tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER); $sql='SELECT friend_user_id FROM '.$tbl_my_friend.' WHERE relation_type<>6 AND friend_user_id<>'.((int)$user_id).' AND user_id='.((int)$user_id); if (isset($id_group) && $id_group>0) { $sql.=' AND relation_type='.$id_group; @@ -156,13 +156,13 @@ class UserFriend extends UserManager { * @param int user id * @param int group id * @param string name to search - * @param array + * @param array */ public static function get_list_path_web_by_user_id ($user_id,$id_group=null,$search_name=null) { $list_paths=array(); $list_path_friend=array(); $array_path_user=array(); - $combine_friend = array(); + $combine_friend = array(); $list_ids = self::get_list_id_friends_by_user_id ($user_id,$id_group,$search_name); if (is_array($list_ids)) { foreach ($list_ids as $values_ids) { @@ -186,7 +186,7 @@ class UserFriend extends UserManager { $list_path_image_friend[] = UserManager::get_user_picture_path_by_id($values_ids['user_sender_id'],'web',false,true); } return $list_path_image_friend; - } + } /** * allow to sent an invitation to my contacts * @author isaac flores paz @@ -206,21 +206,21 @@ class UserFriend extends UserManager { if ($row_exist['count']==0) { $sql='INSERT INTO '.$tbl_message.'(user_sender_id,user_receiver_id,msg_status,send_date,title,content) VALUES('.((int)$user_id).','.((int)$friend_id).','.((int)$status_invitation).',"'.$current_date.'","'.$message_title.'","'.$message_content.'")'; Database::query($sql,__FILE__,__LINE__); - return true; + return true; } elseif ($row_exist['count']==1) { $sql_if_exist='SELECT COUNT(*) AS count FROM '.$tbl_message.' WHERE user_sender_id='.((int)$user_id).' AND user_receiver_id='.((int)$friend_id).' AND msg_status=7'; $res_if_exist=Database::query($sql_if_exist,__FILE__,__LINE__); $row_if_exist=Database::fetch_array($res_if_exist,'ASSOC'); if ($row_if_exist['count']==1) { - $sql_if_exist_up='UPDATE '.$tbl_message.'SET msg_status=5 WHERE user_sender_id='.((int)$user_id).' AND user_receiver_id='.((int)$friend_id).';'; + $sql_if_exist_up='UPDATE '.$tbl_message.'SET msg_status=5 WHERE user_sender_id='.((int)$user_id).' AND user_receiver_id='.((int)$friend_id).';'; Database::query($sql_if_exist_up,__FILE__,__LINE__); return true; } else { - return false; + return false; } } else { - return false; + return false; } } @@ -278,7 +278,7 @@ class UserFriend extends UserManager { $tbl_message=Database::get_main_table(TABLE_MAIN_MESSAGE); $msg_status=7; $sql='UPDATE '.$tbl_message.' SET msg_status='.$msg_status.' WHERE user_sender_id='.((int)$user_send_id).' AND user_receiver_id='.((int)$user_receiver_id).';'; - Database::query($sql,__FILE__,__LINE__); + Database::query($sql,__FILE__,__LINE__); } /** * allow attach to group @@ -291,7 +291,7 @@ class UserFriend extends UserManager { $tbl_user_friend=Database::get_main_table(TABLE_MAIN_USER_FRIEND); $user_id=api_get_user_id(); $sql='UPDATE '.$tbl_user_friend.' SET relation_type='.((int)$type_qualify).' WHERE user_id='.((int)$user_id).' AND friend_user_id='.((int)$id_friend_qualify).';'; - Database::query($sql,__FILE__,__LINE__); + Database::query($sql,__FILE__,__LINE__); } /** * Send invitation a your friends @@ -305,11 +305,11 @@ class UserFriend extends UserManager { $user_info=api_get_user_info($userfriend_id); $succes=get_lang('MessageSentTo'); $succes.= ' : '.api_get_person_name($user_info['firstName'], $user_info['lastName']); - if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) { + if (isset($subject_message) && isset($content_message) && isset($userfriend_id)) { $send_message = MessageManager::send_message(((int)$userfriend_id),Database::escape_string($subject_message), Database::escape_string($content_message)); if ($send_message) { echo Display::display_confirmation_message($succes,true); - } else { + } else { echo Display::display_error_message($succes,true); } exit; @@ -326,10 +326,10 @@ class UserFriend extends UserManager { if ($count_is_true) { echo Display::display_normal_message(get_lang('InvitationHasBeenSent')); }else { - echo Display::display_error_message(get_lang('InvitationHasBeenNotSent')); + echo Display::display_error_message(get_lang('InvitationHasBeenNotSent')); } - + } } - } + } } \ No newline at end of file diff --git a/main/inc/lib/sortabletable.class.php b/main/inc/lib/sortabletable.class.php index 8101497005..44658047af 100644 --- a/main/inc/lib/sortabletable.class.php +++ b/main/inc/lib/sortabletable.class.php @@ -107,7 +107,7 @@ class SortableTable extends HTML_Table { * table */ public $other_tables; - + /** * Create a new SortableTable @@ -128,19 +128,19 @@ class SortableTable extends HTML_Table { $this->table_name = $table_name; $this->additional_parameters = array (); $this->param_prefix = $table_name.'_'; - + $this->page_nr = isset ($_SESSION[$this->param_prefix.'page_nr']) ? intval($_SESSION[$this->param_prefix.'page_nr']) : 1; $this->page_nr = isset ($_GET[$this->param_prefix.'page_nr']) ? intval($_GET[$this->param_prefix.'page_nr']) : $this->page_nr; $this->column = isset ($_SESSION[$this->param_prefix.'column']) ? intval($_SESSION[$this->param_prefix.'column']) : $default_column; $this->column = isset ($_GET[$this->param_prefix.'column']) ? intval($_GET[$this->param_prefix.'column']) : $this->column; - + //$this->direction = isset ($_SESSION[$this->param_prefix.'direction']) ? $_SESSION[$this->param_prefix.'direction'] : $default_order_direction; - - + + if (isset($_SESSION[$this->param_prefix.'direction'])) { $my_session_direction = $_SESSION[$this->param_prefix.'direction']; if(!in_array($my_session_direction, array('ASC','DESC'))){ - $this->direction = 'ASC'; + $this->direction = 'ASC'; } else { if ($my_session_direction=='ASC') { $this->direction = 'ASC'; @@ -148,12 +148,12 @@ class SortableTable extends HTML_Table { $this->direction = 'DESC'; } } - } - + } + if (isset($_GET[$this->param_prefix.'direction'])) { - $my_get_direction = $_GET[$this->param_prefix.'direction']; + $my_get_direction = $_GET[$this->param_prefix.'direction']; if(!in_array($my_get_direction, array('ASC','DESC'))){ - $this->direction = 'ASC'; + $this->direction = 'ASC'; } else { if ($my_get_direction=='ASC') { $this->direction = 'ASC'; @@ -165,10 +165,10 @@ class SortableTable extends HTML_Table { //allow to change paginate in multiples tabs unset($_SESSION[$this->param_prefix.'per_page']); - + $this->per_page = isset ($_SESSION[$this->param_prefix.'per_page']) ? intval($_SESSION[$this->param_prefix.'per_page']) : $default_items_per_page; $this->per_page = isset ($_GET[$this->param_prefix.'per_page']) ? intval($_GET[$this->param_prefix.'per_page']) : $this->per_page; - + $_SESSION[$this->param_prefix.'per_page'] = $this->per_page; $_SESSION[$this->param_prefix.'direction'] = $this->direction ; $_SESSION[$this->param_prefix.'page_nr'] = $this->page_nr; @@ -237,7 +237,7 @@ class SortableTable extends HTML_Table { $message_empty=get_lang('TheListIsEmpty'); } $this->setCellContents(1, 0,$message_empty); - + $empty_table = true; } $html=''; @@ -462,7 +462,7 @@ class SortableTable extends HTML_Table { $param[$tablename.'_direction'] = 'ASC'; } else { $param[$tablename.'_direction'] = $my_get_direction; - } + } } if( isset($_GET[$tablename.'_page_nr'])) $param[$tablename.'_page_nr'] = intval($_GET[$tablename.'_page_nr']); @@ -559,7 +559,7 @@ class SortableTable extends HTML_Table { $row[0] .= '/>'; } } - + foreach ($row as $index => $value) { if (strlen($row[$index]) == 0) { @@ -636,61 +636,61 @@ class SortableTableFromArray extends SortableTable { /** * Sortable table which can be used for data available in an array - * + * * Is a variation of SortableTableFromArray because we add 2 new arrays $column_show and $column_order * $column_show is an array that lets us decide which are going to be the columns to show - * $column_order is an array that lets us decide the ordering of the columns + * $column_order is an array that lets us decide the ordering of the columns * i.e: $column_header=array('a','b','c','d','e'); $column_order=array(1,2,5,4,5); - * These means that the 3th column (letter "c") will be sort like the order we use in the 5th column + * These means that the 3th column (letter "c") will be sort like the order we use in the 5th column */ - -class SortableTableFromArrayConfig extends SortableTable { + +class SortableTableFromArrayConfig extends SortableTable { /** * The array containing the columns that will be show i.e $column_show=array('1','0','0'); we will show only the 1st column */ private $column_show; - + /** - *The array containing the real sort column $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column + *The array containing the real sort column $column_order=array('1''4','3','4'); The 2nd column will be order like the 4th column */ - private $column_order; + private $column_order; /** * The array containing all data for this table */ private $table_data; - + /** * Constructor * @param array $table_data All the information of the table - * @param int $default_column Default column that will be use in the sorts functions + * @param int $default_column Default column that will be use in the sorts functions * @param int $default_items_per_page quantity of pages that we are going to see * @param int $tablename Name of the table - * @param array $column_show An array with binary values 1: we show the column 2: we don't show it - * @param array $column_order An array of integers that let us decide how the columns are going to be sort. - */ + * @param array $column_show An array with binary values 1: we show the column 2: we don't show it + * @param array $column_order An array of integers that let us decide how the columns are going to be sort. + */ public function __construct ($table_data, $default_column = 1, $default_items_per_page = 20, $tablename = 'tablename',$column_show=null,$column_order=null,$direction='ASC') { $this->column_show=$column_show; $this->column_order=$column_order; - + parent :: __construct ($tablename, null, null, $default_column, $default_items_per_page,$direction); - + $this->table_data = $table_data; } /** * Get table data to show on current page * @see SortableTable#get_table_data */ - public function get_table_data($from = 1) { + public function get_table_data($from = 1) { $content = TableSort :: sort_table_config($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC ,$this->column_show, $this->column_order); return array_slice($content, $from, $this->per_page); } - + /** * Get total number of items * @see SortableTable#get_total_number_of_items */ public function get_total_number_of_items () { return count($this->table_data); - } + } } ?> diff --git a/main/inc/lib/specific_fields_manager.lib.php b/main/inc/lib/specific_fields_manager.lib.php index bafb264c7e..3f6cc8c06e 100644 --- a/main/inc/lib/specific_fields_manager.lib.php +++ b/main/inc/lib/specific_fields_manager.lib.php @@ -45,7 +45,7 @@ function delete_specific_field($id) { $sql = 'DELETE FROM %s WHERE id=%s LIMIT 1'; $sql = sprintf($sql, $table_sf, $id); $result = api_sql_query($sql,__FILE__,__LINE__); - //TODO also delete the corresponding values + //TODO also delete the corresponding values } /** @@ -180,7 +180,7 @@ function delete_all_specific_field_value($course_id, $id_specific_field, $tool_i } /** - * Delete all values from a specific item (course_id, tool_id and ref_id). + * Delete all values from a specific item (course_id, tool_id and ref_id). * To be used when deleting such item from Dokeos * @param string Course code * @param string Tool ID @@ -210,14 +210,14 @@ function get_specific_field_code_from_name($name) { $code = strtoupper(substr($name,0,1)); //if no code exists in DB, return current one if (Database::num_rows($res)<1) { return $code;} - + $existing_list = array(); while ($row = Database::fetch_array($res)) { $existing_list[] = $row['code']; } //if the current code doesn't exist in DB, return current one if (!in_array($code,$existing_list)) { return $code;} - + $idx = array_search($code,$list); $c = count($list); for ($i = $idx+1, $j=0 ; $j<$c ; $i++, $j++) { diff --git a/main/inc/lib/stats.lib.inc.php b/main/inc/lib/stats.lib.inc.php index 6ef03c0b29..9577735f02 100644 --- a/main/inc/lib/stats.lib.inc.php +++ b/main/inc/lib/stats.lib.inc.php @@ -1,43 +1,43 @@ - @@ -91,11 +91,11 @@ $TABLESTATS_REFERERS = $_configuration['statistics_database']."`.`track_c_ref information, to count occurences (for os, provider,...) and to increment the number of occurrences of each different element into the corresponding tables - */ + */ function decodeOpenInfos() { global $TABLETRACK_OPEN; - + // record initial value of ignore_user_abort $ignore = ignore_user_abort(); // prevent script from being stopped while executing, the following can be considered @@ -103,7 +103,7 @@ function decodeOpenInfos() ignore_user_abort(1) ; // we take the last event id to prevent miss of some recorded event // only processed record have to be cleaned - $sql = "SELECT open_id + $sql = "SELECT open_id FROM `$TABLETRACK_OPEN` WHERE open_date <= NOW() ORDER BY open_id DESC @@ -117,30 +117,30 @@ function decodeOpenInfos() $res = @mysql_fetch_array($query); $processBegin = $res[0]; // process - + //--Providers And Countries-------------------------------------------// - $sql = "SELECT open_remote_host - FROM `$TABLETRACK_OPEN` + $sql = "SELECT open_remote_host + FROM `$TABLETRACK_OPEN` WHERE open_remote_host != '' AND open_id <= '".$processBegin."' "; $query = mysql_query( $sql ); if( mysql_num_rows($query) != 0 ) { - // load list of countries + // load list of countries $list_countries = loadCountries(); - - while ($row = mysql_fetch_row ($query) ) + + while ($row = mysql_fetch_row ($query) ) { $remote_host = $row[0]; /*****Provider*****/ - //extract provider + //extract provider $provider = extractProvider( $remote_host ); // add or increment provider in the providers array $providers_array = addProvider( $provider,$providers_array ); - + /*****Countries*****/ - // extract country + // extract country $country = extractCountry( $remote_host, $list_countries ); // increment country in the countries table $countries_array = addCountry( $country, $countries_array ); @@ -151,11 +151,11 @@ function decodeOpenInfos() fillCountriesTable( $countries_array ); } // provider and countries done - + //--Browsers and OS---------------------------------------------------// - + $sql = "SELECT open_agent - FROM `$TABLETRACK_OPEN` + FROM `$TABLETRACK_OPEN` WHERE open_remote_host != '' AND open_id <= '".$processBegin."' "; $query = mysql_query( $sql ); @@ -166,8 +166,8 @@ function decodeOpenInfos() $list_browsers = loadBrowsers(); // of OS $list_os = loadOs(); - - while ( $row = mysql_fetch_row ($query) ) + + while ( $row = mysql_fetch_row ($query) ) { $agent = $row[0]; /*****Browser and OS*****/ @@ -177,15 +177,15 @@ function decodeOpenInfos() $browsers_array = addBrowser( $browser , $browsers_array ); $os_array = addOs( $os , $os_array ); } - + fillBrowsersTable( $browsers_array ); fillOsTable( $os_array ); } - // browsers and OS done - - //--Referers----------------------------------------------------------// + // browsers and OS done + + //--Referers----------------------------------------------------------// $sql = "SELECT open_referer FROM `$TABLETRACK_OPEN` @@ -197,22 +197,22 @@ function decodeOpenInfos() { $i=0; - while ($row = mysql_fetch_row ($query) ) + while ($row = mysql_fetch_row ($query) ) { $ref = $row[0]; $referers_array = addReferer( $ref , $referers_array ); } fillReferersTable( $referers_array ); } - - // referers done - + + // referers done + //-------------------------------------------------------------------// - + // end of process // cleaning of $TABLETRACK_OPEN table cleanProcessedRecords($processBegin); - + // reset to the initial value ignore_user_abort($ignore); } @@ -230,23 +230,23 @@ function decodeOpenInfos() * @author Sebastien Piraux * @param limit : all records BEFORE $limit will be affected * @desc this function will delete the remote_host, user_agent - and referer rows from the track_open table recorded before + and referer rows from the track_open table recorded before the date $limit. OPTIMIZE is called to get back the memory espaces deleted */ function cleanProcessedRecords( $limit ) { global $TABLETRACK_OPEN; - $sql = "UPDATE `".$TABLETRACK_OPEN."` + $sql = "UPDATE `".$TABLETRACK_OPEN."` SET open_remote_host = '', open_agent = '', open_referer ='' WHERE open_id <= '".$limit."'"; - + $query = mysql_query( $sql ); - + mysql_query("OPTIMIZE TABLE $TABLETRACK_OPEN"); - + } @@ -261,41 +261,41 @@ function cleanProcessedRecords( $limit ) * @author Sebastien Piraux * @param remhost : must be @getHostByAddr($_SERVER['REMOTE_ADDR'] - * @desc this function will extract the provider name from a given - remote host and record this occurence in the corresponding + * @desc this function will extract the provider name from a given + remote host and record this occurence in the corresponding table */ function extractProvider($remhost) { - + if($remhost == "Unknown") return $remhost; - + $explodedRemhost = explode(".", $remhost); $provider = $explodedRemhost[sizeof( $explodedRemhost )-2] ."." .$explodedRemhost[sizeof( $explodedRemhost )-1]; - + if($provider == "co.uk" || $provider == "co.jp") return $explodedRemhost[sizeof( $explodedRemhost )-3].$provider; else return $provider; - + } /** * @author Sebastien Piraux - * @param provider : name of the provider + * @param provider : name of the provider * @param providers_array : list of providers and their counter - * @desc this function will : - - if the provider is already in the array it will increment + * @desc this function will : + - if the provider is already in the array it will increment the corresponding value - if the provider doesn't exist it will be added and set to 1 */ function addProvider($provider,$providers_array) { - if( isset( $providers_array[$provider] ) ) + if( isset( $providers_array[$provider] ) ) { // add one unity to this provider occurrences $providers_array[$provider] = $providers_array[$provider] + 1; @@ -317,7 +317,7 @@ function addProvider($provider,$providers_array) function fillProvidersTable($providers_array) { global $TABLESTATS_PROVIDERS; - + if(is_array($providers_array)) { foreach ( $providers_array as $prov=>$number ) @@ -326,7 +326,7 @@ function fillProvidersTable($providers_array) FROM `".$TABLESTATS_PROVIDERS."` WHERE `provider` = '".$prov."'"; $res = mysql_query($sql); - + // if this provider already exists in the DB if( $row = mysql_num_rows($res) ) { @@ -338,13 +338,13 @@ function fillProvidersTable($providers_array) else { // insert - $sql2 = "INSERT INTO `".$TABLESTATS_PROVIDERS."` - (`provider`,`counter`) + $sql2 = "INSERT INTO `".$TABLESTATS_PROVIDERS."` + (`provider`,`counter`) VALUES ('".$prov."','".$number."')"; } mysql_query($sql2); - } - } + } + } } /*************************************************************************** @@ -357,23 +357,23 @@ function fillProvidersTable($providers_array) * @author Sebastien Piraux * @return a 2D array filled with code and name of countries - * @desc This function is used to build an array containing + * @desc This function is used to build an array containing countries informations */ function loadCountries() -{ +{ global $TABLESTATS_COUNTRIES; - + $sql = "SELECT code, country FROM `".$TABLESTATS_COUNTRIES."`"; - + $res = mysql_query( $sql ); - + $i = 0 ; - while( $row = mysql_fetch_array( $res ) ) { + while( $row = mysql_fetch_array( $res ) ) { $list_countries[$i][0] = $row["code"]; $list_countries[$i][1] = $row["country"]; - $i++; + $i++; } return $list_countries; mysql_free_result($res); @@ -384,7 +384,7 @@ function loadCountries() * @author Sebastien Piraux * @param remhost : must be @getHostByAddr($_SERVER['REMOTE_ADDR'] - * @param list_countries : list of countries -__- + * @param list_countries : list of countries -__- * @return Name of the country or "Unknown" if not found * @desc this function will extract the country from a given remote host and increment the good value in the corresponding table @@ -396,7 +396,7 @@ function extractCountry($remhost,$list_countries) // country code is the last value of remote host $explodedRemhost = explode(".",$remhost); $countryCode = $explodedRemhost[sizeof( $explodedRemhost )-1]; - + for($i = 0 ; $i < sizeof( $list_countries );$i++) { if($list_countries[$i][0] == $countryCode) @@ -408,15 +408,15 @@ function extractCountry($remhost,$list_countries) /** * @author Sebastien Piraux - * @param country : name of the country or 'Unknown' - * @param countries_array : list of countries and their + * @param country : name of the country or 'Unknown' + * @param countries_array : list of countries and their number of occurence - * @desc this function will increment number of occurrence + * @desc this function will increment number of occurrence for $country in the countries' tables */ function addCountry($country,$countries_array) { - if( isset( $countries_array[$country] ) ) + if( isset( $countries_array[$country] ) ) { // add one unity to this provider occurrences $countries_array[$country] = $countries_array[$country] + 1; @@ -427,7 +427,7 @@ function addCountry($country,$countries_array) $countries_array[$country] = 1; } return $countries_array; - + } @@ -440,7 +440,7 @@ function addCountry($country,$countries_array) function fillCountriesTable($countries_array) { global $TABLESTATS_COUNTRIES; - if(is_array($countries_array) ) + if(is_array($countries_array) ) { foreach ( $countries_array as $country=>$number ) { @@ -451,7 +451,7 @@ function fillCountriesTable($countries_array) WHERE `country` = '".$country."'"; mysql_query($sql); - } + } } } @@ -465,11 +465,11 @@ function fillCountriesTable($countries_array) * @author Sebastien Piraux * @return a 2D array filled with code and name of browsers - * @desc This function is used to build an array containing + * @desc This function is used to build an array containing browser informations */ function loadBrowsers() -{ +{ $buffer = split ("#","Gecko|Gecko#Mozilla/3|Mozilla 3.x#Mozilla/4.0|Mozilla 4.0x#Mozilla/4.5|Mozilla 4.5x#Mozilla/4.6|Mozilla 4.6x#Mozilla/4.7|Mozilla 4.7x#Mozilla/5.0|Mozilla 5.0x#MSIE 1.2|MSIE 1.2#MSIE 3.01|MSIE 3.x#MSIE 3.02|MSIE 3.x#MSIE 4.0|MSIE 4.x#MSIE 4.01|MSIE 4.x#MSIE 4.5|MSIE 4.5#MSIE 5.0b1|MSIE 5.0x#MSIE 5.0b2|MSIE 5.0x#MSIE 5.0|MSIE 5.0x#MSIE 5.01|MSIE 5.0x#MSIE 5.1|MSIE 5.1#MSIE 5.1b1|MSIE 5.1#MSIE 5.5|MSIE 5.5#MSIE 5.5b1|MSIE 5.5#MSIE 5.5b2|MSIE 5.5#MSIE 6.0|MSIE 6#MSIE 6.0b|MSIE 6#MSIE 6.5a|MSIE 6.5#Lynx/2.8.0|Lynx 2#Lynx/2.8.1|Lynx 2#Lynx/2.8.2|Lynx 2#Lynx/2.8.3|Lynx 2#Lynx/2.8.4|Lynx 2#Lynx/2.8.5|Lynx 2#HTTrack 3.0x|HTTrack#OmniWeb/4.0.1|OmniWeb#Opera 3.60|Opera 3.60#Opera 4.0|Opera 4#Opera 4.01|Opera 4#Opera 4.02|Opera 4#Opera 5|Opera 5#Opera/3.60|Opera 3.60#Opera/4|Opera 4#Opera/5|Opera 5#Opera/6|Opera 6#Opera 6|Opera 6#Netscape6|NS 6#Netscape/6|NS 6#Netscape7|NS 7#Netscape/7|NS 7#Konqueror/2.0|Konqueror 2#Konqueror/2.0.1|Konqueror 2#Konqueror/2.1|Konqueror 2#Konqueror/2.1.1|Konqueror 2#Konqueror/2.1.2|Konqueror 2#Konqueror/2.2|Konqueror 2#Teleport Pro|Teleport Pro#WebStripper|WebStripper#WebZIP|WebZIP#Netcraft Web|NetCraft#Googlebot|Googlebot#WebCrawler|WebCrawler#InternetSeer|InternetSeer#ia_archiver|ia archiver"); @@ -487,11 +487,11 @@ function loadBrowsers() * @author Sebastien Piraux * @return a 2D array filled with code and name of OS - * @desc This function is used to build an array containing + * @desc This function is used to build an array containing OS informations */ function loadOs() -{ +{ $buffer = split ("#","Windows 95|Win 95#Windows_95|Win 95#Windows 98|Win 98#Windows NT|Win NT#Windows NT 5.0|Win 2000#Windows NT 5.1|Win XP#Windows 2000|Win 2000#Windows XP|Win XP#Windows ME|Win Me#Win95|Win 95#Win98|Win 98#WinNT|Win NT#linux-2.2|Linux 2#Linux|Linux#Linux 2|Linux 2#Macintosh|Mac#Mac_PPC|Mac#Mac_PowerPC|Mac#SunOS 5|SunOS 5#SunOS 6|SunOS 6#FreeBSD|FreeBSD#beOS|beOS#InternetSeer|InternetSeer#Googlebot|Googlebot#Teleport Pro|Teleport Pro"); $i=0; foreach( $buffer as $buffer1 ) { @@ -506,9 +506,9 @@ function loadOs() * @param remhost : must be $_SERVER['HTTP_USER_AGENT'] * @param list_browsers : browsers list :x * @param list_os : os list :x - * @return a string formatted like : browser|OS + * @return a string formatted like : browser|OS browser and OS are the 'viewable' names - * @desc this function will extract browser and OS from + * @desc this function will extract browser and OS from $_SERVER['HTTP_USER_AGENT'] */ function extractAgent( $user_agent, $list_browsers, $list_os ) @@ -516,44 +516,44 @@ function extractAgent( $user_agent, $list_browsers, $list_os ) // default values, if nothing corresponding found $viewable_browser = "Unknown"; $viewable_os = "Unknown"; - + // search for corresponding pattern in $_SERVER['HTTP_USER_AGENT'] // for browser for($i = 0; $i < count( $list_browsers ); $i++) { $pos = strpos( $user_agent, $list_browsers[$i][0] ); if( $pos !== false ) - { + { $viewable_browser = $list_browsers[$i][1]; - } + } } - + // for os for($i = 0; $i < count($list_os); $i++) { $pos = strpos( $user_agent, $list_os[$i][0] ); if( $pos !== false ) - { + { $viewable_os = $list_os[$i][1]; } } return $viewable_browser."|".$viewable_os; - -} + +} /** * @author Sebastien Piraux * @param browser : name of the browser or 'Unknown' * @param browsers_array : - * @desc this function will : - - if the browser is already in the table it will increment + * @desc this function will : + - if the browser is already in the table it will increment the corresponding value - if the browser doesn't exist it will be added and set to 1 */ function addBrowser($browser,$browsers_array) { - if( isset( $browsers_array[$browser] ) ) + if( isset( $browsers_array[$browser] ) ) { // add one unity to this provider occurrences $browsers_array[$browser] = $browsers_array[$browser] + 1; @@ -564,7 +564,7 @@ function addBrowser($browser,$browsers_array) $browsers_array[$browser] = 1; } return $browsers_array; - + } /** @@ -572,14 +572,14 @@ function addBrowser($browser,$browsers_array) * @author Sebastien Piraux * @param os : name of the OS or 'Unknown' * @param os_array : list of os and number of occurences - * @desc this function will : - - if the os is already in the table it will increment + * @desc this function will : + - if the os is already in the table it will increment the corresponding value - if the os doesn't exist it will be added and set to 1 */ function addOs($os,$os_array) { - if( isset( $os_array[$os] ) ) + if( isset( $os_array[$os] ) ) { // add one unity to this provider occurrences $os_array[$os] = $os_array[$os] + 1; @@ -590,7 +590,7 @@ function addOs($os,$os_array) $os_array[$os] = 1; } return $os_array; - + } /** @@ -602,7 +602,7 @@ function addOs($os,$os_array) function fillBrowsersTable($browsers_array) { global $TABLESTATS_BROWSERS; - if ( is_array($browsers_array ) ) + if ( is_array($browsers_array ) ) { foreach ( $browsers_array as $browser=>$number ) { @@ -622,12 +622,12 @@ function fillBrowsersTable($browsers_array) else { // insert - $sql2 = "INSERT INTO `".$TABLESTATS_BROWSERS."` - (`browser`,`counter`) + $sql2 = "INSERT INTO `".$TABLESTATS_BROWSERS."` + (`browser`,`counter`) VALUES ('".$browser."','".$number."')"; } mysql_query($sql2); - } + } } } @@ -660,12 +660,12 @@ function fillOsTable($os_array) else { // insert - $sql2 = "INSERT INTO `".$TABLESTATS_OS."` - (`os`,`counter`) + $sql2 = "INSERT INTO `".$TABLESTATS_OS."` + (`os`,`counter`) VALUES ('".$os."','".$number."')"; } mysql_query($sql2); - } + } } } @@ -681,14 +681,14 @@ function fillOsTable($os_array) * @author Sebastien Piraux * @param referer : name of the referer * @param referers_array : list of referer and number of occurences - * @desc this function will : - - if the referer is already in the table it will increment + * @desc this function will : + - if the referer is already in the table it will increment the corresponding value - if the referer doesn't exist it will be added and set to 1 */ function addReferer($referer,$referers_array) { - if( isset( $referers_array[$referer] ) ) + if( isset( $referers_array[$referer] ) ) { // add one unity to this provider occurrences $referers_array[$referer] = $referers_array[$referer] + 1; @@ -699,9 +699,9 @@ function addReferer($referer,$referers_array) $referers_array[$referer] = 1; } return $referers_array; - + } - + /** @@ -712,7 +712,7 @@ function addReferer($referer,$referers_array) function fillReferersTable($referers_array) { global $TABLESTATS_REFERERS; - if (is_array($referers_array) ) + if (is_array($referers_array) ) { foreach ( $referers_array as $referer=>$number ) { @@ -720,7 +720,7 @@ function fillReferersTable($referers_array) FROM `".$TABLESTATS_REFERERS."` WHERE `referer` = '".$referer."'"; $res = mysql_query($sql); - + // if this provider already exists in the DB if( $row = mysql_num_rows($res) ) { @@ -732,8 +732,8 @@ function fillReferersTable($referers_array) else { // insert - $sql2 = "INSERT INTO `".$TABLESTATS_REFERERS."` - (`referer`,`counter`) + $sql2 = "INSERT INTO `".$TABLESTATS_REFERERS."` + (`referer`,`counter`) VALUES ('".$referer."','".$number."')"; } mysql_query($sql2); diff --git a/main/inc/lib/statsUtils.lib.inc.php b/main/inc/lib/statsUtils.lib.inc.php index 9a7ecb3c67..373d73adff 100644 --- a/main/inc/lib/statsUtils.lib.inc.php +++ b/main/inc/lib/statsUtils.lib.inc.php @@ -1,39 +1,39 @@ * @param sql : a sql query (as a string) - * @return hours_array + * @return hours_array * @desc Return an assoc array. Keys are the hours, values are the number of time this hours was found. key 'total' return the sum of all number of time hours @@ -187,7 +187,7 @@ function hoursTab($sql) { $hours_array = array('total' => 0); $res = mysql_query($sql); - + if (mysql_errno()) { echo "\n\n"; @@ -212,7 +212,7 @@ function hoursTab($sql) } mysql_free_result($res); } - + return $hours_array; } @@ -255,7 +255,7 @@ function daysTab($sql) } mysql_free_result($res); } - + return $days_array; } @@ -263,7 +263,7 @@ function daysTab($sql) * @author Sebastien Piraux * @param sql : a sql query (as a string) - * @return month_array + * @return month_array * @desc Return an assoc array. Keys are the days, values are the number of time this hours was found. key "total" return the sum of all number of time days @@ -274,7 +274,7 @@ function monthTab($sql) $MonthsLong = array (get_lang('JanuaryLong'), get_lang('FebruaryLong'), get_lang('MarchLong'), get_lang('AprilLong'), get_lang('MayLong'), get_lang('JuneLong'), get_lang('JulyLong'), get_lang('AugustLong'), get_lang('SeptemberLong'), get_lang('OctoberLong'), get_lang('NovemberLong'), get_lang('DecemberLong')); $month_array = array('total' => 0); $res = mysql_query($sql); - + if (mysql_errno()) { echo "\n\n"; @@ -295,7 +295,7 @@ function monthTab($sql) } mysql_free_result($res); } - + return $month_array; } @@ -304,7 +304,7 @@ function monthTab($sql) * @author Sebastien Piraux * @param period_array : an array provided by hoursTab($sql) or daysTab($sql) * @param periodTitle : title of the first column, type of period - * @param linkOnPeriod : + * @param linkOnPeriod : * @desc Display a 4 column array Columns are : hour of day, graph, number of hits and % First line are titles @@ -334,7 +334,7 @@ function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???') $maxSize = $factor * 100; //pixels while(list($periodPiece, $cpt) = each($period_array)) { - if($periodPiece != 'total') + if($periodPiece != 'total') { $pourcent = round(100 * $cpt / $period_array['total']); $barwidth = $factor * $pourcent ; @@ -345,12 +345,12 @@ function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???') " // display hitbar ."$periodPiece : $cpt hits – $pourcent %"; - if($pourcent != 0) + if($pourcent != 0) echo "$periodPiece : $cpt hits – $pourcent %"; // display 100% bar if($pourcent != 100 && $pourcent != 0) echo "$periodPiece : $cpt hits – $pourcent %"; - if($pourcent != 100) + if($pourcent != 100) echo "$periodPiece : $cpt hits – $pourcent %"; echo "$periodPiece : $cpt hits – $pourcent % @@ -369,13 +369,13 @@ function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???') ".get_lang('Total')." -   +   - ".$period_array['total']." + ".$period_array['total']." -   +   "; @@ -392,7 +392,7 @@ function makeHitsTable($period_array, $periodTitle, $linkOnPeriod = '???') titles of columns are title1 and title2 */ function buildTab2col($array_of_results, $title1, $title2) -{ +{ echo "\n"; echo "\n"; if (is_array($array_of_results)) - { + { for($j = 0 ; $j < count($array_of_results) ; $j++) { - echo ''; + echo ''; echo ''; echo ''; echo "\n"; @@ -415,7 +415,7 @@ function buildTab2col($array_of_results, $title1, $title2) } else { - echo ''; + echo ''; echo ''; echo "\n"; } @@ -458,22 +458,22 @@ function buildTab2ColNoTitle($array_of_results) * @param array_of_results : a 2 columns array * @desc this function is used to display integrity errors in the platform - if array_of_results is not an array there is + if array_of_results is not an array there is no error, else errors are displayed */ function buildTabDefcon($array_of_results) { echo "
@@ -404,10 +404,10 @@ function buildTab2col($array_of_results, $title1, $title2)
'.$array_of_results[$j][0].''.$array_of_results[$j][1].'
'.get_lang('NoResult').'
\n"; - + if (is_array($array_of_results)) - { - // there are some strange cases... - echo ''; + { + // there are some strange cases... + echo ''; echo ''; echo "\n"; for($j = 0 ; $j < count($array_of_results) ; $j++) - { + { if($array_of_results[$j][0] == "") { $key = get_lang('NULLValue'); @@ -482,7 +482,7 @@ function buildTabDefcon($array_of_results) { $key = $array_of_results[$j][0]; } - echo ''; + echo ''; echo ''; echo ''; echo "\n"; @@ -491,7 +491,7 @@ function buildTabDefcon($array_of_results) else { // all right - echo ''; + echo ''; echo ''; echo "\n"; } diff --git a/main/inc/lib/surveymanager.lib.php b/main/inc/lib/surveymanager.lib.php index dedccf172d..f1fc037b7c 100644 --- a/main/inc/lib/surveymanager.lib.php +++ b/main/inc/lib/surveymanager.lib.php @@ -32,7 +32,7 @@ */ class SurveyManager { private function __construct() { - + } /** * Creates a new survey for the platform @@ -82,8 +82,8 @@ class SurveyManager { * Possible deprecated method */ function create_group($survey_id,$group_title,$introduction,$table_group) - { - + { + $sql_query = "SELECT * FROM $table_group WHERE groupname='".Database::escape_string($group_title)."' AND survey_id=".Database::escape_string($survey_id); $res = api_sql_query($sql_query, __FILE__, __LINE__); if(mysql_num_rows($res)) @@ -155,11 +155,11 @@ class SurveyManager { /** * Possible deprecated method */ - function insert_into_group ($survey_id,$group_title,$introduction,$tb) { + function insert_into_group ($survey_id,$group_title,$introduction,$tb) { $survey_id = Database::escape_string($survey_id); $group_title = Database::escape_string($group_title); - $introduction = Database::escape_string($introduction); - + $introduction = Database::escape_string($introduction); + $sql="INSERT INTO $tb (group_id,survey_id,group_title,introduction) values('','$survey_id','$group_title','$introduction')"; $result=api_sql_query($sql); return mysql_insert_id(); @@ -453,7 +453,7 @@ class SurveyManager { } /** * Possible deprecated method - */ + */ function get_surveyname_display($sid) { $sid = Database::escape_string($sid); @@ -463,7 +463,7 @@ class SurveyManager { $code=@mysql_result($res,0,'title'); return($code); } - + /* function join_survey($question_type) { @@ -478,7 +478,7 @@ class SurveyManager { */ /** * Possible deprecated method - */ + */ function import_questions($import_type, $ids) { //$groupname=surveymanager::get_groupname($gid_arr[$index]); @@ -529,7 +529,7 @@ class SurveyManager { $table_question = Database :: get_course_table(TABLE_MAIN_SURVEYQUESTION); $survey_id = Database::escape_string($survey_id); - + // Deleting the survey $sql = "DELETE FROM $table_survey WHERE survey_id='".$survey_id."'"; api_sql_query($sql,__FILE__,__LINE__); @@ -1771,100 +1771,100 @@ function getUserAnswersDetails($id_userAnswers, $params=''){ /** - * + * * Manage the "versioning" of a conditional survey - * + * * */ class SurveyTree { - public $surveylist; + public $surveylist; public $plainsurveylist; public $numbersurveys; - + /** * Sets the surveylist and the plainsurveylist */ - public function __construct() { + public function __construct() { // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_user = Database :: get_main_table(TABLE_MAIN_USER); - + // searching $search_restriction = SurveyUtil::survey_search_restriction(); if ($search_restriction) { $search_restriction = ' AND '.$search_restriction; } - + $sql = "SELECT survey.survey_id , survey.parent_id, survey_version, survey.code as name - FROM $table_survey survey - LEFT JOIN $table_survey_question survey_question - ON survey.survey_id = survey_question.survey_id , $table_user user - WHERE survey.author = user.user_id + FROM $table_survey survey + LEFT JOIN $table_survey_question survey_question + ON survey.survey_id = survey_question.survey_id , $table_user user + WHERE survey.author = user.user_id GROUP BY survey.survey_id"; - + $res = api_sql_query($sql, __FILE__, __LINE__); - $surveys_parents = array (); + $surveys_parents = array (); $refs = array(); $list = array(); - $last=array(); + $last=array(); $plain_array=array(); - + while ($survey = Database::fetch_array($res,'ASSOC')) { $plain_array[$survey['survey_id']]=$survey; - $surveys_parents[]=$survey['survey_version']; - $thisref = &$refs[ $survey['survey_id'] ]; + $surveys_parents[]=$survey['survey_version']; + $thisref = &$refs[ $survey['survey_id'] ]; $thisref['parent_id'] = $survey['parent_id']; $thisref['name'] = $survey['name']; $thisref['id'] = $survey['survey_id']; - $thisref['survey_version'] = $survey['survey_version']; - if ($survey['parent_id'] == 0) + $thisref['survey_version'] = $survey['survey_version']; + if ($survey['parent_id'] == 0) { - $list[ $survey['survey_id'] ] = &$thisref; - } - else + $list[ $survey['survey_id'] ] = &$thisref; + } + else { - $refs[ $survey['parent_id'] ]['children'][ $survey['survey_id'] ] = &$thisref; - } - } + $refs[ $survey['parent_id'] ]['children'][ $survey['survey_id'] ] = &$thisref; + } + } $this->surveylist = $list; - $this->plainsurveylist = $plain_array; + $this->plainsurveylist = $plain_array; } - /* + /* function read_children($space=array(),$i=0) - { + { foreach ( $this->surveylist as $key=>$node) { if (is_array($node['children'])) - { + { if (($node['parent_id']==0)) - { - //echo '1
'; + { + //echo '1
'; } else { - $space[]='2>'; + $space[]='2>'; } - - //if have children + + //if have children for ($j=0;$j'; } //echo $node['name']; echo '3
'; - read_children($node['children'],$space,$i); + read_children($node['children'],$space,$i); } else - { - + { + for ($j=0;$j'; - } + } echo $node['name']; echo '5
'; - + } - } + } } */ /* @@ -1872,19 +1872,19 @@ class SurveyTree { { echo $node['name']; echo '
'; //$node['children']=array(); - return $node['children']; + return $node['children']; } else - { + { if (is_array($node['children'])) - { + { return SurveyTree::get_children($node['children'],$id); } else { //return SurveyTree::get_children($node, $id); } - } + } */ /** @@ -1894,52 +1894,52 @@ class SurveyTree { * @param id the id of the survey * @return array the children of a given survey id * - * @author Julio Montoya , Dokeos + * @author Julio Montoya , Dokeos * @version September 2008 */ - public function get_children ($list,$id) { + public function get_children ($list,$id) { $result=array(); foreach ($list as $key=>$node) { if ($key==$id) { - $result = $node['children']; - break; - } + $result = $node['children']; + break; + } if (is_array($node['children'])) - { - //echo $key; echo '--
'; + { + //echo $key; echo '--
'; $re=self::get_children($node['children'],$id); if (!empty($re)) { $result=$re; - } + } } else - { - //echo $key; echo '-
'; - } + { + //echo $key; echo '-
'; + } } return $result; } - + /** * This function gets the parent id of a survey * * @param int survey id * @return int survey parent id * - * @author Julio Montoya , Dokeos + * @author Julio Montoya , Dokeos * @version September 2008 */ - public function getParentId ($id) { + public function getParentId ($id) { $node = $this->plainsurveylist[$id]; if (is_array($node)&& !empty($node['parent_id'])) return $node['parent_id']; else - return -1; + return -1; } - + /** * This function gets all the siblings of a given survey id * @@ -1947,91 +1947,91 @@ class SurveyTree { * @param id the id of the survey * @return array the children of a given survey id * - * @author Julio Montoya , Dokeos + * @author Julio Montoya , Dokeos * @version September 2008 */ public function nextSibling($id) { $result=array(); - $parent_id = self::getParentId($id); + $parent_id = self::getParentId($id); $siblings = self::get_children($this->surveylist ,$parent_id); - //print_r($siblings); - if (count($siblings) > 1) - { - // $key> $id means that the siblings are order 1 2 3 and we suppose that you can't change that order + //print_r($siblings); + if (count($siblings) > 1) + { + // $key> $id means that the siblings are order 1 2 3 and we suppose that you can't change that order foreach ($siblings as $key=>$bro) { if ($key> $id && $key != $id) { $result[$key]=($bro); - } - } + } + } } - return $result; + return $result; } - + /** - * + * * This function shows the last sibling from a given list of surveys * @param id of the survey - * @author Julio Montoya , Dokeos + * @author Julio Montoya , Dokeos * @version September 2008 - * + * */ - public function lastSibling($id) { + public function lastSibling($id) { $result=array(); - $parent_id = self::getParentId($id); + $parent_id = self::getParentId($id); $siblings = self::get_children($this->surveylist ,$parent_id); - //print_r($siblings); - if (count($siblings) > 1) - { + //print_r($siblings); + if (count($siblings) > 1) + { // $key> $id means that the siblings are order 1 2 3 and we suppose that you can't change that order - $i=0; + $i=0; foreach ($siblings as $key=>$bro) { if ($key> $id && $key != $id&& $i==count($siblings)-1) { $result[$key]=($bro); - } - $i++; - } + } + $i++; + } } - return $result; + return $result; } - - + + /** - * - * This function shows the last children of a branch + * + * This function shows the last children of a branch * @param list of nodes * @return array of the lastest node - * @author Julio Montoya , Dokeos + * @author Julio Montoya , Dokeos * @version September 2008 - * + * */ - public function get_last_children_from_branch($list) { - $result=array(); + public function get_last_children_from_branch($list) { + $result=array(); foreach ($list as $key=>$node) - { + { //echo 'frist
'; echo $key; //print_r($node); if ($node['parent_id']!=0) - { - $list_bros = self::lastSibling($key); - //echo ' list_bro
'; + { + $list_bros = self::lastSibling($key); + //echo ' list_bro
'; //print_r($list_bros); - if (is_array($list_bros) && !empty($list_bros)) + if (is_array($list_bros) && !empty($list_bros)) { foreach ($list_bros as $bro) - { - //echo '0'; + { + //echo '0'; if (is_array($bro['children'])) { - //print_r($bro['children']); + //print_r($bro['children']); return $result[]=self::get_last_children_from_branch($bro['children']); } else - { - //echo 'esl'; + { + //echo 'esl'; $result=$bro; //print_r($bro); return $result; @@ -2049,12 +2049,12 @@ class SurveyTree { { return $result[]=self::get_last_children_from_branch($node['children']); } - else - { - //return $result[]=SurveyTree::get_last_children_from_branch($node['children']); - return $result[]=$node; + else + { + //return $result[]=SurveyTree::get_last_children_from_branch($node['children']); + return $result[]=$node; } - + } } else @@ -2064,85 +2064,85 @@ class SurveyTree { { $result[]=self::get_last_children_from_branch($node['children']); } - else + else { - $result[]=$node; + $result[]=$node; } - } + } } return $result; } /* * - * - * This function show the last children of list + * + * This function show the last children of list * @param id - * @param array + * @param array * @return array of the lastest node - * @author Julio Montoya , Dokeos + * @author Julio Montoya , Dokeos * @version September 2008 - * + * + - function get_last_children($id,$last) - { + { foreach ( $this->_list as $key=>$node) { if (($node['parent_id']==$id)) { - $last=$node['name']; echo '
'; + $last=$node['name']; echo '
'; } else { if (is_array($node['children'])) { - return $last = get_last_children($node['children'],$id); - } - } + return $last = get_last_children($node['children'],$id); + } + } } return $last; } */ /** - * This function creates a list of all surveys id + * This function creates a list of all surveys id * @param list of nodes - * @return array with the structure survey_id => survey_name - * @author Julio Montoya , Dokeos + * @return array with the structure survey_id => survey_name + * @author Julio Montoya , Dokeos * @version September 2008 - * + * */ public function createList ($list) { - $result=array(); + $result=array(); foreach ($list as $key=>$node) - { + { if (is_array($node['children'])) - { + { //echo $key; echo '--
'; //print_r($node); //echo '
'; - $result[$key]= $node['name']; + $result[$key]= $node['name']; $re=self::createList($node['children']); if (!empty($re)) - { + { if (is_array($re)) foreach ($re as $key=>$r) - { + { $result[$key]=''.$r; } - else + else { $result[]=$re; } - - } + + } } else - { + { //echo $key; echo '-
'; - $result[$key]=$node['name']; - } - } + $result[$key]=$node['name']; + } + } return $result; - } + } } ?> diff --git a/main/inc/lib/system_announcements.lib.php b/main/inc/lib/system_announcements.lib.php index b94d02e3e2..afa9456997 100644 --- a/main/inc/lib/system_announcements.lib.php +++ b/main/inc/lib/system_announcements.lib.php @@ -262,7 +262,7 @@ class SystemAnnouncementManager if (!checkdate($date_start[1], $date_start[2], $date_start[0])) { Display :: display_normal_message(get_lang('InvalidStartDate')); return false; - } + } if (($date_end[1] || $date_end[2] || $date_end[0]) && !checkdate($date_end[1], $date_end[2], $date_end[0])) { Display :: display_normal_message(get_lang('InvalidEndDate')); return false; @@ -278,9 +278,9 @@ class SystemAnnouncementManager $lang = is_null($lang) ? 'NULL' : "'".Database::escape_string($lang)."'"; $sql = "INSERT INTO ".$db_table." (title,content,date_start,date_end,visible_teacher,visible_student,visible_guest, lang) VALUES ('".$title."','".$content."','".$start."','".$end."','".$visible_teacher."','".$visible_student."','".$visible_guest."',".$lang.")"; - if ($send_mail==1) { - SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student); - } + if ($send_mail==1) { + SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student); + } return api_sql_query($sql,__FILE__,__LINE__); } /** @@ -324,9 +324,9 @@ class SystemAnnouncementManager $id = intval($id); $sql = "UPDATE ".$db_table." SET lang=$lang,title='".$title."',content='".$content."',date_start='".$start."',date_end='".$end."', "; $sql .= " visible_teacher = '".$visible_teacher."', visible_student = '".$visible_student."', visible_guest = '".$visible_guest."' WHERE id='".$id."'"; - + if ($send_mail==1) { - SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student); + SystemAnnouncementManager::send_system_announcement_by_email($title, $content,$visible_teacher, $visible_student); } return api_sql_query($sql,__FILE__,__LINE__); } @@ -369,12 +369,12 @@ class SystemAnnouncementManager $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' WHERE id='".$announcement_id."'"; return api_sql_query($sql,__FILE__,__LINE__); } - + function send_system_announcement_by_email($title,$content,$teacher, $student) { - global $_user; + global $_user; global $_setting; - global $charset; + global $charset; $user_table = Database :: get_main_table(TABLE_MAIN_USER); if ($teacher<>0 AND $student == '0') { $sql = "SELECT * FROM $user_table WHERE email<>'' AND status = '1'"; @@ -388,7 +388,7 @@ class SystemAnnouncementManager if ($teacher == '0' AND $student == '0') { return true; } - + $result = api_sql_query($sql,__FILE__,__LINE__); while($row = Database::fetch_array($result,'ASSOC')) { diff --git a/main/inc/lib/tablesort.lib.php b/main/inc/lib/tablesort.lib.php index 542ea9174f..35aff339fd 100644 --- a/main/inc/lib/tablesort.lib.php +++ b/main/inc/lib/tablesort.lib.php @@ -1,33 +1,33 @@ $row) { if(strlen(strip_tags($row[$column])) != 0 ) { $check_date = strtotime(strip_tags($row[$column])); - // strtotime Returns a timestamp on success, FALSE otherwise. - // Previous to PHP 5.1.0, this function would return -1 on failure. + // strtotime Returns a timestamp on success, FALSE otherwise. + // Previous to PHP 5.1.0, this function would return -1 on failure. $is_date &= ($check_date != -1 && $check_date != false); } else { - $is_date &= false; + $is_date &= false; } } return $is_date; @@ -165,39 +165,39 @@ class TableSort } return $is_image; } - - + + /** * Sort 2-dimensional table. It is possile of change the columns that will be show and the way that the columns are sorted. * @param array $data The data to be sorted. * @param int $column The column on which the data should be sorted (default = 0) * @param string $direction The direction to sort (SORT_ASC (default) orSORT_DESC) - * @param array $column_show The columns that we will show in the table i.e: $column_show=array('1','0','1') we will show the 1st and the 3th column. + * @param array $column_show The columns that we will show in the table i.e: $column_show=array('1','0','1') we will show the 1st and the 3th column. * @param array $column_order Changes how the columns will be sorted ie. $column_order=array('1','4','3','4') The 2nd column will be sorted like the 4 column - * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC,SORT_STRING,SORT_DATE,SORT_IMAGE) * + * @param constant $type How should data be sorted (SORT_REGULAR, SORT_NUMERIC,SORT_STRING,SORT_DATE,SORT_IMAGE) * * @return array The sorted dataset * @author bart.mollet@hogent.be */ - + function sort_table_config($data, $column = 0, $direction = SORT_ASC, $column_show=null, $column_order=null,$type = SORT_REGULAR) { if(!is_array($data) or count($data)==0){return array();} if($column != strval(intval($column))){return $data;} //probably an attack if(!in_array($direction,array(SORT_ASC,SORT_DESC))){return $data;} // probably an attack - $compare_function = ''; - // Change columns sort + $compare_function = ''; + // Change columns sort // Here we say that the real way of how the columns are going to be order is manage by the $column_order array - if(is_array($column_order)) + if(is_array($column_order)) { for($i=0;$i diff --git a/main/inc/lib/text.lib.php b/main/inc/lib/text.lib.php index 121f68aa7a..eea32b92f5 100644 --- a/main/inc/lib/text.lib.php +++ b/main/inc/lib/text.lib.php @@ -100,7 +100,7 @@ function format_locale_date($date_format, $time_stamp = -1, $language = null) /** * @desc this function does some parsing on the text that gets inputted. This parsing can be of any kind * LaTeX notation, Word Censoring, Glossary Terminology (extension will available soon), Musical Notations, ... -* The inspiration for this filter function came from Moodle an phpBB who both use a similar approach +* The inspiration for this filter function came from Moodle an phpBB who both use a similar approach * @param $input string. some text * @return $output string. some text that contains the parsed elements. * @example [tex]\sqrt(2)[/tex] @@ -111,48 +111,48 @@ function text_filter($input, $filter=true) { //$input=stripslashes($input); - + if ($filter==true) { // *** parse [tex]...[/tex] tags *** // // which will return techexplorer or image html depending on the capabilities of the // browser of the user (using some javascript that checks if the browser has the TechExplorer plugin installed or not) $input=_text_parse_tex($input); - - + + // *** parse [teximage]...[/teximage] tags *** // // these force the gif rendering of LaTeX using the mimetex gif renderer //$input=_text_parse_tex_image($input); - - + + // *** parse [texexplorer]...[/texexplorer] tags *** // // these force the texeplorer LaTeX notation $input=_text_parse_texexplorer($input); - + // *** Censor Words *** // // censor words. This function removes certain words by [censored] - // this can be usefull when the campus is open to the world. + // this can be usefull when the campus is open to the world. // $input=text_censor_words($input); - + // *** parse [?]...[/?] tags *** // // for the glossary tool (see http://www.dokeos.com/extensions) $input=_text_parse_glossary($input); - + // parse [wiki]...[/wiki] tags - // this is for the coolwiki plugin. - // $input=text_parse_wiki($input); - + // this is for the coolwiki plugin. + // $input=text_parse_wiki($input); + // parse [tool]...[/tool] tags // this parse function adds a link to a certain tool // $input=text_parse_tool($input); - + // parse [user]...[/user] tags - + // parse [email]...[/email] tags - + // parse [code]...[/code] tags } - + return $input; } @@ -170,10 +170,10 @@ function _text_parse_tex($textext) { //$textext = str_replace(array ("[tex]", "[/tex]"), array ('[*****]', '[/*****]'), $textext); //$textext=stripslashes($texttext); - + $input_array=preg_split("/(\[tex]|\[\/tex])/",$textext,-1, PREG_SPLIT_DELIM_CAPTURE); - - + + foreach ($input_array as $key=>$value) { if ($key>0 && $input_array[$key-1]=='[tex]' AND $input_array[$key+1]=='[/tex]') @@ -184,7 +184,7 @@ function _text_parse_tex($textext) //echo 'LaTeX:
'; } } - + $output=implode('',$input_array); return $output; } @@ -229,7 +229,7 @@ function _text_parse_tool($input) // an array with all the valid tools $tools[]=array(TOOL_ANNOUNCEMENT, 'announcements/announcements.php'); $tools[]=array(TOOL_CALENDAR_EVENT, 'calendar/agenda.php'); - + // check if the name between the [tool] [/tool] tags is a valid one } @@ -242,41 +242,41 @@ function _text_parse_tool($input) */ function latex_gif_renderer($latex_code) { - global $_course; - + global $_course; + // setting the paths and filenames $mimetex_path=api_get_path(LIBRARY_PATH).'mimetex/'; $temp_path=api_get_path(SYS_COURSE_PATH).$_course['path'].'/temp/'; $latex_filename=md5($latex_code).'.gif'; - + if(!file_exists($temp_path.$latex_filename) OR isset($_GET['render'])) { if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) { $mimetex_command=$mimetex_path.'mimetex.exe -e "'.$temp_path.md5($latex_code).'.gif" '.escapeshellarg($latex_code).''; } - else + else { $mimetex_command=$mimetex_path.'mimetex.linux -e "'.$temp_path.md5($latex_code).'.gif" '.escapeshellarg($latex_code); } - exec($mimetex_command); - //echo 'volgende shell commando werd uitgevoerd:
'.$mimetex_command.'

'; + exec($mimetex_command); + //echo 'volgende shell commando werd uitgevoerd:
'.$mimetex_command.'

'; } - + $return = ""; $return .= ''.$latex_code.''; - return $return; + return $return; } /** - * Returns the difference between the current date (date(now)) with the parameter $date in a string format like "2 days, 1 hour" - * Example: $date="2008-03-07 15:44:08"; - * date_to_str($date) it will return 3 days, 20 hours - * + * Returns the difference between the current date (date(now)) with the parameter $date in a string format like "2 days, 1 hour" + * Example: $date="2008-03-07 15:44:08"; + * date_to_str($date) it will return 3 days, 20 hours + * * @param string The string has to be the result of a date function in this format -> date("Y-m-d H:i:s",time()); - * @return string The difference between the current date and the parameter in a literal way "3 days, 2 hour" * - * @author Julio Montoya + * @return string The difference between the current date and the parameter in a literal way "3 days, 2 hour" * + * @author Julio Montoya */ function date_to_str_ago($date) @@ -298,7 +298,7 @@ function date_to_str_ago($date) $min_day=get_lang('MinDay'); $min_hour=get_lang('MinHour'); $min_minute=get_lang('MinMinute'); - + $min_decades=get_lang('MinDecades'); $min_years=get_lang('MinYears'); $min_months=get_lang('MinMonths'); @@ -306,11 +306,11 @@ function date_to_str_ago($date) $min_days=get_lang('MinDays'); $min_hours=get_lang('MinHours'); $min_minutes=get_lang('MinMinutes'); - + // original 1 //$sec_time=array("century"=>3.1556926*pow(10,9),"decade"=>315569260,"year"=>31556926,"month"=>2629743.83,"week"=>604800,"day"=>86400,"hour"=>3600,"minute"=>60,"second"=>1); //$sec_time=array(get_lang('MinDecade')=>315569260,get_lang('MinYear')=>31556926,get_lang('MinMonth')=>2629743.83,get_lang('MinWeek')=>604800,get_lang('MinDay')=>86400,get_lang('MinHour')=>3600,get_lang('MinMinute')=>60); - $sec_time_time=array(315569260,31556926,2629743.83,604800,86400,3600,60); + $sec_time_time=array(315569260,31556926,2629743.83,604800,86400,3600,60); $sec_time_sing=array($min_decade,$min_year,$min_month,$min_week,$min_day,$min_hour,$min_minute); $sec_time_plu =array($min_decades,$min_years,$min_months,$min_weeks,$min_days,$min_hours,$min_minutes); $initialized = true; @@ -335,68 +335,68 @@ function date_to_str_ago($date) $act_day=date('d'); $act_mth=date('n'); $act_yr = date('Y'); - + if ($dst_day==$act_day && $dst_mth==$act_mth && $dst_yr == $act_yr ) { return $today; } if ($dst_day==$act_day-1 && $dst_mth==$act_mth && $dst_yr == $act_yr ) { return $yesterday; - } - - $str_result=array(); + } + + $str_result=array(); $time_result=array(); $key_result=array(); - + $str=''; - $i=0; + $i=0; for ($i=0;$i $time) { continue; - } + } $current_value=intval($time/$seconds); - - if ($current_value != 1) { + + if ($current_value != 1) { $date_str= $sec_time_plu[$i]; } else { $date_str= $sec_time_sing[$i]; - - } + + } $key_result[]=$sec_time_sing[$i]; - - $str_result[]=$current_value.' '.$date_str; - $time_result[]= $current_value; - $str.=$current_value.$date_str; - $time%=$seconds; + + $str_result[]=$current_value.' '.$date_str; + $time_result[]= $current_value; + $str.=$current_value.$date_str; + $time%=$seconds; } - + if ($key_result[0]== $min_day && $key_result[1]== $min_minute) { $key_result[1]=' 0 '.$min_hours; $str_result[0]=$time_result[0].' '.$key_result[0]; - $str_result[1]=$key_result[1]; + $str_result[1]=$key_result[1]; } - + if ($key_result[0]== $min_year && ($key_result[1]== $min_day || $key_result[1]== $min_week)) { $key_result[1]=' 0 '.$min_months; $str_result[0]=$time_result[0].' '.$key_result[0]; - $str_result[1]=$key_result[1]; + $str_result[1]=$key_result[1]; } - + if (!empty($str_result[1])) { $str=$str_result[0].', '.$str_result[1]; } else { $str=$str_result[0]; - } - return $str; + } + return $str; } /** - * This functions cuts a paragraph + * This functions cuts a paragraph * i.e cut('Merry Xmas from Lima',13) = "Merry Xmas fr..." - * @param string the text to "cut" + * @param string the text to "cut" * @param int count of chars * @param bool Whether to embed in a ... - * @return string + * @return string * */ function cut($text,$maxchar,$embed=false) { @@ -407,17 +407,17 @@ function cut($text,$maxchar,$embed=false) return api_substr($text, 0, $maxchar).'...' ; } else { return $text; - } + } } /** * Show a number as only integers if no decimals, but will show 2 decimals if exist. - * - * @param mixed number to convert + * + * @param mixed number to convert * @param int decimal points 0=never, 1=if needed, 2=always * @return mixed an integer or a float depends on the parameter */ -function float_format($number, $flag = 1) -{ +function float_format($number, $flag = 1) +{ if (is_numeric($number)) { // a number if (!$number) { // zero $result = ($flag == 2 ? '0.00' : '0'); // output zero diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 3ac50e9433..ebe35b4236 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -21,7 +21,7 @@ Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium Mail: info@dokeos.com - + ============================================================================== */ /** @@ -30,7 +30,7 @@ * Include/require it in your code to use its functionality. * * @package dokeos.library -* @author Julio Montoya (Score average fixes) +* @author Julio Montoya (Score average fixes) ============================================================================== */ @@ -45,13 +45,13 @@ class Tracking { $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . ' + $sql = 'SELECT login_date, logout_date FROM ' . $tbl_track_login . ' WHERE login_user_id = ' . intval($user_id); $rs = api_sql_query($sql,__FILE__,__LINE__); $nb_seconds = 0; - + $wrong_logout_dates = false; while ($a_connections = Database::fetch_array($rs)) { @@ -61,7 +61,7 @@ class Tracking { $i_timestamp_login_date = strtotime($s_login_date); $i_timestamp_logout_date = strtotime($s_logout_date); - + if($i_timestamp_logout_date>0) { $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date); @@ -72,7 +72,7 @@ class Tracking { } } - + if($nb_seconds>0 || !$wrong_logout_dates) { return $nb_seconds; @@ -96,7 +96,7 @@ class Tracking { $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' + $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' WHERE user_id = ' . $user_id . ' AND course_code="' . $course_code . '"'; @@ -118,18 +118,18 @@ class Tracking { return $nb_seconds; } - + function get_first_connection_date($student_id) { $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $sql = 'SELECT login_date FROM ' . $tbl_track_login . ' - WHERE login_user_id = ' . intval($student_id) . ' + $sql = 'SELECT login_date FROM ' . $tbl_track_login . ' + WHERE login_user_id = ' . intval($student_id) . ' ORDER BY login_date ASC LIMIT 0,1'; $rs = api_sql_query($sql,__FILE__,__LINE__); 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)); + return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($first_login_date)); } } return false; @@ -137,37 +137,37 @@ class Tracking { function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false) { $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $sql = 'SELECT login_date FROM ' . $tbl_track_login . ' - WHERE login_user_id = ' . intval($student_id) . ' + $sql = 'SELECT login_date FROM ' . $tbl_track_login . ' + WHERE login_user_id = ' . intval($student_id) . ' ORDER BY login_date DESC LIMIT 0,1'; $rs = api_sql_query($sql,__FILE__,__LINE__); if(Database::num_rows($rs)>0) { - if ($last_login_date = Database::result($rs, 0, 0)) + if ($last_login_date = Database::result($rs, 0, 0)) { if ($return_timestamp) { return strtotime($last_login_date); } else - { - if (!$warning_message) + { + if (!$warning_message) { return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)); - } - else + } + else { $timestamp = strtotime($last_login_date); $currentTimestamp = mktime(); - + //If the last connection is > than 7 days, the text is red - //345600 = 7 days in seconds - if ($currentTimestamp - $timestamp > 604800) + //345600 = 7 days in seconds + if ($currentTimestamp - $timestamp > 604800) { return '' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . ''; - } - else + } + else { return format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)); } @@ -177,11 +177,11 @@ class Tracking { } return false; } - + function get_first_connection_date_on_the_course($student_id, $course_code) { $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . ' - WHERE user_id = ' . intval($student_id) . ' + $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . ' + WHERE user_id = ' . intval($student_id) . ' AND course_code = "' . Database::escape_string($course_code) . '" ORDER BY login_course_date ASC LIMIT 0,1'; @@ -197,8 +197,8 @@ class Tracking { function get_last_connection_date_on_the_course($student_id, $course_code) { $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . ' - WHERE user_id = ' . intval($student_id) . ' + $sql = 'SELECT login_course_date FROM ' . $tbl_track_login . ' + WHERE user_id = ' . intval($student_id) . ' AND course_code = "' . Database::escape_string($course_code) . '" ORDER BY login_course_date DESC LIMIT 0,1'; @@ -209,7 +209,7 @@ class Tracking { $timestamp = strtotime($last_login_date); $currentTimestamp = mktime(); //If the last connection is > than 7 days, the text is red - //345600 = 7 days in seconds + //345600 = 7 days in seconds if ($currentTimestamp - $timestamp > 604800) { return '' . format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_login_date)) . (api_is_allowed_to_edit()?' ':'').''; } else { @@ -242,7 +242,7 @@ class Tracking { } /** - * This function gets the score average from all tests in a course by student + * This function gets the score average from all tests in a course by student * @param int $student_id - User id * @param string $course_code - Course id * @return string value (number %) Which represents a round integer about the score average. @@ -253,59 +253,59 @@ class Tracking { $student_id = Database::escape_string($student_id); $course_code = Database::escape_string($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - + if(!empty($a_course['db_name'])) - { + { // table definition $tbl_course_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$a_course['db_name']); - $tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - + $tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + //get the list of exercises - $sql = "SELECT id, title FROM $tbl_course_quiz WHERE active <> -1"; + $sql = "SELECT id, title FROM $tbl_course_quiz WHERE active <> -1"; $rs = api_sql_query($sql, __FILE__, __LINE__); $count_exe = Database::num_rows($rs); - + if ($count_exe > 0) { $quiz_avg_total_score = 0; while($quiz = Database::fetch_array($rs)) { - // get the score and max score from track_e_exercise + // get the score and max score from track_e_exercise $sql = 'SELECT exe_result , exe_weighting FROM '.$tbl_stats_exercise.' WHERE exe_exo_id = '.(int)$quiz['id'].' - AND exe_user_id = '.(int)$student_id.' + AND exe_user_id = '.(int)$student_id.' AND orig_lp_id = 0 - AND exe_cours_id = "'.Database::escape_string($course_code).'" - AND orig_lp_item_id = 0 + AND exe_cours_id = "'.Database::escape_string($course_code).'" + AND orig_lp_item_id = 0 ORDER BY exe_date DESC'; - + $rsAttempt = api_sql_query($sql, __FILE__, __LINE__); $nb_attempts = 0; - + $quiz_avg_score = 0; - while ($attempt = Database::fetch_array($rsAttempt)) { - $nb_attempts++; + while ($attempt = Database::fetch_array($rsAttempt)) { + $nb_attempts++; $exe_weight=$attempt['exe_weighting']; - if ($exe_weight >0) { + if ($exe_weight >0) { $quiz_avg_score += round(($attempt['exe_result']/$exe_weight*100),2); - } - } + } + } if($nb_attempts>0) { $quiz_avg_score = $quiz_avg_score / $nb_attempts; - } - - $quiz_avg_total_score += $quiz_avg_score; - } - return $quiz_avg_total_score/$count_exe; - } + } + + $quiz_avg_total_score += $quiz_avg_score; + } + return $quiz_avg_total_score/$count_exe; + } } else { return null; } - + } @@ -316,29 +316,29 @@ class Tracking { $student_id = intval($student_id); $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); if(!empty($a_course['db_name'])) - { + { // table definition $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']); $tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $a_course['db_name']); $tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $a_course['db_name']); $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']); - + //get the list of learning paths $sql = 'SELECT id FROM ' . $tbl_course_lp; $rs = api_sql_query($sql, __FILE__, __LINE__); $nb_lp = Database::num_rows($rs); $avg_progress = 0; - + if ($nb_lp > 0) { while ($lp = Database :: fetch_array($rs)) { - // get the progress in learning pathes + // get the progress in learning pathes $sqlProgress = "SELECT progress FROM " . $tbl_course_lp_view . " AS lp_view - WHERE lp_view.user_id = " . $student_id . " + WHERE lp_view.user_id = " . $student_id . " AND lp_view.lp_id = " . $lp['id'] . " "; $resultItem = api_sql_query($sqlProgress, __FILE__, __LINE__); @@ -349,7 +349,7 @@ class Tracking { } $avg_progress = round($avg_progress / $nb_lp, 1); } - + return $avg_progress; } else @@ -359,37 +359,37 @@ class Tracking { } /** * This function gets: - * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max score. + * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max score. * 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max score. * 3. And finally it will return the average between 1. and 2. * This function does not take the results of a Test out of a LP - * + * * @param User id * @param Course id * @param Array limit average to listed lp ids * @return string value (number %) Which represents a round integer explain in got in 3. */ - function get_avg_student_score($student_id, $course_code, $lp_ids=array()) { + function get_avg_student_score($student_id, $course_code, $lp_ids=array()) { $course_table = Database :: get_main_table(TABLE_MAIN_COURSE); $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); - + $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); - $course = CourseManager :: get_course_information($course_code); + $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $course = CourseManager :: get_course_information($course_code); if (!empty($course['db_name'])) { - - $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']); + + $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']); $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']); $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']); $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']); $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']); - + $sql_course_lp = 'SELECT id FROM '.$lp_table; if(count($lp_ids)!=0) { $sql_course_lp.=' WHERE id IN ('.implode(',',$lp_ids).')'; } - + $sql_result_lp = api_sql_query($sql_course_lp, __FILE__, __LINE__); $lp_scorm_score_total = 0; $lp_scorm_weighting_total = 0; @@ -397,37 +397,37 @@ class Tracking { $lp_scorm_loop=0; $lp_count = 0; $progress = 0; - + if(Database::num_rows($sql_result_lp)>0){ - //Scorm test + //Scorm test while($a_learnpath = Database::fetch_array($sql_result_lp)) { - - //We get the last view id of this LP (with the higher id) - $sql='SELECT max(id) as id FROM '.$lp_view_table.' - WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; + + //We get the last view id of this LP (with the higher id) + $sql='SELECT max(id) as id FROM '.$lp_view_table.' + WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__); $lp_view_id = Database::result($rs_last_lp_view_id,0,'id'); // THE view - + if ($lp_view_id != '') { - // we get the progress - $sql='SELECT progress FROM '.$lp_view_table.' WHERE id="'.$lp_view_id.'"'; + // we get the progress + $sql='SELECT progress FROM '.$lp_view_table.' WHERE id="'.$lp_view_id.'"'; $rs = api_sql_query($sql, __FILE__, __LINE__); $progress = Database::result($rs,0,'progress'); - - // item's list of an scorm - $sql_max_score='SELECT lp_iv.score as score,lp_i.max_score + + // item's list of an scorm + $sql_max_score='SELECT lp_iv.score as score,lp_i.max_score FROM '.$lp_item_view_table.' as lp_iv INNER JOIN '.$lp_item_table.' as lp_i ON lp_i.id = lp_iv.lp_item_id AND lp_i.item_type="sco" WHERE lp_view_id="'.$lp_view_id.'"'; - - //$rs = api_sql_query($sql, __FILE__, __LINE__); + + //$rs = api_sql_query($sql, __FILE__, __LINE__); //$sql_max_score='SELECT max_score FROM '.$lp_item_view_table.' WHERE lp_view_id="'.$lp_view_id.'" '; - $res_max_score=Database::query($sql_max_score,__FILE__,__LINE__); + $res_max_score=Database::query($sql_max_score,__FILE__,__LINE__); $count_total_loop=0; - $num_rows_max_score=Database::num_rows($res_max_score); - + $num_rows_max_score=Database::num_rows($res_max_score); + if ($num_rows_max_score==1) { while ($row_max_score=Database::fetch_array($res_max_score)) { echo $row_max_score['score'].' - '.$row_max_score['max_score']; @@ -435,81 +435,81 @@ class Tracking { //when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100. $lp_scorm_result_score_total+=($row_max_score['score']/100); $current_value = $row_max_score['score']/100; - - } else { + + } else { $lp_scorm_result_score_total+=($row_max_score['score']/$row_max_score['max_score']); $current_value = $row_max_score['score']/$row_max_score['max_score']; - } - $count_total_loop++; - } + } + $count_total_loop++; + } } elseif ($num_rows_max_score > 1) { //echo ' ----
'; while ($row_max_score=Database::fetch_array($res_max_score)) { //echo $row_max_score['score'].' - '.$row_max_score['max_score']; - //echo '
'; + //echo '
'; if ($row_max_score['max_score']==0) { - $lp_scorm_result_score_total+=($row_max_score['score']/100); + $lp_scorm_result_score_total+=($row_max_score['score']/100); $current_value = $row_max_score['score']/100; } else { - //when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100. - $lp_scorm_result_score_total+=($row_max_score['score']/$row_max_score['max_score']); + //when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100. + $lp_scorm_result_score_total+=($row_max_score['score']/$row_max_score['max_score']); $current_value = $row_max_score['score']/$row_max_score['max_score']; } $count_total_loop++; - } - } - + } + } + if ($num_rows_max_score > 0 && ($progress > 0 || $current_value > 0 )) { - $lp_count++; + $lp_count++; } - + if ($count_total_loop==0) { $count_total_loop=1; } - $score_of_scorm_calculate=round((($lp_scorm_result_score_total/$count_total_loop)*100),2); - + $score_of_scorm_calculate=round((($lp_scorm_result_score_total/$count_total_loop)*100),2); + } else { - $score_of_scorm_calculate = 0; - } + $score_of_scorm_calculate = 0; + } } - - //The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row. + + //The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row. mysql_data_seek($sql_result_lp,0); - + if ($lp_count==0) { $lp_count=1; - } - - if(count($lp_ids)==0 ) { + } + + if(count($lp_ids)==0 ) { $score_of_scorm_calculate=round((($score_of_scorm_calculate/$lp_count)),2); } - - $lp_scorm_score_total = $score_of_scorm_calculate; - + + $lp_scorm_score_total = $score_of_scorm_calculate; + //Quizz in a LP while($a_learnpath = Database::fetch_array($sql_result_lp)) { - //we got the maxscore this is wrong + //we got the maxscore this is wrong /* - echo $sql = 'SELECT id as item_id, max_score + echo $sql = 'SELECT id as item_id, max_score FROM '.$lp_item_table.' AS lp_item WHERE lp_id='.$a_learnpath['id'].' AND item_type="quiz"'; */ - + //Path is the exercise id - $sql = 'SELECT path, id as item_id, max_score + $sql = 'SELECT path, id as item_id, max_score FROM '.$lp_item_table.' AS lp_item WHERE lp_id='.$a_learnpath['id'].' - AND item_type="quiz"'; - + AND item_type="quiz"'; + $rsItems = api_sql_query($sql, __FILE__, __LINE__); - + //We get the last view id of this LP $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($student_id)."' and lp_id='".intval($a_learnpath['id'])."'"; - //$sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; + //$sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; $rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__); $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id')); - + $total_score = $total_weighting = 0; if ($lp_view_id!=0) { while ($item = Database :: fetch_array($rsItems, 'ASSOC')) { @@ -518,67 +518,67 @@ class Tracking { $sql = "SELECT score FROM $lp_item_view_table WHERE lp_item_id = '".(int)$item['item_id']."' and lp_view_id = '".(int)$lp_view_id."' ORDER BY view_count DESC limit 1"; - /*$sql = 'SELECT score as student_score + /*$sql = 'SELECT score as student_score FROM '.$lp_item_view_table.' as lp_view_item WHERE lp_view_item.lp_item_id = '.$item['item_id'].' - AND lp_view_id = "'.$lp_view_id.'" ';*/ + AND lp_view_id = "'.$lp_view_id.'" ';*/ $rsScores = api_sql_query($sql, __FILE__, __LINE__); - - // Real max score - this was implemented because of the random exercises + + // Real max score - this was implemented because of the random exercises $sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' . 'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$a_learnpath['id'].'" AND orig_lp_item_id = "'.$item['item_id'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1'; - + $resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__); - $num = Database :: num_rows($resultLastAttempt); - if ($num > 0){ + $num = Database :: num_rows($resultLastAttempt); + if ($num > 0){ if ($num > 1){ while ($rowLA = Database :: fetch_row($resultLastAttempt)) { - $id_last_attempt = $rowLA[0]; + $id_last_attempt = $rowLA[0]; } } else { - $id_last_attempt = Database :: result($resultLastAttempt, 0, 0); + $id_last_attempt = Database :: result($resultLastAttempt, 0, 0); } } - + $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " . "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t"; - + $result = api_sql_query($sql, __FILE__, __LINE__); - $row_max_score = Database :: fetch_array($result); - $maxscore = $row_max_score['maxscore']; + $row_max_score = Database :: fetch_array($result); + $maxscore = $row_max_score['maxscore']; if ($maxscore=='') { $maxscore = $item['max_score']; } - // not right! + // not right! /*if(Database::num_rows($rsScores)>0) { $total_score += Database::result($rsScores, 0, 0); //echo $total_weighting += $item['max_score']; $total_weighting += $maxscore; - + if($total_weighting>0) { - //echo ($total_score/$total_weighting)*100; - $lp_scorm_score_total += ($total_score/$total_weighting)*100; + //echo ($total_score/$total_weighting)*100; + $lp_scorm_score_total += ($total_score/$total_weighting)*100; $lp_scorm_weighting_total+=100; } }*/ - + if(Database::num_rows($rsScores)>0) { $total_score = Database::result($rsScores, 0, 0); //echo $total_weighting += $item['max_score']; - $total_weighting += $maxscore; + $total_weighting += $maxscore; if($total_weighting>0 && $maxscore>0) { //echo $total_score.' - '.$maxscore; echo '
'; - //echo $lp_scorm_score_total += ($total_score/$total_weighting)*100; - $lp_scorm_score_total += ($total_score/$maxscore)*100; + //echo $lp_scorm_score_total += ($total_score/$total_weighting)*100; + $lp_scorm_score_total += ($total_score/$maxscore)*100; $lp_scorm_weighting_total+=100; } - } + } } - } + } } } - - $totalScore = $lp_scorm_score_total; + + $totalScore = $lp_scorm_score_total; $pourcentageScore = 0; if($lp_scorm_weighting_total>0) { //i.e 10.52 @@ -613,27 +613,27 @@ class Tracking { // At first, courses where $coach_id is coach of the course // ////////////////////////////////////////////////////////////// $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id; - - global $_configuration; - if ($_configuration['multiple_access_urls']==true) { - $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + + global $_configuration; + if ($_configuration['multiple_access_urls']==true) { + $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1){ - $sql = 'SELECT id_session, course_code + if ($access_url_id != -1){ + $sql = 'SELECT id_session, course_code FROM ' . $tbl_session_course . ' session_course INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url - ON (session_course.id_session=session_rel_url.session_id) - WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id; + ON (session_course.id_session=session_rel_url.session_id) + WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id; } } - + $result = api_sql_query($sql,__FILE__,__LINE__); while ($a_courses = Database::fetch_array($result)) { $course_code = $a_courses["course_code"]; $id_session = $a_courses["id_session"]; - $sql = "SELECT distinct srcru.id_user - FROM $tbl_session_course_user AS srcru + $sql = "SELECT distinct srcru.id_user + FROM $tbl_session_course_user AS srcru WHERE course_code='$course_code' AND id_session='$id_session'"; $rs = api_sql_query($sql,__FILE__,__LINE__); @@ -647,7 +647,7 @@ class Tracking { // Then, courses where $coach_id is coach of the session // ////////////////////////////////////////////////////////////// - $sql = 'SELECT session_course_user.id_user + $sql = 'SELECT session_course_user.id_user FROM ' . $tbl_session_course_user . ' as session_course_user INNER JOIN ' . $tbl_session_course . ' as session_course ON session_course.course_code = session_course_user.course_code @@ -655,23 +655,23 @@ class Tracking { INNER JOIN ' . $tbl_session . ' as session ON session.id = session_course.id_session AND session.id_coach = ' . $coach_id; - if ($_configuration['multiple_access_urls']==true) { - $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + if ($_configuration['multiple_access_urls']==true) { + $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1){ - $sql = 'SELECT session_course_user.id_user + if ($access_url_id != -1){ + $sql = 'SELECT session_course_user.id_user FROM ' . $tbl_session_course_user . ' as session_course_user INNER JOIN ' . $tbl_session_course . ' as session_course ON session_course.course_code = session_course_user.course_code AND session_course_user.id_session = session_course.id_session INNER JOIN ' . $tbl_session . ' as session ON session.id = session_course.id_session - AND session.id_coach = ' . $coach_id.' + AND session.id_coach = ' . $coach_id.' INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url - ON session.id = session_rel_url.session_id WHERE access_url_id = '.$access_url_id; + ON session.id = session_rel_url.session_id WHERE access_url_id = '.$access_url_id; } } - + $result = api_sql_query($sql,__FILE__,__LINE__); while ($row = Database::fetch_array($result)) { @@ -700,8 +700,8 @@ class Tracking { while ($a_courses = Database::fetch_array($result)) { $course_code = $a_courses["course_code"]; - $sql = "SELECT distinct srcru.id_user - FROM $tbl_session_course_user AS srcru + $sql = "SELECT distinct srcru.id_user + FROM $tbl_session_course_user AS srcru WHERE course_code='$course_code' and id_session = '" . $id_session . "'"; $rs = api_sql_query($sql, __FILE__, __LINE__); @@ -739,11 +739,11 @@ class Tracking { ////////////////////////////////////////////////////////////// // At first, courses where $coach_id is coach of the course // ////////////////////////////////////////////////////////////// - $sql = 'SELECT 1 + $sql = 'SELECT 1 FROM ' . $tbl_session_course_user . ' AS session_course_user INNER JOIN ' . $tbl_session_course . ' AS session_course ON session_course.course_code = session_course_user.course_code - AND id_coach=' . $coach_id . ' + AND id_coach=' . $coach_id . ' WHERE id_user=' . $student_id; $result = api_sql_query($sql, __FILE__, __LINE__); if (Database::num_rows($result) > 0) { @@ -754,7 +754,7 @@ class Tracking { // Then, courses where $coach_id is coach of the session // ////////////////////////////////////////////////////////////// - $sql = 'SELECT session_course_user.id_user + $sql = 'SELECT session_course_user.id_user FROM ' . $tbl_session_course_user . ' as session_course_user INNER JOIN ' . $tbl_session_course . ' as session_course ON session_course.course_code = session_course_user.course_code @@ -771,7 +771,7 @@ class Tracking { } - function get_courses_followed_by_coach($coach_id, $id_session = '') + function get_courses_followed_by_coach($coach_id, $id_session = '') { $coach_id = intval($coach_id); @@ -787,18 +787,18 @@ class Tracking { // At first, courses where $coach_id is coach of the course // ////////////////////////////////////////////////////////////// $sql = 'SELECT DISTINCT course_code FROM ' . $tbl_session_course . ' WHERE id_coach=' . $coach_id; - - global $_configuration; - if ($_configuration['multiple_access_urls']==true) { - $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + + global $_configuration; + if ($_configuration['multiple_access_urls']==true) { + $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1){ $sql = 'SELECT DISTINCT session_course.course_code FROM ' . $tbl_session_course . ' session_course INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url ON (session_course.course_code = course_rel_url.course_code) - WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id; + WHERE id_coach=' . $coach_id.' AND access_url_id = '.$access_url_id; } } - + if (!empty ($id_session)) $sql .= ' AND id_session=' . $id_session; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -808,7 +808,7 @@ class Tracking { ////////////////////////////////////////////////////////////// // Then, courses where $coach_id is coach of the session // - ////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////// $sql = 'SELECT DISTINCT session_course.course_code FROM ' . $tbl_session_course . ' as session_course INNER JOIN ' . $tbl_session . ' as session @@ -816,9 +816,9 @@ class Tracking { AND session.id_coach = ' . $coach_id . ' INNER JOIN ' . $tbl_course . ' as course ON course.code = session_course.course_code'; - - if ($_configuration['multiple_access_urls']==true) { - $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + + if ($_configuration['multiple_access_urls']==true) { + $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1){ $sql = 'SELECT DISTINCT session_course.course_code @@ -828,11 +828,11 @@ class Tracking { AND session.id_coach = ' . $coach_id . ' INNER JOIN ' . $tbl_course . ' as course ON course.code = session_course.course_code - INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url + INNER JOIN '.$tbl_course_rel_access_url.' course_rel_url ON (session_course.course_code = course_rel_url.course_code)'; } } - + if (!empty ($id_session)) { $sql .= ' WHERE session_course.id_session=' . $id_session; if ($_configuration['multiple_access_urls']==true) @@ -841,7 +841,7 @@ class Tracking { if ($_configuration['multiple_access_urls']==true) $sql .= ' WHERE access_url_id = '.$access_url_id; } - + $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = Database::fetch_array($result)) { @@ -861,12 +861,12 @@ class Tracking { // session where we are general coach $sql = 'SELECT DISTINCT id, name, date_start, date_end - FROM ' . $tbl_session . ' + FROM ' . $tbl_session . ' WHERE id_coach=' . $coach_id; - - global $_configuration; - if ($_configuration['multiple_access_urls']==true) { - $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + + global $_configuration; + if ($_configuration['multiple_access_urls']==true) { + $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1){ $sql = 'SELECT DISTINCT id, name, date_start, date_end @@ -877,8 +877,8 @@ class Tracking { } $rs = api_sql_query($sql,__FILE__,__LINE__); - - while ($row = Database::fetch_array($rs)) + + while ($row = Database::fetch_array($rs)) { $a_sessions[$row["id"]] = $row; } @@ -889,34 +889,34 @@ class Tracking { INNER JOIN ' . $tbl_session_course . ' as session_course ON session.id = session_course.id_session AND session_course.id_coach=' . $coach_id; - - global $_configuration; - if ($_configuration['multiple_access_urls']==true) { - $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + + global $_configuration; + if ($_configuration['multiple_access_urls']==true) { + $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1){ $sql = 'SELECT DISTINCT session.id, session.name, session.date_start, session.date_end FROM ' . $tbl_session . ' as session - INNER JOIN ' . $tbl_session_course . ' as session_course - ON session.id = session_course.id_session AND session_course.id_coach=' . $coach_id.' - INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url - ON (session.id = session_rel_url.session_id) + INNER JOIN ' . $tbl_session_course . ' as session_course + ON session.id = session_course.id_session AND session_course.id_coach=' . $coach_id.' + INNER JOIN '.$tbl_session_rel_access_url.' session_rel_url + ON (session.id = session_rel_url.session_id) WHERE access_url_id = '.$access_url_id; } } - + $rs = api_sql_query($sql,__FILE__,__LINE__); - while ($row = Database::fetch_array($rs)) + while ($row = Database::fetch_array($rs)) { $a_sessions[$row["id"]] = $row; } - - if (is_array($a_sessions)) { + + if (is_array($a_sessions)) { foreach ($a_sessions as & $session) { if ($session['date_start'] == '0000-00-00') { $session['status'] = get_lang('SessionActive'); - } + } else { $date_start = explode('-', $session['date_start']); $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]); @@ -928,7 +928,7 @@ class Tracking { else{ if (time() < $time_start) { $session['status'] = get_lang('SessionFuture'); - } + } else{ if (time() > $time_end) { $session['status'] = get_lang('SessionPast'); @@ -951,7 +951,7 @@ class Tracking { $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); - $sql = 'SELECT DISTINCT course_code, id_coach + $sql = 'SELECT DISTINCT course_code, id_coach FROM ' . $tbl_session_course . ' WHERE id_session=' . $session_id; @@ -970,7 +970,7 @@ class Tracking { $student_id = intval($student_id); $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); if(!empty($a_course['db_name'])) @@ -978,10 +978,10 @@ class Tracking { // table definition $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']); $sql = 'SELECT 1 - FROM ' . $tbl_item_property . ' + FROM ' . $tbl_item_property . ' WHERE insert_user_id=' . $student_id . ' AND tool="work"'; - + $rs = api_sql_query($sql, __LINE__, __FILE__); return Database::num_rows($rs); } @@ -998,7 +998,7 @@ class Tracking { $student_id = intval($student_id); $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); if(!empty($a_course['db_name'])) @@ -1006,9 +1006,9 @@ class Tracking { // table definition $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']); $sql = 'SELECT 1 - FROM ' . $tbl_messages . ' + FROM ' . $tbl_messages . ' WHERE poster_id=' . $student_id; - + $rs = api_sql_query($sql, __LINE__, __FILE__); return Database::num_rows($rs); } @@ -1017,27 +1017,27 @@ class Tracking { return null; } } - + /** * This function counts the number of post by course -* @param string $course_code - Course ID +* @param string $course_code - Course ID * @return int the number of post by course -* @author Christian Fasanando , +* @author Christian Fasanando , * @version enero 2009, dokeos 1.8.6 */ - function count_number_of_posts_by_course($course_code) { + function count_number_of_posts_by_course($course_code) { //protect data $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - $count = 0; + $count = 0; if (!empty($a_course['db_name'])) { $tbl_posts = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']); $sql = "SELECT count(*) FROM $tbl_posts"; $result = api_sql_query($sql, __FILE__, __LINE__); $row = Database::fetch_row($result); - $count = $row[0]; - return $count; + $count = $row[0]; + return $count; } else { return null; } @@ -1045,24 +1045,24 @@ class Tracking { /** * This function counts the number of threads by course -* @param string $course_code - Course ID +* @param string $course_code - Course ID * @return int the number of threads by course -* @author Christian Fasanando , +* @author Christian Fasanando , * @version enero 2009, dokeos 1.8.6 */ - function count_number_of_threads_by_course($course_code) { + function count_number_of_threads_by_course($course_code) { //protect data $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - $count = 0; + $count = 0; if (!empty($a_course['db_name'])) { $tbl_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $a_course['db_name']); $sql = "SELECT count(*) FROM $tbl_threads"; $result = api_sql_query($sql, __FILE__, __LINE__); $row = Database::fetch_row($result); - $count = $row[0]; - return $count; + $count = $row[0]; + return $count; } else { return null; } @@ -1070,96 +1070,96 @@ class Tracking { /** * This function counts the number of forums by course -* @param string $course_code - Course ID +* @param string $course_code - Course ID * @return int the number of forums by course -* @author Christian Fasanando , +* @author Christian Fasanando , * @version enero 2009, dokeos 1.8.6 */ - function count_number_of_forums_by_course($course_code) { + function count_number_of_forums_by_course($course_code) { //protect data $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - $count = 0; + $count = 0; if (!empty($a_course['db_name'])) { $tbl_forums = Database :: get_course_table(TABLE_FORUM, $a_course['db_name']); $sql = "SELECT count(*) FROM $tbl_forums"; $result = api_sql_query($sql, __FILE__, __LINE__); $row = Database::fetch_row($result); - $count = $row[0]; - return $count; + $count = $row[0]; + return $count; } else { return null; } - } + } /** * This function counts the chat last connections by course in x days * @param string $course_code - Course ID -* @param int $last_days - last x days +* @param int $last_days - last x days * @return int the chat last connections by course in x days -* @author Christian Fasanando , +* @author Christian Fasanando , * @version enero 2009, dokeos 1.8.6 */ - function chat_connections_during_last_x_days_by_course($course_code,$last_days) { + function chat_connections_during_last_x_days_by_course($course_code,$last_days) { //protect data $last_days = intval($last_days); $course_code = addslashes($course_code); - // get the informations of the course + // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - $count = 0; + $count = 0; if (!empty($a_course['db_name'])) { $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']); - - $sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date + + $sql = "SELECT count(*) FROM $tbl_stats_access WHERE DATE_SUB(NOW(),INTERVAL $last_days DAY) <= access_date AND access_cours_code = '$course_code' AND access_tool='".TOOL_CHAT."'"; $result = api_sql_query($sql, __FILE__, __LINE__); $row = Database::fetch_row($result); - $count = $row[0]; - return $count; + $count = $row[0]; + return $count; } else { return null; } - } + } + - /** * This function gets the last student's connection in chat * @param int $student_id - Student ID * @param string $course_code - Course ID -* @return string the last connection -* @author Christian Fasanando , +* @return string the last connection +* @author Christian Fasanando , * @version enero 2009, dokeos 1.8.6 -*/ +*/ function chat_last_connection($student_id,$course_code) { require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php'); - + //protect datas $student_id = intval($student_id); $course_code = addslashes($course_code); - - // get the informations of the course - $a_course = CourseManager :: get_course_information($course_code); + + // get the informations of the course + $a_course = CourseManager :: get_course_information($course_code); $date_time = ''; if (!empty($a_course['db_name'])) { // table definition $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS, $a_course['db_name']); - $sql = "SELECT access_date FROM $tbl_stats_access + $sql = "SELECT access_date FROM $tbl_stats_access WHERE access_tool='".TOOL_CHAT."' AND access_user_id='$student_id' AND access_cours_code = '$course_code' ORDER BY access_date DESC limit 1"; - + $rs = api_sql_query($sql, __LINE__, __FILE__); - $row = Database::fetch_array($rs); + $row = Database::fetch_array($rs); $last_connection = $row['access_date']; - if (!empty($last_connection)) { - $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection)); - $time = explode(' ',$last_connection); - $date_time = $date_format_long.' '.$time[1]; + if (!empty($last_connection)) { + $date_format_long = format_locale_date(get_lang('DateFormatLongWithoutDay'), strtotime($last_connection)); + $time = explode(' ',$last_connection); + $date_time = $date_format_long.' '.$time[1]; } - - return $date_time; + + return $date_time; } else { return null; - } + } } function count_student_visited_links($student_id, $course_code) { @@ -1171,7 +1171,7 @@ class Tracking { $tbl_stats_links = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS); $sql = 'SELECT 1 - FROM ' . $tbl_stats_links . ' + FROM ' . $tbl_stats_links . ' WHERE links_user_id=' . $student_id . ' AND links_cours_id="' . $course_code . '"'; @@ -1188,7 +1188,7 @@ class Tracking { $tbl_stats_documents = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS); $sql = 'SELECT 1 - FROM ' . $tbl_stats_documents . ' + FROM ' . $tbl_stats_documents . ' WHERE down_user_id=' . $student_id . ' AND down_cours_id="' . $course_code . '"'; @@ -1208,15 +1208,15 @@ class Tracking { } return $a_courses; } - - function get_inactives_students_in_course($course_code, $since, $session_id=0) + + function get_inactives_students_in_course($course_code, $since, $session_id=0) { $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $inner = ''; if($session_id!=0) { - $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user + $inner = ' INNER JOIN '.$tbl_session_course_user.' session_course_user ON stats_login.course_code = session_course_user.course_code AND session_course_user.id_session = '.intval($session_id).' AND session_course_user.id_user = stats_login.user_id '; @@ -1234,42 +1234,42 @@ class Tracking { } return $inactive_users; } - - function count_login_per_student($student_id, $course_code) { - $student_id = intval($student_id); - $course_code = addslashes($course_code); - $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS); - - $sql = 'SELECT '.$student_id.' - FROM ' . $tbl_course_rel_user . ' - WHERE access_user_id=' . $student_id . ' - AND access_cours_code="' . $course_code . '"'; - - $rs = api_sql_query($sql, __FILE__, __LINE__); - $nb_login = Database::num_rows($rs); - - return $nb_login; + + function count_login_per_student($student_id, $course_code) { + $student_id = intval($student_id); + $course_code = addslashes($course_code); + $tbl_course_rel_user = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS); + + $sql = 'SELECT '.$student_id.' + FROM ' . $tbl_course_rel_user . ' + WHERE access_user_id=' . $student_id . ' + AND access_cours_code="' . $course_code . '"'; + + $rs = api_sql_query($sql, __FILE__, __LINE__); + $nb_login = Database::num_rows($rs); + + return $nb_login; } - - + + function get_student_followed_by_drh($hr_dept_id) { - + $hr_dept_id = intval($hr_dept_id); $a_students = array (); - + $tbl_organism = Database :: get_main_table(TABLE_MAIN_ORGANISM); $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); - + $sql = 'SELECT DISTINCT user_id FROM '.$tbl_user.' as user WHERE hr_dept_id='.$hr_dept_id; $rs = api_sql_query($sql, __FILE__, __LINE__); - + while($user = Database :: fetch_array($rs)) { $a_students[$user['user_id']] = $user['user_id']; } - - + + return $a_students; } /** @@ -1293,11 +1293,11 @@ class Tracking { while ($row_type=Database::fetch_array($rs_type)) { if ($row_type['lp_type']==1) {//lp dokeos - + $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'"; $rs_last_lp_view_id = Database::query($sql, __FILE__, __LINE__); $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id')); - + $sql_list_view='SELECT li.max_score,lv.user_id,liw.score,(liw.score/li.max_score) as sum_data FROM '.$lp_item_table.' li INNER JOIN '.$lp_view_table.' lv ON li.lp_id=lv.lp_id INNER JOIN '.$lp_item_view_table.' liw ON liw.lp_item_id=li.id WHERE lv.user_id="'.$user_id.'" AND li.item_type="quiz" AND liw.lp_view_id="'.$lp_view_id.'"'; $sum=0; @@ -1314,11 +1314,11 @@ class Tracking { $sql_list_view=''; $rs_last_lp_view_id=''; - + } elseif ($row_type['lp_type']==2) {//lp scorm $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'"; $rs_last_lp_view_id = Database::query($sql, __FILE__, __LINE__); - $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id')); + $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id')); $sql_list_view='SELECT li.max_score,lv.user_id,liw.score,((liw.score/li.max_score)*100) as sum_data FROM '.$lp_item_table.' li INNER JOIN '.$lp_view_table.' lv ON li.lp_id=lv.lp_id INNER JOIN '.$lp_item_view_table.' liw ON liw.lp_item_id=li.id WHERE lv.user_id="'.$user_id.'" AND li.item_type="sco" AND liw.lp_view_id="'.$lp_view_id.'"'; @@ -1333,18 +1333,18 @@ class Tracking { if ($tot==0) { $tot=1; } - $average_data2=$sum/$tot; + $average_data2=$sum/$tot; } $average_data_sum=$average_data_sum+$average_data1+$average_data2; $average_data2=0; $average_data1=0; $count_loop++; } - + if ((int)$count_loop > 0) { $avg_student_score = round(($average_data_sum / $count_loop), 2); } - + return $avg_student_score; } } diff --git a/main/inc/lib/upload.xajax.php b/main/inc/lib/upload.xajax.php index 995685bf83..9c93b57ada 100644 --- a/main/inc/lib/upload.xajax.php +++ b/main/inc/lib/upload.xajax.php @@ -1,7 +1,7 @@ registerFunction ('updateProgress'); $xajax_upload -> processRequests(); @@ -13,14 +13,14 @@ $xajax_upload -> processRequests(); */ function updateProgress($div_id, $upload_id, $waitAfterupload = false) { - $objResponse = new XajaxResponse(); + $objResponse = new XajaxResponse(); $ul_info = uploadprogress_get_info($upload_id); $percent = intval($ul_info['bytes_uploaded']*100/$ul_info['bytes_total']); if($waitAfterupload && $ul_info['est_sec']<2) { $percent = 100; $objResponse -> addAssign($div_id.'_label' , 'innerHTML', get_lang('UploadFile').' : '.$percent.' %'); $objResponse -> addAssign($div_id.'_waiter_frame','innerHTML',''); - $objResponse -> addScript('clearInterval("myUpload.__progress_bar_interval")'); + $objResponse -> addScript('clearInterval("myUpload.__progress_bar_interval")'); } $objResponse -> addAssign($div_id.'_label' , 'innerHTML', get_lang('UploadFile').' : '.$percent.' %'); $objResponse -> addAssign($div_id.'_filled' , 'style.width', $percent.'%'); diff --git a/main/inc/lib/urlmanager.lib.php b/main/inc/lib/urlmanager.lib.php index 9848f93eaa..6c1f7b547a 100755 --- a/main/inc/lib/urlmanager.lib.php +++ b/main/inc/lib/urlmanager.lib.php @@ -31,17 +31,17 @@ class UrlManager { /** * Creates a new url access to Dokeos - * + * * @author Julio Montoya , * - * @param string The URL of the site + * @param string The URL of the site * @param string The description of the site - * @param int is active or not + * @param int is active or not * @param int the user_id of the owner * @return boolean if success */ function add($url, $description, $active) - { + { $tms = time(); $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); $sql = "INSERT INTO $table_access_url @@ -52,22 +52,22 @@ class UrlManager tms = FROM_UNIXTIME(".$tms.")"; $result = api_sql_query($sql, __FILE__, __LINE__); return $result; - } - + } + /** - * Updates an URL access to Dokeos + * Updates an URL access to Dokeos * @author Julio Montoya , * - * @param int The url id + * @param int The url id * @param string The description of the site - * @param int is active or not + * @param int is active or not * @param int the user_id of the owner - * @return boolean if success + * @return boolean if success */ function udpate($url_id, $url, $description, $active) { $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); - $tms = time(); + $tms = time(); $sql = "UPDATE $table_access_url SET url = '".Database::escape_string($url)."', description = '".Database::escape_string($description)."', @@ -78,69 +78,69 @@ class UrlManager $result = api_sql_query($sql, __FILE__, __LINE__); return $result; } - - + + /** - * Deletes an url + * Deletes an url * @author Julio Montoya * @param int url id * @return boolean true if success * */ function delete($id) { - $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); $sql= "DELETE FROM $table_access_url WHERE id = ".Database::escape_string($id); $result = api_sql_query($sql, __FILE__, __LINE__); return $result; - } - + } + /** - * + * * */ function url_exist($url) - { + { $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); - $sql = "SELECT id FROM $table_access_url WHERE url = '".Database::escape_string($url)."' "; - $res = api_sql_query($sql,__FILE__,__LINE__); - $num = Database::num_rows($res); + $sql = "SELECT id FROM $table_access_url WHERE url = '".Database::escape_string($url)."' "; + $res = api_sql_query($sql,__FILE__,__LINE__); + $num = Database::num_rows($res); return $num; } - + /** - * + * * */ - function url_id_exist($url) - { + function url_id_exist($url) + { $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); - $sql = "SELECT id FROM $table_access_url WHERE id = '".Database::escape_string($url)."' "; - $res = api_sql_query($sql,__FILE__,__LINE__); - $num = Database::num_rows($res); + $sql = "SELECT id FROM $table_access_url WHERE id = '".Database::escape_string($url)."' "; + $res = api_sql_query($sql,__FILE__,__LINE__); + $num = Database::num_rows($res); return $num; - } - + } + /** - * This function get the quantity of URLs + * This function get the quantity of URLs * @author Julio Montoya * @return int count of urls * */ - function url_count() + function url_count() { - $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); $sql = "SELECT count(id) as count_result FROM $table_access_url"; $res = api_sql_query($sql, __FILE__, __LINE__); - $url = Database::fetch_array($res,'ASSOC'); - $result = $url['count_result']; - return $result; + $url = Database::fetch_array($res,'ASSOC'); + $result = $url['count_result']; + return $result; } - + /** * Gets the id, url, description, and active status of ALL URLs * @author Julio Montoya - * @return array + * @return array * */ - function get_url_data() + function get_url_data() { - $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); $sql = "SELECT id, url, description, active FROM $table_access_url"; $res = api_sql_query($sql, __FILE__, __LINE__); $urls = array (); @@ -149,21 +149,21 @@ class UrlManager } return $urls; } - + /** * Gets the id, url, description, and active status of ALL URLs * @author Julio Montoya - * @return array + * @return array * */ - function get_url_data_from_id($url_id) + function get_url_data_from_id($url_id) { - $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); $sql = "SELECT id, url, description, active FROM $table_access_url WHERE id = ".Database::escape_string($url_id); - $res = api_sql_query($sql, __FILE__, __LINE__); - $row = Database::fetch_array($res); + $res = api_sql_query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($res); return $row; } - + /** Gets the inner join of users and urls table * @author Julio Montoya * @return int access url id @@ -172,23 +172,23 @@ class UrlManager function get_url_rel_user_data($access_url_id='') { $where = ''; - $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); if (!empty($access_url_id)) { $where ="WHERE $table_url_rel_user.access_url_id = ".Database::escape_string($access_url_id); } $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; $sql="SELECT u.user_id, lastname, firstname, username, access_url_id - FROM $tbl_user u + FROM $tbl_user u INNER JOIN $table_url_rel_user ON $table_url_rel_user.user_id = u.user_id $where".$order_clause; - $result=api_sql_query($sql,__FILE__,__LINE__); + $result=api_sql_query($sql,__FILE__,__LINE__); $users=api_store_result($result); - return $users; + return $users; } - - + + /** Gets the inner join of access_url and the course table * @author Julio Montoya * @return int access url id @@ -197,24 +197,24 @@ class UrlManager function get_url_rel_course_data($access_url_id='') { $where =''; - $table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE); - + if (!empty($access_url_id)) $where ="WHERE $table_url_rel_course.access_url_id = ".Database::escape_string($access_url_id); - + $sql="SELECT course_code, title, access_url_id - FROM $tbl_course u + FROM $tbl_course u INNER JOIN $table_url_rel_course ON $table_url_rel_course.course_code = code $where ORDER BY title, code"; - - $result=api_sql_query($sql,__FILE__,__LINE__); + + $result=api_sql_query($sql,__FILE__,__LINE__); $courses=api_store_result($result); - return $courses; - } - + return $courses; + } + /** Gets the inner join of access_url and the session table * @author Julio Montoya * @return int access url id @@ -223,49 +223,49 @@ class UrlManager function get_url_rel_session_data($access_url_id='') { $where =''; - $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); - + if (!empty($access_url_id)) $where ="WHERE $table_url_rel_session.access_url_id = ".Database::escape_string($access_url_id); - + $sql="SELECT id, name, access_url_id - FROM $tbl_session u + FROM $tbl_session u INNER JOIN $table_url_rel_session ON $table_url_rel_session.session_id = id $where ORDER BY name, id"; - - $result=api_sql_query($sql,__FILE__,__LINE__); + + $result=api_sql_query($sql,__FILE__,__LINE__); $sessions=api_store_result($result); - return $sessions; - } - - - + return $sessions; + } + + + /** - * Sets the status of an URL 1 or 0 + * Sets the status of an URL 1 or 0 * @author Julio Montoya * @param string lock || unlock * @param int url id * */ function set_url_status($status, $url_id) { - $url_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $url_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); if ($status=='lock') { - $status_db='0'; + $status_db='0'; } if ($status=='unlock') { - $status_db='1'; - } + $status_db='1'; + } if(($status_db=='1' OR $status_db=='0') AND is_numeric($url_id)) { $sql="UPDATE $url_table SET active='".Database::escape_string($status_db)."' WHERE id='".Database::escape_string($url_id)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - } + } } - + /** - * Checks the relationship between an URL and a User (return the num_rows) + * Checks the relationship between an URL and a User (return the num_rows) * @author Julio Montoya * @param int user id * @param int url id @@ -273,15 +273,15 @@ class UrlManager * */ function relation_url_user_exist($user_id, $url_id) { - $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $sql= "SELECT user_id FROM $table_url_rel_user WHERE access_url_id = ".Database::escape_string($url_id)." AND user_id = ".Database::escape_string($user_id)." "; $result = api_sql_query($sql, __FILE__, __LINE__); - $num = Database::num_rows($result); + $num = Database::num_rows($result); return $num; } - + /** - * Checks the relationship between an URL and a Course (return the num_rows) + * Checks the relationship between an URL and a Course (return the num_rows) * @author Julio Montoya * @param int user id * @param int url id @@ -289,16 +289,16 @@ class UrlManager * */ function relation_url_course_exist($course_id, $url_id) { - $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $sql= "SELECT course_code FROM $table_url_rel_course WHERE access_url_id = ".Database::escape_string($url_id)." AND course_code = '".Database::escape_string($course_id)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - $num = Database::num_rows($result); + $num = Database::num_rows($result); return $num; } - - + + /** - * Checks the relationship between an URL and a Session (return the num_rows) + * Checks the relationship between an URL and a Session (return the num_rows) * @author Julio Montoya * @param int user id * @param int url id @@ -306,14 +306,14 @@ class UrlManager * */ function relation_url_session_exist($session_id, $url_id) { - $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $sql= "SELECT session_id FROM $table_url_rel_session WHERE access_url_id = ".Database::escape_string($url_id)." AND session_id = ".Database::escape_string($session_id); $result = api_sql_query($sql, __FILE__, __LINE__); - $num = Database::num_rows($result); + $num = Database::num_rows($result); return $num; - } - - + } + + /** * Add a group of users into a group of URLs * @author Julio Montoya @@ -321,30 +321,30 @@ class UrlManager * @param array of url_ids * */ function add_users_to_urls($user_list, $url_list) - { + { $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $result_array=array(); - + if (is_array($user_list) && is_array($url_list)){ - foreach ($url_list as $url_id) { + foreach ($url_list as $url_id) { foreach ($user_list as $user_id) { - $count = UrlManager::relation_url_user_exist($user_id,$url_id); + $count = UrlManager::relation_url_user_exist($user_id,$url_id); if ($count==0) { $sql = "INSERT INTO $table_url_rel_user SET user_id = ".Database::escape_string($user_id).", access_url_id = ".Database::escape_string($url_id); $result = api_sql_query($sql, __FILE__, __LINE__); - if($result) + if($result) $result_array[$url_id][$user_id]=1; else $result_array[$url_id][$user_id]=0; - } + } } } } return $result_array; } - - + + /** * Add a group of courses into a group of URLs * @author Julio Montoya @@ -352,30 +352,30 @@ class UrlManager * @param array of url_ids * */ function add_courses_to_urls($course_list,$url_list) - { + { $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $result_array=array(); - + if (is_array($course_list) && is_array($url_list)){ - foreach ($url_list as $url_id) { - foreach ($course_list as $course_code) { - $count = UrlManager::relation_url_course_exist($course_code,$url_id); + foreach ($url_list as $url_id) { + foreach ($course_list as $course_code) { + $count = UrlManager::relation_url_course_exist($course_code,$url_id); if ($count==0) { $sql = "INSERT INTO $table_url_rel_course SET course_code = '".Database::escape_string($course_code)."', access_url_id = ".Database::escape_string($url_id); $result = api_sql_query($sql, __FILE__, __LINE__); - if($result) + if($result) $result_array[$url_id][$course_code]=1; else $result_array[$url_id][$course_code]=0; - } + } } } } return $result_array; } - - + + /** * Add a group of sessions into a group of URLs * @author Julio Montoya @@ -383,31 +383,31 @@ class UrlManager * @param array of url_ids * */ function add_sessions_to_urls($session_list,$url_list) - { + { $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $result_array=array(); - + if (is_array($session_list) && is_array($url_list)){ - foreach ($url_list as $url_id) { - foreach ($session_list as $session_id) { - $count = UrlManager::relation_url_session_exist($session_id,$url_id); + foreach ($url_list as $url_id) { + foreach ($session_list as $session_id) { + $count = UrlManager::relation_url_session_exist($session_id,$url_id); if ($count==0) { $sql = "INSERT INTO $table_url_rel_session SET session_id = ".Database::escape_string($session_id).", access_url_id = ".Database::escape_string($url_id); $result = api_sql_query($sql, __FILE__, __LINE__); - if($result) + if($result) $result_array[$url_id][$session_id]=1; else $result_array[$url_id][$session_id]=0; - } + } } } } return $result_array; } - - - + + + /** * Add a user into a url * @author Julio Montoya @@ -416,46 +416,46 @@ class UrlManager * @return boolean true if success * */ function add_user_to_url($user_id, $url_id=1) - { + { $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - if (empty($url_id)) $url_id=1; + if (empty($url_id)) $url_id=1; $count = UrlManager::relation_url_user_exist($user_id,$url_id); - if (empty($count)) { + if (empty($count)) { $sql = "INSERT INTO $table_url_rel_user SET user_id = ".Database::escape_string($user_id).", access_url_id = ".Database::escape_string($url_id); $result = api_sql_query($sql, __FILE__, __LINE__); } - return $result; + return $result; } - + function add_course_to_url($course_code, $url_id=1) - { + { $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); - if (empty($url_id)) $url_id=1; + if (empty($url_id)) $url_id=1; $count = UrlManager::relation_url_course_exist($course_code,$url_id); - if (empty($count)) { + if (empty($count)) { $sql = "INSERT INTO $table_url_rel_course SET course_code = '".Database::escape_string($course_code)."', access_url_id = ".Database::escape_string($url_id); $result = api_sql_query($sql, __FILE__, __LINE__); } - return $result; + return $result; } - - + + function add_session_to_url($session_id, $url_id=1) - { + { $table_url_rel_session= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - if (empty($url_id)) $url_id=1; + if (empty($url_id)) $url_id=1; $count = UrlManager::relation_url_session_exist($session_id,$url_id); - if (empty($count)) { + if (empty($count)) { $sql = "INSERT INTO $table_url_rel_session SET session_id = ".Database::escape_string($session_id).", access_url_id = ".Database::escape_string($url_id); $result = api_sql_query($sql, __FILE__, __LINE__); } - return $result; + return $result; } - - + + /** * Deletes an url and user relationship * @author Julio Montoya @@ -465,12 +465,12 @@ class UrlManager * */ function delete_url_rel_user($user_id, $url_id) { - $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $table_url_rel_user= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); $sql= "DELETE FROM $table_url_rel_user WHERE user_id = ".Database::escape_string($user_id)." AND access_url_id=".Database::escape_string($url_id)." "; $result = api_sql_query($sql, __FILE__, __LINE__); return $result; - } - + } + /** * Deletes an url and course relationship * @author Julio Montoya @@ -480,12 +480,12 @@ class UrlManager * */ function delete_url_rel_course($course_code, $url_id) { - $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $table_url_rel_course= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $sql= "DELETE FROM $table_url_rel_course WHERE course_code = '".Database::escape_string($course_code)."' AND access_url_id=".Database::escape_string($url_id)." "; $result = api_sql_query($sql, __FILE__, __LINE__); return $result; } - + /** * Deletes an url and session relationship * @author Julio Montoya @@ -495,137 +495,137 @@ class UrlManager * */ function delete_url_rel_session($session_id, $url_id) { - $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $sql= "DELETE FROM $table_url_rel_session WHERE session_id = ".Database::escape_string($session_id)." AND access_url_id=".Database::escape_string($url_id)." "; $result = api_sql_query($sql, __FILE__, __LINE__); return $result; } - - + + /** * Updates the access_url_rel_user table with a given user list * @author Julio Montoya * @param array user list - * @param int access_url_id + * @param int access_url_id * */ function update_urls_rel_user($user_list,$access_url_id) { $table_access_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); - $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - + $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $sql = "SELECT user_id FROM $table_url_rel_user WHERE access_url_id=".Database::escape_string($access_url_id); $result = api_sql_query($sql,__FILE__,__LINE__ ); $existingUsers = array(); - + while($row = Database::fetch_array($result)){ $existingUsers[] = $row['user_id']; - } - + } + //adding users foreach($user_list as $enreg_user) { if(!in_array($enreg_user, $existingUsers)) { - UrlManager::add_user_to_url($enreg_user,$access_url_id); + UrlManager::add_user_to_url($enreg_user,$access_url_id); } } - //deleting old users + //deleting old users foreach($existingUsers as $existing_user) { if(!in_array($existing_user, $user_list)) { - UrlManager::delete_url_rel_user($existing_user,$access_url_id); + UrlManager::delete_url_rel_user($existing_user,$access_url_id); } - } + } } - - + + /** * Updates the access_url_rel_course table with a given user list * @author Julio Montoya * @param array user list - * @param int access_url_id + * @param int access_url_id * */ function update_urls_rel_course($course_list,$access_url_id) { $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); - $table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); - + $table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); + $sql = "SELECT course_code FROM $table_url_rel_course WHERE access_url_id=".Database::escape_string($access_url_id); $result = api_sql_query($sql,__FILE__,__LINE__ ); - $existing_courses = array(); - + $existing_courses = array(); + while($row = Database::fetch_array($result)){ $existing_courses[] = $row['course_code']; - } - + } + //adding courses foreach($course_list as $course) { if(!in_array($course, $existing_courses)) { - UrlManager::add_course_to_url($course,$access_url_id); + UrlManager::add_course_to_url($course,$access_url_id); } } - - //deleting old courses + + //deleting old courses foreach($existing_courses as $existing_course) { if(!in_array($existing_course, $course_list)) { - UrlManager::delete_url_rel_course($existing_course,$access_url_id); + UrlManager::delete_url_rel_course($existing_course,$access_url_id); } - } + } } - + /** * Updates the access_url_rel_session table with a given user list * @author Julio Montoya * @param array user list - * @param int access_url_id + * @param int access_url_id * */ function update_urls_rel_session($session_list,$access_url_id) { $table_session = Database :: get_main_table(TABLE_MAIN_SESSION); - $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); - + $table_url_rel_session = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); + $sql = "SELECT session_id FROM $table_url_rel_session WHERE access_url_id=".Database::escape_string($access_url_id); $result = api_sql_query($sql,__FILE__,__LINE__ ); - $existing_sessions = array(); - + $existing_sessions = array(); + while($row = Database::fetch_array($result)){ $existing_sessions[] = $row['session_id']; - } - + } + //adding users foreach($session_list as $session) { if(!in_array($session, $existing_sessions)) { - UrlManager::add_session_to_url($session,$access_url_id); + UrlManager::add_session_to_url($session,$access_url_id); } } - - //deleting old users + + //deleting old users foreach($existing_sessions as $existing_session) { if(!in_array($existing_session, $session_list)) { - UrlManager::delete_url_rel_session($existing_session,$access_url_id); + UrlManager::delete_url_rel_session($existing_session,$access_url_id); } - } + } } - - + + function get_access_url_from_user($user_id) { $table_url_rel_user = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); - $table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); - $sql = "SELECT url, access_url_id FROM $table_url_rel_user url_rel_user INNER JOIN $table_url u + $table_url = Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + $sql = "SELECT url, access_url_id FROM $table_url_rel_user url_rel_user INNER JOIN $table_url u ON (url_rel_user.access_url_id = u.id) WHERE user_id = ".Database::escape_string($user_id); - $result = api_sql_query($sql, __FILE__, __LINE__); - $url_list = api_store_result($result); - return $url_list; - } - + $result = api_sql_query($sql, __FILE__, __LINE__); + $url_list = api_store_result($result); + return $url_list; + } + /** - * + * * */ function get_url_id($url) - { - $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); + { + $table_access_url= Database :: get_main_table(TABLE_MAIN_ACCESS_URL); $sql = "SELECT id FROM $table_access_url WHERE url = '".Database::escape_string($url)."'"; - $result = api_sql_query($sql); + $result = api_sql_query($sql); $access_url_id = Database::result($result, 0, 0); return $access_url_id; - } + } } ?> \ No newline at end of file diff --git a/main/inc/lib/xht.lib.php b/main/inc/lib/xht.lib.php index 115919c2e6..ba8a8d4d62 100644 --- a/main/inc/lib/xht.lib.php +++ b/main/inc/lib/xht.lib.php @@ -7,34 +7,34 @@ */ /** -============================================================================== +============================================================================== * This is an XML HTML template library. * Include/require it in your code to use its functionality. * * This library defines function xht_htmlwchars & class xhtdoc with methods: * - xht_fill_template($template_name) * - xht_substitute($subtext) -* +* * Check htt_error after defining a new xhtdoc(htt_file_contents). -* -* Assign xht_xmldoc (, xht_get_lang, xht_resource, xht_dbgn) +* +* Assign xht_xmldoc (, xht_get_lang, xht_resource, xht_dbgn) * before calling the class methods. * * @package dokeos.library -============================================================================== +============================================================================== */ function xht_htmlwchars($s) // use only where ISO-8859-1 is not required! { - //return ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>', - // str_replace('@§@', '&', - // htmlspecialchars(ereg_replace('&#([0-9]+);', '@§@#\\1;', $s)))); + //return ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>', + // str_replace('@�@', '&', + // htmlspecialchars(ereg_replace('&#([0-9]+);', '@�@#\\1;', $s)))); global $charset; return api_ereg_replace('\[((/?(b|big|i|small|sub|sup|u))|br/)\]', '<\\1>', - str_replace('@§@', '&', - htmlspecialchars(api_ereg_replace('&#([0-9]+);', '@§@#\\1;', $s), ENT_QUOTES, $charset))); + str_replace('@�@', '&', + htmlspecialchars(api_ereg_replace('&#([0-9]+);', '@�@#\\1;', $s), ENT_QUOTES, $charset))); // replaces htmlspecialchars for double-escaped xml chars like '&#nnn;' // and when html tags <...> are represented as [...] } @@ -47,12 +47,12 @@ function xht_is_assoclist($s) // ":key1:value1,, key2:value2,, ..." function xht_explode_assoclist($s) { $result = array(); if (!xht_is_assoclist($s)) return $result; - + foreach (explode(',,', api_substr($s, 1)) as $keyplusvalue) if ($cp = api_strpos($keyplusvalue, api_substr($s, 0, 1))) - $result[trim(api_substr($keyplusvalue, 0, $cp))] = + $result[trim(api_substr($keyplusvalue, 0, $cp))] = api_substr($keyplusvalue, $cp+1); - + return $result; } @@ -79,27 +79,27 @@ function xht_fill_template($template_name, $cur_elem = 0) $template_name = trim($template_name); if (!$template_name || (api_strpos($template_name, ' ') !== FALSE)) return ''; if (!is_string($httext = $this->htt_array[$template_name])) return ''; - - if ($this->xht_dbgn) $this->xht_dbgo .= '\n"; - + $prev_lpp = 0; $prev_sub = ''; $scanpos = 0; - + while (($rpp = api_strpos($httext, XHT_RP, $scanpos)) !== FALSE) // first -} { if (($lpp = api_strpos($httext, XHT_LP)) === FALSE) break; // no {- for -} if ($lpp > $rpp) break; // no {- preceding -} - + while (($next_lpp = api_strpos($httext, XHT_LP, $lpp + XHT_PL)) !== FALSE) if ($next_lpp > $rpp) break; else $lpp = $next_lpp; // find {- closest to -} - + $subtext = api_substr($httext, $lpp + XHT_PL, $rpp - $lpp - XHT_PL); - - $httext = api_substr($httext, 0, $lpp) . - $this->xht_substitute($subtext, $cur_elem, XHT_LP, XHT_RP) . + + $httext = api_substr($httext, 0, $lpp) . + $this->xht_substitute($subtext, $cur_elem, XHT_LP, XHT_RP) . api_substr($httext, $rpp + XHT_PL); // substitute or leave intact - + if ($lpp == $prev_lpp && $subtext == $prev_sub) // prevent looping { $scanpos = $rpp + 1; $prev_lpp = 0; $prev_sub = ''; @@ -109,7 +109,7 @@ function xht_fill_template($template_name, $cur_elem = 0) $prev_lpp = $lpp; $prev_sub = $subtext; } } - + return $httext; } @@ -119,20 +119,20 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') global $charset; $regs = array(); // for use with ereg() - if (!api_ereg(XHT_SUBS2, $subtext, $regs) && !api_ereg(XHT_SUBS1, $subtext, $regs)) + if (!api_ereg(XHT_SUBS2, $subtext, $regs) && !api_ereg(XHT_SUBS1, $subtext, $regs)) return $pre . $subtext . $post; - + $type = $regs[1]; $text = $regs[2]; $result = ''; $subnum = FALSE; - $subtext = isset($regs[3]) ? $regs[3] : ''; - + $subtext = isset($regs[3]) ? $regs[3] : ''; + if ($this->xht_dbgn) // generate debugging output, with new number $subnum { - $subnum = ++ $this->xht_dbgn; - $this->xht_dbgo .= '\n"; } - + if ($type == 'D') // Define, e.g. {-D key value-} { // Assign the value to parameter [key] @@ -142,7 +142,7 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') elseif ($type == 'E') // Escape, e.g. {-E userFunction subtext-} { $result = call_user_func($text, FALSE); // get cached result, if any - + if ($result === FALSE) // no cached result available { $result = $this->xht_substitute($subtext, $cur_elem); @@ -153,7 +153,7 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') { $rdepthn = 'rdepth' . (++ $this->xht_param['rdepth']); $n = 0; $this->xht_param['number'] = '0'; - + if (is_array($a = $this->_lang($text, $cur_elem))) // repeat on array { foreach ($a as $key => $value) @@ -182,9 +182,9 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') } else // repeat on XML elements { - $sub_elems = + $sub_elems = $this->xht_xmldoc->xmd_select_elements($text, $cur_elem); - + foreach ($sub_elems as $subElem) { $this->xht_param['number'] = (string) (++ $n); @@ -194,10 +194,10 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') } // removed 2004/10/05: template_array (security) // added 2005/03/08: associative list (lang arrays deprecated) - + $this->xht_param['rdepth'] --; - // As there is only one ['number'] or one set ['key'] + ['value'], + // As there is only one ['number'] or one set ['key'] + ['value'], // using them in nested repeats may not have the desired result. } elseif ($type == 'T') // Test, e.g. {-T key1 == key2 text-} @@ -205,18 +205,18 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') if (api_ereg('^(=|==|<=|<|!=|<>|>|>=) +([^ ]+) +(.*)$', $subtext, $regs)) { // Comparand= parameter value if set, else languagevar value - - $cmp1 = isset($this->xht_param[$text]) ? + + $cmp1 = isset($this->xht_param[$text]) ? $this->xht_param[$text] : $this->_lang($text, $cur_elem); - $cmp3 = isset($this->xht_param[$cmp3 = $regs[2]]) ? + $cmp3 = isset($this->xht_param[$cmp3 = $regs[2]]) ? $this->xht_param[$cmp3] : $this->_lang($cmp3, $cur_elem); $cmp = strcmp($cmp1, $cmp3); $op = ' ' . $regs[1] . ' '; - - if ($subnum) $this->xht_dbgo .= '\n"; // debugging output - - if ( ($cmp < 0 && api_strpos(' <= < != <> ', $op)) || + + if ( ($cmp < 0 && api_strpos(' <= < != <> ', $op)) || ($cmp == 0 && api_strpos(' = == <= >= ', $op)) || ($cmp > 0 && api_strpos(' != <> > >= ', $op)) ) $result = $this->xht_substitute($regs[3], $cur_elem); @@ -231,7 +231,7 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') { if (api_strpos('CLPVX', $type) !== FALSE) // used to be always $text = $this->xht_substitute($text, $cur_elem); // nested escape - + if ($type == 'C') // Call, e.g. {-C SUBTEMPLATE-} $result = $this->xht_fill_template($text, $cur_elem); elseif ($type == 'H') $result = htmlspecialchars($text, ENT_QUOTES, $charset); @@ -245,29 +245,29 @@ function xht_substitute($subtext, $cur_elem = 0, $pre = '', $post = '') } else // $type == 'V' or 'X' { - + if (api_ereg('^(.*)=/(.+)$', $text, $regs)) // special resource-marker { $path = $regs[1]; $text = $regs[2]; if (api_substr($path, -1) == '/') $path = api_substr($path, 0, -1); - + if ($path) $cur_elem = $this->xht_xmldoc-> xmd_select_single_element($path, $cur_elem); - + $cur_elem = call_user_func($this->xht_resource, $cur_elem); } - - $result = ($type == 'V') ? - $this->xht_xmldoc->xmd_value($text, $cur_elem) : + + $result = ($type == 'V') ? + $this->xht_xmldoc->xmd_value($text, $cur_elem) : $this->xht_xmldoc-> xmd_html_value($text, $cur_elem, 'xht_htmlwchars'); } } - - if ($subnum) $this->xht_dbgo .= '\n"; - + return $result; } @@ -277,10 +277,10 @@ function xht_add_template($template_name, $httext) $this->htt_array[$template_name] = $httext; // removed 2004/10/05: (substr($httext, 0, 6) == 'array(') ? // removed 2004/10/05: @eval('return ' . $httext . ';') : $httext; - + if (!$this->htt_array[$template_name]) { - $this->htt_error = 'template ' . $template_name . + $this->htt_error = 'template ' . $template_name . ' is empty or invalid'; return; } } @@ -290,58 +290,58 @@ function xhtdoc($htt_file_contents) { $htt_file_contents = // normalize \r (Mac) and \r\n (Windows) to \n str_replace("\r", "\n", str_replace("\r\n", "\n", $htt_file_contents)); - + while (api_substr($htt_file_contents, -1) == "\n") $htt_file_contents = api_substr($htt_file_contents, 0, -1); - + $last_line = api_strrchr($htt_file_contents, "\n"); $this->htt_error = ''; - - if (api_strlen($last_line) < 12 || api_substr($last_line, 0, 6) != "\n") { $this->htt_error = 'last line must be of the form '; return; } - + define('XHT_PL', (int) (api_strlen($last_line) - 10) / 2); // Parentheses Lth define('XHT_LP', api_substr($last_line, 6, XHT_PL)); // Left Par define('XHT_RP', api_substr($last_line, 6 + XHT_PL, XHT_PL)); // Right Par - - if (XHT_LP == XHT_RP) + + if (XHT_LP == XHT_RP) { - $this->htt_error = + $this->htt_error = 'parentheses in last line must not be identical'; return; } - + $this->htt_array = array(); // named elements are arrays and strings - - foreach (explode("\n\n"))) { $template_name = trim(api_substr($name_and_text, 0, $name_length)); - - if (api_strpos($template_name, ' ') !== FALSE) give_up('Template ' . + + if (api_strpos($template_name, ' ') !== FALSE) give_up('Template ' . $template_name . ' has a space in its name'); $httext = api_substr($name_and_text, $name_length + XHT_PL + 5); - + while (api_substr($httext, 0, 1) == "\n") $httext = api_substr($httext, 1); while (api_substr($httext, -1) == "\n") $httext = api_substr($httext,0,-1); - + $this->xht_add_template($template_name, $httext); } } - + define('XHT_SUBS1', '^(C|H|L|P|U|V|W|X) +(.*)$'); // substitution types 1: // Call, Htmlchars, Lang, Param, Urlencode, Value, Wchars, Xvalue define('XHT_SUBS2', '^(D|E|R|T) +([^ ]+) +(.*)$'); // substitution types 2: // Define, Escape, Repeat, Test - + $this->xht_dbgo = ''; - - $this->xht_param = array(0 => '0', 1 => '1', + + $this->xht_param = array(0 => '0', 1 => '1', '' => '', 'empty' => '', 'rdepth' => 0); $this->_prev_param = $this->xht_param; // empty: {-R * P empty-} puts the number of subelements in {-P number-} @@ -355,14 +355,14 @@ function _show_param() // for debugging info global $charset; $result = ''; - + foreach ($this->xht_param as $k => $v) if ($v !== $this->_prev_param[$k]) { - $this->_prev_param[$k] = $v; $result .= ', ' . $k . ': ' . + $this->_prev_param[$k] = $v; $result .= ', ' . $k . ': ' . ((api_strlen($v) <= 20) ? $v : api_substr($v, 0, 17).'...'); } - + return $result ? htmlspecialchars(api_substr($result, 1), ENT_QUOTES, $charset) : ''; } @@ -392,39 +392,39 @@ function _lang($var, $cur_elem = 0) A word of explanation... -The last line of a template file (example below) defines the special markers -that are used around template names such as INPUT and OPTION and around HTML -escapes such as 'P value' and 'L Store', { and } in the example. You can also -use markers of more than one character as long as both have the same length, -e.g. <% and %>. The markers must not be equal. In templates with JavaScript +The last line of a template file (example below) defines the special markers +that are used around template names such as INPUT and OPTION and around HTML +escapes such as 'P value' and 'L Store', { and } in the example. You can also +use markers of more than one character as long as both have the same length, +e.g. <% and %>. The markers must not be equal. In templates with JavaScript or
'.get_lang('Defcon').'
'.$key.''.$array_of_results[$j][1].'
'.get_lang('AllRight').'