Browse Source

[svn r21660] logic changes - allow replace glossary terms with javascript - (partial FS#4337)

Isaac Flores 15 years ago
parent
commit
610c4a4554

+ 46 - 56
main/document/document_with_glossary_terms.php

@@ -1,67 +1,57 @@
 <?php
-$language_file[] = 'document';
 require_once '../inc/global.inc.php';
 require_once '../glossary/glossary.class.php';
-/*
-============================================================================== 
-		Main section
-============================================================================== 
-*/ 
 $file = Security::remove_XSS(urldecode($_GET['file']));
 $file=explode('?cidReq',$file);
 $file=$file[0];
 $file_root=$_course['path'].'/document'.str_replace('%2F', '/',$file);
 $file_url_sys=api_get_path(SYS_COURSE_PATH).$file_root;
-$file_url_web=api_get_path(WEB_COURSE_PATH).$file_root;
-
 $content_html=file_get_contents($file_url_sys);
-$new_file=str_replace('<head>','<head><script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script><script type="text/javascript">
+$new_file=preg_replace('/<head>/','<head><script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script><script type="text/javascript">
  $(document).ready(function() {
- 
-	$("body a").toggle(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+">&nbsp;</div></div>");
-   	 	 $("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F5F6CE;border-bottom: 1px dashed #dddddd;border-right: 1px dashed #dddddd;border-left: 1px dashed #dddddd;border-top: 1px dashed #dddddd;color:#305582;margin-left:5px;margin-right:5px;");
-   	 	 $("div#"+div_content_id).attr("style","background-color:#F5F6CE;color:#305582;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(objeto) {
-				$("div#"+div_content_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
-				type: "POST",
-				url: "../glossary/glossary_ajax_request.php",
-				data: "glossary_id="+my_glossary_id,
-				success: function(datos) {
-				 	$("div#"+div_content_id).html(datos);
-				}
-		 	});  	
-   	  		
-	},function(){
-		var current_element,
-		current_element=$(this);
-		div_show_id=current_element.find("div").attr("id");
-	    $("div#"+div_show_id).remove();
-	});
-
-});
-</script>',$content_html);
-$content_html=explode('</head>',$new_file);
-$head_html=$content_html[0];
-$content_html=$content_html[1];
-$array_glossary=GlossaryManager::get_glossary_terms();
-if (count($array_glossary)>0) {
-	foreach ($array_glossary as $index_glossary => $value_glossary) {
-		$to_be_replaced[]=$str_href='<a name="link'.$value_glossary['id'].'"  href="javascript:void(0)" >'.$value_glossary['name'].'</a>';		
-		$to_replaced[]=$value_glossary['name'];
-	}
-}	
-$new_file=str_replace($to_replaced,$to_be_replaced,$content_html);
-$new_file=$head_html.$new_file;
-echo $new_file;
+	$(window).load(function () { 
+     var my_text=$("body").html();
+	 $.ajax({
+		contentType: "application/x-www-form-urlencoded",
+		beforeSend: function(objeto) {
+		},
+		type: "POST",
+		url: "../glossary/glossary_ajax_request.php",
+		data: "glossary_data=true",
+		success: function(datos) {
+		 		data_terms=datos.split("[|.|_|.|-|.|]");	
+		 		for(i=0;i<data_terms.length;i++) {
+		 			specific_terms=data_terms[i].split("__|__|");
+		 	     	new_html=my_text.replace(specific_terms[1],"<a href=\"javascript:void(0)\" name=\"link"+specific_terms[0]+"\" onclick=\"\">"+specific_terms[1]+"</a>");
+		 	     	$("body").html(new_html);
+		 	     	my_text=$("body").html();
+		 		}
+				$("body a").toggle(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+">&nbsp;</div></div>");
+			   	 	 $("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F5F6CE;border-bottom: 1px dashed #dddddd;border-right: 1px dashed #dddddd;border-left: 1px dashed #dddddd;border-top: 1px dashed #dddddd;color:#305582;margin-left:5px;margin-right:5px;");
+			   	 	 $("div#"+div_content_id).attr("style","background-color:#F5F6CE;color:#305582;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(objeto) {
+							$("div#"+div_content_id).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
+							type: "POST",
+							url: "../glossary/glossary_ajax_request.php",
+							data: "glossary_id="+my_glossary_id,
+							success: function(datos) {
+							 	$("div#"+div_content_id).html(datos);
+							}
+					 	});  		
+				},function(){
+					var current_element,
+					current_element=$(this);
+					div_show_id=current_element.find("div").attr("id");
+				    $("div#"+div_show_id).remove();
+				}); } });  }); }); </script>',$content_html);
+print_r($new_file);
 ?>

+ 2 - 8
main/document/headerpage.php

@@ -6,16 +6,12 @@
 */
 	// name of the language file that needs to be included
 $language_file = 'document';
-
-
 require_once '../inc/global.inc.php';
 $noPHP_SELF=true;
 $header_file= Security::remove_XSS($_GET['file']);	
 $path_array=explode('/',str_replace('\\','/',$header_file));
 $path_array = array_map('urldecode',$path_array);
-
 $header_file=implode('/',$path_array);
-
 $nameTools = $header_file;
 
 if(isset($_SESSION['_gid']) && $_SESSION['_gid']!='') {
@@ -27,10 +23,8 @@ $interbreadcrumb[]= array ("url"=>"./document.php?curdirpath=".dirname($header_f
 $interbreadcrumb[]= array ("url"=>"showinframes.php?file=".$header_file, "name"=>$header_file);
 
 Display::display_header(null,"Doc");
-
 echo "<div align=\"center\">";
-$file_url_web='document_with_glossary_terms.php?file='.urlencode(Security::remove_XSS($_GET['file']));
-$file_origin_url_web=api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$header_file."?".api_get_cidreq();
+$file_url_web='document_with_glossary_terms.php?file='.urlencode(Security::remove_XSS($header_file));
+//$file_origin_url_web=api_get_path('WEB_COURSE_PATH').$_course['path'].'/document'.$header_file."?".api_get_cidreq();
 echo "<a href='".$file_url_web."' target='blank'>".get_lang('_cut_paste_link')."</a></div>";
-
 ?>

+ 14 - 19
main/document/showinframes.php

@@ -1,4 +1,4 @@
-<?php // $Id: showinframes.php 21481 2009-06-18 04:47:18Z iflorespaz $ 
+<?php // $Id: showinframes.php 21660 2009-06-28 21:41:31Z iflorespaz $ 
 /*
 ============================================================================== 
 	Dokeos - elearning and course management software
@@ -23,6 +23,7 @@
 	Mail: info@dokeos.com
 ============================================================================== 
 */
+
 /**
 ============================================================================== 
 *	This file will show documents in a separate frame.
@@ -55,15 +56,13 @@
 $language_file[] = 'document';
 require_once '../inc/global.inc.php';
 require_once '../glossary/glossary.class.php';
-if (!empty($_GET['nopages']))
-{
+if (!empty($_GET['nopages'])) {
 	$nopages=Security::remove_XSS($_GET['nopages']);
-	if ($nopages==1)
-	{		
-		require_once api_get_path(INCLUDE_PATH) . 'reduced_header.inc.php';
+	if ($nopages==1) {		
+		require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
 		Display::display_error_message(get_lang('FileNotFound'));
 	}
-	exit();	
+	exit;	
 }
 
 $_SESSION['whereami'] = 'document/view';
@@ -87,15 +86,14 @@ $browser_display_title = "Dokeos Documents - " . Security::remove_XSS($_GET['cid
 
 //only admins get to see the "no frames" link in pageheader.php, so students get a header that's not so high
 $frameheight = 135;
-if($is_courseAdmin)
-{
+if($is_courseAdmin) {
 	$frameheight = 165;	
 }
 
 $file_root=$_course['path'].'/document'.str_replace('%2F', '/',$file);
 $file_url_sys=api_get_path(SYS_COURSE_PATH).$file_root;
 $file_url_web=api_get_path(WEB_COURSE_PATH).$file_root;
-$file_url_web='document_with_glossary_terms.php?file='.urlencode($_GET['file']);
+$file_url_web='document_with_glossary_terms.php?file='.urlencode($file);
 ?>
 <html>
 <head>
@@ -104,16 +102,13 @@ $file_url_web='document_with_glossary_terms.php?file='.urlencode($_GET['file']);
 </title>
 </head>
 	<frameset rows="<?php echo $frameheight; ?>,*" border="0" frameborder="no" >
-		<frame name="top" scrolling="no" noresize target="contents" src="headerpage.php?file=<?php echo $file.'&amp;'.api_get_cidreq(); ?>">
+		<frame name="top" scrolling="no" noresize target="contents" src="headerpage.php?file=<?php echo $file.'&amp;'.api_get_cidreq(); ?>" />
 		<?php
-		if (file_exists($file_url_sys))
-		{								
-			echo '<frame name="main" src="'.$file_url_web.'?'.api_get_cidreq().'&rand='.mt_rand(1,10000).'">';		
+		if (file_exists($file_url_sys)) {								
+			echo '<frame name="main" id="framemain" src="'.$file_url_web.'?'.api_get_cidreq().'&rand='.mt_rand(1,10000).'" />';		
+		} else {
+			echo '<frame name="main" id="framemain" src=showinframes.php?nopages=1 />';				
 		}
-		else
-		{
-			echo '<frame name="main" src=showinframes.php?nopages=1>';				
-		}		
 		?>
 	<noframes>
 	<body>
@@ -121,5 +116,5 @@ $file_url_web='document_with_glossary_terms.php?file='.urlencode($_GET['file']);
 			We suggest you try Mozilla, Firefox, Safari, Opera, or other browsers updated this millenium.</p>
 	</body>
 	</noframes>
-	<frame src="UntitledFrame-1"></frameset>
+	<!--<frame src="#"></frameset>-->
 </html>

+ 12 - 5
main/glossary/glossary_ajax_request.php

@@ -4,18 +4,25 @@
 // including the global dokeos file
 require_once '../inc/global.inc.php';
 require_once '../glossary/glossary.class.php';
-
-// notice for unauthorized people.
-api_protect_course_script(true);
-
 /*
  * search a term and return description from a glossary
  */
  $glossary_id=Security::remove_XSS($_POST['glossary_id']);
 $glossary_description=GlossaryManager::get_glossary_term_by_glossary_id($glossary_id);
+$glossary_data=GlossaryManager::get_glossary_terms();
+
+$glossary_all_data=array();
+foreach ($glossary_data as $glossary_index=>$glossary_value) {
+	$glossary_all_data[]=$glossary_value['id'].'__|__|'.$glossary_value['name'];
+}
+
+$glossary_all_data=implode('[|.|_|.|-|.|]',$glossary_all_data);
 
+//get_glossary_terms
  if (isset($_POST['glossary_id']) && $_POST['glossary_id']==strval(intval($_POST['glossary_id']))) {
   	echo api_xml_http_response_encode($glossary_description);	
+ } elseif (isset($_POST['glossary_data']) && $_POST['glossary_data']=='true') {
+   	echo api_xml_http_response_encode($glossary_all_data);	
  } else {
  	echo '';
- }
+ }