Juan Carlos Raña 15 vuotta sitten
vanhempi
commit
91d22bf2d7
100 muutettua tiedostoa jossa 1800 lisäystä ja 1947 poistoa
  1. 39 39
      main/admin/add_many_session_to_category.php
  2. 2 2
      main/admin/course_add.php
  3. 4 4
      main/admin/course_information.php
  4. 1 1
      main/admin/course_virtual.php
  5. 16 16
      main/admin/resume_session.php
  6. 8 8
      main/admin/session_add.php
  7. 11 11
      main/admin/session_category_edit.php
  8. 48 48
      main/admin/session_category_list.php
  9. 1 1
      main/admin/session_course_edit.php
  10. 46 46
      main/admin/session_course_user.php
  11. 10 10
      main/admin/session_edit.php
  12. 4 4
      main/admin/session_import.php
  13. 6 6
      main/admin/settings.php
  14. 65 65
      main/admin/special_exports.php
  15. 1 1
      main/admin/user_export.php
  16. 7 7
      main/admin/user_information.php
  17. 2 2
      main/announcements/announcements.inc.php
  18. 2 2
      main/calendar/agenda.inc.php
  19. 1 1
      main/chat/chat_hidden.php
  20. 2 2
      main/course_description/index.php
  21. 2 2
      main/course_home/2column.php
  22. 2 2
      main/course_home/3column.php
  23. 25 25
      main/course_home/activity.php
  24. 2 2
      main/course_home/btf_functions.php
  25. 3 3
      main/course_info/infocours.php
  26. 1 1
      main/course_info/postpone.php
  27. 58 58
      main/coursecopy/classes/CourseBuilder.class.php
  28. 2 2
      main/coursecopy/classes/CourseRecycler.class.php
  29. 96 96
      main/coursecopy/classes/CourseRestorer.class.php
  30. 1 1
      main/coursecopy/copy_course.php
  31. 135 135
      main/coursecopy/copy_course_session.php
  32. 4 4
      main/dropbox/dropbox_class.inc.php
  33. 7 7
      main/dropbox/dropbox_download.php
  34. 2 2
      main/dropbox/dropbox_submit.php
  35. 2 2
      main/exercice/answer.class.php
  36. 6 6
      main/exercice/exercice_submit.php
  37. 3 3
      main/exercice/exercise.class.php
  38. 1 1
      main/exercice/hotpotatoes.lib.php
  39. 1 1
      main/exercice/hotspot.class.php
  40. 1 1
      main/exercice/hotspot_answers.as.php
  41. 1 1
      main/exercice/hotspot_savescore.inc.php
  42. 1 1
      main/exercice/mark_free_answer.php
  43. 5 5
      main/exercice/question.class.php
  44. 12 12
      main/forum/forumfunction.inc.php
  45. 26 26
      main/glossary/index.php
  46. 1 1
      main/inc/global.inc.php
  47. 1 1
      main/inc/introductionSection.inc.php
  48. 25 25
      main/inc/lib/add_course.lib.inc.php
  49. 8 8
      main/inc/lib/blog.lib.php
  50. 16 16
      main/inc/lib/classmanager.lib.php
  51. 283 428
      main/inc/lib/course.lib.php
  52. 11 13
      main/inc/lib/database.lib.php
  53. 1 1
      main/inc/lib/events.lib.inc.php
  54. 2 2
      main/inc/lib/fileManage.lib.php
  55. 3 3
      main/inc/lib/fileUpload.lib.php
  56. 127 127
      main/inc/lib/main_api.lib.php
  57. 134 134
      main/inc/lib/sessionmanager.lib.php
  58. 2 2
      main/inc/lib/specific_fields_manager.lib.php
  59. 78 78
      main/inc/lib/surveymanager.lib.php
  60. 52 52
      main/inc/lib/usermanager.lib.php
  61. 19 19
      main/inc/local.inc.php
  62. 2 2
      main/inc/tool_navigation_menu.inc.php
  63. 8 8
      main/install/update-db-scorm-1.6.x-1.8.0.inc.php
  64. 13 13
      main/link/link.php
  65. 1 1
      main/metadata/importdocs.php
  66. 6 6
      main/metadata/importlinks.php
  67. 3 3
      main/metadata/importmanifest.php
  68. 1 1
      main/metadata/index.php
  69. 2 2
      main/metadata/md_document.php
  70. 1 1
      main/metadata/md_funcs.php
  71. 2 2
      main/metadata/md_link.php
  72. 5 5
      main/metadata/md_phpdig.php
  73. 1 1
      main/metadata/md_scorm.php
  74. 1 1
      main/metadata/search.php
  75. 1 1
      main/metadata/statistics.php
  76. 1 1
      main/metadata/update_indexabletext.php
  77. 7 7
      main/newscorm/aicc.class.php
  78. 11 11
      main/newscorm/aiccItem.class.php
  79. 5 5
      main/newscorm/document.php
  80. 20 20
      main/newscorm/learnpath.class.php
  81. 2 2
      main/newscorm/learnpathItem.class.php
  82. 5 5
      main/newscorm/learnpathList.class.php
  83. 43 43
      main/newscorm/learnpath_functions.inc.php
  84. 6 6
      main/newscorm/lp_upload.php
  85. 55 55
      main/newscorm/resourcelinker.inc.php
  86. 25 25
      main/newscorm/resourcelinker.php
  87. 3 3
      main/newscorm/scorm.class.php
  88. 1 1
      main/newscorm/scorm.lib.php
  89. 3 3
      main/newscorm/scormOrganization.class.php
  90. 5 5
      main/newscorm/scorm_admin.php
  91. 9 9
      main/notebook/index.php
  92. 1 1
      main/online/online_links.php
  93. 1 1
      main/online/online_master.php
  94. 13 13
      main/permissions/permissions_functions.inc.php
  95. 7 7
      main/permissions/roles.php
  96. 1 1
      main/reservation/m_reservation.php
  97. 2 2
      main/reservation/rsys.php
  98. 55 55
      main/resourcelinker/resourcelinker.inc.php
  99. 21 21
      main/resourcelinker/resourcelinker.php
  100. 13 13
      main/survey/survey.lib.php

+ 39 - 39
main/admin/add_many_session_to_category.php

@@ -52,7 +52,7 @@ if(isset($_GET['add_type']) && $_GET['add_type']!=''){
 
 if (!api_is_platform_admin()) {
 	$sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
-	$rs = api_sql_query($sql,__FILE__,__LINE__);
+	$rs = Database::query($sql,__FILE__,__LINE__);
 	if (Database::result($rs,0,0)!=$_user['user_id']) {
 		api_not_allowed(true);
 	}
@@ -60,29 +60,29 @@ if (!api_is_platform_admin()) {
 
 function search_courses($needle,$type) {
 	global $tbl_course, $tbl_session, $id_session;
-	
+
 	$xajax_response = new XajaxResponse();
-	$return = '';	
+	$return = '';
 	if(!empty($needle) && !empty($type)) {
 		// xajax send utf8 datas... datas in db can be non-utf8 datas
 		$charset = api_get_setting('platform_charset');
 		$needle = api_convert_encoding($needle, $charset, 'utf-8');
-								
-		$sql = 'SELECT * FROM '.$tbl_session.' WHERE name LIKE "'.$needle.'%" ORDER BY id';	
-				
-		$rs = api_sql_query($sql, __FILE__, __LINE__);		
+
+		$sql = 'SELECT * FROM '.$tbl_session.' WHERE name LIKE "'.$needle.'%" ORDER BY id';
+
+		$rs = Database::query($sql, __FILE__, __LINE__);
 		$course_list = array();
-	
+
 		$return .= '<select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:340px;">';
-		while($course = Database :: fetch_array($rs)) {	
-			$course_list[] = $course['id'];							
-			$return .= '<option value="'.$course['id'].'" title="'.htmlspecialchars($course['name'],ENT_QUOTES).'">'.$course['name'].'</option>';				
+		while($course = Database :: fetch_array($rs)) {
+			$course_list[] = $course['id'];
+			$return .= '<option value="'.$course['id'].'" title="'.htmlspecialchars($course['name'],ENT_QUOTES).'">'.$course['name'].'</option>';
 		}
 		$return .= '</select>';
 		$xajax_response -> addAssign('ajax_list_courses_multiple','innerHTML',api_utf8_encode($return));
-	}	
-	$_SESSION['course_list'] = $course_list;	
-	return $xajax_response;	
+	}
+	$_SESSION['course_list'] = $course_list;
+	return $xajax_response;
 }
 $xajax -> processRequests();
 $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
@@ -95,18 +95,18 @@ function add_course_to_session (code, content) {
 	for (i=0;i<destination.length;i++) {
 		if(destination.options[i].text == content) {
 				return false;
-		} 
+		}
 	}
 	destination.options[destination.length] = new Option(content,code);
 	destination.selectedIndex = -1;
-	sortOptions(destination.options);	
+	sortOptions(destination.options);
 }
 function send() {
 	if (document.formulaire.CategorySessionId.value!=0) {
 		//alert(document.formulaire.CategorySessionId.value);
 		document.formulaire.formSent.value=0;
 		document.formulaire.submit();
-	}	
+	}
 }
 function remove_item(origin)
 {
@@ -132,7 +132,7 @@ if ($_POST['formSent']) {
 	if($Categoryid != 0 && count($SessionCategoryList)>0 ){
 		$session_id = join(',', $SessionCategoryList);
 		$sql = "UPDATE $tbl_session SET session_category_id = $Categoryid WHERE id in ($session_id) ";
-		api_sql_query($sql,__FILE__,__LINE__);
+		Database::query($sql,__FILE__,__LINE__);
 		header('Location: session_list.php?id_category='.$Categoryid);
 	} else {
 		header('Location: add_many_session_to_category.php?msg=error');
@@ -153,17 +153,17 @@ $rows_category_session = array();
 if(isset($_POST['CategorySessionId']) && $_POST['formSent'] == 0 ){
 	$where = 'WHERE session_category_id !='.intval($_POST['CategorySessionId']);
 	$sql = 'SELECT id, name  FROM '.$tbl_session .' WHERE session_category_id ='.intval($_POST['CategorySessionId']).' ORDER BY name';
-	$result=api_sql_query($sql,__FILE__,__LINE__);	
-	$rows_category_session = api_store_result($result);
+	$result=Database::query($sql,__FILE__,__LINE__);
+	$rows_category_session = Database::store_result($result);
 }
 
 $sql = "SELECT id, name  FROM $tbl_session_category ORDER BY name";
-$result=api_sql_query($sql,__FILE__,__LINE__);	
-$rows_session_category = api_store_result($result);
+$result=Database::query($sql,__FILE__,__LINE__);
+$rows_session_category = Database::store_result($result);
 
 $sql = "SELECT id, name  FROM $tbl_session $where ORDER BY name";
-$result=api_sql_query($sql,__FILE__,__LINE__);	
-$rows_session = api_store_result($result);
+$result=Database::query($sql,__FILE__,__LINE__);
+$rows_session = Database::store_result($result);
 ?>
 <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?page=<?php echo $_GET['page']; if(!empty($_GET['add'])) echo '&add=true' ; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
 <input type="hidden" name="formSent" value="1" />
@@ -180,11 +180,11 @@ if(!empty($errorMsg))
 	<td width="" align="center"> <b><?php echo get_lang('SessionCategoryName') ?> :</b><br />
 	<select name="CategorySessionId" style="width: 320px;" onchange="javascript:send();" >
 		<option value="0" selected> </option>
-		<?php 
+		<?php
 		foreach($rows_session_category as $category) {
 			if($category['id'] == $_POST['CategorySessionId'])
   			echo '<option value="'.$category['id'].'" selected>'.$category['name'].'</option>';
-  			else 
+  			else
   			echo '<option value="'.$category['id'].'">'.$category['name'].'</option>';
 		}
   		?>
@@ -200,13 +200,13 @@ if(!empty($errorMsg))
 
 <?php if($add_type == 'multiple') { ?>
 <tr><td width="45%" align="center">
- <?php echo get_lang('FirstLetterCourse'); ?> : 
+ <?php echo get_lang('FirstLetterCourse'); ?> :
      <select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
       <option value="%">--</option>
       <?php
       echo Display :: get_alphabet_options();
       echo Display :: get_numeric_options(0,9,'');
-      ?> 
+      ?>
      </select>
 </td>
 <td>&nbsp;</td></tr>
@@ -214,8 +214,8 @@ if(!empty($errorMsg))
 <tr>
   <td width="45%" align="center">
 	<div id="ajax_list_courses_multiple">
-	<select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:320px;"> 
-	<?php 
+	<select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
+	<?php
 	foreach($rows_session as $enreg) {
 	?>
 		<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'],ENT_QUOTES).'"'; if(in_array($enreg['id'],$CourseList)) echo 'selected="selected"'; ?>><?php echo $enreg['name']; ?></option>
@@ -236,8 +236,8 @@ if(!empty($errorMsg))
   	<button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
 	<br /><br />
 	<button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
-  <?php 
-  } 
+  <?php
+  }
   ?>
 	<br /><br /><br /><br /><br /><br />
 	<?php
@@ -246,7 +246,7 @@ if(!empty($errorMsg))
   </td>
   <td width="45%" align="center">
   <select id='destination' name="SessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
-	<?php 
+	<?php
 	foreach($rows_category_session as $enreg) {
 	?>
 		<option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'],ENT_QUOTES).'"'; if(in_array($enreg['id'],$CourseList)) echo 'selected="selected"'; ?>><?php echo $enreg['name']; ?></option>
@@ -269,25 +269,25 @@ function moveItem(origin , destination){
 	}
 	destination.selectedIndex = -1;
 	sortOptions(destination.options);
-	
+
 
 }
 
 function sortOptions(options) {
 
 	newOptions = new Array();
-	
+
 	for (i = 0 ; i<options.length ; i++) {
-		newOptions[i] = options[i];							
+		newOptions[i] = options[i];
 	}
 
 	newOptions = newOptions.sort(mysort);
 	options.length = 0;
 
-	for(i = 0 ; i < newOptions.length ; i++){		
-		options[i] = newOptions[i];			
+	for(i = 0 ; i < newOptions.length ; i++){
+		options[i] = newOptions[i];
 	}
-	
+
 }
 
 function mysort(a, b){

+ 2 - 2
main/admin/course_add.php

@@ -74,7 +74,7 @@ if ($_configuration['multiple_access_urls']==true){
 $res = Database::query($sql,__FILE__,__LINE__);
 $teachers = array();
 $teachers[0] = '-- '.get_lang('NoManager').' --';
-while($obj = mysql_fetch_object($res))
+while($obj = Database::fetch_object($res))
 {
 	$teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
 }
@@ -182,7 +182,7 @@ if( $form->validate()) {
 		$pictures_array=fill_course_repository($currentCourseRepository);
 		fill_Db_course($currentCourseDbName, $currentCourseRepository, $course_language,$pictures_array);
 		register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date,$course_teachers);
-		$sql = "UPDATE $table_course SET disk_quota = '".$disk_quota."', visibility = '".mysql_real_escape_string($course['visibility'])."', subscribe = '".mysql_real_escape_string($course['subscribe'])."', unsubscribe='".mysql_real_escape_string($course['unsubscribe'])."' WHERE code = '".$currentCourseId."'";
+		$sql = "UPDATE $table_course SET disk_quota = '".$disk_quota."', visibility = '".Database::escape_string($course['visibility'])."', subscribe = '".Database::escape_string($course['subscribe'])."', unsubscribe='".Database::escape_string($course['unsubscribe'])."' WHERE code = '".$currentCourseId."'";
 		Database::query($sql,__FILE__,__LINE__);
 		header('Location: course_list.php');
 		exit ();

+ 4 - 4
main/admin/course_information.php

@@ -28,7 +28,7 @@ function get_course_usage($course_code)
     $course_code = Database::escape_string($course_code);
 	$sql = "SELECT * FROM $table WHERE code='".$course_code."'";
 	$res = Database::query($sql,__FILE__,__LINE__);
-	$course = mysql_fetch_object($res);
+	$course = Database::fetch_object($res);
 	// Learnpaths
 	$table = Database :: get_course_table(TABLE_LP_MAIN, $course->db_name);
 	$usage[] = array (get_lang(ucfirst(TOOL_LEARNPATH)), Database::count_rows($table));
@@ -66,7 +66,7 @@ $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
 $code = Database::escape_string($_GET['code']);
 $sql = "SELECT * FROM $table_course WHERE code = '".$code."'";
 $res = Database::query($sql,__FILE__,__LINE__);
-$course = mysql_fetch_object($res);
+$course = Database::fetch_object($res);
 $tool_name = $course->title.' ('.$course->visual_code.')';
 Display::display_header($tool_name);
 //api_display_tool_title($tool_name);
@@ -107,7 +107,7 @@ $is_western_name_order = api_is_western_name_order();
 if (mysql_num_rows($res) > 0)
 {
 	$users = array ();
-	while ($obj = mysql_fetch_object($res))
+	while ($obj = Database::fetch_object($res))
 	{
 		$user = array ();
 		$user[] = $obj->official_code;
@@ -160,7 +160,7 @@ $res = Database::query($sql,__FILE__,__LINE__);
 if (mysql_num_rows($res) > 0)
 {
 	$data = array ();
-	while ($class = mysql_fetch_object($res))
+	while ($class = Database::fetch_object($res))
 	{
 		$row = array ();
 		$row[] = $class->name;

+ 1 - 1
main/admin/course_virtual.php

@@ -227,7 +227,7 @@ function display_create_virtual_course_form()
 									ORDER BY tree_pos";
 			$category_result = Database::query($sql_query, __FILE__, __LINE__);
 
-			while ($current_category = mysql_fetch_array($category_result))
+			while ($current_category = Database::fetch_array($category_result))
 			{
 				echo "<option value=\"", $current_category["code"], "\"";
 				echo ">(", $current_category["code"], ") ", $current_category["name"];

+ 16 - 16
main/admin/resume_session.php

@@ -54,11 +54,11 @@ if(!api_is_platform_admin() && $session['session_admin_id']!=$_user['user_id'])
 	api_not_allowed(true);
 }
 
-$sql = 'SELECT name FROM  '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"'; 
-$rs = api_sql_query($sql, __FILE__, __LINE__);
+$sql = 'SELECT name FROM  '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
+$rs = Database::query($sql, __FILE__, __LINE__);
 $session_category = '';
 if(mysql_num_rows($rs)>0) {
-	$rows_session_category = api_store_result($rs);
+	$rows_session_category = Database::store_result($rs);
 	$rows_session_category = $rows_session_category[0];
 	$session_category = $rows_session_category['name'];
 }
@@ -213,30 +213,30 @@ else {
 	$courses=Database::store_result($result);
 	foreach($courses as $course){
 		//select the number of users
-		
-		$sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru 
+
+		$sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
 				WHERE srcru.id_user = sru.id_user AND srcru.course_code = '".Database::escape_string($course['code'])."'
-				AND srcru.id_session = '".intval($id_session)."'";  
-				 				
-		$rs = api_sql_query($sql, __FILE__, __LINE__);
+				AND srcru.id_session = '".intval($id_session)."'";
+
+		$rs = Database::query($sql, __FILE__, __LINE__);
 		$course['nbr_users'] = mysql_result($rs,0,0);
-		
+
 		// Get coachs of the courses in session
-		
-		$sql = "SELECT user.lastname,user.firstname,user.username FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user 
+
+		$sql = "SELECT user.lastname,user.firstname,user.username FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
 				WHERE session_rcru.id_user = user.user_id AND session_rcru.id_session = '".intval($id_session)."' AND session_rcru.course_code ='".Database::escape_string($course['code'])."' AND session_rcru.status=2";
 		$rs = Database::query($sql,__FILE__,__LINE__);
-		
+
 		$coachs = array();
-		if (Database::num_rows($rs) > 0) {			
+		if (Database::num_rows($rs) > 0) {
 			while($info_coach = Database::fetch_array($rs)) {
 				$coachs[] = $info_coach['lastname'].' '.$info_coach['firstname'].' ('.$info_coach['username'].')';
-			}						
+			}
 		} else {
 			$coach = get_lang('None');
 		}
-		
-					
+
+
 		if (count($coachs) > 0) {
 			$coach = implode('<br />',$coachs);
 		} else {

+ 8 - 8
main/admin/session_add.php

@@ -199,11 +199,11 @@ if (intval($count_users)<50) {
 </td>
 </tr>
 <?php
-	$id_session_category = ''; 
+	$id_session_category = '';
 	$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
 	$sql = 'SELECT id, name FROM '.$tbl_session_category.' ORDER BY name ASC';
-	$result = api_sql_query($sql,__FILE__,__LINE__);
-	$Categories = api_store_result($result);
+	$result = Database::query($sql,__FILE__,__LINE__);
+	$Categories = Database::store_result($result);
 ?>
 <tr>
   <td width="40%"><?php echo get_lang('SessionCategory') ?></td>
@@ -369,8 +369,8 @@ for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
 <tr>
   <td width="40%"><?php echo get_lang('SessionVisibility') ?></td>
   <td width="60%">
-  	<select name="session_visibility" style="width:250px;">		
-		<?php 
+  	<select name="session_visibility" style="width:250px;">
+		<?php
 		$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('ReadOnly'), SESSION_VISIBLE=>get_lang('Visible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('Invisible')));
 		foreach($visibility_list as $key=>$item): ?>
 		<option value="<?php echo $key; ?>" <?php if($item == $visibility_id) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
@@ -399,9 +399,9 @@ function setDisable(select){
 	document.form.day_end.disabled = (select.checked) ? true : false;
 	document.form.month_end.disabled = (select.checked) ? true : false;
 	document.form.year_end.disabled = (select.checked) ? true : false;
-	
-	document.form.session_visibility.disabled = (select.checked) ? true : false;	
-	document.form.session_visibility.selectedIndex = 0;	
+
+	document.form.session_visibility.disabled = (select.checked) ? true : false;
+	document.form.session_visibility.selectedIndex = 0;
 }
 </script>
 <?php

+ 11 - 11
main/admin/session_category_edit.php

@@ -4,7 +4,7 @@
 	Dokeos - elearning and course management software
 
 	Copyright (c) 2009 Dokeos SPRL
-	
+
 	For a full list of contributors, see "credits.txt".
 	The full license can be read in "license.txt".
 
@@ -37,8 +37,8 @@ $tool_name = get_lang('EditSessionCategory');
 $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
 $interbreadcrumb[]=array('url' => "session_category_list.php","name" => get_lang('ListSessionCategory'));
 $sql = "SELECT * FROM $tbl_session_category WHERE id='".$id."' ORDER BY name";
-$result=api_sql_query($sql,__FILE__,__LINE__);
-if (!$infos=mysql_fetch_array($result)) {
+$result=Database::query($sql,__FILE__,__LINE__);
+if (!$infos=Database::fetch_array($result)) {
 	header('Location: session_list.php');
 	exit();
 }
@@ -51,12 +51,12 @@ if (!api_is_platform_admin() && $infos['session_admin_id']!=$_user['user_id']) {
 if ($_POST['formSent']) {
 	$formSent=1;
 	$name= $_POST['name'];
-	$year_start= $_POST['year_start']; 
-	$month_start=$_POST['month_start']; 
-	$day_start=$_POST['day_start']; 
-	$year_end=$_POST['year_end']; 
-	$month_end=$_POST['month_end']; 
-	$day_end=$_POST['day_end']; 
+	$year_start= $_POST['year_start'];
+	$month_start=$_POST['month_start'];
+	$day_start=$_POST['day_start'];
+	$year_end=$_POST['year_end'];
+	$month_end=$_POST['month_end'];
+	$day_end=$_POST['day_end'];
 	$return = SessionManager::edit_category_session($id, $name, $year_start, $month_start, $day_start, $year_end, $month_end, $day_end);
 	if ($return == strval(intval($return))) {
 		header('Location: session_category_list.php?action=show_message&message='.urlencode(get_lang('SessionCategoryUpdate')));
@@ -209,13 +209,13 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
 <tr>
 	<td>
 		&nbsp;
-	</td>	
+	</td>
 </tr>
 <tr>
   <td>&nbsp;</td>
   <td>
 <button class="save" type="submit" value="<?php echo get_lang('ModifyThisSession') ?>"><?php echo get_lang('ModifyThisSession') ?></button>
-  
+
   </td>
 </tr>
 

+ 48 - 48
main/admin/session_category_list.php

@@ -12,19 +12,19 @@ api_protect_admin_script(true);
 // setting the section (for the tabs)
 $this_section=SECTION_PLATFORM_ADMIN;
 $htmlHeadXtra[] = '<script language="javascript">
-		
+
 				function selectAll(idCheck,numRows,action) {
-					
+
 					for(i=0;i<numRows;i++) {
 						idcheck = document.getElementById(idCheck+"_"+i);
 						if (action == "true"){
 							idcheck.checked = true;
 						} else {
 							idcheck.checked = false;
-						}		
-					}		
-							
-				}				
+						}
+					}
+
+				}
 				</script>';
 
 $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
@@ -55,7 +55,7 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 	$active_group[] = $form->createElement('checkbox','active','',get_lang('Active'));
 	$active_group[] = $form->createElement('checkbox','inactive','',get_lang('Inactive'));
 	$form->addGroup($active_group,'',get_lang('ActiveSession'),'<br/>',false);
-	
+
 	$form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"');
 	$defaults['active'] = 1;
 	$defaults['inactive'] = 1;
@@ -65,46 +65,46 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 	$limit = 20;
 	$from = $page * $limit;
 	//if user is crfp admin only list its sessions
-	if(!api_is_platform_admin()) {		
+	if(!api_is_platform_admin()) {
 		$where .= (empty($_REQUEST['keyword']) ? " " : " WHERE name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
 	}
 	else {
 		$where .= (empty($_REQUEST['keyword']) ? " " : " WHERE name LIKE '%".addslashes($_REQUEST['keyword'])."%'");
 	}
-	
-	$query = "SELECT sc.*, (select count(id) FROM $tbl_session WHERE session_category_id = sc.id) as nbr_session 
-	 			FROM $tbl_session_category sc 
-	 			$where 
-	 			ORDER BY $sort $order   
+
+	$query = "SELECT sc.*, (select count(id) FROM $tbl_session WHERE session_category_id = sc.id) as nbr_session
+	 			FROM $tbl_session_category sc
+	 			$where
+	 			ORDER BY $sort $order
 	 			LIMIT $from,".($limit+1);
 
-	$query_rows = "SELECT count(*) as total_rows  
+	$query_rows = "SELECT count(*) as total_rows
 				FROM $tbl_session_category sc $where ";
-	
+
 	$order = ($order == 'ASC')? 'DESC': 'ASC';
-	$result_rows = api_sql_query($query_rows,__FILE__,__LINE__);
+	$result_rows = Database::query($query_rows,__FILE__,__LINE__);
 	$recorset = Database::fetch_array($result_rows);
 	$num = $recorset['total_rows'];
-	$result = api_sql_query($query,__FILE__,__LINE__);
-	$Sessions = api_store_result($result);
+	$result = Database::query($query,__FILE__,__LINE__);
+	$Sessions = Database::store_result($result);
 	$nbr_results = sizeof($Sessions);
-	$tool_name = get_lang('ListSessionCategory');	
-	Display::display_header($tool_name);	
+	$tool_name = get_lang('ListSessionCategory');
+	Display::display_header($tool_name);
 	api_display_tool_title($tool_name);
-    
+
     if (!empty($_GET['warn'])) {
         Display::display_warning_message(urldecode($_GET['warn']),false);
     }
     if(isset($_GET['action'])) {
         Display::display_normal_message(stripslashes($_GET['message']),false);
     }
-    ?>	
-	
-	<div class="actions">		
+    ?>
+
+	<div class="actions">
 	<?php
 	echo '<div style="float:right;">
-			<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('view_more_stats.gif',get_lang('AddSession')).get_lang('AddSessionCategory').'</a>									
-	 	  </div>';	  
+			<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('view_more_stats.gif',get_lang('AddSession')).get_lang('AddSessionCategory').'</a>
+	 	  </div>';
 	?>
 	<form method="POST" action="session_category_list.php">
 		<input type="text" name="keyword" value="<?php echo Security::remove_XSS($_GET['keyword']); ?>"/>
@@ -112,8 +112,8 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 		<!-- <a href="session_list.php?search=advanced"><?php echo get_lang('AdvancedSearch'); ?></a> -->
 		</form>
 	<form method="post" action="<?php echo api_get_self(); ?>?action=delete&sort=<?php echo $sort; ?>" onsubmit="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;">
-	 </div><br />	
-	<div align="left">	
+	 </div><br />
+	<div align="left">
 	<?php
 	if(count($Sessions)==0 && isset($_POST['keyword'])) {
 		echo get_lang('NoSearchResults');
@@ -122,23 +122,23 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 		if ($num > $limit) {
 			if ($page) {
 			?>
-			<a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&order=<?php echo  Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>	
+			<a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&order=<?php echo  Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
 			<?php
 			} else {
 				echo get_lang('Previous');
 			}
-			?>	
+			?>
 			|
 			<?php
 			if($nbr_results > $limit) {
-				?>	
-				<a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&order=<?php echo  Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>	
+				?>
+				<a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&order=<?php echo  Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
 				<?php
 			} else {
 				echo get_lang('Next');
 			}
 		}
-		?>	
+		?>
 	</div>
 		<br />
 		<table class="data_table" width="100%">
@@ -150,7 +150,7 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 		  <th><a href="<?php echo api_get_self(); ?>?sort=date_end&order=<?php echo ($sort=='date_end')? $order: 'ASC'; ?>"><?php echo get_lang('EndDate'); ?></a></th>
 		  <th><?php echo get_lang('Actions'); ?></th>
 		</tr>
-	
+
 		<?php
 		$i=0;
 		$x=0;
@@ -159,15 +159,15 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 				break;
 			}
 		$sql = 'SELECT COUNT(session_category_id) FROM '.$tbl_session.' WHERE session_category_id = '.intval($enreg['id']);
-		$rs = api_sql_query($sql, __FILE__, __LINE__);
+		$rs = Database::query($sql, __FILE__, __LINE__);
 		list($nb_courses) = Database::fetch_array($rs);
 		?>
 		<tr class="<?php echo $i?'row_odd':'row_even'; ?>">
-		  <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>		  
+		  <td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
 		  <td><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></td>
 		  <td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
 		  <td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
-		  <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>		  
+		  <td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
 		  <td>
 			<a href="session_category_edit.php?&id=<?php echo $enreg['id']; ?>"><?php Display::display_icon('edit.gif', get_lang('Edit')); ?></a>
 			<a href="<?php echo api_get_self(); ?>?sort=<?php echo $sort; ?>&action=delete_off_session&idChecked=<?php echo $enreg['id']; ?>" onclick="javascript:if(!confirm('<?php echo get_lang('ConfirmYourChoice'); ?>')) return false;"><?php Display::display_icon('delete.gif', get_lang('Delete')); ?></a>
@@ -176,23 +176,23 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 		<?php
 			$i=$i ? 0 : 1;
 			$x++;
-		}	
-		unset($Sessions);	
+		}
+		unset($Sessions);
 		?>
 		</table>
 		<br />
-	
+
 		<div align="left">
-	
+
 		<?php
-		
+
 		if ($num > $limit) {
 		if ($page)
 			{
 			?>
-		
+
 			<a href="<?php echo api_get_self(); ?>?page=<?php echo $page-1; ?>&sort=<?php echo $sort; ?>&order=<?php echo  Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
-		
+
 			<?php
 			}
 			else
@@ -200,16 +200,16 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
 				echo get_lang('Previous');
 			}
 			?>
-		
+
 			|
-		
+
 			<?php
 			if($nbr_results > $limit)
 			{
 			?>
-		
+
 			<a href="<?php echo api_get_self(); ?>?page=<?php echo $page+1; ?>&sort=<?php echo $sort; ?>&order=<?php echo  Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Next'); ?></a>
-		
+
 			<?php
 			}
 			else

+ 1 - 1
main/admin/session_course_edit.php

@@ -139,7 +139,7 @@ foreach($coaches as $enreg)
 {
 ?>
 
-	<option value="<?php echo $enreg['user_id']; ?>" <?php if((!$sent && (is_array($arr_infos) && in_array($enreg['user_id'],$arr_infos))) || ($sent && $enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['firstname', $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
+	<option value="<?php echo $enreg['user_id']; ?>" <?php if((!$sent && (is_array($arr_infos) && in_array($enreg['user_id'],$arr_infos))) || ($sent && $enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
 
 <?php
 }

+ 46 - 46
main/admin/session_course_user.php

@@ -46,7 +46,7 @@ if (empty($id_user) || empty($id_session)) {
 
 if (!api_is_platform_admin()) {
 	$sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
-	$rs = api_sql_query($sql,__FILE__,__LINE__);
+	$rs = Database::query($sql, __FILE__, __LINE__);
 	if (Database::result($rs,0,0)!=$_user['user_id']) {
 		api_not_allowed(true);
 	}
@@ -58,35 +58,35 @@ $CourseList=$SessionList=array();
 $courses=$sessions=array();
 $noPHP_SELF=true;
 
-if ($_POST['formSent']) {		
-	$formSent			= $_POST['formSent'];		
+if ($_POST['formSent']) {
+	$formSent			= $_POST['formSent'];
 	$CourseList			= $_POST['SessionCoursesList'];
-	
+
 	if (!is_array($CourseList)) {
 		$CourseList=array();
 	}
-	
+
 	$sql="SELECT distinct code
-			FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course 
-			ON course.code = session_rel_course.course_code inner join $tbl_session_rel_course_rel_user as srcru 
-			ON (srcru.id_session =  session_rel_course.id_session)	
+			FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course
+			ON course.code = session_rel_course.course_code inner join $tbl_session_rel_course_rel_user as srcru
+			ON (srcru.id_session =  session_rel_course.id_session)
 			WHERE id_user = $id_user and session_rel_course.id_session = $id_session";
-	
-	$rs = api_sql_query($sql);
-	$existingCourses = api_store_result($rs);	
-	if (count($CourseList) == count($existingCourses)) {		
+
+	$rs = Database::query($sql, __FILE__, __LINE__);
+	$existingCourses = Database::store_result($rs);
+	if (count($CourseList) == count($existingCourses)) {
 		header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('MaybeYouWantToDeleteThisUserFromSession'));
 		exit;
 	}
-	foreach($CourseList as $enreg_course) {		
+	foreach($CourseList as $enreg_course) {
 		$exists = false;
 		foreach($existingCourses as $existingCourse) {
 			if($enreg_course == $existingCourse['course_code']) {
 				$exists=true;
 			}
 		}
-		if(!$exists) {	
-			$enreg_course = Database::escape_string($enreg_course);		
+		if(!$exists) {
+			$enreg_course = Database::escape_string($enreg_course);
 			$sql_delete = "DELETE FROM $tbl_session_rel_course_rel_user
 							WHERE id_user='".$id_user."'  AND course_code='".$enreg_course."' AND id_session=$id_session";
 			Database::query($sql_delete,__FILE__, __LINE__);
@@ -94,21 +94,21 @@ if ($_POST['formSent']) {
 				//update session rel course table
 				$sql_update  = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1 WHERE id_session='$id_session' AND course_code='$enreg_course'";
 				Database::query($sql_update,__FILE__, __LINE__);
-			}			
+			}
 		}
 	}
-	foreach($existingCourses as $existingCourse) {				
+	foreach($existingCourses as $existingCourse) {
 		//$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code, id_coach) VALUES('$id_session','$enreg_course','$id_coach')";
 		if(!in_array($existingCourse['code'], $CourseList)){
 			$existingCourse = Database::escape_string($existingCourse['code']);
 			$sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$existingCourse','$id_user')";
 			Database::query($sql_insert,__FILE__, __LINE__);
-			if(Database::affected_rows()) {				
+			if(Database::affected_rows()) {
 				//update session rel course table
 				$sql_update  = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1 WHERE id_session='$id_session' AND course_code='$existingCourse'";
 				Database::query($sql_update,__FILE__, __LINE__);
 			}
-			
+
 		}
 	}
 	//header('Location: session_course_user.php?id_user='.$id_user.'&id_session='.$id_session);
@@ -120,7 +120,7 @@ if ($_POST['formSent']) {
 Display::display_header($tool_name);
 
 if (!empty($_GET['msg'])) {
-    Display::display_normal_message(urldecode($_GET['msg']));    
+    Display::display_normal_message(urldecode($_GET['msg']));
 }
 
 // the form header
@@ -128,22 +128,22 @@ $session_info = SessionManager::fetch($id_session);
 echo '<div class="row"><div class="form_header">'.$tool_name.' ('.$session_info['name'].')</div></div><br />';
 $nosessionCourses = $sessionCourses = array();
 
-/*$sql="SELECT distinct code, title, visual_code, session_rel_course.id_session 
-FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course 
-ON course.code = session_rel_course.course_code inner join $tbl_session_rel_course_rel_user as srcru 
-ON (srcru.id_session =  session_rel_course.id_session)	
+/*$sql="SELECT distinct code, title, visual_code, session_rel_course.id_session
+FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course
+ON course.code = session_rel_course.course_code inner join $tbl_session_rel_course_rel_user as srcru
+ON (srcru.id_session =  session_rel_course.id_session)
 WHERE id_user = $id_user and session_rel_course.id_session = $id_session";
 */
 // actual user
 $sql="SELECT code, title, visual_code, srcru.id_session " .
 			"FROM $tbl_course course inner JOIN $tbl_session_rel_course_rel_user   as srcru  " .
 			"ON course.code = srcru.course_code  where srcru.id_user = $id_user AND id_session = $id_session";
-			
+
 //all
 $sql_all="SELECT code, title, visual_code, src.id_session " .
 			"FROM $tbl_course course inner JOIN $tbl_session_rel_course  as src  " .
 			"ON course.code = src.course_code AND id_session = $id_session";
-			
+
 
 /*
 	echo $sql="SELECT code, title, visual_code, id_session
@@ -152,10 +152,10 @@ $sql_all="SELECT code, title, visual_code, src.id_session " .
 				ON course.code = session_rel_course.course_code
 				AND session_rel_course.id_session = ".intval($id_session)."
 			ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
-	*/					
+	*/
 /*global $_configuration;
-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 code, title, visual_code, id_session
@@ -164,28 +164,28 @@ if ($_configuration['multiple_access_urls']==true) {
 				ON course.code = session_rel_course.course_code
 				AND session_rel_course.id_session = ".intval($id_session)."
 			INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.course_code=course.code)
-			WHERE access_url_id = $access_url_id 
+			WHERE access_url_id = $access_url_id
 			ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
-	}	
+	}
 }*/
 
-$result=api_sql_query($sql,__FILE__,__LINE__);	
-$Courses=api_store_result($result);	
+$result=Database::query($sql,__FILE__,__LINE__);
+$Courses=Database::store_result($result);
 
-$result=api_sql_query($sql_all,__FILE__,__LINE__);	
-$CoursesAll=api_store_result($result);	
+$result=Database::query($sql_all,__FILE__,__LINE__);
+$CoursesAll=Database::store_result($result);
 
 $course_temp = array();
 foreach($Courses as $course) {
 	$course_temp[] = $course['code'];
-}	
+}
 foreach($CoursesAll as $course) {
 	if (in_array($course['code'], $course_temp)) {
 		$nosessionCourses[$course['code']] = $course ;
 	} else {
 		$sessionCourses[$course['code']] = $course ;
 	}
-}	
+}
 
 unset($Courses);
 ?>
@@ -232,11 +232,11 @@ unset($nosessionCourses);
   <td width="45%" align="center"><select id='destination' name="SessionCoursesList[]" multiple="multiple" size="20" style="width:320px;">
 <?php
 foreach($sessionCourses as $enreg)
-{	
-?>	
+{
+?>
 	<option value="<?php echo $enreg['code']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>"><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
 
-<?php 
+<?php
 }
 unset($sessionCourses);
 ?>
@@ -259,25 +259,25 @@ function moveItem(origin , destination){
 	}
 	destination.selectedIndex = -1;
 	sortOptions(destination.options);
-	
+
 
 }
 
 function sortOptions(options) {
 
 	newOptions = new Array();
-	
+
 	for (i = 0 ; i<options.length ; i++) {
-		newOptions[i] = options[i];							
+		newOptions[i] = options[i];
 	}
 
 	newOptions = newOptions.sort(mysort);
 	options.length = 0;
 
-	for(i = 0 ; i < newOptions.length ; i++){		
-		options[i] = newOptions[i];			
+	for(i = 0 ; i < newOptions.length ; i++){
+		options[i] = newOptions[i];
 	}
-	
+
 }
 
 function mysort(a, b){

+ 10 - 10
main/admin/session_edit.php

@@ -29,7 +29,7 @@ $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('Session
 
 $result=Database::query("SELECT name,date_start,date_end,id_coach, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility FROM $tbl_session WHERE id='$id'",__FILE__,__LINE__);
 
-if (!$infos=mysql_fetch_array($result)) {
+if (!$infos=Database::fetch_array($result)) {
 	header('Location: session_list.php');
 	exit();
 }
@@ -55,7 +55,7 @@ if ($_POST['formSent']) {
 	$id_coach=$_POST['id_coach'];
 	$id_session_category = $_POST['session_category'];
 	$id_visibility = $_POST['session_visibility'];
-	
+
 	$return = SessionManager::edit_session($id,$name,$year_start,$month_start,$day_start,$year_end,$month_end,$day_end,$nb_days_acess_before,$nb_days_acess_after,$nolimit, $id_coach, $id_session_category,$id_visibility);
 	if ($return == strval(intval($return))) {
 		header('Location: resume_session.php?id_session='.$return);
@@ -123,11 +123,11 @@ unset($Coaches);
   </select></td>
 </tr>
 <?php
-	$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);	
-	//$access_url_id = api_get_current_access_url_id();							
+	$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
+	//$access_url_id = api_get_current_access_url_id();
 	$sql = 'SELECT id, name FROM '.$tbl_session_category.' ORDER BY name ASC';
-	$result = api_sql_query($sql,__FILE__,__LINE__);
-	$Categories = api_store_result($result);
+	$result = Database::query($sql,__FILE__,__LINE__);
+	$Categories = Database::store_result($result);
 ?>
 <tr>
   <td width="30%"><?php echo get_lang('SessionCategory') ?></td>
@@ -315,8 +315,8 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
 <tr>
   <td width="30%"><?php echo get_lang('SessionVisibility') ?></td>
   <td width="70%">
-  	<select name="session_visibility" style="width:250px;">		
-		<?php	
+  	<select name="session_visibility" style="width:250px;">
+		<?php
 		$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('ReadOnly'), SESSION_VISIBLE=>get_lang('Visible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('Invisible')));
 		foreach($visibility_list as $key=>$item): ?>
 		<option value="<?php echo $key; ?>" <?php if($key == $infos['visibility']) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
@@ -352,8 +352,8 @@ function setDisable(select){
 	document.form.year_end.disabled = (select.checked) ? true : false;
 
 	document.form.session_visibility.disabled = (select.checked) ? true : false;
-	
-	document.form.session_visibility.selectedIndex = 0;	
+
+	document.form.session_visibility.selectedIndex = 0;
 
 }
 </script>

+ 4 - 4
main/admin/session_import.php

@@ -113,7 +113,7 @@ if ($_POST['formSent']) {
 
 							// When it is applicable, adding the access_url rel user relationship too.
 							Database::query($sql, __FILE__, __LINE__);
-							$return = Database::get_last_insert_id();
+							$return = Database::insert_id();
 							global $_configuration;
 							require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
 							if ($_configuration['multiple_access_urls']) {
@@ -313,7 +313,7 @@ if ($_POST['formSent']) {
 									date_end = '$date_end',
 									session_admin_id=".intval($_user['user_id']);
 							$rs_session = Database::query($sql_session, __FILE__, __LINE__);
-							$session_id = Database::get_last_insert_id();
+							$session_id = Database::insert_id();
 							$session_counter++;
 
 						} else {
@@ -328,7 +328,7 @@ if ($_POST['formSent']) {
 										date_end = '$date_end',
 										session_admin_id=".intval($_user['user_id']);
 								$rs_session = Database::query($sql_session, __FILE__, __LINE__);
-								$session_id = Database::get_last_insert_id();
+								$session_id = Database::insert_id();
 								$session_counter++;
 							} else {
 								// if the session already exists - update it.
@@ -573,7 +573,7 @@ if ($_POST['formSent']) {
 								date_end = '$date_end',
 								session_admin_id=".intval($_user['user_id']);
 						$rs_session = Database::query($sql_session, __FILE__, __LINE__);
-						$session_id = Database::get_last_insert_id();
+						$session_id = Database::insert_id();
 						$session_counter++;
 					} else {
 						$my_session_result = SessionManager::get_session_by_name($session_name);

+ 6 - 6
main/admin/settings.php

@@ -86,11 +86,11 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
 	$renderer = & $form->defaultRenderer();
 	$renderer->setHeaderTemplate('<div class="sectiontitle">{header}</div>'."\n");
 	$renderer->setElementTemplate('<div class="sectioncomment">{label}</div>'."\n".'<div class="sectionvalue">{element}</div>'."\n");
-	$my_category = mysql_real_escape_string($_GET['category']);
+	$my_category = Database::escape_string($_GET['category']);
 
 	$sqlcountsettings = "SELECT COUNT(*) FROM $table_settings_current WHERE category='".$my_category."' AND type<>'checkbox'";
 	$resultcountsettings = Database::query($sqlcountsettings, __FILE__, __LINE__);
-	$countsetting = mysql_fetch_array($resultcountsettings);
+	$countsetting = Database::fetch_array($resultcountsettings);
 
 	if ($_configuration['access_url']==1)
 	{
@@ -128,7 +128,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
 	//print_r($settings_by_access_list);echo '</pre>';
 	//$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
 	//$resultsettings = Database::query($sqlsettings, __FILE__, __LINE__);
-	//while ($row = mysql_fetch_array($resultsettings))
+	//while ($row = Database::fetch_array($resultsettings))
 	$default_values = array();
 	foreach($settings as $row) {
 		if ($row['variable'] == 'search_enabled') { continue; }
@@ -296,7 +296,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
 		{
 			if (!is_array($value))
 			{
-				//$sql = "UPDATE $table_settings_current SET selected_value='".mysql_real_escape_string($value)."' WHERE variable='$key'";
+				//$sql = "UPDATE $table_settings_current SET selected_value='".Database::escape_string($value)."' WHERE variable='$key'";
 				//$result = Database::query($sql, __FILE__, __LINE__);
 
 				if (api_get_setting($key) != $value) $keys[] = $key;
@@ -381,7 +381,7 @@ $action_images['search']        = 'search.gif';
 //$resultcategories = Database::query($selectcategories, __FILE__, __LINE__);
 $resultcategories = api_get_settings_categories(array('stylesheets','Plugins', 'Templates', 'Search'));
 echo "\n<div class=\"actions\">";
-//while ($row = mysql_fetch_array($resultcategories))
+//while ($row = Database::fetch_array($resultcategories))
 foreach($resultcategories as $row)
 {
 	echo "\n\t<a href=\"".api_get_self()."?category=".$row['category']."\">".Display::return_icon($action_images[strtolower($row['category'])], api_ucfirst(get_lang($row['category']))).api_ucfirst(get_lang($row['category']))."</a>";
@@ -530,7 +530,7 @@ function handle_plugins()
 	//$sql = "SELECT * FROM $table_settings_current WHERE category='Plugins'";
 	//$result = Database::query($sql);
 	$result = api_get_settings('Plugins');
-	//while ($row = mysql_fetch_array($result))
+	//while ($row = Database::fetch_array($result))
 	foreach($result as $row)
 	{
 		$usedplugins[$row['variable']][] = $row['selected_value'];

+ 65 - 65
main/admin/special_exports.php

@@ -3,13 +3,13 @@
 /**
  * ==============================================================================
  * Special exports
- * 
+ *
  * @author Jhon Hinojosa <jhon.hinojosa@dokeos.com>
  * @package special.export
  * ==============================================================================
  */
 
-// name of the language file that needs to be included 
+// name of the language file that needs to be included
 $language_file = array ('admin');
 // including the global file
 include ('../inc/global.inc.php');
@@ -48,7 +48,7 @@ $error =0;
 
 $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
-		
+
 if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
 	require_once api_get_path(LIBRARY_PATH).'document.lib.php';
 	require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
@@ -58,14 +58,14 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
 		$to_group_id = 0;
 		$code_course = '';
 		$sql_session = "SELECT id, name FROM $tbl_session ";
-		$query_session = api_sql_query($sql_session, __FILE__, __LINE__);
+		$query_session = Database::query($sql_session, __FILE__, __LINE__);
 		$ListSession = array();
 		while($rows_session = mysql_fetch_assoc($query_session)) {
-			$ListSession[$rows_session['id']] = $rows_session['name'];  
+			$ListSession[$rows_session['id']] = $rows_session['name'];
 		}
 		$zip_folder=new PclZip($FileZip['TEMP_FILE_ZIP']);
 		if(!isset($_POST['resource']) || count($_POST['resource']) == 0 ) {
-			Display::display_error_message(get_lang('ErrorMsgSpecialExport')); 
+			Display::display_error_message(get_lang('ErrorMsgSpecialExport'));
 		} else {
 			$Resource = $_POST['resource'];
 			foreach($Resource as $Code_course => $Sessions) {
@@ -73,36 +73,36 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
 				$tbl_document = Database::get_course_table(TABLE_DOCUMENT, $_course['db_name']);
 				$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $_course['db_name']);
 				//Add tem to the zip file course
-				$sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props 
-					WHERE `props`.`tool`='".TOOL_DOCUMENT."' 
-						AND `docs`.`id`=`props`.`ref` 
-						AND `docs`.`path` LIKE '".$querypath."/%' 
-						AND `docs`.`filetype`='file' 
-						AND `docs`.`session_id` = '0' 
-						AND `props`.`visibility`<>'2' 
+				$sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props
+					WHERE `props`.`tool`='".TOOL_DOCUMENT."'
+						AND `docs`.`id`=`props`.`ref`
+						AND `docs`.`path` LIKE '".$querypath."/%'
+						AND `docs`.`filetype`='file'
+						AND `docs`.`session_id` = '0'
+						AND `props`.`visibility`<>'2'
 						AND `props`.`to_group_id`=".$to_group_id."";
-				$query = api_sql_query($sql ,__FILE__,__LINE__);	
+				$query = Database::query($sql ,__FILE__,__LINE__);
 				while($rows_course_file = mysql_fetch_assoc($query)) {
-					$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'], 
+					$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'],
 									 PCLZIP_OPT_ADD_PATH, $_course['directory'],
 									 PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE']
 									);
 				}
-				foreach($Sessions as $IdSession => $value){					
+				foreach($Sessions as $IdSession => $value){
 					$session_id = Security::remove_XSS($IdSession);
 					//Add tem to the zip file session course
-					$sql_session_doc = "SELECT path FROM $tbl_document AS docs,$tbl_property AS props 
-						WHERE `props`.`tool`='".TOOL_DOCUMENT."' 
-							AND `docs`.`id`=`props`.`ref` 
-							AND `docs`.`path` LIKE '".$querypath."/%' 
-							AND `docs`.`filetype`='file' 
-							AND `docs`.`session_id` = '$session_id' 
-							AND `props`.`visibility`<>'2' 
+					$sql_session_doc = "SELECT path FROM $tbl_document AS docs,$tbl_property AS props
+						WHERE `props`.`tool`='".TOOL_DOCUMENT."'
+							AND `docs`.`id`=`props`.`ref`
+							AND `docs`.`path` LIKE '".$querypath."/%'
+							AND `docs`.`filetype`='file'
+							AND `docs`.`session_id` = '$session_id'
+							AND `props`.`visibility`<>'2'
 							AND `props`.`to_group_id`=".$to_group_id."";
-					$query_session_doc = api_sql_query($sql_session_doc, __FILE__, __LINE__);
+					$query_session_doc = Database::query($sql_session_doc, __FILE__, __LINE__);
 					while($rows_course_session_file = mysql_fetch_assoc($query_session_doc)) {
-						$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],  
-										 PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$ListSession[$session_id],  
+						$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],
+										 PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$ListSession[$session_id],
 										 PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory'].'/document'.$FileZip['PATH_REMOVE']
 										);
 					}
@@ -121,7 +121,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
  {
 	window.location="../course_info/download.php?archive=<?php echo $name; ?>&session=true";
  }
-</script> //-->	
+</script> //-->
 <?php
 }
 
@@ -133,7 +133,7 @@ function create_zip(){
 	$sys_archive_path = api_get_path(SYS_ARCHIVE_PATH);
 	$sys_course_path = api_get_path(SYS_COURSE_PATH);
 	$temp_zip_dir = $sys_archive_path."temp";
-	if(!is_dir($temp_zip_dir)) { 
+	if(!is_dir($temp_zip_dir)) {
 		mkdir($temp_zip_dir);
 	} else {
 		$handle=opendir($temp_zip_dir);
@@ -146,12 +146,12 @@ function create_zip(){
 		closedir($handle);
 	}
 	$temp_zip_file = $temp_zip_dir."/".md5(time()).".zip"; 	//create zipfile of given directory
-	
-	
-	
-	return array('PATH' => $path, 
-				 'PATH_TEMP_ARCHIVE' => $temp_zip_dir, 
-				 'PATH_COURSE' => $sys_course_path, 
+
+
+
+	return array('PATH' => $path,
+				 'PATH_TEMP_ARCHIVE' => $temp_zip_dir,
+				 'PATH_COURSE' => $sys_course_path,
 				 'TEMP_FILE_ZIP' => $temp_zip_file,
 				 'PATH_REMOVE' => $remove_dir);
 }
@@ -159,12 +159,12 @@ function create_zip(){
 function rename_zip($FileZip) {
 	event_download(($FileZip['PATH'] == '/')?'full_export_'.date('Ymd').'.zip (folder)': basename($FileZip['PATH']).'.zip (folder)');
 	$name = ($FileZip['PATH']=='/')? 'full_export_'.date('Ymd').'.zip':basename($FileZip['PATH']).'.zip';
-	if(file_exists($FileZip['PATH_TEMP_ARCHIVE'].'/'.$name)){ unlink($FileZip['PATH_TEMP_ARCHIVE'].'/'.$name); }	
-	if(file_exists($FileZip['TEMP_FILE_ZIP'])) { 
+	if(file_exists($FileZip['PATH_TEMP_ARCHIVE'].'/'.$name)){ unlink($FileZip['PATH_TEMP_ARCHIVE'].'/'.$name); }
+	if(file_exists($FileZip['TEMP_FILE_ZIP'])) {
 		rename($FileZip['TEMP_FILE_ZIP'], $FileZip['PATH_TEMP_ARCHIVE'].'/'.$name);
 		return $name;
 	} else { return false; }
-	
+
 }
 
 function fullexportspecial(){
@@ -185,42 +185,42 @@ function fullexportspecial(){
 			$tbl_document = Database::get_course_table(TABLE_DOCUMENT, $_course['db_name']);
 			$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $_course['db_name']);
 			//Add tem to the zip file course
-			$sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props 
-				WHERE `props`.`tool`='".TOOL_DOCUMENT."' 
-					AND `docs`.`id`=`props`.`ref` 
-					AND `docs`.`path` LIKE '".$querypath."/%' 
-					AND `docs`.`filetype`='file' 
-					AND `docs`.`session_id` = '0' 
-					AND `props`.`visibility`<>'2' 
+			$sql = "SELECT path FROM $tbl_document AS docs, $tbl_property AS props
+				WHERE `props`.`tool`='".TOOL_DOCUMENT."'
+					AND `docs`.`id`=`props`.`ref`
+					AND `docs`.`path` LIKE '".$querypath."/%'
+					AND `docs`.`filetype`='file'
+					AND `docs`.`session_id` = '0'
+					AND `props`.`visibility`<>'2'
 					AND `props`.`to_group_id`=".$to_group_id."";
-			$query = api_sql_query($sql ,__FILE__,__LINE__);	
+			$query = Database::query($sql ,__FILE__,__LINE__);
 			while($rows_course_file = mysql_fetch_assoc($query)) {
 				$rows_course_file['path'];
-				$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'], 
+				$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory']."/document".$rows_course_file['path'],
 								 PCLZIP_OPT_ADD_PATH, $_course['directory'],
 								 PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory']."/document".$FileZip['PATH_REMOVE']
 								);
 			}
 			//Add tem to the zip file session course
 			$code_course = $_course['code'];
-			$sql_session = "SELECT id, name, course_code  FROM $tbl_session_course 
-				INNER JOIN  $tbl_session ON id_session = id 
+			$sql_session = "SELECT id, name, course_code  FROM $tbl_session_course
+				INNER JOIN  $tbl_session ON id_session = id
 				WHERE course_code = '$code_course' ";
-			$query_session = api_sql_query($sql_session, __FILE__, __LINE__);
+			$query_session = Database::query($sql_session, __FILE__, __LINE__);
 			while($rows_session = mysql_fetch_assoc($query_session)) {
 				$session_id = $rows_session['id'];
-				$sql_session_doc = "SELECT path FROM $tbl_document AS docs,$tbl_property AS props 
-					WHERE `props`.`tool`='".TOOL_DOCUMENT."' 
-						AND `docs`.`id`=`props`.`ref` 
-						AND `docs`.`path` LIKE '".$querypath."/%' 
-						AND `docs`.`filetype`='file' 
-						AND `docs`.`session_id` = '$session_id' 
-						AND `props`.`visibility`<>'2' 
+				$sql_session_doc = "SELECT path FROM $tbl_document AS docs,$tbl_property AS props
+					WHERE `props`.`tool`='".TOOL_DOCUMENT."'
+						AND `docs`.`id`=`props`.`ref`
+						AND `docs`.`path` LIKE '".$querypath."/%'
+						AND `docs`.`filetype`='file'
+						AND `docs`.`session_id` = '$session_id'
+						AND `props`.`visibility`<>'2'
 						AND `props`.`to_group_id`=".$to_group_id."";
-				$query_session_doc = api_sql_query($sql_session_doc, __FILE__, __LINE__);
+				$query_session_doc = Database::query($sql_session_doc, __FILE__, __LINE__);
 				while($rows_course_session_file = mysql_fetch_assoc($query_session_doc)) {
-					$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],  
-									 PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$rows_session['name'],  
+					$zip_folder->add($FileZip['PATH_COURSE'].$_course['directory'].'/document'.$rows_course_session_file['path'],
+									 PCLZIP_OPT_ADD_PATH, $_course['directory']."/".$rows_session['name'],
 									 PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'].$_course['directory'].'/document'.$FileZip['PATH_REMOVE']
 									);
 				}
@@ -233,15 +233,15 @@ function fullexportspecial(){
 		}else{
 			$export = true;
 			return $name;
-		}		
+		}
 	}else{
 		Display::display_error_message(get_lang('ErrorMsgSpecialExport')); //main API
 		$export = false;
 		return false;
-	}	
+	}
 }
 
-if($export == true && $name != false) { 
+if($export == true && $name != false) {
 	Display::display_confirmation_message(get_lang('BackupCreated').'<br /><br /><a class="bottom-link" href="'.api_get_path(WEB_CODE_PATH).'course_info/download.php?archive='.urlencode($name).'&session=true">'.$name.'</a>', false);
 	echo '<p><a class="bottom-link"  href="'.api_get_path(WEB_CODE_PATH).'admin/index.php">&nbsp;'.get_lang('MainMenu').'</a></p>';
 } else{
@@ -251,8 +251,8 @@ if($export == true && $name != false) {
 		$course = $cb->build_session_course();
 		if($course === false){
 			Display::display_error_message(get_lang('ErrorMsgSpecialExport'));
-			form_special_export(); 
-		} else { 
+			form_special_export();
+		} else {
 			Display::display_normal_message(get_lang('ToExportSpecialSelect'));
 			CourseSelectForm :: display_form_session_export($course);
 		}
@@ -278,7 +278,7 @@ function form_special_export(){
 }
 /*
 ==============================================================================
-		FOOTER 
+		FOOTER
 ==============================================================================
 */
 Display::display_footer();

+ 1 - 1
main/admin/user_export.php

@@ -68,7 +68,7 @@ if ($_configuration['multiple_access_urls']==true) {
 	}
 }
 $result = Database::query($sql, __FILE__, __LINE__);
-while ($course = mysql_fetch_object($result))
+while ($course = Database::fetch_object($result))
 {
 	$courses[$course->code] = $course->visual_code.' - '.$course->title;
 }

+ 7 - 7
main/admin/user_information.php

@@ -155,12 +155,12 @@ if(count($sessions)>0){
 										ON session_course.id_session = session.id
 									 WHERE session_course.id_session = $id_session
 									 ORDER BY i";
-		*/							 
-		// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not  	 
-		$personal_course_list_sql = "SELECT distinct course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, CONCAT(user.lastname,' ',user.firstname) t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name, IF(session_course.id_coach = 3,'2', '5') 
-										FROM $tbl_session_course_user as session_course_user INNER JOIN $tbl_course AS course 
+		*/
+		// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not
+		$personal_course_list_sql = "SELECT distinct course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, CONCAT(user.lastname,' ',user.firstname) t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name, IF(session_course.id_coach = 3,'2', '5')
+										FROM $tbl_session_course_user as session_course_user INNER JOIN $tbl_course AS course
 										ON course.code = session_course_user.course_code AND session_course_user.id_session = $id_session INNER JOIN $tbl_session as session ON session_course_user.id_session = session.id
-										INNER JOIN $tbl_session_course as session_course 
+										INNER JOIN $tbl_session_course as session_course
 										LEFT JOIN $tbl_user as user ON user.user_id = session_course.id_coach
 										WHERE session_course_user.id_user = $user_id  ORDER BY i";
 
@@ -221,7 +221,7 @@ if (Database::num_rows($res) > 0)
 	$header[] = array (get_lang('Status'), true);
 	$header[] = array ('', false);
 	$data = array ();
-	while ($course = mysql_fetch_object($res))
+	while ($course = Database::fetch_object($res))
 	{
 		$row = array ();
 		$row[] = $course->code;
@@ -261,7 +261,7 @@ if (Database::num_rows($res) > 0)
 	$header[] = array (get_lang('ClassName'), true);
 	$header[] = array ('', false);
 	$data = array ();
-	while ($class = mysql_fetch_object($res))
+	while ($class = Database::fetch_object($res))
 	{
 		$row = array();
 		$row[] = $class->name;

+ 2 - 2
main/announcements/announcements.inc.php

@@ -754,7 +754,7 @@ function store_advalvas_item($emailTitle,$newContent, $order, $to)
 	// store in the table announcement
 	$sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order', session_id=".intval($_SESSION['id_session']);
 	$result = Database::query($sql,__FILE__,__LINE__) or die (mysql_error());
-	$last_id= Database::get_last_insert_id();
+	$last_id= Database::insert_id();
 
 	// store in item_property (first the groups, then the users
 	if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
@@ -804,7 +804,7 @@ function store_advalvas_group_item($emailTitle,$newContent, $order, $to, $to_use
 	// store in the table announcement
 	$sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order', session_id=".intval($_SESSION['id_session']);
 	$result = Database::query($sql,__FILE__,__LINE__) or die (mysql_error());
-	$last_id= Database::get_last_insert_id();
+	$last_id= Database::insert_id();
 
 	// store in item_property (first the groups, then the users
 	if (!isset($to_users)) // !isset($to): when no user is selected we send it to everyone

+ 2 - 2
main/calendar/agenda.inc.php

@@ -1063,7 +1063,7 @@ function store_agenda_item_as_announcement($item_id){
 		$res_ins = Database::query($sql_ins,__FILE__,__LINE__);
 		if($res > 0)
 		{
-			$ann_id = Database::get_last_insert_id();
+			$ann_id = Database::insert_id();
 			//Now also get the list of item_properties rows for this agenda_item (calendar_event)
 			//and copy them into announcement item_properties
 			$table_props = Database::get_course_table(TABLE_ITEM_PROPERTY);
@@ -1792,7 +1792,7 @@ function display_agenda_items()
 
 	$session_id = api_get_session_id();
 	$session_condition = api_get_session_condition($session_id);
-	
+
 	if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()))
 	{
 		// A.1. you are a course admin with a USER filter

+ 1 - 1
main/chat/chat_hidden.php

@@ -114,7 +114,7 @@ if ($_SESSION["origin"] == 'whoisonline') {  //check if our target has denied ou
 	$track_user_table = Database::get_main_table(TABLE_MAIN_USER);
 	$sql="select chatcall_text from $track_user_table where ( user_id = $talk_to )";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	$row=mysql_fetch_array($result);
+	$row=Database::fetch_array($result);
 	if ($row['chatcall_text'] == 'DENIED') {
 		echo "<script language=javascript> alert('".get_lang('ChatDenied')."'); </script>";
 		$sql="update $track_user_table set chatcall_user_id = '', chatcall_date = '', chatcall_text='' where (user_id = $talk_to)";

+ 2 - 2
main/course_description/index.php

@@ -141,7 +141,7 @@ if (api_is_allowed_to_edit(null,true) && !is_null($description_id) || $action ==
 	// Delete a description block
 	if ($action == 'delete') {
 		$sql = "DELETE FROM $tbl_course_description WHERE id='".$description_id."'";
-		api_sql_query($sql, __FILE__, __LINE__);
+		Database::query($sql, __FILE__, __LINE__);
 		//update item_property (delete)
 		api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, Database::escape_string($description_id), 'delete', api_get_user_id());
 		Display :: display_confirmation_message(get_lang('CourseDescriptionDeleted'));
@@ -229,7 +229,7 @@ if (api_is_allowed_to_edit(null,true) && !is_null($description_id) || $action ==
 				$sql = "INSERT INTO $tbl_course_description SET id = '".$description_id."', title = '".Database::escape_string(Security::remove_XSS($title,COURSEMANAGERLOWSECURITY))."', content = '".Database::escape_string(Security::remove_XSS($content,COURSEMANAGERLOWSECURITY))."', session_id = ".intval($session_id)." ";
 				Database::query($sql, __FILE__, __LINE__);
 			}
-			$id = Database::get_last_insert_id();
+			$id = Database::insert_id();
 			if ($id > 0) {
 				//insert into item_property
 				api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $id, 'CourseDescriptionAdded', api_get_user_id());

+ 2 - 2
main/course_home/2column.php

@@ -85,7 +85,7 @@ function show_tools($course_tool_category)
 	$i=0;
 
 	// grabbing all the tools from $course_tool_table
-	while ($temp_row = mysql_fetch_array($result))
+	while ($temp_row = Database::fetch_array($result))
 	{
 		if($course_tool_category == TOOL_PUBLIC_BUT_HIDDEN && $temp_row['image'] != 'scormbuilder.gif')
 		{
@@ -119,7 +119,7 @@ function show_tools($course_tool_category)
 	{
 		$properties = array();
 		$result_links=Database::query($sql_links,__FILE__,__LINE__);
-		while ($links_row=mysql_fetch_array($result_links))
+		while ($links_row=Database::fetch_array($result_links))
 		{
 			unset($properties);
 			$properties['name']=$links_row['title'];

+ 2 - 2
main/course_home/3column.php

@@ -89,7 +89,7 @@ if (is_allowed_to_edit())
 	{
 		$sql = "SELECT * FROM $TBL_ACCUEIL WHERE id=$id";
 		$result = Database::query($sql,__FILE__,__LINE__);
-		$toolsRow = mysql_fetch_array($result);
+		$toolsRow = Database::fetch_array($result);
 		$tool_name = htmlspecialchars($toolsRow['name'] != "" ? $toolsRow['name'] : $toolsRow['link'],ENT_QUOTES,$charset);
 		if($toolsRow['img'] != "external.gif")
 		{
@@ -154,7 +154,7 @@ if (is_allowed_to_edit())
 	elseif (isset ($update) && $update)
 	{
 		$result 	= Database::query("SELECT * FROM $TBL_ACCUEIL WHERE id=$id");
-		$toolsRow 	= mysql_fetch_array($result);
+		$toolsRow 	= Database::fetch_array($result);
 		$racine		= $_configuration['root_sys']."/".$currentCourseID."/images/";
 		$chemin		= $racine;
 		$name	= $toolsRow[1];

+ 25 - 25
main/course_home/activity.php

@@ -58,13 +58,13 @@ function show_tools_category($course_tool_category)
 	$course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
 	$is_allowed_to_edit = api_is_allowed_to_edit();
 	$is_platform_admin = api_is_platform_admin();
-	
+
 	//condition for the session
 	$session_id = api_get_session_id();
 	$condition_session = api_get_session_condition($session_id,true,true);
-	
+
 	switch ($course_tool_category) {
-		
+
 		case TOOL_STUDENT_VIEW:
 				$result = Database::query("SELECT * FROM $course_tool_table WHERE visibility = '1' AND (category = 'authoring' OR category = 'interaction') $condition_session ORDER BY id",__FILE__,__LINE__);
 				$colLink ="##003399";
@@ -219,11 +219,11 @@ function show_tools_category($course_tool_category)
 		$lnk = '';
 		foreach($all_tools_list as $toolsRow)
 		{
-			
+
 			if (api_get_session_id()!=0 && in_array($toolsRow['name'],array('course_maintenance','course_setting'))) {
 				continue;
 			}
-			
+
 			if(!($i%2))
 				{echo	"<tr valign=\"top\">\n";}
 
@@ -255,7 +255,7 @@ function show_tools_category($course_tool_category)
 				}
 
 			}
-			
+
 			// Both checks are necessary as is_platform_admin doesn't take student view into account
 			if( $is_platform_admin && $is_allowed_to_edit)
 			{
@@ -348,10 +348,10 @@ function show_tools_category($course_tool_category)
 					$tool_name = get_lang(ucfirst($toolsRow['name']));
 				}
 				Display::display_icon($toolsRow['image'], $tool_name, array('class'=>'tool-icon','id'=>'toolimage_'.$toolsRow["id"]));
-				
+
 				//validacion when belongs to a session
 				$session_img = api_get_session_image($toolsRow['session_id'], $_user['status']);
-				
+
 				echo '</a> ';
 
 				echo $my_tool_link;
@@ -413,11 +413,11 @@ if (isset($_GET['sent_http_request']) && $_GET['sent_http_request']==1) {
 		if(isset($_GET['visibility']) && $_GET['visibility']==0) // visibility 1 -> 0
 		{
 			if ($_GET["id"]==strval(intval($_GET["id"]))) {
-				$sql="UPDATE $tool_table SET visibility=0 WHERE id='".$_GET["id"]."'";	
-				Database::query($sql,__FILE__,__LINE__);				
+				$sql="UPDATE $tool_table SET visibility=0 WHERE id='".$_GET["id"]."'";
+				Database::query($sql,__FILE__,__LINE__);
 			}
 		}
-	
+
 	  /*
 		-----------------------------------------------------------
 			REACTIVATE
@@ -426,7 +426,7 @@ if (isset($_GET['sent_http_request']) && $_GET['sent_http_request']==1) {
 		elseif(isset($_GET['visibility'])&& $_GET['visibility']==1) // visibility 0,2 -> 1
 		{
 			if ($_GET["id"]==strval(intval($_GET["id"]))) {
-				Database::query("UPDATE $tool_table SET visibility=1 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);				
+				Database::query("UPDATE $tool_table SET visibility=1 WHERE id='".$_GET["id"]."'",__FILE__,__LINE__);
 			}
 		}
 
@@ -508,45 +508,45 @@ if(api_is_platform_admin())
  *
  * @param id	session id
  * @return string	session data
- * 
+ *
  */
 function show_session_data($id_session) {
 	$session_table = Database::get_main_table(TABLE_MAIN_SESSION);
 	$user_table = Database::get_main_table(TABLE_MAIN_USER);
 	$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
-	
+
 	$sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes, DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility
 				FROM '.$session_table.'
 			LEFT JOIN '.$user_table.'
 				ON id_coach = user_id
 			WHERE '.$session_table.'.id='.$id_session;
-	
-	$rs = api_sql_query($sql, __FILE__, __LINE__);
-	$session = api_store_result($rs);
+
+	$rs = Database::query($sql, __FILE__, __LINE__);
+	$session = Database::store_result($rs);
 	$session = $session[0];
-	
+
 	$sql_category = 'SELECT name FROM '.$session_category_table.' WHERE id = "'.intval($session['session_category_id']).'"';
-	$rs_category = api_sql_query($sql_category, __FILE__, __LINE__);
+	$rs_category = Database::query($sql_category, __FILE__, __LINE__);
 	$session_category = '';
 	if (mysql_num_rows($rs_category) > 0) {
-		$rows_session_category = api_store_result($rs_category);
+		$rows_session_category = Database::store_result($rs_category);
 		$rows_session_category = $rows_session_category[0];
 		$session_category = $rows_session_category['name'];
 	}
-	
+
 	if ($session['date_start'] == '00-00-0000') {
 		$msg_date = get_lang('NoTimeLimits');
 	} else {
 		$msg_date = get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
 	}
-	
+
 	$output  = '';
 	if (!empty($session_category)) {
 		$output .= '<tr><td>'. get_lang('SessionCategory') . ': ' . '<b>' . $session_category .'</b></td></tr>';
 	}
 	$output .= '<tr><td style="width:50%">'. get_lang('SessionName') . ': ' . '<b>' . $session['name'] .'</b></td><td>'. get_lang('GeneralCoach') . ': ' . '<b>' . $session['lastname'].' '.$session['firstname'].' ('.$session['username'].')' .'</b></td></tr>';
 	$output .= '<tr><td>'. get_lang('SessionIdentifier') . ': '. Display::return_icon('star.png', ' ', array('align' => 'absmiddle')) .'</td><td>'. get_lang('Date') . ': ' . '<b>' . $msg_date .'</b></td></tr>';
-	
+
 	return $output;
 }
 
@@ -604,10 +604,10 @@ if(api_is_allowed_to_edit())
 			<?php show_tools_category(TOOL_ADMIN_PLATEFORM); ?>
 		</table>
 	</div>
-	
+
 	<?php
 		} elseif (api_is_coach()) {
-			
+
 			if (api_get_setting('show_session_data') === 'true' && $id_session > 0) {
 	?>
 		<div class="courseadminview">

+ 2 - 2
main/course_home/btf_functions.php

@@ -84,7 +84,7 @@ function showtools2($cat)
 	$result = Database::query($sql, __FILE__, __LINE__);
 
 	// grabbing all the tools from $course_tool_table
-	while ($tempRow = mysql_fetch_array($result))
+	while ($tempRow = Database::fetch_array($result))
 	{
 		/*
 		if ($tempRow['img'] !== "scormbuilder.gif" AND $tempRow['img'] !== "blog.gif")
@@ -118,7 +118,7 @@ function showtools2($cat)
 								WHERE tl.on_homepage='1' AND tip.visibility = 1";
 		}
 		$result_links = Database::query($sql_links);
-		while ($links_row = mysql_fetch_array($result_links))
+		while ($links_row = Database::fetch_array($result_links))
 		{
 			$properties = array ();
 			$properties['name'] = $links_row['title'];

+ 3 - 3
main/course_info/infocours.php

@@ -106,7 +106,7 @@ $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
 
 // Get all course categories
-$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE'  OR code = '".mysql_real_escape_string($_course['categoryCode'])."'  ORDER BY tree_pos";
+$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE'  OR code = '".Database::escape_string($_course['categoryCode'])."'  ORDER BY tree_pos";
 $res = Database::query($sql, __FILE__, __LINE__);
 
 $s_select_course_tutor_name="SELECT tutor_name FROM $tbl_course WHERE code='$course_code'";
@@ -123,7 +123,7 @@ if(mysql_num_rows($q_result_titulars)==0){
 }
 
 $a_profs[0] = '-- '.get_lang('NoManager').' --';
-while ($a_titulars = mysql_fetch_array($q_result_titulars)) {
+while ($a_titulars = Database::fetch_array($q_result_titulars)) {
 	$s_username = $a_titulars['username'];
 	$s_lastname = $a_titulars['lastname'];
 	$s_firstname = $a_titulars['firstname'];
@@ -138,7 +138,7 @@ while ($a_titulars = mysql_fetch_array($q_result_titulars)) {
 	$a_profs[api_get_person_name($s_firstname, $s_lastname)] = api_get_person_name($s_lastname, $s_firstname).' ('.$s_username.')';
 }
 
-while ($cat = mysql_fetch_array($res))
+while ($cat = Database::fetch_array($res))
 {
 	$categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
 	ksort($categories);

+ 1 - 1
main/course_info/postpone.php

@@ -77,7 +77,7 @@ $currentCourseRepository 	= $_course["path"];
 
 $sqlCourseExtention 			= "SELECT last_visit, last_edit, creation_date, expiration_date FROM ".$TABLECOURSE." WHERE code = '".$_cid."'";
 $resultCourseExtention 			= Database::query($sqlCourseExtention,__FILE__,__LINE__);
-$currentCourseExtentionData 	= mysql_fetch_array($resultCourseExtention);
+$currentCourseExtentionData 	= Database::fetch_array($resultCourseExtention);
 $currentCourseLastVisit 		= $currentCourseExtentionData["last_visit"];
 $currentCourseLastEdit			= $currentCourseExtentionData["last_edit"];
 $currentCourseCreationDate 		= $currentCourseExtentionData["creation_date"];

+ 58 - 58
main/coursecopy/classes/CourseBuilder.class.php

@@ -58,24 +58,24 @@ class CourseBuilder
 	 */
 	function build($session_id = 0,$course_code = '')
 	{
-		
+
 		if (!empty($session_id) && !empty($course_code)) {
 			$course_info = api_get_course_info($course_code);
-			$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES,$course_info['dbName']);	
+			$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES,$course_info['dbName']);
 			$table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
-				
+
 			$this->build_documents($session_id,$course_code);
 			$this->build_quizzes($session_id,$course_code);
 			$this->build_glossary($session_id,$course_code);
 			$this->build_learnpaths($session_id,$course_code);
 			$this->build_links($session_id,$course_code);
 			$this->build_course_descriptions($session_id,$course_code);
-			
+
 		} else {
-			
+
 			$table_link = Database :: get_course_table(TABLE_LINKED_RESOURCES);
 			$table_properties = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-			
+
 			$this->build_events();
 			$this->build_announcements();
 			$this->build_links();
@@ -89,7 +89,7 @@ class CourseBuilder
 		}
 
 		//TABLE_LINKED_RESOURCES is the "resource" course table, which is deprecated, apparently
-		
+
 		foreach ($this->course->resources as $type => $resources) {
 			foreach ($resources as $id => $resource) {
 				$sql = "SELECT * FROM ".$table_link." WHERE source_type = '".$resource->get_type()."' AND source_id = '".$resource->get_id()."'";
@@ -99,7 +99,7 @@ class CourseBuilder
 				}
 			}
 		}
-		
+
 		foreach ($this->course->resources as $type => $resources)
 		{
 			foreach ($resources as $id => $resource)
@@ -125,45 +125,45 @@ class CourseBuilder
 	 */
 	function build_documents($session_id = 0,$course_code = '')
 	{
-				
+
 		if (!empty($course_code) && !empty($session_id)) {
 			$course_info = api_get_course_info($course_code);
 			$table_doc = Database :: get_course_table(TABLE_DOCUMENT,$course_info['dbName']);
 			$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
-			
+
 			$session_id = intval($session_id);
-			
-			if (!empty($this->course->type) && $this->course->type=='partial') {        	
+
+			if (!empty($this->course->type) && $this->course->type=='partial') {
         		$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND path NOT LIKE \'/images/gallery%\' AND session_id = '.$session_id.' ORDER BY path';
 			} else {
 	        	$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND session_id = '.$session_id.' ORDER BY path';
-			}						
-			
+			}
+
 			$db_result = Database::query($sql, __FILE__, __LINE__);
 			while ($obj = Database::fetch_object($db_result))
 			{
 				$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
 				$this->course->add_resource($doc);
-			}				
-			
+			}
+
 		} else {
 			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
 			$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-			
-			if (!empty($this->course->type) && $this->course->type=='partial')        	
+
+			if (!empty($this->course->type) && $this->course->type=='partial')
         	$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND path NOT LIKE \'/images/gallery%\' ORDER BY path';
 	        else
 	        	$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 ORDER BY path';
-			
+
 			$db_result = Database::query($sql, __FILE__, __LINE__);
 			while ($obj = Database::fetch_object($db_result))
 			{
 				$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
 				$this->course->add_resource($doc);
 			}
-		}	
-			
-        
+		}
+
+
 	}
 	/**
 	 * Build the forums
@@ -230,29 +230,29 @@ class CourseBuilder
 	 */
 	function build_links($session_id = 0,$course_code = '')
 	{
-		
+
 		if (!empty($session_id) && !empty($course_code)) {
 			$course_info = api_get_course_info($course_code);
 			$table = Database :: get_course_table(TABLE_LINK,$course_info['dbName']);
 			$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY,$course_info['dbName']);
 			$session_id = intval($session_id);
-			$sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2  AND session_id = '$session_id' ORDER BY l.display_order";	
+			$sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2  AND session_id = '$session_id' ORDER BY l.display_order";
 		} else {
 			$table = Database :: get_course_table(TABLE_LINK);
 			$table_prop = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-			$sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2  ORDER BY l.display_order";	
+			$sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2  ORDER BY l.display_order";
 		}
 
-		$db_result = api_sql_query($sql, __FILE__, __LINE__);
+		$db_result = Database::query($sql, __FILE__, __LINE__);
 		while ($obj = Database::fetch_object($db_result))
 		{
 			$link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
 			$this->course->add_resource($link);
-			
+
 			if (!empty($course_code)) {
 				$res = $this->build_link_category($obj->category_id,$course_code);
 			} else {
-				$res = $this->build_link_category($obj->category_id);	
+				$res = $this->build_link_category($obj->category_id);
 			}
 
 			if($res > 0)
@@ -284,7 +284,7 @@ class CourseBuilder
 			$course_info = api_get_course_info($course_code);
 			$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY, $course_info['dbName']);
 		} else {
-			$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);	
+			$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
 		}
 
 		$sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id;
@@ -306,17 +306,17 @@ class CourseBuilder
 			$course_info = api_get_course_info($course_code);
 			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST, $course_info['dbName']);
 			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION, $course_info['dbName']);
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);						
+			$table_doc = Database :: get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
 			$session_id = intval($session_id);
 			$sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0 AND session_id = '.$session_id; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
 		} else {
 			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
 			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
 			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
-			$sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)			
+			$sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
 		}
-		
-		$db_result = api_sql_query($sql, __FILE__, __LINE__);
+
+		$db_result = Database::query($sql, __FILE__, __LINE__);
 		while ($obj = Database::fetch_object($db_result))
 		{
 			if (strlen($obj->sound) > 0)
@@ -333,21 +333,21 @@ class CourseBuilder
 			}
 			$this->course->add_resource($quiz);
 		}
-		
+
 		if (!empty($course_code)) {
 			$this->build_quiz_questions($course_code);
 		} else {
-			$this->build_quiz_questions();	
+			$this->build_quiz_questions();
 		}
-		
-		
+
+
 	}
 	/**
 	 * Build the Quiz-Questions
 	 */
 	function build_quiz_questions($course_code = '')
 	{
-		
+
 		if (!empty($course_code)) {
 			$course_info = api_get_course_info($course_code);
 			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST,$course_info['dbName']);
@@ -358,7 +358,7 @@ class CourseBuilder
 			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
 			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
 			$table_que = Database :: get_course_table(TABLE_QUIZ_QUESTION);
-			$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);	
+			$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
 		}
 
 		// Building normal tests.
@@ -521,7 +521,7 @@ class CourseBuilder
 			$course_info = api_get_course_info($course_code);
 			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION,$course_info['dbName']);
 			$session_id = intval($session_id);
-			$sql = 'SELECT * FROM '.$table. ' WHERE session_id ='.$session_id;	
+			$sql = 'SELECT * FROM '.$table. ' WHERE session_id ='.$session_id;
 		} else {
 			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
 			$sql = 'SELECT * FROM '.$table;
@@ -539,23 +539,23 @@ class CourseBuilder
 	 */
 	function build_learnpaths($session_id = 0,$course_code = '')
 	{
-		
+
 		if (!empty($session_id) && !empty($course_code)) {
 			$course_info 	= api_get_course_info($course_code);
 			$table_main 	= Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']);
 			$table_item 	= Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']);
 			$table_tool 	= Database::get_course_table(TABLE_TOOL_LIST,$course_info['dbName']);
-	
-			$sql = 'SELECT * FROM '.$table_main.' WHERE session_id = '.$session_id;			
+
+			$sql = 'SELECT * FROM '.$table_main.' WHERE session_id = '.$session_id;
 		} else {
 			$table_main 	= Database :: get_course_table(TABLE_LP_MAIN);
 			$table_item 	= Database :: get_course_table(TABLE_LP_ITEM);
 			$table_tool 	= Database::get_course_table(TABLE_TOOL_LIST);
 
-			$sql = 'SELECT * FROM '.$table_main;			
+			$sql = 'SELECT * FROM '.$table_main;
 		}
 
-		$db_result = api_sql_query($sql, __FILE__, __LINE__);
+		$db_result = Database::query($sql, __FILE__, __LINE__);
 
 		while ($obj = Database::fetch_object($db_result))
 		{
@@ -638,33 +638,33 @@ class CourseBuilder
 	 * Build the glossarys
 	 */
 	function build_glossary($session_id = 0, $course_code = '') {
-		
+
 		if (!empty($session_id) && !empty($course_code)) {
 			$course_info = api_get_course_info($course_code);
 			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY,$course_info['dbName']);
-			$session_id = intval($session_id);											
+			$session_id = intval($session_id);
 	        if (!empty($this->course->type) && $this->course->type=='partial') {
 	        	$sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = '.$session_id;
 	        } else {
 	        	$sql = 'SELECT * FROM '.$table_glossary.' g WHERE session_id = '.$session_id;
-	        }		        	        	        
+	        }
 		} else {
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);					
+			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
 	        if (!empty($this->course->type) && $this->course->type=='partial') {
 	        	$sql = 'SELECT * FROM '.$table_glossary.' g ';
 	        } else {
 	        	$sql = 'SELECT * FROM '.$table_glossary.' g ';
-	        }	
+	        }
 		}
-		
-		$db_result = api_sql_query($sql, __FILE__, __LINE__);
+
+		$db_result = Database::query($sql, __FILE__, __LINE__);
 		while ($obj = Database::fetch_object($db_result))
 		{
 			$doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
 			$this->course->add_resource($doc);
 		}
 	}
-	
+
 	/*
 	 * build session course by jhon
 	 * */
@@ -672,19 +672,19 @@ class CourseBuilder
 		$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 		$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
 		$list_course = Database::get_course_list();
-		$list = array(); 
+		$list = array();
 		foreach($list_course as $_course) {
 			$this->course = new Course();
 			$this->course->code = $_course['code'];
 			$this->course->type = 'partial';
 			$this->course->path = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/';
 			$this->course->backup_path = api_get_path(SYS_COURSE_PATH).$_course['directory'];
-			$this->course->encoding = api_get_system_encoding(); //current platform encoding 
+			$this->course->encoding = api_get_system_encoding(); //current platform encoding
 			$code_course = $_course['code'];
-			$sql_session = "SELECT id, name, course_code  FROM $tbl_session_course 
-				INNER JOIN  $tbl_session ON id_session = id 
+			$sql_session = "SELECT id, name, course_code  FROM $tbl_session_course
+				INNER JOIN  $tbl_session ON id_session = id
 				WHERE course_code = '$code_course' ";
-			$query_session = api_sql_query($sql_session, __FILE__, __LINE__);			
+			$query_session = Database::query($sql_session, __FILE__, __LINE__);
 			while($rows_session = mysql_fetch_assoc($query_session)) {
 				$session = new CourseSession($rows_session['id'], $rows_session['name']);
 				$this->course->add_resource($session);

+ 2 - 2
main/coursecopy/classes/CourseRecycler.class.php

@@ -189,7 +189,7 @@ class CourseRecycler
 		$table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY);
 		$sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category WHERE f.forum_id IS NULL";
 		$res = Database::query($sql,__FILE__,__LINE__);
-		while ($obj = mysql_fetch_object($res))
+		while ($obj = Database::fetch_object($res))
 		{
 			$sql = "DELETE FROM ".$table_forumcat." WHERE cat_id = ".$obj->cat_id;
 			Database::query($sql,__FILE__,__LINE__);
@@ -205,7 +205,7 @@ class CourseRecycler
 		$link_table = Database :: get_course_table(TABLE_LINK);
 		$sql = "SELECT lc.id FROM ".$link_cat_table." lc LEFT JOIN ".$link_table." l ON lc.id=l.category_id WHERE l.id IS NULL";
 		$res = Database::query($sql,__FILE__,__LINE__);
-		while ($obj = mysql_fetch_object($res))
+		while ($obj = Database::fetch_object($res))
 		{
 			$sql = "DELETE FROM ".$link_cat_table." WHERE id = ".$obj->id;
 			Database::query($sql,__FILE__,__LINE__);

+ 96 - 96
main/coursecopy/classes/CourseRestorer.class.php

@@ -83,7 +83,7 @@ class CourseRestorer
 	 * which the resources should be stored. Default: Current Dokeos-course.
 	 */
 	function restore($destination_course_code = '',$session_id = 0)
-	{		
+	{
 		if ($destination_course_code == '') {
 			$course_info = api_get_course_info();
 			$this->course->destination_db = $course_info['dbName'];
@@ -94,7 +94,7 @@ class CourseRestorer
 			$this->course->destination_path = $course_info['directory'];
 		}
 		// platform encoding
-		$course_charset = $this->course->encoding; 
+		$course_charset = $this->course->encoding;
 
 		if (!empty($session_id)) {
 			$this->restore_documents($session_id);
@@ -102,7 +102,7 @@ class CourseRestorer
 			$this->restore_glossary($session_id);
 			$this->restore_learnpaths($session_id);
 			$this->restore_links($session_id);
-			$this->restore_course_descriptions($session_id);	
+			$this->restore_course_descriptions($session_id);
 		} else {
 			$this->restore_links();
 			$this->restore_tool_intro();
@@ -110,24 +110,24 @@ class CourseRestorer
 			$this->restore_announcements();
 			$this->restore_documents();
 			$this->restore_scorm_documents();
-			$this->restore_course_descriptions();			
+			$this->restore_course_descriptions();
 			$this->restore_quizzes(); // after restore_documents! (for correct import of sound/video)
 			$this->restore_learnpaths();
 			$this->restore_surveys();
 			$this->restore_student_publication();
-			$this->restore_glossary();		
+			$this->restore_glossary();
 		}
 
-		
+
 		// Restore the item properties
 		$table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db);
-		
+
 		$condition_session = "";
-		
+
 		if (!empty($session_id)) {
 			$condition_session = " , id_session='".intval($session_id)."'";
 		}
-		
+
 		foreach ($this->course->resources as $type => $resources) {
 			if (is_array($resources)) {
 				foreach ($resources as $id => $resource) {
@@ -183,8 +183,8 @@ class CourseRestorer
 	 * Restore documents
 	 */
 	function restore_documents($session_id = 0)
-	{		
-		if ($this->course->has_resources(RESOURCE_DOCUMENT)) {			
+	{
+		if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
 			$table = Database :: get_course_table(TABLE_DOCUMENT, $this->course->destination_db);
 			$resources = $this->course->resources;
 			$destination_course['dbName']= $this->course->destination_db;
@@ -263,76 +263,76 @@ class CourseRestorer
 									$new_file_name = $file_name_no_ext.'_'.$i.$ext;
 									$file_exists = file_exists($path.$new_file_name);
 								}
-								
-			
+
+
 								if (!empty($session_id)) {
-			
+
 									$document_path = explode('/',$document->path,3);
 									$course_path = $path;								// "/var/www/wiener/courses/"
 									$orig_base_folder = $document_path[1];
 									$orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
-			
+
 									if (is_dir($orig_base_path)) {
-																															
+
 										$new_base_foldername = $orig_base_folder;	// e.g: "carpeta1"
 										$new_base_path   = $orig_base_path;			// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1"
-											  	  
+
 										if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
 											unset($_SESSION['new_base_foldername']);
 											unset($_SESSION['orig_base_foldername']);
-											unset($_SESSION['new_base_path']);																																
-										}																			
-										
+											unset($_SESSION['new_base_path']);
+										}
+
 										$folder_exists = file_exists($new_base_path);
 										if ($folder_exists) {
 											$_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
 											$x = '';
-											while ($folder_exists) {												
+											while ($folder_exists) {
 												$x = $x + 1;
-												$new_base_foldername = $document_path[1].'_'.$x;     
+												$new_base_foldername = $document_path[1].'_'.$x;
 												$new_base_path = $orig_base_path.'_'.$x;
 												if ($_SESSION['new_base_foldername'] == $new_base_foldername) break;
 												$folder_exists = file_exists($new_base_path);
-											}																																	
+											}
 											$_SESSION['new_base_foldername'] = $new_base_foldername;
-											$_SESSION['new_base_path'] = $new_base_path;																																															
-										} 																																				
+											$_SESSION['new_base_path'] = $new_base_path;
+										}
 
-										if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {																						
+										if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
 											$new_base_foldername = $_SESSION['new_base_foldername'];
-											$new_base_path = $_SESSION['new_base_path'];																						
+											$new_base_path = $_SESSION['new_base_path'];
 										}
-																												
-										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png" 
+
+										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
 										$basedir_dest_path = dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
-										$dest_filename = basename($dest_document_path);  				// e.g: "collaborative.png" 
-										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document" 
+										$dest_filename = basename($dest_document_path);  				// e.g: "collaborative.png"
+										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
 										$course_info = api_get_course_info($this->course->destination_path);
 										$path_title = '/'.$new_base_foldername.'/'.$document_path[2];
-						
+
 										copy_folder_course_session($basedir_dest_path, $base_path_document,$session_id,$course_info, $document);
-			
+
 										copy($course_path.$document->path, $dest_document_path);
 										$sql = "INSERT INTO $table SET path = '$path_title', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string(basename($path_title))."' ,filetype='".$document->file_type."', size= '".$document->size."', session_id = '$session_id'";
-										
+
 										Database::query($sql, __FILE__, __LINE__);
-										$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::get_last_insert_id();			  
-										
-										} else {																						
+										$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
+
+										} else {
 											copy($path.$document->path, $path.$new_file_name);
 											$sql = "INSERT INTO ".$table." SET path = '/".Database::escape_string(substr($new_file_name, 9))."', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."', session_id = '$session_id'";
 											Database::query($sql, __FILE__, __LINE__);
-											$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::get_last_insert_id();
-										}	  
-			
-									} else {									
+											$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
+										}
+
+									} else {
 										copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
 										$sql = "INSERT INTO ".$table." SET path = '/".Database::escape_string(substr($new_file_name, 9))."', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."'";
-										api_sql_query($sql, __FILE__, __LINE__);
-										$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::get_last_insert_id();
-									}			
+										Database::query($sql, __FILE__, __LINE__);
+										$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
+									}
 									break;
-									
+
 						} // end switch
 					} // end if file exists
 					else
@@ -344,7 +344,7 @@ class CourseRestorer
 							copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
 							$sql = "INSERT INTO ".$table." SET path = '/".substr($document->path, 9)."', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."'";
 							Database::query($sql, __FILE__, __LINE__);
-							$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::get_last_insert_id();
+							$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
 						}
 						else
 						{
@@ -376,14 +376,14 @@ class CourseRestorer
 					{
 						$sql = "INSERT INTO ".$table." SET path = '/".Database::escape_string(substr($document->path, 9))."', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string($document->title)."' ,filetype='".$document->file_type."', size= '".$document->size."'";
 						Database::query($sql, __FILE__, __LINE__);
-						$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::get_last_insert_id();
+						$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
 					}*/
 				} // end folder
 			} // end for each
 		// Delete sessions for the copy the new folder in session
 		unset($_SESSION['new_base_foldername']);
 		unset($_SESSION['orig_base_foldername']);
-		unset($_SESSION['new_base_path']);		
+		unset($_SESSION['new_base_path']);
 		}
 	}
 
@@ -495,7 +495,7 @@ class CourseRestorer
 					", session_id = ".(int)Database::escape_string($forum->session_id).
 					", forum_image = '".Database::escape_string($forum->image)."'";
 				Database::query($sql, __FILE__, __LINE__);
-				$new_id = Database::get_last_insert_id();
+				$new_id = Database::insert_id();
 				$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
 				$forum_topics = 0;
 				if (is_array($this->course->resources[RESOURCE_FORUMTOPIC]))
@@ -543,7 +543,7 @@ class CourseRestorer
 				", locked = ".(int)Database::escape_string($forum_cat->locked).
 				", session_id = ".(int)Database::escape_string($forum_cat->session_id);
 			Database::query($sql, __FILE__, __LINE__);
-			$new_id = Database::get_last_insert_id();
+			$new_id = Database::insert_id();
 			$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
 			return $new_id;
 		}
@@ -571,7 +571,7 @@ class CourseRestorer
 			", thread_title_qualify = '".Database::escape_string($topic->title_qualify).
 			"', thread_qualify_max = ".(float)Database::escape_string($topic->qualify_max);
 		Database::query($sql, __FILE__, __LINE__);
-		$new_id = Database::get_last_insert_id();
+		$new_id = Database::insert_id();
 		$this->course->resources[RESOURCE_FORUMTOPIC][$id]->destination_id = $new_id;
 		$topic_replies = -1;
 		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post)
@@ -616,7 +616,7 @@ class CourseRestorer
 			", post_parent_id = ".(int)Database::escape_string($post->parent_post_id).
 			", visible = ".(int)Database::escape_string($post->visible);
 		Database::query($sql, __FILE__, __LINE__);
-		$new_id = Database::get_last_insert_id();
+		$new_id = Database::insert_id();
 		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
 		return $new_id;
 	}
@@ -635,16 +635,16 @@ class CourseRestorer
 				$sql = "SELECT MAX(display_order) FROM  $link_table WHERE category_id='" . Database::escape_string($cat_id). "'";
 				$result = Database::query($sql, __FILE__, __LINE__);
     			list($max_order) = Database::fetch_array($result);
-    			
-    			$condition_session = "";    			
+
+    			$condition_session = "";
     			if (!empty($session_id)) {
-    				$condition_session = " , session_id = '$session_id' ";	
+    				$condition_session = " , session_id = '$session_id' ";
     			}
-    			
+
 				$sql = "INSERT INTO ".$link_table." SET url = '".Database::escape_string($link->url)."', title = '".Database::escape_string($link->title)."', description = '".Database::escape_string($link->description)."', category_id='".$cat_id."', on_homepage = '".$link->on_homepage."', display_order='".($max_order+1)."' $condition_session";
-				
+
 				Database::query($sql, __FILE__, __LINE__);
-				$this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::get_last_insert_id();
+				$this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id();
 			}
 		}
 	}
@@ -665,7 +665,7 @@ class CourseRestorer
 				$sql = "INSERT INTO ".$tool_intro_table." SET id='".Database::escape_string($tool_intro->id)."', intro_text = '".Database::escape_string($tool_intro->intro_text)."'";
 				Database::query($sql, __FILE__, __LINE__);
 
-				$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::get_last_insert_id();
+				$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::insert_id();
 			}
 		}
 	}
@@ -674,12 +674,12 @@ class CourseRestorer
 	 */
 	function restore_link_category($id,$session_id = 0)
 	{
-		
-		$condition_session = "";    			
+
+		$condition_session = "";
 		if (!empty($session_id)) {
-			$condition_session = " , session_id = '$session_id' ";	
+			$condition_session = " , session_id = '$session_id' ";
 		}
-		
+
 		if ($id == 0)
 			return 0;
 		$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY, $this->course->destination_db);
@@ -693,7 +693,7 @@ class CourseRestorer
 			$display_order=$orderMax+1;
 			$sql = "INSERT INTO ".$link_cat_table." SET category_title = '".Database::escape_string($link_cat->title)."', description='".Database::escape_string($link_cat->description)."', display_order='".$display_order."' $condition_session ";
 			Database::query($sql, __FILE__, __LINE__);
-			$new_id = Database::get_last_insert_id();
+			$new_id = Database::insert_id();
 			$this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id;
 			return $new_id;
 		}
@@ -712,7 +712,7 @@ class CourseRestorer
 			{
 				$sql = "INSERT INTO ".$table." SET title = '".Database::escape_string($event->title)."', content = '".Database::escape_string($event->content)."', start_date = '".$event->start_date."', end_date = '".$event->end_date."'";
 				Database::query($sql, __FILE__, __LINE__);
-				$this->course->resources[RESOURCE_EVENT][$id]->destination_id = Database::get_last_insert_id();
+				$this->course->resources[RESOURCE_EVENT][$id]->destination_id = Database::insert_id();
 			}
 		}
 	}
@@ -748,7 +748,7 @@ class CourseRestorer
 
 				$sql = "INSERT INTO ".$table." SET title = '".Database::escape_string($cd->title)."', content = '".Database::escape_string($description_content)."' $condition_session";
 				Database::query($sql, __FILE__, __LINE__);
-				$this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = Database::get_last_insert_id();
+				$this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = Database::insert_id();
 			}
 		}
 	}
@@ -770,7 +770,7 @@ class CourseRestorer
 							"display_order = '".$announcement->display_order."', " .
 							"email_sent = '".$announcement->email_sent."'";
 				Database::query($sql, __FILE__, __LINE__);
-				$this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = Database::get_last_insert_id();
+				$this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = Database::insert_id();
 			}
 		}
 	}
@@ -800,13 +800,13 @@ class CourseRestorer
 				}
 				if ($id != -1)
 				{
-				
-					$condition_session = "";    			
+
+					$condition_session = "";
     				if (!empty($session_id)) {
     					$session_id = intval($session_id);
-    					$condition_session = " , session_id = '$session_id' ";	
+    					$condition_session = " , session_id = '$session_id' ";
     				}
-    			
+
 					// Normal tests are stored in the database.
 					$sql = "INSERT INTO ".$table_qui.
 						" SET title = '".Database::escape_string($quiz->title).
@@ -823,7 +823,7 @@ class CourseRestorer
 						"', feedback_type = ".(int)$quiz->feedback_type.
 						$condition_session;
 					Database::query($sql, __FILE__, __LINE__);
-					$new_id = Database::get_last_insert_id();
+					$new_id = Database::insert_id();
 				}
 				else
 				{
@@ -860,7 +860,7 @@ class CourseRestorer
 			$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course->destination_db);
 			$sql = "INSERT INTO ".$table_que." SET question = '".addslashes($question->question)."', description = '".addslashes($question->description)."', ponderation = '".addslashes($question->ponderation)."', position = '".addslashes($question->position)."', type='".addslashes($question->quiz_type)."', picture='".addslashes($question->picture)."', level='".addslashes($question->level)."'";
 			Database::query($sql, __FILE__, __LINE__);
-			$new_id = Database::get_last_insert_id();
+			$new_id = Database::insert_id();
 			foreach ($question->answers as $index => $answer)
 			{
 				$sql = "INSERT INTO ".$table_ans." SET id= '". ($index +1)."',question_id = '".$new_id."', answer = '".Database::escape_string($answer['answer'])."', correct = '".$answer['correct']."', comment = '".Database::escape_string($answer['comment'])."', ponderation='".$answer['ponderation']."', position = '".$answer['position']."', hotspot_coordinates = '".$answer['hotspot_coordinates']."', hotspot_type = '".$answer['hotspot_type']."'";
@@ -953,7 +953,7 @@ class CourseRestorer
 							//Insert the new source survey
 							Database::query($sql, __FILE__, __LINE__);
 
-							$new_id = Database::get_last_insert_id();
+							$new_id = Database::insert_id();
 							$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
 							foreach ($survey->question_ids as $index => $question_id)
 							{
@@ -991,7 +991,7 @@ class CourseRestorer
 							//Insert the new source survey
 							Database::query($sql, __FILE__, __LINE__);
 
-							$new_id = Database::get_last_insert_id();
+							$new_id = Database::insert_id();
 							$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
 							foreach ($survey->question_ids as $index => $question_id)
 							{
@@ -1018,7 +1018,7 @@ class CourseRestorer
 				else
 				{
 					Database::query($sql, __FILE__, __LINE__);
-					$new_id = Database::get_last_insert_id();
+					$new_id = Database::insert_id();
 					$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
 					foreach ($survey->question_ids as $index => $question_id)
 					{
@@ -1080,7 +1080,7 @@ class CourseRestorer
 					"max_value = 			'".Database::escape_string($question->max_value)."' ";
 			Database::query($sql, __FILE__, __LINE__);
 
-			$new_id = Database::get_last_insert_id();
+			$new_id = Database::insert_id();
 			foreach ($question->answers as $index => $answer) {
 				$sql = "INSERT INTO ".$table_ans." " .
 						"SET " .
@@ -1109,13 +1109,13 @@ class CourseRestorer
 			$resources = $this->course->resources;
 
 			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
-				
+
 				$condition_session = "";
 				if (!empty($session_id)) {
 					$session_id = intval($session_id);
 					$condition_session = " , session_id = '$session_id' ";
-				} 
-				
+				}
+
 				$sql = "INSERT INTO ".$table_main." " .
 						"SET lp_type = '".$lp->lp_type."', " .
 								"name = '".Database::escape_string($lp->name)."', " .
@@ -1134,7 +1134,7 @@ class CourseRestorer
 								"debug= '".Database::escape_string($lp->debug)."' $condition_session ";
 				Database::query($sql, __FILE__, __LINE__);
 
-				$new_lp_id = Database::get_last_insert_id();
+				$new_lp_id = Database::insert_id();
 
 				if($lp->visibility) {
 					$sql = "INSERT INTO $table_tool SET name='".Database::escape_string($lp->name)."', link='newscorm/lp_controller.php?action=view&lp_id=$new_lp_id', image='scormbuilder.gif', visibility='1', admin='0', address='squaregrey.gif'";
@@ -1175,12 +1175,12 @@ class CourseRestorer
 					$path = Database::escape_string($item['path']);
 					if(strval(intval($path)) === $path) {
 						if (!empty($session_id)) {
-							$path = intval($path);	
+							$path = intval($path);
 						} else {
-							$path = $this->get_new_id($item['item_type'],$path);	
-						}						
-					}										
-					
+							$path = $this->get_new_id($item['item_type'],$path);
+						}
+					}
+
 					$sql = "INSERT INTO ".$table_item." SET " .
 							"lp_id = '".Database::escape_string($new_lp_id)."', " .
 							"item_type='".Database::escape_string($item['item_type'])."', " .
@@ -1200,7 +1200,7 @@ class CourseRestorer
 							"launch_data = '".Database::escape_string($item['launch_dataprereq_type'])."'";
 
 					Database::query($sql, __FILE__, __LINE__);
-					$new_item_id = Database::get_last_insert_id();
+					$new_item_id = Database::insert_id();
 					//save a link between old and new item IDs
 					$new_item_ids[$item['id']] = $new_item_id;
 					//save a reference of items that need a parent_item_id refresh
@@ -1408,19 +1408,19 @@ class CourseRestorer
 			$t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY, $this->course->destination_db);
 			$resources = $this->course->resources;
 			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
-				
-				$condition_session = "";    			
+
+				$condition_session = "";
     			if (!empty($session_id)) {
     				$session_id = intval($session_id);
-    				$condition_session = " , session_id = '$session_id' ";	
+    				$condition_session = " , session_id = '$session_id' ";
     			}
-				
+
 				$sql = "INSERT INTO ".$table_glossary." SET  name = '".Database::escape_string($glossary->name)."', description = '".Database::escape_string($glossary->description)."', display_order='".Database::escape_string($glossary->display_order)."' $condition_session ";
 				Database::query($sql, __FILE__, __LINE__);
-				$this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = Database::get_last_insert_id();
-				 															    			 	
-			}						
-		}				
-	}	
+				$this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = Database::insert_id();
+
+			}
+		}
+	}
 }
 ?>

+ 1 - 1
main/coursecopy/copy_course.php

@@ -110,7 +110,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
 	<?php
 	echo get_lang('SelectDestinationCourse');
 	echo ' <select name="destination_course"/>';
-	while ($obj = mysql_fetch_object($res)) {
+	while ($obj = Database::fetch_object($res)) {
 		echo '<option value="'.$obj->code.'">'.$obj->title.'</option>';
 	}
 	echo '</select>';

+ 135 - 135
main/coursecopy/copy_course_session.php

@@ -4,15 +4,15 @@
 /**
  * ==============================================================================
  * Copy resources from one course in a session to another one.
- * 
+ *
  * @author Christian Fasanando <christian.fasanando@dokeos.com>
  * @package dokeos.backup
  * ==============================================================================
  */
- 
+
 /*  INIT SECTION  */
- 
-// name of the language file that needs to be included 
+
+// name of the language file that needs to be included
 $language_file = array('coursebackup','admin');
 $cidReset = true;
 require_once '../inc/global.inc.php';
@@ -56,201 +56,201 @@ $tbl_course							= Database::get_main_table(TABLE_MAIN_COURSE);
 /* FUNCTIONS */
 
 function make_select_session_list($name,$sessions,$attr = array()) {
-	
+
 	$attrs = '';
-	if (count($attr) > 0) {		
+	if (count($attr) > 0) {
 		foreach ($attr as $key => $value) {
-			$attrs .= ' '.$key.'='.$value. ' ';		
-		}		
+			$attrs .= ' '.$key.'='.$value. ' ';
+		}
 	}
-	
-	$output = '<select name="'.$name.'" '.$attrs.'>';	
-	if (count($sessions) == 0) { 
-		$output .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option>';		
+
+	$output = '<select name="'.$name.'" '.$attrs.'>';
+	if (count($sessions) == 0) {
+		$output .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option>';
 	} else {
-		$output .= '<option value = "0">'.get_lang('SelectASession').'</option>';	
+		$output .= '<option value = "0">'.get_lang('SelectASession').'</option>';
 	}
-	
+
 	if (is_array($sessions)) {
 		foreach ($sessions as $session) {
-			$output .= '<option value="'.$session['id'].'">'.$session['name'].' ('.$session['category_name'].')</option>';		
+			$output .= '<option value="'.$session['id'].'">'.$session['name'].' ('.$session['category_name'].')</option>';
 		}
-	}	
+	}
 	$output .= '</select>';
  	return $output;
 }
 
 function display_form() {
-	
+
 	global $charset;
-	
+
 	$html  = '';
-	$sessions = SessionManager::get_sessions_list();		
-	
+	$sessions = SessionManager::get_sessions_list();
+
 	$html .= '<form name="formulaire" method="post" action="'.api_get_self().'" >';
-	
+
 	$html .= '<table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">';
-	
+
 	$html .= '<tr><td width="30%" align="center"><b>'.get_lang('OriginCoursesFromSession').':</b></td>';
 	$html .= '<td >&nbsp;</td><td align="center" width="30%"><b>'.get_lang('DestinationCoursesFromSession').':</b></td></tr>';
 	$html .= '<tr><td width="30%" align="center">'.make_select_session_list('sessions_list_origin',$sessions,array('onchange'=>'xajax_search_courses(this.value,\'origin\')')).'</td>';
 	$html .= '<td>&nbsp;</td><td width="30%" align="center"><div id="ajax_sessions_list_destination">';
 	$html .= '<select name="sessions_list_destination" onchange = "xajax_search_courses(this.value,\'destination\')">';
-	$html .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option></select ></div></td></tr>';		
-		
+	$html .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option></select ></div></td></tr>';
+
 	$html .= '<tr><td width="30%" align="center"><div id="ajax_list_courses_origin">';
 	$html .= '<select id="origin" name="SessionCoursesListOrigin[]" multiple="multiple" size="20" style="width:320px;"></select></div></td>';
-	
-	// Options configuration	
-	$html .= '<td align="top"><div class="sectiontitle">'.get_lang('CopyCourse').'</div>';		
+
+	// Options configuration
+	$html .= '<td align="top"><div class="sectiontitle">'.get_lang('CopyCourse').'</div>';
 	$introduction = get_lang('CopyCourseFromSessionToSessionExplanation',true);
-	$html .= '<div class="normal-message">'.$introduction.'</div>';		  
+	$html .= '<div class="normal-message">'.$introduction.'</div>';
 	$html .= '<div style="height:150px;padding-top:10px;padding-bottom:50px"><h3>'.get_lang('TypeOfCopy').'</h3>';
 	$html .= '<input type="radio" class="checkbox" id="copy_option_1" name="copy_option" value="full_copy" checked="checked"/>';
-	$html .= '<label for="copy_option_1">'.get_lang('FullCopy').'</label><br/>';		  
+	$html .= '<label for="copy_option_1">'.get_lang('FullCopy').'</label><br/>';
 	$html .= '<input type="radio" class="checkbox" id="copy_option_2" name="copy_option" value="select_items" disabled="disabled"/>';
 	$html .= '<label for="copy_option_2"><span id="title_option2" style="color:#aaa">'.get_lang('LetMeSelectItems').'</span></label><br/><br/>';
 	$html .= '<button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.get_lang('CopyCourse').'</button></div>';
-		  
+
 	// actions
 	$html .= '<div class="sectiontitle">';
 	// link back to the documents overview
 	$html .= '<a href="../admin/index.php">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('PlatformAdmin'),array('style'=>'vertical-align:middle')).get_lang('Back').' '.get_lang('To').' '.get_lang('PlatformAdmin').'</a>';
 	$html .= '</div>';
-  
-  
+
+
 	$html .= '</td><td width="30%" align="center">';
 	$html .= '<div id="ajax_list_courses_destination">';
 	$html .= '<select id="destination" name="SessionCoursesListDestination[]" multiple="multiple" size="20" style="width:320px;" ></select></div></td>';
-	$html .= '</tr></table></form>';  
-	  
+	$html .= '</tr></table></form>';
+
 	echo $html;
 }
 
 function search_courses($id_session,$type) {
 	global $tbl_course, $tbl_session_rel_course, $course_list;
-	
+
 	$xajax_response = new XajaxResponse();
 	$return_origin = '';
 	$select_destination = '';
 	if (!empty($type)) {
-		
+
 		$id_session = intval($id_session);
 
 		if ($type == 'origin') {
-			
+
 			// search courses by id_session for origin list
 			$sql = "SELECT c.code, c.visual_code, c.title, src.id_session
 					FROM $tbl_course c, $tbl_session_rel_course src
 					WHERE src.course_code = c.code
-					AND src.id_session = '".intval($id_session)."'";										
-			$rs = api_sql_query($sql, __FILE__, __LINE__);
-			
+					AND src.id_session = '".intval($id_session)."'";
+			$rs = Database::query($sql, __FILE__, __LINE__);
+
 			$course_list = array();
-								
+
 			$return .= '<select id="origin" name="SessionCoursesListOrigin[]" multiple="multiple" size="20" style="width:320px;" onclick="checkSelected(this.id,\'copy_option_2\',\'title_option2\',\'destination\')">';
-			while($course = Database :: fetch_array($rs)) {	
+			while($course = Database :: fetch_array($rs)) {
 				$course_list[] = "'{$course['code']}'";
-				$course_title=str_replace("'","\'",$course_title);								
+				$course_title=str_replace("'","\'",$course_title);
 
 				$return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
-											
+
 			}
-			
+
 			$return .= '</select>';
 			$_SESSION['course_list'] = $course_list;
 			$_SESSION['session_origin'] = $id_session;
-			
+
 			// Build select for destination sessions where is not included current session from select origin
-			if (!empty($id_session)) {			
+			if (!empty($id_session)) {
 				$session_table =Database::get_main_table(TABLE_MAIN_SESSION);
 				$session_category_table = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
-						
+
 				$sql = " 	SELECT s.id, s.name, sc.name as category_name
 							FROM $session_table s , $session_category_table sc
 							WHERE s.session_category_id = sc.id AND s.id NOT IN('$id_session')";
-				
-				$rs_select_destination = api_sql_query($sql, __FILE__, __LINE__);		
-				
-				$select_destination .= '<select name="sessions_list_destination" onchange = "xajax_search_courses(this.value,\'destination\')">';			
+
+				$rs_select_destination = Database::query($sql, __FILE__, __LINE__);
+
+				$select_destination .= '<select name="sessions_list_destination" onchange = "xajax_search_courses(this.value,\'destination\')">';
 				$select_destination .= '<option value = "0">'.get_lang('SelectASession').'</option>';
-				while($session = Database :: fetch_array($rs_select_destination)) {					
-									
-					$select_destination .= '<option value="'.$session['id'].'">'.$session['name'].' ('.$session['category_name'].')</option>';				
+				while($session = Database :: fetch_array($rs_select_destination)) {
+
+					$select_destination .= '<option value="'.$session['id'].'">'.$session['name'].' ('.$session['category_name'].')</option>';
 				}
 				$select_destination .= '</select>';
 				$xajax_response -> addAssign('ajax_sessions_list_destination','innerHTML',api_utf8_encode($select_destination));
 			} else{
-				$select_destination .= '<select name="sessions_list_destination" onchange = "xajax_search_courses(this.value,\'destination\')">';			
+				$select_destination .= '<select name="sessions_list_destination" onchange = "xajax_search_courses(this.value,\'destination\')">';
 				$select_destination .= '<option value = "0">'.get_lang('ThereIsNotStillASession').'</option>';
 				$select_destination .= '</select>';
 				$xajax_response -> addAssign('ajax_sessions_list_destination','innerHTML',api_utf8_encode($select_destination));
 			}
-			
+
 			// select multiple destination empty
 			$select_multiple_empty = '<select id="destination" name="SessionCoursesListDestination[]" multiple="multiple" size="20" style="width:320px;"></select>';
-			
+
 			// send response by ajax
-			$xajax_response -> addAssign('ajax_list_courses_origin','innerHTML',api_utf8_encode($return));			
+			$xajax_response -> addAssign('ajax_list_courses_origin','innerHTML',api_utf8_encode($return));
 			$xajax_response -> addAssign('ajax_list_courses_destination','innerHTML',api_utf8_encode($select_multiple_empty));
-		
+
 		} else {
-			
+
 			$list_courses_origin = implode(',',$_SESSION['course_list']);
 			$session_origin = $_SESSION['session_origin'];
-			
+
 			// search courses by id_session where course codes is include en courses list destination
 			$sql = "SELECT c.code, c.visual_code, c.title, src.id_session
 					FROM $tbl_course c, $tbl_session_rel_course src
 					WHERE src.course_code = c.code
 					AND src.id_session = '".intval($id_session)."'
-					AND c.code IN ($list_courses_origin)";										
-			$rs = api_sql_query($sql, __FILE__, __LINE__);
-			
+					AND c.code IN ($list_courses_origin)";
+			$rs = Database::query($sql, __FILE__, __LINE__);
+
 			$course_list_destination = array();
 			$return .= '<select id="destination" name="SessionCoursesListDestination[]" multiple="multiple" size="20" style="width:320px;" onmouseover="this.disabled=true;" onmouseout="this.disabled=false;">';
-			while($course = Database :: fetch_array($rs)) {	
+			while($course = Database :: fetch_array($rs)) {
 				$course_list_destination[] = $course['code'];
-				$course_title=str_replace("'","\'",$course_title);				
-				$return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';				
+				$course_title=str_replace("'","\'",$course_title);
+				$return .= '<option value="'.$course['code'].'" title="'.htmlspecialchars($course['title'].' ('.$course['visual_code'].')',ENT_QUOTES).'">'.$course['title'].' ('.$course['visual_code'].')</option>';
 			}
 			$return .= '</select>';
 			$_SESSION['course_list_destination'] = $course_list_destination;
 
 			// send response by ajax
 			$xajax_response -> addAssign('ajax_list_courses_destination','innerHTML',api_utf8_encode($return));
-			
-			// disable option from session courses list origin where if no the same con the destination			
+
+			// disable option from session courses list origin where if no the same con the destination
 			$sql = "SELECT c.code, c.visual_code, c.title, src.id_session
 					FROM $tbl_course c, $tbl_session_rel_course src
 					WHERE src.course_code = c.code
-					AND src.id_session = '".intval($session_origin)."'";										
-			$result = api_sql_query($sql, __FILE__, __LINE__);						
-								
+					AND src.id_session = '".intval($session_origin)."'";
+			$result = Database::query($sql, __FILE__, __LINE__);
+
 			$return_option_disabled = '<select id="origin" name="SessionCoursesListOrigin[]" multiple="multiple" size="20" style="width:320px;" onclick="checkSelected(this.id,\'copy_option_2\',\'title_option2\',\'destination\')">';
-			while($cours = Database :: fetch_array($result)) {									
-				$course_title=str_replace("'","\'",$course_title);												
+			while($cours = Database :: fetch_array($result)) {
+				$course_title=str_replace("'","\'",$course_title);
 				if (count($course_list_destination) > 0) {
-					if (!in_array($cours['code'],$course_list_destination)) {																				
+					if (!in_array($cours['code'],$course_list_destination)) {
 						$return_option_disabled .= '<optgroup style="color:#ccc" label="'.$cours['title'].' ('.$cours['visual_code'].')" >'.$cours['title'].' ('.$cours['visual_code'].')</optgroup>';
 					} else {
 						$return_option_disabled .= '<option value="'.$cours['code'].'" title="'.htmlspecialchars($cours['title'].' ('.$cours['visual_code'].')',ENT_QUOTES).'">'.$cours['title'].' ('.$cours['visual_code'].')</option>';
-					}																											
+					}
 				} else {
-					if (empty($id_session)) {					
+					if (empty($id_session)) {
 						$return_option_disabled .= '<option value="'.$cours['code'].'" title="'.htmlspecialchars($cours['title'].' ('.$cours['visual_code'].')',ENT_QUOTES).'">'.$cours['title'].' ('.$cours['visual_code'].')</option>';
-					} else {						
+					} else {
 						$return_option_disabled .= '<optgroup style="color:#ccc" label="'.$cours['title'].'('.$cours['visual_code'].')" >'.$cours['title'].' ('.$cours['visual_code'].')</optgroup>';
 					}
-					
-				}										
-			}						
+
+				}
+			}
 			$return_option_disabled .= '</select>';
 			// send response by ajax
-			$xajax_response -> addAssign('ajax_list_courses_origin','innerHTML',api_utf8_encode($return_option_disabled));			
+			$xajax_response -> addAssign('ajax_list_courses_origin','innerHTML',api_utf8_encode($return_option_disabled));
 		}
 
-	}			
+	}
 	return $xajax_response;
 }
 $xajax -> processRequests();
@@ -258,34 +258,34 @@ $xajax -> processRequests();
 /* HTML head extra */
 
 $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
-$htmlHeadXtra[] = '<script language="javascript">							
-				
+$htmlHeadXtra[] = '<script language="javascript">
+
 						function checkSelected(id_select,id_radio,id_title,id_destination) {
 						   var num=0;
 						   obj_origin = document.getElementById(id_select);
-						   obj_destination = document.getElementById(id_destination);		
-							
+						   obj_destination = document.getElementById(id_destination);
+
 						   for (x=0;x<obj_origin.options.length;x++) {
-						      if (obj_origin.options[x].selected) {						      		
-						      		if (obj_destination.options.length > 0) {										
-										for (y=0;y<obj_destination.options.length;y++) {													
+						      if (obj_origin.options[x].selected) {
+						      		if (obj_destination.options.length > 0) {
+										for (y=0;y<obj_destination.options.length;y++) {
 												if (obj_origin.options[x].value == obj_destination.options[y].value) {
-													obj_destination.options[y].selected = true;	
-												} 															
-									   	}	
+													obj_destination.options[y].selected = true;
+												}
+									   	}
 									}
 						      		num++;
 						      	} else {
-						      		if (obj_destination.options.length > 0) {										
-										for (y=0;y<obj_destination.options.length;y++) {													
+						      		if (obj_destination.options.length > 0) {
+										for (y=0;y<obj_destination.options.length;y++) {
 												if (obj_origin.options[x].value == obj_destination.options[y].value) {
-													obj_destination.options[y].selected = false;	
-												} 												
-									   		}	
-									}		
-						      	}						      	
+													obj_destination.options[y].selected = false;
+												}
+									   		}
+									}
+						      	}
 						   }
-						
+
 						   if (num == 1) {
 						      document.getElementById(id_radio).disabled = false;
 						      document.getElementById(id_title).style.color = \'#000\';
@@ -303,108 +303,108 @@ Display::display_header($nameTools);
 
 /*  MAIN CODE  */
 
-if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')) {		
+if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'full_copy')) {
 
 	$destination_course = $origin_course = $destination_session = $origin_session = '';
-		 
+
 	if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
-		
+
 		$destination_course	 	= $_POST['destination_course'];
 		$origin_course 			= $_POST['origin_course'];
 		$destination_session 	= $_POST['destination_session'];
 		$origin_session 		= $_POST['origin_session'];
-								
+
 		$course = CourseSelectForm :: get_posted_course('copy_course',$origin_session,$origin_course);
 		$cr = new CourseRestorer($course);
 		//$cr->set_file_option($_POST['same_file_name_option']);
 		$cr->restore($destination_course,$destination_session);
 		Display::display_normal_message(get_lang('CopyFinished'));
-		display_form();		
+		display_form();
 	} else {
 
 		$arr_course_origin 		= array();
 		$arr_course_destination = array();
 		$destination_session 	= '';
 		$origin_session 		= '';
-		
-		if (isset($_POST['SessionCoursesListOrigin'])) {					
+
+		if (isset($_POST['SessionCoursesListOrigin'])) {
 			$arr_course_origin 		= $_POST['SessionCoursesListOrigin'];
 		}
-		if (isset($_POST['SessionCoursesListDestination'])) {					
+		if (isset($_POST['SessionCoursesListDestination'])) {
 			$arr_course_destination = $_POST['SessionCoursesListDestination'];
 		}
-		if (isset($_POST['sessions_list_destination'])) {					
+		if (isset($_POST['sessions_list_destination'])) {
 			$destination_session 	= $_POST['sessions_list_destination'];
 		}
-		if (isset($_POST['sessions_list_origin'])) {					
+		if (isset($_POST['sessions_list_origin'])) {
 			$origin_session 		= $_POST['sessions_list_origin'];
 		}
-				
+
 		if ((is_array($arr_course_origin) && count($arr_course_origin) > 0)  && !empty($destination_session)) {
-			
+
 			foreach ($arr_course_origin as $course_origin) {
-				
+
 				$cb = new CourseBuilder();
 				$course = $cb->build($origin_session,$course_origin);
 				$cr = new CourseRestorer($course);
 				//$cr->set_file_option($_POST['same_file_name_option']);
 				$cr->restore($course_origin,$destination_session);
-				
+
 			}
 			Display::display_normal_message(get_lang('CopyFinished'));
-			display_form();	
-		} else {			
+			display_form();
+		} else {
 			Display::display_error_message(get_lang('YouMustSelectACourseFromOriginalSession'));
-			display_form();			
+			display_form();
 		}
-		
+
 	}
 
 } elseif (isset ($_POST['copy_option']) && $_POST['copy_option'] == 'select_items') {
-		
-	// Else, if a CourseSelectForm is requested, show it	
-	if (api_get_setting('show_glossary_in_documents') != 'none') { 
+
+	// Else, if a CourseSelectForm is requested, show it
+	if (api_get_setting('show_glossary_in_documents') != 'none') {
 		Display::display_normal_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
 	}
-	
+
 	$arr_course_origin 		= array();
 	$arr_course_destination = array();
 	$destination_session 	= '';
 	$origin_session 		= '';
-	
-	if (isset($_POST['SessionCoursesListOrigin'])) {					
+
+	if (isset($_POST['SessionCoursesListOrigin'])) {
 		$arr_course_origin 		= $_POST['SessionCoursesListOrigin'];
 	}
-	if (isset($_POST['SessionCoursesListDestination'])) {					
+	if (isset($_POST['SessionCoursesListDestination'])) {
 		$arr_course_destination 		= $_POST['SessionCoursesListDestination'];
 	}
-	if (isset($_POST['sessions_list_destination'])) {					
+	if (isset($_POST['sessions_list_destination'])) {
 		$destination_session 	= $_POST['sessions_list_destination'];
 	}
-	if (isset($_POST['sessions_list_origin'])) {					
+	if (isset($_POST['sessions_list_origin'])) {
 		$origin_session 		= $_POST['sessions_list_origin'];
 	}
-	
+
 	if ((is_array($arr_course_origin) && count($arr_course_origin) > 0) && !empty($destination_session)) {
-		Display::display_normal_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz')); 
+		Display::display_normal_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
 		$cb = new CourseBuilder();
 		$course = $cb->build($origin_session,$arr_course_origin[0]);
 		//$hidden_fields['same_file_name_option'] = $_POST['same_file_name_option'];
 		$hidden_fields['destination_course'] 	= $arr_course_origin[0];
 		$hidden_fields['origin_course'] 		= $arr_course_origin[0];
 		$hidden_fields['destination_session'] 	= $destination_session;
-		$hidden_fields['origin_session'] 		= $origin_session;	
+		$hidden_fields['origin_session'] 		= $origin_session;
 		CourseSelectForm :: display_form($course,$hidden_fields, true);
 		echo '<div style="float:right"><a href="javascript:window.back();">'.Display::return_icon('back.png',get_lang('Back').' '.get_lang('To').' '.get_lang('PlatformAdmin'),array('style'=>'vertical-align:middle')).get_lang('Back').'</a></div>';
 	} else {
 		Display::display_error_message(get_lang('You must select a course from original session and select a destination session'));
 		display_form();
 	}
-		
-} else {		
+
+} else {
 	display_form();
 }
 
-/*  FOOTER  */ 
+/*  FOOTER  */
 
 Display::display_footer();

+ 4 - 4
main/dropbox/dropbox_class.inc.php

@@ -114,7 +114,7 @@ class Dropbox_Work {
 				FROM ".dropbox_cnf("tbl_file")."
 				WHERE filename = '".addslashes($this->filename)."'";
         $result = Database::query($sql,__FILE__,__LINE__);
-		$res = mysql_fetch_array($result);
+		$res = Database::fetch_array($result);
 		if ($res != FALSE) {
 			$this->isOldWork = TRUE;
 		}
@@ -146,7 +146,7 @@ class Dropbox_Work {
 						)";
 
         	$result = Database::query($sql,__FILE__,__LINE__);
-			$this->id = mysql_insert_id(); //get automatically inserted id
+			$this->id = Database::insert_id(); //get automatically inserted id
 		}
 
 		// insert entries into person table
@@ -174,7 +174,7 @@ class Dropbox_Work {
 				FROM ".dropbox_cnf("tbl_file")."
 				WHERE id='".addslashes($id)."'";
         $result = Database::query($sql,__FILE__,__LINE__);
-		$res = mysql_fetch_array($result,MYSQL_ASSOC);
+		$res = Database::fetch_array($result, 'ASSOC');
 
 		// Check if uploader is still in Dokeos system
 		$uploader_id = stripslashes($res["uploader_id"]);
@@ -215,7 +215,7 @@ class Dropbox_Work {
 		$result = Database::query("SELECT feedback_date, feedback, cat_id FROM ".
 		    dropbox_cnf("tbl_post")." WHERE dest_user_id='".$_user['user_id'].
 		    "' AND file_id='".$id."'",__FILE__,__LINE__);
-		if ($res = mysql_fetch_array($result))
+		if ($res = Database::fetch_array($result))
 		{
     		$this->feedback_date = $res["feedback_date"];
     		$this->feedback = $res["feedback"];

+ 7 - 7
main/dropbox/dropbox_download.php

@@ -42,23 +42,23 @@ if ( isset($_GET['cat_id']) AND is_numeric($_GET['cat_id']) AND $_GET['action']=
 	{
 		// here we also incorporate the person table to make sure that deleted sent documents are not included.
 		$sql="SELECT DISTINCT file.id, file.filename, file.title FROM ".$dropbox_cnf["tbl_file"]." file, ".$dropbox_cnf["tbl_person"]." person
-				WHERE file.uploader_id='".mysql_real_escape_string($_user['user_id'])."'
-				AND file.cat_id='".mysql_real_escape_string($_GET['cat_id'])."'
-				AND person.user_id='".mysql_real_escape_string($_user['user_id'])."'
+				WHERE file.uploader_id='".Database::escape_string($_user['user_id'])."'
+				AND file.cat_id='".Database::escape_string($_GET['cat_id'])."'
+				AND person.user_id='".Database::escape_string($_user['user_id'])."'
 				AND person.file_id=file.id
 				" ;
 	}
 	if ($_GET['sent_received']=='received')
 	{
 		$sql="SELECT DISTINCT file.id, file.filename, file.title FROM ".$dropbox_cnf["tbl_file"]." file, ".$dropbox_cnf["tbl_person"]." person, ".$dropbox_cnf["tbl_post"]." post
-				WHERE post.cat_id='".mysql_real_escape_string($_GET['cat_id'])."'
-				AND person.user_id='".mysql_real_escape_string($_user['user_id'])."'
+				WHERE post.cat_id='".Database::escape_string($_GET['cat_id'])."'
+				AND person.user_id='".Database::escape_string($_user['user_id'])."'
 				AND person.file_id=file.id
 				AND post.file_id=file.id
 				" ;
 	}
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		$files_to_download[]=$row['id'];
 	}
@@ -97,7 +97,7 @@ if ( ! isset( $_GET['id']) || ! is_numeric( $_GET['id']))
 $allowed_to_download=false;
 
 // Check if the user has sent or received the file.
-$sql="SELECT * FROM ".$dropbox_cnf["tbl_person"]." WHERE file_id='".mysql_real_escape_string($_GET['id'])."' AND user_id='".mysql_real_escape_string($_user['user_id'])."'";
+$sql="SELECT * FROM ".$dropbox_cnf["tbl_person"]." WHERE file_id='".Database::escape_string($_GET['id'])."' AND user_id='".Database::escape_string($_user['user_id'])."'";
 $result=Database::query($sql);
 if (mysql_num_rows($result)>0)
 {

+ 2 - 2
main/dropbox/dropbox_submit.php

@@ -339,7 +339,7 @@ if ( isset( $_GET['mailingIndex']))  // examine or send
             }
 
 	        $result = Database::query($sel . $thisRecip . "'",__FILE__,__LINE__);
-	        while ( ($res = mysql_fetch_array($result))) {$students[] = $res;}
+	        while ( ($res = Database::fetch_array($result))) {$students[] = $res;}
 	        mysql_free_result($result);
 
 	    	if (count($students) == 1)
@@ -487,7 +487,7 @@ if ( isset( $_GET['mailingIndex']))  // examine or send
 	        if ( mysql_num_rows($result) > 0)
 	        {
 		        $remainingUsers = '';
-		        while ( ($res = mysql_fetch_array($result)))
+		        while ( ($res = Database::fetch_array($result)))
 		        {
 					$remainingUsers .= ', ' . htmlspecialchars(api_get_person_name($res[1], $res[0]), ENT_QUOTES, $charset);
 		        }

+ 2 - 2
main/exercice/answer.class.php

@@ -122,7 +122,7 @@ class Answer
 		$i=1;
 
 		// while a record is found
-		while($object=mysql_fetch_object($result))
+		while($object=Database::fetch_object($result))
 		{
 			$this->id[$i]=$object->id;
 			$this->answer[$i]=$object->answer;
@@ -170,7 +170,7 @@ class Answer
 		$i=1;
 
 		// while a record is found
-		while($object=mysql_fetch_object($result))
+		while($object=Database::fetch_object($result))
 		{
 			$this->answer[$i]=$object->answer;
 			$this->correct[$i]=$object->correct;

+ 6 - 6
main/exercice/exercice_submit.php

@@ -626,18 +626,18 @@ if ($formSent) {
 			// goes to the script that will show the result of the exercise
 			if ($exerciseType == ALL_ON_ONE_PAGE) {
 				header("Location: exercise_result.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
-			} else {			
+			} else {
 				if ($exe_id != '') {
 					//clean incomplete
 					$update_query = 'UPDATE ' . $stat_table . ' SET ' . "status = '', data_tracking='', exe_date = '" . date('Y-m-d H:i:s') . "'" . ' WHERE exe_id = ' . Database::escape_string($exe_id);
-					api_sql_query($update_query, __FILE__, __LINE__);
-				}			
+					Database::query($update_query, __FILE__, __LINE__);
+				}
 				header("Location: exercise_show.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
 			}
 			exit ();
 		} else {
 			header("Location: exercice_submit.php?exerciseId=$exerciseId");
-			exit;			
+			exit;
 		}
 	}
 	if ($debug > 0) {
@@ -1085,10 +1085,10 @@ if (!empty ($error)) {
 			$submit_btn .= "</button>";
 			echo $submit_btn;
 		}
-		
+
 	}
 
-	
+
 	echo "</table>
 			</td>
 			</tr>

+ 3 - 3
main/exercice/exercise.class.php

@@ -406,7 +406,7 @@ class Exercise
         Database::query($query,__FILE__,__LINE__);*/
         $id = add_document($_course,str_replace($documentPath,'',$audioPath).'/'.$this->sound,'file',$sound['size'],$sound['name']);
 
-        //$id = Database::get_last_insert_id();
+        //$id = Database::insert_id();
         //$time = time();
         //$time = date("Y-m-d H:i:s", $time);
         // insert into the item_property table, using default visibility of "visible"
@@ -500,7 +500,7 @@ class Exercise
         $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
         $TBL_QUIZ_QUESTION= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
 
-		
+
 		$id = $this->id;
 		$exercise = $this->exercise;
 		$description = $this->description;
@@ -511,7 +511,7 @@ class Exercise
 		$random = $this->random;
 		$active = $this->active;
 		$session_id = api_get_session_id();
-		
+
 		if ($feedbacktype==1){
 			$results_disabled = 1;
 		} else {

+ 1 - 1
main/exercice/hotpotatoes.lib.php

@@ -92,7 +92,7 @@ function GetComment($path,$course_code='') {
 	$query = "select comment from $dbTable where path='$path'";
 	$result = Database::query($query,__FILE__,__LINE__);
 
-	while ($row = mysql_fetch_array($result)) {
+	while ($row = Database::fetch_array($result)) {
 		return $row[0];
 	}
 	return "";

+ 1 - 1
main/exercice/hotspot.class.php

@@ -70,7 +70,7 @@ class HotSpot extends Question {
 			if (file_exists($picturePath.'/'.$this->picture)) { 
 				//list($width,$height) = @getimagesize($file_info['tmp_name']); does not work	
 				list($width,$height) = @getimagesize($picturePath.'/'.$this->picture);				
-				if($width>=$height) {
+				if($width>$height) {
 					$this->resizePicture('width',545);
 				} else {
 					$this->resizePicture('height',350);

+ 1 - 1
main/exercice/hotspot_answers.as.php

@@ -40,7 +40,7 @@ $result = Database::query($sql,__FILE__,__LINE__);
 $output = "hotspot_lang=$courseLang&hotspot_image=$pictureName&hotspot_image_width=$pictureWidth&hotspot_image_height=$pictureHeight&courseCode=$coursePath";
 $i = 0;
 
-while ($hotspot = mysql_fetch_array($result))
+while ($hotspot = Database::fetch_array($result))
 {
 	$output .= "&hotspot_".$hotspot['id']."=true";
 	// Square or rectancle

+ 1 - 1
main/exercice/hotspot_savescore.inc.php

@@ -54,6 +54,6 @@ $sql = "INSERT INTO $TBL_TRACK_E_HOTSPOT (`user_id` , `course_id` , `quiz_id` ,
 			'".Database::escape_string($coordinates)."')";
 $result = Database::query($sql,__FILE__,__LINE__);
 // Save insert id into session if users changes answer.
-$insert_id = mysql_insert_id();
+$insert_id = Database::insert_id();
 $_SESSION['exerciseResult'][$questionId]['ids'][$answerOrderId] = $insert_id;
 ?>

+ 1 - 1
main/exercice/mark_free_answer.php

@@ -139,7 +139,7 @@ if($action == 'mark'){
 			#echo $sql;
 			$res = Database::query($sql,__FILE__,__LINE__);
 			if(mysql_num_rows($res)>0){
-				$row = mysql_fetch_array($res);
+				$row = Database::fetch_array($res);
 				//@todo Check that just summing past score and the new free answer mark doesn't come up
 				// with a score higher than the possible score for that exercise
 				$my_score = $row['exe_result'] + $_POST['score'];

+ 5 - 5
main/exercice/question.class.php

@@ -91,7 +91,7 @@ abstract class Question
 		$result=Database::query($sql,__FILE__,__LINE__);
 
 		// if the question has been found
-		if($object=mysql_fetch_object($result))
+		if($object=Database::fetch_object($result))
 		{
 			$objQuestion = Question::getInstance($object->type);
 			$objQuestion->id=$id;
@@ -107,7 +107,7 @@ abstract class Question
 			$result=Database::query($sql,__FILE__,__LINE__);
 
 			// fills the array with the exercises which this question is in
-			while($object=mysql_fetch_object($result))
+			while($object=Database::fetch_object($result))
 			{
 				$objQuestion->exerciseList[]=$object->exercice_id;
 			}
@@ -623,7 +623,7 @@ abstract class Question
 					)";
 			Database::query($sql,__FILE__,__LINE__);
 
-			$this->id=Database::get_last_insert_id();
+			$this->id=Database::insert_id();
 
 			api_item_property_update($_course, TOOL_QUIZ, $this->id,'QuizQuestionAdded',$_user['user_id']);
 
@@ -905,7 +905,7 @@ abstract class Question
 		$sql="INSERT INTO $TBL_QUESTIONS(question,description,ponderation,position,type) VALUES('".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."')";
 		Database::query($sql,__FILE__,__LINE__);
 
-		$id=Database::get_last_insert_id();
+		$id=Database::insert_id();
 		// duplicates the picture
 		$this->exportPicture($id);
 
@@ -1004,7 +1004,7 @@ abstract class Question
 		$editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150');
 		if(is_array($fck_config)){
 			$editor_config = array_merge($editor_config, $fck_config);
-		}		
+		}
 		if(!api_is_allowed_to_edit(null,true)) $editor_config['UserStatus'] = 'student';
 
 		$form -> addElement('html','<div class="row">

+ 12 - 12
main/forum/forumfunction.inc.php

@@ -496,22 +496,22 @@ function store_forumcategory($values) {
 	$row=Database::fetch_array($result);
 	$new_max=$row['sort_max']+1;
 	$session_id = api_get_session_id();
-	
+
 	$clean_cat_title=Database::escape_string(Security::remove_XSS($values['forum_category_title']));
 
 	if (isset($values['forum_category_id'])) { // storing an edit
 		$sql="UPDATE ".$table_categories." SET cat_title='".$clean_cat_title."', cat_comment='".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['forum_category_comment'])),COURSEMANAGERLOWSECURITY))."' WHERE cat_id='".Database::escape_string($values['forum_category_id'])."'";
 		Database::query($sql,__FILE__,__LINE__);
-		$last_id=Database::get_last_insert_id();
+		$last_id=Database::insert_id();
 		api_item_property_update(api_get_course_info(), TOOL_FORUM_CATEGORY, $values['forum_category_id'], 'ForumCategoryUpdated', api_get_user_id());
 		$return_message=get_lang('ForumCategoryEdited');
 	} else {
 		$sql = "INSERT INTO ".$table_categories." (cat_title, cat_comment, cat_order, session_id) VALUES ('".$clean_cat_title."','".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['forum_category_comment'])),COURSEMANAGERLOWSECURITY))."','".Database::escape_string($new_max)."','".Database::escape_string($session_id)."')";
 		Database::query($sql,__FILE__,__LINE__);
-		$last_id = Database::get_last_insert_id();
+		$last_id = Database::insert_id();
 		if ($last_id > 0) {
 			api_item_property_update(api_get_course_info(), TOOL_FORUM_CATEGORY, $last_id, 'ForumCategoryAdded', api_get_user_id());
-		}		
+		}
 		$return_message=get_lang('ForumCategoryAdded');
 	}
 
@@ -543,9 +543,9 @@ function store_forum($values) {
 		$new_max=$row['sort_max']+1;
 	}
 
-	
+
 	$session_id = api_get_session_id();
-	
+
 	$clean_title = Database::escape_string(Security::remove_XSS($values['forum_title']));
 
 	// forum images
@@ -645,7 +645,7 @@ function store_forum($values) {
 				'".Database::escape_string(isset($new_max)?$new_max:null)."',
 				".intval($session_id).")";
 		Database::query($sql,__FILE__,__LINE__);
-		$last_id = Database::get_last_insert_id();
+		$last_id = Database::insert_id();
 		if ($last_id > 0) {
 			api_item_property_update($_course, TOOL_FORUM, $last_id, 'ForumAdded', api_get_user_id());
 		}
@@ -1104,11 +1104,11 @@ function get_forum_categories($id='') {
 	$table_categories		= Database :: get_course_table(TABLE_FORUM_CATEGORY);
 	$table_item_property	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
 	$forum_categories_list = array();
-	
+
 	//condition for the session
 	$session_id = api_get_session_id();
 	$condition_session = api_get_session_condition($session_id);
-	
+
 	if ($id == '') {
 		$sql="SELECT * FROM".$table_categories." forum_categories, ".$table_item_property." item_properties
 					WHERE forum_categories.cat_id=item_properties.ref
@@ -1192,11 +1192,11 @@ function get_forums($id='') {
 	global $table_users;
 
 	// **************** GETTING ALL THE FORUMS ************************* //
-	
+
 	//condition for the session
 	$session_id = api_get_session_id();
 	$condition_session = api_get_session_condition($session_id);
-	
+
 	$forum_list = array();
 	if ($id=='') {
 		//-------------- Student -----------------//
@@ -3089,7 +3089,7 @@ function store_move_post($values) {
 				'".Database::escape_string($current_post['post_date'])."'
 				)";
 		$result=Database::query($sql, __FILE__, __LINE__);
-		$new_thread_id=Database::get_last_insert_id();
+		$new_thread_id=Database::insert_id();
 		api_item_property_update($_course, TOOL_FORUM_THREAD, $new_thread_id,"visible", $current_post['poster_id']);
 
 		// moving the post to the newly created thread

+ 26 - 26
main/glossary/index.php

@@ -144,25 +144,25 @@ function save_glossary($values)
 
 	// get the maximum display order of all the glossary items
 	$max_glossary_item = get_max_glossary_item();
-	
+
 	// session_id
 	$session_id = api_get_session_id();
-	
+
 	// check if the glossary term already exists
 	if (glossary_exists($values['glossary_title']))
 	{
 		// display the feedback message
 		Display::display_error_message('GlossaryTermAlreadyExistsYouShouldEditIt');
 	} else {
-		$sql = "INSERT INTO $t_glossary (name, description, display_order, session_id) 
+		$sql = "INSERT INTO $t_glossary (name, description, display_order, session_id)
 				VALUES(
 					'".Database::escape_string(Security::remove_XSS($values['glossary_title']))."',
 					'".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['glossary_comment'])),COURSEMANAGERLOWSECURITY))."',
 					'".(int)($max_glossary_item + 1)."',
 					'".Database::escape_string($session_id)."'
 					)";
-		$result = api_sql_query($sql, __FILE__, __LINE__);
-		$id = Database::get_last_insert_id();
+		$result = Database::query($sql, __FILE__, __LINE__);
+		$id = Database::insert_id();
 		if ($id>0) {
 			//insert into item_property
 			api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, $id, 'GlossaryAdded', api_get_user_id());
@@ -300,10 +300,10 @@ function delete_glossary($glossary_id)
 
 	$sql = "DELETE FROM $t_glossary WHERE glossary_id='".Database::escape_string($glossary_id)."'";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	
+
 	//update item_property (delete)
 	api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, Database::escape_string($glossary_id), 'delete', api_get_user_id());
-	
+
 	// reorder the remaining terms
 	reorder_glossary();
 	$_SESSION['max_glossary_display'] = get_max_glossary_item();
@@ -340,9 +340,9 @@ function display_glossary()
 		$table->set_header(3, get_lang('CreationDate'), false);
 		$table->set_header(4, get_lang('UpdateDate'), false);
 		if (api_is_allowed_to_edit(null,true)) {
-			$table->set_header(5, get_lang('Actions'), false);		
+			$table->set_header(5, get_lang('Actions'), false);
 			$table->set_column_filter(5, 'actions_filter');
-		}	
+		}
 		$table->display();
 	}
 	if ($_SESSION['glossary_view'] == 'list')
@@ -406,17 +406,17 @@ function get_glossary_data($from, $number_of_items, $column, $direction)
 	// Database table definition
 	$t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
 	$t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-	
+
 	if (api_is_allowed_to_edit(null,true)) {
 		$col5 = ", glossary.glossary_id	as col5";
 	} else {
 		$col5 = " ";
 	}
-	
+
 	//condition for the session
 	$session_id = api_get_session_id();
 	$condition_session = api_get_session_condition($session_id);
-	
+
 	$sql = "SELECT
 				glossary.display_order 	as col0,
 				glossary.name 			as col1,
@@ -425,41 +425,41 @@ function get_glossary_data($from, $number_of_items, $column, $direction)
 				ip.lastedit_date		as col4
 				$col5,
 				glossary.session_id as session_id
-			FROM $t_glossary glossary, $t_item_propery ip 
+			FROM $t_glossary glossary, $t_item_propery ip
 			WHERE glossary.glossary_id = ip.ref
 			AND tool = '".TOOL_GLOSSARY."' $condition_session";
 	$sql .= " ORDER BY col$column $direction ";
 	$sql .= " LIMIT $from,$number_of_items";
-	
-	$res = api_sql_query($sql, __FILE__, __LINE__);
-	
+
+	$res = Database::query($sql, __FILE__, __LINE__);
+
 	$return = array();
 	$array = array();
 	while ($data = Database::fetch_array($res)) {
-		
+
 		$array[0] = $data[0];
-		
+
 		//validacion when belongs to a session
 		$session_img = api_get_session_image($data['session_id'], $_user['status']);
 		$array[1] = $data[1] . $session_img;
-		
+
 		if (!$_SESSION['glossary_view'] || $_SESSION['glossary_view'] == 'table') {
 			$array[2] = str_replace(array('<p>','</p>'),array('','<br />'),$data[2]);
 		} else {
 			$array[2] = $data[2];
 		}
-		
+
 		$array[3] = $data[3];
 		$array[4] = $data[4];
-		
+
 		if (api_is_allowed_to_edit(null,true)) {
 			$array[5] = $data[5];
 		}
-		
+
 		$return[] = $array;
 	}
-	
-	return $return;	
+
+	return $return;
 }
 
 /**
@@ -501,10 +501,10 @@ function actions_filter($glossary_id,$url_params,$row)
 		}
 	}
 	$return .= '<a href="'.api_get_self().'?action=edit_glossary&amp;glossary_id='.$row[5].'&msg=edit">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a>';
-	
+
 	$glossary_data = get_glossary_information($row[5]);
 	$glossary_term = $glossary_data['glossary_title'];
-		
+
 	$return .= '<a href="'.api_get_self().'?action=delete_glossary&amp;glossary_id='.$row[5].'" onclick="return confirmation(\''.$glossary_term.'\');">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
 	return $return;
 }

+ 1 - 1
main/inc/global.inc.php

@@ -120,7 +120,7 @@ if (!mysql_select_db($_configuration['main_database'], $dokeos_database_connecti
 // The platform's character set must be retrieved at this early moment.
 $sql = "SELECT selected_value FROM settings_current WHERE variable = 'platform_charset';";
 $result = Database::query($sql, __FILE__, __LINE__);
-while ($row = @mysql_fetch_array($result)) {
+while ($row = @Database::fetch_array($result)) {
 	$charset = $row[0];
 }
 if (empty($charset)) {

+ 1 - 1
main/inc/introductionSection.inc.php

@@ -128,7 +128,7 @@ if ($intro_editAllowed) {
 
 $sql = "SELECT intro_text FROM $TBL_INTRODUCTION WHERE id='".$moduleId."'";
 $intro_dbQuery = Database::query($sql,__FILE__,__LINE__);
-$intro_dbResult = mysql_fetch_array($intro_dbQuery);
+$intro_dbResult = Database::fetch_array($intro_dbQuery);
 $intro_content = $intro_dbResult['intro_text'];
 
 /* Determines the correct display */

+ 25 - 25
main/inc/lib/add_course.lib.inc.php

@@ -633,8 +633,8 @@ function update_Db_course($courseDbName)
 		)";
 	Database::query($sql, __FILE__, __LINE__);
 	$sql = "ALTER TABLE `".$TABLEQUIZ . "` ADD INDEX ( session_id ) ";
-	api_sql_query($sql, __FILE__, __LINE__);
-	
+	Database::query($sql, __FILE__, __LINE__);
+
 	// Exercise tool - questions
 	$sql = "
 		CREATE TABLE `".$TABLEQUIZQUESTIONLIST . "` (
@@ -851,7 +851,7 @@ function update_Db_course($courseDbName)
 	Database::query($sql, __FILE__, __LINE__);
 	$sql = "ALTER TABLE `".$TABLETOOLLINK . "` ADD INDEX ( session_id ) ";
 	Database::query($sql, __FILE__, __LINE__);
-	
+
 	$sql = "
 		CREATE TABLE `".$TABLETOOLLINKCATEGORIES . "` (
 		id smallint unsigned NOT NULL auto_increment,
@@ -906,7 +906,7 @@ function update_Db_course($courseDbName)
 	Database::query($sql, __FILE__, __LINE__);
 	$sql = "ALTER TABLE `".$TABLETOOLWIKI . "` ADD INDEX ( session_id ) ";
 	Database::query($sql, __FILE__, __LINE__);
-	
+
 	//
 	$sql = "CREATE TABLE `".$TABLEWIKICONF . "` (
 		page_id int NOT NULL default 0,
@@ -1055,7 +1055,7 @@ function update_Db_course($courseDbName)
 		visibility tinyint NOT NULL default '1',
 		start_visible datetime NOT NULL default '0000-00-00 00:00:00',
 		end_visible datetime NOT NULL default '0000-00-00 00:00:00',
-		id_session INT NOT NULL DEFAULT 0		
+		id_session INT NOT NULL DEFAULT 0
 		) TYPE=MyISAM;", __FILE__, __LINE__);
 	Database::query("ALTER TABLE `$TABLEITEMPROPERTY` ADD INDEX idx_item_property_toolref (tool,ref)", __FILE__, __LINE__);
 
@@ -1316,7 +1316,7 @@ function update_Db_course($courseDbName)
 	}
 	$sql = "ALTER TABLE `".$tbl_blogs . "` ADD INDEX ( session_id ) ";
 	Database::query($sql, __FILE__, __LINE__);
-	
+
 	$sql = "
 		CREATE TABLE `" . $tbl_blogs_comments . "` (
 			comment_id int NOT NULL AUTO_INCREMENT ,
@@ -1658,7 +1658,7 @@ function update_Db_course($courseDbName)
 	$result = Database::query($sql, __FILE__, __LINE__) or die(mysql_error($sql));
 	$sql = "ALTER TABLE `".$TBL_GLOSSARY . "` ADD INDEX ( session_id ) ";
 	Database::query($sql, __FILE__, __LINE__);
-	
+
 	// table notebook
 	$sql = "CREATE TABLE `".$TBL_NOTEBOOK."` (
 			  notebook_id int unsigned NOT NULL auto_increment,
@@ -2002,7 +2002,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_GROUP . "','group/group.php','group.gif','".string2binary(api_get_setting('course_create_active_tools', 'groups')) . "','0','squaregrey.gif','NO','_self','interaction','0')", __FILE__, __LINE__);
 	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_CHAT . "','chat/chat.php','chat.gif','".string2binary(api_get_setting('course_create_active_tools', 'chat')) . "','0','squaregrey.gif','NO','_self','interaction','0')", __FILE__, __LINE__);
 	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_STUDENTPUBLICATION . "','work/work.php','works.gif','".string2binary(api_get_setting('course_create_active_tools', 'student_publications')) . "','0','squaregrey.gif','NO','_self','interaction','0')", __FILE__, __LINE__);
-	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_SURVEY."','survey/survey_list.php','survey.gif','".string2binary(api_get_setting('course_create_active_tools', 'survey')) . "','0','squaregrey.gif','NO','_self','interaction','0')", __FILE__, __LINE__);	
+	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_SURVEY."','survey/survey_list.php','survey.gif','".string2binary(api_get_setting('course_create_active_tools', 'survey')) . "','0','squaregrey.gif','NO','_self','interaction','0')", __FILE__, __LINE__);
 	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_WIKI ."','wiki/index.php','wiki.gif','".string2binary(api_get_setting('course_create_active_tools', 'wiki')) . "','0','squaregrey.gif','NO','_self','interaction','0')", __FILE__, __LINE__);
     Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_GRADEBOOK."','gradebook/index.php','gradebook.gif','".string2binary(api_get_setting('course_create_active_tools', 'gradebook')). "','0','squaregrey.gif','NO','_self','authoring','0')", __FILE__, __LINE__);
 	Database::query("INSERT INTO `" . $tbl_course_homepage . "` VALUES (NULL, '" . TOOL_GLOSSARY."','glossary/index.php','glossary.gif','".string2binary(api_get_setting('course_create_active_tools', 'glossary')). "','0','squaregrey.gif','NO','_self','authoring','0')", __FILE__, __LINE__);
@@ -2085,31 +2085,31 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 		*/
 		//Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/example_document.html','example_document.html','file','3367')", __FILE__, __LINE__);
 		//we need to add the document properties too!
-		//$example_doc_id = Database :: get_last_insert_id();
+		//$example_doc_id = Database :: insert_id();
 		//Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,1)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/images','".get_lang('Images')."','folder','0')", __FILE__, __LINE__);
-		$example_doc_id = Database :: get_last_insert_id();
+		$example_doc_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/images/gallery','".get_lang('DefaultCourseImages')."','folder','0')", __FILE__, __LINE__);
-		$example_doc_id = Database :: get_last_insert_id();
+		$example_doc_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 
         Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/shared_folder','".get_lang('SharedDocumentsDirectory')."','folder','0')", __FILE__, __LINE__);
-        $example_doc_id = Database :: get_last_insert_id();
+        $example_doc_id = Database :: insert_id();
         Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/audio','".get_lang('Audio')."','folder','0')", __FILE__, __LINE__);
-		$example_doc_id = Database :: get_last_insert_id();
+		$example_doc_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/flash','".get_lang('Flash')."','folder','0')", __FILE__, __LINE__);
-		$example_doc_id = Database :: get_last_insert_id();
+		$example_doc_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('/video','".get_lang('Video')."','folder','0')", __FILE__, __LINE__);
-		$example_doc_id = Database :: get_last_insert_id();
+		$example_doc_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$example_doc_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 
 		//FILL THE COURSE DOCUMENT WITH DEFAULT COURSE PICTURES
@@ -2144,7 +2144,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 					$folder_path=substr($value["dir"],0,strlen($value["dir"])-1);
 					$temp=explode("/",$folder_path);
 					Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('$path_documents".$folder_path."','".$temp[count($temp)-1]."','folder','0')", __FILE__, __LINE__);
-					$image_id = Database :: get_last_insert_id();
+					$image_id = Database :: insert_id();
 					Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$image_id,'DocumentAdded',1,0,NULL,0)", __FILE__, __LINE__);
 				}
 
@@ -2153,7 +2153,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 					$temp=explode("/",$value["file"]);
 					$file_size=filesize($course_documents_folder.$value["file"]);
 			        Database::query("INSERT INTO `".$TABLETOOLDOCUMENT . "`(path,title,filetype,size) VALUES ('$path_documents".$value["file"]."','".$temp[count($temp)-1]."','file','$file_size')", __FILE__, __LINE__);
-					$image_id = Database :: get_last_insert_id();
+					$image_id = Database :: insert_id();
 					Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('document',1,NOW(),NOW(),$image_id,'DocumentAdded',1,0,NULL,1)", __FILE__, __LINE__);
 				}
 			}
@@ -2166,7 +2166,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 		*/
 		Database::query("INSERT INTO `".$TABLETOOLAGENDA . "` VALUES ( NULL, '".lang2db(get_lang('AgendaCreationTitle')) . "', '".lang2db(get_lang('AgendaCreationContenu')) . "', now(), now(), NULL, 0)", __FILE__, __LINE__);
 		//we need to add the item properties too!
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		$sql = "INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_CALENDAR_EVENT . "',1,NOW(),NOW(),$insert_id,'AgendaAdded',1,0,NULL,1)";
 		Database::query($sql, __FILE__, __LINE__);
 
@@ -2179,15 +2179,15 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 							VALUES ('http://www.google.com','Google','".lang2db(get_lang('Google')) . "','0','0','0','_self')";
 		Database::query($add_google_link_sql, __FILE__, __LINE__);
 		//we need to add the item properties too!
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		$sql = "INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_LINK . "',1,NOW(),NOW(),$insert_id,'LinkAdded',1,0,NULL,1)";
 		Database::query($sql, __FILE__, __LINE__);
 
 		$add_wikipedia_link_sql = "	INSERT INTO `".$TABLETOOLLINK . "` (url, title, description, category_id, display_order, on_homepage, target)
 							VALUES ('http://www.wikipedia.org','Wikipedia','".lang2db(get_lang('Wikipedia')) . "','0','1','0','_self')";
-		api_sql_query($add_wikipedia_link_sql, __FILE__, __LINE__);
+		Database::query($add_wikipedia_link_sql, __FILE__, __LINE__);
 		//we need to add the item properties too!
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		$sql = "INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_LINK . "',1,NOW(),NOW(),$insert_id,'LinkAdded',1,0,NULL,1)";
 		Database::query($sql, __FILE__, __LINE__);
 
@@ -2199,7 +2199,7 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 		$sql = "INSERT INTO `".$TABLETOOLANNOUNCEMENTS . "` (title,content,end_date,display_order,email_sent) VALUES ('".lang2db(get_lang('AnnouncementExampleTitle')) . "', '".lang2db(get_lang('AnnouncementEx')) . "', NOW(), '1','0')";
 		Database::query($sql, __FILE__, __LINE__);
 		//we need to add the item properties too!
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		$sql = "INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_ANNOUNCEMENT . "',1,NOW(),NOW(),$insert_id,'AnnouncementAdded',1,0,NULL,1)";
 		Database::query($sql, __FILE__, __LINE__);
 
@@ -2238,15 +2238,15 @@ function fill_Db_course($courseDbName, $courseRepository, $language,$default_doc
 		-----------------------------------------------------------
 		*/
 		Database::query("INSERT INTO `$TABLEFORUMCATEGORIES` VALUES (1,'".lang2db(get_lang('ExampleForumCategory'))."', '', 1, 0, 0)", __FILE__, __LINE__);
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('forum_category',1,NOW(),NOW(),$insert_id,'ForumCategoryAdded',1,0,NULL,1)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `$TABLEFORUMS` (forum_title, forum_comment, forum_threads,forum_posts,forum_last_post,forum_category, allow_anonymous, allow_edit,allow_attachments, allow_new_threads,default_view,forum_of_group,forum_group_public_private, forum_order,locked,session_id ) VALUES ('".lang2db(get_lang('ExampleForum'))."', '', 0, 0, 0, 1, 0, 1, '0', 1, 'flat','0', 'public', 1, 0,0)", __FILE__, __LINE__);
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('" . TOOL_FORUM . "',1,NOW(),NOW(),$insert_id,'ForumAdded',1,0,NULL,1)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `$TABLEFORUMTHREADS` (thread_id, thread_title, forum_id, thread_replies, thread_poster_id, thread_poster_name, thread_views, thread_last_post, thread_date, locked, thread_qualify_max) VALUES (1, '".lang2db(get_lang('ExampleThread'))."', 1, 0, 1, '', 0, 1, NOW(), 0, 10)", __FILE__, __LINE__);
-		$insert_id = Database :: get_last_insert_id();
+		$insert_id = Database :: insert_id();
 		Database::query("INSERT INTO `".$TABLEITEMPROPERTY . "` (tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility) VALUES ('forum_thread',1,NOW(),NOW(),$insert_id,'ForumThreadAdded',1,0,NULL,1)", __FILE__, __LINE__);
 
 		Database::query("INSERT INTO `$TABLEFORUMPOSTS` VALUES (1, '".lang2db(get_lang('ExampleThread'))."', '".lang2db(get_lang('ExampleThreadContent'))."', 1, 1, 1, '', NOW(), 0, 0, 1)", __FILE__, __LINE__);

+ 8 - 8
main/inc/lib/blog.lib.php

@@ -129,7 +129,7 @@ class Blog {
 	public static function create_blog ($title, $subtitle) {
 		global $_user;
 		$current_date=date('Y-m-d H:i:s',time());
-		$session_id = api_get_session_id();		
+		$session_id = api_get_session_id();
 		// Tabel definitions
 		$tbl_blogs 			= Database::get_course_table(TABLE_BLOGS);
 		$tbl_tool 			= Database::get_course_table(TABLE_TOOL_LIST);
@@ -145,7 +145,7 @@ class Blog {
 			$sql = "INSERT INTO $tbl_blogs (blog_name, blog_subtitle, date_creation, visibility, session_id )
 						VALUES ('".Database::escape_string($title)."', '".Database::escape_string($subtitle)."', '".$current_date."', '1', '$session_id');";
 			Database::query($sql, __FILE__, __LINE__);
-			$this_blog_id = Database::get_last_insert_id();
+			$this_blog_id = Database::insert_id();
 
 			if ($this_blog_id > 0) {
 				//insert into item_property
@@ -187,7 +187,7 @@ class Blog {
 		// Update the blog
 		$sql = "UPDATE $tbl_blogs SET blog_name = '".Database::escape_string($title)."',	blog_subtitle = '".Database::escape_string($subtitle)."' WHERE blog_id ='".Database::escape_string((int)$blog_id)."' LIMIT 1";
 		Database::query($sql, __FILE__, __LINE__);
-		$this_blog_id = Database::get_last_insert_id();
+		$this_blog_id = Database::insert_id();
 
 		//update item_property (update)
 		api_item_property_update(api_get_course_info(), TOOL_BLOGS, Database::escape_string($blog_id), 'BlogUpdated', api_get_user_id());
@@ -241,7 +241,7 @@ class Blog {
 		// Delete from course homepage
 		$sql = "DELETE FROM $tbl_tool WHERE link = 'blog/blog.php?blog_id=".(int)$blog_id."'";
 		Database::query($sql, __FILE__, __LINE__);
-		
+
 		//update item_property (delete)
 		api_item_property_update(api_get_course_info(), TOOL_BLOGS, Database::escape_string($blog_id), 'delete', api_get_user_id());
 	}
@@ -514,7 +514,7 @@ class Blog {
 					VALUES ('".(int)$blog_id."', '" . Database::escape_string($title)."', '" . Database::escape_string($description)."', '" . Database::escape_string($color)."', '0');";
 		Database::query($sql, __FILE__, __LINE__);
 
-		$task_id = mysql_insert_id();
+		$task_id = Database::insert_id();
 		$tool = 'BLOG_' . $blog_id;
 
 		if($articleDelete == 'on')
@@ -2833,11 +2833,11 @@ class Blog {
 		$counter = 0;
 
 		$tbl_blogs = Database::get_course_table(TABLE_BLOGS);
-		
+
 		//condition for the session
 		$session_id = api_get_session_id();
 		$condition_session = api_get_session_condition($session_id, false);
-		
+
 		$sql = 'SELECT blog_name,blog_subtitle,visibility,blog_id FROM '.$tbl_blogs.' ORDER BY date_creation DESC ';
 		$result = Database::query($sql, __FILE__, __LINE__);
 
@@ -2852,7 +2852,7 @@ class Blog {
 			foreach($list_info as $key => $info_log) {
 				//validacion when belongs to a session
 				$session_img = api_get_session_image($info_log[4], $_user['status']);
-				
+
 				$url_start_blog = 'blog.php' ."?". "blog_id=".$info_log[3]. "&amp;".api_get_cidreq();
 				$title = $info_log[0];
     			$image = '<img src="../img/blog.gif" border="0" align="absmiddle" alt="' . $title . '">'."\n";

+ 16 - 16
main/inc/lib/classmanager.lib.php

@@ -46,7 +46,7 @@ class ClassManager
 		$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
 		$sql = "SELECT * FROM $table_class WHERE id='".$class_id."'";
 		$res = Database::query($sql, __FILE__, __LINE__);
-		return mysql_fetch_array($res, MYSQL_ASSOC);
+		return Database::fetch_array($res, 'ASSOC');
 	}
 	/**
 	 * Change the name of a class
@@ -56,7 +56,7 @@ class ClassManager
 	function set_name($name, $class_id)
 	{
 		$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
-		$sql = "UPDATE $table_class SET name='".mysql_real_escape_string($name)."' WHERE id='".$class_id."'";
+		$sql = "UPDATE $table_class SET name='".Database::escape_string($name)."' WHERE id='".$class_id."'";
 		$res = Database::query($sql, __FILE__, __LINE__);
 	}
 	/**
@@ -66,7 +66,7 @@ class ClassManager
 	function create_class($name)
 	{
 		$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
-		$sql = "INSERT INTO $table_class SET name='".mysql_real_escape_string($name)."'";
+		$sql = "INSERT INTO $table_class SET name='".Database::escape_string($name)."'";
 		Database::query($sql, __FILE__, __LINE__);
 		return mysql_affected_rows() == 1;
 	}
@@ -77,7 +77,7 @@ class ClassManager
 	function class_name_exists($name)
 	{
 		$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
-		$sql = "SELECT * FROM $table_class WHERE name='".mysql_real_escape_string($name)."'";
+		$sql = "SELECT * FROM $table_class WHERE name='".Database::escape_string($name)."'";
 		$res = Database::query($sql, __FILE__, __LINE__);
 		return mysql_num_rows($res) != 0;
 	}
@@ -111,7 +111,7 @@ class ClassManager
 		$sql = "SELECT * FROM $table_class_user cu, $table_user u WHERE cu.class_id = '".$class_id."' AND cu.user_id = u.user_id";
 		$res = Database::query($sql, __FILE__, __LINE__);
 		$users = array ();
-		while ($user = mysql_fetch_array($res, MYSQL_ASSOC))
+		while ($user = Database::fetch_array($res, 'ASSOC'))
 		{
 			$users[] = $user;
 		}
@@ -174,7 +174,7 @@ class ClassManager
 		$sql = "SELECT * FROM $table_class_course cc, $table_course c WHERE cc.class_id = '".$class_id."' AND cc.course_code = c.code";
 		$res = Database::query($sql, __FILE__, __LINE__);
 		$courses = array ();
-		while ($course = mysql_fetch_array($res, MYSQL_ASSOC))
+		while ($course = Database::fetch_array($res, 'ASSOC'))
 		{
 			$courses[] = $course;
 		}
@@ -190,11 +190,11 @@ class ClassManager
 		$tbl_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
 		$tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
 		$tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
-		$sql = "INSERT IGNORE INTO $tbl_course_class SET course_code = '".mysql_real_escape_string($course_code)."', class_id = '".mysql_real_escape_string($class_id)."'";
+		$sql = "INSERT IGNORE INTO $tbl_course_class SET course_code = '".Database::escape_string($course_code)."', class_id = '".Database::escape_string($class_id)."'";
 		Database::query($sql, __FILE__, __LINE__);
-		$sql = "SELECT user_id FROM $tbl_class_user WHERE class_id = '".mysql_real_escape_string($class_id)."'";
+		$sql = "SELECT user_id FROM $tbl_class_user WHERE class_id = '".Database::escape_string($class_id)."'";
 		$res = Database::query($sql, __FILE__, __LINE__);
-		while ($user = mysql_fetch_object($res))
+		while ($user = Database::fetch_object($res))
 		{
 			CourseManager :: subscribe_user($user->user_id, $course_code);
 		}
@@ -210,11 +210,11 @@ class ClassManager
 	{
 		$tbl_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
 		$tbl_class_user = Database :: get_main_table(TABLE_MAIN_CLASS_USER);
-		$sql = "SELECT cu.user_id,COUNT(cc.class_id) FROM $tbl_course_class cc, $tbl_class_user cu WHERE  cc.class_id = cu.class_id AND cc.course_code = '".mysql_real_escape_string($course_code)."' GROUP BY cu.user_id HAVING COUNT(cc.class_id) = 1";
+		$sql = "SELECT cu.user_id,COUNT(cc.class_id) FROM $tbl_course_class cc, $tbl_class_user cu WHERE  cc.class_id = cu.class_id AND cc.course_code = '".Database::escape_string($course_code)."' GROUP BY cu.user_id HAVING COUNT(cc.class_id) = 1";
 		$single_class_users = Database::query($sql, __FILE__, __LINE__);
-		while ($single_class_user = mysql_fetch_object($single_class_users))
+		while ($single_class_user = Database::fetch_object($single_class_users))
 		{
-			$sql = "SELECT * FROM $tbl_class_user WHERE class_id = '".mysql_real_escape_string($class_id)."' AND user_id = '".mysql_real_escape_string($single_class_user->user_id)."'";
+			$sql = "SELECT * FROM $tbl_class_user WHERE class_id = '".Database::escape_string($class_id)."' AND user_id = '".Database::escape_string($single_class_user->user_id)."'";
 			$res = Database::query($sql, __FILE__, __LINE__);
 			if (mysql_num_rows($res) > 0)
 			{
@@ -224,7 +224,7 @@ class ClassManager
 				}
 			}
 		}
-		$sql = "DELETE FROM $tbl_course_class WHERE course_code = '".mysql_real_escape_string($course_code)."' AND class_id = '".mysql_real_escape_string($class_id)."'";
+		$sql = "DELETE FROM $tbl_course_class WHERE course_code = '".Database::escape_string($course_code)."' AND class_id = '".Database::escape_string($class_id)."'";
 		Database::query($sql, __FILE__, __LINE__);
 	}
 
@@ -238,7 +238,7 @@ class ClassManager
 		$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
 		$sql = "SELECT * FROM $table_class WHERE name='".$name."'";
 		$res = Database::query($sql, __FILE__, __LINE__);
-		$obj = mysql_fetch_object($res);
+		$obj = Database::fetch_object($res);
 		return $obj->id;
 	}
 	/**
@@ -250,10 +250,10 @@ class ClassManager
 	{
 		$table_class = Database :: get_main_table(TABLE_MAIN_CLASS);
 		$table_course_class = Database :: get_main_table(TABLE_MAIN_COURSE_CLASS);
-		$sql = "SELECT cl.* FROM $table_class cl, $table_course_class cc WHERE cc.course_code = '".mysql_real_escape_string($course_code)."' AND cc.class_id = cl.id";
+		$sql = "SELECT cl.* FROM $table_class cl, $table_course_class cc WHERE cc.course_code = '".Database::escape_string($course_code)."' AND cc.class_id = cl.id";
 		$res = Database::query($sql, __FILE__, __LINE__);
 		$classes = array ();
-		while ($class = mysql_fetch_array($res, MYSQL_ASSOC))
+		while ($class = Database::fetch_array($res, 'ASSOC'))
 		{
 			$classes[] = $class;
 		}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 283 - 428
main/inc/lib/course.lib.php


+ 11 - 13
main/inc/lib/database.lib.php

@@ -642,17 +642,6 @@ class Database {
 		return $obj->n;
 	}
 
-	/**
-	 * Gets the ID of the last item inserted into the database
-	 *
-	 * @author Yannick Warnier <yannick.warnier@dokeos.com>
-	 * @return integer The last ID as returned by the DB function
-	 * @comment This should be updated to use ADODB at some point
-	 */
-	public static function get_last_insert_id() {
-		return mysql_insert_id();
-	}
-
 	/**
 	 * Escapes a string to insert into the database as text
 	 * @param string		The string to escape
@@ -724,8 +713,10 @@ class Database {
 	}
 
 	/**
-	 * Recovers the last ID of any insert query executed over this SQL connection
-	 * @return	integer	Unique ID of the latest inserted row
+	 * Gets the ID of the last item inserted into the database
+	 *
+	 * @return integer The last ID as returned by the DB function
+	 * @comment This should be updated to use ADODB at some point
 	 */
 	public static function insert_id() {
 		return mysql_insert_id();
@@ -818,5 +809,12 @@ class Database {
 		return api_get_language_isocode($language);
 	}
 
+	/**
+	 * @deprecated Use Database::insert_id() instead.
+	 */
+	public static function get_last_insert_id() {
+		return mysql_insert_id();
+	}
+
 }
 //end class Database

+ 1 - 1
main/inc/lib/events.lib.inc.php

@@ -450,7 +450,7 @@ function create_event_exercice($exo_id)
 	$sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id )
 			VALUES (  ".$user_id.",  '".$_cid."' )";
 	$res = @Database::query($sql,__FILE__,__LINE__);
-	$id= Database::get_last_insert_id();
+	$id= Database::insert_id();
 	return $id;
 }
 

+ 2 - 2
main/inc/lib/fileManage.lib.php

@@ -69,7 +69,7 @@ function update_db_info($action, $oldPath, $newPath="")
             $mdType = (substr($dbTable, -13) == 'scormdocument') ?
                 'Scorm' : 'Document';
 
-            while ($row = mysql_fetch_array($result))
+            while ($row = Database::fetch_array($result))
             {
                 $eid = $mdType . '.' . $row['id'];
                 $mdStore->mds_delete($eid);
@@ -783,7 +783,7 @@ class FileManager
 		$sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'";
 		//api_display_debug_info($sql_query);
 		$sql_result = Database::query($sql_query,__FILE__,__LINE__);
-		$result = mysql_fetch_array($sql_result);
+		$result = Database::fetch_array($sql_result);
 
 		//determine which query to execute
 		if( $result["number_existing"] > 0 )

+ 3 - 3
main/inc/lib/fileUpload.lib.php

@@ -1163,9 +1163,9 @@ function add_document($_course,$path,$filetype,$filesize,$title,$comment=NULL, $
 	(`path`, `filetype`, `size`, `title`, `comment`, `readonly`, `session_id`)
 	VALUES ('$path','$filetype','$filesize','".
 	Database::escape_string(htmlspecialchars($title, ENT_QUOTES, $charset))."', '$comment', $readonly, $session_id)";
-	if(api_sql_query($sql,__FILE__,__LINE__))
+	if(Database::query($sql,__FILE__,__LINE__))
 	{
-		//display_message("Added to database (id ".mysql_insert_id().")!");
+		//display_message("Added to database (id ".Database::insert_id().")!");
 		return Database::insert_id();
 	}
 	else
@@ -1318,7 +1318,7 @@ function set_default_settings($upload_path,$filename,$filetype="file")
 	//$query="select count(*) as bestaat from `$dbTable` where path='$upload_path/$filename'";
 	$query="select count(*) as bestaat from $dbTable where path='$upload_path/$filename'";
 	$result=Database::query($query,__FILE__,__LINE__);
-	$row=mysql_fetch_array($result);
+	$row=Database::fetch_array($result);
 	if($row["bestaat"]>0)
 		//$query="update `$dbTable` set path='$upload_path/$filename',visibility='$default_visibility', filetype='$filetype' where path='$upload_path/$filename'";
 		$query="update $dbTable set path='$upload_path/$filename',visibility='$default_visibility', filetype='$filetype' where path='$upload_path/$filename'";

+ 127 - 127
main/inc/lib/main_api.lib.php

@@ -1425,29 +1425,29 @@ function api_get_session_info($session_id) {
 		$sesion_id = intval(Database::escape_string($session_id));
 		$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 		$sql = "SELECT * FROM $tbl_session WHERE id = $session_id";
-		$result = api_sql_query($sql,__FILE__,__LINE__);
-		
-	    if (Database::num_rows($result)>0) {    
+		$result = Database::query($sql,__FILE__,__LINE__);
+
+	    if (Database::num_rows($result)>0) {
 	    	$data = Database::fetch_array($result, 'ASSOC');
 	    }
 	}
-	return $data;	
+	return $data;
 }
 
 /**
  * Gets the session visibility by session id
  * @param   int	session id
  * @return  int	0 = session still available, SESSION_VISIBLE_READ_ONLY = 1, SESSION_VISIBLE = 2, SESSION_INVISIBLE = 3
- */				
-function api_get_session_visibility($session_id) {	
+ */
+function api_get_session_visibility($session_id) {
 	$visibility = 0; //means that the session is still available
 	if (!empty($session_id)) {
 		$sesion_id = intval(Database::escape_string($session_id));
 		$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
-		
+
 		$is_coach = api_is_course_coach();
-		
-		$condition_date_end = "";		
+
+		$condition_date_end = "";
 		if ($is_coach) {
 			$condition_date_end = " AND (CURDATE() > (SELECT adddate(date_end,nb_days_access_after_end) FROM $tbl_session WHERE id = $session_id) AND date_end != '0000-00-00') ";
 		} else {
@@ -1455,9 +1455,9 @@ function api_get_session_visibility($session_id) {
 		}
 
 		$sql = "SELECT visibility FROM $tbl_session
-				WHERE id = $session_id $condition_date_end "; // session is old and is not unlimited					
+				WHERE id = $session_id $condition_date_end "; // session is old and is not unlimited
 
-		$result = api_sql_query($sql,__FILE__,__LINE__);
+		$result = Database::query($sql,__FILE__,__LINE__);
 
 	    if (Database::num_rows($result)>0) {
 	    	$row = Database::fetch_array($result, 'ASSOC');
@@ -1466,32 +1466,32 @@ function api_get_session_visibility($session_id) {
 	    	$visibility = 0;
 	    }
 	}
-	return $visibility;	
+	return $visibility;
 }
 /**
  * Gets the visibility of an session of a course that a student have
  * @param   int     session id
- * @param   string  Dokeos course code 
- * @param   int     user id 
+ * @param   string  Dokeos course code
+ * @param   int     user id
  * @return  int  	0= Session available (in date), SESSION_VISIBLE_READ_ONLY = 1, SESSION_VISIBLE = 2, SESSION_INVISIBLE = 3
- */		
-function api_get_session_visibility_by_user($session_id,$course_code, $user_id) {	
+ */
+function api_get_session_visibility_by_user($session_id,$course_code, $user_id) {
 	$visibility = 0; //means that the session is still available
 	if (!empty($session_id) && !empty($user_id)){
 		$sesion_id = intval(Database::escape_string($session_id));
 		$user_id = intval(Database::escape_string($user_id));
 		$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION_REL_COURSE_REL_USER);
 		$sql = "SELECT visibility FROM $tbl_session
-				WHERE id_session = $session_id AND id_user = $user_id AND course_code = '$course_code'"; // session old		
-		$result = api_sql_query($sql,__FILE__,__LINE__);		
-	    if (Database::num_rows($result)>0) {    
+				WHERE id_session = $session_id AND id_user = $user_id AND course_code = '$course_code'"; // session old
+		$result = Database::query($sql,__FILE__,__LINE__);
+	    if (Database::num_rows($result)>0) {
 	    	$row = Database::fetch_array($result, 'ASSOC');
 	    	$visibility = $row['visibility'];
 	    } else {
 	    	$visibility = 0;
 	    }
 	}
-	return $visibility;	
+	return $visibility;
 }
 
 /**
@@ -1516,22 +1516,22 @@ function api_get_session_image($session_id, $status_id) {
  * This function add an additional condition according to the session of the course
  * @param int	session id
  * @param bool	optional, true if more than one condition false if the only condition in the query
- * @param bool	optional, true if condition is only with session_id = current session id, false if condition is with 0 else 
+ * @param bool	optional, true if condition is only with session_id = current session id, false if condition is with 0 else
  * @return string	condition of the session
  */
 function api_get_session_condition($session_id, $state = true, $both = false) {
 
-	$session_id = intval($session_id);	
-			
+	$session_id = intval($session_id);
+
 	//condition to show resources by session
 	$condition_session = '';
 	$condition_add = $state == false ? " WHERE " : " AND ";
 	if ($session_id > 0) {
-		if (api_is_session_in_category($session_id,'20091U') || $both) {						
-			$condition_session = $condition_add . " ( session_id = ".(int)$session_id." OR session_id = 0 ) ";	
+		if (api_is_session_in_category($session_id,'20091U') || $both) {
+			$condition_session = $condition_add . " ( session_id = ".(int)$session_id." OR session_id = 0 ) ";
 		} else {
 			$condition_session = $condition_add . "  session_id = ".(int)$session_id." ";
-		}		
+		}
 	} else {
 		$condition_session = $condition_add . " session_id = 0 ";
 	}
@@ -1540,7 +1540,7 @@ function api_get_session_condition($session_id, $state = true, $both = false) {
 }
 
 /**
- * This function returns information about coachs from a course in session 
+ * This function returns information about coachs from a course in session
  * @param int	- optional, session id
  * @param string - optional, course code
  * @return array  -	array containing user_id, lastname, firstname, username.
@@ -1550,29 +1550,29 @@ function api_get_coachs_from_course($session_id=0,$course_code='') {
 	if (!empty($session_id)) {
 		$session_id = intval($session_id);
 	} else {
-		$session_id = api_get_session_id();		
+		$session_id = api_get_session_id();
 	}
-	
+
 	if (!empty($course_code)) {
 		$course_code = Database::escape_string($course_code);
 	} else {
-		$course_code = api_get_course_id();		
-	}		
+		$course_code = api_get_course_id();
+	}
 
 	$tbl_user 					= Database :: get_main_table(TABLE_MAIN_USER);
-	$tbl_session_course_user 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);	
+	$tbl_session_course_user 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 	$coachs = array();
 
 	$sql = "SELECT u.user_id,u.lastname,u.firstname,u.username FROM $tbl_user u,$tbl_session_course_user scu
-			WHERE u.user_id = scu.id_user AND scu.id_session = '$session_id' AND scu.course_code = '$course_code' AND scu.status = 2";																				
+			WHERE u.user_id = scu.id_user AND scu.id_session = '$session_id' AND scu.course_code = '$course_code' AND scu.status = 2";
 	$rs = Database::query($sql,__FILE__,__LINE__);
-	
+
 	if (Database::num_rows($rs) > 0) {
-		
+
 		while ($row = Database::fetch_array($rs)) {
 			$coachs[] = $row;
 		}
-		return $coachs;		
+		return $coachs;
 	} else {
 		return false;
 	}
@@ -1669,36 +1669,36 @@ function api_is_coach($session_id = 0, $course_code = '') {
 	if (!empty($session_id)) {
 		$session_id = intval($session_id);
 	} else {
-		$session_id = api_get_session_id();		
+		$session_id = api_get_session_id();
 	}
-	
+
 	if (!empty($course_code)) {
 		$course_code = Database::escape_string($course_code);
 	} else {
-		$course_code = api_get_course_id();		
-	}		
+		$course_code = api_get_course_id();
+	}
 
 	$sql = "SELECT DISTINCT id, name, date_start, date_end
 							FROM session
 							INNER JOIN session_rel_course_rel_user session_rc_ru
 								ON session_rc_ru.id_user = '".Database::escape_string($_user['user_id'])."'
-							WHERE session_rc_ru.course_code = '$course_code' AND session_rc_ru.status = 2 AND session_rc_ru.id_session = '$session_id'		
-							ORDER BY date_start, date_end, name";	
-																									
-	$result = api_sql_query($sql,__FILE__,__LINE__);
-	$sessionIsCoach = api_store_result($result);
-							
+							WHERE session_rc_ru.course_code = '$course_code' AND session_rc_ru.status = 2 AND session_rc_ru.id_session = '$session_id'
+							ORDER BY date_start, date_end, name";
+
+	$result = Database::query($sql,__FILE__,__LINE__);
+	$sessionIsCoach = Database::store_result($result);
+
 	$sql = "SELECT DISTINCT id, name, date_start, date_end
 							FROM session
 							WHERE session.id_coach =  '".Database::escape_string($_user['user_id'])."'
-							AND id = '$session_id'		
-							ORDER BY date_start, date_end, name";						
-															
-	$result = api_sql_query($sql,__FILE__,__LINE__);
-	$sessionIsCoach = array_merge($sessionIsCoach , api_store_result($result));	
+							AND id = '$session_id'
+							ORDER BY date_start, date_end, name";
+
+	$result = Database::query($sql,__FILE__,__LINE__);
+	$sessionIsCoach = array_merge($sessionIsCoach , Database::store_result($result));
 
 	return (count($sessionIsCoach) > 0);
-	
+
 }
 
 /**
@@ -1711,22 +1711,22 @@ function api_is_session_admin() {
 }
 
 /**
- * This function check is a session is assigned into a category 
+ * This function check is a session is assigned into a category
  * @param int	- session id
- * @param string - category name 
+ * @param string - category name
  * @return bool  -	true if is found, otherwise false
  */
 function api_is_session_in_category($session_id,$category_name) {
-	
+
 	$session_id = intval($session_id);
 	$category_name = Database::escape_string($category_name);
-	
+
 	$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 	$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
-	
+
 	$sql = "select 1 FROM $tbl_session WHERE $session_id IN (SELECT s.id FROM $tbl_session s, $tbl_session_category sc  WHERE s.session_category_id = sc.id AND sc.name LIKE '%$category_name' )";
 	$rs = Database::query($sql,__FILE__,__LINE__);
-	
+
 	if (Database::num_rows($rs) > 0) {
 		return true;
 	} else {
@@ -1912,9 +1912,9 @@ function api_display_debug_info($debug_info) {
 */
 
 function api_is_allowed_to_edit($tutor=false,$coach=false,$session_coach = false) {
-	
+
 	$is_courseAdmin = api_is_course_admin() || api_is_platform_admin();
-	if (!$is_courseAdmin && $tutor == true) {	//if we also want to check if the user is a tutor...	    
+	if (!$is_courseAdmin && $tutor == true) {	//if we also want to check if the user is a tutor...
 		$is_courseAdmin = $is_courseAdmin || api_is_course_tutor();
 	}
 	if (!$is_courseAdmin && $coach == true) {	//if we also want to check if the user is a coach...';
@@ -1922,22 +1922,22 @@ function api_is_allowed_to_edit($tutor=false,$coach=false,$session_coach = false
 		// check if session visibility is read only for coachs
 		$is_allowed_coach_to_edit = api_is_course_coach();
 		$my_session_id = api_get_session_id();
-		$session_visibility = api_get_session_visibility($my_session_id);				
+		$session_visibility = api_get_session_visibility($my_session_id);
 		if ($session_visibility==SESSION_VISIBLE_READ_ONLY) {
 			$is_allowed_coach_to_edit = false;
-		}		
-					
+		}
+
 		if (api_get_setting('allow_coach_to_edit_course_session') == 'true') { // check if coach is allowed to edit a course
 			$is_courseAdmin = $is_courseAdmin || $is_allowed_coach_to_edit;
 		} else {
 			$is_courseAdmin = $is_courseAdmin;
-		}				
-		
+		}
+
 	}
-	if (!$is_courseAdmin && $session_coach == true) {	
+	if (!$is_courseAdmin && $session_coach == true) {
 		$is_courseAdmin = $is_courseAdmin || api_is_coach();
 	}
-	
+
 	if (api_get_setting('student_view_enabled') == 'true') {	//check if the student_view is enabled, and if so, if it is activated
 		$is_allowed = $is_courseAdmin && $_SESSION['studentview'] != "studentview";
 		return $is_allowed;
@@ -1947,31 +1947,31 @@ function api_is_allowed_to_edit($tutor=false,$coach=false,$session_coach = false
 }
 
 /**
-* Checks if a student can edit contents in a session depending 
-* on the session visibility  
+* Checks if a student can edit contents in a session depending
+* on the session visibility
 * @param	bool	Whether to check if the user has the tutor role
 * @param	bool	Whether to check if the user has the coach role
 * @return boolean, true: the user has the rights to edit, false: he does not
 */
 function api_is_allowed_to_session_edit($tutor=false,$coach=false) {
 	if (api_is_allowed_to_edit($tutor, $coach)) {
-		// if I'm a teacher, I will return true in order to not affect the normal behaviour of Dokeos tools	
+		// if I'm a teacher, I will return true in order to not affect the normal behaviour of Dokeos tools
 		return true;
 	} else {
 		if (api_get_session_id()==0) {
-			// i'm not in a session so i will return true to not affect the normal behaviour of Dokeos tools			
+			// i'm not in a session so i will return true to not affect the normal behaviour of Dokeos tools
 			return true;
 		} else {
-			//I'm in a session and I'm a student 		
+			//I'm in a session and I'm a student
 			$session_id= api_get_session_id();
 			// Get the session visibility
-			$session_visibility = api_get_session_visibility($session_id);	//if 0 the session is still available 
+			$session_visibility = api_get_session_visibility($session_id);	//if 0 the session is still available
 			if ($session_visibility!=0) {
 				//@todo we could load the session_rel_course_rel_user permission to increase the level of detail
 				//echo api_get_user_id();
 				//echo api_get_course_id();
-								
-				switch($session_visibility) { 
+
+				switch($session_visibility) {
 					case SESSION_VISIBLE_READ_ONLY: //1
 					return false;
 					break;
@@ -2248,7 +2248,7 @@ function api_get_item_visibility($_course, $tool, $id) {
  * @desc update the item_properties table (if entry not exists, insert) of the course
  */
 function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $user_id, $to_group_id = 0, $to_user_id = NULL, $start_visible = 0, $end_visible = 0, $session_id = 0) {
-	
+
 	// definition of variables
 	$tool = Database::escape_string($tool);
 	$item_id = Database::escape_string($item_id);
@@ -2266,33 +2266,33 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
 	if (!empty($session_id)) {
 		$session_id = intval($session_id);
 	}
-	
+
 	// Definition of tables
-	$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']);		
-		
+	$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$_course['dbName']);
+
 	if ($to_user_id <= 0) {
 		$to_user_id = NULL; //no to_user_id set
 	}
-	
+
 	if (!is_null($to_user_id)) {
 		// $to_user_id has more priority than $to_group_id
 		$to_field = "to_user_id";
 		$to_value = $to_user_id;
 	} else {
-		// $to_user_id is not set	
+		// $to_user_id is not set
 		$to_field = "to_group_id";
 		$to_value = $to_group_id;
-	}	
-	
+	}
+
 	// set filters for $to_user_id and $to_group_id, with priority for $to_user_id
-	
+
 	$condition_session = "";
-	if (!empty($session_id)) {		
-		$condition_session = " AND id_session = '$session_id' ";		
+	if (!empty($session_id)) {
+		$condition_session = " AND id_session = '$session_id' ";
 	}
 
-	$filter = "tool='$tool' AND ref='$item_id' $condition_session ";	
-	
+	$filter = "tool='$tool' AND ref='$item_id' $condition_session ";
+
 	if ($item_id == "*") {
 		$filter = "tool='$tool' AND visibility<>'2' $condition_session"; // for all (not deleted) items of the tool
 	}
@@ -2313,79 +2313,79 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
 	switch ($lastedit_type) {
 		case "delete" : // delete = make item only visible for the platform admin
 			$visibility = '2';
-			
+
 			if (!empty($session_id)) {
-																	
-				// check if session id already exist into itemp_properties for updating visibility or add it  
+
+				// check if session id already exist into itemp_properties for updating visibility or add it
 				$sql = "select id_session FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref='$item_id' AND id_session = '$session_id'";
 				$rs = Database::query($sql,__FILE__,__LINE__);
-				if (Database::num_rows($rs) > 0) {					
+				if (Database::num_rows($rs) > 0) {
 					$sql = "UPDATE $TABLE_ITEMPROPERTY
 							SET lastedit_type='".str_replace('_', '', ucwords($tool))."Deleted', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility', id_session = '$session_id' $set_type
 							WHERE $filter";
 				} else {
-										
+
 					$sql = "INSERT INTO $TABLE_ITEMPROPERTY
 						   		  			(tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, id_session)
-						         	VALUES 	('$tool','$item_id','$time', '$user_id', '$time',	'$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";								         						         		
+						         	VALUES 	('$tool','$item_id','$time', '$user_id', '$time',	'$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";
 				}
-									
-			}	else {				
+
+			}	else {
 				$sql = "UPDATE $TABLE_ITEMPROPERTY
 										SET lastedit_type='".str_replace('_', '', ucwords($tool))."Deleted', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
-										WHERE $filter";	
+										WHERE $filter";
 			}
-						
+
 			break;
-		case "visible" : // change item to visible 
+		case "visible" : // change item to visible
 			$visibility = '1';
-			
+
 			if (!empty($session_id)) {
-																	
-				// check if session id already exist into itemp_properties for updating visibility or add it  
+
+				// check if session id already exist into itemp_properties for updating visibility or add it
 				$sql = "select id_session FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref='$item_id' AND id_session = '$session_id'";
 				$rs = Database::query($sql,__FILE__,__LINE__);
-				if (Database::num_rows($rs) > 0) {					
+				if (Database::num_rows($rs) > 0) {
 					$sql = "UPDATE $TABLE_ITEMPROPERTY
 							SET lastedit_type='".str_replace('_', '', ucwords($tool))."Visible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility', id_session = '$session_id' $set_type
 							WHERE $filter";
 				} else {
-										
+
 					$sql = "INSERT INTO $TABLE_ITEMPROPERTY
 						   		  			(tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, id_session)
-						         	VALUES 	('$tool','$item_id','$time', '$user_id', '$time',	'$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";								         						         		
+						         	VALUES 	('$tool','$item_id','$time', '$user_id', '$time',	'$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";
 				}
-									
-			}	else {				
+
+			}	else {
 				$sql = "UPDATE $TABLE_ITEMPROPERTY
 										SET lastedit_type='".str_replace('_', '', ucwords($tool))."Visible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
-										WHERE $filter";	
-			}												
-										
+										WHERE $filter";
+			}
+
 			break;
 		case "invisible" : // change item to invisible
-			$visibility = '0';			
-			if (!empty($session_id)) {				
-				// check if session id already exist into itemp_properties for updating visibility or add it  
+			$visibility = '0';
+			if (!empty($session_id)) {
+				// check if session id already exist into itemp_properties for updating visibility or add it
 				$sql = "Select id_session FROM $TABLE_ITEMPROPERTY WHERE tool = '$tool' AND ref='$item_id' AND id_session = '$session_id'";
 				$rs = Database::query($sql,__FILE__,__LINE__);
-				if (Database::num_rows($rs) > 0) {					
+				if (Database::num_rows($rs) > 0) {
 					$sql = "UPDATE $TABLE_ITEMPROPERTY
 							SET lastedit_type='".str_replace('_', '', ucwords($tool))."Invisible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility', id_session = '$session_id' $set_type
-							WHERE $filter";										
+							WHERE $filter";
 				} else {
 
 					$sql = "INSERT INTO $TABLE_ITEMPROPERTY
 						   		  			(tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, id_session)
-						         	VALUES 	('$tool','$item_id','$time', '$user_id', '$time',	'$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";											
+						         	VALUES 	('$tool','$item_id','$time', '$user_id', '$time',	'$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";
 				}
 
 			} else {
 				$sql = "UPDATE $TABLE_ITEMPROPERTY
 										SET lastedit_type='".str_replace('_', '', ucwords($tool))."Invisible', lastedit_date='$time', lastedit_user_id='$user_id', visibility='$visibility' $set_type
-										WHERE $filter";				
+										WHERE $filter";
 			}
-									
+
 			break;
 		default : // item will be added or updated
 			$set_type = ", lastedit_type='$lastedit_type' ";
@@ -2399,7 +2399,7 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
 	$res = mysql_query($sql);
 	// insert if no entries are found (can only happen in case of $lastedit_type switch is 'default')
 	if (mysql_affected_rows() == 0) {
-		
+
 		$sql = "INSERT INTO $TABLE_ITEMPROPERTY
 						   		  			(tool,ref,insert_date,insert_user_id,lastedit_date,lastedit_type,   lastedit_user_id,$to_field,  visibility,   start_visible,   end_visible, id_session)
 						         	VALUES 	('$tool','$item_id','$time',    '$user_id',	   '$time',		 '$lastedit_type','$user_id',	   '$to_value','$visibility','$start_visible','$end_visible', '$session_id')";
@@ -2957,7 +2957,7 @@ function copy_folder_course_session($pathname, $base_path_document,$session_id,$
     if (is_dir($pathname) || empty($pathname)) {
         return true;
     }
- 
+
     // Ensure a file does not already exist with the same name
     if (is_file($pathname)) {
         trigger_error('mkdirr() File exists', E_USER_WARNING);
@@ -2967,31 +2967,31 @@ function copy_folder_course_session($pathname, $base_path_document,$session_id,$
     $folders = explode(DIRECTORY_SEPARATOR,str_replace($base_path_document.DIRECTORY_SEPARATOR,'',$pathname));
 
     $new_pathname = $base_path_document;
-    $path = ''; 
+    $path = '';
 
     foreach ($folders as $folder) {
 	$new_pathname .= DIRECTORY_SEPARATOR.$folder;
 	$path .= DIRECTORY_SEPARATOR.$folder;
 
 	if (!file_exists($new_pathname)) {
-		
+
 		$sql = "SELECT * FROM $table WHERE path = '$path' AND filetype = 'folder' AND session_id = '$session_id'";
 		$rs1  = Database::query($sql,__FILE__,__LINE__);
 		$num_rows = Database::num_rows($rs1);
 
-		if ($num_rows == 0) { 		
+		if ($num_rows == 0) {
 			if (mkdir($new_pathname)) {
 				$perm = api_get_setting('permissions_for_new_directories');
 				$perm = octdec(!empty($perm)?$perm:'0770');
 				chmod($new_pathname,$perm);
-			}		
-			// Insert new folder with destination session_id 
+			}
+			// Insert new folder with destination session_id
 			$sql = "INSERT INTO ".$table." SET path = '$path', comment = '".Database::escape_string($document->comment)."', title = '".Database::escape_string(basename($new_pathname))."' ,filetype='folder', size= '0', session_id = '$session_id'";
 			Database::query($sql, __FILE__, __LINE__);
-			$document_id = Database::insert_id();					
+			$document_id = Database::insert_id();
 			api_item_property_update($course_info,TOOL_DOCUMENT,$document_id,'FolderCreated',api_get_user_id(),0,0);
 		}
-	} 
+	}
 
     } // en foreach
 

+ 134 - 134
main/inc/lib/sessionmanager.lib.php

@@ -46,15 +46,15 @@ class SessionManager {
 	public static function create_session ($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility) {
 		global $_user;
 		$name= trim($sname);
-		$year_start= intval($syear_start); 
-		$month_start=intval($smonth_start); 
-		$day_start=intval($sday_start); 
-		$year_end=intval($syear_end); 
-		$month_end=intval($smonth_end); 
-		$day_end=intval($sday_end); 
-		$nb_days_acess_before = intval($snb_days_acess_before); 
-		$nb_days_acess_after = intval($snb_days_acess_after); 
-		$id_session_category = intval($id_session_category);		
+		$year_start= intval($syear_start);
+		$month_start=intval($smonth_start);
+		$day_start=intval($sday_start);
+		$year_end=intval($syear_end);
+		$month_end=intval($smonth_end);
+		$day_end=intval($sday_end);
+		$nb_days_acess_before = intval($snb_days_acess_before);
+		$nb_days_acess_after = intval($snb_days_acess_after);
+		$id_session_category = intval($id_session_category);
 		$id_visibility = intval($id_visibility);
 		$tbl_user		= Database::get_main_table(TABLE_MAIN_USER);
 		$tbl_session	= Database::get_main_table(TABLE_MAIN_SESSION);
@@ -92,12 +92,12 @@ class SessionManager {
 				$msg=get_lang('SessionNameAlreadyExists');
 				return $msg;
 			} else {
-				$sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility) 
+				$sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility)
 							   VALUES('".Database::escape_string($name)."','$date_start','$date_end','$id_coach',".intval($_user['user_id']).",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")";
 				Database::query($sql_insert ,__FILE__,__LINE__);
-				$id_session=Database::get_last_insert_id();	
-								
-				// add event to system log		
+				$id_session=Database::insert_id();
+
+				// add event to system log
 				$time = time();
 				$user_id = api_get_user_id();
 				event_system(LOG_SESSION_CREATE, LOG_SESSION_ID, $id_session, $time, $user_id);
@@ -139,7 +139,7 @@ class SessionManager {
 		$nb_days_acess_after = intval($nb_days_acess_after);
 		$id_session_category = intval($id_session_category);
 		$id_visibility = intval($id_visibility);
-		
+
 		$tbl_user		= Database::get_main_table(TABLE_MAIN_USER);
 		$tbl_session	= Database::get_main_table(TABLE_MAIN_SESSION);
 		$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
@@ -184,9 +184,9 @@ class SessionManager {
 						date_start='".$date_start."',
 						date_end='".$date_end."',
 						id_coach='".$id_coach."',
-						nb_days_access_before_beginning = ".$nb_days_acess_before.",  
-						nb_days_access_after_end = ".$nb_days_acess_after.", 
-						session_category_id = ".$id_session_category." , 
+						nb_days_access_before_beginning = ".$nb_days_acess_before.",
+						nb_days_access_after_end = ".$nb_days_acess_after.",
+						session_category_id = ".$id_session_category." ,
 						visibility= ".$id_visibility."
 					  WHERE id='$id'";
 				Database::query($sql,__FILE__,__LINE__);
@@ -203,8 +203,8 @@ class SessionManager {
 	 * @author Carlos Vargas <carlos.vargas@dokeos.com>, from existing code
 	 * @param	array	id_checked
 	 * @param   boolean  optional, true if the function is called by a webservice, false otherwise.
-     * @return	void	Nothing, or false on error 
-	 * The parameters is a array to delete sessions 
+     * @return	void	Nothing, or false on error
+	 * The parameters is a array to delete sessions
 	 **/
 	public static function delete_session ($id_checked,$from_ws = false) {
 		$tbl_session=						Database::get_main_table(TABLE_MAIN_SESSION);
@@ -218,7 +218,7 @@ class SessionManager {
 		} else {
 			$id_checked=intval($id_checked);
 		}
-		
+
 		if (!api_is_platform_admin() && !$from_ws) {
 			$sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_checked;
 			$rs = Database::query($sql,__FILE__,__LINE__);
@@ -234,32 +234,32 @@ class SessionManager {
 		// delete extra session fields
 		$t_sf 		= Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
 		$t_sfv 		= Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
-		
+
 		// Delete extra fields from session where field variable is "SECCION"
 		$sql = "SELECT t_sfv.field_id FROM $t_sfv t_sfv, $t_sf t_sf  WHERE t_sfv.session_id = '$id_checked' AND t_sf.field_variable = 'SECCION' ";
 		$rs_field = Database::query($sql,__FILE__,__LINE__);
-				
+
 		$field_id = 0;
 		if (Database::num_rows($rs_field) == 1) {
 			$row_field = Database::fetch_row($rs_field);
 			$field_id = $row_field[0];
-			
+
 			$sql_delete_sfv = "DELETE FROM $t_sfv WHERE session_id = '$id_checked' AND field_id = '$field_id'";
-			$rs_delete_sfv = Database::query($sql_delete_sfv,__FILE__,__LINE__);										
+			$rs_delete_sfv = Database::query($sql_delete_sfv,__FILE__,__LINE__);
 		}
-		
+
 		$sql = "SELECT * FROM $t_sfv WHERE field_id = '$field_id' ";
 		$rs_field_id = Database::query($sql,__FILE__,__LINE__);
-		
+
 		if (Database::num_rows($rs_field_id) == 0) {
 			$sql_delete_sf = "DELETE FROM $t_sf WHERE id = '$field_id'";
-			$rs_delete_sf = Database::query($sql_delete_sf,__FILE__,__LINE__);	
+			$rs_delete_sf = Database::query($sql_delete_sf,__FILE__,__LINE__);
 		}
 
 		/*
 		$sql = "SELECT distinct field_id FROM $t_sfv  WHERE session_id = '$id_checked'";
-		$res_field_ids = @api_sql_query($sql,__FILE__,__LINE__);
-		
+		$res_field_ids = @Database::query($sql,__FILE__,__LINE__);
+
 		if (Database::num_rows($res_field_ids) > 0) {
 			while($row_field_id = Database::fetch_row($res_field_ids)){
 				$field_ids[] = $row_field_id[0];
@@ -269,11 +269,11 @@ class SessionManager {
 		//delete from table_session_field_value from a given session id
 
 		$sql_session_field_value = "DELETE FROM $t_sfv WHERE session_id = '$id_checked'";
-		@api_sql_query($sql_session_field_value,__FILE__,__LINE__);
+		@Database::query($sql_session_field_value,__FILE__,__LINE__);
 
 		$sql = "SELECT distinct field_id FROM $t_sfv";
-		$res_field_all_ids = @api_sql_query($sql,__FILE__,__LINE__);
-		
+		$res_field_all_ids = @Database::query($sql,__FILE__,__LINE__);
+
 		if (Database::num_rows($res_field_all_ids) > 0) {
 			while($row_field_all_id = Database::fetch_row($res_field_all_ids)){
 				$field_all_ids[] = $row_field_all_id[0];
@@ -282,17 +282,17 @@ class SessionManager {
 
 		if (count($field_ids) > 0 && count($field_all_ids) > 0) {
 			foreach($field_ids as $field_id) {
-				// check if field id is used into table field value				
+				// check if field id is used into table field value
 				if (in_array($field_id,$field_all_ids)) {
 					continue;
 				} else {
 					$sql_session_field = "DELETE FROM $t_sf WHERE id = '$field_id'";
-					api_sql_query($sql_session_field,__FILE__,__LINE__);
-				}	
-			}			
+					Database::query($sql_session_field,__FILE__,__LINE__);
+				}
+			}
 		}
 		*/
-		// add event to system log		
+		// add event to system log
 		$time = time();
 		$user_id = api_get_user_id();
 		event_system(LOG_SESSION_DELETE, LOG_SESSION_ID, $id_checked, $time, $user_id);
@@ -309,7 +309,7 @@ class SessionManager {
 	  * @return	void		Nothing, or false on error
 	  **/
 	public static function suscribe_users_to_session ($id_session,$user_list, $visibility=SESSION_VISIBLE_READ_ONLY, $empty_users=true) {
-	 	
+
 	  	if ($id_session!= strval(intval($id_session))) return false;
 	   	foreach($user_list as $intUser){
 	   		if ($intUser!= strval(intval($intUser))) return false;
@@ -318,17 +318,17 @@ class SessionManager {
 		$tbl_session_rel_course_rel_user	= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 	   	$tbl_session_rel_user 				= Database::get_main_table(TABLE_MAIN_SESSION_USER);
 	   	$tbl_session						= Database::get_main_table(TABLE_MAIN_SESSION);
-	   	
-	   	if (empty($visibility)) {	   		
+
+	   	if (empty($visibility)) {
 	   		$sql = "SELECT visibility FROM $tbl_session WHERE id_session='$id_session'";
-			$result = api_sql_query($sql,__FILE__,__LINE__);
+			$result = Database::query($sql,__FILE__,__LINE__);
 			$row = Database::fetch_array($result);
 			$visibility = $row['visibility'];
 			if (empty($visibility))
 				$visibility = SESSION_VISIBLE_READ_ONLY; // by default readonly 1
 	   	}
-	   	
-		
+
+
 	   	$sql = "SELECT id_user FROM $tbl_session_rel_user WHERE id_session='$id_session'";
 		$result = Database::query($sql,__FILE__,__LINE__);
 		$existingUsers = array();
@@ -516,7 +516,7 @@ class SessionManager {
 						                tms = FROM_UNIXTIME($time)";
 			$result = Database::query($sql,__FILE__,__LINE__);
 
-			$field_id=Database::get_last_insert_id();
+			$field_id=Database::insert_id();
 		}
 		return $field_id;
 	}
@@ -630,16 +630,16 @@ class SessionManager {
 	public static function get_session_by_name ($session_name) {
 		$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
 		$sql = 'SELECT id, id_coach, date_start, date_end FROM '.$tbl_session.' WHERE name="'.Database::escape_string($session_name).'"';
-		$result = api_sql_query($sql,  __FILE__, __LINE__);
+		$result = Database::query($sql,  __FILE__, __LINE__);
 		$num = Database::num_rows($result);
 		if ($num>0){
-			return Database::fetch_array($result);	
+			return Database::fetch_array($result);
 		} else {
 			return false;
 		}
 	}
-	
-	/** 
+
+	/**
 	  * Create a session category
 	  * @author Jhon Hinojosa <jhon.hinojosa@dokeos.com>, from existing code
 	  * @param	string 		name
@@ -654,16 +654,16 @@ class SessionManager {
 	public static function create_category_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end, $sday_end){
 		$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
 		$name= trim($sname);
-		$year_start= intval($syear_start); 
-		$month_start=intval($smonth_start); 
-		$day_start=intval($sday_start); 
-		$year_end=intval($syear_end); 
-		$month_end=intval($smonth_end); 
+		$year_start= intval($syear_start);
+		$month_start=intval($smonth_start);
+		$day_start=intval($sday_start);
+		$year_end=intval($syear_end);
+		$month_end=intval($smonth_end);
 		$day_end=intval($sday_end);
-		
+
 		$date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
 		$date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
-				
+
 		if (empty($name)) {
 			$msg=get_lang('SessionCategoryNameIsRequired');
 			return $msg;
@@ -672,24 +672,24 @@ class SessionManager {
 			return $msg;
 		} elseif (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end)) {
 			$msg=get_lang('InvalidEndDate');
-			return $msg;			
+			return $msg;
 		} elseif($date_start >= $date_end) {
 			$msg=get_lang('StartDateShouldBeBeforeEndDate');
 			return $msg;
 		} else {
 			$sql = "INSERT INTO $tbl_session_category(name, date_start, date_end) VALUES('".Database::escape_string($name)."','$date_start','$date_end')";
-			api_sql_query($sql ,__FILE__,__LINE__);
-			$id_session=Database::get_last_insert_id();
+			Database::query($sql ,__FILE__,__LINE__);
+			$id_session=Database::insert_id();
 			// add event to system log
 			$time = time();
 			$user_id = api_get_user_id();
 			event_system(LOG_SESSION_CATEGORY_CREATE, LOG_SESSION_CATEGORY_ID, $id_session, $time, $user_id);
 			return $id_session;
-		}	
+		}
 	}
-	
-	/** 
-	 * Edit a sessions categories 
+
+	/**
+	 * Edit a sessions categories
 	 * @author Jhon Hinojosa <jhon.hinojosa@dokeos.com>,from existing code
 	 * @param	integer		id
 	 * @param	string 		name
@@ -705,16 +705,16 @@ class SessionManager {
 	public static function edit_category_session($id, $sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end, $sday_end){
 		$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
 		$name= trim($sname);
-		$year_start= intval($syear_start); 
-		$month_start=intval($smonth_start); 
-		$day_start=intval($sday_start); 
-		$year_end=intval($syear_end); 
-		$month_end=intval($smonth_end); 
+		$year_start= intval($syear_start);
+		$month_start=intval($smonth_start);
+		$day_start=intval($sday_start);
+		$year_end=intval($syear_end);
+		$month_end=intval($smonth_end);
 		$day_end=intval($sday_end);
 		$id=intval($id);
 		$date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
 		$date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
-		
+
 		if (empty($name)) {
 			$msg=get_lang('SessionCategoryNameIsRequired');
 			return $msg;
@@ -723,83 +723,83 @@ class SessionManager {
 			return $msg;
 		} elseif (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end)) {
 			$msg=get_lang('InvalidEndDate');
-			return $msg;			
+			return $msg;
 		} elseif($date_start >= $date_end) {
 			$msg=get_lang('StartDateShouldBeBeforeEndDate');
 			return $msg;
 		} else {
-			$sql = "UPDATE $tbl_session_category SET name = '".Database::escape_string($name)."', date_start = '$date_start', date_end = '$date_end' 
+			$sql = "UPDATE $tbl_session_category SET name = '".Database::escape_string($name)."', date_start = '$date_start', date_end = '$date_end'
 					WHERE id= '".$id."' ";
-			$result = api_sql_query($sql, __FILE__,__LINE__);
+			$result = Database::query($sql, __FILE__,__LINE__);
 			return ($result? true:false);
 		}
 	}
-	
-	/** 
-	 * Delete sessions categories 
+
+	/**
+	 * Delete sessions categories
 	 * @author Jhon Hinojosa <jhon.hinojosa@dokeos.com>, from existing code
 	 * @param	array	id_checked
 	 * @param	bool	include delete session
 	 * @param	bool	optional, true if the function is called by a webservice, false otherwise.
-     * @return	void	Nothing, or false on error 
-	 * The parameters is a array to delete sessions 
+     * @return	void	Nothing, or false on error
+	 * The parameters is a array to delete sessions
 	 **/
 	public static function delete_session_category($id_checked, $delete_session = false,$from_ws = false){
 		$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
 		$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
-		if(is_array($id_checked)) { 
+		if(is_array($id_checked)) {
 			$id_checked=Database::escape_string(implode(',',$id_checked));
 		} else {
 			$id_checked=intval($id_checked);
 		}
 		$sql = "SELECT id FROM $tbl_session WHERE session_category_id IN (".$id_checked.")";
-		$result = @api_sql_query($sql,__FILE__,__LINE__);
+		$result = @Database::query($sql,__FILE__,__LINE__);
 		while ($rows = Database::fetch_array($result)) {
 			$session_id = $rows['id'];
 			if($delete_session == true){
 				if ($from_ws) {
-					SessionManager::delete_session($session_id,true);										
-				} else {					
-					SessionManager::delete_session($session_id);						
-				}																				
+					SessionManager::delete_session($session_id,true);
+				} else {
+					SessionManager::delete_session($session_id);
+				}
 			}
-		}		
+		}
 		$sql = "DELETE FROM $tbl_session_category WHERE id IN (".$id_checked.")";
-		$rs = @api_sql_query($sql,__FILE__,__LINE__);
+		$rs = @Database::query($sql,__FILE__,__LINE__);
 		$result = Database::affected_rows();
-		
+
 		// add event to system log
 		$time = time();
 		$user_id = api_get_user_id();
 		event_system(LOG_SESSION_CATEGORY_DELETE, LOG_SESSION_CATEGORY_ID, $id_checked, $time, $user_id);
-		
-		
+
+
 		// delete extra session fields where field variable is "PERIODO"
 		$t_sf 		= Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
 		$t_sfv 		= Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
-		
+
 		$sql = "SELECT t_sfv.field_id FROM $t_sfv t_sfv, $t_sf t_sf  WHERE t_sfv.session_id = '$id_checked' AND t_sf.field_variable = 'PERIODO' ";
 		$rs_field = Database::query($sql,__FILE__,__LINE__);
-		
+
 		$field_id = 0;
 		if (Database::num_rows($rs_field) > 0) {
 			$row_field = Database::fetch_row($rs_field);
-			$field_id = $row_field[0];			
+			$field_id = $row_field[0];
 			$sql_delete_sfv = "DELETE FROM $t_sfv WHERE session_id = '$id_checked' AND field_id = '$field_id'";
 			$rs_delete_sfv = Database::query($sql_delete_sfv,__FILE__,__LINE__);
-		} 
+		}
 
 		$sql = "SELECT * FROM $t_sfv WHERE field_id = '$field_id' ";
 		$rs_field_id = Database::query($sql,__FILE__,__LINE__);
-		
+
 		if (Database::num_rows($rs_field_id) == 0) {
 			$sql_delete_sf = "DELETE FROM $t_sf WHERE id = '$field_id'";
-			$rs_delete_sf = Database::query($sql_delete_sf,__FILE__,__LINE__);	
+			$rs_delete_sf = Database::query($sql_delete_sf,__FILE__,__LINE__);
 		}
-		
+
 		return true;
 	}
-	
+
 	/**
      * Get a list of sessions of which the given conditions match with an = 'cond'
 	 * @param array $conditions a list of condition (exemple : status=>STUDENT)
@@ -816,8 +816,8 @@ class SessionManager {
 		$return_array = array();
 
 		$sql_query = " SELECT s.id, s.name, s.nbr_courses, s.date_start, s.date_end, u.firstname, u.lastname , sc.name as category_name
-				FROM $session_table s 
-				INNER JOIN $user_table u ON s.id_coach = u.user_id 
+				FROM $session_table s
+				INNER JOIN $user_table u ON s.id_coach = u.user_id
 				LEFT JOIN  $session_category_table sc ON s.session_category_id = sc.id ";
 
 		if (count($conditions)>0) {
@@ -838,10 +838,10 @@ class SessionManager {
 		return $return_array;
 	}
 	/**
-	 * Get the session category information by id  
+	 * Get the session category information by id
 	 * @param string session category ID
-	 * @return mixed false if the session category does not exist, array if the session category exists  
-	 */	
+	 * @return mixed false if the session category does not exist, array if the session category exists
+	 */
 	public static function get_session_category ($id) {
 		$id = intval($id);
 		$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
@@ -854,85 +854,85 @@ class SessionManager {
 			return false;
 		}
 	}
-	
+
 	/**
-	 * Assign a coach to course in session with status = 2  
+	 * Assign a coach to course in session with status = 2
 	 * @param int  		- user id
 	 * @param int  		- session id
 	 * @param string  	- course code
 	 * @param bool  	- optional, if is true the user don't be a coach now, otherwise it'll assign a coach
-	 * @return bool true if there are affected rows, otherwise false  
-	 */	
+	 * @return bool true if there are affected rows, otherwise false
+	 */
 	function set_coach_to_course_session($user_id, $session_id = 0, $course_code = '',$nocoach = false) {
-		
-		// Definition of variables				
-		$user_id = intval($user_id);				
-		
-		if (!empty($session_id)) {			
-			$session_id = intval($session_id);			
+
+		// Definition of variables
+		$user_id = intval($user_id);
+
+		if (!empty($session_id)) {
+			$session_id = intval($session_id);
 		} else {
 			$session_id = api_get_session_id();
-		}				
-		
-		if (!empty($course_code)) {			
-			$course_code = Database::escape_string($course_code);			
+		}
+
+		if (!empty($course_code)) {
+			$course_code = Database::escape_string($course_code);
 		} else {
 			$course_code = api_get_course_id();
 		}
-		
-		// definitios of tables		
+
+		// definitios of tables
 		$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 		$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
 		$tbl_user	= Database::get_main_table(TABLE_MAIN_USER);
 
 		// check if user is a teacher
 		$sql= "SELECT * FROM $tbl_user WHERE status='1' AND user_id = '$user_id'";
-		
+
 		$rs_check_user = Database::query($sql,__FILE__,__LINE__);
-		
-		if (Database::num_rows($rs_check_user) > 0) {						
-			
+
+		if (Database::num_rows($rs_check_user) > 0) {
+
 			if ($nocoach) {
-				
+
 				// check if user_id exits int session_rel_user
 				$sql = "SELECT id_user FROM $tbl_session_rel_user WHERE id_session = '$session_id' AND id_user = '$user_id'";
 				$res = Database::query($sql,__FILE__,__LINE__);
-				
-				if (Database::num_rows($res) > 0) {					
-					// The user don't be a coach now					
+
+				if (Database::num_rows($res) > 0) {
+					// The user don't be a coach now
 					$sql = "UPDATE $tbl_session_rel_course_rel_user SET status = 0 WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
-					$rs_update = Database::query($sql,__FILE__,__LINE__);	
+					$rs_update = Database::query($sql,__FILE__,__LINE__);
 					if (Database::affected_rows() > 0) return true;
 					else return false;
 				} else {
-					// The user don't be a coach now					
+					// The user don't be a coach now
 					$sql = "DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
 					$rs_delete = Database::query($sql,__FILE__,__LINE__);
 					if (Database::affected_rows() > 0) return true;
 					else return false;
 				}
-							
+
 			} else {
-				// Assign user like a coach to course			
-				// First check if the user is registered in the course 
+				// Assign user like a coach to course
+				// First check if the user is registered in the course
 				$sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id'";
 				$rs_check = Database::query($sql,__FILE__,__LINE__);
-				
+
 				//Then update or insert
 				if (Database::num_rows($rs_check) > 0) {
 					$sql = "UPDATE $tbl_session_rel_course_rel_user SET status = 2 WHERE id_session = '$session_id' AND course_code = '$course_code' AND id_user = '$user_id' ";
 					$rs_update = Database::query($sql,__FILE__,__LINE__);
 					if (Database::affected_rows() > 0) return true;
-					else return false;						
+					else return false;
 				} else {
 					$sql = " INSERT INTO $tbl_session_rel_course_rel_user(id_session, course_code, id_user, status) VALUES('$session_id', '$course_code', '$user_id', 2)";
 					$rs_insert = Database::query($sql,__FILE__,__LINE__);
 					if (Database::affected_rows() > 0) return true;
-					else return false;				
-				}							
+					else return false;
+				}
 			}
 		} else {
 			return false;
 		}
-	}	
+	}
 }

+ 2 - 2
main/inc/lib/specific_fields_manager.lib.php

@@ -25,7 +25,7 @@ function add_specific_field($name) {
   $sql = sprintf($sql, $table_sf, $_safe_code, $_safe_name);
   $result = Database::query($sql,__FILE__,__LINE__);
   if ($result) {
-    return Database::get_last_insert_id();
+    return Database::insert_id();
   }
   else {
     return FALSE;
@@ -158,7 +158,7 @@ function add_specific_field_value($id_specific_field, $course_id, $tool_id, $ref
   $sql = sprintf($sql, $table_sf_values, $course_id, $tool_id, $ref_id, $id_specific_field, Database::escape_string($value));
   $result = Database::query($sql,__FILE__,__LINE__);
   if ($result) {
-    return Database::get_last_insert_id();
+    return Database::insert_id();
   }
   else {
     return FALSE;

+ 78 - 78
main/inc/lib/surveymanager.lib.php

@@ -48,7 +48,7 @@ class SurveyManager {
 			$str_survey_list .= "<select name=\"exiztingsurvey\" $extra_script>\n";
 			$str_survey_list .= "<option value=\"\">--Select Survey--</option>";
 
-			while($result=mysql_fetch_array($sql_result))
+			while($result=Database::fetch_array($sql_result))
 			{
 			 $selected = ($seleced_surveyid==$result[survey_id])?"selected":"";
 			 $str_survey_list .= "\n<option value=\"".$result[survey_id]."\" ".$selected.">".$result[title]."</option>";
@@ -96,11 +96,11 @@ class SurveyManager {
 
 			$sql = 'SELECT MAX(sortby) FROM '.$table_group.' WHERE survey_id="'.Database::escape_string($survey_id).'"';
 			$rs = Database::query($sql, __FILE__, __LINE__);
-			list($sortby) = mysql_fetch_array($rs);
+			list($sortby) = Database::fetch_array($rs);
 			$sortby++;
 			$sql="INSERT INTO $table_group(group_id,survey_id,groupname,introduction, sortby) values('','$survey_id','$group_title','$introduction','$sortby')";
 			$result=Database::query($sql);
-			return mysql_insert_id();
+			return Database::insert_id();
 		 }
 
 	}
@@ -162,7 +162,7 @@ class SurveyManager {
 
 		$sql="INSERT INTO $tb (group_id,survey_id,group_title,introduction) values('','$survey_id','$group_title','$introduction')";
 		$result=Database::query($sql);
-		return mysql_insert_id();
+		return Database::insert_id();
 	}
 	/**
 	 * Possible  deprecated method
@@ -188,7 +188,7 @@ class SurveyManager {
 		$sql_result = Database::query($sql_query,__FILE__,__LINE__);
 		echo "<select name=\"author\">";
 		echo "<option value=\"\"><--Select Survey--></optional>";
-		while ($result =@mysql_fetch_array($sql_result))
+		while ($result =@Database::fetch_array($sql_result))
 		{
 			echo "\n<option value=\"".$result[survey_id]."\">".$result[title]."</option>";
 		}
@@ -203,7 +203,7 @@ class SurveyManager {
 			$sql = "INSERT INTO $table_survey (code,title, subtitle, author,lang,avail_from,avail_till, is_shared,template,intro,surveythanks,creation_date) values('$surveycode','$surveytitle','$surveysubtitle','$author','$survey_language','$availablefrom','$availabletill','$isshare','$surveytemplate','$surveyintroduction','$surveythanks',curdate())";
 			$result = Database::query($sql, __FILE__, __LINE__);
 			//$result = Database::query($sql);
-			$survey_id = mysql_insert_id();
+			$survey_id = Database::insert_id();
 			$sql2 = "INSERT INTO $table_group(group_id,survey_id,groupname,introduction) values('','$survey_id','No Group','This is your Default Group')";
 			$result = Database::query($sql2, __FILE__, __LINE__);
 			return $survey_id;
@@ -233,7 +233,7 @@ class SurveyManager {
 					creation_date = "NOW()"';
 
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$new_survey_id = mysql_insert_id();
+		$new_survey_id = Database::insert_id();
 
 		// copy the groups
 		$groups = self::listGroups($id);
@@ -251,7 +251,7 @@ class SurveyManager {
 			//$table_survey = Database :: get_course_table(TABLE_SURVEY);
 			$sql = "INSERT INTO $table_survey (code,title, subtitle, author,lang,avail_from,avail_till, is_shared,template,intro,surveythanks,creation_date) values('$surveycode','$surveytitle','$surveysubtitle','$author','$survey_language','$availablefrom','$availabletill','$isshare','$surveytemplate','$surveyintroduction','$surveythanks',curdate())";
 			$result = Database::query($sql, __FILE__, __LINE__);
-			$survey_id = mysql_insert_id();
+			$survey_id = Database::insert_id();
 			return $survey_id;
 	}
 	/**
@@ -261,7 +261,7 @@ class SurveyManager {
 	{
           $sql_course = "SELECT * FROM $table_course WHERE code = '$cidReq'";
           $res_course = Database::query($sql_course,__FILE__,__LINE__);
-          $obj_course=@mysql_fetch_object($res_course);
+          $obj_course=@Database::fetch_object($res_course);
           $curr_dbname = $obj_course->db_name ;
           $surveyid = Database::escape_string($surveyid);
 		  $sql = "UPDATE $curr_dbname.survey SET code='$surveycode', title='$surveytitle', subtitle='$surveysubtitle', lang='$survey_language',   avail_from='$availablefrom', avail_till='$availabletill', is_shared='$isshare', template='$surveytemplate', intro='$surveyintroduction',surveythanks='$surveythanks'
@@ -298,7 +298,7 @@ class SurveyManager {
 		$table_question = Database :: get_course_table(TABLE_MAIN_SURVEYQUESTION);
 		$sql = "INSERT INTO  $table_question (gid,type,caption,ans1,ans2,ans3,ans4,ans5,ans6,ans7,ans8,ans9,ans10,open_ans,anst,ansd,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10) values('$gid','$type','$caption',$x'$open_ans','$anst','$ansd',$y)";
 		$result = Database::query($sql);
-		return mysql_insert_id();
+		return Database::insert_id();
 	}
 
 	function get_question($questionid)
@@ -317,7 +317,7 @@ class SurveyManager {
 	{
     	$sql_sort = "SELECT max(sortby) AS sortby FROM $curr_dbname.questions ";
 		$res_sort=Database::query($sql_sort);
-		$rs=mysql_fetch_object($res_sort);
+		$rs=Database::fetch_object($res_sort);
 		$sortby=$rs->sortby;
 		if(empty($sortby))
 		{
@@ -354,7 +354,7 @@ class SurveyManager {
 		//}
 			$sql = "INSERT INTO $curr_dbname.questions (gid,survey_id,qtype,caption,alignment,sortby,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,at,ad,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10) values('$gid','$surveyid','$qtype','$caption','$alignment','$sortby',$x'$anst','$ansd',$y)";
 			$result = Database::query($sql);
-			return mysql_insert_id();
+			return Database::insert_id();
 
 		}
 
@@ -372,7 +372,7 @@ class SurveyManager {
 		$ansd = $answerD;
 		$sql = "UPDATE $curr_dbname.questions SET qtype='$qtype',caption='$caption',alignment='$alignment',a1='$answers[0]',a2='$answers[1]',a3='$answers[2]',a4='$answers[3]',a5='$answers[4]',a6='$answers[5]',a7='$answers[6]',a8='$answers[7]',a9='$answers[8]',a10='$answers[9]' WHERE qid='$qid'";
 		$result = Database::query($sql);
-		return mysql_insert_id();
+		return Database::insert_id();
 	}
 
 	/**
@@ -409,7 +409,7 @@ class SurveyManager {
 			$qid = Database::escape_string($qid);
 	        $sql = "SELECT * FROM $curr_dbname.questions where qid='$qid'";
 			$res=Database::query($sql);
-			$rs=mysql_fetch_object($res);
+			$rs=Database::fetch_object($res);
 			$properties = get_object_vars($rs);
 			foreach ($properties as $property=>$val){
 				$val = stripslashes($val);
@@ -437,7 +437,7 @@ class SurveyManager {
 		global $_course;
 		$sql='SELECT * FROM '.$_course['dbName'].'.survey WHERE survey_id='.intval($id);
 		$res=Database::query($sql);
-		return mysql_fetch_object($res);
+		return Database::fetch_object($res);
 	}
 	/**
 	 * Possible  deprecated method
@@ -472,7 +472,7 @@ class SurveyManager {
 		  $table_question = Database :: get_course_table(TABLE_MAIN_SURVEYQUESTION);
 		  echo $sql="select t1.title as stitle, t3.type as type, t3.caption as caption, t2.groupname as groupname from $table_survey t1, $table_group t2, $table_question t3  where t1.survey_id=t2.survey_id  and t3.gid=t2.group_id and t3.type='$question_type'";
 		  $sql_result = Database::query($sql,__FILE__,__LINE__);
-		  $result = mysql_fetch_object($sql_result);
+		  $result = Database::fetch_object($sql_result);
 		  return ($result);
 		  }
 		  */
@@ -505,7 +505,7 @@ class SurveyManager {
 				$res = Database::query($sql);
 				$sql = "INSERT INTO $table_group('survey_id', 'groupname') values('$sid', '$groupname')";
 				$res = Database::query($sql);
-				$gid_arr[$index]+= mysql_insert_id();
+				$gid_arr[$index]+= Database::insert_id();
 				$groupids=implode(",",$gid_arr);
 			  }
 			}
@@ -537,7 +537,7 @@ class SurveyManager {
 		// Deleting all the questions of the survey
 		$sql = "SELECT * FROM $table_group WHERE survey_id='".$survey_id."'";
 		$res = Database::query($sql,__FILE__,__LINE__);
-		while($obj = mysql_fetch_object($res))
+		while($obj = Database::fetch_object($res))
 		{
 			$sql = "DELETE FROM $table_question WHERE gid='".$obj->group_id."'";
 			Database::query($sql,__FILE__,__LINE__);
@@ -612,7 +612,7 @@ class SurveyManager {
 			$str_group_list = "";
 			$str_group_list .= "<select name=\"exiztinggroup\" $extra_script>\n";
 
-			while($result=mysql_fetch_array($sql_result))
+			while($result=Database::fetch_array($sql_result))
 			{
 			 $selected = ($seleced_groupid==$result[group_id])?"selected":"";
 			 $str_group_list .= "\n<option value=\"".$result[group_id]."\" ".$selected.">".$result[groupname]."</option>\n";
@@ -682,7 +682,7 @@ class SurveyManager {
 				$sql = "SELECT * FROM $table_question WHERE gid = '$temp_gid'";
 				$res = Database::query($sql);
 				$num_rows = mysql_num_rows($res);
-				while($obj = mysql_fetch_object($res))
+				while($obj = Database::fetch_object($res))
 				{
 					$temp_qtype = $obj->qtype;
 					$temp_caption = $obj->caption;
@@ -733,13 +733,13 @@ class SurveyManager {
 		//echo "ths is num".$num;
 		$parameters = array();
 		$displays = array();
-		while($obj = @mysql_fetch_object($res))
+		while($obj = @Database::fetch_object($res))
 		{
 
 			$groupid = $obj->group_id;
 			$query = "SELECT * FROM $table_question WHERE gid = '$groupid'";
 			$result = Database::query($query);
-		  while($object = @mysql_fetch_object($result))
+		  while($object = @Database::fetch_object($result))
 			{
 				$display = array();
 				$display[] = '<input type="checkbox" name="course[]" value="'.$object->qid.'"/>';
@@ -767,16 +767,16 @@ class SurveyManager {
 	  {
 	 $sql = "SELECT *  FROM $db_name.survey_group WHERE survey_id = '$surveyid'";
      $res = Database::query($sql,__FILE__,__LINE__);
-	 while($obj=@mysql_fetch_object($res))
+	 while($obj=@Database::fetch_object($res))
      {
 		 $groupname=addslashes($obj->groupname);
 		 $introduction=addslashes($obj->introduction);
 	   $sql_insert = "INSERT INTO $curr_dbname.survey_group(group_id,survey_id,groupname,introduction) values('','$newsurveyid','$groupname','$introduction')";
 	   $resnext = Database::query($sql_insert,__FILE__,__LINE__);
-	   $groupid = mysql_insert_id();
+	   $groupid = Database::insert_id();
 	   $sql_q = "SELECT *  FROM $db_name.questions WHERE gid = '$obj->group_id'";
 	   $res_q = Database::query($sql_q,__FILE__,__LINE__);
-       while($obj_q = mysql_fetch_object($res_q))
+       while($obj_q = Database::fetch_object($res_q))
 	   {
 		 $caption1=addslashes($obj_q->caption);
 		      $a1=addslashes($obj_q->a1);
@@ -803,7 +803,7 @@ class SurveyManager {
 			  $r10=addslashes($obj_q->r10);
 		 $sql_sort = "SELECT max(sortby) AS sortby FROM $curr_dbname.questions ";
          $res_sort=Database::query($sql_sort);
-         $rs=mysql_fetch_object($res_sort);
+         $rs=Database::fetch_object($res_sort);
 	     $sortby=$rs->sortby;
 	     if(empty($sortby))
 	     {$sortby=1;}
@@ -831,13 +831,13 @@ function insert_old_groups($sid,$gids,$table_group,$table_question)
 	{
 		$sql = "SELECT * FROM $table_group WHERE group_id = '$gid_arr[$p]'";
 		$res = Database::query($sql);
-		$obj = mysql_fetch_object($res);
+		$obj = Database::fetch_object($res);
 		$gname = $obj->groupname;
 		if($gname=='Default')
 		{
 			$query = "SELECT * FROM $table_group WHERE survey_id = '$sid' AND groupname = 'Default'";
 			$result = Database::query($query);
-			$object = mysql_fetch_object($result);
+			$object = Database::fetch_object($result);
 			$gid = $object->group_id;
 			$sql_def_check = "SELECT * FROM $table_question WHERE gid = '$gid'";
 			$res_def_check = Database::query($sql_def_check);
@@ -852,7 +852,7 @@ function insert_old_groups($sid,$gids,$table_group,$table_question)
 				$sql_ques = "SELECT * FROM $table_question WHERE gid= '$gid_arr[$p]'";
 				$res_ques = Database::query($sql_ques);
 				$num = mysql_num_rows($res_ques);
-				while($obj_ques = mysql_fetch_object($res_ques))
+				while($obj_ques = Database::fetch_object($res_ques))
 				{
 					$temp_qtype = $obj_ques->qtype;
 					$temp_caption = $obj_ques->caption;
@@ -904,11 +904,11 @@ function insert_old_groups($sid,$gids,$table_group,$table_question)
 			{
 			$sql_insert = "INSERT INTO $table_group(group_id,survey_id,groupname,introduction,imported_group) values('','$sid','$gname','$intro','$gid_arr[$p]')";
 			$res_insert = Database::query($sql_insert);
-			$new_gid = mysql_insert_id();
+			$new_gid = Database::insert_id();
 			$sql_ques = "SELECT * FROM $table_question WHERE gid= '$gid_arr[$p]'";
 			$res_ques = Database::query($sql_ques);
 			$num = mysql_num_rows($res_ques);
-			while($obj_ques = mysql_fetch_object($res_ques))
+			while($obj_ques = Database::fetch_object($res_ques))
 			{
 				$temp_qtype = $obj_ques->qtype;
 				$temp_caption = $obj_ques->caption;
@@ -957,7 +957,7 @@ function insert_old_groups($sid,$gids,$table_group,$table_question,$db_name,$cid
 	$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
 	$sql = "SELECT * FROM $table_course WHERE code = '$cidReq'";
 	$res = Database::query($sql,__FILE__,__LINE__);
-	$obj_name=@mysql_fetch_object($res);
+	$obj_name=@Database::fetch_object($res);
 	$current_db_name = $obj_name->db_name ;
 	$gid_arr = explode(",",$gids);
 	$index = count($gid_arr);
@@ -966,13 +966,13 @@ function insert_old_groups($sid,$gids,$table_group,$table_question,$db_name,$cid
 	{
 		$sql = "SELECT * FROM $db_name.survey_group WHERE group_id = '$gid_arr[$p]'";
 		$res = Database::query($sql);
-		$obj = mysql_fetch_object($res);
+		$obj = Database::fetch_object($res);
 		$gname = $obj->groupname;
 		if($gname=='No Group')
 		{
 			$query = "SELECT * FROM $db_name.survey_group WHERE survey_id = '$sid' AND groupname = 'No Group'";
 			$result = Database::query($query);
-			$object = mysql_fetch_object($result);
+			$object = Database::fetch_object($result);
 			$gid = $object->group_id;
 			$sql_def_check = "SELECT * FROM $db_name.questions WHERE gid = '$gid'";
 			$res_def_check = Database::query($sql_def_check);
@@ -988,7 +988,7 @@ function insert_old_groups($sid,$gids,$table_group,$table_question,$db_name,$cid
 				$sql_ques = "SELECT * FROM $db_name.questions WHERE gid= '$gid_arr[$p]'";
 				$res_ques = Database::query($sql_ques);
 				$num = mysql_num_rows($res_ques);
-				while($obj_ques = mysql_fetch_object($res_ques))
+				while($obj_ques = Database::fetch_object($res_ques))
 				{
 					$temp_qtype = $obj_ques->qtype;
 					$temp_caption = $obj_ques->caption;
@@ -1040,11 +1040,11 @@ function insert_old_groups($sid,$gids,$table_group,$table_question,$db_name,$cid
 			{
 			$sql_insert = "INSERT INTO $current_db_name.survey_group(group_id,survey_id,groupname,introduction,imported_group) values('','$sid','$gname','$intro','$gid_arr[$p]')";
 			$res_insert = Database::query($sql_insert);
-			$new_gid = mysql_insert_id();
+			$new_gid = Database::insert_id();
 			$sql_ques = "SELECT * FROM $db_name.questions WHERE gid= '$gid_arr[$p]'";
 			$res_ques = Database::query($sql_ques);
 			$num = mysql_num_rows($res_ques);
-			while($obj_ques = mysql_fetch_object($res_ques))
+			while($obj_ques = Database::fetch_object($res_ques))
 			{
 				$temp_qtype = $obj_ques->qtype;
 				$temp_caption = $obj_ques->caption;
@@ -1093,7 +1093,7 @@ function import_question($surveyid,$qids,$table_group,$table_question,$db_name,$
    $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
    $sql_course = "SELECT * FROM $table_course WHERE code = '$cidReq'";
    $res_course = Database::query($sql_course,__FILE__,__LINE__);
-   $obj_name=@mysql_fetch_object($res_course);
+   $obj_name=@Database::fetch_object($res_course);
    $current_db_name = $obj_name->db_name ;
    $qid=explode(",",$qids);
    $count = count($qid);
@@ -1101,17 +1101,17 @@ function import_question($surveyid,$qids,$table_group,$table_question,$db_name,$
    {
 	 $sql_q = "SELECT *  FROM $table_question WHERE qid = '$qid[$i]'";
      $res_q = Database::query($sql_q,__FILE__,__LINE__);
-	 $obj=@mysql_fetch_object($res_q);
+	 $obj=@Database::fetch_object($res_q);
 	 $oldgid=$obj->gid;
 	 $sql = "SELECT *  FROM $table_group WHERE group_id = '$oldgid'";
 	 $res = Database::query($sql,__FILE__,__LINE__);
-	 $obj_gr = @mysql_fetch_object($res);
+	 $obj_gr = @Database::fetch_object($res);
 	 $gname = $obj_gr->groupname;
 	 $gintro = $obj_gr->introduction;
      $sql_gid = "SELECT *  FROM $table_group WHERE survey_id = '$surveyid' AND groupname = '$gname'";
 	 $res_gid = Database::query($sql_gid,__FILE__,__LINE__);
 	 $num=mysql_num_rows($res_gid);
-     $obj_gid=@mysql_fetch_object($res_gid);
+     $obj_gid=@Database::fetch_object($res_gid);
 	 $sql_quesid = "SELECT *  FROM $table_question WHERE gid = '$obj_gid->group_id' AND caption = '$obj->caption'";
      $res_quesid = Database::query($sql_quesid,__FILE__,__LINE__);
      $num_ques=mysql_num_rows($res_quesid);
@@ -1131,7 +1131,7 @@ function import_question($surveyid,$qids,$table_group,$table_question,$db_name,$
   {
 	 $sql_ginsert="INSERT INTO $current_db_name.survey_group(group_id,survey_id,groupname,introduction) values('','$surveyid','$gname','$gintro')";
 	 Database::query($sql_ginsert,__FILE__,__LINE__);
-     $new_gid = mysql_insert_id();
+     $new_gid = Database::insert_id();
 	 $sql_q_insert = "INSERT INTO $current_db_name.questions (qid,gid,qtype,caption,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,at,ad,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10) values('','$new_gid','$obj->qtype','$obj->caption','$obj->a1','$obj->a2','$obj->a3','$obj->a4','$obj->a5','$obj->a6','$obj->a7','$obj->a8','$obj->a9','$obj->a10','$obj->at','$obj->ad','$obj->r1','$obj->r2','$obj->r3','$obj->r4','$obj->r5','$obj->r6','$obj->r7','$obj->r8','$obj->r9','$obj->r10')";
 	 Database::query($sql_q_insert,__FILE__,__LINE__);
     }
@@ -1146,7 +1146,7 @@ function create_course_survey_rel($cidReq,$survey_id,$table_course,$table_course
 {
  $sql = "SELECT * FROM $table_course WHERE code = '$cidReq'";
  $res = Database::query($sql,__FILE__,__LINE__);
- $obj=@mysql_fetch_object($res);
+ $obj=@Database::fetch_object($res);
  $db_name = $obj->db_name ;
  $sql="INSERT INTO $table_course_survey_rel(id,course_code,db_name,survey_id) values('','$cidReq','$db_name','$survey_id')";
 
@@ -1164,17 +1164,17 @@ function import_existing_question($surveyid,$qids,$table_group,$table_question,$
   {
 	 $sql_q = "SELECT *  FROM $table_question WHERE qid = '$qid[$i]'";
      $res_q = Database::query($sql_q,__FILE__,__LINE__);
-	 $obj=@mysql_fetch_object($res_q);
+	 $obj=@Database::fetch_object($res_q);
 	 $oldgid=$obj->gid;
 	 $sql = "SELECT *  FROM $table_group WHERE group_id = '$oldgid'";
 	 $res = Database::query($sql,__FILE__,__LINE__);
-	 $obj_gr = @mysql_fetch_object($res);
+	 $obj_gr = @Database::fetch_object($res);
 	 $gname = $obj_gr->groupname;
 	 $gintro = $obj_gr->introduction;
      $sql_gid = "SELECT *  FROM $table_group WHERE survey_id = '$surveyid' AND groupname = '$gname'";
 	 $res_gid = Database::query($sql_gid,__FILE__,__LINE__);
 	 $num=mysql_num_rows($res_gid);
-     $obj_gid=@mysql_fetch_object($res_gid);
+     $obj_gid=@Database::fetch_object($res_gid);
 	 $sql_quesid = "SELECT *  FROM $table_question WHERE gid = '$obj_gid->group_id' AND caption = '$obj->caption'";
      $res_quesid = Database::query($sql_quesid,__FILE__,__LINE__);
      $num_ques=mysql_num_rows($res_quesid);
@@ -1194,7 +1194,7 @@ function import_existing_question($surveyid,$qids,$table_group,$table_question,$
   {
 	 $sql_ginsert="INSERT INTO $table_group(group_id,survey_id,groupname,introduction) values('','$surveyid','$gname','$gintro')";
 	 Database::query($sql_ginsert,__FILE__,__LINE__);
-     $new_gid = mysql_insert_id();
+     $new_gid = Database::insert_id();
 	 $sql_q_insert = "INSERT INTO $table_question (qid,gid,qtype,caption,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,at,ad,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10) values('','$new_gid','$obj->qtype','$obj->caption','$obj->a1','$obj->a2','$obj->a3','$obj->a4','$obj->a5','$obj->a6','$obj->a7','$obj->a8','$obj->a9','$obj->a10','$obj->at','$obj->ad','$obj->r1','$obj->r2','$obj->r3','$obj->r4','$obj->r5','$obj->r6','$obj->r7','$obj->r8','$obj->r9','$obj->r10')";
 	 Database::query($sql_q_insert,__FILE__,__LINE__);
     }
@@ -1214,13 +1214,13 @@ function insert_existing_groups ($sid,$gids,$table_group,$table_question)
 	{
 		$sql = "SELECT * FROM $table_group WHERE group_id = '$gid_arr[$p]'";
 		$res = Database::query($sql);
-		$obj = mysql_fetch_object($res);
+		$obj = Database::fetch_object($res);
 		$gname = $obj->groupname;
 		if($gname=='No Group')
 		{
 			$query = "SELECT * FROM $table_group WHERE survey_id = '$sid' AND groupname = 'No Group'";
 			$result = Database::query($query);
-			$object = mysql_fetch_object($result);
+			$object = Database::fetch_object($result);
 			$gid = $object->group_id;
 			$sql_def_check = "SELECT * FROM $table_question WHERE gid = '$gid'";
 			$res_def_check = Database::query($sql_def_check);
@@ -1235,7 +1235,7 @@ function insert_existing_groups ($sid,$gids,$table_group,$table_question)
 				$sql_ques = "SELECT * FROM $table_question WHERE gid= '$gid_arr[$p]'";
 				$res_ques = Database::query($sql_ques);
 				$num = mysql_num_rows($res_ques);
-				while($obj_ques = mysql_fetch_object($res_ques))
+				while($obj_ques = Database::fetch_object($res_ques))
 				{
 					$temp_qtype = $obj_ques->qtype;
 					$temp_caption = $obj_ques->caption;
@@ -1287,11 +1287,11 @@ function insert_existing_groups ($sid,$gids,$table_group,$table_question)
 			{
 			$sql_insert = "INSERT INTO $table_group(group_id,survey_id,groupname,introduction,imported_group) values('','$sid','$gname','$intro','$gid_arr[$p]')";
 			$res_insert = Database::query($sql_insert);
-			$new_gid = mysql_insert_id();
+			$new_gid = Database::insert_id();
 			$sql_ques = "SELECT * FROM $table_question WHERE gid= '$gid_arr[$p]'";
 			$res_ques = Database::query($sql_ques);
 			$num = mysql_num_rows($res_ques);
-			while($obj_ques = mysql_fetch_object($res_ques))
+			while($obj_ques = Database::fetch_object($res_ques))
 			{
 				$temp_qtype = $obj_ques->qtype;
 				$temp_caption = $obj_ques->caption;
@@ -1364,14 +1364,14 @@ function question_import($surveyid,$qids,$db_name,$curr_dbname)
    {
 	 $sql_sort = "SELECT max(sortby) AS sortby FROM $curr_dbname.questions ";
      $res_sort=Database::query($sql_sort);
-     $rs=mysql_fetch_object($res_sort);
+     $rs=Database::fetch_object($res_sort);
 	 $sortby=$rs->sortby;
 	 if(empty($sortby))
 	 {$sortby=1;}
 	 else{$sortby=$sortby+1;}
 	 $sql_q = "SELECT * FROM $db_name.questions WHERE qid = '$qid[$i]'";
      $res_q = Database::query($sql_q,__FILE__,__LINE__);
-	 $obj=@mysql_fetch_object($res_q);
+	 $obj=@Database::fetch_object($res_q);
 	 $oldgid=$obj->gid;
 	 $caption1=addslashes($obj->caption);
 	  $a1=addslashes($obj->a1);
@@ -1398,7 +1398,7 @@ function question_import($surveyid,$qids,$db_name,$curr_dbname)
 			  $r10=addslashes($obj_q->r10);
      //$sql_gr = "SELECT * FROM $db_name.survey_group WHERE group_id = '$oldgid'";
      //$res_gr = Database::query($sql_gr,__FILE__,__LINE__);
-	 // $obj_gr=@mysql_fetch_object($res_gr);
+	 // $obj_gr=@Database::fetch_object($res_gr);
 	 //$groupname = $obj_gr->groupname
 	 $sql_quesid = "SELECT *  FROM $curr_dbname.questions WHERE survey_id = '$surveyid' AND imported_question = '$qid[$i]' AND db_name = '$db_name'";
      $res_quesid = Database::query($sql_quesid,__FILE__,__LINE__);
@@ -1411,11 +1411,11 @@ function question_import($surveyid,$qids,$db_name,$curr_dbname)
 	 {
 	  $sql_group = "SELECT * FROM $db_name.survey_group WHERE group_id = '$oldgid'";
 	  $res_group = Database::query($sql_group,__FILE__,__LINE__);
-	  $obj_group=@mysql_fetch_object($res_group);
+	  $obj_group=@Database::fetch_object($res_group);
 	  $groupname = $obj_group->groupname;
 	  $sql = "SELECT *  FROM $curr_dbname.survey_group WHERE groupname = '$groupname' AND survey_id = '$surveyid'";
 	  $res = Database::query($sql,__FILE__,__LINE__);
-      $obj_gro = mysql_fetch_object($res);
+      $obj_gro = Database::fetch_object($res);
 	   $num_group=mysql_num_rows($res);
 	  if($num_group>0)
 	   {
@@ -1427,7 +1427,7 @@ function question_import($surveyid,$qids,$db_name,$curr_dbname)
 		 //$num_group;
       $sql_ginsert="INSERT INTO $curr_dbname.survey_group(group_id,survey_id,groupname,introduction,imported_group, db_name) values('','$surveyid','$groupname','$obj_group->introduction','$oldgid','$db_name')";
 	    Database::query($sql_ginsert,__FILE__,__LINE__);
-        $new_gid = mysql_insert_id();
+        $new_gid = Database::insert_id();
       $sql_q_insert = "INSERT INTO $curr_dbname.questions (qid,gid,survey_id,qtype,caption,alignment,sortby,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,at,ad,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,imported_question,db_name) values('','$new_gid','$surveyid','$obj->qtype','$caption1','$obj->alignment','$sortby','$a1','$a2','$a3','$a4','$a5','$a6','$a7','$a8','$a9','$a10','$at','$ad','$r1','$r2','$r3','$r4','$r5','$r6','$r7','$r8','$r9','$r10','$qid[$i]','$db_name')";
 	    Database::query($sql_q_insert,__FILE__,__LINE__);
        }
@@ -1445,13 +1445,13 @@ function import_group($surveyid,$gids,$db_name,$curr_dbname)
 	{
 		$sql = "SELECT * FROM $db_name.survey_group WHERE group_id = '$gid_arr[$i]'";
 		$res = Database::query($sql,__FILE__,__LINE__);
-		$obj = mysql_fetch_object($res);
+		$obj = Database::fetch_object($res);
 		$sql_ques = "SELECT * FROM $db_name.questions WHERE gid = '$gid_arr[$i]'";
 		$res_ques = Database::query($sql_ques,__FILE__,__LINE__);
-		$obj_ques = mysql_fetch_object($res_ques);
+		$obj_ques = Database::fetch_object($res_ques);
 		$sql_check = "SELECT * FROM $curr_dbname.survey_group WHERE survey_id = '$surveyid' AND imported_group = '$gid_arr[$i]' AND db_name = '$db_name'";
 		$res_check = Database::query($sql_check);
-		$obj_check = mysql_fetch_object($res_check);
+		$obj_check = Database::fetch_object($res_check);
 		$num = mysql_num_rows($res_check);
 		if($num>0)
 		{
@@ -1472,7 +1472,7 @@ function import_group($surveyid,$gids,$db_name,$curr_dbname)
 		 {
 			$insert_group = "INSERT INTO $curr_dbname.survey_group (group_id,survey_id,groupname,introduction,imported_group,db_name) values('','$surveyid','$obj->groupname','$obj->introduction','$obj->group_id','$db_name')";
 			$res_insert_group=Database::query($insert_group);
-            $new_gid = mysql_insert_id();
+            $new_gid = Database::insert_id();
 			$sql_insert_grp =  "INSERT INTO $curr_dbname.questions (qid,gid,qtype,caption,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,at,ad,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,imported_question,db_name) values('','$new_gid','$surveyid','$obj_ques->qtype','$obj_ques->caption','$obj_ques->a1','$obj_ques->a2','$obj_ques->a3','$obj_ques->a4','$obj_ques->a5','$obj_ques->a6','$obj_ques->a7','$obj_ques->a8','$obj_ques->a9','$obj_ques->a10','$obj_ques->at','$obj_ques->ad','$obj_ques->r1','$obj_ques->r2','$obj_ques->r3','$obj_ques->r4','$obj_ques->r5','$obj_ques->r6','$obj_ques->r7','$obj_ques->r8','$obj_ques->r9','$obj_ques->r10','$obj_ques->qid','$db_name')";
 			Database::query($sql_insert_grp);
 		 }
@@ -1493,13 +1493,13 @@ function import_group($sid,$gids,$db_name,$curr_dbname)
 	{
 		$sql = "SELECT * FROM $db_name.survey_group WHERE group_id = '$gid_arr[$i]'";
 		$res = Database::query($sql);
-		$obj = mysql_fetch_object($res);
+		$obj = Database::fetch_object($res);
 		$groupname=addslashes($obj->groupname);
 		$introduction=addslashes($obj->introduction);
 		$g_sortby = intval($obj->sortby);
 		$sql_curr = "SELECT * FROM $curr_dbname.survey_group WHERE survey_id = '$sid' AND groupname = '$obj->groupname'";
 		$res_curr = Database::query($sql_curr);
-		$obj_curr = mysql_fetch_object($res_curr);
+		$obj_curr = Database::fetch_object($res_curr);
 		$gid = $obj_curr->group_id;
 		$num = mysql_num_rows($res_curr);
 
@@ -1507,7 +1507,7 @@ function import_group($sid,$gids,$db_name,$curr_dbname)
 		{
 			$sql_ques = "SELECT * FROM $curr_dbname.questions WHERE gid = '$gid'";
 			$res_ques = Database::query($sql_ques);
-			$obj_ques = mysql_fetch_object($res_ques);
+			$obj_ques = Database::fetch_object($res_ques);
 			$count = mysql_num_rows($res_ques);
 			for($j=0;$j<$count;$j++)
 			{
@@ -1518,7 +1518,7 @@ function import_group($sid,$gids,$db_name,$curr_dbname)
 			$check_db = @array_unique($check_db);
 			$sql_old = "SELECT * FROM $db_name.questions WHERE gid = '$gid_arr[$i]'";
 			$res_old = Database::query($sql_old);
-			while($obj_old = mysql_fetch_object($res_old))
+			while($obj_old = Database::fetch_object($res_old))
 			{
 			  $caption1=addslashes($obj_old->caption);
 	          $a1=addslashes($obj_old->a1);
@@ -1545,7 +1545,7 @@ function import_group($sid,$gids,$db_name,$curr_dbname)
 			  $r10=addslashes($obj_old->r10);
 				$sql_sort = "SELECT max(sortby) AS sortby FROM $curr_dbname.questions ";
                 $res_sort=Database::query($sql_sort);
-                $rs=mysql_fetch_object($res_sort);
+                $rs=Database::fetch_object($res_sort);
 	            $sortby=$rs->sortby;
 	            if(empty($sortby))
 	            {$sortby=1;}
@@ -1567,10 +1567,10 @@ function import_group($sid,$gids,$db_name,$curr_dbname)
 
 			$sql_insertg = "INSERT INTO $curr_dbname.survey_group (group_id, survey_id, groupname, introduction, imported_group, db_name, sortby) VALUES ('', '$sid', '$groupname', '$introduction', '$obj->group_id', '$db_name', $g_sortby)";
 			Database::query($sql_insertg);
-			$group_id = mysql_insert_id();
+			$group_id = Database::insert_id();
 			$sql_old = "SELECT * FROM $db_name.questions WHERE gid = '$gid_arr[$i]'";
 			$res_old = Database::query($sql_old);
-			while($obj_old = mysql_fetch_object($res_old))
+			while($obj_old = Database::fetch_object($res_old))
 			{
 			  $caption1=addslashes($obj_old->caption);
 	          $a1=addslashes($obj_old->a1);
@@ -1597,7 +1597,7 @@ function import_group($sid,$gids,$db_name,$curr_dbname)
 			  $r10=addslashes($obj_old->r10);
 				$sql_sort = "SELECT max(sortby) AS sortby FROM $curr_dbname.questions ";
                 $res_sort=Database::query($sql_sort);
-                $rs=mysql_fetch_object($res_sort);
+                $rs=Database::fetch_object($res_sort);
 	            $sortby=$rs->sortby;
 	            if(empty($sortby))
 	            {$sortby=1;}
@@ -1625,9 +1625,9 @@ function get_status()
 	global $_user;
 
 	$table_user = Database::get_main_table(TABLE_MAIN_USER);
-	$sqlm = "SELECT  status FROM  $table_user WHERE user_id = '".mysql_real_escape_string($_user['user_id'])."'";
+	$sqlm = "SELECT  status FROM  $table_user WHERE user_id = '".Database::escape_string($_user['user_id'])."'";
 	$resm = Database::query($sqlm,__FILE__,__LINE__);
-	$objm=@mysql_fetch_object($resm);
+	$objm=@Database::fetch_object($resm);
 	$ss = $objm->status ;
 	return $ss;
 }
@@ -1667,7 +1667,7 @@ function get_questions_move($curr_dbname)
 {
 	$sql_select_questions="SELECT  * from $curr_dbname.questions order by `sortby` asc";
 	$result=mysql_query($sql_select_questions);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 		{
 		// we only need the database name of the course
 		$question1[]=array("caption"=> $row['caption'], "qid" => $row['qid'],"sortby" => $row['sortby']);
@@ -1684,7 +1684,7 @@ function listGroups($id_survey, $fields = '*')
 			WHERE survey_id='.$id_survey.' ORDER BY sortby';
 	$rs = Database::query($sql, __FILE__, __LINE__);
 	$groups = array();
-	while($row = mysql_fetch_array($rs)){
+	while($row = Database::fetch_array($rs)){
 		$groups[] = $row;
 	}
 	return $groups;
@@ -1708,7 +1708,7 @@ function listQuestions($id_survey, $fields = '*')
 	$rs = Database::query($sql, __FILE__, __LINE__);
 
 	$questions = array();
-	while($row = mysql_fetch_array($rs)){
+	while($row = Database::fetch_array($rs)){
 		$questions[] = $row;
 	}
 
@@ -1728,7 +1728,7 @@ function listAnswers($qid){
 	$rs = Database::query($sql, __FILE__, __LINE__);
 
 	$answers = array();
-	while($row = mysql_fetch_array($rs)){
+	while($row = Database::fetch_array($rs)){
 		$answers[] = $row;
 	}
 
@@ -1747,7 +1747,7 @@ function listUsers($survey_id, $dbname, $fields='id, user_id, firstname, lastnam
 				$order_clause;
 	$rs = Database::query($sql, __FILE__, __LINE__);
 	$users = array();
-	while ($row = mysql_fetch_array($rs)) {
+	while ($row = Database::fetch_array($rs)) {
 		$users[] = $row;
 	}
 	return $users;
@@ -1761,7 +1761,7 @@ function getUserAnswersDetails($id_userAnswers, $params=''){
 	$sql = 'SELECT * FROM '.$table_answers.' '.$where.' '.$order;
 	$rs = Database::query($sql, __FILE__, __LINE__);
 	$answers = array();
-	while($row = mysql_fetch_array($rs))
+	while($row = Database::fetch_array($rs))
 		$answers[] = $row;
 
 	return $answers;

+ 52 - 52
main/inc/lib/usermanager.lib.php

@@ -100,7 +100,7 @@ class UserManager {
 		$result = Database::query($sql, __FILE__, __LINE__);
 		if ($result) {
 			//echo "id returned";
-			$return = Database::get_last_insert_id();
+			$return = Database::insert_id();
 			global $_configuration;
 			require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
 			if ($_configuration['multiple_access_urls'] == true) {
@@ -1102,7 +1102,7 @@ class UserManager {
 		$result = Database::query($sql);
 		if ($result) {
 			//echo "id returned";
-			$return = Database::get_last_insert_id();
+			$return = Database::insert_id();
 		} else {
 			//echo "false - failed" ;
 			return false;
@@ -1489,8 +1489,8 @@ class UserManager {
 		}
 		return $result_data;
 	}
-	
-	
+
+
 	/**
 	 * Gives a list of [session_category][session_id] for the current user.
 	 * @param integer $user_id
@@ -1513,22 +1513,22 @@ class UserManager {
 		}
 		/*
 		//we filter the courses from the URL
-		$join_access_url=$where_access_url='';		
-		global $_configuration;		
+		$join_access_url=$where_access_url='';
+		global $_configuration;
 		if ($_configuration['multiple_access_urls']==true) {
 			$access_url_id = api_get_current_access_url_id();
 			if($access_url_id!=-1) {
-				$tbl_url_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);		
+				$tbl_url_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
 				$join_access_url= "LEFT JOIN $tbl_url_course url_rel_course ON url_rel_course.course_code= course.code";
 				$where_access_url=" AND access_url_id = $access_url_id ";
 			}
 		}
-		*/		
+		*/
 		// get the list of sessions where the user is subscribed as student
-		
+
 		$condition_date_end = "";
 		if ($is_time_over) {
-			$condition_date_end = " AND date_end < CURDATE() AND date_end != '0000-00-00' ";	
+			$condition_date_end = " AND date_end < CURDATE() AND date_end != '0000-00-00' ";
 		} else {
 			$condition_date_end = " AND (date_end >= CURDATE() OR date_end = '0000-00-00') ";
 		}
@@ -1537,12 +1537,12 @@ class UserManager {
 								FROM $tbl_session_user, $tbl_session
 								WHERE id_session=id AND id_user=$user_id $condition_date_end
 								ORDER BY session_category_id, date_start, date_end";
-														
-		$result = Database::query($sessions_sql,__FILE__,__LINE__);	
+
+		$result = Database::query($sessions_sql,__FILE__,__LINE__);
 		while ($row = Database::fetch_array($result)) {
-			$categories[$row['session_category_id']][] = $row['id']; 
+			$categories[$row['session_category_id']][] = $row['id'];
 		}
-		
+
 		// get the list of sessions where the user is subscribed as coach in a course $tbl_session_course_user
 		/*$sessions_sql = "SELECT DISTINCT id, session_category_id
 								FROM $tbl_session as session
@@ -1550,33 +1550,33 @@ class UserManager {
 									ON session_rel_course.id_session = session.id
 									AND session_rel_course.id_coach = $user_id
 								ORDER BY session_category_id, date_start, date_end";*/
-								
+
 		$sessions_sql = "SELECT DISTINCT id, session_category_id
 								FROM $tbl_session as session
 								INNER JOIN $tbl_session_course_user as session_rel_course_user
 									ON session_rel_course_user.id_session = session.id
 									AND session_rel_course_user.id_user = $user_id
-									AND session_rel_course_user.status = 2	$condition_date_end	
+									AND session_rel_course_user.status = 2	$condition_date_end
 								ORDER BY session_category_id, date_start, date_end";
-				
+
 		$result = Database::query($sessions_sql,__FILE__,__LINE__);
 		while ($row = Database::fetch_array($result)) {
-			$categories[$row['session_category_id']][] = $row['id']; 
+			$categories[$row['session_category_id']][] = $row['id'];
 		}
-	
+
 		// get the list of sessions where the user is subscribed as coach
 		$sessions_sql = "SELECT DISTINCT id, session_category_id
 								FROM $tbl_session as session
 								WHERE session.id_coach = $user_id $condition_date_end
-								ORDER BY session_category_id, date_start, date_end";		
-								
+								ORDER BY session_category_id, date_start, date_end";
+
 		$result = Database::query($sessions_sql,__FILE__,__LINE__);
 		while ($row = Database::fetch_array($result)) {
-			$categories[$row['session_category_id']][] = $row['id']; 
+			$categories[$row['session_category_id']][] = $row['id'];
 		}
 		return $categories;
-	}	
-	
+	}
+
 	/**
 	 * Gives a list of [session_id-course_code] => [status] for the current user.
 	 * @param integer $user_id
@@ -1643,23 +1643,23 @@ class UserManager {
 								WHERE id_session=id AND id_user=$user_id
 								AND (date_start <= CURDATE() AND date_end >= CURDATE() OR date_start='0000-00-00')
 								ORDER BY date_start, date_end, name";
-		$result = api_sql_query($sessions_sql,__FILE__,__LINE__);	
-		$sessions=api_store_result($result);	
-		$sessions = array_merge($sessions , api_store_result($result));
-		
-		
+		$result = Database::query($sessions_sql,__FILE__,__LINE__);
+		$sessions=Database::store_result($result);
+		$sessions = array_merge($sessions , Database::store_result($result));
+
+
 		// get the list of sessions where the user is subscribed as student where visibility = SESSION_VISIBLE_READ_ONLY = 1  SESSION_VISIBLE = 2
 		$sessions_out_date_sql = "SELECT DISTINCT id, name, date_start, date_end
 								FROM $tbl_session_user, $tbl_session
 								WHERE id_session=id AND id_user=$user_id
 								AND (date_end <= CURDATE() AND date_end<>'0000-00-00') AND (visibility = ".SESSION_VISIBLE_READ_ONLY." || visibility = ".SESSION_VISIBLE.")
 								ORDER BY date_start, date_end, name";
-		$result_out_date = api_sql_query($sessions_out_date_sql,__FILE__,__LINE__);	
-		$sessions_out_date=api_store_result($result_out_date);	
+		$result_out_date = Database::query($sessions_out_date_sql,__FILE__,__LINE__);
+		$sessions_out_date=Database::store_result($result_out_date);
 		$sessions = array_merge($sessions , $sessions_out_date);
-		
-				
-			
+
+
+
 		// get the list of sessions where the user is subscribed as coach in a course
 		$sessions_sql = "SELECT DISTINCT id, name, date_start, date_end, DATE_SUB(date_start, INTERVAL nb_days_access_before_beginning DAY), ADDDATE(date_end, INTERVAL nb_days_access_after_end DAY)
 			FROM $tbl_session as session
@@ -1729,17 +1729,17 @@ class UserManager {
 											ON session_course.id_session = session.id
 										 WHERE session_course.id_session = $id_session
 										 ORDER BY i";
-				*/		
-			// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not  	 
-			$personal_course_list_sql = "SELECT distinct course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, CONCAT(user.lastname,' ',user.firstname) t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name, IF(session_course.id_coach = 3,'2', '5') 
-										FROM $tbl_session_course_user as session_course_user INNER JOIN $tbl_course AS course 
+				*/
+			// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not
+			$personal_course_list_sql = "SELECT distinct course.code k, course.directory d, course.visual_code c, course.db_name db, course.title i, CONCAT(user.lastname,' ',user.firstname) t, email, course.course_language l, 1 sort, category_code user_course_cat, date_start, date_end, session.id as id_session, session.name as session_name, IF(session_course.id_coach = 3,'2', '5')
+										FROM $tbl_session_course_user as session_course_user INNER JOIN $tbl_course AS course
 										ON course.code = session_course_user.course_code AND session_course_user.id_session = $id_session INNER JOIN $tbl_session as session ON session_course_user.id_session = session.id
-										INNER JOIN $tbl_session_course as session_course 
+										INNER JOIN $tbl_session_course as session_course
 										LEFT JOIN $tbl_user as user ON user.user_id = session_course.id_coach
 										WHERE session_course_user.id_user = $user_id  ORDER BY i";
-	
-			$course_list_sql_result = api_sql_query($personal_course_list_sql, __FILE__, __LINE__);
-	
+
+			$course_list_sql_result = Database::query($personal_course_list_sql, __FILE__, __LINE__);
+
 			while ($result_row = Database::fetch_array($course_list_sql_result)) {
 				$key = $result_row['id_session'].' - '.$result_row['k'];
 				$result_row['s'] = $result_row['14'];
@@ -1750,7 +1750,7 @@ class UserManager {
 			}
 		}
 		//print_r($personal_course_list);
-		
+
 		return $personal_course_list;
 	}
 	/**
@@ -1763,30 +1763,30 @@ class UserManager {
 		$tbl_session 				= Database :: get_main_table(TABLE_MAIN_SESSION);
 		$tbl_session_course 		= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 		$tbl_session_course_user 	= Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-		
+
 		$user_id = intval($user_id);
 		//we filter the courses from the URL
-		$join_access_url=$where_access_url='';		
-		global $_configuration;		
+		$join_access_url=$where_access_url='';
+		global $_configuration;
 		if ($_configuration['multiple_access_urls']==true) {
 			$access_url_id = api_get_current_access_url_id();
 			if($access_url_id!=-1) {
-				$tbl_url_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);		
+				$tbl_url_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
 				$join_access_url= "LEFT JOIN $tbl_url_course url_rel_course ON url_rel_course.course_code= course.code";
 				$where_access_url=" AND access_url_id = $access_url_id ";
 			}
 		}
-	
+
 		// variable initialisation
 		$personal_course_list_sql = '';
 		$personal_course_list = array();
 		$courses = array();
-	
-		// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not  	 
-		$personal_course_list_sql = "SELECT distinct scu.course_code as code 
+
+		// this query is very similar to the above query, but it will check the session_rel_course_user table if there are courses registered to our user or not
+		$personal_course_list_sql = "SELECT distinct scu.course_code as code
 									FROM $tbl_session_course_user as scu
 									$join_access_url
-									WHERE scu.id_user = $user_id 
+									WHERE scu.id_user = $user_id
 									AND scu.id_session = $session_id
 									$where_access_url
 									ORDER BY code";

+ 19 - 19
main/inc/local.inc.php

@@ -935,11 +935,11 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { // ses
 		    	$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
 		    	$tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
 		    	$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
-		    	
-		    	
-		    	$sql = " SELECT session.id_coach, session_admin_id FROM $tbl_session session,$tbl_session_course_user session_rcru 
+
+
+		    	$sql = " SELECT session.id_coach, session_admin_id FROM $tbl_session session,$tbl_session_course_user session_rcru
 		    			WHERE session_rcru.id_session = session.id AND session_rcru.course_code = '$_cid' AND session_rcru.id_user='{$_user['user_id']}' AND session_rcru.status = 2";
-		    	
+
 		        /*$sql = "SELECT session.id_coach, session_admin_id
 						FROM ".$tbl_session." as session
 						INNER JOIN ".$tbl_session_course_user."
@@ -977,10 +977,10 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { // ses
 							FROM ".$tbl_session_course_user."
 							WHERE course_code='$_cid'
 							AND id_user = '".$_user['user_id']."'
-							AND id_session = '".api_get_session_id()."'		
+							AND id_session = '".api_get_session_id()."'
 							AND status = 2";
 
-			        $result = api_sql_query($sql,__FILE__,__LINE__);
+			        $result = Database::query($sql,__FILE__,__LINE__);
 			        if ($row = Database::fetch_array($result)) {
 			        	$_courseUser['role'] = 'Professor';
 			            $is_courseMember     = true;
@@ -999,11 +999,11 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { // ses
 		        		// Check if the user is a student is this session
 				        $sql = "SELECT * FROM ".$tbl_session_course_user."
 				        		WHERE id_user  = '".$_user['user_id']."'
-				        		AND id_session = '".api_get_session_id()."'		
+				        		AND id_session = '".api_get_session_id()."'
 								AND course_code = '$cidReq' AND status NOT IN(2)";
-	
+
 				        $result = Database::query($sql,__FILE__,__LINE__);
-	
+
 				        if (Database::num_rows($result) > 0) { // this  user have a recorded state for this course
 				        	while($row = Database::fetch_array($result)){
 					            $is_courseMember     = true;
@@ -1045,25 +1045,25 @@ if ((isset($uidReset) && $uidReset) || (isset($cidReset) && $cidReset)) { // ses
     		$is_allowed_in_course = true;
     	else $is_allowed_in_course = false;
 	}
-	
+
 	// requires testing!!!
-	
+
 	// check the session visibility
 	if ($is_allowed_in_course) {
 		$my_session_id = api_get_session_id();
-		//if I'm in a session  
-		//var_dump($is_platformAdmin, $is_courseTutor,api_is_coach());		
-		if ($my_session_id!=0) 
-			if (!$is_platformAdmin) { 
-				// admin and session coach are *not* affected to the invisible session mode 
+		//if I'm in a session
+		//var_dump($is_platformAdmin, $is_courseTutor,api_is_coach());
+		if ($my_session_id!=0)
+			if (!$is_platformAdmin) {
+				// admin and session coach are *not* affected to the invisible session mode
 				// the coach is not affected because he can log in some days after the end date of a session
 				$session_visibility = api_get_session_visibility($my_session_id);
 				if ($session_visibility==SESSION_INVISIBLE)
-					$is_allowed_in_course =false;	 
+					$is_allowed_in_course =false;
 			}
-		
+
 	}
-	
+
     // save the states
 
 	api_session_register('is_courseMember');

+ 2 - 2
main/inc/tool_navigation_menu.inc.php

@@ -75,7 +75,7 @@ function get_navigation_items($include_admin_tools = false)
 
 		$sql_menu_query = "SELECT * FROM $course_tools_table WHERE visibility='1' and admin='0' ORDER BY id ASC";
 		$sql_result = Database::query($sql_menu_query, __FILE__, __LINE__);
-		while ($row = mysql_fetch_array($sql_result))
+		while ($row = Database::fetch_array($sql_result))
 		{
 			$navigation_items[$row['id']] = $row;
 			/*
@@ -107,7 +107,7 @@ function get_navigation_items($include_admin_tools = false)
 			$course_settings_sql = "	SELECT name,image FROM $course_tools_table
 															WHERE link='course_info/infocours.php'";
 			$sql_result = Database::query($course_settings_sql);
-			$course_setting_info = mysql_fetch_array($sql_result);
+			$course_setting_info = Database::fetch_array($sql_result);
 			$course_setting_visual_name = get_lang(ucfirst($course_setting_info['name']));
 			if (api_get_session_id()==0) {
 				// course settings item

+ 8 - 8
main/install/update-db-scorm-1.6.x-1.8.0.inc.php

@@ -141,7 +141,7 @@ foreach($courses_id_full_table_prefix_list as $course_code => $db)
                         "'".mysql_real_escape_string($row['learnpath_name'])."'," .
                         "'".mysql_real_escape_string($row['learnpath_description'])."',$dsp_ord,'Dokeos')";
         $ins_lp_res = Database::query($ins_lp_sql);
-        $in_id = Database::get_last_insert_id();
+        $in_id = Database::insert_id();
         if(empty($in_id) or $in_id == false) die('Could not insert lp: '.$ins_lp_sql);
         $lp_ids[$row['learnpath_id']] = $in_id;
         $dsp_ord++;
@@ -185,7 +185,7 @@ foreach($courses_id_full_table_prefix_list as $course_code => $db)
                 ")";
         //echo $ins_lp_sql."<br/>\n";
         $ins_res = Database::query($ins_lp_sql,__FILE__,__LINE__);
-        $in_id = Database::get_last_insert_id();
+        $in_id = Database::insert_id();
         //echo "&nbsp;&nbsp;Inserted item $in_id<br />\n";
         if(empty($in_id) OR $in_id == false) die('Could not insert lp: '.$ins_sql);
         $parent_chaps[$row['id']] = $row['parent_chapter_id'];
@@ -341,7 +341,7 @@ foreach($courses_id_full_table_prefix_list as $course_code => $db)
                     $row['display_order']." " .
                     ")";
             $ins_res = Database::query($ins_lp_sql,__FILE__,__LINE__);
-            $in_id = Database::get_last_insert_id();
+            $in_id = Database::insert_id();
             //echo "&nbsp;&nbsp;Inserted item $in_id (".$row['title'].")<br />\n";
             if(empty($in_id) OR $in_id == false) die('Could not insert lp_item: '.$ins_sql);
             $lp_items[$parent_lps[$row['chapter_id']]][$row['id']] = $in_id;
@@ -443,7 +443,7 @@ foreach($courses_id_full_table_prefix_list as $course_code => $db)
                         ")";
                 //echo $sql_ins_view;
                 $res_ins_view = Database::query($sql_ins_view,__FILE__,__LINE__);
-                $in_id = Database::get_last_insert_id();
+                $in_id = Database::insert_id();
                 $user_id = $row['user_id'];
                 $learnpath_id = $row['learnpath_id'];
                 $lp_view = $in_id;
@@ -948,7 +948,7 @@ foreach($scorms as $my_course_code => $paths_list )
                         ")";
                     //echo "$ins_sql<br/>";
                     $ins_res = Database::query($ins_sql,__FILE__,__LINE__);
-                    $view_insert_id = Database::get_last_insert_id();
+                    $view_insert_id = Database::insert_id();
                 }
                 $sel_sqlc = "SELECT * FROM $my_new_lp_item " .
                         "WHERE lp_id = ".$lp_ids[$my_content_id]." AND ref = '$my_identifier'";
@@ -1005,7 +1005,7 @@ foreach($scorms as $my_course_code => $paths_list )
                 ")";
         if($loglevel>1){error_log("$sql_ins",0);}
         $sql_res = Database::query($sql_ins,__FILE__,__LINE__);
-        $in_id = Database::get_last_insert_id();
+        $in_id = Database::insert_id();
         if(empty($in_id) or $in_id == false) die('Could not insert scorm lp: '.$sql_ins);
         //echo "&nbsp;&nbsp;Inserted item $in_id<br />\n";
         $lp_ids[$my_content_id] = $in_id; //contains the old LP ID => the new LP ID
@@ -1100,7 +1100,7 @@ foreach($scorms as $my_course_code => $paths_list )
                     "'$my_item_path'" .
                     ")";
                 $ins_res = Database::query($ins_sql,__FILE__,__LINE__);
-                $item_insert_id = Database::get_last_insert_id();
+                $item_insert_id = Database::insert_id();
                 $lp_item_ids[$lp_ids[$my_content_id]][$my_sco_id]=$item_insert_id;
                 $lp_item_refs[$lp_ids[$my_content_id]][$my_identifier]=$item_insert_id;
             }
@@ -1127,7 +1127,7 @@ foreach($scorms as $my_course_code => $paths_list )
                         "1" .
                         ")";
                     $ins_res = Database::query($ins_sql,__FILE__,__LINE__);
-                    $view_insert_id = Database::get_last_insert_id();
+                    $view_insert_id = Database::insert_id();
                 }
                 $ins_sql = "INSERT INTO $my_new_lp_item_view (" .
                         "lp_item_id, lp_view_id, view_count," .

+ 13 - 13
main/link/link.php

@@ -112,7 +112,7 @@ $nameTools = get_lang('Links');
 //condition for the session
 $session_id = api_get_session_id();
 $condition_session = api_get_session_condition($session_id, false);
-		
+
 if (isset($_GET['action']) && $_GET['action']=='addlink') {
 	$nameTools = '';
 	$interbreadcrumb[] = array ('url' => 'link.php', 'name' => get_lang('Links'));
@@ -270,11 +270,11 @@ if(api_get_setting('search_enabled')=='true') {
 					</div>
 				</div>';
 
-		
-		
-	
+
+
+
 		$sqlcategories = "SELECT * FROM ".$tbl_categories." $condition_session ORDER BY display_order DESC";
-		$resultcategories = api_sql_query($sqlcategories,__FILE__,__LINE__);
+		$resultcategories = Database::query($sqlcategories,__FILE__,__LINE__);
 
 		if (Database::num_rows($resultcategories)) {
 			echo '	<div class="row">
@@ -473,7 +473,7 @@ if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='
 	//Starting the table which contains the categories
 	$sqlcategories = "SELECT * FROM ".$tbl_categories." $condition_session ORDER BY display_order DESC";
 	$resultcategories = Database::query($sqlcategories);
-		
+
 	echo '<table class="data_table">';
 	// displaying the links which have no category (thus category = 0 or NULL), if none present this will not be displayed
 	$sqlLinks = "SELECT * FROM ".$tbl_link." WHERE category_id=0 or category_id IS NULL";
@@ -492,7 +492,7 @@ if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='
 	while ($myrow = Database::fetch_array($resultcategories)) {
 		//validacion when belongs to a session
 		$session_img = api_get_session_image($myrow['session_id'], $_user['status']);
-				
+
 		//if (!isset($urlview))
 		if ($urlview == '')
 		{
@@ -519,10 +519,10 @@ if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='
 					echo '<th width="81%"  style="font-weight: bold; text-align:left;padding-left: 5px;">';
 					echo '<a href="'.api_get_self()."?".api_get_cidreq()."&urlview=".Security::remove_XSS($newurlview)."\">";
 					echo "<img src=../img/remove.gif>&nbsp;&nbsp;".api_htmlentities($myrow["category_title"],ENT_QUOTES,$charset)."</a><br/>&nbsp;&nbsp;&nbsp;".$myrow["description"];
-					
+
 					if (api_is_allowed_to_edit(null,true))
-						{	
-							echo '<th>';	
+						{
+							echo '<th>';
 							showcategoryadmintools($myrow["id"]);
 							echo '</th>';
 						}
@@ -543,9 +543,9 @@ if (empty($_GET['action']) || ($_GET['action']!='editlink' && $_GET['action']!='
 					echo'</a><br />&nbsp;&nbsp;&nbsp;';
 					echo $myrow["description"];
 						if (api_is_allowed_to_edit(null, true))
-						{	
-							echo '<th style="text-align:center;">';	
-							showcategoryadmintools($myrow["id"]);			
+						{
+							echo '<th style="text-align:center;">';
+							showcategoryadmintools($myrow["id"]);
 							echo '</th>';
 						}
 					echo '</th>';

+ 1 - 1
main/metadata/importdocs.php

@@ -65,7 +65,7 @@ echo get_lang('Tool'), ': ', mysql_num_rows($result), "<br><br>\n";
 
 $idt = array(); $cidpar = '?cidReq=' . $_course['sysCode'];
 
-while ($row = mysql_fetch_array($result))  // load indexabletexts in memory
+while ($row = Database::fetch_array($result))  // load indexabletexts in memory
 {
     $mdObj = new mdobject($_course, substr($row['eid'], AFTER_DOT));
     $idt[$mdObj->mdo_url . $cidpar] = $row['indexabletext'];

+ 6 - 6
main/metadata/importlinks.php

@@ -88,7 +88,7 @@ function get_cat($catname)
     $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
     $result = Database::query("SELECT id FROM $linkcat_table WHERE " . $cateq, __FILE__, __LINE__);
 
-    if (mysql_num_rows($result) >= 1 && ($row = mysql_fetch_array($result)))
+    if (mysql_num_rows($result) >= 1 && ($row = Database::fetch_array($result)))
         return $row['id'];  // several categories with same name: take first
 
     return FALSE;
@@ -107,7 +107,7 @@ if (isset($lcn))  // category_title
 
     $result = $mdStore->mds_get_many('eid,mdxmltext', OF_EID_TYPE);
 
-    while ($row = mysql_fetch_array($result))
+    while ($row = Database::fetch_array($result))
         if (check_andor_get($row, '', $mdCat, $lcn)) $uceids[] = $row['eid'];
 
     if (($lci = get_cat($lcn)) !== FALSE)
@@ -115,7 +115,7 @@ if (isset($lcn))  // category_title
         $link_table = Database::get_course_table(TABLE_LINK);
         $result = Database::query("SELECT id FROM $link_table WHERE category_id=" . $lci, __FILE__, __LINE__);
 
-        while ($row = mysql_fetch_array($result))
+        while ($row = Database::fetch_array($result))
         {
             $lceids[$id = (int) $row['id']] = ($eid = EID_TYPE . '.' . $id);
 
@@ -194,7 +194,7 @@ elseif ($slo == get_lang('Index') && file_exists($phpDigIncCn) && count($mceids)
         OF_EID_TYPE . " AND eid IN ('" .
         implode("','", array_map('addslashes', $mceids)) . "')");
 
-    while ($row = mysql_fetch_array($result))  // load indexabletexts in memory
+    while ($row = Database::fetch_array($result))  // load indexabletexts in memory
         $idt[check_andor_get($row, $mdUrl)] = $row['indexabletext'];
 
     require($phpDigIncCn);  // switch to PhpDig DB
@@ -279,7 +279,7 @@ echo '<h3>', get_lang('Statistics'), '</h3>', "\n";
 $result = $mdStore->mds_get_many('eid,mdxmltext', OF_EID_TYPE);
 echo get_lang('TotalMDEs'), mysql_num_rows($result), "\n";
 
-while ($row = mysql_fetch_array($result))
+while ($row = Database::fetch_array($result))
 {
     $cat = check_andor_get($row, $mdCat);
     $perCat[$cat] = ($pc = $perCat[$cat]) ? $pc + 1 : 1;
@@ -327,7 +327,7 @@ if (count($perCat)) foreach ($perCat as $cat => $number)
 $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
 $result = Database::query("SELECT category_title FROM $linkcat_table", __FILE__, __LINE__);
 
-while ($row = mysql_fetch_array($result))
+while ($row = Database::fetch_array($result))
 {
     $cat = $row['category_title']; $hcat = htmlspecialchars($cat, ENT_QUOTES, $charset);
     if ($perCat[$cat] == $hcat) $dups[] = $cat;

+ 3 - 3
main/metadata/importmanifest.php

@@ -65,7 +65,7 @@ if (isset($workWith))  // explicit in URL, or selected at bottom of screen
 
     if (mysql_num_rows($result) == 1)
     {
-        if (($row = mysql_fetch_array($result)))
+        if (($row = Database::fetch_array($result)))
         {
         	$sdi = $row['id'];
         }
@@ -408,7 +408,7 @@ elseif ($smo == get_lang('Index') && file_exists($phpDigIncCn) &&
         ($sdisub ? "." . $sdisub . "\_%'" : ".%'") .
         ($sdiall ? "" : " AND NOT INSTR(eid,'_')"));  // SQL LIKE underscore
 
-    while ($row = mysql_fetch_array($result))  // load indexabletexts in memory
+    while ($row = Database::fetch_array($result))  // load indexabletexts in memory
     {
         // URL: index.php[?sid=xxx[&thumb=yyy]] (file[1]/@href: pptslnnn_t.jpg)
 
@@ -460,7 +460,7 @@ echo '<h3>', get_lang('Statistics'), '</h3>', "\n";
 $result = $mdStore->mds_get_many('eid', "eid LIKE '" . EID_TYPE . ".%'");
 echo get_lang('TotalMDEs'), mysql_num_rows($result), "\n";
 
-while ($row = mysql_fetch_array($result))
+while ($row = Database::fetch_array($result))
 {
     $eid_id = substr($eid = $row['eid'], TPLEN);
 

+ 1 - 1
main/metadata/index.php

@@ -70,7 +70,7 @@ $result = Database::query("SELECT isocode FROM " .
 
 $sep = ":"; $langLangs = $sep . "xx" . $sep . "xx";
 
-while ($row = mysql_fetch_array($result))
+while ($row = Database::fetch_array($result))
     if (($isocode = $row['isocode']))
     	$langLangs .= ",, " . $isocode . $sep . $isocode;
 

+ 2 - 2
main/metadata/md_document.php

@@ -164,7 +164,7 @@ function mdobject($_course, $id)
     $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v;
 
     $document_table = Database::get_course_table(TABLE_DOCUMENT);
-    if (($docinfo = @mysql_fetch_array(Database::query(
+    if (($docinfo = @Database::fetch_array(Database::query(
             "SELECT path,title,comment,filetype FROM $document_table WHERE id='" .
             addslashes($id) . "'", __FILE__, __LINE__))))
     {
@@ -177,7 +177,7 @@ function mdobject($_course, $id)
         $group_info = Database::get_course_table(TABLE_GROUP);
         if (($result = Database::query(
                 "SELECT id,secret_directory FROM $group_info",  __FILE__, __LINE__)))
-            while (($row = mysql_fetch_array($result)))
+            while (($row = Database::fetch_array($result)))
                 if (($secdir = $row['secret_directory'] . '/') ==
                         substr($this->mdo_path, 0, strlen($secdir)))
                 {

+ 1 - 1
main/metadata/md_funcs.php

@@ -263,7 +263,7 @@ var $mds_something;
 
 function mds_get($eid, $column = 'mdxmltext', $must_exist = '')  // none: FALSE
 {
-    if (($mdt = mysql_fetch_array($this->_query("SELECT " . $column .
+    if (($mdt = Database::fetch_array($this->_query("SELECT " . $column .
         " FROM " . MDS_TABLE . " WHERE ", $eid)))) return $mdt[$column];
 
     if ($must_exist) give_up($must_exist . $this->_coldat('eid', $eid));

+ 2 - 2
main/metadata/md_link.php

@@ -198,7 +198,7 @@ function mdobject($_course, $id)
     $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v;
 
     $link_table = Database::get_course_table(TABLE_LINK);
-    if (($linkinfo = @mysql_fetch_array(Database::query(
+    if (($linkinfo = @Database::fetch_array(Database::query(
             "SELECT url,title,description,category_id FROM $link_table WHERE id='" .
             addslashes($id) . "'", __FILE__, __LINE__))))
     {
@@ -208,7 +208,7 @@ function mdobject($_course, $id)
         $this->mdo_category =    ($lci = $linkinfo['category_id']);
 
         $linkcat_table = Database::get_course_table(TABLE_LINK_CATEGORY);
-        if (($catinfo = @mysql_fetch_array(Database::query(
+        if (($catinfo = @Database::fetch_array(Database::query(
                 "SELECT category_title FROM $linkcat_table WHERE id='" .
                 addslashes($lci) . "'", __FILE__, __LINE__))))
             $this->mdo_category_title =    $catinfo['category_title'];

+ 5 - 5
main/metadata/md_phpdig.php

@@ -78,13 +78,13 @@ function find_site($url)
 
     if (mysql_num_rows($result) == 1)
     {
-        $row = mysql_fetch_array($result); return (int) $row['site_id'];
+        $row = Database::fetch_array($result); return (int) $row['site_id'];
     }
     else
     {
         $result = Database::query("INSERT INTO " . PHPDIG_DB_PREFIX .
             "sites SET " . $site_url, __FILE__, __LINE__);  // new site
-        $site_id = mysql_insert_id();
+        $site_id = Database::insert_id();
 
         $result = Database::query("INSERT INTO " . PHPDIG_DB_PREFIX .
             "site_page (site_id,num_page) VALUES ('$site_id', '0')");
@@ -105,7 +105,7 @@ function remove_engine_entries($url, $path, $file = '')
         "spider WHERE site_id=" . ($site_id = find_site($url)) . $and_path,
         __FILE__, __LINE__);  // find page(s)
 
-    while ($row = mysql_fetch_array($result))
+    while ($row = Database::fetch_array($result))
     {
         Database::query("DELETE FROM " . PHPDIG_DB_PREFIX .
             "engine WHERE spider_id=" . (int)$row['spider_id'],
@@ -136,7 +136,7 @@ function index_words($site_id, $path, $file, $first_words, $keywords)
     Database::query("INSERT INTO " . PHPDIG_DB_PREFIX . $spider_set_path_etc,
         __FILE__, __LINE__);
 
-    $spider_id = mysql_insert_id(); $new = 0;
+    $spider_id = Database::insert_id(); $new = 0;
 
     foreach ($keywords as $key => $w)
     if (strlen($key) > SMALL_WORDS_SIZE and strlen($key) <= MAX_WORDS_SIZE and
@@ -153,7 +153,7 @@ function index_words($site_id, $path, $file, $first_words, $keywords)
                 "keywords (keyword,twoletters) VALUES ('" . addslashes($key) .
                 "','" .addslashes(substr(str_replace('\\','',$key),0,2)) ."')",
             __FILE__, __LINE__);
-            $key_id = mysql_insert_id(); $new++;
+            $key_id = Database::insert_id(); $new++;
         }
         else
         {

+ 1 - 1
main/metadata/md_scorm.php

@@ -87,7 +87,7 @@ function mdobject($_course, $id)
 
     $this->mdo_dcmap_e = $ieee_dcmap_e; $this->mdo_dcmap_v = $ieee_dcmap_v;
 	$sql = "SELECT path,description,lp_type FROM $scormdocument WHERE id='" . addslashes($id) . "'";
-    if (($docinfo = @mysql_fetch_array(Database::query($sql,__FILE__, __LINE__))))
+    if (($docinfo = @Database::fetch_array(Database::query($sql,__FILE__, __LINE__))))
     {
         $this->mdo_path =     $docinfo['path'];
 		//Sometimes the new scorm-tool adds '/.' at the end of a directory name, so remove this before continue

+ 1 - 1
main/metadata/search.php

@@ -96,7 +96,7 @@ if (isset($_POST['mdsc']))  // Search criteria
 
         $result = $mdStore->mds_get_many('eid,mdxmltext', $whereclause);
 
-        while (($myrow = @mysql_fetch_array($result)))
+        while (($myrow = @Database::fetch_array($result)))
         {
             // not quite a real manifest, but very much like one...
 

+ 1 - 1
main/metadata/statistics.php

@@ -84,7 +84,7 @@ echo get_lang('TotalMDEs'), mysql_num_rows($result), "<br>\n";
 
 echo count($kwds), ' ', get_lang('CourseKwds'), '<br>', "\n";
 
-while ($row = mysql_fetch_array($result))
+while ($row = Database::fetch_array($result))
 {
     $eid = $row['eid']; $curr = ''; $xmltext = $row['mdxmltext']; $offset = 0;
 

+ 1 - 1
main/metadata/update_indexabletext.php

@@ -58,7 +58,7 @@ echo get_lang('TotalMDEs'), $total = mysql_num_rows($result), "<br><br>\n";
 
 if ($total > 100) set_time_limit((int) ($total / 10));
 
-while ($row = mysql_fetch_array($result))
+while ($row = Database::fetch_array($result))
 {
     $eid = $row['eid']; $xmltext = $row['mdxmltext'];
     $xhtDoc->xht_xmldoc = new xmddoc(explode("\n", $xmltext));

+ 7 - 7
main/newscorm/aicc.class.php

@@ -93,16 +93,16 @@ class aicc extends learnpath {
 
 			//CRS distribute crs params into the aicc object
 			if(!empty($crs_params['course']['course_creator'])){
-				$this->course_creator = mysql_real_escape_string($crs_params['course']['course_creator']);
+				$this->course_creator = Database::escape_string($crs_params['course']['course_creator']);
 			}
 			if(!empty($crs_params['course']['course_id'])){
-				$this->course_id = mysql_real_escape_string($crs_params['course']['course_id']);
+				$this->course_id = Database::escape_string($crs_params['course']['course_id']);
 			}
 			if(!empty($crs_params['course']['course_system'])){
 				$this->course_system = $crs_params['course']['course_system'];
 			}
 			if(!empty($crs_params['course']['course_title'])){
-				$this->course_title = mysql_real_escape_string($crs_params['course']['course_title']);
+				$this->course_title = Database::escape_string($crs_params['course']['course_title']);
 			}
 			if(!empty($crs_params['course']['course_level'])){
 				$this->course_level = $crs_params['course']['course_level'];
@@ -129,7 +129,7 @@ class aicc extends learnpath {
 				$this->course_version = $crs_params['course']['version'];
 			}
 			if(!empty($crs_params['course_description'])){
-				$this->course_description = mysql_real_escape_string($crs_params['course_description']);
+				$this->course_description = Database::escape_string($crs_params['course_description']);
 			}
 
      		// Parse the Descriptor File (.des) - csv-type
@@ -258,7 +258,7 @@ class aicc extends learnpath {
 				"'aicc_api.php','".$this->course_creator."',$dsp)";
 		if($this->debug>2){error_log('New LP - In import_aicc(), inserting path: '. $sql,0);}
 		$res = Database::query($sql);
-		$lp_id = Database::get_last_insert_id();
+		$lp_id = Database::insert_id();
 		$this->lp_id = $lp_id;
 		api_item_property_update(api_get_course_info($course_code),TOOL_LEARNPATH,$this->lp_id,'LearnpathAdded',api_get_user_id());
 		api_item_property_update(api_get_course_info($course_code),TOOL_LEARNPATH,$this->lp_id,'visible',api_get_user_id());
@@ -298,7 +298,7 @@ class aicc extends learnpath {
 					")";
 			$res_item = Database::query($sql_item);
 			if($this->debug>1){error_log('New LP - In aicc::import_aicc() - inserting item : '.$sql_item.' : '.mysql_error(),0);}
-			$item_id = Database::get_last_insert_id();
+			$item_id = Database::insert_id();
 			//now update previous item to change next_item_id
 			if($previous != 0){
 				$upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE id = $previous";
@@ -673,7 +673,7 @@ class aicc extends learnpath {
 
 		$sql = "SELECT * FROM $tbl_lp WHERE id=".$lp_id;
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$row = mysql_fetch_array($result);
+		$row = Database::fetch_array($result);
 		$LPname = $row['path'];
 		$list = split('/',$LPname);
 		$LPnamesafe = $list[0];

+ 11 - 11
main/newscorm/aiccItem.class.php

@@ -50,37 +50,37 @@ class aiccItem extends learnpathItem{
 			     		switch($a)
 			     		{
             				case 'system_id':
-            					$this->identifier = mysql_real_escape_string(strtolower($value));
+            					$this->identifier = Database::escape_string(strtolower($value));
             					break;
             				case 'type':
-            					$this->au_type = mysql_real_escape_string($value);
+            					$this->au_type = Database::escape_string($value);
             					break;
             				case 'command_line':
-            					$this->command_line = mysql_real_escape_string($value);
+            					$this->command_line = Database::escape_string($value);
             					break;
             				case 'max_time_allowed':
-            					$this->maxtimeallowed = mysql_real_escape_string($value);
+            					$this->maxtimeallowed = Database::escape_string($value);
             					break;
             				case 'time_limit_action':
-            					$this->timelimitaction = mysql_real_escape_string($value);
+            					$this->timelimitaction = Database::escape_string($value);
             					break;
             				case 'max_score':
-            					$this->max_score = mysql_real_escape_string($value);
+            					$this->max_score = Database::escape_string($value);
             					break;
             				case 'core_vendor':
-            					$this->core_vendor = mysql_real_escape_string($value);
+            					$this->core_vendor = Database::escape_string($value);
             					break;
             				case 'system_vendor':
-            					$this->system_vendor = mysql_real_escape_string($value);
+            					$this->system_vendor = Database::escape_string($value);
             					break;
             				case 'file_name':
-            					$this->path = mysql_real_escape_string($value);
+            					$this->path = Database::escape_string($value);
             					break;
             				case 'mastery_score':
-            					$this->masteryscore = mysql_real_escape_string($value);
+            					$this->masteryscore = Database::escape_string($value);
             					break;
             				case 'web_launch':
-            					$this->parameters = mysql_real_escape_string($value);
+            					$this->parameters = Database::escape_string($value);
             					break;
 			     		}
 			     	}

+ 5 - 5
main/newscorm/document.php

@@ -130,7 +130,7 @@ $result = mysql_query ("SELECT * FROM $tbl_document
 				WHERE path LIKE    '".$curDirPath."/%'
 				AND   path NOT LIKE '".$curDirPath."/%/%'");
 
-if ($result) while($row = mysql_fetch_array($result, MYSQL_ASSOC))
+if ($result) while($row = Database::fetch_array($result, 'ASSOC'))
 {
   $attribute['path'      ][] = $row['path'      ];
   $attribute['visibility'][] = $row['visibility'];
@@ -353,7 +353,7 @@ if ($fileList)
     }
     $sql="SELECT name FROM $tbl_document WHERE ((path='$sqlpath') and (filetype='folder'))";
     $result=Database::query($sql,__FILE__,__LINE__);
-    $row=mysql_fetch_array($result);
+    $row=Database::fetch_array($result);
     if ($row['name']) { $name=$row['name']; } else { $name=$dspFileName; }
     echo	"<tr align=\"center\"", " class=".$oddclass.">\n",
         	"<td align=\"left\" valign='middle'>&nbsp;",
@@ -418,18 +418,18 @@ if (!$curDirPath) {
   $sql="select * from $tbl_learnpath_main";
   $result=Database::query($sql,__FILE__,__LINE__);
   $counter=0;
-  while ($row=mysql_fetch_array($result)) {
+  while ($row=Database::fetch_array($result)) {
     $counter++;
     if (($counter % 2)==0) { $oddclass="row_odd"; } else { $oddclass="row_even"; }
 
     $id=$row["learnpath_id"];
     $sql2="SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
     $result2=Database::query($sql2,__FILE__,__LINE__);
-    $row2=mysql_fetch_array($result2);
+    $row2=Database::fetch_array($result2);
     $name=$row2['learnpath_name'];
     $sql3="SELECT * FROM $tbl_tool where (name=\"$name\" and image='scormbuilder.gif')";
     $result3=Database::query($sql3,__FILE__,__LINE__);
-    $row3=mysql_fetch_array($result3);
+    $row3=Database::fetch_array($result3);
     if ((api_is_allowed_to_edit()) or ((!api_is_allowed_to_edit()) and ($row3["visibility"] == '1'))) {
       $row['learnpath_name']=str_replace(' ','&nbsp;',$row['learnpath_name']);
       if ($row3["visibility"] != '1') { $style=' class="invisible"'; } else { $style=''; }

+ 20 - 20
main/newscorm/learnpath.class.php

@@ -63,7 +63,7 @@ class learnpath {
 	var $arrMenu = array(); //array for the menu items
 
 	var $debug = 0; //logging level
-	
+
 	var $lp_session_id =0;
 
 	/**
@@ -136,7 +136,7 @@ class learnpath {
 	   			$this->preview_image= $row['preview_image'];
 	   			$this->author= $row['author'];
 	   			$this->lp_session_id = $row['session_id'];
-	   			
+
 	   			if($this->type == 2){
     				if($row['force_commit'] == 1){
     					$this->force_commit = true;
@@ -203,7 +203,7 @@ class learnpath {
 			$this->attempt = 1;
 			$sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
 			$res_ins = Database::query($sql_ins, __FILE__, __LINE__);
-			$this->lp_view_id = Database :: get_last_insert_id();
+			$this->lp_view_id = Database :: insert_id();
 			if ($this->debug > 2) {
 				error_log('New LP - learnpath::learnpath() ' . __LINE__ . ' - inserting new lp_view: ' . $sql_ins, 0);
 			}
@@ -510,7 +510,7 @@ class learnpath {
 		$res_ins = Database::query($sql_ins, __FILE__, __LINE__);
 
 		if ($res_ins > 0) {
-			$new_item_id = Database :: get_last_insert_id($res_ins);
+			$new_item_id = Database :: insert_id($res_ins);
 
 			//update the item that should come after the new item
 			$sql_update_next = "
@@ -598,10 +598,10 @@ class learnpath {
 		//check lp_name doesn't exist, otherwise append something
 		$i = 0;
 		$name = learnpath :: escape_string($name);
-		
+
 		//session_id
 		$session_id = api_get_session_id();
-		
+
 		$check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
 		//if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
 		$res_name = Database::query($check_name, __FILE__, __LINE__);
@@ -649,7 +649,7 @@ class learnpath {
 				"'local','','".Database::escape_string($session_id)."')";
 				//if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
 				$res_insert = Database::query($sql_insert, __FILE__, __LINE__);
-				$id = Database :: get_last_insert_id();
+				$id = Database :: insert_id();
 				if ($id > 0) {
 					//insert into item_property
 					api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $id, 'LearnpathAdded', api_get_user_id());
@@ -2280,9 +2280,9 @@ class learnpath {
 			return '';
 		}
 	}
-	
+
 	/**
-	* Gets the learnpath session id 
+	* Gets the learnpath session id
 	* @return	string	Learnpath theme
 	*/
 	function get_lp_session_id() {
@@ -2295,7 +2295,7 @@ class learnpath {
 			return 0;
 		}
 	}
-	
+
 
 	/**
 	 * Gets the learnpath image
@@ -2778,10 +2778,10 @@ class learnpath {
 	 * @return	string	HTML TOC ready to display
 	 */
 	function get_html_toc() {
-		
-		
+
+
 		$is_allowed_to_edit = api_is_allowed_to_edit(null,true);
-				
+
 		$charset = api_get_setting('platform_charset');
 		$display_action_links_with_icons = false;
 
@@ -2796,7 +2796,7 @@ class learnpath {
 		// build, display
 		if ($is_allowed_to_edit) {
 			$gradebook = Security :: remove_XSS($_GET['gradebook']);
-			
+
 			//var_dump($this->get_lp_session_id());
 			if ($this->get_lp_session_id()==api_get_session_id()) {
 				$html .= '<div class="actions_lp">';
@@ -2811,8 +2811,8 @@ class learnpath {
 				}
 				$html .= '</div>';
 			}
-			
-			
+
+
 		}
 		$html .= '<div id="inner_lp_toc" class="inner_lp_toc">' . "\n";
 		require_once ('resourcelinker.inc.php');
@@ -3221,7 +3221,7 @@ class learnpath {
 			$sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
 			"VALUES (" . $this->get_id() . "," . $this->get_user_id() . ",1)";
 			$res = Database::query($sql, __FILE__, __LINE__);
-			$id = Database :: get_last_insert_id();
+			$id = Database :: insert_id();
 			$this->lp_view_id = $id;
 		}
 		return $this->lp_view_id;
@@ -3704,7 +3704,7 @@ class learnpath {
 			error_log('New LP - Inserting new lp_view for restart: ' . $sql, 0);
 		}
 		$res = Database::query($sql, __FILE__, __LINE__);
-		if ($view_id = Database :: get_last_insert_id($res)) {
+		if ($view_id = Database :: insert_id($res)) {
 			$this->lp_view_id = $view_id;
 			$this->attempt = $this->attempt + 1;
 		} else {
@@ -4609,9 +4609,9 @@ class learnpath {
 	 * @return string
 	 */
 	function overview() {
-		
+
 		$is_allowed_to_edit = api_is_allowed_to_edit(null,true);
-			
+
 		$platform_charset = api_get_system_encoding();
 		if ($this->debug > 0) {
 			error_log('New LP - In learnpath::overview()', 0);

+ 2 - 2
main/newscorm/learnpathItem.class.php

@@ -2235,7 +2235,7 @@ function get_terms()
 
       			if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view forced: '.$sql,0);}
 		     	$res = Database::query($sql,__FILE__,__LINE__);
-		     	$this->db_item_view_id = Database::get_last_insert_id();
+		     	$this->db_item_view_id = Database::insert_id();
 		     	$inserted = true;
 		   }
 
@@ -2281,7 +2281,7 @@ function get_terms()
 		     			"'".$this->lesson_location."')";
 		     	if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view: '.$sql,0);}
 		     	$res = Database::query($sql,__FILE__,__LINE__);
-		     	$this->db_item_view_id = Database::get_last_insert_id();
+		     	$this->db_item_view_id = Database::insert_id();
 	     	} else {
 	     		$sql = '';
 	     		if($this->type=='hotpotatoes') {

+ 5 - 5
main/newscorm/learnpathList.class.php

@@ -35,12 +35,12 @@ class learnpathList {
     	}
     	$this->course_code = $course_code;
     	$this->user_id = $user_id;
-    	
+
     	//condition for the session
 		$session_id = api_get_session_id();
 		$condition_session = api_get_session_condition($session_id, false);
-    	
-    	$sql = "SELECT * FROM $lp_table $condition_session ORDER BY display_order ASC, name ASC";    	
+
+    	$sql = "SELECT * FROM $lp_table $condition_session ORDER BY display_order ASC, name ASC";
     	$res = Database::query($sql);
     	$names = array();
     	while ($row = Database::fetch_array($res))
@@ -48,7 +48,7 @@ class learnpathList {
     		//check if published
     		$pub = '';
     		$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
-    		//use domesticate here instead of mysql_real_escape_string because
+    		//use domesticate here instead of Database::escape_string because
     		//it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
     		//is done using domesticate()
     		$myname = domesticate($row['name']);
@@ -67,7 +67,7 @@ class learnpathList {
 
     		$this->list[$row['id']] = array(
     			'lp_type' => $row['lp_type'],
-    			'lp_session' => $row['session_id'],    			
+    			'lp_session' => $row['session_id'],
     			'lp_name' => stripslashes($row['name']),
     			'lp_desc' => stripslashes($row['description']),
     			'lp_path' => $row['path'],

+ 43 - 43
main/newscorm/learnpath_functions.inc.php

@@ -95,7 +95,7 @@ function deletemodule($parent_item_id)
 	//Added for multi-level behaviour - slightly recursive
 	$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$learnpath_id";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		if ($row['parent_item_id'] == $parent_item_id)
 		{
@@ -154,7 +154,7 @@ function deletepath($path_id)
 	//also delete all elements inside that path
 	$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$path_id";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		deletemodule($row['id']);
 	}
@@ -280,7 +280,7 @@ function movemodule($direction, $id)
 	// see similar comment in moveitem() function
 	// @TODO: this only works for chapters in multi-level mode. Why not gather
 	// this function and moveitem to keep only one multi-uses function?
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		// step 2: performing the move (only happens when passed trhough step 1 at least once)
 		if (!empty ($this_cat_order))
@@ -332,7 +332,7 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
 			AND parent_item_id = $parent_id
 			ORDER BY display_order DESC";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	$row = mysql_fetch_array($result);
+	$row = Database::fetch_array($result);
 	$last_chapter_order = $row["display_order"];
 
 	// getting the last order number of the items
@@ -340,7 +340,7 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
 			AND parent_item_id = $parent_id
 			ORDER BY display_order DESC";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	$row = mysql_fetch_array($result);
+	$row = Database::fetch_array($result);
 	$last_item_order = $row["display_order"];
 	$new_order = max($last_chapter_order, $last_item_order) + 1;
 
@@ -357,7 +357,7 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
 		{
 			return false;
 		}
-		$id = Database :: get_last_insert_id();
+		$id = Database :: insert_id();
 	}
 	elseif ($type === 'item')
 	{
@@ -372,7 +372,7 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
 		{
 			return false;
 		}
-		$id = Database :: get_last_insert_id();
+		$id = Database :: insert_id();
 	}
 	return $id;
 }
@@ -390,7 +390,7 @@ function array_learnpath_categories()
 	$sql = "SELECT * FROM  $tbl_learnpath_chapter  WHERE (lp_id=$learnpath_id) ORDER BY display_order ASC";
 	$result = Database::query($sql, __FILE__, __LINE__);
 
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		$array_learnpath_categories[] = array ($row["id"], $row["chapter_name"]);
 	}
@@ -464,7 +464,7 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve
 	$counter = 0;
 	$num_modules = count($tree[$parent_item_id]);
 
-	//while ($row=mysql_fetch_array($result))
+	//while ($row=Database::fetch_array($result))
 	if (isset ($tree[$parent_item_id]))
 	{
 		foreach ($tree[$parent_item_id] as $row)
@@ -579,7 +579,7 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve
 							{
 								echo get_lang('prereq_deleted_error');
 							}
-							$row_items2 = mysql_fetch_array($result_items2);
+							$row_items2 = Database::fetch_array($result_items2);
 							display_addedresource_link_in_learnpath($row_items2["item_type"], $row_items2["ref"], '', $row_items2["id"], 'builder', '', 0);
 							if ((($row_items2["item_type"] == TOOL_QUIZ) or ($row_items2["item_type"] == 'HotPotatoes')) and ($row_items['prerequisite']))
 							{
@@ -597,7 +597,7 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve
 							{
 								echo "<font color='red'>$lang_prereq_deleted_error</font>";
 							}
-							$row_items2 = mysql_fetch_array($result_items2);
+							$row_items2 = Database::fetch_array($result_items2);
 							echo " {$row_items2['title']}";
 						}*/
 					}
@@ -658,7 +658,7 @@ function display_all_learnpath()
 	$i = 1;
 	$num_modules = mysql_num_rows($result);
 
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		//other grey color : #E6E6E6
 		echo "<tr><td bgcolor=\"$color2\" width=400><b>&nbsp;";
@@ -674,11 +674,11 @@ function display_all_learnpath()
 			$id = $row["lp_id"];
 			$sql2 = "SELECT * FROM $tbl_learnpath_main where lp_id=$id";
 			$result2 = Database::query($sql2, __FILE__, __LINE__);
-			$row2 = mysql_fetch_array($result2);
+			$row2 = Database::fetch_array($result2);
 			$name = $row2['learnpath_name'];
 			$sql3 = "SELECT * FROM $tbl_tool where (name=\"$name\" and image='scormbuilder.gif')";
 			$result3 = Database::query($sql3, __FILE__, __LINE__);
-			$row3 = mysql_fetch_array($result3);
+			$row3 = Database::fetch_array($result3);
 			if (($row3["visibility"]) == '1')
 			{
 				echo "<td bgcolor=\"$color2\" align=center><a href='".api_get_self()."?action=publishpath&set=i&id=".$row["lp_id"]."'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9><img src=\"../img/visible.gif\" border=\"0\" title=\"$lang_no_publish\"></a></td>";
@@ -820,16 +820,16 @@ function learnpath_items($itemid)
 
 	$sql_items = "SELECT parent_item_id FROM $tbl_lp_item WHERE id='$itemid'";
 	$moduleid_sql = Database::query($sql_items);
-	$moduleid_array = mysql_fetch_array($moduleid_sql); //first row of the results
+	$moduleid_array = Database::fetch_array($moduleid_sql); //first row of the results
 	$moduleid = $moduleid_array["parent_item_id"];
 
 	$sql_items = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$moduleid' ORDER BY display_order ASC";
 	$result_items = Database::query($sql_items);
-	$ar = mysql_fetch_array($result_items);
+	$ar = Database::fetch_array($result_items);
 	while ($ar != '')
 	{
 		$result[] = $ar;
-		$ar = mysql_fetch_array($result_items);
+		$ar = Database::fetch_array($result_items);
 	}
 	return $result;
 
@@ -850,11 +850,11 @@ function learnpath_chapters($learnpath_id)
 	$sql_items = "SELECT * FROM $tbl_lp_item WHERE lp_id='$learnpath_id' AND item_type='dokeos_chapter' ORDER BY display_order ASC";
 	//$sql_items = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id='$learnpath_id' ORDER BY display_order ASC";
 	$result_items = Database::query($sql_items, __FILE__, __LINE__);
-	$ar = mysql_fetch_array($result_items);
+	$ar = Database::fetch_array($result_items);
 	while ($ar != '')
 	{
 		$result[] = $ar;
-		$ar = mysql_fetch_array($result_items);
+		$ar = Database::fetch_array($result_items);
 	}
 	return $result;
 
@@ -910,7 +910,7 @@ function prereqcheck($id_in_path)
 	//3 Get item data from the database
 	$sql_items = "SELECT * FROM $tbl_learnpath_item WHERE id='$id_in_path'";
 	$result_items = Database::query($sql_items);
-	$row = mysql_fetch_array($result_items);
+	$row = Database::fetch_array($result_items);
 	//4 Check prerequisite's type
 	if ($row['prereq_type'] == 'i')
 	{
@@ -930,7 +930,7 @@ function prereqcheck($id_in_path)
 		}
 		$sql_items3 = "SELECT * FROM $tbl_learnpath_user WHERE (learnpath_item_id='$id_in_path3' and user_id=$user_id)";
 		$result_items3 = Database::query($sql_items3);
-		$row3 = mysql_fetch_array($result_items3);
+		$row3 = Database::fetch_array($result_items3);
 
 		//4.a.3 Get the link that needs to be shown for the current item (not the prereq)
 		$stepname = display_addedresource_link_in_learnpath($row['item_type'], $row['ref'], '', $id_in_path, 'builder', 'nolink');
@@ -940,7 +940,7 @@ function prereqcheck($id_in_path)
 		//4.a.4 Get the prerequisite item
 		$sql6 = "SELECT * FROM $tbl_learnpath_item WHERE (id='$id_in_path3')";
 		$result6 = Database::query($sql6);
-		$row6 = mysql_fetch_array($result6);
+		$row6 = Database::fetch_array($result6);
 		//4.a.5 Get a link to the prerequisite item
 		$prereqname = display_addedresource_link_in_learnpath($row6['item_type'], $row6['ref'], '', $id_in_path3, 'builder', 'nolink'); //this is the prereq of the step we want to open
 
@@ -986,7 +986,7 @@ function prereqcheck($id_in_path)
 		$sql_items3 = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$id_in_path2'";
 		$result_items3 = Database::query($sql_items3);
 		$allcompleted = true;
-		while ($row3 = mysql_fetch_array($result_items3))
+		while ($row3 = Database::fetch_array($result_items3))
 		{
 			//4.b.3 Cycle through items in the prerequisite chapter
 			//4.b.3.1 Get data ready to use
@@ -1002,7 +1002,7 @@ function prereqcheck($id_in_path)
 			//4.b.3.2 Get user-item relation
 			$sql_items4 = "SELECT * FROM $tbl_learnpath_user WHERE (learnpath_item_id='$id_in_path4' and user_id=$user_id)";
 			$result_items4 = Database::query($sql_items4);
-			$row4 = mysql_fetch_array($result_items4);
+			$row4 = Database::fetch_array($result_items4);
 			//4.b.3.3 If any of these elements is not 'completed', the overall completion status is false
 			if ($row4['status'] != "completed" and $row4['status'] != 'passed')
 			{
@@ -1019,7 +1019,7 @@ function prereqcheck($id_in_path)
 			//4.b.4.b Something was not completed. Return corresponding message
 			$sql5 = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id='$learnpath_id' and id='$id_in_path2')";
 			$result5 = Database::query($sql5);
-			$row5 = mysql_fetch_array($result5);
+			$row5 = Database::fetch_array($result5);
 			$prereqmodulename = trim($row5['chapter_name']);
 			$prereq = $langPrereqModuleMinimum1.$prereqmodulename.$langPrereqModuleMinimum2;
 		}
@@ -1084,7 +1084,7 @@ function get_learnpath_tree($learnpath_id)
 		//error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql,0);
 		$res = Database::query($sql, __FILE__, __LINE__);
 		//error_log('New LP - learnpath_functions - get_learnpath_tree: Found '.Database::num_rows($res).' results',0);
-		while ($myrow = mysql_fetch_array($res, MYSQL_ASSOC))
+		while ($myrow = Database::fetch_array($res, 'ASSOC'))
 		{
 			//$items[] = $myrow;
 			//$items_by_chapter[$myrow['parent_item_id']][$myrow['display_order']] = $myrow;
@@ -1196,7 +1196,7 @@ function display_toc_chapter_contents($tree, $parent_item_id = 0, $learnpath_id,
 			// If this element is an item (understand: not a directory/module)
 			$sql0 = "SELECT * FROM $tbl_learnpath_user WHERE (user_id='".$uid."' and learnpath_item_id='".$elem['id']."' and lp_id='".$learnpath_id."')";
 			$result0 = Database::query($sql0, __FILE__, __LINE__);
-			$row0 = mysql_fetch_array($result0);
+			$row0 = Database::fetch_array($result0);
 
 			$completed = '';
 			if (($row0['status'] == 'completed') or ($row0['status'] == 'passed'))
@@ -1295,7 +1295,7 @@ function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree
 
 			$sql = "SELECT * FROM $tbl_learnpath_user "."WHERE user_id = $user_id "."AND lp_id = $learnpath_id "."AND learnpath_item_id = ".$elem['id'];
 			$res = Database::query($sql, __FILE__, __LINE__);
-			$myrow = mysql_fetch_array($res);
+			$myrow = Database::fetch_array($res);
 
 			if (($myrow['status'] == 'completed') || ($myrow['status'] == 'passed'))
 			{
@@ -1341,7 +1341,7 @@ function is_empty($id)
 
 	if ($num_modules != 0)
 	{
-		while ($row = mysql_fetch_array($result))
+		while ($row = Database::fetch_array($result))
 		{
 
 			$num_items = 0;
@@ -1700,7 +1700,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			$barreMois = "";
 
 			//3 For each event corresponding to this agenda, do the following:
-			while ($myrow = mysql_fetch_array($result))
+			while ($myrow = Database::fetch_array($result))
 			{
 				//3.1 Make the blue month bar appear only once.
 				if ($barreMois != date("m", strtotime($myrow["start_date"])))
@@ -1774,7 +1774,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			$expcontent .= "<table class=\"data_table\">";
 
 			//3 For each announcement matching the query
-			while ($myrow = mysql_fetch_array($result))
+			while ($myrow = Database::fetch_array($result))
 			{
 				//3.1 Get the __ field data
 				$content = $myrow[1];
@@ -1821,7 +1821,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 				//2.a This course has one (or more) description in the database
 				$expcontent .= "<hr noshade=\"noshade\" size=\"1\" />";
 				//2.a.1 For each description available for this course
-				while ($row = mysql_fetch_array($result))
+				while ($row = Database::fetch_array($result))
 				{
 					//2.a.1.1 Write title to export string
 					$expcontent .= "<h4>".$row['title']."</h4>";
@@ -1845,7 +1845,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
 			$sql_query = "SELECT * FROM $tbl_document WHERE id=$item_id";
 			$sql_result = Database::query($sql_query, __FILE__, __LINE__);
-			$myrow = mysql_fetch_array($sql_result);
+			$myrow = Database::fetch_array($sql_result);
 			//2 Get the origin path of the document to treat it internally
 			$orig = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$myrow["path"];
 			//3 Make some kind of strange transformation to get the destination filepath ???
@@ -1958,7 +1958,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			//1 Get the introduction text data from the database
 			$TBL_INTRO = Database :: get_course_tool_intro_table();
 			$result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE id=1");
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			$intro = $myrow["intro_text"];
 			//2 Write introduction text to the export string
 			$expcontent .= "<br />".$intro;
@@ -1969,7 +1969,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			//1 Get HotPotatoes data from the document table
 			$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
 			$result = Database::query("SELECT * FROM $tbl_document WHERE id=$item_id", __FILE__, __LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			//2 Get the document path
 			$testfile = api_get_path(SYS_COURSE_PATH).$_course['path']."/document".urldecode($myrow['path']);
 			//3 Get the document contents into a string
@@ -2047,11 +2047,11 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			$tbl_posts =Database::get_course_table(TABLE_FORUM_POST);
 			$tbl_posts_text =Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
 			$result = Database::query("SELECT * FROM $tbl_posts where post_id=$item_id", __FILE__, __LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_titel = "SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow["post_id"];
 			$result_titel = Database::query($sql_titel, __FILE__, __LINE__);
-			$myrow_titel = mysql_fetch_array($result_titel);
+			$myrow_titel = Database::fetch_array($result_titel);
 
 			$posternom = $myrow['nom'];
 			$posterprenom = $myrow['prenom'];
@@ -2093,7 +2093,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
 			//1 Get the link data from the database
 			$TABLETOOLLINK = Database :: get_course_link_table();
 			$result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$item_id", __FILE__, __LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			$thelink = $myrow["url"];
 			//2 Check the link type (open in blank page or in current page)
 			if ($item_type == "Link _blank")
@@ -2200,7 +2200,7 @@ function exportpath($learnpath_id)
 	include_once (api_get_path(LIBRARY_PATH)."fileUpload.lib.php");
 	$sql = "SELECT * FROM $tbl_learnpath_main WHERE (lp_id=$learnpath_id)";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	$row = mysql_fetch_array($result);
+	$row = Database::fetch_array($result);
 	$LPname = $row['learnpath_name'];
 	$LPnamesafe = replace_dangerous_char($LPname, 'strict');
 
@@ -2231,7 +2231,7 @@ function exportpath($learnpath_id)
 	$result = Database::query($sql, __FILE__, __LINE__);
 
 	//5 export the items listed in Circle I one by one
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		//5.1 Get items data from the database for this chapter
 		$parent_item_id = $row['id'];
@@ -2240,7 +2240,7 @@ function exportpath($learnpath_id)
 		$sql2b = "SELECT * FROM $tbl_learnpath_item WHERE (parent_item_id=$parent_item_id) ORDER BY display_order ASC";
 		$result2b = Database::query($sql2b, __FILE__, __LINE__);
 
-		while ($row2 = mysql_fetch_array($result2b))
+		while ($row2 = Database::fetch_array($result2b))
 		{
 			//5.1.1 Check if the element is in the circle1 array
 			$tobeexported = false;
@@ -2456,7 +2456,7 @@ function createimsmanifest($circle1_files, $learnpath_id)
 
 		$sql = "SELECT * FROM $tbl_learnpath_item WHERE (id=".$circle1_files[2][$i].")";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$row = mysql_fetch_array($result);
+		$row = Database::fetch_array($result);
 		$parent_item_id = $row['parent_item_id'];
 
 		if ($parent_item_id != $previous_item_id)
@@ -2464,7 +2464,7 @@ function createimsmanifest($circle1_files, $learnpath_id)
 			//we create the item tag for the chapter (without indifierref)
 			$sql2 = "SELECT * FROM $tbl_learnpath_chapter WHERE (id=".$parent_item_id.")";
 			$result2 = Database::query($sql2, __FILE__, __LINE__);
-			$row2 = mysql_fetch_array($result2);
+			$row2 = Database::fetch_array($result2);
 			$chapter_name = $row2['chapter_name'];
 
 			$attributes = '';

+ 6 - 6
main/newscorm/lp_upload.php

@@ -78,9 +78,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST'
 				$oAICC->import_aicc(api_get_course_id());
 			}
 			$proximity = '';
-			if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
+			if(!empty($_REQUEST['content_proximity'])){$proximity = Database::escape_string($_REQUEST['content_proximity']);}
 			$maker = '';
-			if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
+			if(!empty($_REQUEST['content_maker'])){$maker = Database::escape_string($_REQUEST['content_maker']);}
 			$oAICC->set_proximity($proximity);
 			$oAICC->set_maker($maker);
 			$oAICC->set_jslib('aicc_api.php');
@@ -134,9 +134,9 @@ elseif($_SERVER['REQUEST_METHOD'] == 'POST')
 			}
 
 			$proximity = '';
-			if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
+			if(!empty($_REQUEST['content_proximity'])){$proximity = Database::escape_string($_REQUEST['content_proximity']);}
 			$maker = '';
-			if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
+			if(!empty($_REQUEST['content_maker'])){$maker = Database::escape_string($_REQUEST['content_maker']);}
 			$oScorm->set_proximity($proximity);
 			$oScorm->set_maker($maker);
 			$oScorm->set_jslib('scorm_api.php');
@@ -150,9 +150,9 @@ elseif($_SERVER['REQUEST_METHOD'] == 'POST')
 				$oAICC->import_aicc(api_get_course_id());
 			}
 			$proximity = '';
-			if(!empty($_REQUEST['content_proximity'])){$proximity = mysql_real_escape_string($_REQUEST['content_proximity']);}
+			if(!empty($_REQUEST['content_proximity'])){$proximity = Database::escape_string($_REQUEST['content_proximity']);}
 			$maker = '';
-			if(!empty($_REQUEST['content_maker'])){$maker = mysql_real_escape_string($_REQUEST['content_maker']);}
+			if(!empty($_REQUEST['content_maker'])){$maker = Database::escape_string($_REQUEST['content_maker']);}
 			$oAICC->set_proximity($proximity);
 			$oAICC->set_maker($maker);
 			$oAICC->set_jslib('aicc_api.php');

+ 55 - 55
main/newscorm/resourcelinker.inc.php

@@ -114,7 +114,7 @@ function show_documents($folder)
 	$document_table = Database::get_course_table(TABLE_DOCUMENT);
 	$sql="SELECT * from $document_table, $item_property_table WHERE id=ref AND tool = '".TOOL_DOCUMENT."' AND $visibility AND to_group_id = 0 AND to_user_id IS NULL  ORDER BY path ASC";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		if (!$folder)
 		{
@@ -169,7 +169,7 @@ function show_documents($folder)
 			//	echo '<br />';
 			//	}// if (str_replace($folder.'/','',$conform_folder)!==$folder)
 		} // else (if (!$folder))
-	} //while ($row=mysql_fetch_array($result))
+	} //while ($row=Database::fetch_array($result))
 
 	// this is code for the case that we are in a subfolder
 	if ($good_paths)
@@ -282,31 +282,31 @@ function display_addedresource_link($type, $id, $style='')
 		case 'Agenda':
 			$TABLEAGENDA = $_course['dbNameGlu'].'calendar_event';
 			$result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Ad_Valvas':
 			$tbl_announcement = $_course['dbNameGlu'].'announcement';
 			$result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Link':
 			$TABLETOOLLINK = $_course['dbNameGlu'].'link';
 			$result = Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode($myrow['url'])."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Exercise':
 			$TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
 			$result = Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Forum':
 			$TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
 			$result = Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow['forum_name']."</a><br />\n";
 			break;
 		case 'Thread':  //=topics
@@ -314,24 +314,24 @@ function display_addedresource_link($type, $id, $style='')
 			$tbl_posts_text	= $_course['dbNameGlu'].'bb_posts_text';
 			$TBL_FORUMS		= $_course['dbNameGlu'].'bb_forums';
 			$result = Database::query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
 			$result_title = Database::query($sql_title,__FILE__,__LINE__);
-			$myrow_title = mysql_fetch_array($result_title);
+			$myrow_title = Database::fetch_array($result_title);
 			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow['topic_id'].'&amp;forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow_title['post_title']."</a><br />\n";
 			break;
 		case 'Post':
 			$tbl_post = Database::get_course_table(TABLE_FORUM_POST);
 			$sql = "SELECT * FROM $tbl_post p WHERE post_id = $id";
 			$result = Database::query($sql,__FILE__,__LINE__);
-			$post = mysql_fetch_object($result);
+			$post = Database::fetch_object($result);
 			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post->topic_id.'&amp;forum='.$post->forum_id.'"'.$styling.'>'.$post->post_title."</a><br />\n";
 			break;
 		case 'Document':
 			$dbTable = $_course['dbNameGlu'].'document';
 			$result = Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			$pathname = explode('/',$myrow['path']); // making a correct name for the link
 			$last = count($pathname) - 1;  // making a correct name for the link
 			$filename = $pathname[$last];  // making a correct name for the link
@@ -386,10 +386,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Agenda":
 			$TABLEAGENDA 		= $_course['dbNameGlu']."calendar_event";
 			$result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			$agenda_id=$row['item_id'];
@@ -436,10 +436,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Ad_Valvas":
 			$tbl_announcement = $_course['dbNameGlu']."announcement";
 			$result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["content"]=$row['title']; }
 			$desc=$row['description'];
 			$ann_id=$row['item_id'];
@@ -496,10 +496,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Link" :
 			$TABLETOOLLINK	= $_course['dbNameGlu']."link";
 			$result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -555,14 +555,14 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Exercise":
 			$TBL_EXERCICES  = $_course['dbNameGlu'].'quiz';
 			$result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder=='builder') { $origin='builder'; }
 			  //this is needed for the exercise_submit.php can delete the session info about tests
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
 			$result=Database::query($sql,__FILE__,__LINE__);
-			$row=mysql_fetch_array($result);
+			$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -613,7 +613,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$TBL_DOCUMENT  = $_course['dbNameGlu'].'document';
 			$documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
 			$result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
-			$myrow= mysql_fetch_array($result);
+			$myrow= Database::fetch_array($result);
 			$path=$myrow["path"];
 			$name=GetQuizName($path,$documentPath);
 
@@ -621,7 +621,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			  //this is needed for the exercise_submit.php can delete the session info about tests
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -671,10 +671,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Forum":
 			$TBL_FORUMS = Database::get_course_table(TABLE_FORUM,$_course['database']);
 			$result= Database::query("SELECT * FROM $TBL_FORUMS WHERE forum_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -723,10 +723,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$tbl_topics = Database::get_course_table(TABLE_FORUM_THREAD,$_course['database']);
 			$sql="SELECT * FROM $tbl_topics where topic_id=$id";
 			$result= Database::query($sql,__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -775,14 +775,14 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$tbl_posts_text  = $_course['dbNameGlu'].'bb_posts_text';
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
 			$result_titel=Database::query($sql_titel,__FILE__,__LINE__);
-			$myrow_titel=mysql_fetch_array($result_titel);
+			$myrow_titel=Database::fetch_array($result_titel);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -839,7 +839,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$mysql = "SELECT * FROM `$dbTable` WHERE id=$id";
 			//error_log('New LP - Querying document table: '.$mysql,0);
 			$result = Database::query($mysql,__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$pathname=explode("/",$myrow["path"]); // making a correct name for the link
 			$last=count($pathname)-1;  // making a correct name for the link
@@ -861,7 +861,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
 			//error_log('New LP - Querying lp_item table: '.$sql,0);
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $filename=$row['title']; }
 			$desc=$row['description'];
 
@@ -906,7 +906,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Assignments":
 			$name=get_lang('Assignments');
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -955,7 +955,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Dropbox":
 			$name=get_lang('Dropbox');
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -994,7 +994,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Introduction_text":
 			$name=get_lang('IntroductionText');
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1035,7 +1035,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Course_description":
 			$name=get_lang('CourseDescription');
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1075,7 +1075,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Groups":
 			$name=get_lang('Groups');
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1114,7 +1114,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Users":
 			$name=get_lang('Users');
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1181,10 +1181,10 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Agenda":
 			$TABLEAGENDA 		= $_course['dbNameGlu']."calendar_event";
 			$result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			$agenda_id=$row['item_id'];
@@ -1202,7 +1202,7 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Ad_Valvas":
 			$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
 			$result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder != 'builder')
 			{
@@ -1217,10 +1217,10 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Link" :
 			$TABLETOOLLINK	= $_course['dbNameGlu']."link";
 			$result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 
 			$thelink=$myrow["url"];
 			if ($builder != 'builder')
@@ -1236,13 +1236,13 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Exercise":
 			$TBL_EXERCICES  = $_course['dbNameGlu'].'quiz';
 			$result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder=='builder') { $origin='builder'; }
 			  //this is needed for the exercise_submit.php can delete the session info about tests
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 
 			if ($builder != 'builder')
@@ -1259,7 +1259,7 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 	  	    $TBL_DOCUMENT  = $_course['dbNameGlu'].'document';
 		    $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
 			$result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
-		    $myrow= mysql_fetch_array($result);
+		    $myrow= Database::fetch_array($result);
 		    $path=$myrow["path"];
 		  	$name=GetQuizName($path,$documentPath);
 
@@ -1280,12 +1280,12 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Forum":
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";  // TODO: This is the old table name, it should be corrected.
 			$result= Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder=='builder') { $origin='builder'; }
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
 
 			if ($myrow["forum_name"]=='') { $type="Forum"; }
@@ -1307,10 +1307,10 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$sql="SELECT * FROM `$tbl_topics` where topic_id=$id";
 			$result= Database::query($sql,__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 
 			if ($builder != 'builder')
 			{
@@ -1327,14 +1327,14 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 			$tbl_posts_text  = $_course['dbNameGlu'].'bb_posts_text';
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
 			$result_titel=Database::query($sql_titel,__FILE__,__LINE__);
-			$myrow_titel=mysql_fetch_array($result_titel);
+			$myrow_titel=Database::fetch_array($result_titel);
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
 			$desc=$row['description'];
     		$link .= str_repeat("&nbsp;&gt;",$level);
@@ -1357,14 +1357,14 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Document":
 			$dbTable  = $_course['dbNameGlu']."document";
 			$result=Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$pathname=explode("/",$myrow["path"]); // making a correct name for the link
 			$last=count($pathname)-1;  // making a correct name for the link
 			$filename=$pathname[$last];  // making a correct name for the link
 
 			$sql="select * from $tbl_lp_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 
 			if ($builder != 'builder')
 			{
@@ -1533,7 +1533,7 @@ function edit_added_resources($type, $id)
 
 	$sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id=$id";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		$addedresource[]=$row["resource_type"];
 		$addedresourceid[]=$row["resource_id"];
@@ -1576,7 +1576,7 @@ function display_added_resources($type, $id, $style='')
 
 	$sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		if ($origin != 'learnpath')
 		{

+ 25 - 25
main/newscorm/resourcelinker.php

@@ -130,7 +130,7 @@ if (!empty ($_POST['add_chapter']) && !empty ($_POST['title']))
 			"WHERE lp_id = $learnpath_id ".
 			" AND parent_item_id = $chapter_id";
 	$res = Database::query($sql, __FILE__, __LINE__);
-	$row = mysql_fetch_array($res);
+	$row = Database::fetch_array($res);
 	$lastorder_item = $row['maxi'];
 	if(empty($lastorder_item)){
 		$lastorder_item = 0;
@@ -148,7 +148,7 @@ if (!empty ($_POST['add_chapter']) && !empty ($_POST['title']))
 			"VALUES "."($learnpath_id,'dokeos_chapter','$title', $chapter_id, $previous, 0, $order )";
 	//error_log('New LP - Inserting new resource: '.$sql,0);
 	$res = Database::query($sql, __FILE__, __LINE__);
-	$my_id = Database::get_last_insert_id($res);
+	$my_id = Database::insert_id($res);
 	if($previous>0){
 		$sql = "UPDATE $tbl_lp_item SET next_item_id = $my_id WHERE id=$previous";
 		$res = Database::query($sql,__FILE__,__LINE__);
@@ -181,7 +181,7 @@ if (!empty ($_POST['external_link_submit']))
 		$sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
 		$result = Database::query($sql, __FILE__, __LINE__);
 		$addedresource[] = "Link";
-		$addedresourceid[] = mysql_insert_id();
+		$addedresourceid[] = Database::insert_id();
 		$_SESSION['addedresource'] = $addedresource;
 		$_SESSION['addedresourceid'] = $addedresourceid;
 	}
@@ -251,7 +251,7 @@ if ($add)
 						"VALUES (".$learnpath_id.",'dokeos_chapter','".$learnpath_chapter_name."',".$chapter_id.",$previous,0,".$lastorder.")";
 				//error_log('New LP - Inserting new resource: '.$sql,0);
 				$res = Database::query($sql, __FILE__, __LINE__);
-				$my_id = Database::get_last_insert_id($res);
+				$my_id = Database::insert_id($res);
 				if($previous>0){
 					$sql = "UPDATE $tbl_lp_item SET next_item_id = $my_id WHERE id=$previous";
 					$res = Database::query($sql,__FILE__,__LINE__);
@@ -310,7 +310,7 @@ if ($add)
 						//get title from tool-type table
 						$tooltable = Database::get_course_table(TABLE_DOCUMENT);
 						$result = Database::query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__);
-						$myrow=mysql_fetch_array($result);
+						$myrow=Database::fetch_array($result);
 						$title = $myrow['title'];
 						break;
 					case 'Exercise':
@@ -318,7 +318,7 @@ if ($add)
 						//get title from tool-type table
 						$tooltable = Database::get_course_table(TABLE_QUIZ_TEST);
 						$result = Database::query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__);
-						$myrow=mysql_fetch_array($result);
+						$myrow=Database::fetch_array($result);
 						$title = $myrow['title'];
 						break;
 					case 'Forum':
@@ -330,7 +330,7 @@ if ($add)
 						//get title from tool-type table
 						$tooltable = Database::get_course_table(TABLE_AGENDA);
 						$result = Database::query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__);
-						$myrow=mysql_fetch_array($result);
+						$myrow=Database::fetch_array($result);
 						$title = $myrow['title'];
 						break;
 					case 'Ad_Valvas':
@@ -338,7 +338,7 @@ if ($add)
 						//get title from tool-type table
 						$tooltable = Database::get_course_table(TABLE_ANNOUNCEMENT);
 						$result = Database::query("SELECT * FROM $tooltable WHERE id=".$addedresourceid[$i],__FILE__,__LINE__);
-						$myrow=mysql_fetch_array($result);
+						$myrow=Database::fetch_array($result);
 						$title = $myrow['title'];
 						break;
 
@@ -347,7 +347,7 @@ if ($add)
 						"VALUES ($learnpath_id, '$title','$chapter_id', '$addedresource_item','$addedresourceid[$i]',$previous,0,'".$lastorder."')";
 				//error_log('New LP - Inserting new resource: '.$sql,0);
 				$result = Database::query($sql, __FILE__, __LINE__);
-				$my_id = Database::get_last_insert_id($result);
+				$my_id = Database::insert_id($result);
 				if($previous>0){
 					$sql = "UPDATE $tbl_lp_item SET next_item_id = $my_id WHERE id = $previous";
 					//error_log($sql,0);
@@ -495,12 +495,12 @@ else
 	$learnpath_select_query = "	SELECT * FROM $tbl_lp
 		  								WHERE id=$learnpath_id";
 	$sql_result = Database::query($learnpath_select_query);
-	$therow = mysql_fetch_array($sql_result);
+	$therow = Database::fetch_array($sql_result);
 
 	$learnpath_chapter_query = "	SELECT * FROM $tbl_lp_item
 		  								WHERE (lp_id = '$learnpath_id' and id = '$chapter_id')";
 	$sql_result = Database::query($learnpath_chapter_query);
-	$therow2 = mysql_fetch_array($sql_result);
+	$therow2 = Database::fetch_array($sql_result);
 
 	$from_learnpath = 'yes';
 	session_register('from_learnpath');
@@ -535,7 +535,7 @@ $active_modules=array();
 $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
 $sql_select_active="SELECT * FROM $tool_table WHERE visibility='1'";
 $result_select_active=Database::query($sql_select_active);
-while ($row=mysql_fetch_array($result_select_active))
+while ($row=Database::fetch_array($result_select_active))
 {
 	$active_modules[]=$row['name'];
 }
@@ -750,7 +750,7 @@ if ($content == "Agenda")
 
 	$result = Database::query($sql);
 
-	while ($myrow = mysql_fetch_array($result))
+	while ($myrow = Database::fetch_array($result))
 	{
 		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
 		echo "<img src='../img/agenda.gif' alt='agenda'>";
@@ -821,7 +821,7 @@ if ($content == "Ad_Valvas")
 	$sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i  WHERE i.tool = '".TOOL_ANNOUNCEMENT."' AND a.id=i.ref AND i.visibility='1' AND i.to_group_id = 0 AND i.to_user_id IS NULL ORDER BY a.display_order ASC";
 	//error_log($sql,0);
 	$result = Database::query($sql,__FILE__,__LINE__);
-	while ($myrow = mysql_fetch_array($result))
+	while ($myrow = Database::fetch_array($result))
 	{
 		echo "<table width=\"100%\"><tr><td>";
 		echo "<img src='../img/valves.gif' alt='advalvas'>";
@@ -853,7 +853,7 @@ if ($content == "Forum")
 		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.forum_category=categories.cat_id ORDER BY forums.forum_category DESC";
 		//error_log($sql,0);
 		$result = Database::query($sql, __FILE__, __LINE__);
-		while ($myrow = mysql_fetch_array($result))
+		while ($myrow = Database::fetch_array($result))
 		{
 			if ($myrow["cat_title"] !== $old_cat_title)
 			{
@@ -871,13 +871,13 @@ if ($content == "Forum")
 		// displaying the category title
 		$sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$myrow = mysql_fetch_array($result);
+		$myrow = Database::fetch_array($result);
 		echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
 
 		// displaying the forum title
 		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$myrow = mysql_fetch_array($result);
+		$myrow = Database::fetch_array($result);
 		echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
 
 		if (!$thread)
@@ -885,7 +885,7 @@ if ($content == "Forum")
 			// displaying all the threads of this forum
 			$sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
 			$result = Database::query($sql, __FILE__, __LINE__);
-			while ($myrow = mysql_fetch_array($result))
+			while ($myrow = Database::fetch_array($result))
 			{
 				echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&lp_id=$learnpath_id&parent_item_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
 				showorhide_addresourcelink("Thread", $myrow["topic_id"]);
@@ -897,7 +897,7 @@ if ($content == "Forum")
 			// displaying all the replies
 			$sql = "SELECT * FROM ".$tbl_posts." post WHERE post.topic_id=$thread ORDER BY post.post_id ASC";
 			$result = Database::query($sql, __FILE__, __LINE__);
-			while ($myrow = mysql_fetch_array($result))
+			while ($myrow = Database::fetch_array($result))
 			{
 				echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
 				echo $myrow["post_text"]."</td>";
@@ -947,7 +947,7 @@ if ($content == "Link")
 	if (mysql_num_rows($result) > 0)
 	{
 		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
-		while ($myrow = mysql_fetch_array($result))
+		while ($myrow = Database::fetch_array($result))
 		{
 			echo "<img src='../img/links.gif'>".$myrow["title"];
 			echo "<br>";
@@ -959,12 +959,12 @@ if ($content == "Link")
 	// showing the categories and the links in it.
 	$sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
 	$resultcategories = Database::query($sqlcategories) or die;
-	while ($myrow = @ mysql_fetch_array($resultcategories))
+	while ($myrow = @ Database::fetch_array($resultcategories))
 	{
 		$sql_links = "SELECT * FROM ".$link_table.", ".$item_property_table." WHERE category_id='".$myrow["id"]."' AND tool = '".TOOL_LINK."' AND id=ref AND visibility='1' ORDER BY display_order DESC";
 		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
 		$result_links = Database::query($sql_links, __FILE__, __LINE__);
-		while ($myrow = mysql_fetch_array($result_links))
+		while ($myrow = Database::fetch_array($result_links))
 		{
 			echo "<img src='../img/links.gif' />".$myrow["title"];
 			echo "<br>";
@@ -983,7 +983,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes"))
 {
 	$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
 	$result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
-	while ($myrow = mysql_fetch_array($result))
+	while ($myrow = Database::fetch_array($result))
 	{
 		echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
 		showorhide_addresourcelink($content, $myrow["id"]);
@@ -997,7 +997,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes"))
 		$documentPath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
 		$sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY `id` ASC";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		while ($myrow = mysql_fetch_array($result))
+		while ($myrow = Database::fetch_array($result))
 		{
 			$path = $myrow["path"];
 			echo "<img src='../img/jqz.jpg'>".GetQuizName($path, $documentPath)."<br>";
@@ -1042,7 +1042,7 @@ if ($content == "Externallink")
 	$sql = "SELECT * FROM `$tbl_categories` ORDER BY display_order ASC";
 	echo $sql;
 	$result = Database::query($sql, __FILE__, __LINE__);
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
 	}

+ 3 - 3
main/newscorm/scorm.class.php

@@ -388,7 +388,7 @@ class scorm extends learnpath {
 					"VALUES (2,'".$myname."', '".$oOrganization->get_ref()."','','".$this->subdir."', 0, 'embedded', '".$this->manifest_encoding."','scorm_api.php',$dsp)";
 			if($this->debug>1){error_log('New LP - In import_manifest(), inserting path: '. $sql,0);}
 			$res = Database::query($sql,__FILE__,__LINE__);
-			$lp_id = Database::get_last_insert_id();
+			$lp_id = Database::insert_id();
 			$this->lp_id = $lp_id;
 			//insert into item_property
 			api_item_property_update(api_get_course_info($course_code),TOOL_LEARNPATH,$this->lp_id,'LearnpathAdded',api_get_user_id());
@@ -470,7 +470,7 @@ class scorm extends learnpath {
 						")";
 				$res_item = Database::query($sql_item);
 				if($this->debug>1){error_log('New LP - In import_manifest(), inserting item : '.$sql_item.' : '.mysql_error(),0);}
-				$item_id = Database::get_last_insert_id();
+				$item_id = Database::insert_id();
 				//now update previous item to change next_item_id
 				$upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE id = $previous";
 				$upd_res = Database::query($upd);
@@ -862,7 +862,7 @@ class scorm extends learnpath {
 
 		$sql = "SELECT * FROM $tbl_lp WHERE id=".$lp_id;
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$row = mysql_fetch_array($result);
+		$row = Database::fetch_array($result);
 		$LPname = $row['path'];
 		$list = split('/',$LPname);
 		$LPnamesafe = $list[0];

+ 1 - 1
main/newscorm/scorm.lib.php

@@ -61,7 +61,7 @@ function removescormDir($dir)
             $courseid=$_course['official_code'];
             $sql="SELECT * FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
             $result=Database::query($sql,__FILE__,__LINE__);
-            while ($row=mysql_fetch_array($result))
+            while ($row=Database::fetch_array($result))
             {
 	      $c=$row['contentId'];
 	      $sql2="DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_SCO_DATA)." where contentId=$c";

+ 3 - 3
main/newscorm/scormOrganization.class.php

@@ -164,7 +164,7 @@ class scormOrganization {
     function get_name()
     {
     	if(!empty($this->title)){
-    		return mysql_real_escape_string($this->title);
+    		return Database::escape_string($this->title);
     	}else{
     		return '';
     	}
@@ -176,7 +176,7 @@ class scormOrganization {
     function get_ref()
     {
     	if(!empty($this->identifier)){
-    		return mysql_real_escape_string($this->identifier);
+    		return Database::escape_string($this->identifier);
     	}else{
     		return '';
     	}
@@ -187,7 +187,7 @@ class scormOrganization {
      */
     function set_name($title){
     	if(!empty($title)){
-    		$this->title = mysql_real_escape_string($title);
+    		$this->title = Database::escape_string($title);
     	}
     }
 }

+ 5 - 5
main/newscorm/scorm_admin.php

@@ -100,7 +100,7 @@ switch($action){
 			$result=Database::query($sql,__FILE__,__LINE__);
 			$sql="SELECT * FROM $tbl_learnpath_chapter where learnpath_id=$id";
 			$result=Database::query($sql,__FILE__,__LINE__);
-			while ($row=mysql_fetch_array($result))
+			while ($row=Database::fetch_array($result))
 			{
 				$c=$row['id'];
 				$sql2="DELETE FROM $tbl_learnpath_item where chapter_id=$c";
@@ -119,7 +119,7 @@ switch($action){
 		if(!empty($id)){
 			$sql="SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
 			$result=Database::query($sql,__FILE__,__LINE__);
-			$row=mysql_fetch_array($result);
+			$row=Database::fetch_array($result);
 			$name=domesticate($row['learnpath_name']);
 			if ($set_visibility == 'i') {
 				$s=$name." ".get_lang('_no_published');
@@ -133,7 +133,7 @@ switch($action){
 			}
 			$sql="SELECT * FROM $tbl_tool where (name='$name' and image='scormbuilder.gif')";
 			$result=Database::query($sql,__FILE__,__LINE__);
-			$row2=mysql_fetch_array($result);
+			$row2=Database::fetch_array($result);
 			$num=mysql_num_rows($result);
 			if (($set_visibility == 'i') && ($num>0))
 			{
@@ -181,7 +181,7 @@ switch($action){
 		{
 		  $sql ="INSERT INTO $tbl_learnpath_main (learnpath_name, learnpath_description) VALUES ('".domesticate($learnpath_name)."','".domesticate($learnpath_description)."')";
 		  Database::query($sql,__FILE__,__LINE__);
-		  $my_lp_id = Database::get_last_insert_id();
+		  $my_lp_id = Database::insert_id();
 		  $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('".domesticate($learnpath_name)."','learnpath/learnpath_handler.php?learnpath_id=$my_lp_id','scormbuilder.gif','1','0','pastillegris.gif',0)";
 		  Database::query($sql,__FILE__,__LINE__);
 		  //instead of displaying this info text, get the user directly to the learnpath edit page
@@ -386,7 +386,7 @@ if($is_allowedToEdit) // TEACHER ONLY
     // At least one of these variables are empty. So it's okay to proceed this way
     /* Check if there is yet a record for this file in the DB */
     $result = mysql_query ("SELECT * FROM $tbl_document WHERE path LIKE '".$visibilityPath."'");
-    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
+    while($row = Database::fetch_array($result, 'ASSOC'))
     {
       $attribute['path'      ] = $row['path'      ];
       $attribute['visibility'] = $row['visibility'];

+ 9 - 9
main/notebook/index.php

@@ -55,7 +55,7 @@ Display::display_introduction_section(TOOL_NOTEBOOK);
 // Action handling: Adding a note
 if (isset($_GET['action']) && $_GET['action'] == 'addnote')
 {
-	if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {		 
+	if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
 		api_not_allowed();
 	}
 
@@ -257,12 +257,12 @@ function save_note($values) {
 				'".Database::escape_string(date('Y-m-d H:i:s'))."',
 				'0')";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	$id = Database::get_last_insert_id();
+	$id = Database::insert_id();
 	if ($id > 0) {
 		//insert into item_property
 		api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, $id, 'NotebookAdded', api_get_user_id());
 	}
-	
+
 	// display the feedback message
 	Display::display_confirmation_message(get_lang('NoteAdded'));
 }
@@ -274,7 +274,7 @@ function get_note_information($notebook_id) {
 	$sql = "SELECT 	notebook_id 		AS notebook_id,
 					title				AS note_title,
 					description 		AS note_comment,
-			   		session_id			AS session_id					
+			   		session_id			AS session_id
 			   FROM $t_notebook
 			   WHERE notebook_id = '".Database::escape_string($notebook_id)."' ";
 	$result = Database::query($sql, __FILE__, __LINE__);
@@ -306,7 +306,7 @@ function update_note($values) {
 
 	//update item_property (update)
 	api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($values['notebook_id']), 'NotebookUpdated', api_get_user_id());
-	
+
 	// display the feedback message
 	Display::display_confirmation_message(get_lang('NoteUpdated'));
 }
@@ -317,17 +317,17 @@ function delete_note($notebook_id) {
 
 	$sql = "DELETE FROM $t_notebook WHERE notebook_id='".Database::escape_string($notebook_id)."' AND user_id = '".Database::escape_string(api_get_user_id())."'";
 	$result = Database::query($sql, __FILE__, __LINE__);
-	
+
 	//update item_property (delete)
 	api_item_property_update(api_get_course_info(), TOOL_NOTEBOOK, Database::escape_string($notebook_id), 'delete', api_get_user_id());
-	
+
 	Display::display_confirmation_message(get_lang('NoteDeleted'));
 }
 
 function display_notes() {
 
 	global $_user;
-		
+
 	if (!$_GET['direction'])
 	{
 		$sort_direction = 'ASC';
@@ -355,7 +355,7 @@ function display_notes() {
 			elseif(api_is_allowed_to_session_edit(false,true)){
 				echo '<a href="index.php?'.api_get_cidreq().'&amp;action=addnote">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
 			}
-			
+
 		} else {
 			echo '<a href="javascript:void(0)">'.Display::return_icon('filenew.gif',get_lang('NoteAddNew')).get_lang('NoteAddNew').'</a>';
 		}

+ 1 - 1
main/online/online_links.php

@@ -149,7 +149,7 @@ $result=Database::query($query,__FILE__,__LINE__);
 
 $Links=array();
 
-while($row=mysql_fetch_array($result))
+while($row=Database::fetch_array($result))
 {
 	$Links[]=$row;
 

+ 1 - 1
main/online/online_master.php

@@ -47,7 +47,7 @@ $tbl_online_link=Database::get_course_table(TABLE_ONLINE_LINK);
 $query="SELECT t1.user_id,username,picture_uri,t2.status FROM $tbl_user t1,$tbl_course_user t2 WHERE t1.user_id=t2.user_id AND course_code='$_cid' AND (t1.user_id='".$_user['user_id']."' OR t2.status='1')";
 $result=Database::query($query,__FILE__,__LINE__);
 
-while($row=mysql_fetch_array($result))
+while($row=Database::fetch_array($result))
 {
 	if($row['user_id'] == $_user['user_id'])
 	{

+ 13 - 13
main/permissions/permissions_functions.inc.php

@@ -41,7 +41,7 @@ function store_permissions($content, $id)
 	}
 
 	// We first delete all the existing permissions for that user/group/role
-	$sql="DELETE FROM $table  WHERE $id_field = '".mysql_real_escape_string($id)."'";
+	$sql="DELETE FROM $table  WHERE $id_field = '".Database::escape_string($id)."'";
 	$result=Database::query($sql, __FILE__, __LINE__);
 
 	// looping through the post values to find the permission (containing the string permission* )
@@ -50,7 +50,7 @@ function store_permissions($content, $id)
 		if(strstr($key,"permission*"))
 		{
 			list($brol,$tool,$action)=explode("*",$key);
-			$sql="INSERT INTO $table ($id_field,tool,action) VALUES ('".mysql_real_escape_string($id)."','".mysql_real_escape_string($tool)."','".mysql_real_escape_string($action)."')";
+			$sql="INSERT INTO $table ($id_field,tool,action) VALUES ('".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($action)."')";
 			$result=Database::query($sql, __FILE__, __LINE__);
 
 
@@ -100,7 +100,7 @@ function store_one_permission($content, $action, $id, $tool,$permission)
 	// grating a right
 	if($action=='grant')
 	{
-		$sql="INSERT INTO $table ($id_field,tool,action) VALUES ('".mysql_real_escape_string($id)."','".mysql_real_escape_string($tool)."','".mysql_real_escape_string($permission)."')";
+		$sql="INSERT INTO $table ($id_field,tool,action) VALUES ('".Database::escape_string($id)."','".Database::escape_string($tool)."','".Database::escape_string($permission)."')";
 		$result=Database::query($sql, __FILE__, __LINE__);
 		if($result)
 		{
@@ -109,7 +109,7 @@ function store_one_permission($content, $action, $id, $tool,$permission)
 	}
 	if($action=='revoke')
 	{
-		$sql="DELETE FROM $table WHERE $id_field = '".mysql_real_escape_string($id)."' AND tool='".mysql_real_escape_string($tool)."' AND action='".mysql_real_escape_string($permission)."'";
+		$sql="DELETE FROM $table WHERE $id_field = '".Database::escape_string($id)."' AND tool='".Database::escape_string($tool)."' AND action='".Database::escape_string($permission)."'";
 		$result=Database::query($sql, __FILE__, __LINE__);
 		if($result)
 		{
@@ -161,10 +161,10 @@ function get_permissions($content, $id)
 	// where the first dimension is the tool.
 	$sql="
 		SELECT * FROM " . $table . "
-		WHERE " . $id_field . "='" . mysql_real_escape_string($id) . "'";
+		WHERE " . $id_field . "='" . Database::escape_string($id) . "'";
 	$result = Database::query($sql, __FILE__, __LINE__);
 
-	while($row = mysql_fetch_array($result))
+	while($row = Database::fetch_array($result))
 		$currentpermissions[$row['tool']][] = $row['action'];
 
 	return $currentpermissions;
@@ -420,7 +420,7 @@ function display_role_list($current_course_roles, $current_platform_roles)
 	// platform roles
 	$sql="SELECT * FROM $platform_roles_table";
 	$result=Database::query($sql, __FILE__, __LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		if(in_array($row['role_id'], $current_platform_roles))
 		{
@@ -449,7 +449,7 @@ function display_role_list($current_course_roles, $current_platform_roles)
 	// course roles
 	$sql="SELECT * FROM $coures_roles_table";
 	$result=Database::query($sql, __FILE__, __LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		if(in_array($row['role_id'], $current_course_roles))
 		{
@@ -505,7 +505,7 @@ function get_roles($content,$id, $scope='course')
 	//$sql="SELECT role.role_id FROM $table role_group_user, $table_role role WHERE role_group_user.$id_field = '$id' AND role_group_user.role_id=role.role_id AND role_group_user.scope='".$scope."'";$sql="SELECT role.role_id FROM $table role_group_user, $table_role role WHERE role_group_user.$id_field = '$id' AND role_group_user.role_id=role.role_id AND role_group_user.scope='".$scope."'";
 	$sql="SELECT role_id FROM $table WHERE $id_field = '$id' AND scope='".$scope."'";
 	$result=Database::query($sql, __FILE__, __LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		$current_roles[]=$row['role_id'];
 	}
@@ -533,7 +533,7 @@ function get_all_roles($content='course')
 	$current_roles=array();
 	$sql="SELECT * FROM $table_role";
 	$result=Database::query($sql, __FILE__, __LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		$roles[]=$row;
 	}
@@ -596,7 +596,7 @@ function get_roles_permissions($content,$id, $scope='course')
 
 	$result = Database::query($sql, __FILE__, __LINE__);
 
-	while($row=mysql_fetch_array($result))
+	while($row=Database::fetch_array($result))
 		$current_role_permissions[$row['tool']][]=$row['action'];
 
 	return $current_role_permissions;
@@ -632,7 +632,7 @@ function assign_role($content, $action, $id, $role_id, $scope='course')
 	// grating a right
 	if($action=='grant')
 	{
-		$sql="INSERT INTO $table (role_id, scope,  $id_field) VALUES ('".mysql_real_escape_string($role_id)."','".mysql_real_escape_string($scope)."','".mysql_real_escape_string($id)."')";
+		$sql="INSERT INTO $table (role_id, scope,  $id_field) VALUES ('".Database::escape_string($role_id)."','".Database::escape_string($scope)."','".Database::escape_string($id)."')";
 		$result=Database::query($sql, __FILE__, __LINE__);
 		if($result)
 		{
@@ -641,7 +641,7 @@ function assign_role($content, $action, $id, $role_id, $scope='course')
 	}
 	if($action=='revoke')
 	{
-		$sql="DELETE FROM $table WHERE $id_field = '".mysql_real_escape_string($id)."' AND role_id='".mysql_real_escape_string($role_id)."'";
+		$sql="DELETE FROM $table WHERE $id_field = '".Database::escape_string($id)."' AND role_id='".Database::escape_string($role_id)."'";
 		$result=Database::query($sql, __FILE__, __LINE__);
 		if($result)
 		{

+ 7 - 7
main/permissions/roles.php

@@ -17,9 +17,9 @@ if ($_POST['StoreRolePermissions'])
 	{
 		$table_role=Database::get_course_table(TABLE_ROLE);
 		$sql="INSERT INTO $table_role (role_name, role_comment, default_role)
-					VALUES ('".mysql_real_escape_string($_POST['role_name'])."','".mysql_real_escape_string($_POST['role_comment'])."','".mysql_real_escape_string($_POST['default_role'])."')";
-		$result=mysql_query($sql) or die(mysql_error());
-		$role_id=mysql_insert_id();
+					VALUES ('".Database::escape_string($_POST['role_name'])."','".Database::escape_string($_POST['role_comment'])."','".Database::escape_string($_POST['default_role'])."')";
+		$result=Database::query($sql);
+		$role_id=Database::insert_id();
 		$result_message=store_permissions('role', $role_id);
 	}
 	else
@@ -41,22 +41,22 @@ if (isset($_GET['action']) AND isset($_GET['role_id']) AND $_GET['action']=='del
 {
 	//deleting the assignments fo this role: users
 	$table=Database::get_course_table(TABLE_ROLE_USER);
-	$sql="DELETE FROM $table WHERE role_id='".mysql_real_escape_string($_GET['role_id'])."'";
+	$sql="DELETE FROM $table WHERE role_id='".Database::escape_string($_GET['role_id'])."'";
 	$result=Database::query($sql, __LINE__, __FILE__);
 
 	// deleting the assignments of this role: groups
 	$table=Database::get_course_table(TABLE_ROLE_GROUP);
-	$sql="DELETE FROM $table WHERE role_id='".mysql_real_escape_string($_GET['role_id'])."'";
+	$sql="DELETE FROM $table WHERE role_id='".Database::escape_string($_GET['role_id'])."'";
 	$result=Database::query($sql, __LINE__, __FILE__);
 
 	// deleting the permissions of this role
 	$table=Database::get_course_table(TABLE_ROLE_PERMISSION);
-	$sql="DELETE FROM $table WHERE role_id='".mysql_real_escape_string($_GET['role_id'])."'";
+	$sql="DELETE FROM $table WHERE role_id='".Database::escape_string($_GET['role_id'])."'";
 	$result=Database::query($sql, __LINE__, __FILE__);
 
 	// deleting the role
 	$table_role=Database::get_course_table(TABLE_ROLE);
-	$sql="DELETE FROM $table_role WHERE role_id='".mysql_real_escape_string($_GET['role_id'])."'";
+	$sql="DELETE FROM $table_role WHERE role_id='".Database::escape_string($_GET['role_id'])."'";
 	$result=Database::query($sql, __LINE__, __FILE__);
 
 	$result_message=get_lang('RoleDeleted');

+ 1 - 1
main/reservation/m_reservation.php

@@ -356,7 +356,7 @@ switch ($_GET['action']) {
 		}
 
 		if($_POST['recurrence_c'] && $msg_number == 0){
-				$Inserted_id = mysql_insert_id();
+				$Inserted_id = Database::insert_id();
 				$recurrence_date_start = Rsys :: mysql_datetime_to_timestamp($values['start']);
 				$recurrence_date_end = Rsys :: mysql_datetime_to_timestamp($values['end']);
 				$recurrence_period_end = Rsys :: mysql_datetime_to_timestamp($values['recurrence_until']);

+ 2 - 2
main/reservation/rsys.php

@@ -167,7 +167,7 @@ class Rsys {
 		if (Rsys :: check_category($naam)) {
 			$sql = "INSERT INTO ".Rsys :: getTable("category")." (name) VALUES ('".Database::escape_string($naam)."')";
 			Database::query($sql, __FILE__, __LINE__);
-			return Database::get_last_insert_id();
+			return Database::insert_id();
 		}
 		return false;
 	}
@@ -354,7 +354,7 @@ class Rsys {
 		if (Rsys :: check_item($name, $category)) {
 			$sql = "INSERT INTO ".Rsys :: getTable("item")." (category_id,course_code,name,description,creator) VALUES ('".Database::escape_string($category)."','".Database::escape_string($course)."','".Database::escape_string($name)."','".Database::escape_string($description)."','".api_get_user_id()."')";
 			Database::query($sql, __FILE__, __LINE__);
-			return Database::get_last_insert_id();
+			return Database::insert_id();
 		}
 		return false;
 	}

+ 55 - 55
main/resourcelinker/resourcelinker.inc.php

@@ -110,7 +110,7 @@ function show_documents($folder)
 	$document_table = Database::get_course_table(TABLE_DOCUMENT);
 	$sql="SELECT * from $document_table, $item_property_table WHERE id=ref AND tool = '".TOOL_DOCUMENT."' AND $visibility AND to_group_id = 0 AND to_user_id IS NULL  ORDER BY path ASC";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		if (!$folder)
 		{
@@ -165,7 +165,7 @@ function show_documents($folder)
 			//	echo '<br />';
 			//	}// if (str_replace($folder.'/','',$conform_folder)!==$folder)
 		} // else (if (!$folder))
-	} //while ($row=mysql_fetch_array($result))
+	} //while ($row=Database::fetch_array($result))
 
 	// this is code for the case that we are in a subfolder
 	if ($good_paths)
@@ -277,31 +277,31 @@ function display_addedresource_link($type, $id, $style='')
 		case 'Agenda':
 			$TABLEAGENDA = $_course['dbNameGlu'].'calendar_event';
 			$result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/agenda.gif" align="middle" /> <a href="../calendar/agenda.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Ad_Valvas':
 			$tbl_announcement = $_course['dbNameGlu'].'announcement';
 			$result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/valves.gif" align="middle" /> <a href="../announcements/announcements.php"'.$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Link':
 			$TABLETOOLLINK = $_course['dbNameGlu'].'link';
 			$result = Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/links.gif" align="middle" /> <a href="#" onclick="javascript:window.open(\'../link/link_goto.php?link_id='.$myrow['id'].'&amp;link_url='.urlencode($myrow['url'])."','MyWindow','width=500,height=400,top='+((screen.height-400)/2)+',left='+((screen.width-500)/2)+',scrollbars=1,resizable=1,menubar=1'); return false;\"".$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Exercise':
 			$TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
 			$result = Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/quiz.gif" align="middle" /> <a href="../exercice/exercice_submit.php?exerciseId='.$myrow['id'].'"'.$styling.'>'.$myrow['title']."</a><br />\n";
 			break;
 		case 'Forum':
 			$TBL_FORUMS = $_course['dbNameGlu'].'bb_forums';
 			$result = Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewforum.php?forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow['forum_name']."</a><br />\n";
 			break;
 		case 'Thread':  //=topics
@@ -309,11 +309,11 @@ function display_addedresource_link($type, $id, $style='')
 			$tbl_posts_text	= $_course['dbNameGlu'].'bb_posts_text';
 			$TBL_FORUMS		= $_course['dbNameGlu'].'bb_forums';
 			$result = Database::query("SELECT * FROM `$tbl_posts` posts, `$TBL_FORUMS` forum WHERE forum.forum_id=posts.forum_id and post_id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_title = "SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
 			$result_title = Database::query($sql_title,__FILE__,__LINE__);
-			$myrow_title = mysql_fetch_array($result_title);
+			$myrow_title = Database::fetch_array($result_title);
 			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$myrow['topic_id'].'&amp;forum='.$myrow['forum_id'].'&amp;md5='.$myrow['md5'].'"'.$styling.'>'.$myrow_title['post_title']."</a><br />\n";
 			break;
 		case 'Post':
@@ -321,13 +321,13 @@ function display_addedresource_link($type, $id, $style='')
 			$tbl_post_text = Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
 			$sql = "SELECT * FROM $tbl_post p, $tbl_post_text t WHERE p.post_id = t.post_id AND p.post_id = $id";
 			$result = Database::query($sql,__FILE__,__LINE__);
-			$post = mysql_fetch_object($result);
+			$post = Database::fetch_object($result);
 			echo '<img src="../img/forum.gif" align="middle" /> <a href="../phpbb/viewtopic.php?topic='.$post->topic_id.'&amp;forum='.$post->forum_id.'"'.$styling.'>'.$post->post_title."</a><br />\n";
 			break;
 		case 'Document':
 			$dbTable = $_course['dbNameGlu'].'document';
 			$result = Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__);
-			$myrow = mysql_fetch_array($result);
+			$myrow = Database::fetch_array($result);
 			$pathname = explode('/',$myrow['path']); // making a correct name for the link
 			$last = count($pathname) - 1;  // making a correct name for the link
 			$filename = $pathname[$last];  // making a correct name for the link
@@ -379,10 +379,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Agenda":
 			$TABLEAGENDA 		= $_course['dbNameGlu']."calendar_event";
 			$result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			$agenda_id=$row['item_id'];
@@ -428,10 +428,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Ad_Valvas":
 			$tbl_announcement = $_course['dbNameGlu']."announcement";
 			$result = Database::query("SELECT * FROM `$tbl_announcement` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["content"]=$row['title']; }
 			$desc=$row['description'];
 			$ann_id=$row['item_id'];
@@ -487,10 +487,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Link" :
 			$TABLETOOLLINK	= $_course['dbNameGlu']."link";
 			$result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -545,13 +545,13 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Exercise":
 			$TBL_EXERCICES  = $_course['dbNameGlu'].'quiz';
 			$result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder=='builder') { $origin='builder'; }
 			  //this is needed for the exercise_submit.php can delete the session info about tests
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -601,7 +601,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$TBL_DOCUMENT  = $_course['dbNameGlu'].'document';
 			$documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
 			$result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
-			$myrow= mysql_fetch_array($result);
+			$myrow= Database::fetch_array($result);
 			$path=$myrow["path"];
 			$name=GetQuizName($path,$documentPath);
 
@@ -609,7 +609,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			  //this is needed for the exercise_submit.php can delete the session info about tests
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -658,10 +658,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Forum":
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$result= Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -711,10 +711,10 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$sql="SELECT * FROM `$tbl_topics` where topic_id=$id";
 			$result= Database::query($sql,__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["topic_title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -762,14 +762,14 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$tbl_posts_text  = $_course['dbNameGlu'].'bb_posts_text';
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
 			$result_titel=Database::query($sql_titel,__FILE__,__LINE__);
-			$myrow_titel=mysql_fetch_array($result_titel);
+			$myrow_titel=Database::fetch_array($result_titel);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -823,7 +823,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Document":
 			$dbTable  = $_course['dbNameGlu']."document";
 			$result=Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$pathname=explode("/",$myrow["path"]); // making a correct name for the link
 			$last=count($pathname)-1;  // making a correct name for the link
@@ -844,7 +844,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 			$image=choose_image($filename);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $filename=$row['title']; }
 			$desc=$row['description'];
 
@@ -888,7 +888,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Assignments":
 			$name=get_lang('Assignments');
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -935,7 +935,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Dropbox":
 			$name=get_lang('Dropbox');
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -972,7 +972,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Introduction_text":
 			$name=get_lang('IntroductionText');
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1011,7 +1011,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Course_description":
 			$name=get_lang('CourseDescription');
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1049,7 +1049,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Groups":
 			$name=get_lang('Groups');
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1086,7 +1086,7 @@ function display_addedresource_link_in_learnpath($type, $id, $completed, $id_in_
 		case "Users":
 			$name=get_lang('Users');
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $name=$row['title']; }
 			$desc=$row['description'];
 			echo str_repeat("&nbsp;&gt;",$level);
@@ -1152,10 +1152,10 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Agenda":
 			$TABLEAGENDA 		= $_course['dbNameGlu']."calendar_event";
 			$result = Database::query("SELECT * FROM `$TABLEAGENDA` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 			$desc=$row['description'];
 			$agenda_id=$row['item_id'];
@@ -1173,7 +1173,7 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Ad_Valvas":
 			$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
 			$result = Database::query("SELECT * FROM $tbl_announcement WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder != 'builder')
 			{
@@ -1188,10 +1188,10 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Link" :
 			$TABLETOOLLINK	= $_course['dbNameGlu']."link";
 			$result= Database::query("SELECT * FROM `$TABLETOOLLINK` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 
 			$thelink=$myrow["url"];
 			if ($builder != 'builder')
@@ -1207,13 +1207,13 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Exercise":
 			$TBL_EXERCICES  = $_course['dbNameGlu'].'quiz';
 			$result= Database::query("SELECT * FROM `$TBL_EXERCICES` WHERE id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder=='builder') { $origin='builder'; }
 			  //this is needed for the exercise_submit.php can delete the session info about tests
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["title"]=$row['title']; }
 
 			if ($builder != 'builder')
@@ -1230,7 +1230,7 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 	  	    $TBL_DOCUMENT  = $_course['dbNameGlu'].'document';
 		    $documentPath=api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
 			$result = Database::query("SELECT * FROM `".$TBL_DOCUMENT."` WHERE id=$id");
-		    $myrow= mysql_fetch_array($result);
+		    $myrow= Database::fetch_array($result);
 		    $path=$myrow["path"];
 		  	$name=GetQuizName($path,$documentPath);
 
@@ -1251,12 +1251,12 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Forum":
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$result= Database::query("SELECT * FROM `$TBL_FORUMS` WHERE forum_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			if ($builder=='builder') { $origin='builder'; }
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow["forum_name"]=$row['title']; }
 
 			if ($myrow["forum_name"]=='') { $type="Forum"; }
@@ -1278,10 +1278,10 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$sql="SELECT * FROM `$tbl_topics` where topic_id=$id";
 			$result= Database::query($sql,__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 
 			if ($builder != 'builder')
 			{
@@ -1299,14 +1299,14 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 			$tbl_posts_text  = $_course['dbNameGlu'].'bb_posts_text';
 			$TBL_FORUMS = $_course['dbNameGlu']."bb_forums";
 			$result= Database::query("SELECT * FROM `$tbl_posts` where post_id=$id",__FILE__,__LINE__);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 			// grabbing the title of the post
 			$sql_titel="SELECT * FROM `$tbl_posts_text` WHERE post_id=".$myrow["post_id"];
 			$result_titel=Database::query($sql_titel,__FILE__,__LINE__);
-			$myrow_titel=mysql_fetch_array($result_titel);
+			$myrow_titel=Database::fetch_array($result_titel);
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 			if ($row['title'] != '') { $myrow_titel["post_title"]=$row['title']; }
 			$desc=$row['description'];
     		$link .= str_repeat("&nbsp;&gt;",$level);
@@ -1330,14 +1330,14 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path)
 		case "Document":
 			$dbTable  = $_course['dbNameGlu']."document";
 			$result=Database::query("SELECT * FROM `$dbTable` WHERE id=$id",__FILE__,__LINE);
-			$myrow=mysql_fetch_array($result);
+			$myrow=Database::fetch_array($result);
 
 			$pathname=explode("/",$myrow["path"]); // making a correct name for the link
 			$last=count($pathname)-1;  // making a correct name for the link
 			$filename=$pathname[$last];  // making a correct name for the link
 
 			$sql="select * from $tbl_learnpath_item where id=$id_in_path";
-			$result=Database::query($sql,__FILE__,__LINE__);	$row=mysql_fetch_array($result);
+			$result=Database::query($sql,__FILE__,__LINE__);	$row=Database::fetch_array($result);
 
 			if ($builder != 'builder')
 			{
@@ -1506,7 +1506,7 @@ function edit_added_resources($type, $id)
 
 	$sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id=$id";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		$addedresource[]=$row["resource_type"];
 		$addedresourceid[]=$row["resource_id"];
@@ -1549,7 +1549,7 @@ function display_added_resources($type, $id, $style='')
 
 	$sql="SELECT * FROM `$TABLERESOURCE` WHERE source_type='$type' and source_id='$id'";
 	$result=Database::query($sql,__FILE__,__LINE__);
-	while ($row=mysql_fetch_array($result))
+	while ($row=Database::fetch_array($result))
 	{
 		if ($origin != 'learnpath')
 		{

+ 21 - 21
main/resourcelinker/resourcelinker.php

@@ -125,12 +125,12 @@ if (!empty ($_POST['add_chapter']) && !empty ($_POST['title']))
 	// get max display_order so far in this parent chapter
 	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
 	$res = Database::query($sql, __FILE__, __LINE__);
-	$row = mysql_fetch_array($res);
+	$row = Database::fetch_array($res);
 	$max_temp = $row[0];
 
 	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
 	$res = Database::query($sql, __FILE__, __LINE__);
-	$row = mysql_fetch_array($res);
+	$row = Database::fetch_array($res);
 	$max_temp2 = $row[0];
 	if ($max_temp2 > $max_temp)
 	{
@@ -166,7 +166,7 @@ if (!empty ($_POST['external_link_submit']))
 		$sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
 		$result = Database::query($sql, __FILE__, __LINE__);
 		$addedresource[] = "Link";
-		$addedresourceid[] = mysql_insert_id();
+		$addedresourceid[] = Database::insert_id();
 		$_SESSION['addedresource'] = $addedresource;
 		$_SESSION['addedresourceid'] = $addedresourceid;
 	}
@@ -213,7 +213,7 @@ if ($add)
 		if(mysql_num_rows($result)==0){
 			$lastorder_item = 0;
 		}else{
-			$row = mysql_fetch_array($result);
+			$row = Database::fetch_array($result);
 			$lastorder_item = ($row[0]);
 		}
 		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
@@ -221,7 +221,7 @@ if ($add)
 		if(mysql_num_rows($result)==0){
 			$lastorder_chapter = 0;
 		}else{
-			$row = mysql_fetch_array($result);
+			$row = Database::fetch_array($result);
 			$lastorder_chapter = ($row[0]);
 		}
 		$lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);
@@ -403,12 +403,12 @@ else
 	$learnpath_select_query = "	SELECT * FROM $tbl_learnpath_main
 		  								WHERE learnpath_id=$learnpath_id";
 	$sql_result = Database::query($learnpath_select_query);
-	$therow = mysql_fetch_array($sql_result);
+	$therow = Database::fetch_array($sql_result);
 
 	$learnpath_chapter_query = "	SELECT * FROM $tbl_learnpath_chapter
 		  								WHERE (learnpath_id = '$learnpath_id' and id = '$chapter_id')";
 	$sql_result = Database::query($learnpath_chapter_query);
-	$therow2 = mysql_fetch_array($sql_result);
+	$therow2 = Database::fetch_array($sql_result);
 
 	$from_learnpath = 'yes';
 	session_register('from_learnpath');
@@ -443,7 +443,7 @@ $active_modules=array();
 $tool_table = Database::get_course_table(TABLE_TOOL_LIST);
 $sql_select_active="SELECT * FROM $tool_table WHERE visibility='1'";
 $result_select_active=Database::query($sql_select_active);
-while ($row=mysql_fetch_array($result_select_active))
+while ($row=Database::fetch_array($result_select_active))
 {
 	$active_modules[]=$row['name'];
 }
@@ -653,7 +653,7 @@ if ($content == "Agenda")
 
 	$result = Database::query($sql);
 
-	while ($myrow = mysql_fetch_array($result))
+	while ($myrow = Database::fetch_array($result))
 	{
 		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
 		echo "<img src='../img/agenda.gif' alt='agenda'>";
@@ -723,7 +723,7 @@ if ($content == "Ad_Valvas")
 	$sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i  WHERE i.tool = '".TOOL_ANNOUNCEMENT."' AND a.id=i.ref AND i.visibility='1' AND i.to_group_id = 0 AND i.to_user_id IS NULL ORDER BY a.display_order ASC";
 
 	$result = Database::query($sql,__FILE__,__LINE__);
-	while ($myrow = mysql_fetch_array($result))
+	while ($myrow = Database::fetch_array($result))
 	{
 		echo "<table width=\"100%\"><tr><td>";
 		echo "<img src='../img/valves.gif' alt='advalvas'>";
@@ -755,7 +755,7 @@ if ($content == "Forum")
 	{
 		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		while ($myrow = mysql_fetch_array($result))
+		while ($myrow = Database::fetch_array($result))
 		{
 			if ($myrow["cat_title"] !== $old_cat_title)
 			{
@@ -773,13 +773,13 @@ if ($content == "Forum")
 		// displaying the category title
 		$sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$myrow = mysql_fetch_array($result);
+		$myrow = Database::fetch_array($result);
 		echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
 
 		// displaying the forum title
 		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		$myrow = mysql_fetch_array($result);
+		$myrow = Database::fetch_array($result);
 		echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
 
 		if (!$thread)
@@ -787,7 +787,7 @@ if ($content == "Forum")
 			// displaying all the threads of this forum
 			$sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
 			$result = Database::query($sql, __FILE__, __LINE__);
-			while ($myrow = mysql_fetch_array($result))
+			while ($myrow = Database::fetch_array($result))
 			{
 				echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
 				showorhide_addresourcelink("Thread", $myrow["topic_id"]);
@@ -799,7 +799,7 @@ if ($content == "Forum")
 			// displaying all the replies
 			$sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
 			$result = Database::query($sql, __FILE__, __LINE__);
-			while ($myrow = mysql_fetch_array($result))
+			while ($myrow = Database::fetch_array($result))
 			{
 				echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
 				echo $myrow["post_text"]."</td>";
@@ -849,7 +849,7 @@ if ($content == "Link")
 	if (mysql_num_rows($result) > 0)
 	{
 		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
-		while ($myrow = mysql_fetch_array($result))
+		while ($myrow = Database::fetch_array($result))
 		{
 			echo "<img src='../img/links.gif'>".$myrow["title"];
 			echo "<br>";
@@ -861,12 +861,12 @@ if ($content == "Link")
 	// showing the categories and the links in it.
 	$sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
 	$resultcategories = Database::query($sqlcategories) or die;
-	while ($myrow = @ mysql_fetch_array($resultcategories))
+	while ($myrow = @ Database::fetch_array($resultcategories))
 	{
 		$sql_links = "SELECT * FROM ".$link_table.", ".$item_property_table." WHERE category_id='".$myrow["id"]."' AND tool = '".TOOL_LINK."' AND id=ref AND visibility='1' ORDER BY display_order DESC";
 		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
 		$result_links = Database::query($sql_links, __FILE__, __LINE__);
-		while ($myrow = mysql_fetch_array($result_links))
+		while ($myrow = Database::fetch_array($result_links))
 		{
 			echo "<img src='../img/links.gif' />".$myrow["title"];
 			echo "<br>";
@@ -885,7 +885,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes"))
 {
 	$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
 	$result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
-	while ($myrow = mysql_fetch_array($result))
+	while ($myrow = Database::fetch_array($result))
 	{
 		echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
 		showorhide_addresourcelink($content, $myrow["id"]);
@@ -899,7 +899,7 @@ if (($content == "Exercise") or ($content == "HotPotatoes"))
 		$documentPath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document';
 		$sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY `id` ASC";
 		$result = Database::query($sql, __FILE__, __LINE__);
-		while ($myrow = mysql_fetch_array($result))
+		while ($myrow = Database::fetch_array($result))
 		{
 			$path = $myrow["path"];
 			echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
@@ -944,7 +944,7 @@ if ($content == "Externallink")
 	$sql = "SELECT * FROM `$tbl_categories` ORDER BY display_order ASC";
 	echo $sql;
 	$result = Database::query($sql, __FILE__, __LINE__);
-	while ($row = mysql_fetch_array($result))
+	while ($row = Database::fetch_array($result))
 	{
 		echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
 	}

+ 13 - 13
main/survey/survey.lib.php

@@ -261,7 +261,7 @@ class survey_manager
 				//insert into item_property
 				api_item_property_update(api_get_course_info(), TOOL_SURVEY, $survey_id, 'SurveyAdded', api_get_user_id());
 			}
-			
+
 			if($values['survey_type']==1 && !empty($values['parent_id'])){
 				survey_manager::copy_survey($values['parent_id'],$survey_id);
 			}
@@ -339,10 +339,10 @@ class survey_manager
 							anonymous	= '".Database::escape_string($values['anonymous'])."'".$additionalsets."
 					WHERE survey_id = '".Database::escape_string($values['survey_id'])."'";
 			$result = Database::query($sql, __FILE__, __LINE__);
-			
+
 			//update into item_property (update)
 			api_item_property_update(api_get_course_info(), TOOL_SURVEY, Database::escape_string($values['survey_id']), 'SurveyUpdated', api_get_user_id());
-			
+
 			//$return['message'] = get_lang('SurveyUpdatedSuccesfully').'<br />'.get_lang('YouCanNowAddQuestionToYourSurvey').': ';
 			//$return['message'] .= '<a href="survey.php?survey_id='.$values['survey_id'].'">'.get_lang('Here').'</a>';
 			//$return['message'] .= get_lang('OrReturnToSurveyOverview').'<a href="survey_list.php">'.get_lang('Here').'</a>';
@@ -434,10 +434,10 @@ class survey_manager
 
 		// deleting the questions of the survey
 		survey_manager::delete_all_survey_questions($survey_id, $shared);
-		
+
 		//update into item_property (delete)
 		api_item_property_update(api_get_course_info(), TOOL_SURVEY, Database::escape_string($survey_id), 'delete', api_get_user_id());
-		
+
 		return void;
 	}
 
@@ -4642,12 +4642,12 @@ class SurveyUtil {
 		if ($search_restriction)
 		{
 			$search_restriction = ' AND '.$search_restriction;
-		}		
-		
+		}
+
 		//condition for the session
 		$session_id = api_get_session_id();
 		$condition_session = api_get_session_condition($session_id);
-		
+
 		//IF(is_shared<>0,'V','-')	 					AS col6,
 		$sql = "SELECT
 					survey.survey_id							AS col0,
@@ -4672,17 +4672,17 @@ class SurveyUtil {
 		$sql .= " GROUP BY survey.survey_id";
 		$sql .= " ORDER BY col$column $direction ";
 		$sql .= " LIMIT $from,$number_of_items";
-		$res = api_sql_query($sql, __FILE__, __LINE__);
+		$res = Database::query($sql, __FILE__, __LINE__);
 		$surveys = array();
 		$array = array();
 		while ($survey = Database::fetch_array($res)) {
 			$array[0] = $survey[0];
 			$array[1] = $survey[1];
-			
+
 			//validacion when belongs to a session
 			$session_img = api_get_session_image($survey['session_id'], $_user['status']);
 			$array[2] = $survey[2] . $session_img;
-			
+
 			$array[3] = $survey[3];
 			$array[4] = $survey[4];
 			$array[5] = $survey[5];
@@ -4691,12 +4691,12 @@ class SurveyUtil {
 			$array[8] = $survey[8];
 			$array[9] = $survey[9];
 			$array[10] = $survey[10];
-			
+
 			$surveys[] = $array;
 		}
 		return $surveys;
 	}
-	
+
 	function get_survey_data_for_coach($from, $number_of_items, $column, $direction)
 	{
 		//echo '<pre>';

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä