Feature #347 - Course settings and Course creation, Documents, Dropbox tool: Removing the parameters __FILE__ and __LINE__ in the Database::query() calls.

skala
Ivan Tcholakov 16 years ago
parent d7374d430e
commit bc60747b1b
  1. 6
      main/calendar/agenda.inc.php
  2. 30
      main/course_info/infocours.php
  3. 2
      main/course_info/postpone.php
  4. 60
      main/coursecopy/classes/CourseBuilder.class.php
  5. 88
      main/coursecopy/classes/CourseRecycler.class.php
  6. 132
      main/coursecopy/classes/CourseRestorer.class.php
  7. 4
      main/coursecopy/classes/CourseSelectForm.class.php
  8. 2
      main/coursecopy/copy_course.php
  9. 8
      main/coursecopy/copy_course_session.php
  10. 2
      main/create_course/add_course.php
  11. 2
      main/document/create_document.php
  12. 4
      main/document/document.inc.php
  13. 2
      main/document/document.php
  14. 8
      main/document/downloadfolder.inc.php
  15. 10
      main/document/edit_document.php
  16. 2
      main/document/slideshow.php
  17. 10
      main/document/upload.php
  18. 28
      main/dropbox/dropbox_class.inc.php
  19. 2
      main/dropbox/dropbox_download.php
  20. 48
      main/dropbox/dropbox_functions.inc.php
  21. 9
      main/dropbox/dropbox_submit.php

