Fixing hotpotatoe bug while saving inside a LP see BT#6986

1.9.x
Julio Montoya 11 years ago
parent 43190f4b11
commit 1d2626f2f2
  1. 23
      main/exercice/savescores.php
  2. 18
      main/exercice/showinframes.php
  3. 15
      main/newscorm/learnpath.class.php
  4. 54
      main/newscorm/resourcelinker.inc.php

@ -35,12 +35,12 @@ my_delete($full_file_path.$_user['user_id'].".t.html");
$TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$_cid = api_get_course_id();
$score = $_REQUEST['score'];
$origin = $_REQUEST['origin'];
$learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
$lpViewId = isset($_REQUEST['lp_view_id']) ? intval($_REQUEST['lp_view_id']) : null;
$course_id = $courseInfo['real_id'];
$_cid = api_get_course_id();
$jscript2run = '';
/**
@ -103,10 +103,19 @@ if ($origin != 'learnpath') {
} else {
$htmlHeadXtra[] = $jscript2run;
Display::display_reduced_header();
$sql = "UPDATE $TABLE_LP_ITEM_VIEW SET
status = 'completed'
WHERE c_id = $course_id AND lp_item_id= $learnpath_item_id";
Database::query($sql);
Display::display_confirmation_message(get_lang('HotPotatoesFinished'));
if (!empty($course_id) && !empty($learnpath_item_id) && !empty($lpViewId)) {
$sql = "UPDATE $TABLE_LP_ITEM_VIEW SET
status = 'completed'
WHERE
c_id = $course_id AND
lp_item_id= $learnpath_item_id AND
lp_view_id = $lpViewId
";
Database::query($sql);
Display::display_confirmation_message(get_lang('HotPotatoesFinished'));
} else {
Display::display_error_message(get_lang('Error'));
}
Display::display_footer();
}

@ -8,16 +8,18 @@
require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
$_course = api_get_course_info();
$time = time();
$doc_url = str_replace(array('../', '\\', '\\0', '..'), array('', '', '', ''), urldecode($_GET['file']));
$cid = api_get_course_id();
$document_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$document_web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document';
$origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
$learnpath_id = isset($_REQUEST['learnpath_id']) ? $_REQUEST['learnpath_id'] : null;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? $_REQUEST['learnpath_item_id'] : null;
$time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null;
$document_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document';
$document_web_path = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document';
$origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
$learnpath_id = isset($_REQUEST['learnpath_id']) ? $_REQUEST['learnpath_id'] : null;
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? $_REQUEST['learnpath_item_id'] : null;
$time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null;
$lpViewId = isset($_REQUEST['lp_view_id']) ? $_REQUEST['lp_view_id'] : null;
$user_id = api_get_user_id();
$full_file_path = $document_path.$doc_url;
@ -35,10 +37,10 @@ if ($content == '') {
if (SaveScoreVariable==0) {
SaveScoreVariable = 1;
if (C.ie) {
document.location.href = '".api_get_path(WEB_PATH)."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS($time)."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score;
document.location.href = '".api_get_path(WEB_PATH)."main/exercice/savescores.php?lp_view_id=$lpViewId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS($time)."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score;
//window.alert(Score);
} else {
window.location.href = '".api_get_path(WEB_PATH)."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS($time)."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score;
window.location.href = '".api_get_path(WEB_PATH)."main/exercice/savescores.php?lp_view_id=$lpViewId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS($time)."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score;
}
}
}

@ -3373,8 +3373,12 @@ class learnpath
$file = 'lp_content.php?type=dir';
} else {
require_once 'resourcelinker.inc.php';
$file = rl_get_resource_link_for_learnpath($course_id, $this->get_id(), $item_id);
$file = rl_get_resource_link_for_learnpath(
$course_id,
$this->get_id(),
$item_id,
$this->get_view_id()
);
if ($this->debug > 0) {
error_log('rl_get_resource_link_for_learnpath - file: ' . $file, 0);
@ -3489,7 +3493,12 @@ class learnpath
list ($decoded) = explode('?', $decoded);
if (!is_file(realpath($sys_course_path . '/scorm/' . $lp_path . '/' . $decoded))) {
require_once 'resourcelinker.inc.php';
$file = rl_get_resource_link_for_learnpath($course_id, $this->get_id(), $item_id);
$file = rl_get_resource_link_for_learnpath(
$course_id,
$this->get_id(),
$item_id,
$this->get_view_id()
);
if (empty($file)) {
$file = 'blank.php?error=document_not_found';
} else {

@ -1120,28 +1120,25 @@ function get_addedresource_link_in_learnpath($type, $id, $id_in_path) {
$link .= "../exercice/exercise_submit.php?origin=$origin&exerciseId=".$myrow["id"];
}
break;
case 'HotPotatoes':
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
$result = Database::query("SELECT * FROM ".$TBL_DOCUMENT." WHERE c_id = $course_id AND id=$id");
$myrow = Database::fetch_array($result);
$path = $myrow['path'];
$name = GetQuizName($path, $documentPath);
if ($builder=='builder') { $origin='builder'; }
$name = GetQuizName($path, $documentPath);
if ($builder == 'builder') {
$origin = 'builder';
}
$cid = $_course['official_code'];
if ($builder != 'builder') {
$link .= api_get_self()."?action=closelesson&source_forum=".$_GET['source_forum']."&how=complete&id_in_path=$id_in_path&learnpath_id=$learnpath_id&type=HotPotatoes&origin=$origin&id=$id#$id_in_path";
} else {
$link .= "../exercice/showinframes.php?file=$path&cid=$cid&uid=".$_user['user_id'];
}
break;
case 'Forum':
//deprecated
//deprecated
$TBL_FORUMS = Database::get_course_table(TABLE_FORUM); // TODO: This is the old table name, it should be corrected.
$result = Database::query("SELECT * FROM $TBL_FORUMS WHERE c_id = $course_id AND forum_id=$id");
$myrow = Database::fetch_array($result);
@ -1585,11 +1582,6 @@ function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_win
$in_frames = in_array($ext, array('htm', 'html', 'gif', 'jpg', 'jpeg', 'png'));
$output = '<img src="../img/'.$image.'" align="middle" /> <a href="../document/'.($in_frames ? 'showinframes.php?file=' : 'download.php?doc_url=').$myrow['path'].'"'.$styling.' '.$target.'>'.$filename."</a><br />\n";
break;
/*
case 'Externallink':
$output = '<img src="../img/links.gif" align="middle" /> <a href="'.$id.'"'.$styling.' '.$target.'>'.$id."</a><br />\n";
break;
*/
}
return $output;
}
@ -1602,26 +1594,31 @@ function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_win
* In each case, we query the corresponding table for information and build the link
* with that information.
* @author Yannick Warnier <ywarnier@beeznest.org> - rebranding based on previous work (display_addedresource_link_in_learnpath())
* @param int Course code
* @param int The learning path ID (in lp table)
* @param int id_in_path - the unique index in the items table
* @param int $course_id Course code
* @param int $learnpath_id The learning path ID (in lp table)
* @param int $id_in_path the unique index in the items table
* @param int $lpViewId
*/
function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path)
function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path, $lpViewId)
{
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$course_info = api_get_course_info_by_id($course_id);
$course_id = $course_info['real_id'];
$course_code = $course_info['code'];
$session_id = api_get_session_id();
$learnpath_id = intval($learnpath_id);
$id_in_path = intval($id_in_path);
$sql_item = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
$res_item = Database::query($sql_item);
$learnpath_id = intval($learnpath_id);
$id_in_path = intval($id_in_path);
$lpViewId = intval($lpViewId);
$sql = "SELECT * FROM $tbl_lp_item
WHERE
c_id = $course_id AND
lp_id = $learnpath_id AND
id = $id_in_path AND
lp_view_id = $lpViewId";
$res_item = Database::query($sql);
if (Database::num_rows($res_item) < 1) {
return -1; //exit
return -1;
}
$row_item = Database::fetch_array($res_item);
@ -1655,7 +1652,6 @@ function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_pa
$sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND id=$id";
$result= Database::query($sql);
$myrow=Database::fetch_array($result);
if ($row_item['title'] != '') {
$myrow['title'] = $row_item['title'];
}
@ -1669,7 +1665,7 @@ function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_pa
$path = $myrow['path'];
$link .= $main_dir_path.'exercice/showinframes.php?file='.$path.'' .
'&origin='.$origin.'&cid='.$course_code.'&uid='.api_get_user_id().'' .
'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path;
'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$id_in_path.'&lp_view_id='.$lpViewId;
break;
case TOOL_FORUM:
$link .= $main_dir_path.'forum/viewforum.php?forum='.$id.'&lp=true&origin=learnpath';

Loading…
Cancel
Save