Fix glossary ajax requests see #7638
	
		
	
				
					
				
			
							parent
							
								
									9c27ac5027
								
							
						
					
					
						commit
						2bb3b7d2c7
					
				@ -0,0 +1,14 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require_once '../inc/global.inc.php'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$tpl = new Template(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$templateName = 'glossary/glossary_auto.js.tpl'; | 
				
			||||||
 | 
					if (api_get_setting('show_glossary_in_documents') == 'ismanual') { | 
				
			||||||
 | 
					    $templateName = 'glossary/glossary_manual.js.tpl'; | 
				
			||||||
 | 
					} | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$contentTemplate = $tpl->get_template($templateName); | 
				
			||||||
 | 
					$tpl->display($contentTemplate); | 
				
			||||||
@ -0,0 +1,62 @@ | 
				
			|||||||
 | 
					<?php | 
				
			||||||
 | 
					/* For licensing terms, see /license.txt */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* @todo move this file in the inc/ajax/ folder */ | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Glossary ajax request code | 
				
			||||||
 | 
					 * @package chamilo.glossary | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require_once '../inc/global.inc.php'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** | 
				
			||||||
 | 
					 * Search a term and return description from a glossary. | 
				
			||||||
 | 
					 */ | 
				
			||||||
 | 
					$charset = api_get_system_encoding(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//replace image path | 
				
			||||||
 | 
					$path_image=api_get_path(WEB_COURSE_PATH).api_get_course_path(); | 
				
			||||||
 | 
					$path_image_search='../../courses/'.api_get_course_path(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (isset($_POST['glossary_id']) && | 
				
			||||||
 | 
					    $_POST['glossary_id'] == strval(intval($_POST['glossary_id'])) | 
				
			||||||
 | 
					) { | 
				
			||||||
 | 
					    $glossary_id= Security::remove_XSS($_POST['glossary_id']); | 
				
			||||||
 | 
					    $glossary_description_by_id = GlossaryManager::get_glossary_term_by_glossary_id($glossary_id); | 
				
			||||||
 | 
					    $glossary_description_by_id = str_replace($path_image_search,$path_image,$glossary_description_by_id); | 
				
			||||||
 | 
					    echo api_xml_http_response_encode($glossary_description_by_id); | 
				
			||||||
 | 
					} elseif (isset($_POST['glossary_data']) && $_POST['glossary_data']=='true') { | 
				
			||||||
 | 
					    //get_glossary_terms | 
				
			||||||
 | 
					    $glossary_data = GlossaryManager::get_glossary_terms(); | 
				
			||||||
 | 
					    $glossary_all_data = array(); | 
				
			||||||
 | 
					    if (count($glossary_data) > 0) { | 
				
			||||||
 | 
					        foreach ($glossary_data as $glossary_index => $glossary_value) { | 
				
			||||||
 | 
					            $glossary_all_data[] = $glossary_value['id'].'__|__|'.$glossary_value['name']; | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					        $glossary_all_data = implode('[|.|_|.|-|.|]', $glossary_all_data); | 
				
			||||||
 | 
					        echo api_xml_http_response_encode($glossary_all_data); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} elseif(isset($_POST['glossary_name'])) { | 
				
			||||||
 | 
					    $my_glossary_name = Security::remove_XSS($_POST['glossary_name']); | 
				
			||||||
 | 
					    $my_glossary_name = api_convert_encoding($my_glossary_name, $charset, 'UTF-8'); | 
				
			||||||
 | 
					    $my_glossary_name = trim($my_glossary_name); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $glossary_description = GlossaryManager::get_glossary_term_by_glossary_name( | 
				
			||||||
 | 
					        $my_glossary_name | 
				
			||||||
 | 
					    ); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $glossary_description = str_replace( | 
				
			||||||
 | 
					        $path_image_search, | 
				
			||||||
 | 
					        $path_image, | 
				
			||||||
 | 
					        $glossary_description | 
				
			||||||
 | 
					    ); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (is_null($glossary_description) || strlen(trim($glossary_description)) == 0) { | 
				
			||||||
 | 
					        echo api_xml_http_response_encode(get_lang('NoResults')); | 
				
			||||||
 | 
					    } else { | 
				
			||||||
 | 
					        echo api_xml_http_response_encode($glossary_description); | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					} else { | 
				
			||||||
 | 
					    echo api_xml_http_response_encode(get_lang('NoResults')); | 
				
			||||||
 | 
					} | 
				
			||||||
@ -0,0 +1,80 @@ | 
				
			|||||||
 | 
					$(document).ready(function() { | 
				
			||||||
 | 
					    $(window).load(function () { | 
				
			||||||
 | 
					        var my_text = $(".glossary-content").html(); | 
				
			||||||
 | 
					        var ajaxRequestUrl = "{{ _p.web }}main/glossary/glossary_ajax_request.php"; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $.ajax({ | 
				
			||||||
 | 
					            contentType: "application/x-www-form-urlencoded", | 
				
			||||||
 | 
					            type: "POST", | 
				
			||||||
 | 
					            url: ajaxRequestUrl, | 
				
			||||||
 | 
					            data: "glossary_data=true", | 
				
			||||||
 | 
					            success: function(datas) { | 
				
			||||||
 | 
					                if (datas.length==0) { | 
				
			||||||
 | 
					                    return false; | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					                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]; | 
				
			||||||
 | 
					                    var real_code = specific_terms[0]; | 
				
			||||||
 | 
					                    complex_array[real_code] = real_term; | 
				
			||||||
 | 
					                    cp_complex_array[real_code] = real_term; | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                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; | 
				
			||||||
 | 
					                                } | 
				
			||||||
 | 
					                            } | 
				
			||||||
 | 
					                        } | 
				
			||||||
 | 
					                        $('#highlight-plugin').removeHighlight().highlight(n,my_index) | 
				
			||||||
 | 
					                    } | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                var complex_array = new Array(); | 
				
			||||||
 | 
					                $("#highlight-plugin .glossary-ajax").mouseover(function(){ | 
				
			||||||
 | 
					                    random_id = Math.round(Math.random()*100); | 
				
			||||||
 | 
					                    div_show_id="div_show_id"+random_id; | 
				
			||||||
 | 
					                    div_content_id="div_content_id"+random_id; | 
				
			||||||
 | 
					                    $(this).append("<div id="+div_show_id+" ><div id="+div_content_id+"> </div></div>"); | 
				
			||||||
 | 
					                    $("div#"+div_show_id).attr("style","z-index:99;display:inline;float:left;position:absolute;background-color:#F2F2F2;border-bottom: 1px solid #2E2E2E;border-right: 1px solid #2E2E2E;border-left: 1px solid #2E2E2E;border-top: 1px solid #2E2E2E;color:#305582;margin-left:5px;margin-right:5px;"); | 
				
			||||||
 | 
					                    $("div#"+div_content_id).attr("style","z-index:99;background-color:#F2F2F2;color:#0B3861;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;"); | 
				
			||||||
 | 
					                    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("<img src='{{ _p.web_main }}/inc/lib/javascript/indicator.gif' />"); | 
				
			||||||
 | 
					                        }, | 
				
			||||||
 | 
					                        type: "POST", | 
				
			||||||
 | 
					                        url: ajaxRequestUrl, | 
				
			||||||
 | 
					                        data: "glossary_id="+my_glossary_id, | 
				
			||||||
 | 
					                        success: function(datas) { | 
				
			||||||
 | 
					                            $("div#"+div_content_id).html(datas); | 
				
			||||||
 | 
					                        } | 
				
			||||||
 | 
					                    }); | 
				
			||||||
 | 
					                }); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                $("#highlight-plugin .glossary-ajax").mouseout(function(){ | 
				
			||||||
 | 
					                    var current_element = $(this); | 
				
			||||||
 | 
					                    div_show_id=current_element.find("div").attr("id"); | 
				
			||||||
 | 
					                    $("div#"+div_show_id).remove(); | 
				
			||||||
 | 
					                }); | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					        }); | 
				
			||||||
 | 
					    }); | 
				
			||||||
 | 
					}); | 
				
			||||||
