Skip to content

Commit

Permalink
Add course URL in lp ajax calls see BT#13168
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Aug 11, 2017
1 parent a43e0c9 commit 4f34e09
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 219 deletions.
11 changes: 9 additions & 2 deletions main/lp/lp_ajax_save_item.php
Expand Up @@ -69,7 +69,15 @@ function save_item(
error_log("finish: $lmsFinish - navigatesAway: $userNavigatesAway");
}

$myLP = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
$courseCode = api_get_course_id();
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
if ($courseInfo) {
$courseCode = $courseInfo['code'];
}
}

$myLP = learnpath::getLpFromSession($courseCode, $lp_id, $user_id);

if (!is_a($myLP, 'learnpath')) {
if ($debug) {
Expand All @@ -78,7 +86,6 @@ function save_item(

return null;
}

$prerequisitesCheck = $myLP->prerequisites_match($item_id);

/** @var learnpathItem $myLPI */
Expand Down
41 changes: 24 additions & 17 deletions main/lp/scorm_api.php
Expand Up @@ -205,9 +205,10 @@ function APIobject() {
olms.asset_timer = 0;
olms.userfname = '<?php echo str_replace("'", "\\'", $user['firstname']); ?>';
olms.userlname = '<?php echo str_replace("'", "\\'", $user['lastname']); ?>';

olms.execute_stats = false;

var courseUrl = '?cidReq='+olms.lms_course_code+'&id_session='+olms.lms_session_id;

/**
* Add the "addListeners" function to the "onload" event of the window and
* start the timer if necessary (asset)
Expand Down Expand Up @@ -293,7 +294,7 @@ function LMSInitialize() {

$.ajax({
type: "POST",
url: "lp_ajax_initialize.php",
url: "lp_ajax_initialize.php" + courseUrl,
data: params,
dataType: 'script',
async: false,
Expand Down Expand Up @@ -1363,8 +1364,11 @@ function update_progress_bar(nbr_complete, nbr_total, mode) {
/**
* Update the gamification values (number of stars and score)
*/
function updateGamificationValues() {
var fetchValues = $.ajax('<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php', {
function updateGamificationValues()
{
var fetchValues = $.ajax(
'<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php?' + courseUrl,
{
dataType: 'json',
data: {
a: 'update_gamification'
Expand Down Expand Up @@ -1648,7 +1652,7 @@ function switch_item(current_item, next_item){
//(4) refresh the audio player if needed
$.ajax({
type: "POST",
url: "lp_nav.php",
url: "lp_nav.php"+courseUrl,
data: {
lp_item: next_item
},
Expand Down Expand Up @@ -1676,10 +1680,12 @@ function switch_item(current_item, next_item){
* Hide or show the navigation buttons if the current item is the First or Last
*/
var checkCurrentItemPosition = function(lpItemId) {
var currentItem = $.getJSON('<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php', {
a: 'check_item_position',
lp_item: lpItemId
}
var currentItem = $.getJSON(
'<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php' + courseUrl,
{
a: 'check_item_position',
lp_item: lpItemId
}
).done(function(parsedResponse,statusText,jqXhr) {
var position = jqXhr.responseJSON;
if (position == 'first') {
Expand All @@ -1703,7 +1709,8 @@ function switch_item(current_item, next_item){
* Get a forum info when the learning path item has a associated forum
*/
var loadForumThread = function(lpId, lpItemId) {
var loadForum = $.getJSON('<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php', {
var loadForum = $.getJSON(
'<?php echo api_get_path(WEB_AJAX_PATH) ?>lp.ajax.php' + courseUrl, {
a: 'get_forum_thread',
lp: lpId,
lp_item: lpItemId
Expand Down Expand Up @@ -1821,7 +1828,7 @@ function xajax_save_item(
$.ajax({
type:"POST",
data: params,
url: "lp_ajax_save_item.php",
url: "lp_ajax_save_item.php" + courseUrl,
dataType: "script",
async: false
});
Expand Down Expand Up @@ -1935,7 +1942,7 @@ function xajax_save_item_scorm(
$.ajax({
type:"POST",
data: params,
url: "lp_ajax_save_item.php",
url: "lp_ajax_save_item.php" + courseUrl,
dataType: "script",
async: false
});
Expand All @@ -1953,7 +1960,7 @@ function xajax_start_timer() {
logit_lms('xajax_start_timer() called',3);
$.ajax({
type: "GET",
url: "lp_ajax_start_timer.php",
url: "lp_ajax_start_timer.php" + courseUrl,
dataType: "script",
async: false,
success: function(time) {
Expand Down Expand Up @@ -1997,7 +2004,7 @@ function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,ite
$.ajax({
type: "POST",
data: params,
url: "lp_ajax_save_objectives.php",
url: "lp_ajax_save_objectives.php" + courseUrl,
dataType: "script",
async: false
});
Expand Down Expand Up @@ -2027,7 +2034,7 @@ function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id
$.ajax({
type: "POST",
data: params,
url: "lp_ajax_switch_item.php",
url: "lp_ajax_switch_item.php" + courseUrl,
dataType: "script",
async: false
});
Expand Down Expand Up @@ -2056,7 +2063,7 @@ function xajax_switch_item_toc(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,
$.ajax({
type: "POST",
data: params,
url: "lp_ajax_switch_item_toc.php",
url: "lp_ajax_switch_item_toc.php" + courseUrl,
dataType: "script",
async: false
});
Expand Down Expand Up @@ -2086,7 +2093,7 @@ function attach_glossary_into_scorm(type) {
my_protocol = location.protocol;
my_pathname=location.pathname;
work_path = my_pathname.substr(0,my_pathname.indexOf('<?php echo api_get_path(REL_COURSE_PATH) ?>'));
var ajaxRequestUrl = '<?php echo api_get_path(WEB_CODE_PATH).'glossary/glossary_ajax_request.php'; ?>';
var ajaxRequestUrl = '<?php echo api_get_path(WEB_CODE_PATH).'glossary/glossary_ajax_request.php'; ?>' + courseUrl;

if (type == 'automatic') {
$.ajax({
Expand Down
155 changes: 77 additions & 78 deletions main/template/default/glossary/glossary_auto.js.tpl
Expand Up @@ -2,97 +2,96 @@
$(document).ready(function() {
$(window).load(function () {
{% endif %}
var my_text = $(".glossary-content").html();
var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php?{{ _p.web_cid_query }}";
var imageSource = "{{ _p.web }}main/inc/lib/javascript/indicator.gif";
var indicatorImage ='<img src="' + imageSource + '" />';

var my_text = $(".glossary-content").html();
var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php";
var imageSource = "{{ _p.web }}main/inc/lib/javascript/indicator.gif";
var indicatorImage ='<img src="' + imageSource + '" />';

$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(content_object) {},
type: "POST",
url: ajaxRequestUrl,
data: "glossary_data=true",
success: function(datas) {
if (datas.length==0) {
return false;
}
// glossary terms
data_terms=datas.split("[|.|_|.|-|.|]");
var complex_array = new Array();
var cp_complex_array = new Array();
for(i=0;i<data_terms.length;i++) {
specific_terms=data_terms[i].split("__|__|");
var real_term = specific_terms[1]; // glossary term
var real_code = specific_terms[0]; // glossary id
complex_array[real_code] = real_term;
cp_complex_array[real_code] = real_term;
}
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(content_object) {},
type: "POST",
url: ajaxRequestUrl,
data: "glossary_data=true",
success: function(datas) {
if (datas.length==0) {
return false;
}
// glossary terms
data_terms=datas.split("[|.|_|.|-|.|]");
var complex_array = new Array();
var cp_complex_array = new Array();
for(i=0;i<data_terms.length;i++) {
specific_terms=data_terms[i].split("__|__|");
var real_term = specific_terms[1]; // glossary term
var real_code = specific_terms[0]; // glossary id
complex_array[real_code] = real_term;
cp_complex_array[real_code] = real_term;
}

complex_array.reverse();
complex_array.reverse();

for (var my_index in complex_array) {
n = complex_array[my_index];
if (n == null) {
n = '';
} else {
for (var cp_my_index in cp_complex_array) {
cp_data = cp_complex_array[cp_my_index];
if (cp_data == null) {
cp_data = '';
} else {
if (cp_data == n) {
my_index = cp_my_index;
}
for (var my_index in complex_array) {
n = complex_array[my_index];
if (n == null) {
n = '';
} else {
for (var cp_my_index in cp_complex_array) {
cp_data = cp_complex_array[cp_my_index];
if (cp_data == null) {
cp_data = '';
} else {
if (cp_data == n) {
my_index = cp_my_index;
}
}
$('body').removeHighlight().highlight(n, my_index);
}
$('body').removeHighlight().highlight(n, my_index);
}
}

var complex_array = new Array();
//mouse on click
$("body").on("click", ".glossary-ajax", function(e) {
random_id = Math.round(Math.random()*100);
div_show_id = "div_show_id";
div_content_id = "div_content_id";
var complex_array = new Array();
//mouse on click
$("body").on("click", ".glossary-ajax", function(e) {
random_id = Math.round(Math.random()*100);
div_show_id = "div_show_id";
div_content_id = "div_content_id";
$(this).append("<div id="+div_show_id+"><div id="+div_content_id+">&nbsp;</div></div>");
var $target = $(this);
$(this).append("<div id="+div_show_id+"><div id="+div_content_id+">&nbsp;</div></div>");
var $target = $(this);
//$("#"+div_show_id).dialog("destroy");
$("#"+div_show_id).dialog({
autoOpen: false,
width: 600,
height: 200,
position: { my: 'left top', at: 'right top', of: $target },
close: function(){
$("div#"+div_show_id).remove();
$("div#"+div_content_id).remove();
}
});
//$("#"+div_show_id).dialog("destroy");
$("#"+div_show_id).dialog({
autoOpen: false,
width: 600,
height: 200,
position: { my: 'left top', at: 'right top', of: $target },
close: function(){
$("div#"+div_show_id).remove();
$("div#"+div_content_id).remove();
}
});
notebook_id = $(this).attr("name");
data_notebook = notebook_id.split("link");
my_glossary_id = data_notebook[1];
notebook_id = $(this).attr("name");
data_notebook = notebook_id.split("link");
my_glossary_id = data_notebook[1];
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(content_object) {
$("div#"+div_content_id).html(indicatorImage);
},
type: "POST",
url: ajaxRequestUrl,
data: "glossary_id="+my_glossary_id,
success: function(datas) {
$("div#"+div_content_id).html(datas);
$("#"+div_show_id).dialog("open");
}
});
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(content_object) {
$("div#"+div_content_id).html(indicatorImage);
},
type: "POST",
url: ajaxRequestUrl,
data: "glossary_id="+my_glossary_id,
success: function(datas) {
$("div#"+div_content_id).html(datas);
$("#"+div_show_id).dialog("open");
}
});
}
});
});
}
});
{% if add_ready %}
});
});
Expand Down
31 changes: 15 additions & 16 deletions main/template/default/glossary/glossary_manual.js.tpl
@@ -1,11 +1,10 @@
var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php";
var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php?{{ _p.web_cid_query }}";
var imageSource = "{{ _p.web_main }}" + "inc/lib/javascript/indicator.gif";
var indicatorImage ='<img src="' + imageSource + '" />';

{% if add_ready %}
$(document).ready(function() {
{% endif %}

$("body").on("click", ".glossary", function() {
is_glossary_name = $(this).html();
random_id = Math.round(Math.random()*100);
Expand All @@ -27,20 +26,20 @@ $(document).ready(function() {
$("div#"+div_content_id).remove();
}
});
var indicator =
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(result) {
$("div#"+div_content_id).html(indicatorImage);
},
type: "POST",
url: ajaxRequestUrl,
data: "glossary_name="+is_glossary_name,
success: function(data) {
$("div#"+div_content_id).html(data);
$("#"+div_show_id).dialog("open");
}
});

$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(result) {
$("div#"+div_content_id).html(indicatorImage);
},
type: "POST",
url: ajaxRequestUrl,
data: "glossary_name="+is_glossary_name,
success: function(data) {
$("div#"+div_content_id).html(data);
$("#"+div_show_id).dialog("open");
}
});
});

{% if add_ready %}
Expand Down

0 comments on commit 4f34e09

Please sign in to comment.