Fixing SQL queries due the nes DB changes (singe database) see #3910

skala
Julio Montoya 14 years ago
parent 9f6cf9419a
commit c7b150b0e9
  1. 10
      main/newscorm/aicc.class.php
  2. 4
      main/newscorm/audiorecorder.inc.php
  3. 19
      main/newscorm/learnpath.class.php
  4. 193
      main/newscorm/learnpath_functions.inc.php
  5. 12
      main/newscorm/lp_build.php
  6. 1
      main/newscorm/lp_controller.php
  7. 12
      main/newscorm/lp_edit_item_prereq.php

@ -238,9 +238,11 @@ class aicc extends learnpath {
if (Database::num_rows($res) < 1) { error_log('New LP - Database for '.$course_code.' not found '.__FILE__.' '.__LINE__, 0); return -1; } if (Database::num_rows($res) < 1) { error_log('New LP - Database for '.$course_code.' not found '.__FILE__.' '.__LINE__, 0); return -1; }
$row = Database::fetch_array($res); $row = Database::fetch_array($res);
$course_id = api_get_course_int_id();
$new_lp = Database::get_course_table(TABLE_LP_MAIN); $new_lp = Database::get_course_table(TABLE_LP_MAIN);
$new_lp_item = Database::get_course_table(TABLE_LP_ITEM); $new_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$get_max = "SELECT MAX(display_order) FROM $new_lp"; $get_max = "SELECT MAX(display_order) FROM $new_lp WHERE c_id = $course_id";
$res_max = Database::query($get_max); $res_max = Database::query($get_max);
if (Database::num_rows($res_max) < 1) { if (Database::num_rows($res_max) < 1) {
$dsp = 1; $dsp = 1;
@ -253,7 +255,7 @@ class aicc extends learnpath {
$sql = "INSERT INTO $new_lp (c_id, lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib, content_maker,display_order)" . $sql = "INSERT INTO $new_lp (c_id, lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib, content_maker,display_order)" .
"VALUES " . "VALUES " .
"($this->course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."'," . "($course_id, 3, '".$this->course_title."', '".$this->course_id."','".$this->course_description."'," .
"'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."'," . "'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."'," .
"'aicc_api.php','".$this->course_creator."',$dsp)"; "'aicc_api.php','".$this->course_creator."',$dsp)";
if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '. $sql, 0); } if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '. $sql, 0); }
@ -286,7 +288,7 @@ class aicc extends learnpath {
//$previous = (!empty($this->au_order_list_new_id[x]) ? $this->au_order_list_new_id[x] : 0); // TODO: Deal with the previous. //$previous = (!empty($this->au_order_list_new_id[x]) ? $this->au_order_list_new_id[x] : 0); // TODO: Deal with the previous.
$sql_item = "INSERT INTO $new_lp_item (c_id, lp_id,item_type,ref,title, path,min_score,max_score, $field_add parent_item_id,previous_item_id,next_item_id, prerequisite,display_order) " . $sql_item = "INSERT INTO $new_lp_item (c_id, lp_id,item_type,ref,title, path,min_score,max_score, $field_add parent_item_id,previous_item_id,next_item_id, prerequisite,display_order) " .
"VALUES " . "VALUES " .
"($this->course_id, $lp_id, 'au','".$oAu->identifier."','".$title."'," . "($course_id, $lp_id, 'au','".$oAu->identifier."','".$title."'," .
"'$path',0,100, $value_add" . "'$path',0,100, $value_add" .
"$parent, $previous, 0, " . "$parent, $previous, 0, " .
"'$prereq', 0" . "'$prereq', 0" .
@ -296,7 +298,7 @@ class aicc extends learnpath {
$item_id = Database::insert_id(); $item_id = Database::insert_id();
// Now update previous item to change next_item_id. // Now update previous item to change next_item_id.
if ($previous != 0) { if ($previous != 0) {
$upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE id = $previous"; $upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE c_id = $course_id AND id = $previous";
$upd_res = Database::query($upd); $upd_res = Database::query($upd);
// Update the previous item id. // Update the previous item id.
} }

@ -26,6 +26,8 @@ function getFLVDuration($flv_path) {
} }
} }
$course_id = api_get_course_int_id();
if ($audio_recorder_studentview == 'false') { if ($audio_recorder_studentview == 'false') {
$width = 295; $width = 295;
$height= 90; $height= 90;
@ -41,7 +43,7 @@ if ($audio_recorder_studentview == 'false') {
$cp = api_get_course_path(); $cp = api_get_course_path();
$docs = Database::get_course_table(TABLE_DOCUMENT); $docs = Database::get_course_table(TABLE_DOCUMENT);
$select = "SELECT * FROM $docs " . $select = "SELECT * FROM $docs " .
" WHERE path like BINARY '/audio/lpi".Database::escape_string($audio_recorder_item_id)."-%' AND filetype='file' " . " WHERE c_id = $course_id AND path like BINARY '/audio/lpi".Database::escape_string($audio_recorder_item_id)."-%' AND filetype='file' " .
" ORDER BY path DESC"; " ORDER BY path DESC";
$res = Database::query($select); $res = Database::query($select);
if (Database::num_rows($res) > 0) { if (Database::num_rows($res) > 0) {

@ -7546,8 +7546,6 @@ class learnpath {
* @return string * @return string
*/ */
public function display_item_small_form($item_type, $title = '', $data) { public function display_item_small_form($item_type, $title = '', $data) {
global $charset;
$return = '<div class="lp_small_form">'; $return = '<div class="lp_small_form">';
$return .= '<p class="lp_title">' . $title . '</p>'; $return .= '<p class="lp_title">' . $title . '</p>';
$return .= '<form method="post">'; $return .= '<form method="post">';
@ -7578,11 +7576,11 @@ class learnpath {
* @return string HTML form * @return string HTML form
*/ */
public function display_item_prerequisites_form($item_id) { public function display_item_prerequisites_form($item_id) {
global $charset; $course_id = api_get_course_int_id();
$tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM); $tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
$item_id = intval($item_id); $item_id = intval($item_id);
/* Current prerequisite */ /* Current prerequisite */
$sql = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = " . $item_id; $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND id = " . $item_id;
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
@ -7611,7 +7609,7 @@ class learnpath {
$return .= '<label for="idNone">' . get_lang('None') . '</label>'; $return .= '<label for="idNone">' . get_lang('None') . '</label>';
$return .= '</tr>'; $return .= '</tr>';
$sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id; $sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = $course_id AND lp_id = " . $this->lp_id;
$result = Database::query($sql); $result = Database::query($sql);
$arrLP = array (); $arrLP = array ();
while ($row = Database :: fetch_array($result)) { while ($row = Database :: fetch_array($result)) {
@ -7695,19 +7693,18 @@ class learnpath {
* @return string HTML form * @return string HTML form
*/ */
public function display_lp_prerequisites_list() { public function display_lp_prerequisites_list() {
global $charset;
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$lp_id = $this->lp_id; $lp_id = $this->lp_id;
$tbl_lp = Database :: get_course_table(TABLE_LP_MAIN); $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
// get current prerequisite // get current prerequisite
$sql = "SELECT * FROM $tbl_lp WHERE c_id = ".$course_id." AND id = $lp_id "; $sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $lp_id ";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database :: fetch_array($result); $row = Database :: fetch_array($result);
$preq_id = $row['prerequisite']; $preq_id = $row['prerequisite'];
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$session_condition = api_get_session_condition($session_id, false); $session_condition = api_get_session_condition($session_id);
$sql = "SELECT * FROM $tbl_lp $session_condition ORDER BY display_order "; echo $sql = "SELECT * FROM $tbl_lp WHERE c_id = $course_id $session_condition ORDER BY display_order ";
$rs = Database::query($sql); $rs = Database::query($sql);
$return = ''; $return = '';
$return .= '<select name="prerequisites" >'; $return .= '<select name="prerequisites" >';
@ -7750,8 +7747,8 @@ class learnpath {
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id); $condition_session = api_get_session_condition($session_id);
$sql_quiz = "SELECT * FROM $tbl_quiz WHERE c_id = ".$course_id." AND active<>'-1' $condition_session ORDER BY title ASC"; $sql_quiz = "SELECT * FROM $tbl_quiz WHERE c_id = $course_id AND active<>'-1' $condition_session ORDER BY title ASC";
$sql_hot = "SELECT * FROM $tbl_doc WHERE c_id = ".$course_id." AND path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC"; $sql_hot = "SELECT * FROM $tbl_doc WHERE c_id = $course_id AND path LIKE '" . $uploadPath . "/%/%htm%' $condition_session ORDER BY id ASC";
$res_quiz = Database::query($sql_quiz); $res_quiz = Database::query($sql_quiz);
$res_hot = Database::query($sql_hot); $res_hot = Database::query($sql_hot);

@ -30,10 +30,13 @@
* @return boolean True if item was deleted, false if not found or error * @return boolean True if item was deleted, false if not found or error
*/ */
function deleteitem($id) { function deleteitem($id) {
$course_id = api_get_course_int_id();
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
// Get the display order for this item before it is deleted. // Get the display order for this item before it is deleted.
$sql = "SELECT display_order, parent_item_id FROM $tbl_lp_item WHERE id=$id"; $sql = "SELECT display_order, parent_item_id FROM $tbl_lp_item WHERE c_id = $course_id AND id=$id";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) == 0) { if (Database::num_rows($result) == 0) {
return false; return false;
@ -42,15 +45,15 @@ function deleteitem($id) {
$display_order = $row[0]; $display_order = $row[0];
$parent_item_id = $row[1]; $parent_item_id = $row[1];
// Delete the item. // Delete the item.
$sql = "DELETE FROM $tbl_learnpath_item WHERE id='$id'"; $sql = "DELETE FROM $tbl_learnpath_item WHERE c_id = $course_id AND id='$id'";
$result = Database::query($sql); $result = Database::query($sql);
if ($result === false) { if ($result === false) {
return false; return false;
} }
// Update the other items and chapters. // Update the other items and chapters.
$sql = "UPDATE $tbl_learnpath_item SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_item_id"; $sql = "UPDATE $tbl_learnpath_item SET display_order = display_order-1 WHERE c_id = $course_id AND display_order > $display_order AND parent_item_id = $parent_item_id";
$result = Database::query($sql); $result = Database::query($sql);
$sql = "UPDATE $tbl_learnpath_chapter SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_item_id"; $sql = "UPDATE $tbl_learnpath_chapter SET display_order = display_order-1 WHERE c_id = $course_id AND display_order > $display_order AND parent_item_id = $parent_item_id";
$result = Database::query($sql); $result = Database::query($sql);
return true; return true;
@ -64,11 +67,12 @@ function deleteitem($id) {
*/ */
function deletemodule($parent_item_id) { function deletemodule($parent_item_id) {
global $learnpath_id; global $learnpath_id;
$course_id = api_get_course_int_id();
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
// Added for multi-level behaviour - slightly recursive. // Added for multi-level behaviour - slightly recursive.
$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$learnpath_id"; $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND lp_id=$learnpath_id";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
if ($row['parent_item_id'] == $parent_item_id) { if ($row['parent_item_id'] == $parent_item_id) {
@ -81,7 +85,7 @@ function deletemodule($parent_item_id) {
// Get this chapter's display order. // Get this chapter's display order.
$sql = "SELECT display_order, parent_item_id FROM $tbl_learnpath_chapter $sql = "SELECT display_order, parent_item_id FROM $tbl_learnpath_chapter
WHERE id=$parent_item_id and lp_id=$learnpath_id"; WHERE c_id = $course_id AND id=$parent_item_id and lp_id=$learnpath_id";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) == 0) { if (Database::num_rows($result) == 0) {
return false; return false;
@ -92,16 +96,16 @@ function deletemodule($parent_item_id) {
$parent_id = $row[1]; $parent_id = $row[1];
// Delete the chapter itself. // Delete the chapter itself.
$sql = "DELETE FROM $tbl_learnpath_chapter WHERE (id=$parent_item_id and lp_id=$learnpath_id)"; $sql = "DELETE FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND (id=$parent_item_id and lp_id=$learnpath_id)";
$result = Database::query($sql); $result = Database::query($sql);
// Delete items from that chapter. // Delete items from that chapter.
$sql2 = "DELETE FROM $tbl_learnpath_item WHERE parent_item_id=$parent_item_id"; $sql2 = "DELETE FROM $tbl_learnpath_item WHERE c_id = $course_id AND parent_item_id=$parent_item_id";
$result = Database::query($sql2); $result = Database::query($sql2);
// Update all other chapters accordingly. // Update all other chapters accordingly.
$sql = "UPDATE $tbl_learnpath_item SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_id"; $sql = "UPDATE $tbl_learnpath_item SET display_order = display_order-1 WHERE c_id = $course_id AND display_order > $display_order AND parent_item_id = $parent_id";
$result = Database::query($sql); $result = Database::query($sql);
$sql = "UPDATE $tbl_learnpath_chapter SET display_order = display_order-1 WHERE display_order > $display_order AND parent_item_id = $parent_id"; $sql = "UPDATE $tbl_learnpath_chapter SET display_order = display_order-1 WHERE c_id = $course_id AND display_order > $display_order AND parent_item_id = $parent_id";
$result = Database::query($sql); $result = Database::query($sql);
return true; return true;
@ -118,12 +122,14 @@ function deletepath($path_id) {
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$sql = "DELETE FROM $tbl_learnpath_main WHERE lp_id='$path_id'"; $course_id = api_get_course_int_id();
$sql = "DELETE FROM $tbl_learnpath_main WHERE c_id = $course_id AND lp_id='$path_id'";
$result = Database::query($sql); $result = Database::query($sql);
//@TODO check how this function is used before uncommenting the following //@TODO check how this function is used before uncommenting the following
//also delete all elements inside that path //also delete all elements inside that path
$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id = $path_id"; $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND lp_id = $path_id";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
deletemodule($row['id']); deletemodule($row['id']);
@ -141,6 +147,8 @@ function deletepath($path_id) {
*/ */
function moveitem($direction, $id, $moduleid, $type = 'item') { function moveitem($direction, $id, $moduleid, $type = 'item') {
global $learnpath_id; global $learnpath_id;
$course_id = api_get_course_int_id();
$tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER);
@ -182,17 +190,17 @@ function moveitem($direction, $id, $moduleid, $type = 'item') {
$sql1 = ''; $sql1 = '';
$sql2 = ''; $sql2 = '';
if ($orig_type == 'chapter') { if ($orig_type == 'chapter') {
$sql1 = "UPDATE $tbl_learnpath_chapter SET display_order = ".$dest_order." WHERE (id=$orig_id and parent_item_id=$moduleid)"; $sql1 = "UPDATE $tbl_learnpath_chapter SET display_order = ".$dest_order." WHERE c_id = $course_id AND (id=$orig_id and parent_item_id=$moduleid)";
} elseif ($orig_type == 'item') { } elseif ($orig_type == 'item') {
$sql1 = "UPDATE $tbl_learnpath_item SET display_order = ".$dest_order." WHERE (id=$orig_id and parent_item_id=$moduleid)"; $sql1 = "UPDATE $tbl_learnpath_item SET display_order = ".$dest_order." WHERE c_id = $course_id AND (id=$orig_id and parent_item_id=$moduleid)";
} else { } else {
return false; return false;
} }
if ($dest_type == 'chapter') { if ($dest_type == 'chapter') {
$sql2 = "UPDATE $tbl_learnpath_chapter SET display_order = ".$orig_order." WHERE (id='$dest_id' and parent_item_id=$moduleid)"; $sql2 = "UPDATE $tbl_learnpath_chapter SET display_order = ".$orig_order." WHERE c_id = $course_id AND (id='$dest_id' and parent_item_id=$moduleid)";
} elseif ($dest_type == 'item') { } elseif ($dest_type == 'item') {
$sql2 = "UPDATE $tbl_learnpath_item SET display_order = ".$orig_order." WHERE (id='$dest_id' and parent_item_id=$moduleid)"; $sql2 = "UPDATE $tbl_learnpath_item SET display_order = ".$orig_order." WHERE c_id = $course_id AND (id='$dest_id' and parent_item_id=$moduleid)";
} else { } else {
return false; return false;
} }
@ -209,7 +217,9 @@ function moveitem($direction, $id, $moduleid, $type = 'item') {
*/ */
function movemodule($direction, $id) { function movemodule($direction, $id) {
global $learnpath_id; global $learnpath_id;
$tbl_learnpath_chapter = Database :: get_course_learnpath_chapter_table(); $course_id = api_get_course_int_id();
$tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER);
if ($direction == 'up') { if ($direction == 'up') {
$sortDirection = 'DESC'; $sortDirection = 'DESC';
} else { } else {
@ -217,7 +227,7 @@ function movemodule($direction, $id) {
} }
// Select all chapters of first level (parent_item_id = 0). // Select all chapters of first level (parent_item_id = 0).
$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id AND parent_item_id = 0) ORDER BY display_order $sortDirection"; $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND (lp_id=$learnpath_id AND parent_item_id = 0) ORDER BY display_order $sortDirection";
$result = Database::query($sql); $result = Database::query($sql);
$previousrow = ''; $previousrow = '';
@ -230,8 +240,8 @@ function movemodule($direction, $id) {
$next_cat_order = $row['display_order']; $next_cat_order = $row['display_order'];
$next_cat_id = $row['id']; $next_cat_id = $row['id'];
$sql1 = "UPDATE $tbl_learnpath_chapter SET display_order = '$next_cat_order' WHERE (id='$this_cat_id' and lp_id=$learnpath_id)"; $sql1 = "UPDATE $tbl_learnpath_chapter SET display_order = '$next_cat_order' WHERE c_id = $course_id AND (id='$this_cat_id' and lp_id=$learnpath_id)";
$sql2 = "UPDATE $tbl_learnpath_chapter SET display_order = '$this_cat_order' WHERE (id='$next_cat_id' and lp_id=$learnpath_id)"; $sql2 = "UPDATE $tbl_learnpath_chapter SET display_order = '$this_cat_order' WHERE c_id = $course_id AND (id='$next_cat_id' and lp_id=$learnpath_id)";
Database::query($sql1); Database::query($sql1);
Database::query($sql2); Database::query($sql2);
unset ($this_cat_order); unset ($this_cat_order);
@ -264,9 +274,11 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$course_id = api_get_course_int_id();
// Getting the last order number from the chapters table, in this learnpath, for the parent chapter given. // Getting the last order number from the chapters table, in this learnpath, for the parent chapter given.
$sql = "SELECT * FROM $tbl_learnpath_chapter $sql = "SELECT * FROM $tbl_learnpath_chapter
WHERE lp_id=$learnpath_id AND parent_item_id = $parent_id WHERE c_id = $course_id AND lp_id=$learnpath_id AND parent_item_id = $parent_id
ORDER BY display_order DESC"; ORDER BY display_order DESC";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
@ -274,13 +286,13 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
// Getting the last order number of the items. // Getting the last order number of the items.
$sql = "SELECT * FROM $tbl_learnpath_item $sql = "SELECT * FROM $tbl_learnpath_item
WHERE parent_item_id = $parent_id WHERE c_id = $course_id AND parent_item_id = $parent_id
ORDER BY display_order DESC"; ORDER BY display_order DESC";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$last_item_order = $row['display_order']; $last_item_order = $row['display_order'];
$new_order = max($last_chapter_order, $last_item_order) + 1; $new_order = max($last_chapter_order, $last_item_order) + 1;
$course_id = api_get_course_int_id();
if ($type === 'chapter') { if ($type === 'chapter') {
$sql = "INSERT INTO $tbl_learnpath_chapter (c_id, lp_id, chapter_name, chapter_description, display_order) $sql = "INSERT INTO $tbl_learnpath_chapter (c_id, lp_id, chapter_name, chapter_description, display_order)
VALUES ( $course_id, VALUES ( $course_id,
@ -310,11 +322,11 @@ function insert_item($type = 'item', $name, $chapter_description = '', $parent_i
* @return array List of learnpath chapter titles * @return array List of learnpath chapter titles
*/ */
function array_learnpath_categories() { function array_learnpath_categories() {
//global $tbl_learnpath_chapter; $course_id = api_get_course_int_id();
global $learnpath_id; global $learnpath_id;
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id) ORDER BY display_order ASC"; $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND (lp_id=$learnpath_id) ORDER BY display_order ASC";
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
@ -368,7 +380,7 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve
// do not diplay useless information // do not diplay useless information
//echo "<tr><td>&nbsp;$lang_nochapters</td></tr>"; //echo "<tr><td>&nbsp;$lang_nochapters</td></tr>";
} else { } else {
echo " <tr align='center' valign='top'>\n"." <td><b>&nbsp;$lang_title_and_desc </b></td>\n"." <td><b>&nbsp;$lang_add_item </b></td>\n"; echo " <tr align='center' valign='top'><td><b>&nbsp;$lang_title_and_desc </b></td>\n"." <td><b>&nbsp;$lang_add_item </b></td>\n";
if (is_prereq($learnpath_id)) { if (is_prereq($learnpath_id)) {
echo " <td bgcolor='#ddddee'><b>&nbsp;$lang_prerequisites_limit </b></td>\n"; echo " <td bgcolor='#ddddee'><b>&nbsp;$lang_prerequisites_limit </b></td>\n";
} else { } else {
@ -527,50 +539,6 @@ function display_learnpath_chapters($parent_item_id = 0, $tree = array (), $leve
} }
} }
/**
* Displays all learning paths.
* @return void
* @todo eliminate all global $lang declarations, use get_lang, improve structure.
*/
function display_all_learnpath() {
global $tbl_tool, $color2;
global $xml_output, $lang_edit_learnpath, $lang_delete_learnpath, $lang_publish, $lang_no_publish, $lang_add_learnpath_chapter_to_path;
$tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN);
$sql = "SELECT * FROM $tbl_learnpath_main ORDER BY learnpath_name";
$result = Database::query($sql);
$i = 1;
$num_modules = Database::num_rows($result);
while ($row = Database::fetch_array($result)) {
// Other grey color : #E6E6E6
echo "<tr><td bgcolor=\"$color2\" width=400><b>&nbsp;";
echo "<a href='learnpath_handler.php?&lp_id={$row['lp_id']}'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9>{$row['learnpath_name']}</a>";
echo "</b><br /><i><div class=text align=justify>{$row['learnpath_description']}</div></i></td>";
// Showing the edit, delete and publish icons.
if (api_is_allowed_to_edit()) {
echo "<td bgcolor=\"$color2\" align=center><a href='learnpath_handler.php?lp_id={$row['lp_id']}&action=add&type=learnpathcategory'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9><img src='../img/0.gif' width='13' height='13' border='0' title='$lang_add_learnpath_chapter_to_path'></a></td>";
echo "<td bgcolor=\"$color2\" align=center><a href='".api_get_self()."?action=editpath&id=".$row['lp_id']."'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9><img src=\"../img/edit.gif\" border=\"0\" title=\"$lang_edit_learnpath\"></a></td>";
echo "<td bgcolor=\"$color2\" align=center><a href='".api_get_self()."?action=deletepath&id=".$row['lp_id']."'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9><img src=\"../img/delete.gif\" border=\"0\" title=\"$lang_delete_learnpath\" onclick=\"javascript: return confirmation('".$row['learnpath_name']."');\"></a></td>";
$id = $row['lp_id'];
$sql2 = "SELECT * FROM $tbl_learnpath_main WHERE lp_id=$id";
$result2 = Database::query($sql2);
$row2 = Database::fetch_array($result2);
$name = $row2['learnpath_name'];
$sql3 = "SELECT * FROM $tbl_tool WHERE (name=\"$name\" AND image='scormbuilder.gif')";
$result3 = Database::query($sql3);
$row3 = Database::fetch_array($result3);
if (($row3['visibility']) == '1') {
echo "<td bgcolor=\"$color2\" align=center><a href='".api_get_self()."?action=publishpath&set=i&id=".$row['lp_id']."'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9><img src=\"../img/visible.gif\" border=\"0\" title=\"$lang_no_publish\"></a></td>";
} else {
echo "<td bgcolor=\"$color2\" align=center><a href='".api_get_self()."?action=publishpath&set=v&id=".$row['lp_id']."'&SQMSESSID=36812c2dea7d8d6e708d5e6a2f09b0b9><img src=\"../img/invisible.gif\" border=\"0\" title=\"$lang_publish\"></a></td>";
}
}
$i ++;
echo "<tr><td>&nbsp;</td></tr>";
}
}
/** /**
* Displays the learning path items/steps. * Displays the learning path items/steps.
@ -581,9 +549,10 @@ function display_all_learnpath() {
function display_learnpath_items($categoryid) { function display_learnpath_items($categoryid) {
global $xml_output; global $xml_output;
global $lang_prerequisites, $lang_move_down, $lang_move_up, $lang_edit_learnpath_item, $lang_delete_learnpath_item, $learnpath_id, $lang_add_prereq, $lang_prereq_deleted_error, $lang_pre_short, $langThisItem; global $lang_prerequisites, $lang_move_down, $lang_move_up, $lang_edit_learnpath_item, $lang_delete_learnpath_item, $learnpath_id, $lang_add_prereq, $lang_prereq_deleted_error, $lang_pre_short, $langThisItem;
$course_id = api_get_course_int_id();
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$sql_items = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$categoryid' ORDER BY display_order ASC"; $sql_items = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND parent_item_id='$categoryid' ORDER BY display_order ASC";
$result_items = Database::query($sql_items); $result_items = Database::query($sql_items);
$number_items = Database::num_rows($result_items); $number_items = Database::num_rows($result_items);
$i = 1; $i = 1;
@ -610,7 +579,7 @@ function display_learnpath_items($categoryid) {
//if ($row_items['prereq_type'] == 'i') { //if ($row_items['prereq_type'] == 'i') {
// item // item
$sql_items2 = "SELECT * FROM $tbl_lp_item WHERE id='$prereq'"; // Check if prereq has been deleted. $sql_items2 = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND id='$prereq'"; // Check if prereq has been deleted.
$result_items2 = Database::query($sql_items2); $result_items2 = Database::query($sql_items2);
$number_items2 = Database::num_rows($result_items2); $number_items2 = Database::num_rows($result_items2);
if ($number_items2 == 0) { if ($number_items2 == 0) {
@ -675,13 +644,15 @@ function display_learnpath_items($categoryid) {
function learnpath_items($itemid) { function learnpath_items($itemid) {
global $xml_output; global $xml_output;
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$course_id = api_get_course_int_id();
$sql_items = "SELECT parent_item_id FROM $tbl_lp_item WHERE id='$itemid'"; $sql_items = "SELECT parent_item_id FROM $tbl_lp_item WHERE c_id = $course_id AND id='$itemid'";
$moduleid_sql = Database::query($sql_items); $moduleid_sql = Database::query($sql_items);
$moduleid_array = Database::fetch_array($moduleid_sql); // First row of the results. $moduleid_array = Database::fetch_array($moduleid_sql); // First row of the results.
$moduleid = $moduleid_array['parent_item_id']; $moduleid = $moduleid_array['parent_item_id'];
$sql_items = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$moduleid' ORDER BY display_order ASC"; $sql_items = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND parent_item_id='$moduleid' ORDER BY display_order ASC";
$result_items = Database::query($sql_items); $result_items = Database::query($sql_items);
$ar = Database::fetch_array($result_items); $ar = Database::fetch_array($result_items);
while ($ar != '') { while ($ar != '') {
@ -698,10 +669,11 @@ function learnpath_items($itemid) {
*/ */
function learnpath_chapters($learnpath_id) { function learnpath_chapters($learnpath_id) {
global $xml_output, $learnpath_id; global $xml_output, $learnpath_id;
//$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$course_id = api_get_course_int_id();
$sql_items = "SELECT * FROM $tbl_lp_item WHERE lp_id='$learnpath_id' AND item_type='dokeos_chapter' ORDER BY display_order ASC";
$sql_items = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id='$learnpath_id' AND item_type='dokeos_chapter' ORDER BY display_order ASC";
//$sql_items = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id='$learnpath_id' ORDER BY display_order ASC"; //$sql_items = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id='$learnpath_id' ORDER BY display_order ASC";
$result_items = Database::query($sql_items); $result_items = Database::query($sql_items);
$ar = Database::fetch_array($result_items); $ar = Database::fetch_array($result_items);
@ -720,10 +692,11 @@ function learnpath_chapters($learnpath_id) {
function is_prereq($learnpath_id) { function is_prereq($learnpath_id) {
global $xml_output; global $xml_output;
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$course_id = api_get_course_int_id();
$prereq = false; $prereq = false;
$sql_items = "SELECT * FROM $tbl_lp_item WHERE lp_id='$learnpath_id' AND parent_item_id=0 ORDER BY display_order ASC"; $sql_items = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id='$learnpath_id' AND parent_item_id=0 ORDER BY display_order ASC";
$result_items = Database::query($sql_items); $result_items = Database::query($sql_items);
while ($ar = Database::fetch_array($result_items)) { while ($ar = Database::fetch_array($result_items)) {
$c = $ar['id']; $c = $ar['id'];
@ -751,11 +724,13 @@ function prereqcheck($id_in_path) {
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$course_id = api_get_course_int_id();
// 2. Initialise return value. // 2. Initialise return value.
$prereq = false; $prereq = false;
// 3. Get item data from the database. // 3. Get item data from the database.
$sql_items = "SELECT * FROM $tbl_learnpath_item WHERE id='$id_in_path'"; $sql_items = "SELECT * FROM $tbl_learnpath_item WHERE c_id = $course_id AND id='$id_in_path'";
$result_items = Database::query($sql_items); $result_items = Database::query($sql_items);
$row = Database::fetch_array($result_items); $row = Database::fetch_array($result_items);
// 4. Check prerequisite's type. // 4. Check prerequisite's type.
@ -771,7 +746,7 @@ function prereqcheck($id_in_path) {
} else { } else {
$user_id = $_user['user_id']; $user_id = $_user['user_id'];
} }
$sql_items3 = "SELECT * FROM $tbl_learnpath_user WHERE (learnpath_item_id='$id_in_path3' and user_id=$user_id)"; $sql_items3 = "SELECT * FROM $tbl_learnpath_user WHERE c_id = $course_id AND (learnpath_item_id='$id_in_path3' and user_id=$user_id)";
$result_items3 = Database::query($sql_items3); $result_items3 = Database::query($sql_items3);
$row3 = Database::fetch_array($result_items3); $row3 = Database::fetch_array($result_items3);
@ -814,7 +789,7 @@ function prereqcheck($id_in_path) {
// 4.b.1 Get data ready to use. // 4.b.1 Get data ready to use.
$id_in_path2 = $row['prereq_id']; $id_in_path2 = $row['prereq_id'];
// 4.b.2 Get all items in the prerequisite chapter. // 4.b.2 Get all items in the prerequisite chapter.
$sql_items3 = "SELECT * FROM $tbl_lp_item WHERE parent_item_id='$id_in_path2'"; $sql_items3 = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND parent_item_id='$id_in_path2'";
$result_items3 = Database::query($sql_items3); $result_items3 = Database::query($sql_items3);
$allcompleted = true; $allcompleted = true;
while ($row3 = Database::fetch_array($result_items3)) { while ($row3 = Database::fetch_array($result_items3)) {
@ -827,7 +802,7 @@ function prereqcheck($id_in_path) {
$user_id = $_user['user_id']; $user_id = $_user['user_id'];
} }
// 4.b.3.2 Get user-item relation. // 4.b.3.2 Get user-item relation.
$sql_items4 = "SELECT * FROM $tbl_learnpath_user WHERE (learnpath_item_id='$id_in_path4' and user_id=$user_id)"; $sql_items4 = "SELECT * FROM $tbl_learnpath_user WHERE c_id = $course_id AND (learnpath_item_id='$id_in_path4' and user_id=$user_id)";
$result_items4 = Database::query($sql_items4); $result_items4 = Database::query($sql_items4);
$row4 = Database::fetch_array($result_items4); $row4 = Database::fetch_array($result_items4);
// 4.b.3.3 If any of these elements is not 'completed', the overall completion status is false. // 4.b.3.3 If any of these elements is not 'completed', the overall completion status is false.
@ -840,7 +815,7 @@ function prereqcheck($id_in_path) {
$prereq = false; $prereq = false;
} else { } else {
// 4.b.4.b Something was not completed. Return corresponding message. // 4.b.4.b Something was not completed. Return corresponding message.
$sql5 = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id='$learnpath_id' and id='$id_in_path2')"; $sql5 = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND (lp_id='$learnpath_id' and id='$id_in_path2')";
$result5 = Database::query($sql5); $result5 = Database::query($sql5);
$row5 = Database::fetch_array($result5); $row5 = Database::fetch_array($result5);
$prereqmodulename = trim($row5['chapter_name']); $prereqmodulename = trim($row5['chapter_name']);
@ -874,12 +849,10 @@ function get_learnpath_tree($learnpath_id) {
$tree = array(); $tree = array();
$chapters = array(); $chapters = array();
//$chapters = array();
//$chapters_by_parent = array();
//$items = array();
//$items_by_chapter = array();
$all_items_by_chapter = array(); $all_items_by_chapter = array();
$sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = ".$learnpath_id." AND item_type='dokeos_chapter' ORDER BY display_order"; $course_id = api_get_course_int_id();
$sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = ".$learnpath_id." AND item_type='dokeos_chapter' ORDER BY display_order";
//error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql,0); //error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql,0);
$res = Database::query($sql); $res = Database::query($sql);
// Format the $chapters_by_parent array so we have a suitable structure to work with. // Format the $chapters_by_parent array so we have a suitable structure to work with.
@ -897,7 +870,7 @@ function get_learnpath_tree($learnpath_id) {
// Now for every item in each chapter, get a suitable structure too. // Now for every item in each chapter, get a suitable structure too.
foreach ($chapters as $row) { foreach ($chapters as $row) {
// Select items from this chapter. // Select items from this chapter.
$sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $learnpath_id AND parent_item_id = ".$row['id']." ORDER BY display_order"; $sql = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND parent_item_id = ".$row['id']." ORDER BY display_order";
//error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql, 0); //error_log('New LP - learnpath_functions - get_learnpath_tree: '.$sql, 0);
$res = Database::query($sql); $res = Database::query($sql);
//error_log('New LP - learnpath_functions - get_learnpath_tree: Found '.Database::num_rows($res).' results', 0); //error_log('New LP - learnpath_functions - get_learnpath_tree: Found '.Database::num_rows($res).' results', 0);
@ -1036,6 +1009,7 @@ function display_toc_chapter_contents($tree, $parent_item_id = 0, $learnpath_id,
* @param integer Level of recursivity we have reached * @param integer Level of recursivity we have reached
* @param integer Counter of elements already displayed * @param integer Counter of elements already displayed
* @author Yannick Warnier <yannick.warnier@beeznest.com> * @author Yannick Warnier <yannick.warnier@beeznest.com>
* @deprecated this function seems to be unused
* @note : forced display because of display_addedresource_link_in_learnpath behaviour (outputing a string would be better) * @note : forced display because of display_addedresource_link_in_learnpath behaviour (outputing a string would be better)
*/ */
function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree = false, $level = 0, $counter = 0) { function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree = false, $level = 0, $counter = 0) {
@ -1103,8 +1077,9 @@ function get_tracking_table($learnpath_id, $user_id, $parent_item_id = 0, $tree
function is_empty($id) { function is_empty($id) {
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
$tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER); $tbl_learnpath_chapter = Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $tbl_learnpath_chapter WHERE lp_id=$id ORDER BY display_order ASC"; $sql = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND lp_id=$id ORDER BY display_order ASC";
$result = Database::query($sql); $result = Database::query($sql);
$num_modules = Database::num_rows($result); $num_modules = Database::num_rows($result);
$empty = true; $empty = true;
@ -1114,7 +1089,7 @@ function is_empty($id) {
$num_items = 0; $num_items = 0;
$parent_item_id = $row['id']; $parent_item_id = $row['id'];
$sql2 = "SELECT * FROM $tbl_learnpath_item WHERE (parent_item_id=$parent_item_id) ORDER BY display_order ASC"; $sql2 = "SELECT * FROM $tbl_learnpath_item WHERE c_id = $course_id AND (parent_item_id=$parent_item_id) ORDER BY display_order ASC";
$result2 = Database::query($sql2); $result2 = Database::query($sql2);
$num_items = Database::num_rows($result2); $num_items = Database::num_rows($result2);
if ($num_items > 0) { if ($num_items > 0) {
@ -1338,14 +1313,11 @@ function export_exercise($item_id) {
*/ */
function exportitem($id, $item_id, $item_type, $add_scorm_communications = false) { function exportitem($id, $item_id, $item_type, $add_scorm_communications = false) {
$course_id = api_get_course_int_id();
global $circle1_files, $expdir, $_course, $_SESSION, $GLOBALS; global $circle1_files, $expdir, $_course, $_SESSION, $GLOBALS;
global $timeNoSecFormat, $dateFormatLong, $language_interface, $langPubl, $langDone, $langThisCourseDescriptionIsEmpty, $lang_course_description, $lang_introduction_text, $_cid, $langHotPotatoesFinished, $lang_author, $lang_date, $lang_groups, $lang_users, $lang_ass, $lang_dropbox, $test, $langQuestion; global $timeNoSecFormat, $dateFormatLong, $language_interface, $langPubl, $langDone, $langThisCourseDescriptionIsEmpty, $lang_course_description, $lang_introduction_text, $_cid, $langHotPotatoesFinished, $lang_author, $lang_date, $lang_groups, $lang_users, $lang_ass, $lang_dropbox, $test, $langQuestion;
//$_course = $_SESSION['course'];
require_once api_get_path(LIBRARY_PATH).'database.lib.php';
//$tbl_learnpath_item = Database::get_course_learnpath_item_table();
$libp = api_get_path(SYS_CODE_PAH); $libp = api_get_path(SYS_CODE_PAH);
include_once $libp.'exercice/exercise.class.php'; include_once $libp.'exercice/exercise.class.php';
include_once $libp.'question.class.php'; include_once $libp.'question.class.php';
@ -1428,7 +1400,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
case 'Agenda': case 'Agenda':
// 1. Get agenda event data from the database table. // 1. Get agenda event data from the database table.
$TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA); $TABLEAGENDA = Database :: get_course_table(TABLE_AGENDA);
$sql = "SELECT * FROM ".$TABLEAGENDA." where (id=$item_id)"; $sql = "SELECT * FROM ".$TABLEAGENDA." where c_id = $course_id AND (id=$item_id)";
$result = Database::query($sql); $result = Database::query($sql);
// 2. Prepare table output. // 2. Prepare table output.
@ -1497,7 +1469,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
case 'Ad_Valvas': case 'Ad_Valvas':
// 1. Get the announcement data from the database // 1. Get the announcement data from the database
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
$sql = "SELECT * FROM $tbl_announcement where id='$item_id'"; $sql = "SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id='$item_id'";
$result = Database::query($sql); $result = Database::query($sql);
// 2. Initialise export string // 2. Initialise export string
@ -1540,7 +1512,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
case 'Course_description': case 'Course_description':
// 1. Get course description data from database. // 1. Get course description data from database.
$tbl_course_description = Database :: get_course_table(TABLE_COURSE_DESCRIPTION); $tbl_course_description = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
$result = Database::query("SELECT id, title, content FROM ".$tbl_course_description." ORDER BY id"); $result = Database::query("SELECT id, title, content FROM ".$tbl_course_description." WHERE c_id = $course_id ORDER BY id");
// 2. Check this element. // 2. Check this element.
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -1567,7 +1539,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
case 'Document': case 'Document':
// 1. Get the document data from the database. // 1. Get the document data from the database.
$tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$sql_query = "SELECT * FROM $tbl_document WHERE id=$item_id"; $sql_query = "SELECT * FROM $tbl_document WHERE c_id = $course_id AND id=$item_id";
$sql_result = Database::query($sql_query); $sql_result = Database::query($sql_query);
$myrow = Database::fetch_array($sql_result); $myrow = Database::fetch_array($sql_result);
// 2. Get the origin path of the document to treat it internally. // 2. Get the origin path of the document to treat it internally.
@ -1673,7 +1645,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
$TBL_INTRO = Database :: get_course_tool_intro_table(); $TBL_INTRO = Database :: get_course_tool_intro_table();
// Modified by Ivan Tcholakov, 15-SEP-2008. // Modified by Ivan Tcholakov, 15-SEP-2008.
//$result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE id=1"); //$result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE id=1");
$result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE id='course_homepage'"); $result = Database::query("SELECT * FROM ".$TBL_INTRO." WHERE c_id = $course_id AND id='course_homepage'");
// //
$myrow = Database::fetch_array($result); $myrow = Database::fetch_array($result);
$intro = $myrow['intro_text']; $intro = $myrow['intro_text'];
@ -1685,7 +1657,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
case 'HotPotatoes': case 'HotPotatoes':
// 1. Get HotPotatoes data from the document table. // 1. Get HotPotatoes data from the document table.
$tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
$result = Database::query("SELECT * FROM $tbl_document WHERE id=$item_id"); $result = Database::query("SELECT * FROM $tbl_document WHERE c_id = $course_id AND id=$item_id");
$myrow = Database::fetch_array($result); $myrow = Database::fetch_array($result);
// 2. Get the document path. // 2. Get the document path.
$testfile = api_get_path(SYS_COURSE_PATH).$_course['path']."/document".urldecode($myrow['path']); $testfile = api_get_path(SYS_COURSE_PATH).$_course['path']."/document".urldecode($myrow['path']);
@ -1762,10 +1734,10 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
// 1. Get the forum post data from the database. // 1. Get the forum post data from the database.
$tbl_posts =Database::get_course_table(TABLE_FORUM_POST); $tbl_posts =Database::get_course_table(TABLE_FORUM_POST);
$tbl_posts_text =Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE); $tbl_posts_text =Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
$result = Database::query("SELECT * FROM $tbl_posts where post_id=$item_id"); $result = Database::query("SELECT * FROM $tbl_posts where c_id = $course_id AND post_id=$item_id");
$myrow = Database::fetch_array($result); $myrow = Database::fetch_array($result);
// Grabbing the title of the post. // Grabbing the title of the post.
$sql_titel = "SELECT * FROM $tbl_posts_text WHERE post_id=".$myrow['post_id']; $sql_titel = "SELECT * FROM $tbl_posts_text WHERE c_id = $course_id AND post_id=".$myrow['post_id'];
$result_titel = Database::query($sql_titel); $result_titel = Database::query($sql_titel);
$myrow_titel = Database::fetch_array($result_titel); $myrow_titel = Database::fetch_array($result_titel);
@ -1810,7 +1782,7 @@ function exportitem($id, $item_id, $item_type, $add_scorm_communications = false
case 'Link _blank': case 'Link _blank':
// 1. Get the link data from the database. // 1. Get the link data from the database.
$TABLETOOLLINK = Database :: get_course_link_table(); $TABLETOOLLINK = Database :: get_course_link_table();
$result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE id=$item_id"); $result = Database::query("SELECT * FROM $TABLETOOLLINK WHERE c_id = $course_id AND id=$item_id");
$myrow = Database::fetch_array($result); $myrow = Database::fetch_array($result);
$thelink = $myrow['url']; $thelink = $myrow['url'];
// 2. Check the link type (open in blank page or in current page). // 2. Check the link type (open in blank page or in current page).
@ -1891,6 +1863,9 @@ function deldir($dir) {
function exportpath($learnpath_id) { function exportpath($learnpath_id) {
// 1. Initialise variables. // 1. Initialise variables.
global $_course, $circle1_files, $LPnamesafe, $LPname, $expdir; global $_course, $circle1_files, $LPnamesafe, $LPname, $expdir;
$course_id = api_get_course_int_id();
//$tbl_learnpath_main, $tbl_learnpath_chapter, $tbl_learnpath_item, //$tbl_learnpath_main, $tbl_learnpath_chapter, $tbl_learnpath_item,
$tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN); $tbl_learnpath_main = Database :: get_course_table(TABLE_LEARNPATH_MAIN);
$tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM); $tbl_learnpath_item = Database :: get_course_table(TABLE_LEARNPATH_ITEM);
@ -1901,7 +1876,7 @@ function exportpath($learnpath_id) {
// 2. Get the name of the LP. // 2. Get the name of the LP.
include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php'; include_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
$sql = "SELECT * FROM $tbl_learnpath_main WHERE (lp_id=$learnpath_id)"; $sql = "SELECT * FROM $tbl_learnpath_main WHERE c_id = $course_id AND (lp_id=$learnpath_id)";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$LPname = $row['learnpath_name']; $LPname = $row['learnpath_name'];
@ -1926,7 +1901,7 @@ function exportpath($learnpath_id) {
// 4. Get the first level chapters - YW added parent_item_id condition for multi-level paths. // 4. Get the first level chapters - YW added parent_item_id condition for multi-level paths.
$sql = "SELECT * FROM $tbl_learnpath_chapter $sql = "SELECT * FROM $tbl_learnpath_chapter
WHERE (lp_id=$learnpath_id and parent_item_id=0) WHERE c_id = $course_id AND (lp_id=$learnpath_id and parent_item_id=0)
ORDER BY display_order ASC"; ORDER BY display_order ASC";
// To get all the elements, we should use the function that builds the table of content get_learnpath_tree. // To get all the elements, we should use the function that builds the table of content get_learnpath_tree.
//WHERE (lp_id=$learnpath_id) //WHERE (lp_id=$learnpath_id)
@ -1939,7 +1914,7 @@ function exportpath($learnpath_id) {
$parent_item_id = $row['id']; $parent_item_id = $row['id'];
//$sql2a = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id and parent_item_id=$parent_item_id) ORDER BY display_order ASC"; //$sql2a = "SELECT * FROM $tbl_learnpath_chapter WHERE (lp_id=$learnpath_id and parent_item_id=$parent_item_id) ORDER BY display_order ASC";
//$result2a = Database::query($sql); //$result2a = Database::query($sql);
$sql2b = "SELECT * FROM $tbl_learnpath_item WHERE (parent_item_id=$parent_item_id) ORDER BY display_order ASC"; $sql2b = "SELECT * FROM $tbl_learnpath_item WHERE c_id = $course_id AND (parent_item_id=$parent_item_id) ORDER BY display_order ASC";
$result2b = Database::query($sql2b); $result2b = Database::query($sql2b);
while ($row2 = Database::fetch_array($result2b)) { while ($row2 = Database::fetch_array($result2b)) {
@ -2131,19 +2106,21 @@ function createimsmanifest($circle1_files, $learnpath_id) {
// Items list. // Items list.
$i = 0; $i = 0;
$course_id = api_get_course_int_id();
$previous_item_id = '00'; $previous_item_id = '00';
while ($circle1_files[0][$i]) { while ($circle1_files[0][$i]) {
// Check whether we are in the border of two chapters. // Check whether we are in the border of two chapters.
//if (!$desc=strpos($circle1_files[2][$i],'scription')) { // This is needed if the descriptions are exported to file. //if (!$desc=strpos($circle1_files[2][$i],'scription')) { // This is needed if the descriptions are exported to file.
$sql = "SELECT * FROM $tbl_learnpath_item WHERE (id=".$circle1_files[2][$i].")"; $sql = "SELECT * FROM $tbl_learnpath_item WHERE c_id = $course_id AND (id=".$circle1_files[2][$i].")";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$parent_item_id = $row['parent_item_id']; $parent_item_id = $row['parent_item_id'];
if ($parent_item_id != $previous_item_id) { if ($parent_item_id != $previous_item_id) {
// We create the item tag for the chapter (without indifierref). // We create the item tag for the chapter (without indifierref).
$sql2 = "SELECT * FROM $tbl_learnpath_chapter WHERE (id=".$parent_item_id.")"; $sql2 = "SELECT * FROM $tbl_learnpath_chapter WHERE c_id = $course_id AND (id=".$parent_item_id.")";
$result2 = Database::query($sql2); $result2 = Database::query($sql2);
$row2 = Database::fetch_array($result2); $row2 = Database::fetch_array($result2);
$chapter_name = $row2['chapter_name']; $chapter_name = $row2['chapter_name'];

@ -58,17 +58,18 @@ if ((!$is_allowed_to_edit) || ($isStudentView)) {
/* The learnpath has been just created, go get the last id. */ /* The learnpath has been just created, go get the last id. */
$is_new = false; $is_new = false;
$course_id = api_get_course_int_id();
if ($learnpath_id == 0) { if ($learnpath_id == 0) {
$is_new = true; $is_new = true;
$sql = "SELECT id FROM " . $tbl_lp . " ORDER BY id DESC LIMIT 0, 1"; $sql = "SELECT id FROM " . $tbl_lp . " WHERE c_id = $course_id ORDER BY id DESC LIMIT 0, 1";
$result = Database::query($sql); $result = Database::query($sql);
$row = Database::fetch_array($result); $row = Database::fetch_array($result);
$learnpath_id = $row['id']; $learnpath_id = $row['id'];
} }
$sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id"; $sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
$result = Database::query($sql_query); $result = Database::query($sql_query);
$therow = Database::fetch_array($result); $therow = Database::fetch_array($result);
@ -110,8 +111,7 @@ function stripslashes(str) {
} }
function confirmation(name) { function confirmation(name) {
name=stripslashes(name); name=stripslashes(name);
if (confirm("<?php echo $suredel; ?> " + name + " ?")) if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
{
return true; return true;
} else { } else {
return false; return false;
@ -148,7 +148,7 @@ echo '<table cellpadding="0" cellspacing="0" class="lp_build">';
$learnpathadded .= '<a href="lp_controller.php?'.api_get_cidreq().'&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("BasicOverview").'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'), array('style' => 'vertical-align: middle;'),'22').' '.get_lang('BasicOverview').'</a>: '.get_lang('BasicOverviewComment').'<br />'; $learnpathadded .= '<a href="lp_controller.php?'.api_get_cidreq().'&amp;gradebook='.$gradebook.'&amp;action=admin_view&amp;lp_id=' . $_SESSION['oLP']->lp_id . '" title="'.get_lang("BasicOverview").'">'.Display::return_icon('move_learnpath.png', get_lang('BasicOverview'), array('style' => 'vertical-align: middle;'),'22').' '.get_lang('BasicOverview').'</a>: '.get_lang('BasicOverviewComment').'<br />';
$learnpathadded .= '<a href="lp_controller.php?'.api_get_cidreq().'&amp;gradebook='.$gradebook.'&action=view&lp_id='.$_SESSION['oLP']->lp_id.'">'.Display::return_icon('view_left_right.png', get_lang('Display'),array('style' => 'vertical-align: middle;'),'22').' '.get_lang('Display').'</a>: '.get_lang('DisplayComment').'<br />'; $learnpathadded .= '<a href="lp_controller.php?'.api_get_cidreq().'&amp;gradebook='.$gradebook.'&action=view&lp_id='.$_SESSION['oLP']->lp_id.'">'.Display::return_icon('view_left_right.png', get_lang('Display'),array('style' => 'vertical-align: middle;'),'22').' '.get_lang('Display').'</a>: '.get_lang('DisplayComment').'<br />';
$learnpathadded .= '<br /></p>'; $learnpathadded .= '<br /></p>';
Display::display_normal_message($learnpathadded, false); echo $learnpathadded;
} }
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';

@ -205,6 +205,7 @@ if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : ''); $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : '');
switch ($action) { switch ($action) {
case 'add_item': case 'add_item':

@ -45,18 +45,13 @@ if ((! $is_allowed_to_edit) || ($isStudentView)) {
error_log('New LP - User not authorized in lp_edit_item_prereq.php'); error_log('New LP - User not authorized in lp_edit_item_prereq.php');
header('location:lp_controller.php?action=view&lp_id='.$learnpath_id); header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
} }
// From here on, we are admin because of the previous condition, so don't check anymore. $course_id = api_get_course_int_id();
$sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id";
$sql_query = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND id = $learnpath_id";
$result = Database::query($sql_query); $result = Database::query($sql_query);
$therow = Database::fetch_array($result); $therow = Database::fetch_array($result);
//$admin_output = '';
/*
Course admin section
- all the functions not available for students - always available in this case (page only shown to admin)
*/
/* SHOWING THE ADMIN TOOLS */ /* SHOWING THE ADMIN TOOLS */
if (isset($_SESSION['gradebook'])){ if (isset($_SESSION['gradebook'])){
@ -71,7 +66,6 @@ if (!empty($gradebook) && $gradebook == 'view') {
} }
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths')); $interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
$interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => stripslashes("{$therow['name']}")); $interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => stripslashes("{$therow['name']}"));
// Theme calls. // Theme calls.

Loading…
Cancel
Save