@ -4449,7 +4449,7 @@ function delete_attachment_file($id_attach) {
$id_attach=Database::escape_string($id_attach); $id_attach=Database::escape_string($id_attach);
$sql="DELETE FROM $agenda_table_attachment WHERE id = ".(int)$id_attach; $sql="DELETE FROM $agenda_table_attachment WHERE id = ".(int)$id_attach;
$result=Database::query($sql, __LINE__, __FILE__); $result=Database::query($sql);
$last_id_file=Database::insert_id(); $last_id_file=Database::insert_id();
// update item_property // update item_property
api_item_property_update($_course, 'calendar_event_attachment', $id_attach ,'AgendaAttachmentDeleted', api_get_user_id()); api_item_property_update($_course, 'calendar_event_attachment', $id_attach ,'AgendaAttachmentDeleted', api_get_user_id());
@ -4497,7 +4497,7 @@ function add_agenda_attachment_file($file_comment,$last_id) {
if ($result) { if ($result) {
$sql='INSERT INTO '.$agenda_table_attachment.'(filename,comment, path,agenda_id,size) '. $sql='INSERT INTO '.$agenda_table_attachment.'(filename,comment, path,agenda_id,size) '.
"VALUES ( '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".$_FILES['user_upload']['size']."' )"; "VALUES ( '".$safe_file_name."', '".$safe_file_comment."', '".$safe_new_file_name."' , '".$last_id."', '".$_FILES['user_upload']['size']."' )";
$result=Database::query($sql, __LINE__, __FILE__); $result=Database::query($sql);
$message.=' / '.get_lang('FileUploadSucces').'<br />'; $message.=' / '.get_lang('FileUploadSucces').'<br />';
$last_id_file=Database::insert_id(); $last_id_file=Database::insert_id();
@ -4548,7 +4548,7 @@ function edit_agenda_attachment_file($file_comment,$agenda_id,$id_attach) {
if ($result) { if ($result) {
$sql="UPDATE $agenda_table_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', agenda_id = '$safe_agenda_id', size ='".$_FILES['user_upload']['size']."' $sql="UPDATE $agenda_table_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', agenda_id = '$safe_agenda_id', size ='".$_FILES['user_upload']['size']."'
WHERE id = '$safe_id_attach'"; WHERE id = '$safe_id_attach'";
$result=Database::query($sql, __LINE__, __FILE__); $result=Database::query($sql);
api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach ,'AgendaAttachmentUpdated', api_get_user_id()); api_item_property_update($_course, 'calendar_event_attachment', $safe_id_attach ,'AgendaAttachmentUpdated', api_get_user_id());

@ -107,19 +107,19 @@ $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
// Get all course categories // Get all course categories
$sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' OR code = '".Database::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__); $res = Database::query($sql);
$s_select_course_tutor_name="SELECT tutor_name FROM $tbl_course WHERE code='$course_code'"; $s_select_course_tutor_name="SELECT tutor_name FROM $tbl_course WHERE code='$course_code'";
$q_tutor=Database::query($s_select_course_tutor_name, __FILE__, __LINE__); $q_tutor=Database::query($s_select_course_tutor_name);
$s_tutor=Database::result($q_tutor,0,"tutor_name"); $s_tutor=Database::result($q_tutor,0,"tutor_name");
$s_sql_course_titular="SELECT DISTINCT username, lastname, firstname FROM $tbl_user as user, $tbl_course_user as course_rel_user WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."'"; $s_sql_course_titular="SELECT DISTINCT username, lastname, firstname FROM $tbl_user as user, $tbl_course_user as course_rel_user WHERE (course_rel_user.status='1') AND user.user_id=course_rel_user.user_id AND course_code='".$course_code."'";
$q_result_titulars=Database::query($s_sql_course_titular, __FILE__, __LINE__); $q_result_titulars=Database::query($s_sql_course_titular);
$target_name = api_sort_by_first_name() ? 'firstname' : 'lastname'; $target_name = api_sort_by_first_name() ? 'firstname' : 'lastname';
if(Database::num_rows($q_result_titulars)==0){ if(Database::num_rows($q_result_titulars)==0){
$sql="SELECT username, lastname, firstname FROM $tbl_user as user, $tbl_admin as admin WHERE admin.user_id=user.user_id ORDER BY ".$target_name." ASC"; $sql="SELECT username, lastname, firstname FROM $tbl_user as user, $tbl_admin as admin WHERE admin.user_id=user.user_id ORDER BY ".$target_name." ASC";
$q_result_titulars=Database::query($sql, __FILE__, __LINE__); $q_result_titulars=Database::query($sql);
} }
$a_profs[0] = '-- '.get_lang('NoManager').' --'; $a_profs[0] = '-- '.get_lang('NoManager').' --';
@ -336,49 +336,49 @@ if ($form->validate() && is_settings_editable()) {
tutor_name = '".$update_values['tutor_name']."', tutor_name = '".$update_values['tutor_name']."',
registration_code = '".$update_values['course_registration_password']."' registration_code = '".$update_values['course_registration_password']."'
WHERE code = '".$course_code."'"; WHERE code = '".$course_code."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
//update course_settings table - this assumes those records exist, otherwise triggers an error //update course_settings table - this assumes those records exist, otherwise triggers an error
$table_course_setting = Database::get_course_table(TABLE_COURSE_SETTING); $table_course_setting = Database::get_course_table(TABLE_COURSE_SETTING);
if($update_values['email_alert_to_teacher_on_new_user_in_course'] != $values['email_alert_to_teacher_on_new_user_in_course']){ if($update_values['email_alert_to_teacher_on_new_user_in_course'] != $values['email_alert_to_teacher_on_new_user_in_course']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_to_teacher_on_new_user_in_course']." WHERE variable = 'email_alert_to_teacher_on_new_user_in_course' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_to_teacher_on_new_user_in_course']." WHERE variable = 'email_alert_to_teacher_on_new_user_in_course' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['email_alert_manager_on_new_doc'] != $values['email_alert_manager_on_new_doc']){ if($update_values['email_alert_manager_on_new_doc'] != $values['email_alert_manager_on_new_doc']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_doc']." WHERE variable = 'email_alert_manager_on_new_doc' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_doc']." WHERE variable = 'email_alert_manager_on_new_doc' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['email_alert_on_new_doc_dropbox'] != $values['email_alert_on_new_doc_dropbox']){ if($update_values['email_alert_on_new_doc_dropbox'] != $values['email_alert_on_new_doc_dropbox']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_on_new_doc_dropbox']." WHERE variable = 'email_alert_on_new_doc_dropbox' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_on_new_doc_dropbox']." WHERE variable = 'email_alert_on_new_doc_dropbox' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['email_alert_manager_on_new_quiz'] != $values['email_alert_manager_on_new_quiz']){ if($update_values['email_alert_manager_on_new_quiz'] != $values['email_alert_manager_on_new_quiz']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_quiz']." WHERE variable = 'email_alert_manager_on_new_quiz' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['email_alert_manager_on_new_quiz']." WHERE variable = 'email_alert_manager_on_new_quiz' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['allow_user_edit_agenda'] != $values['allow_user_edit_agenda']){ if($update_values['allow_user_edit_agenda'] != $values['allow_user_edit_agenda']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_agenda']." WHERE variable = 'allow_user_edit_agenda' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_agenda']." WHERE variable = 'allow_user_edit_agenda' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['allow_user_edit_announcement'] != $values['allow_user_edit_announcement']){ if($update_values['allow_user_edit_announcement'] != $values['allow_user_edit_announcement']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_announcement']." WHERE variable = 'allow_user_edit_announcement' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_edit_announcement']." WHERE variable = 'allow_user_edit_announcement' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['allow_user_image_forum'] != $values['allow_user_image_forum']){ if($update_values['allow_user_image_forum'] != $values['allow_user_image_forum']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_image_forum']." WHERE variable = 'allow_user_image_forum' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_user_image_forum']." WHERE variable = 'allow_user_image_forum' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['allow_open_chat_window'] != $values['allow_open_chat_window']){ if($update_values['allow_open_chat_window'] != $values['allow_open_chat_window']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_open_chat_window']." WHERE variable = 'allow_open_chat_window' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_open_chat_window']." WHERE variable = 'allow_open_chat_window' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['course_theme'] != $values['course_theme']){ if($update_values['course_theme'] != $values['course_theme']){
$sql = "UPDATE $table_course_setting SET value = '".$update_values['course_theme']."' WHERE variable = 'course_theme' "; $sql = "UPDATE $table_course_setting SET value = '".$update_values['course_theme']."' WHERE variable = 'course_theme' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
if($update_values['allow_learningpath_theme'] != $values['allow_learning_path_theme']){ if($update_values['allow_learningpath_theme'] != $values['allow_learning_path_theme']){
$sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_learning_path_theme']." WHERE variable = 'allow_learning_path_theme' "; $sql = "UPDATE $table_course_setting SET value = ".(int)$update_values['allow_learning_path_theme']." WHERE variable = 'allow_learning_path_theme' ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }

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

@ -97,7 +97,7 @@ class CourseBuilder
foreach ($this->course->resources as $type => $resources) { foreach ($this->course->resources as $type => $resources) {
foreach ($resources as $id => $resource) { foreach ($resources as $id => $resource) {
$sql = "SELECT * FROM ".$table_link." WHERE source_type = '".$resource->get_type()."' AND source_id = '".$resource->get_id()."'"; $sql = "SELECT * FROM ".$table_link." WHERE source_type = '".$resource->get_type()."' AND source_id = '".$resource->get_id()."'";
$res = Database::query($sql, __FILE__, __LINE__); $res = Database::query($sql);
while ($link = Database::fetch_object($res)) { while ($link = Database::fetch_object($res)) {
$this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id); $this->course->resources[$type][$id]->add_linked_resource($link->resource_type, $link->resource_id);
} }
@ -112,7 +112,7 @@ class CourseBuilder
if ($tool != null) if ($tool != null)
{ {
$sql = "SELECT * FROM $table_properties WHERE TOOL = '".$tool."' AND ref='".$resource->get_id()."'"; $sql = "SELECT * FROM $table_properties WHERE TOOL = '".$tool."' AND ref='".$resource->get_id()."'";
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql);
$all_properties = array (); $all_properties = array ();
while ($item_property = Database::fetch_array($res)) while ($item_property = Database::fetch_array($res))
{ {
@ -143,7 +143,7 @@ class CourseBuilder
$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'; $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__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size); $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
@ -159,7 +159,7 @@ class CourseBuilder
else else
$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND d.session_id = 0 ORDER BY path'; $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND d.session_id = 0 ORDER BY path';
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size); $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
@ -176,7 +176,7 @@ class CourseBuilder
{ {
$table = Database :: get_course_table(TABLE_FORUM); $table = Database :: get_course_table(TABLE_FORUM);
$sql = 'SELECT * FROM '.$table; $sql = 'SELECT * FROM '.$table;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image); $forum = new Forum($obj->forum_id, $obj->forum_title, $obj->forum_comment, $obj->forum_category, $obj->forum_last_post, $obj->forum_threads, $obj->forum_posts, $obj->allow_anonymous, $obj->allow_edit, $obj->approval_direct_post, $obj->allow_attachements, $obj->allow_new_threads, $obj->default_view, $obj->forum_of_group, $obj->forum_group_public_private, $obj->forum_order, $obj->locked, $obj->session_id, $obj->forum_image);
@ -193,7 +193,7 @@ class CourseBuilder
{ {
$table = Database :: get_course_table(TABLE_FORUM_CATEGORY); $table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
$sql = 'SELECT * FROM '.$table.' WHERE cat_id = '.$id; $sql = 'SELECT * FROM '.$table.' WHERE cat_id = '.$id;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id); $forum_category = new ForumCategory($obj->cat_id, $obj->cat_title, $obj->cat_comment, $obj->cat_order, $obj->locked, $obj->session_id);
@ -207,7 +207,7 @@ class CourseBuilder
{ {
$table = Database :: get_course_table(TABLE_FORUM_THREAD); $table = Database :: get_course_table(TABLE_FORUM_THREAD);
$sql = 'SELECT * FROM '.$table; $sql = 'SELECT * FROM '.$table;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max); $forum_topic = new ForumTopic($obj->thread_id, $obj->thread_title, $obj->thread_date, $obj->thread_poster_id, $obj->thread_poster_name, $obj->forum_id, $obj->thread_last_post, $obj->thread_replies, $obj->thread_views, $obj->thread_sticky, $obj->locked, $obj->thread_close_date, $obj->thread_weight, $obj->thread_title_qualify, $obj->thread_qualify_max);
@ -222,7 +222,7 @@ class CourseBuilder
{ {
$table_post = Database :: get_course_table(TABLE_FORUM_POST); $table_post = Database :: get_course_table(TABLE_FORUM_POST);
$sql = 'SELECT * FROM '.$table_post; $sql = 'SELECT * FROM '.$table_post;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$forum_post = new ForumPost($obj->post_id, $obj->post_title, $obj->post_text, $obj->post_date, $obj->poster_id, $obj->poster_name, $obj->post_notification, $obj->post_parent_id, $obj->thread_id, $obj->forum_id, $obj->visible); $forum_post = new ForumPost($obj->post_id, $obj->post_title, $obj->post_text, $obj->post_date, $obj->poster_id, $obj->poster_name, $obj->post_notification, $obj->post_parent_id, $obj->thread_id, $obj->forum_id, $obj->visible);
@ -247,7 +247,7 @@ class CourseBuilder
$sql = "SELECT * FROM $table l, $table_prop p WHERE p.ref=l.id AND p.tool = '".TOOL_LINK."' AND p.visibility != 2 AND l.session_id = 0 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 l.session_id = 0 ORDER BY l.display_order";
} }
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage); $link = new Link($obj->id, $obj->title, $obj->url, $obj->description, $obj->category_id, $obj->on_homepage);
@ -272,7 +272,7 @@ class CourseBuilder
{ {
$table = Database :: get_course_table(TABLE_TOOL_INTRO); $table = Database :: get_course_table(TABLE_TOOL_INTRO);
$sql = 'SELECT * FROM '.$table; $sql = 'SELECT * FROM '.$table;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$tool_intro = new ToolIntro($obj->id, $obj->intro_text); $tool_intro = new ToolIntro($obj->id, $obj->intro_text);
@ -292,7 +292,7 @@ class CourseBuilder
} }
$sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id; $sql = 'SELECT * FROM '.$link_cat_table.' WHERE id = '.$id;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order); $link_category = new LinkCategory($obj->id, $obj->category_title, $obj->description, $obj->display_order);
@ -320,7 +320,7 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0 AND session_id = 0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes) $sql = 'SELECT * FROM '.$table_qui.' WHERE active >=0 AND session_id = 0'; //select only quizzes with active = 0 or 1 (not -1 which is for deleted quizzes)
} }
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
if (strlen($obj->sound) > 0) if (strlen($obj->sound) > 0)
@ -330,7 +330,7 @@ class CourseBuilder
} }
$quiz = new Quiz($obj->id, $obj->title, $obj->description, $obj->random, $obj->type, $obj->active, $obj->sound, $obj->max_attempt, $obj->results_disabled, $obj->access_condition, $obj->start_time, $obj->end_time, $obj->feedback_type, $obj->random_answers, $obj->expired_time); $quiz = new Quiz($obj->id, $obj->title, $obj->description, $obj->random, $obj->type, $obj->active, $obj->sound, $obj->max_attempt, $obj->results_disabled, $obj->access_condition, $obj->start_time, $obj->end_time, $obj->feedback_type, $obj->random_answers, $obj->expired_time);
$sql = 'SELECT * FROM '.$table_rel.' WHERE exercice_id = '.$obj->id; $sql = 'SELECT * FROM '.$table_rel.' WHERE exercice_id = '.$obj->id;
$db_result2 = Database::query($sql, __FILE__, __LINE__); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2))
{ {
$quiz->add_question($obj2->question_id, $obj2->question_order); $quiz->add_question($obj2->question_id, $obj2->question_order);
@ -367,12 +367,12 @@ class CourseBuilder
// Building normal tests. // Building normal tests.
$sql = 'SELECT * FROM '.$table_que; $sql = 'SELECT * FROM '.$table_que;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level); $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id; $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql, __FILE__, __LINE__); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2))
{ {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type); $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
@ -385,7 +385,7 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table_que. $sql = 'SELECT * FROM '.$table_que.
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui. ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test. ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) if (Database::num_rows($db_result) > 0)
{ {
$build_orphan_questions = true; $build_orphan_questions = true;
@ -393,7 +393,7 @@ class CourseBuilder
{ {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level); $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.(int)$obj->id; $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.(int)$obj->id;
$db_result2 = Database::query($sql, __FILE__, __LINE__); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2))
{ {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type); $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
@ -419,7 +419,7 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table_que. $sql = 'SELECT * FROM '.$table_que.
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui. ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1';
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) if (Database::num_rows($db_result) > 0)
{ {
$orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions. $orphan_questions = new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0); // Tjis is the fictional test for collecting orphan questions.
@ -428,7 +428,7 @@ class CourseBuilder
{ {
$question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level); $question = new QuizQuestion($obj->id, $obj->question, $obj->description, $obj->ponderation, $obj->type, $obj->position, $obj->picture,$obj->level);
$sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id; $sql = 'SELECT * FROM '.$table_ans.' WHERE question_id = '.$obj->id;
$db_result2 = Database::query($sql, __FILE__, __LINE__); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2))
{ {
$question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type); $question->add_answer($obj2->id, $obj2->answer, $obj2->correct, $obj2->comment, $obj2->ponderation, $obj2->position, $obj2->hotspot_coordinates, $obj2->hotspot_type);
@ -445,7 +445,7 @@ class CourseBuilder
$table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$sql = 'SELECT * FROM '.$table_survey.' WHERE session_id = 0 '; $sql = 'SELECT * FROM '.$table_survey.' WHERE session_id = 0 ';
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$survey = new Survey($obj->survey_id, $obj->code,$obj->title, $survey = new Survey($obj->survey_id, $obj->code,$obj->title,
@ -455,7 +455,7 @@ class CourseBuilder
$obj->creation_date, $obj->invited, $obj->answered, $obj->creation_date, $obj->invited, $obj->answered,
$obj->invite_mail, $obj->reminder_mail); $obj->invite_mail, $obj->reminder_mail);
$sql = 'SELECT * FROM '.$table_question.' WHERE survey_id = '.$obj->survey_id; $sql = 'SELECT * FROM '.$table_question.' WHERE survey_id = '.$obj->survey_id;
$db_result2 = Database::query($sql, __FILE__, __LINE__); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2))
{ {
$survey->add_question($obj2->question_id); $survey->add_question($obj2->question_id);
@ -472,7 +472,7 @@ class CourseBuilder
$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_opt = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$sql = 'SELECT * FROM '.$table_que; $sql = 'SELECT * FROM '.$table_que;
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$question = new SurveyQuestion($obj->question_id, $obj->survey_id, $question = new SurveyQuestion($obj->question_id, $obj->survey_id,
@ -480,7 +480,7 @@ class CourseBuilder
$obj->type, $obj->display, $obj->sort, $obj->type, $obj->display, $obj->sort,
$obj->shared_question_id, $obj->max_value); $obj->shared_question_id, $obj->max_value);
$sql = 'SELECT * FROM '.$table_opt.' WHERE question_id = '."'".$obj->question_id."'"; $sql = 'SELECT * FROM '.$table_opt.' WHERE question_id = '."'".$obj->question_id."'";
$db_result2 = Database::query($sql, __FILE__, __LINE__); $db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) while ($obj2 = Database::fetch_object($db_result2))
{ {
$question->add_answer($obj2->option_text, $obj2->sort); $question->add_answer($obj2->option_text, $obj2->sort);
@ -495,7 +495,7 @@ class CourseBuilder
{ {
$table = Database :: get_course_table(TABLE_ANNOUNCEMENT); $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
$sql = 'SELECT * FROM '.$table.' WHERE session_id = 0'; $sql = 'SELECT * FROM '.$table.' WHERE session_id = 0';
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent); $announcement = new Announcement($obj->id, $obj->title, $obj->content, $obj->end_date,$obj->display_order,$obj->email_sent);
@ -509,7 +509,7 @@ class CourseBuilder
{ {
$table = Database :: get_course_table(TABLE_AGENDA); $table = Database :: get_course_table(TABLE_AGENDA);
$sql = 'SELECT * FROM '.$table.' WHERE session_id = 0'; $sql = 'SELECT * FROM '.$table.' WHERE session_id = 0';
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date); $event = new Event($obj->id, $obj->title, $obj->content, $obj->start_date, $obj->end_date);
@ -531,7 +531,7 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table. ' WHERE session_id = 0'; $sql = 'SELECT * FROM '.$table. ' WHERE session_id = 0';
} }
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type); $cd = new CourseDescription($obj->id, $obj->title, $obj->content, $obj->description_type);
@ -559,7 +559,7 @@ class CourseBuilder
$sql = 'SELECT * FROM '.$table_main.' WHERE session_id = 0'; $sql = 'SELECT * FROM '.$table_main.' WHERE session_id = 0';
} }
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
@ -661,7 +661,7 @@ class CourseBuilder
} }
} }
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order); $doc = new Glossary($obj->glossary_id, $obj->name, $obj->description, $obj->display_order);
@ -688,7 +688,7 @@ class CourseBuilder
$sql_session = "SELECT id, name, course_code FROM $tbl_session_course $sql_session = "SELECT id, name, course_code FROM $tbl_session_course
INNER JOIN $tbl_session ON id_session = id INNER JOIN $tbl_session ON id_session = id
WHERE course_code = '$code_course' "; WHERE course_code = '$code_course' ";
$query_session = Database::query($sql_session, __FILE__, __LINE__); $query_session = Database::query($sql_session);
while ($rows_session = Database::fetch_assoc($query_session)) { while ($rows_session = Database::fetch_assoc($query_session)) {
$session = new CourseSession($rows_session['id'], $rows_session['name']); $session = new CourseSession($rows_session['id'], $rows_session['name']);
$this->course->add_resource($session); $this->course->add_resource($session);
@ -709,7 +709,7 @@ class CourseBuilder
$tbl_wiki = Database::get_course_table(TABLE_WIKI); $tbl_wiki = Database::get_course_table(TABLE_WIKI);
$sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE session_id = 0'; $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE session_id = 0';
} }
$db_result = api_sql_query($sql, __FILE__, __LINE__); $db_result = api_sql_query($sql);
while ($obj = Database::fetch_object($db_result)) while ($obj = Database::fetch_object($db_result))
{ {
$wiki = new Wiki($obj->id, $obj->page_id, $obj->reflink, $obj->title, $obj->content, $obj->user_id, $obj->group_id, $obj->dtime, $obj->progress, $obj->version); $wiki = new Wiki($obj->id, $obj->page_id, $obj->reflink, $obj->title, $obj->content, $obj->user_id, $obj->group_id, $obj->dtime, $obj->progress, $obj->version);

@ -61,16 +61,16 @@ class CourseRecycler
foreach ($resources as $id => $resource) foreach ($resources as $id => $resource)
{ {
$sql = "DELETE FROM ".$table_linked_resources." WHERE (source_type = '".$type."' AND source_id = '".$id."') OR (resource_type = '".$type."' AND resource_id = '".$id."') "; $sql = "DELETE FROM ".$table_linked_resources." WHERE (source_type = '".$type."' AND source_id = '".$id."') OR (resource_type = '".$type."' AND resource_id = '".$id."') ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
if(is_numeric($id)) if(is_numeric($id))
{ {
$sql = "DELETE FROM ".$table_item_properties." WHERE tool ='".$resource->get_tool()."' AND ref=".$id; $sql = "DELETE FROM ".$table_item_properties." WHERE tool ='".$resource->get_tool()."' AND ref=".$id;
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
elseif ($type == RESOURCE_TOOL_INTRO) elseif ($type == RESOURCE_TOOL_INTRO)
{ {
$sql = "DELETE FROM $table_tool_intro WHERE id='$id'"; $sql = "DELETE FROM $table_tool_intro WHERE id='$id'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
} }
@ -102,7 +102,7 @@ class CourseRecycler
} }
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT])));
$sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
@ -124,9 +124,9 @@ class CourseRecycler
$page_ids = implode(',', $pages); $page_ids = implode(',', $pages);
$sql = "DELETE FROM ".$table_wiki." WHERE id IN(".$wiki_ids.")"; $sql = "DELETE FROM ".$table_wiki." WHERE id IN(".$wiki_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_wiki_conf." WHERE page_id IN(".$page_ids.")"; $sql = "DELETE FROM ".$table_wiki_conf." WHERE page_id IN(".$page_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
@ -138,7 +138,7 @@ class CourseRecycler
$table_glossary = Database::get_course_table(TABLE_GLOSSARY); $table_glossary = Database::get_course_table(TABLE_GLOSSARY);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_GLOSSARY]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_GLOSSARY])));
$sql = "DELETE FROM ".$table_glossary." WHERE glossary_id IN(".$ids.")"; $sql = "DELETE FROM ".$table_glossary." WHERE glossary_id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
@ -152,7 +152,7 @@ class CourseRecycler
$table = Database :: get_course_table(TABLE_LINK); $table = Database :: get_course_table(TABLE_LINK);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_LINK]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_LINK])));
$sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -178,44 +178,44 @@ class CourseRecycler
" USING ".$table_attachment." INNER JOIN ".$table_post. " USING ".$table_attachment." INNER JOIN ".$table_post.
" WHERE ".$table_attachment.".post_id = ".$table_post.".post_id". " WHERE ".$table_attachment.".post_id = ".$table_post.".post_id".
" AND ".$table_post.".forum_id IN(".$forum_ids.");"; " AND ".$table_post.".forum_id IN(".$forum_ids.");";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_mail_queue. $sql = "DELETE FROM ".$table_mail_queue.
" USING ".$table_mail_queue." INNER JOIN ".$table_post. " USING ".$table_mail_queue." INNER JOIN ".$table_post.
" WHERE ".$table_mail_queue.".post_id = ".$table_post.".post_id". " WHERE ".$table_mail_queue.".post_id = ".$table_post.".post_id".
" AND ".$table_post.".forum_id IN(".$forum_ids.");"; " AND ".$table_post.".forum_id IN(".$forum_ids.");";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
// Just in case, deleting in the same table using thread_id as record-linker. // Just in case, deleting in the same table using thread_id as record-linker.
$sql = "DELETE FROM ".$table_mail_queue. $sql = "DELETE FROM ".$table_mail_queue.
" USING ".$table_mail_queue." INNER JOIN ".$table_thread. " USING ".$table_mail_queue." INNER JOIN ".$table_thread.
" WHERE ".$table_mail_queue.".thread_id = ".$table_thread.".thread_id". " WHERE ".$table_mail_queue.".thread_id = ".$table_thread.".thread_id".
" AND ".$table_thread.".forum_id IN(".$forum_ids.");"; " AND ".$table_thread.".forum_id IN(".$forum_ids.");";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify. $sql = "DELETE FROM ".$table_thread_qualify.
" USING ".$table_thread_qualify." INNER JOIN ".$table_thread. " USING ".$table_thread_qualify." INNER JOIN ".$table_thread.
" WHERE ".$table_thread_qualify.".thread_id = ".$table_thread.".thread_id". " WHERE ".$table_thread_qualify.".thread_id = ".$table_thread.".thread_id".
" AND ".$table_thread.".forum_id IN(".$forum_ids.");"; " AND ".$table_thread.".forum_id IN(".$forum_ids.");";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_thread_qualify_log. $sql = "DELETE FROM ".$table_thread_qualify_log.
" USING ".$table_thread_qualify_log." INNER JOIN ".$table_thread. " USING ".$table_thread_qualify_log." INNER JOIN ".$table_thread.
" WHERE ".$table_thread_qualify_log.".thread_id = ".$table_thread.".thread_id". " WHERE ".$table_thread_qualify_log.".thread_id = ".$table_thread.".thread_id".
" AND ".$table_thread.".forum_id IN(".$forum_ids.");"; " AND ".$table_thread.".forum_id IN(".$forum_ids.");";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_notification." WHERE forum_id IN(".$forum_ids.")"; $sql = "DELETE FROM ".$table_notification." WHERE forum_id IN(".$forum_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_post." WHERE forum_id IN(".$forum_ids.")"; $sql = "DELETE FROM ".$table_post." WHERE forum_id IN(".$forum_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_thread." WHERE forum_id IN(".$forum_ids.")"; $sql = "DELETE FROM ".$table_thread." WHERE forum_id IN(".$forum_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_forum." WHERE forum_id IN(".$forum_ids.")"; $sql = "DELETE FROM ".$table_forum." WHERE forum_id IN(".$forum_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -227,11 +227,11 @@ class CourseRecycler
$table_forum = Database :: get_course_table(TABLE_FORUM); $table_forum = Database :: get_course_table(TABLE_FORUM);
$table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY); $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"; $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__); $res = Database::query($sql);
while ($obj = Database::fetch_object($res)) while ($obj = Database::fetch_object($res))
{ {
$sql = "DELETE FROM ".$table_forumcat." WHERE cat_id = ".$obj->cat_id; $sql = "DELETE FROM ".$table_forumcat." WHERE cat_id = ".$obj->cat_id;
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -243,11 +243,11 @@ class CourseRecycler
$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY); $link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
$link_table = Database :: get_course_table(TABLE_LINK); $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"; $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__); $res = Database::query($sql);
while ($obj = Database::fetch_object($res)) while ($obj = Database::fetch_object($res))
{ {
$sql = "DELETE FROM ".$link_cat_table." WHERE id = ".$obj->id; $sql = "DELETE FROM ".$link_cat_table." WHERE id = ".$obj->id;
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -260,7 +260,7 @@ class CourseRecycler
$table = Database :: get_course_table(TABLE_AGENDA); $table = Database :: get_course_table(TABLE_AGENDA);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_EVENT]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_EVENT])));
$sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -273,7 +273,7 @@ class CourseRecycler
$table = Database :: get_course_table(TABLE_ANNOUNCEMENT); $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_ANNOUNCEMENT]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_ANNOUNCEMENT])));
$sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -294,9 +294,9 @@ class CourseRecycler
// Deletion of the normal tests, questions in them are not deleted, they become orphan at this moment. // Deletion of the normal tests, questions in them are not deleted, they become orphan at this moment.
$sql = "DELETE FROM ".$table_qui." WHERE id <> -1 AND id IN(".$ids.")"; $sql = "DELETE FROM ".$table_qui." WHERE id <> -1 AND id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_rel." WHERE exercice_id <> -1 AND exercice_id IN(".$ids.")"; $sql = "DELETE FROM ".$table_rel." WHERE exercice_id <> -1 AND exercice_id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
// Identifying again and deletion of the orphan questions, if it was desired. // Identifying again and deletion of the orphan questions, if it was desired.
if ($delete_orphan_questions) if ($delete_orphan_questions)
@ -304,7 +304,7 @@ class CourseRecycler
$sql = 'SELECT questions.id FROM '.$table_qui_que. $sql = 'SELECT questions.id FROM '.$table_qui_que.
' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui. ' as questions LEFT JOIN '.$table_rel.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$table_qui.
' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test. ' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1'; // active = -1 means "deleted" test.
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
if (Database::num_rows($db_result) > 0) if (Database::num_rows($db_result) > 0)
{ {
$orphan_ids = array(); $orphan_ids = array();
@ -314,18 +314,18 @@ class CourseRecycler
} }
$orphan_ids = implode(',', $orphan_ids); $orphan_ids = implode(',', $orphan_ids);
$sql = "DELETE FROM ".$table_rel." WHERE question_id IN(".$orphan_ids.")"; $sql = "DELETE FROM ".$table_rel." WHERE question_id IN(".$orphan_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_qui_ans." WHERE question_id IN(".$orphan_ids.")"; $sql = "DELETE FROM ".$table_qui_ans." WHERE question_id IN(".$orphan_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_qui_que." WHERE id IN(".$orphan_ids.")"; $sql = "DELETE FROM ".$table_qui_que." WHERE id IN(".$orphan_ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
} }
// Purge "deleted" tests (active = -1). // Purge "deleted" tests (active = -1).
$sql = "DELETE FROM ".$table_qui." WHERE active = -1"; $sql = "DELETE FROM ".$table_qui." WHERE active = -1";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
/** /**
* Recycle surveys - removes everything * Recycle surveys - removes everything
@ -341,15 +341,15 @@ class CourseRecycler
$table_survey_i = Database :: get_course_table(TABLE_SURVEY_INVITATION); $table_survey_i = Database :: get_course_table(TABLE_SURVEY_INVITATION);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_SURVEY]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_SURVEY])));
$sql = "DELETE FROM ".$table_survey_i." "; $sql = "DELETE FROM ".$table_survey_i." ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_survey_a." WHERE survey_id IN(".$ids.")"; $sql = "DELETE FROM ".$table_survey_a." WHERE survey_id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_survey_q_o." WHERE survey_id IN(".$ids.")"; $sql = "DELETE FROM ".$table_survey_q_o." WHERE survey_id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_survey_q." WHERE survey_id IN(".$ids.")"; $sql = "DELETE FROM ".$table_survey_q." WHERE survey_id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$sql = "DELETE FROM ".$table_survey." WHERE survey_id IN(".$ids.")"; $sql = "DELETE FROM ".$table_survey." WHERE survey_id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
/** /**
@ -369,34 +369,34 @@ class CourseRecycler
{ {
//remove links from course homepage //remove links from course homepage
$sql = "DELETE FROM $table_tool WHERE link LIKE '%lp_controller.php%lp_id=$id%' AND image='scormbuilder.gif'"; $sql = "DELETE FROM $table_tool WHERE link LIKE '%lp_controller.php%lp_id=$id%' AND image='scormbuilder.gif'";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
//remove elements from lp_* tables (from bottom-up) by removing interactions, then item_view, then views and items, then paths //remove elements from lp_* tables (from bottom-up) by removing interactions, then item_view, then views and items, then paths
$sql_items = "SELECT id FROM $table_item WHERE lp_id=$id"; $sql_items = "SELECT id FROM $table_item WHERE lp_id=$id";
$res_items = Database::query($sql_items,__FILE__,__LINE__); $res_items = Database::query($sql_items);
while ($row_item = Database::fetch_array($res_items)) while ($row_item = Database::fetch_array($res_items))
{ {
//get item views //get item views
$sql_iv = "SELECT id FROM $table_iv WHERE lp_item_id=".$row_item['id']; $sql_iv = "SELECT id FROM $table_iv WHERE lp_item_id=".$row_item['id'];
$res_iv = Database::query($sql_iv,__FILE__,__LINE__); $res_iv = Database::query($sql_iv);
while ($row_iv = Database::fetch_array($res_iv)) while ($row_iv = Database::fetch_array($res_iv))
{ {
//delete interactions //delete interactions
$sql_iv_int_del = "DELETE FROM $table_iv_int WHERE lp_iv_id = ".$row_iv['id']; $sql_iv_int_del = "DELETE FROM $table_iv_int WHERE lp_iv_id = ".$row_iv['id'];
$res_iv_int_del = Database::query($sql_iv_int_del,__FILE__,__LINE__); $res_iv_int_del = Database::query($sql_iv_int_del);
} }
//delete item views //delete item views
$sql_iv_del = "DELETE FROM $table_iv WHERE lp_item_id=".$row_item['id']; $sql_iv_del = "DELETE FROM $table_iv WHERE lp_item_id=".$row_item['id'];
$res_iv_del = Database::query($sql_iv_del,__FILE__,__LINE__); $res_iv_del = Database::query($sql_iv_del);
} }
//delete items //delete items
$sql_items_del = "DELETE FROM $table_item WHERE lp_id=$id"; $sql_items_del = "DELETE FROM $table_item WHERE lp_id=$id";
$res_items_del = Database::query($sql_items_del,__FILE__,__LINE__); $res_items_del = Database::query($sql_items_del);
//delete views //delete views
$sql_views_del = "DELETE FROM $table_view WHERE lp_id=$id"; $sql_views_del = "DELETE FROM $table_view WHERE lp_id=$id";
$res_views_del = Database::query($sql_views_del,__FILE__,__LINE__); $res_views_del = Database::query($sql_views_del);
//delete lps //delete lps
$sql_del = "DELETE FROM $table_main WHERE id = $id"; $sql_del = "DELETE FROM $table_main WHERE id = $id";
$res_del = Database::query($sql_del,__FILE__,__LINE__); $res_del = Database::query($sql_del);
} }
} }
} }
@ -410,7 +410,7 @@ class CourseRecycler
$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_COURSEDESCRIPTION]))); $ids = implode(',', (array_keys($this->course->resources[RESOURCE_COURSEDESCRIPTION])));
$sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")"; $sql = "DELETE FROM ".$table." WHERE id IN(".$ids.")";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
} }

@ -158,7 +158,7 @@ class CourseRestorer
// First check if there isn't allready a record for this resource // First check if there isn't allready a record for this resource
$sql = "SELECT * FROM $table WHERE tool = '".$property['tool']."' AND ref = '".$resource->destination_id."'"; $sql = "SELECT * FROM $table WHERE tool = '".$property['tool']."' AND ref = '".$resource->destination_id."'";
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql);
if( Database::num_rows($res) == 0) { if( Database::num_rows($res) == 0) {
// The to_group_id and to_user_id are set to default values as users/groups possibly not exist in the target course // The to_group_id and to_user_id are set to default values as users/groups possibly not exist in the target course
$sql = "INSERT INTO $table SET $sql = "INSERT INTO $table SET
@ -175,7 +175,7 @@ class CourseRestorer
to_user_id = '".Database::escape_string($property['to_user_id'])."', to_user_id = '".Database::escape_string($property['to_user_id'])."',
to_group_id = '0' $condition_session" ; to_group_id = '0' $condition_session" ;
; ;
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
} }
@ -195,7 +195,7 @@ class CourseRestorer
{ {
$to_resource = $this->course->resources[$to_type][$to_id]; $to_resource = $this->course->resources[$to_type][$to_id];
$sql = "INSERT INTO ".$table." SET source_type = '".$type."', source_id = '".$resource->destination_id."', resource_type='".$to_type."', resource_id='".$to_resource->destination_id."' "; $sql = "INSERT INTO ".$table." SET source_type = '".$type."', source_id = '".$resource->destination_id."', resource_type='".$to_type."', resource_id='".$to_resource->destination_id."' ";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
} }
@ -225,7 +225,7 @@ class CourseRestorer
$new = substr($document->path, 8); $new = substr($document->path, 8);
if (!is_dir($path.'document/'.$new)) { if (!is_dir($path.'document/'.$new)) {
$sql = "SELECT id FROM ".$table." WHERE path='/".Database::escape_string($new)."'"; $sql = "SELECT id FROM ".$table." WHERE path='/".Database::escape_string($new)."'";
$res = Database::query($sql, __FILE__, __LINE__); $res = Database::query($sql);
$num_result = Database::num_rows($res); $num_result = Database::num_rows($res);
if ($num_result==0) { if ($num_result==0) {
$created_dir = create_unexisting_directory($destination_course,api_get_user_id(),0, 0 ,$path.'document',$new,basename($new),$visibility); $created_dir = create_unexisting_directory($destination_course,api_get_user_id(),0, 0 ,$path.'document',$new,basename($new),$visibility);
@ -241,7 +241,7 @@ class CourseRestorer
$my_temp .= $dirs[$i]; $my_temp .= $dirs[$i];
if (!is_dir($path.'document/'.$my_temp)) { if (!is_dir($path.'document/'.$my_temp)) {
$sql = "SELECT id FROM ".$table." WHERE path='/".Database::escape_string($my_temp)."'"; $sql = "SELECT id FROM ".$table." WHERE path='/".Database::escape_string($my_temp)."'";
$res = Database::query($sql, __FILE__, __LINE__); $res = Database::query($sql);
$num_result = Database::num_rows($res); $num_result = Database::num_rows($res);
if ($num_result==0) { if ($num_result==0) {
$created_dir = create_unexisting_directory($destination_course,api_get_user_id(),0, 0 ,$path.'document','/'.$my_temp,basename($my_temp)); $created_dir = create_unexisting_directory($destination_course,api_get_user_id(),0, 0 ,$path.'document','/'.$my_temp,basename($my_temp));
@ -271,15 +271,15 @@ class CourseRestorer
copy($origin_path, $path.$document->path); copy($origin_path, $path.$document->path);
} }
$sql = "SELECT id FROM ".$table." WHERE path='/".substr($document->path, 9)."'"; $sql = "SELECT id FROM ".$table." WHERE path='/".substr($document->path, 9)."'";
$res = Database::query($sql, __FILE__, __LINE__); $res = Database::query($sql);
$obj = Database::fetch_object($res); $obj = Database::fetch_object($res);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
$sql = "UPDATE ".$table." SET comment = '".Database::escape_string($document->comment)."', title='".Database::escape_string($document->title)."', size='".$document->size."' WHERE id = '".$obj->id."'"; $sql = "UPDATE ".$table." SET comment = '".Database::escape_string($document->comment)."', title='".Database::escape_string($document->title)."', size='".$document->size."' WHERE id = '".$obj->id."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
break; break;
case FILE_SKIP : case FILE_SKIP :
$sql = "SELECT id FROM ".$table." WHERE path='/".Database::escape_string(substr($document->path, 9))."'"; $sql = "SELECT id FROM ".$table." WHERE path='/".Database::escape_string(substr($document->path, 9))."'";
$res = Database::query($sql, __FILE__, __LINE__); $res = Database::query($sql);
$obj = Database::fetch_object($res); $obj = Database::fetch_object($res);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id; $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
break; break;
@ -353,20 +353,20 @@ class CourseRestorer
copy($course_path.$document->path, $dest_document_path); 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'"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
} else { } else {
copy($path.$document->path, $path.$new_file_name); 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'"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
} }
} else { } else {
copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name); 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."'"; $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."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
} }
break; break;
@ -381,7 +381,7 @@ class CourseRestorer
{ {
copy($this->course->backup_path.'/'.$document->path, $path.$document->path); 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."'"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
} }
else else
@ -404,7 +404,7 @@ class CourseRestorer
else else
{ {
/*$sql = "SELECT id FROM ".$table." WHERE path = '/".Database::escape_string(substr($document->path, 9))."'"; /*$sql = "SELECT id FROM ".$table." WHERE path = '/".Database::escape_string(substr($document->path, 9))."'";
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql);
if( Database::num_rows($res)> 0) if( Database::num_rows($res)> 0)
{ {
$obj = Database::fetch_object($res); $obj = Database::fetch_object($res);
@ -413,7 +413,7 @@ class CourseRestorer
else else
{ {
$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."'"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = Database::insert_id();
}*/ }*/
} // end folder } // end folder
@ -532,7 +532,7 @@ class CourseRestorer
", locked = ".(int)Database::escape_string($forum->locked). ", locked = ".(int)Database::escape_string($forum->locked).
", session_id = ".(int)Database::escape_string($forum->session_id). ", session_id = ".(int)Database::escape_string($forum->session_id).
", forum_image = '".Database::escape_string($forum->image)."'"; ", forum_image = '".Database::escape_string($forum->image)."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
$forum_topics = 0; $forum_topics = 0;
@ -551,7 +551,7 @@ class CourseRestorer
{ {
$last_post = $this->course->resources[RESOURCE_FORUMPOST][$forum->last_post]; $last_post = $this->course->resources[RESOURCE_FORUMPOST][$forum->last_post];
$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics.", forum_last_post = ".(int)$last_post->destination_id." WHERE forum_id = ".(int)$new_id; $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics.", forum_last_post = ".(int)$last_post->destination_id." WHERE forum_id = ".(int)$new_id;
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
} }
@ -580,7 +580,7 @@ class CourseRestorer
"', cat_order = ".(int)Database::escape_string($forum_cat->order). "', cat_order = ".(int)Database::escape_string($forum_cat->order).
", locked = ".(int)Database::escape_string($forum_cat->locked). ", locked = ".(int)Database::escape_string($forum_cat->locked).
", session_id = ".(int)Database::escape_string($forum_cat->session_id); ", session_id = ".(int)Database::escape_string($forum_cat->session_id);
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_FORUMCATEGORY][$id]->destination_id = $new_id;
return $new_id; return $new_id;
@ -608,7 +608,7 @@ class CourseRestorer
"', thread_weight = ".(float)Database::escape_string($topic->weight). "', thread_weight = ".(float)Database::escape_string($topic->weight).
", thread_title_qualify = '".Database::escape_string($topic->title_qualify). ", thread_title_qualify = '".Database::escape_string($topic->title_qualify).
"', thread_qualify_max = ".(float)Database::escape_string($topic->qualify_max); "', thread_qualify_max = ".(float)Database::escape_string($topic->qualify_max);
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_FORUMTOPIC][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_FORUMTOPIC][$id]->destination_id = $new_id;
$topic_replies = -1; $topic_replies = -1;
@ -624,12 +624,12 @@ class CourseRestorer
if (is_object($last_post)) if (is_object($last_post))
{ {
$sql = "UPDATE ".$table." SET thread_last_post = ".(int)$last_post->destination_id; $sql = "UPDATE ".$table." SET thread_last_post = ".(int)$last_post->destination_id;
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
if ($topic_replies >= 0) if ($topic_replies >= 0)
{ {
$sql = "UPDATE ".$table." SET thread_replies = ".$topic_replies; $sql = "UPDATE ".$table." SET thread_replies = ".$topic_replies;
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
return $new_id; return $new_id;
} }
@ -653,7 +653,7 @@ class CourseRestorer
"', post_notification = ".(int)Database::escape_string($post->topic_notify). "', post_notification = ".(int)Database::escape_string($post->topic_notify).
", post_parent_id = ".(int)Database::escape_string($post->parent_post_id). ", post_parent_id = ".(int)Database::escape_string($post->parent_post_id).
", visible = ".(int)Database::escape_string($post->visible); ", visible = ".(int)Database::escape_string($post->visible);
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
return $new_id; return $new_id;
@ -671,7 +671,7 @@ class CourseRestorer
{ {
$cat_id = $this->restore_link_category($link->category_id,$session_id); $cat_id = $this->restore_link_category($link->category_id,$session_id);
$sql = "SELECT MAX(display_order) FROM $link_table WHERE category_id='" . Database::escape_string($cat_id). "'"; $sql = "SELECT MAX(display_order) FROM $link_table WHERE category_id='" . Database::escape_string($cat_id). "'";
$result = Database::query($sql, __FILE__, __LINE__); $result = Database::query($sql);
list($max_order) = Database::fetch_array($result); list($max_order) = Database::fetch_array($result);
$condition_session = ""; $condition_session = "";
@ -681,7 +681,7 @@ class CourseRestorer
$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"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_LINK][$id]->destination_id = Database::insert_id();
} }
} }
@ -698,10 +698,10 @@ class CourseRestorer
foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro)
{ {
$sql = "DELETE FROM ".$tool_intro_table." WHERE id='".Database::escape_string($tool_intro->id)."'"; $sql = "DELETE FROM ".$tool_intro_table." WHERE id='".Database::escape_string($tool_intro->id)."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$sql = "INSERT INTO ".$tool_intro_table." SET id='".Database::escape_string($tool_intro->id)."', intro_text = '".Database::escape_string($tool_intro->intro_text)."'"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = Database::insert_id();
} }
@ -726,11 +726,11 @@ class CourseRestorer
if (is_object($link_cat) && !$link_cat->is_restored()) if (is_object($link_cat) && !$link_cat->is_restored())
{ {
$sql = "SELECT MAX(display_order) FROM $link_cat_table"; $sql = "SELECT MAX(display_order) FROM $link_cat_table";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
list($orderMax)=Database::fetch_array($result,'NUM'); list($orderMax)=Database::fetch_array($result,'NUM');
$display_order=$orderMax+1; $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 "; $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__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id = $new_id;
return $new_id; return $new_id;
@ -752,7 +752,7 @@ class CourseRestorer
$event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course($event->content, $this->course->code, $this->course->destination_path); $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course($event->content, $this->course->code, $this->course->destination_path);
$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."'"; $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__); Database::query($sql);
$this->course->resources[RESOURCE_EVENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_EVENT][$id]->destination_id = Database::insert_id();
} }
} }
@ -785,7 +785,7 @@ class CourseRestorer
$condition_session = " , session_id = '$session_id' "; $condition_session = " , session_id = '$session_id' ";
} }
$sql = "INSERT INTO ".$table." SET description_type = '".Database::escape_string($cd->description_type)."',title = '".Database::escape_string($cd->title)."', content = '".Database::escape_string($description_content)."' $condition_session"; $sql = "INSERT INTO ".$table." SET description_type = '".Database::escape_string($cd->description_type)."',title = '".Database::escape_string($cd->title)."', content = '".Database::escape_string($description_content)."' $condition_session";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = Database::insert_id();
} }
} }
@ -811,7 +811,7 @@ class CourseRestorer
"end_date = '".$announcement->date."', " . "end_date = '".$announcement->date."', " .
"display_order = '".$announcement->display_order."', " . "display_order = '".$announcement->display_order."', " .
"email_sent = '".$announcement->email_sent."'"; "email_sent = '".$announcement->email_sent."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = Database::insert_id();
} }
} }
@ -835,7 +835,7 @@ class CourseRestorer
if ($this->course->resources[RESOURCE_DOCUMENT][$quiz->media]->is_restored()) if ($this->course->resources[RESOURCE_DOCUMENT][$quiz->media]->is_restored())
{ {
$sql = "SELECT path FROM ".$table_doc." WHERE id = ".$resources[RESOURCE_DOCUMENT][$quiz->media]->destination_id; $sql = "SELECT path FROM ".$table_doc." WHERE id = ".$resources[RESOURCE_DOCUMENT][$quiz->media]->destination_id;
$doc = Database::query($sql, __FILE__, __LINE__); $doc = Database::query($sql);
$doc = Database::fetch_object($doc); $doc = Database::fetch_object($doc);
$doc = str_replace('/audio/', '', $doc->path); $doc = str_replace('/audio/', '', $doc->path);
} }
@ -869,7 +869,7 @@ class CourseRestorer
", random_answers = ".(int)$quiz->random_answers. ", random_answers = ".(int)$quiz->random_answers.
", expired_time = ".(int)$quiz->expired_time. ", expired_time = ".(int)$quiz->expired_time.
$condition_session; $condition_session;
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
} else { } else {
// $id = -1 identifies the fictionary test for collecting orphan questions. We do not store it in the database. // $id = -1 identifies the fictionary test for collecting orphan questions. We do not store it in the database.
@ -879,7 +879,7 @@ class CourseRestorer
foreach ($quiz->question_ids as $index => $question_id) { foreach ($quiz->question_ids as $index => $question_id) {
$qid = $this->restore_quiz_question($question_id); $qid = $this->restore_quiz_question($question_id);
$sql = "INSERT IGNORE INTO ".$table_rel." SET question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$quiz->question_orders[$index].""; $sql = "INSERT IGNORE INTO ".$table_rel." SET question_id = ".$qid.", exercice_id = ".$new_id.", question_order = ".$quiz->question_orders[$index]."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
} }
@ -907,14 +907,14 @@ class CourseRestorer
$question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path); $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($question->description, $this->course->code, $this->course->destination_path);
$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)."'"; $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__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
if ($question->quiz_type == 4) { // for answer type matching if ($question->quiz_type == 4) { // for answer type matching
foreach ($question->answers as $index => $answer) { foreach ($question->answers as $index => $answer) {
$sql = "INSERT INTO ".$table_ans." SET id= '".$answer['id']."',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']."'"; $sql = "INSERT INTO ".$table_ans." SET id= '".$answer['id']."',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']."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} else { } else {
foreach ($question->answers as $index => $answer) { foreach ($question->answers as $index => $answer) {
@ -924,7 +924,7 @@ class CourseRestorer
$answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['comment'], $this->course->code, $this->course->destination_path); $answer['comment'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($answer['comment'], $this->course->code, $this->course->destination_path);
$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']."'"; $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']."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
@ -950,7 +950,7 @@ class CourseRestorer
AND lang="'.Database::escape_string($survey->lang).'" AND lang="'.Database::escape_string($survey->lang).'"
'; ';
$result_check = Database::query($sql_check, __FILE__, __LINE__); $result_check = Database::query($sql_check);
// check resources inside html from fckeditor tool and copy correct urls into recipient course // check resources inside html from fckeditor tool and copy correct urls into recipient course
$survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->title, $this->course->code, $this->course->destination_path); $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->title, $this->course->code, $this->course->destination_path);
@ -1017,7 +1017,7 @@ class CourseRestorer
"reminder_mail = '".Database::escape_string($survey->reminder_mail)."'"; "reminder_mail = '".Database::escape_string($survey->reminder_mail)."'";
//Insert the new source survey //Insert the new source survey
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
@ -1027,11 +1027,11 @@ class CourseRestorer
$sql = "UPDATE ".$table_que." " . $sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " . "SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid.""; "question_id = ".$qid."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$sql = "UPDATE ".$table_ans." ". $sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " . "SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid.""; "question_id = ".$qid."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
break; break;
@ -1044,7 +1044,7 @@ class CourseRestorer
require_once(api_get_path(SYS_CODE_PATH).'survey/survey.lib.php'); require_once(api_get_path(SYS_CODE_PATH).'survey/survey.lib.php');
$sql_select_existing_survey = "SELECT * FROM $table_sur WHERE survey_id='".Database::escape_string(Database::result($result_check,0,0))."'"; $sql_select_existing_survey = "SELECT * FROM $table_sur WHERE survey_id='".Database::escape_string(Database::result($result_check,0,0))."'";
$result = Database::query($sql_select_existing_survey, __FILE__, __LINE__); $result = Database::query($sql_select_existing_survey);
$survey_data = Database::fetch_array($result,'ASSOC'); $survey_data = Database::fetch_array($result,'ASSOC');
// if the survey is shared => also delete the shared content // if the survey is shared => also delete the shared content
@ -1055,7 +1055,7 @@ class CourseRestorer
$return = survey_manager :: delete_survey($survey_data['survey_id'],false,$this->course->destination_db); $return = survey_manager :: delete_survey($survey_data['survey_id'],false,$this->course->destination_db);
//Insert the new source survey //Insert the new source survey
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
@ -1065,11 +1065,11 @@ class CourseRestorer
$sql = "UPDATE ".$table_que." " . $sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " . "SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid.""; "question_id = ".$qid."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$sql = "UPDATE ".$table_ans." ". $sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " . "SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid.""; "question_id = ".$qid."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
break; break;
@ -1083,7 +1083,7 @@ class CourseRestorer
//No existing survey with the same language and the same code, we just copy the survey //No existing survey with the same language and the same code, we just copy the survey
else else
{ {
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
foreach ($survey->question_ids as $index => $question_id) foreach ($survey->question_ids as $index => $question_id)
@ -1092,11 +1092,11 @@ class CourseRestorer
$sql = "UPDATE ".$table_que." " . $sql = "UPDATE ".$table_que." " .
"SET survey_id = ".$new_id." WHERE " . "SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid.""; "question_id = ".$qid."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$sql = "UPDATE ".$table_ans." ". $sql = "UPDATE ".$table_ans." ".
"SET survey_id = ".$new_id." WHERE " . "SET survey_id = ".$new_id." WHERE " .
"question_id = ".$qid.""; "question_id = ".$qid."";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
@ -1111,7 +1111,7 @@ class CourseRestorer
{ {
$table_sur = Database :: get_course_table(TABLE_SURVEY, $this->course->destination_db); $table_sur = Database :: get_course_table(TABLE_SURVEY, $this->course->destination_db);
$sql = "SELECT * FROM $table_sur WHERE code='".Database::escape_string($survey_code)."'"; $sql = "SELECT * FROM $table_sur WHERE code='".Database::escape_string($survey_code)."'";
$result = Database::query($sql, __FILE__, __LINE__); $result = Database::query($sql);
if(Database::num_rows($result) > 0) return false; else return true; if(Database::num_rows($result) > 0) return false; else return true;
} }
@ -1147,7 +1147,7 @@ class CourseRestorer
"sort = '".Database::escape_string($question->sort)."', " . "sort = '".Database::escape_string($question->sort)."', " .
"shared_question_id = '".Database::escape_string($question->shared_question_id)."', " . "shared_question_id = '".Database::escape_string($question->shared_question_id)."', " .
"max_value = '".Database::escape_string($question->max_value)."' "; "max_value = '".Database::escape_string($question->max_value)."' ";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
foreach ($question->answers as $index => $answer) { foreach ($question->answers as $index => $answer) {
@ -1162,7 +1162,7 @@ class CourseRestorer
"sort = '".Database::escape_string($answer['sort'])."', " . "sort = '".Database::escape_string($answer['sort'])."', " .
"survey_id = '".Database::escape_string($question->survey_id)."'"; "survey_id = '".Database::escape_string($question->survey_id)."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
$this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
} }
@ -1205,13 +1205,13 @@ class CourseRestorer
"js_lib= '".Database::escape_string($lp->js_lib)."', " . "js_lib= '".Database::escape_string($lp->js_lib)."', " .
"content_license= '".Database::escape_string($lp->content_license)."', " . "content_license= '".Database::escape_string($lp->content_license)."', " .
"debug= '".Database::escape_string($lp->debug)."' $condition_session "; "debug= '".Database::escape_string($lp->debug)."' $condition_session ";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_lp_id = Database::insert_id(); $new_lp_id = Database::insert_id();
if($lp->visibility) { 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'"; $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'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
$new_item_ids = array(); $new_item_ids = array();
@ -1272,7 +1272,7 @@ class CourseRestorer
"parameters='".Database::escape_string($item['parameters'])."', " . "parameters='".Database::escape_string($item['parameters'])."', " .
"launch_data = '".Database::escape_string($item['launch_dataprereq_type'])."'"; "launch_data = '".Database::escape_string($item['launch_dataprereq_type'])."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
$new_item_id = Database::insert_id(); $new_item_id = Database::insert_id();
//save a link between old and new item IDs //save a link between old and new item IDs
$new_item_ids[$item['id']] = $new_item_id; $new_item_ids[$item['id']] = $new_item_id;
@ -1308,7 +1308,7 @@ class CourseRestorer
foreach ($old_prerequisite as $key=>$my_old_prerequisite) { foreach ($old_prerequisite as $key=>$my_old_prerequisite) {
if($my_old_prerequisite != ''){ if($my_old_prerequisite != ''){
$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."' WHERE id = '".$key."' "; $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."' WHERE id = '".$key."' ";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
@ -1316,7 +1316,7 @@ class CourseRestorer
foreach ($old_refs as $key=>$my_old_ref) { foreach ($old_refs as $key=>$my_old_ref) {
if ($my_old_ref != '') { if ($my_old_ref != '') {
$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."' WHERE id = '".$key."' "; $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."' WHERE id = '".$key."' ";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
} }
@ -1326,7 +1326,7 @@ class CourseRestorer
$parent_new_id = $new_item_ids[$parent_item_old_id]; $parent_new_id = $new_item_ids[$parent_item_old_id];
} }
$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' WHERE id = '".$new_item_id."'"; $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."' WHERE id = '".$new_item_id."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) { foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
$previous_new_id = 0; $previous_new_id = 0;
@ -1334,7 +1334,7 @@ class CourseRestorer
$previous_new_id = $new_item_ids[$previous_item_old_id]; $previous_new_id = $new_item_ids[$previous_item_old_id];
} }
$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' WHERE id = '".$new_item_id."'"; $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."' WHERE id = '".$new_item_id."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
foreach ($next_item_ids as $new_item_id => $next_item_old_id) { foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
@ -1343,7 +1343,7 @@ class CourseRestorer
$next_new_id = $new_item_ids[$next_item_old_id]; $next_new_id = $new_item_ids[$next_item_old_id];
} }
$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' WHERE id = '".$new_item_id."'"; $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."' WHERE id = '".$new_item_id."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id)
@ -1353,7 +1353,7 @@ class CourseRestorer
$prerequisite_new_id = $new_item_ids[$prerequisite_old_id]; $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
} }
$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."' WHERE id = '".$new_item_id."'"; $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."' WHERE id = '".$new_item_id."'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
} }
$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id; $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
@ -1417,9 +1417,9 @@ class CourseRestorer
$query_sql_ip = $query_sql_fin_ip.$query_sql_ini_ip; $query_sql_ip = $query_sql_fin_ip.$query_sql_ini_ip;
$query_sql_sa = $query_sql_fin_sa.$query_sql_ini_sa; $query_sql_sa = $query_sql_fin_sa.$query_sql_ini_sa;
Database::query($query_sql_sp,__FILE__,__LINE__); Database::query($query_sql_sp);
Database::query($query_sql_ip,__FILE__,__LINE__); Database::query($query_sql_ip);
Database::query($query_sql_sa,__FILE__,__LINE__); Database::query($query_sql_sa);
} }
@ -1492,7 +1492,7 @@ class CourseRestorer
$glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($glossary->description, $this->course->code, $this->course->destination_path); $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course($glossary->description, $this->course->code, $this->course->destination_path);
$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 "; $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__); Database::query($sql);
$this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = Database::insert_id(); $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = Database::insert_id();
} }
@ -1530,18 +1530,18 @@ class CourseRestorer
'".Database::escape_string($wiki->progress)."', '".Database::escape_string($wiki->progress)."',
'".intval($wiki->version)."', '".intval($wiki->version)."',
'".(!empty($session_id)?intval($session_id):0)."')"; '".(!empty($session_id)?intval($session_id):0)."')";
$rs2 = Database::query($sql, __FILE__, __LINE__); $rs2 = Database::query($sql);
$new_id = Database::insert_id(); $new_id = Database::insert_id();
$this->course->resources[RESOURCE_WIKI][$id]->destination_id = $new_id; $this->course->resources[RESOURCE_WIKI][$id]->destination_id = $new_id;
$sql = "UPDATE $table_wiki set page_id = '$new_id' WHERE id = '$new_id'"; $sql = "UPDATE $table_wiki set page_id = '$new_id' WHERE id = '$new_id'";
Database::query($sql, __FILE__, __LINE__); Database::query($sql);
// we also add an entry in wiki_conf // we also add an entry in wiki_conf
$sql = "INSERT INTO $table_wiki_conf $sql = "INSERT INTO $table_wiki_conf
(page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_size, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit) (page_id, task, feedback1, feedback2, feedback3, fprogress1, fprogress2, fprogress3, max_size, max_text, max_version, startdate_assig, enddate_assig, delayedsubmit)
VALUES VALUES
('".intval($new_id)."', '', '', '', '', '', '', '', NULL, 0, 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0)"; ('".intval($new_id)."', '', '', '', '', '', '', '', NULL, 0, 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0)";
$rs1 = Database::query($sql, __FILE__, __LINE__); $rs1 = Database::query($sql);
} }
} }
} }