@ -0,0 +1,39 @@ | 
				
			|||||||
 | 
					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 + '" />'; | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$(document).ready(function() { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $('html').on('mouseup', function(e) { | 
				
			||||||
 | 
					        if(!$(e.target).closest('.popover').length) { | 
				
			||||||
 | 
					            $('.popover').each(function(){ | 
				
			||||||
 | 
					                $(this.previousSibling).popover('hide'); | 
				
			||||||
 | 
					            }); | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					    }); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $(".glossary").attr('data-toggle', 'popover'); | 
				
			||||||
 | 
					    $(".glossary").popover({ | 
				
			||||||
 | 
					        'content': '{{ 'Loading' | get_lang }}', | 
				
			||||||
 | 
					        'html' : true | 
				
			||||||
 | 
					    }); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $("body").on("click", ".glossary", function() { | 
				
			||||||
 | 
					        is_glossary_name = $(this).html(); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var thisLink = $(this); | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $.ajax({ | 
				
			||||||
 | 
					            contentType: "application/x-www-form-urlencoded", | 
				
			||||||
 | 
					            type: "POST", | 
				
			||||||
 | 
					            url: ajaxRequestUrl, | 
				
			||||||
 | 
					            data: "glossary_name="+is_glossary_name, | 
				
			||||||
 | 
					            success: function(data) { | 
				
			||||||
 | 
					                thisLink.attr('data-title', is_glossary_name).data('bs.popover'); | 
				
			||||||
 | 
					                var popover = thisLink.attr('data-content',data).data('bs.popover'); | 
				
			||||||
 | 
					                popover.setContent(); | 
				
			||||||
 | 
					                popover.$tip.addClass(popover.options.placement); | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					        }); | 
				
			||||||
 | 
					    }); | 
				
			||||||
 | 
					}); | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue