You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					137 lines
				
				4.0 KiB
			
		
		
			
		
	
	
					137 lines
				
				4.0 KiB
			| 
								 
											19 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
								/* For licensing terms, see /license.txt */
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								/**
							 | 
						||
| 
								 | 
							
								*	This script shows the list of exercises for administrators and students.
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
								*	@package chamilo.exercise
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								* 	@author Istvan Mandak
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								* 	@version $Id: Hpdownload.php 22201 2009-07-17 19:57:03Z cfasanando $
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								*/
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Code
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								session_cache_limiter('public');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
								require_once '../inc/global.inc.php';
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								$this_section=SECTION_COURSES;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								$tbl_document = Database::get_course_table(TABLE_DOCUMENT);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								$doc_url=str_replace(array('../','\\..','\\0','..\\'),array('','','',''),urldecode($_GET['doc_url']));
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								$filename=basename($doc_url);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								// launch event
							 | 
						||
| 
								 
											11 years ago
										 
									 | 
							
								//Event::event_download($doc_url);
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								if (isset($_course['path'])) {
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
								    $course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
							 | 
						||
| 
								 | 
							
									$full_file_name = $course_path.Security::remove_XSS($doc_url);
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								} else {
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
								    $course_path = api_get_path(SYS_COURSE_PATH).$cid.'/document';
							 | 
						||
| 
								 | 
							
									$full_file_name = $course_path.Security::remove_XSS($doc_url);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								if(!is_file($full_file_name)) {
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
									exit;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								if (!Security::check_abs_path($full_file_name, $course_path.'/')) {
							 | 
						||
| 
								 
											11 years ago
										 
									 | 
							
								    exit;
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								$extension=explode('.',$filename);
							 | 
						||
| 
								 | 
							
								$extension=strtolower($extension[sizeof($extension)-1]);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								switch($extension) {
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
									case 'gz':		$content_type='application/x-gzip';			break;
							 | 
						||
| 
								 | 
							
									case 'zip':		$content_type='application/zip';			break;
							 | 
						||
| 
								 | 
							
									case 'pdf':		$content_type='application/pdf';			break;
							 | 
						||
| 
								 | 
							
									case 'png':		$content_type='image/png';					break;
							 | 
						||
| 
								 | 
							
									case 'gif':		$content_type='image/gif';					break;
							 | 
						||
| 
								 | 
							
									case 'jpg':		$content_type='image/jpeg';					break;
							 | 
						||
| 
								 | 
							
									case 'txt':		$content_type='text/plain';					break;
							 | 
						||
| 
								 | 
							
									case 'htm':		$content_type='text/html';					break;
							 | 
						||
| 
								 | 
							
									case 'html':	$content_type='text/html';					break;
							 | 
						||
| 
								 | 
							
									default:		$content_type='application/octet-stream';	break;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								header('Content-disposition: filename='.$filename);
							 | 
						||
| 
								 | 
							
								header('Content-Type: '.$content_type);
							 | 
						||
| 
								 | 
							
								header('Expires: '.gmdate('D, d M Y H:i:s',time()+10).' GMT');
							 | 
						||
| 
								 | 
							
								header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()+10).' GMT');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
									Dynamic parsing section
							 | 
						||
| 
								 | 
							
									is activated whenever a user views an html file
							 | 
						||
| 
								 | 
							
									work in progress
							 | 
						||
| 
								 | 
							
									- question: we could also parse per line,
							 | 
						||
| 
								 | 
							
									perhaps this would be faster.
							 | 
						||
| 
								 | 
							
									($file_content = file($full_file_name) returns file in array)
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
								if ($content_type == 'text/html') {
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
									$directory_name = dirname($full_file_name);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
									$dir=str_replace(array('\\',$_configuration['root_sys']."courses/".$_course['path'].'/document'),array('/',''),$directory_name);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											15 years ago
										 
									 | 
							
									if($dir[strlen($dir)-1] != '/') {
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$dir.='/';
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
									//Parse whole file at one
							 | 
						||
| 
								 | 
							
									$fp = fopen($full_file_name, "r");
							 | 
						||
| 
								 | 
							
									$file_content = fread ($fp, filesize ($full_file_name));
							 | 
						||
| 
								 | 
							
									fclose($fp);
							 | 
						||
| 
								 
											11 years ago
										 
									 | 
							
								    $exercisePath = api_get_self();
							 | 
						||
| 
								 | 
							
								  	$exfile = explode('/',$exercisePath);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								  	$exfile = $exfile[sizeof($exfile)-1];
							 | 
						||
| 
								 
											11 years ago
										 
									 | 
							
								  	$exercisePath = substr($exercisePath,0,strpos($exercisePath,$exfile));
							 | 
						||
| 
								 | 
							
								  	$exercisePath = $exercisePath;
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$content = $file_content;
							 | 
						||
| 
								 | 
							
										$mit = "function Finish(){";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n".
							 | 
						||
| 
								 | 
							
										"function mySaveScore() // This function included by Dokeos System\n".
							 | 
						||
| 
								 | 
							
								"{\n".
							 | 
						||
| 
								 | 
							
								"   if (SaveScoreVariable==0)\n".
							 | 
						||
| 
								 | 
							
								"		{\n".
							 | 
						||
| 
								 | 
							
								"			SaveScoreVariable = 1;\n".
							 | 
						||
| 
								 | 
							
								"			if (C.ie)\n".
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								"			{\n".
							 | 
						||
| 
								 
											11 years ago
										 
									 | 
							
								"				document.location.href = \"".$exercisePath."savescores.php?origin=$origin&time=$time&test=".$doc_url."&uid=".$_user['user_id']."&cid=".$cid."&score=\"+Score;\n".
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								"				//window.alert(Score);\n".
							 | 
						||
| 
								 | 
							
								"			}\n".
							 | 
						||
| 
								 | 
							
								"			else\n".
							 | 
						||
| 
								 | 
							
								"			{\n".
							 | 
						||
| 
								 | 
							
								"			}\n".
							 | 
						||
| 
								 | 
							
								"		}\n".
							 | 
						||
| 
								 | 
							
								"}\n".
							 | 
						||
| 
								 | 
							
								"// Must be included \n".
							 | 
						||
| 
								 | 
							
								"function Finish(){\n".
							 | 
						||
| 
								 | 
							
								" mySaveScore();";
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$newcontent = str_replace($mit,$js_content,$content);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$prehref="javascript:void(0);";
							 | 
						||
| 
								 
											10 years ago
										 
									 | 
							
										$posthref = api_get_path(WEB_CODE_PATH) . "main/exercise/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid;
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$newcontent = str_replace($prehref,$posthref,$newcontent);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$prehref="class=\"GridNum\" onclick=";
							 | 
						||
| 
								 | 
							
										$posthref="class=\"GridNum\" onMouseover=";
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										$newcontent = str_replace($prehref,$posthref,$newcontent);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
										header('Content-length: '.strlen($newcontent));
							 | 
						||
| 
								 | 
							
										// Dipsp.
							 | 
						||
| 
								 | 
							
										echo $newcontent;
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
									exit();
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								//normal case, all non-html files
							 | 
						||
| 
								 | 
							
								//header('Content-length: '.filesize($full_file_name));
							 | 
						||
| 
								 | 
							
								$fp=fopen($full_file_name,'rb');
							 | 
						||
| 
								 
											17 years ago
										 
									 | 
							
								fpassthru($fp);
							 | 
						||
| 
								 
											19 years ago
										 
									 | 
							
								fclose($fp);
							 | 
						||
| 
								 
											14 years ago
										 
									 | 
							
								?>
							 |