@ -253,13 +253,13 @@ class CourseSelectForm
} }
$sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND id = '.$resource_item.$condition_session.' ORDER BY path'; $sql = 'SELECT * FROM '.$table_doc.' d, '.$table_prop.' p WHERE tool = \''.TOOL_DOCUMENT.'\' AND p.ref = d.id AND p.visibility != 2 AND id = '.$resource_item.$condition_session.' ORDER BY path';
$db_result = Database::query($sql, __FILE__, __LINE__); $db_result = Database::query($sql);
while ($obj = Database::fetch_object($db_result)) { while ($obj = Database::fetch_object($db_result)) {
$doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size); $doc = new Document($obj->id, $obj->path, $obj->comment, $obj->title, $obj->filetype, $obj->size);
$course->add_resource($doc); $course->add_resource($doc);
// adding item property // adding item property
$sql = "SELECT * FROM $table_prop WHERE TOOL = '".RESOURCE_DOCUMENT."' AND ref='".$resource_item."'"; $sql = "SELECT * FROM $table_prop WHERE TOOL = '".RESOURCE_DOCUMENT."' AND ref='".$resource_item."'";
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql);
$all_properties = array (); $all_properties = array ();
while ($item_property = Database::fetch_array($res,'ASSOC')) { while ($item_property = Database::fetch_array($res,'ASSOC')) {
$all_properties[] = $item_property; $all_properties[] = $item_property;

@ -76,7 +76,7 @@ if ((isset ($_POST['action']) && $_POST['action'] == 'course_select_form') || (i
$sql .= ' AND cu.status=1 '; $sql .= ' AND cu.status=1 ';
} }
$sql .= ' AND target_course_code IS NULL AND cu.user_id = '.$user_info['user_id'].' AND c.code != '."'".$course_info['sysCode']."'".' ORDER BY title ASC'; $sql .= ' AND target_course_code IS NULL AND cu.user_id = '.$user_info['user_id'].' AND c.code != '."'".$course_info['sysCode']."'".' ORDER BY title ASC';
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql);
if( Database::num_rows($res) == 0) { if( Database::num_rows($res) == 0) {
Display::display_normal_message(get_lang('NoDestinationCoursesAvailable')); Display::display_normal_message(get_lang('NoDestinationCoursesAvailable'));
} else { } else {

@ -145,7 +145,7 @@ function search_courses($id_session,$type) {
FROM $tbl_course c, $tbl_session_rel_course src FROM $tbl_course c, $tbl_session_rel_course src
WHERE src.course_code = c.code WHERE src.course_code = c.code
AND src.id_session = '".$id_session."'"; AND src.id_session = '".$id_session."'";
$rs = Database::query($sql, __FILE__, __LINE__); $rs = Database::query($sql);
$course_list = array(); $course_list = array();
@ -171,7 +171,7 @@ function search_courses($id_session,$type) {
FROM $session_table s , $session_category_table sc FROM $session_table s , $session_category_table sc
WHERE s.session_category_id = sc.id AND s.id NOT IN('$id_session')"; WHERE s.session_category_id = sc.id AND s.id NOT IN('$id_session')";
$rs_select_destination = Database::query($sql, __FILE__, __LINE__); $rs_select_destination = Database::query($sql);
$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('SelectASession').'</option>'; $select_destination .= '<option value = "0">'.get_lang('SelectASession').'</option>';
@ -206,7 +206,7 @@ function search_courses($id_session,$type) {
WHERE src.course_code = c.code WHERE src.course_code = c.code
AND src.id_session = '".intval($id_session)."' AND src.id_session = '".intval($id_session)."'
AND c.code IN ($list_courses_origin)"; AND c.code IN ($list_courses_origin)";
$rs = Database::query($sql, __FILE__, __LINE__); $rs = Database::query($sql);
$course_list_destination = array(); $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;">'; $return .= '<select id="destination" name="SessionCoursesListDestination[]" multiple="multiple" size="20" style="width:320px;" onmouseover="this.disabled=true;" onmouseout="this.disabled=false;">';
@ -226,7 +226,7 @@ function search_courses($id_session,$type) {
FROM $tbl_course c, $tbl_session_rel_course src FROM $tbl_course c, $tbl_session_rel_course src
WHERE src.course_code = c.code WHERE src.course_code = c.code
AND src.id_session = '".intval($session_origin)."'"; AND src.id_session = '".intval($session_origin)."'";
$result = Database::query($sql, __FILE__, __LINE__); $result = Database::query($sql);
$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\')">'; $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)) { while($cours = Database :: fetch_array($result)) {

@ -122,7 +122,7 @@ if ($form->validate()) {
$keys = define_course_keys($wanted_code, "", $_configuration['db_prefix']); $keys = define_course_keys($wanted_code, "", $_configuration['db_prefix']);
$sql_check = sprintf('SELECT * FROM '.$table_course.' WHERE visual_code = "%s"',Database :: escape_string($wanted_code)); $sql_check = sprintf('SELECT * FROM '.$table_course.' WHERE visual_code = "%s"',Database :: escape_string($wanted_code));
$result_check = Database::query($sql_check,__FILE__,__LINE__); //I don't know why this api function doesn't work... $result_check = Database::query($sql_check); //I don't know why this api function doesn't work... Ivan, 12-FEB-2010: What do you mean?
if ( Database::num_rows($result_check)<1 ) { if ( Database::num_rows($result_check)<1 ) {
if (sizeof($keys)) { if (sizeof($keys)) {
$visual_code = $keys["currentCourseCode"]; $visual_code = $keys["currentCourseCode"];

@ -500,7 +500,7 @@ if ($form->validate()) {
$ct .= ", comment='$new_comment'"; $ct .= ", comment='$new_comment'";
if ($new_title) if ($new_title)
$ct .= ", title='$new_title'"; $ct .= ", title='$new_title'";
Database::query("UPDATE $TABLE_DOCUMENT SET".substr($ct, 1)." WHERE id = '$document_id'", __FILE__, __LINE__); Database::query("UPDATE $TABLE_DOCUMENT SET".substr($ct, 1)." WHERE id = '$document_id'");
} }
$dir= substr($dir,0,-1); $dir= substr($dir,0,-1);
header('Location: document.php?curdirpath='.urlencode($dir)); header('Location: document.php?curdirpath='.urlencode($dir));

@ -56,7 +56,7 @@ function build_directory_selector($folders,$curdirpath,$group_dir='',$changeRend
$folder_sql = implode("','",$escaped_folders); $folder_sql = implode("','",$escaped_folders);
$doc_table = Database::get_course_table(TABLE_DOCUMENT); $doc_table = Database::get_course_table(TABLE_DOCUMENT);
$sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')"; $sql = "SELECT * FROM $doc_table WHERE filetype='folder' AND path IN ('".$folder_sql."')";
$res = Database::query($sql,__FILE__,__LINE__); $res = Database::query($sql);
$folder_titles = array(); $folder_titles = array();
while($obj = Database::fetch_object($res)) while($obj = Database::fetch_object($res))
{ {
@ -491,7 +491,7 @@ function get_titles_of_path($path)
else else
{ {
$sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE path LIKE BINARY "'.$tmp_path.'"'; $sql = 'SELECT title FROM '.Database::get_course_table(TABLE_DOCUMENT).' WHERE path LIKE BINARY "'.$tmp_path.'"';
$rs = Database::query($sql,__FILE__,__LINE__); $rs = Database::query($sql);
$tmp_title = '/'.Database::result($rs,0,0); $tmp_title = '/'.Database::result($rs,0,0);
$path_displayed .= $tmp_title; $path_displayed .= $tmp_title;
$tmp_folders_titles[$tmp_path] = $tmp_title; $tmp_folders_titles[$tmp_path] = $tmp_title;

@ -94,7 +94,7 @@ if(isset($_GET['id_session'])) {
// Check whether the tool is actually visible // Check whether the tool is actually visible
$table_course_tool = Database::get_course_table(TABLE_TOOL_LIST, $_course['dbName']); $table_course_tool = Database::get_course_table(TABLE_TOOL_LIST, $_course['dbName']);
$tool_sql = 'SELECT visibility FROM ' . $table_course_tool . ' WHERE name = "'. TOOL_DOCUMENT .'" LIMIT 1'; $tool_sql = 'SELECT visibility FROM ' . $table_course_tool . ' WHERE name = "'. TOOL_DOCUMENT .'" LIMIT 1';
$tool_result = Database::query($tool_sql,__FILE__,__LINE__); $tool_result = Database::query($tool_sql);
$tool_row = Database::fetch_array($tool_result); $tool_row = Database::fetch_array($tool_result);
$tool_visibility = $tool_row['visibility']; $tool_visibility = $tool_row['visibility'];
if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $group_member_with_upload_rights)) if ($tool_visibility == '0' && $to_group_id == '0' && !($is_allowed_to_edit || $group_member_with_upload_rights))

@ -80,7 +80,7 @@ if (is_allowed_to_edit())
$querypath=$path; $querypath=$path;
} }
//search for all files that are not deleted => visibility != 2 //search for all files that are not deleted => visibility != 2
$query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`<>'2' AND `props`.`to_group_id`=".$to_group_id."",__FILE__,__LINE__); $query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`<>'2' AND `props`.`to_group_id`=".$to_group_id."");
//add tem to the zip file //add tem to the zip file
while ($not_deleted_file = Database::fetch_assoc($query)) while ($not_deleted_file = Database::fetch_assoc($query))
{ {
@ -102,7 +102,7 @@ else
//big problem: visible files that are in a hidden folder are included when we do a query for visiblity='v'!!! //big problem: visible files that are in a hidden folder are included when we do a query for visiblity='v'!!!
//so... I do it in a couple of steps: //so... I do it in a couple of steps:
//1st: get all files that are visible in the given path //1st: get all files that are visible in the given path
$query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`='1' AND `docs`.`filetype`='file' AND `props`.`to_group_id`=".$to_group_id,__FILE__,__LINE__); $query = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`='1' AND `docs`.`filetype`='file' AND `props`.`to_group_id`=".$to_group_id);
//add them to an array //add them to an array
while ($all_visible_files = Database::fetch_assoc($query)) while ($all_visible_files = Database::fetch_assoc($query))
{ {
@ -113,7 +113,7 @@ else
//print_r($all_visible_files_path); //print_r($all_visible_files_path);
//echo('</pre>'); //echo('</pre>');
//2nd: get all folders that are invisible in the given path //2nd: get all folders that are invisible in the given path
$query2 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`<>'1' AND `docs`.`filetype`='folder'",__FILE__,__LINE__); $query2 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$querypath."/%' AND `props`.`visibility`<>'1' AND `docs`.`filetype`='folder'");
//if we get invisible folders, we have to filter out these results from all visible files we found //if we get invisible folders, we have to filter out these results from all visible files we found
if(Database::num_rows($query2)>0) if(Database::num_rows($query2)>0)
{ {
@ -122,7 +122,7 @@ else
{ {
//3rd: get all files that are in the found invisible folder (these are "invisible" too) //3rd: get all files that are in the found invisible folder (these are "invisible" too)
//echo "<br><br>invisible folders: ".$sys_course_path.$_course['path']."/document".$invisible_folders['path']."<br>"; //echo "<br><br>invisible folders: ".$sys_course_path.$_course['path']."/document".$invisible_folders['path']."<br>";
$query3 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$invisible_folders['path']."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`='1'",__FILE__,__LINE__); $query3 = Database::query("SELECT path FROM $doc_table AS docs,$prop_table AS props WHERE `props`.`tool`='".TOOL_DOCUMENT."' AND `docs`.`id`=`props`.`ref` AND `docs`.`path` LIKE '".$invisible_folders['path']."/%' AND `docs`.`filetype`='file' AND `props`.`visibility`='1'");
//add tem to an array //add tem to an array
while ($files_in_invisible_folder = Database::fetch_assoc($query3)) while ($files_in_invisible_folder = Database::fetch_assoc($query3))
{ {

@ -328,7 +328,7 @@ if (isset($_POST['newComment']))
$newComment = trim(Database::escape_string(Security::remove_XSS($_POST['newComment']))); // remove spaces $newComment = trim(Database::escape_string(Security::remove_XSS($_POST['newComment']))); // remove spaces
$newTitle = trim(Database::escape_string(Security::remove_XSS($_POST['newTitle']))); // remove spaces $newTitle = trim(Database::escape_string(Security::remove_XSS($_POST['newTitle']))); // remove spaces
// Check if there is already a record for this file in the DB // Check if there is already a record for this file in the DB
$result = Database::query ("SELECT * FROM $dbTable WHERE path LIKE BINARY '".$commentPath."'",__FILE__,__LINE__); $result = Database::query ("SELECT * FROM $dbTable WHERE path LIKE BINARY '".$commentPath."'");
while($row = Database::fetch_array($result, 'ASSOC')) while($row = Database::fetch_array($result, 'ASSOC'))
{ {
$attribute['path' ] = $row['path' ]; $attribute['path' ] = $row['path' ];
@ -340,7 +340,7 @@ if (isset($_POST['newComment']))
SET comment='".$newComment."', title='".$newTitle."' SET comment='".$newComment."', title='".$newTitle."'
WHERE path WHERE path
LIKE BINARY '".$commentPath."'"; LIKE BINARY '".$commentPath."'";
Database::query($query,__FILE__,__LINE__); Database::query($query);
$oldComment = $newComment; $oldComment = $newComment;
$oldTitle = $newTitle; $oldTitle = $newTitle;
$comments_updated = get_lang('ComMod'); $comments_updated = get_lang('ComMod');
@ -370,7 +370,7 @@ if (isset($_POST['renameTo']))
/** TODO check if this code is still used **/ /** TODO check if this code is still used **/
/* Search the old comment */ // RH: metadata: added 'id,' /* Search the old comment */ // RH: metadata: added 'id,'
$result = Database::query("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'",__FILE__,__LINE__); $result = Database::query("SELECT id,comment,title FROM $dbTable WHERE path LIKE BINARY '$dir$doc'");
$message = "<i>Debug info</i><br>directory = $dir<br>"; $message = "<i>Debug info</i><br>directory = $dir<br>";
$message .= "document = $file_name<br>"; $message .= "document = $file_name<br>";
@ -608,7 +608,7 @@ if( isset($info_message))
// readonly // readonly
$sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"'; $sql = 'SELECT id, readonly FROM '.$dbTable.' WHERE path LIKE BINARY "'.$dir.$doc.'"';
$rs = Database::query($sql, __FILE__, __LINE__); $rs = Database::query($sql);
$readonly = Database::result($rs,0,'readonly'); $readonly = Database::result($rs,0,'readonly');
$doc_id = Database::result($rs,0,'id'); $doc_id = Database::result($rs,0,'id');
@ -616,7 +616,7 @@ $doc_id = Database::result($rs,0,'id');
$sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).' $sql = 'SELECT insert_user_id FROM '.Database::get_course_table(TABLE_ITEM_PROPERTY).'
WHERE tool LIKE "document" WHERE tool LIKE "document"
AND ref='.intval($doc_id); AND ref='.intval($doc_id);
$rs = Database::query($sql, __FILE__, __LINE__); $rs = Database::query($sql);
$owner_id = Database::result($rs,0,'insert_user_id'); $owner_id = Database::result($rs,0,'insert_user_id');

@ -229,7 +229,7 @@ if ($slide_id !== "all") {
$pathpart=$path.'/'; $pathpart=$path.'/';
} }
$sql = "SELECT * FROM $tbl_documents WHERE path='".Database::escape_string($pathpart.$image_files_only[$slide])."'"; $sql = "SELECT * FROM $tbl_documents WHERE path='".Database::escape_string($pathpart.$image_files_only[$slide])."'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
echo '<table align="center" border="0" cellspacing="10">'; echo '<table align="center" border="0" cellspacing="10">';

@ -280,7 +280,7 @@ if(isset($_FILES['user_upload'])) {
if ($new_comment) $ct .= ", comment='$new_comment'"; if ($new_comment) $ct .= ", comment='$new_comment'";
if ($new_title) $ct .= ", title='$new_title'"; if ($new_title) $ct .= ", title='$new_title'";
Database::query("UPDATE $table_document SET" . substr($ct, 1) . Database::query("UPDATE $table_document SET" . substr($ct, 1) .
" WHERE id = '$docid'", __FILE__, __LINE__); " WHERE id = '$docid'");
} }
//showing message when sending zip files //showing message when sending zip files
if ($new_path === true && $_POST['unzip'] == 1) { if ($new_path === true && $_POST['unzip'] == 1) {
@ -289,7 +289,7 @@ if(isset($_FILES['user_upload'])) {
if ( (api_get_setting('search_enabled')=='true') && ($docid = DocumentManager::get_document_id($_course, $new_path))) { if ( (api_get_setting('search_enabled')=='true') && ($docid = DocumentManager::get_document_id($_course, $new_path))) {
$table_document = Database::get_course_table(TABLE_DOCUMENT); $table_document = Database::get_course_table(TABLE_DOCUMENT);
$result = Database::query("SELECT * FROM $table_document WHERE id = '$docid' LIMIT 1", __FILE__, __LINE__); $result = Database::query("SELECT * FROM $table_document WHERE id = '$docid' LIMIT 1");
if (Database::num_rows($result) == 1) { if (Database::num_rows($result) == 1) {
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$doc_path = api_get_path(SYS_COURSE_PATH) . $courseDir. $row['path']; $doc_path = api_get_path(SYS_COURSE_PATH) . $courseDir. $row['path'];
@ -357,7 +357,7 @@ if(isset($_FILES['user_upload'])) {
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1'; $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
$sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid); $sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid);
$res = Database::query($sql, __FILE__, __LINE__); $res = Database::query($sql);
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {
$se_ref = Database::fetch_array($res); $se_ref = Database::fetch_array($res);
@ -388,7 +388,7 @@ if(isset($_FILES['user_upload'])) {
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'UPDATE %s SET search_did=%d WHERE id=%d LIMIT 1'; $sql = 'UPDATE %s SET search_did=%d WHERE id=%d LIMIT 1';
$sql = sprintf($sql, $tbl_se_ref, (int)$did, (int)$se_ref['id']); $sql = sprintf($sql, $tbl_se_ref, (int)$did, (int)$se_ref['id']);
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
@ -420,7 +420,7 @@ if(isset($_FILES['user_upload'])) {
$sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did) $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
VALUES (NULL , \'%s\', \'%s\', %s, %s)'; VALUES (NULL , \'%s\', \'%s\', %s, %s)';
$sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid, $did); $sql = sprintf($sql, $tbl_se_ref, $courseid, TOOL_DOCUMENT, $docid, $did);
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
} }
} }
} }

@ -113,7 +113,7 @@ class Dropbox_Work {
$sql="SELECT id, upload_date $sql="SELECT id, upload_date
FROM ".$dropbox_cnf["tbl_file"]." FROM ".$dropbox_cnf["tbl_file"]."
WHERE filename = '".addslashes($this->filename)."'"; WHERE filename = '".addslashes($this->filename)."'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
$res = Database::fetch_array($result); $res = Database::fetch_array($result);
if ($res != FALSE) { if ($res != FALSE) {
$this->isOldWork = TRUE; $this->isOldWork = TRUE;
@ -129,7 +129,7 @@ class Dropbox_Work {
, author = '".addslashes($this->author)."' , author = '".addslashes($this->author)."'
, last_upload_date = '".addslashes($this->last_upload_date)."' , last_upload_date = '".addslashes($this->last_upload_date)."'
WHERE id='".addslashes($this->id)."'"; WHERE id='".addslashes($this->id)."'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
} else { } else {
$this->upload_date = $this->last_upload_date; $this->upload_date = $this->last_upload_date;
$sql="INSERT INTO ".$dropbox_cnf["tbl_file"]." $sql="INSERT INTO ".$dropbox_cnf["tbl_file"]."
@ -145,7 +145,7 @@ class Dropbox_Work {
, ".intval($_SESSION['id_session'])." , ".intval($_SESSION['id_session'])."
)"; )";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
$this->id = Database::insert_id(); //get automatically inserted id $this->id = Database::insert_id(); //get automatically inserted id
} }
@ -173,7 +173,7 @@ class Dropbox_Work {
$sql="SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id $sql="SELECT uploader_id, filename, filesize, title, description, author, upload_date, last_upload_date, cat_id
FROM ".$dropbox_cnf["tbl_file"]." FROM ".$dropbox_cnf["tbl_file"]."
WHERE id='".addslashes($id)."'"; WHERE id='".addslashes($id)."'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
$res = Database::fetch_array($result, 'ASSOC'); $res = Database::fetch_array($result, 'ASSOC');
// Check if uploader is still in Dokeos system // Check if uploader is still in Dokeos system
@ -203,7 +203,7 @@ class Dropbox_Work {
if ($_GET['action']=='viewfeedback' AND $this->id==$_GET['id']) { if ($_GET['action']=='viewfeedback' AND $this->id==$_GET['id']) {
$feedback2=array(); $feedback2=array();
$sql_feedback = "SELECT * FROM ".$dropbox_cnf["tbl_feedback"]." WHERE file_id='".$id."' ORDER BY feedback_id ASC"; $sql_feedback = "SELECT * FROM ".$dropbox_cnf["tbl_feedback"]." WHERE file_id='".$id."' ORDER BY feedback_id ASC";
$result = Database::query($sql_feedback, __FILE__, __LINE__); $result = Database::query($sql_feedback);
while ($row_feedback=Database::fetch_array($result)) { while ($row_feedback=Database::fetch_array($result)) {
$row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']); $row_feedback['feedback'] = Security::remove_XSS($row_feedback['feedback']);
$feedback2[]=$row_feedback; $feedback2[]=$row_feedback;
@ -214,7 +214,7 @@ class Dropbox_Work {
// RH: Feedback // RH: Feedback
$result = Database::query("SELECT feedback_date, feedback, cat_id FROM ". $result = Database::query("SELECT feedback_date, feedback, cat_id FROM ".
dropbox_cnf("tbl_post")." WHERE dest_user_id='".$_user['user_id']. dropbox_cnf("tbl_post")." WHERE dest_user_id='".$_user['user_id'].
"' AND file_id='".$id."'",__FILE__,__LINE__); "' AND file_id='".$id."'");
if ($res = Database::fetch_array($result)) if ($res = Database::fetch_array($result))
{ {
$this->feedback_date = $res["feedback_date"]; $this->feedback_date = $res["feedback_date"];
@ -334,7 +334,7 @@ class Dropbox_SentWork extends Dropbox_Work
$sql="SELECT dest_user_id, feedback_date, feedback $sql="SELECT dest_user_id, feedback_date, feedback
FROM ".$dropbox_cnf["tbl_post"]." FROM ".$dropbox_cnf["tbl_post"]."
WHERE file_id='".addslashes($id)."'"; WHERE file_id='".addslashes($id)."'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
while ($res = Database::fetch_array($result)) { while ($res = Database::fetch_array($result)) {
// check for deleted users // check for deleted users
$dest_user_id = $res["dest_user_id"]; $dest_user_id = $res["dest_user_id"];
@ -393,7 +393,7 @@ class Dropbox_Person
//if (intval($_SESSION['id_session']>0)) { $sql .= " AND r.session_id = ".intval($_SESSION['id_session']); } //if (intval($_SESSION['id_session']>0)) { $sql .= " AND r.session_id = ".intval($_SESSION['id_session']); }
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
while ($res = Database::fetch_array($result)) { while ($res = Database::fetch_array($result)) {
$temp = new Dropbox_Work($res["file_id"]); $temp = new Dropbox_Work($res["file_id"]);
$temp -> category = $res['cat_id']; $temp -> category = $res['cat_id'];
@ -409,7 +409,7 @@ class Dropbox_Person
//if(intval($_SESSION['id_session']>0)) { $sql .= " AND f.session_id = ".intval($_SESSION['id_session']); } //if(intval($_SESSION['id_session']>0)) { $sql .= " AND f.session_id = ".intval($_SESSION['id_session']); }
$result =Database::query($sql,__FILE__,__LINE__); $result =Database::query($sql);
while ($res = Database::fetch_array($result)) { while ($res = Database::fetch_array($result)) {
$this->sentWork[] = new Dropbox_SentWork($res["id"]); $this->sentWork[] = new Dropbox_SentWork($res["id"]);
} }
@ -518,7 +518,7 @@ class Dropbox_Person
global $dropbox_cnf; global $dropbox_cnf;
//delete entries in person table concerning received works //delete entries in person table concerning received works
foreach ($this->receivedWork as $w) { foreach ($this->receivedWork as $w) {
Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'",__FILE__,__LINE__); Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'");
} }
removeUnusedFiles(); //check for unused files removeUnusedFiles(); //check for unused files
@ -558,7 +558,7 @@ class Dropbox_Person
} }
} }
//delete entries in person table concerning received works //delete entries in person table concerning received works
Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__); Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$id."'");
removeUnusedFiles(); //check for unused files removeUnusedFiles(); //check for unused files
} }
@ -569,7 +569,7 @@ class Dropbox_Person
global $dropbox_cnf; global $dropbox_cnf;
//delete entries in person table concerning sent works //delete entries in person table concerning sent works
foreach ($this->sentWork as $w) { foreach ($this->sentWork as $w) {
Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'",__FILE__,__LINE__); Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$w->id."'");
removeMoreIfMailing($w->id); // RH: Mailing: see init1 removeMoreIfMailing($w->id); // RH: Mailing: see init1
} }
removeUnusedFiles(); //check for unused files removeUnusedFiles(); //check for unused files
@ -597,7 +597,7 @@ class Dropbox_Person
} }
//$file_id = $this->sentWork[$index]->id; // RH: Mailing //$file_id = $this->sentWork[$index]->id; // RH: Mailing
//delete entries in person table concerning sent works //delete entries in person table concerning sent works
Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__); Database::query("DELETE FROM ".$dropbox_cnf["tbl_person"]." WHERE user_id='".$this->userId."' AND file_id='".$id."'");
removeMoreIfMailing($id); // RH: Mailing: see init1 removeMoreIfMailing($id); // RH: Mailing: see init1
removeUnusedFiles(); //check for unused files removeUnusedFiles(); //check for unused files
} }
@ -630,7 +630,7 @@ class Dropbox_Person
Database::query("UPDATE ".$dropbox_cnf["tbl_post"]." SET feedback_date='". Database::query("UPDATE ".$dropbox_cnf["tbl_post"]." SET feedback_date='".
addslashes($feedback_date)."', feedback='".addslashes($text). addslashes($feedback_date)."', feedback='".addslashes($text).
"' WHERE dest_user_id='".$this->userId."' AND file_id='".$id."'",__FILE__,__LINE__); "' WHERE dest_user_id='".$this->userId."' AND file_id='".$id."'");
//update item_property (previously last_tooledit) table //update item_property (previously last_tooledit) table

@ -57,7 +57,7 @@ if ( isset($_GET['cat_id']) AND is_numeric($_GET['cat_id']) AND $_GET['action']=
AND post.file_id=file.id AND post.file_id=file.id
" ; " ;
} }
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
while ($row=Database::fetch_array($result)) while ($row=Database::fetch_array($result))
{ {
$files_to_download[]=$row['id']; $files_to_download[]=$row['id'];

@ -154,11 +154,11 @@ function delete_category($action, $id)
// step 1: delete the category // step 1: delete the category
$sql="DELETE FROM ".$dropbox_cnf['tbl_category']." WHERE cat_id='".Database::escape_string($id)."' AND $sentreceived='1'"; $sql="DELETE FROM ".$dropbox_cnf['tbl_category']." WHERE cat_id='".Database::escape_string($id)."' AND $sentreceived='1'";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
// step 2: delete all the documents in this category // step 2: delete all the documents in this category
$sql="SELECT * FROM ".$entries_table." WHERE cat_id='".Database::escape_string($id)."'"; $sql="SELECT * FROM ".$entries_table." WHERE cat_id='".Database::escape_string($id)."'";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
while ($row=Database::fetch_array($result)) while ($row=Database::fetch_array($result))
{ {
@ -244,7 +244,7 @@ function store_move($id, $target, $part)
WHERE dest_user_id='".Database::escape_string($_user['user_id'])."' WHERE dest_user_id='".Database::escape_string($_user['user_id'])."'
AND file_id='".Database::escape_string($id)."' AND file_id='".Database::escape_string($id)."'
"; ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$return_message=get_lang('ReceivedFileMoved'); $return_message=get_lang('ReceivedFileMoved');
} }
if ($part=='sent') if ($part=='sent')
@ -253,7 +253,7 @@ function store_move($id, $target, $part)
WHERE uploader_id='".Database::escape_string($_user['user_id'])."' WHERE uploader_id='".Database::escape_string($_user['user_id'])."'
AND id='".Database::escape_string($id)."' AND id='".Database::escape_string($id)."'
"; ";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
$return_message=get_lang('SentFileMoved'); $return_message=get_lang('SentFileMoved');
} }
} }
@ -343,7 +343,7 @@ function get_dropbox_categories($filter='')
$sql="SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE user_id='".$_user['user_id']."' $condition_session"; $sql="SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE user_id='".$_user['user_id']."' $condition_session";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
while ($row=Database::fetch_array($result)) while ($row=Database::fetch_array($result))
{ {
if(($filter=='sent' AND $row['sent']==1) OR ($filter=='received' AND $row['received']==1) OR $filter=='') if(($filter=='sent' AND $row['sent']==1) OR ($filter=='received' AND $row['received']==1) OR $filter=='')
@ -401,7 +401,7 @@ function store_addcategory()
$session_id = api_get_session_id(); $session_id = api_get_session_id();
// step 3a, we check if the category doesn't already exist // step 3a, we check if the category doesn't already exist
$sql="SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE user_id='".$_user['user_id']."' AND cat_name='".Database::escape_string(Security::remove_XSS($_POST['category_name']))."' AND received='".$received."' AND sent='$sent' AND session_id='$session_id'"; $sql="SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE user_id='".$_user['user_id']."' AND cat_name='".Database::escape_string(Security::remove_XSS($_POST['category_name']))."' AND received='".$received."' AND sent='$sent' AND session_id='$session_id'";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
// step 3b, we add the category if it does not exist yet. // step 3b, we add the category if it does not exist yet.
@ -409,7 +409,7 @@ function store_addcategory()
{ {
$sql="INSERT INTO ".$dropbox_cnf['tbl_category']." (cat_name, received, sent, user_id, session_id) $sql="INSERT INTO ".$dropbox_cnf['tbl_category']." (cat_name, received, sent, user_id, session_id)
VALUES ('".Database::escape_string(Security::remove_XSS($_POST['category_name']))."', '".Database::escape_string($received)."', '".Database::escape_string($sent)."', '".Database::escape_string($_user['user_id'])."',$session_id)"; VALUES ('".Database::escape_string(Security::remove_XSS($_POST['category_name']))."', '".Database::escape_string($received)."', '".Database::escape_string($sent)."', '".Database::escape_string($_user['user_id'])."',$session_id)";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
return array('type' => 'confirmation', 'message'=>get_lang('CategoryStored')); return array('type' => 'confirmation', 'message'=>get_lang('CategoryStored'));
} }
else else
@ -422,7 +422,7 @@ function store_addcategory()
$sql="UPDATE ".$dropbox_cnf['tbl_category']." SET cat_name='".Database::escape_string(Security::remove_XSS($_POST['category_name']))."', received='".Database::escape_string($received)."' , sent='".Database::escape_string($sent)."' $sql="UPDATE ".$dropbox_cnf['tbl_category']." SET cat_name='".Database::escape_string(Security::remove_XSS($_POST['category_name']))."', received='".Database::escape_string($received)."' , sent='".Database::escape_string($sent)."'
WHERE user_id='".Database::escape_string($_user['user_id'])."' WHERE user_id='".Database::escape_string($_user['user_id'])."'
AND cat_id='".Database::escape_string(Security::remove_XSS($_POST['edit_id']))."'"; AND cat_id='".Database::escape_string(Security::remove_XSS($_POST['edit_id']))."'";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
return array('type' => 'confirmation', 'message'=>get_lang('CategoryModified')); return array('type' => 'confirmation', 'message'=>get_lang('CategoryModified'));
} }
} }
@ -446,7 +446,7 @@ function display_addcategory_form($category_name='', $id='',$action)
{ {
// retrieve the category we are editing // retrieve the category we are editing
$sql="SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE cat_id='".Database::escape_string($id)."'"; $sql="SELECT * FROM ".$dropbox_cnf['tbl_category']." WHERE cat_id='".Database::escape_string($id)."'";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
$row=Database::fetch_array($result); $row=Database::fetch_array($result);
if ($category_name=='') // after an edit with an error we do not want to return to the original name but the name we already modified. (happens when createinrecievedfiles AND createinsentfiles are not checked) if ($category_name=='') // after an edit with an error we do not want to return to the original name but the name we already modified. (happens when createinrecievedfiles AND createinsentfiles are not checked)
@ -717,7 +717,7 @@ function getUserNameFromId ( $id) // RH: Mailing: return 'Mailing ' + id
$sql = "SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ', lastname)" : "CONCAT(lastname,' ', firstname)")." AS name $sql = "SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ', lastname)" : "CONCAT(lastname,' ', firstname)")." AS name
FROM " . $dropbox_cnf["tbl_user"] . " FROM " . $dropbox_cnf["tbl_user"] . "
WHERE user_id='$id'"; WHERE user_id='$id'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
$res = Database::fetch_array( $result); $res = Database::fetch_array( $result);
if ( $res == FALSE) return FALSE; if ( $res == FALSE) return FALSE;
@ -734,7 +734,7 @@ function getLoginFromId ( $id)
$sql = "SELECT username $sql = "SELECT username
FROM " . dropbox_cnf("tbl_user") . " FROM " . dropbox_cnf("tbl_user") . "
WHERE user_id='$id'"; WHERE user_id='$id'";
$result =Database::query($sql,__FILE__,__LINE__); $result =Database::query($sql);
$res = Database::fetch_array( $result); $res = Database::fetch_array( $result);
if ( $res == FALSE) return FALSE; if ( $res == FALSE) return FALSE;
return stripslashes( $res["username"]); return stripslashes( $res["username"]);
@ -764,14 +764,14 @@ function removeUnusedFiles( )
FROM " . dropbox_cnf("tbl_file") . " f FROM " . dropbox_cnf("tbl_file") . " f
LEFT JOIN " . dropbox_cnf("tbl_person") . " p ON f.id = p.file_id LEFT JOIN " . dropbox_cnf("tbl_person") . " p ON f.id = p.file_id
WHERE p.user_id IS NULL"; WHERE p.user_id IS NULL";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
while ( $res = Database::fetch_array( $result)) while ( $res = Database::fetch_array( $result))
{ {
//delete the selected files from the post and file tables //delete the selected files from the post and file tables
$sql = "DELETE FROM " . dropbox_cnf("tbl_post") . " WHERE file_id='" . $res['id'] . "'"; $sql = "DELETE FROM " . dropbox_cnf("tbl_post") . " WHERE file_id='" . $res['id'] . "'";
$result1 = Database::query($sql,__FILE__,__LINE__); $result1 = Database::query($sql);
$sql = "DELETE FROM " . dropbox_cnf("tbl_file") . " WHERE id='" . $res['id'] . "'"; $sql = "DELETE FROM " . dropbox_cnf("tbl_file") . " WHERE id='" . $res['id'] . "'";
$result1 = Database::query($sql,__FILE__,__LINE__); $result1 = Database::query($sql);
//delete file from server //delete file from server
@unlink( dropbox_cnf("sysPath") . "/" . $res["filename"]); @unlink( dropbox_cnf("sysPath") . "/" . $res["filename"]);
@ -799,7 +799,7 @@ function getUserOwningThisMailing($mailingPseudoId, $owner = 0, $or_die = '')
FROM " . $dropbox_cnf["tbl_file"] . " f FROM " . $dropbox_cnf["tbl_file"] . " f
LEFT JOIN " . $dropbox_cnf["tbl_post"] . " p ON f.id = p.file_id LEFT JOIN " . $dropbox_cnf["tbl_post"] . " p ON f.id = p.file_id
WHERE p.dest_user_id = '" . $mailingPseudoId . "'"; WHERE p.dest_user_id = '" . $mailingPseudoId . "'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
if (!($res = Database::fetch_array($result))) if (!($res = Database::fetch_array($result)))
die(dropbox_lang("generalError")." (code 901)"); die(dropbox_lang("generalError")." (code 901)");
@ -826,7 +826,7 @@ function removeMoreIfMailing($file_id)
$sql = "SELECT p.dest_user_id $sql = "SELECT p.dest_user_id
FROM " . $dropbox_cnf["tbl_post"] . " p FROM " . $dropbox_cnf["tbl_post"] . " p
WHERE p.file_id = '" . $file_id . "'"; WHERE p.file_id = '" . $file_id . "'";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
if ( $res = Database::fetch_array( $result)) if ( $res = Database::fetch_array( $result))
{ {
@ -834,11 +834,11 @@ function removeMoreIfMailing($file_id)
if ( $mailingPseudoId > dropbox_cnf("mailingIdBase")) if ( $mailingPseudoId > dropbox_cnf("mailingIdBase"))
{ {
$sql = "DELETE FROM " . dropbox_cnf("tbl_person") . " WHERE user_id='" . $mailingPseudoId . "'"; $sql = "DELETE FROM " . dropbox_cnf("tbl_person") . " WHERE user_id='" . $mailingPseudoId . "'";
$result1 = Database::query($sql,__FILE__,__LINE__); $result1 = Database::query($sql);
$sql = "UPDATE " . dropbox_cnf("tbl_file") . $sql = "UPDATE " . dropbox_cnf("tbl_file") .
" SET uploader_id='" . api_get_user_id() . "' WHERE uploader_id='" . $mailingPseudoId . "'"; " SET uploader_id='" . api_get_user_id() . "' WHERE uploader_id='" . $mailingPseudoId . "'";
$result1 = Database::query($sql,__FILE__,__LINE__); $result1 = Database::query($sql);
} }
} }
} }
@ -1083,7 +1083,7 @@ function display_user_link($user_id, $name='')
{ {
$table_user = Database::get_main_table(TABLE_MAIN_USER); $table_user = Database::get_main_table(TABLE_MAIN_USER);
$sql="SELECT * FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'"; $sql="SELECT * FROM $table_user WHERE user_id='".Database::escape_string($user_id)."'";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
$row=Database::fetch_array($result); $row=Database::fetch_array($result);
return "<a href=\"../user/userInfo.php?uInfo=".$row['user_id']."\">".api_get_person_name($row['firstname'], $row['lastname'])."</a>"; return "<a href=\"../user/userInfo.php?uInfo=".$row['user_id']."\">".api_get_person_name($row['firstname'], $row['lastname'])."</a>";
} }
@ -1151,7 +1151,7 @@ function feedback_form()
// we now check if the other users have not delete this document yet. If this is the case then it is useless to see the // we now check if the other users have not delete this document yet. If this is the case then it is useless to see the
// add feedback since the other users will never get to see the feedback. // add feedback since the other users will never get to see the feedback.
$sql="SELECT * FROM ".$dropbox_cnf["tbl_person"]." WHERE file_id='".Database::escape_string($_GET['id'])."'"; $sql="SELECT * FROM ".$dropbox_cnf["tbl_person"]." WHERE file_id='".Database::escape_string($_GET['id'])."'";
$result=Database::query($sql,__LINE__, __FILE__); $result=Database::query($sql);
$number_users_who_see_file=Database::num_rows($result); $number_users_who_see_file=Database::num_rows($result);
if ($number_users_who_see_file>1) if ($number_users_who_see_file>1)
{ {
@ -1192,7 +1192,7 @@ function store_feedback()
{ {
$sql="INSERT INTO ".$dropbox_cnf['tbl_feedback']." (file_id, author_user_id, feedback, feedback_date) VALUES $sql="INSERT INTO ".$dropbox_cnf['tbl_feedback']." (file_id, author_user_id, feedback, feedback_date) VALUES
('".Database::escape_string($_GET['id'])."','".Database::escape_string($_user['user_id'])."','".Database::escape_string($_POST['feedback'])."',NOW())"; ('".Database::escape_string($_GET['id'])."','".Database::escape_string($_user['user_id'])."','".Database::escape_string($_POST['feedback'])."',NOW())";
Database::query($sql,__FILE__,__LINE__); Database::query($sql);
return get_lang('DropboxFeedbackStored'); return get_lang('DropboxFeedbackStored');
} }
} }
@ -1238,7 +1238,7 @@ function zip_download ($array)
WHERE file.id IN (".implode(', ',$array).") WHERE file.id IN (".implode(', ',$array).")
AND file.id=person.file_id AND file.id=person.file_id
AND person.user_id='".$_user['user_id']."'"; AND person.user_id='".$_user['user_id']."'";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
while ($row=Database::fetch_array($result)) while ($row=Database::fetch_array($result))
{ {
$files[$row['filename']]=array('filename'=>$row['filename'],'title'=>$row['title'], 'author'=>$row['author'], 'description'=>$row['description']); $files[$row['filename']]=array('filename'=>$row['filename'],'title'=>$row['title'], 'author'=>$row['author'], 'description'=>$row['description']);
@ -1486,7 +1486,7 @@ function get_total_number_feedback($file_id='')
global $dropbox_cnf; global $dropbox_cnf;
$sql="SELECT COUNT(feedback_id) AS total, file_id FROM ".$dropbox_cnf['tbl_feedback']." GROUP BY file_id"; $sql="SELECT COUNT(feedback_id) AS total, file_id FROM ".$dropbox_cnf['tbl_feedback']." GROUP BY file_id";
$result=Database::query($sql, __FILE__, __LINE__); $result=Database::query($sql);
while ($row=Database::fetch_array($result)) while ($row=Database::fetch_array($result))
{ {
$return[$row['file_id']]=$row['total']; $return[$row['file_id']]=$row['total'];
@ -1553,7 +1553,7 @@ function get_last_tool_access($tool, $course_code='', $user_id='')
AND access_tool='".Database::escape_string($tool)."' AND access_tool='".Database::escape_string($tool)."'
ORDER BY access_date DESC ORDER BY access_date DESC
LIMIT 1"; LIMIT 1";
$result=Database::query($sql,__FILE__,__LINE__); $result=Database::query($sql);
$row=Database::fetch_array($result); $row=Database::fetch_array($result);
return $row['access_date']; return $row['access_date'];
} }

@ -1,7 +1,6 @@
<?php //$id: $ <?php //$id: $
/* For licensing terms, see /dokeos_license.txt */ /* For licensing terms, see /dokeos_license.txt */
/* /*
* ======================================== * ========================================
* PREVENT RESUBMITING * PREVENT RESUBMITING
@ -338,7 +337,7 @@ if ( isset( $_GET['mailingIndex'])) // examine or send
unset($students); unset($students);
} }
$result = Database::query($sel . $thisRecip . "'",__FILE__,__LINE__); $result = Database::query($sel . $thisRecip . "'");
while ( ($res = Database::fetch_array($result))) {$students[] = $res;} while ( ($res = Database::fetch_array($result))) {$students[] = $res;}
Database::free_result($result); Database::free_result($result);
@ -482,7 +481,7 @@ if ( isset( $_GET['mailingIndex'])) // examine or send
ON cu.user_id = u.user_id AND cu.course_code = '".$_course['sysCode']."' ON cu.user_id = u.user_id AND cu.course_code = '".$_course['sysCode']."'
WHERE cu.status = 5 WHERE cu.status = 5
AND u.user_id NOT IN ('" . implode("', '" , $students) . "')"; AND u.user_id NOT IN ('" . implode("', '" , $students) . "')";
$result = Database::query($sql,__FILE__,__LINE__); $result = Database::query($sql);
if ( Database::num_rows($result) > 0) if ( Database::num_rows($result) > 0)
{ {
@ -521,11 +520,11 @@ if ( isset( $_GET['mailingIndex'])) // examine or send
SET filesize = '0' SET filesize = '0'
, upload_date = '".$sendDT."', last_upload_date = '".$sendDT."' , upload_date = '".$sendDT."', last_upload_date = '".$sendDT."'
WHERE id='".addslashes($mailing_item->id)."'"; WHERE id='".addslashes($mailing_item->id)."'";
$result =Database::query($sql,__FILE__,__LINE__); $result =Database::query($sql);
} }
elseif ($mailing_item->filesize != 0) elseif ($mailing_item->filesize != 0)
{ {
$errormsg .= '<br>' . dropbox_lang("mailingNotYetSent") . '<br>'; $errormsg .= '<br />' . dropbox_lang("mailingNotYetSent") . '<br />';
} }
} }
} }

Loading…
Cancel
Save