Noel Dieschburg 13 years ago
parent
commit
23782f7cc3

+ 5 - 0
custompages/url-images/README

@@ -0,0 +1,5 @@
+Custom Pages : URL Images
+
+This features allows each access URL to have a number of images (currently three) specific to this URL. This allows easier customization of landing pages by access URL.
+
+You can access a URL's images by calling the static function CustomPages::getURLImages() in your custom page.

+ 33 - 0
main/admin/access_url_edit.php

@@ -43,6 +43,19 @@ if( $form->validate()) {
 			} else {
 			} else {
 				UrlManager::udpate($url_id, $url.'/', $description, $active);
 				UrlManager::udpate($url_id, $url.'/', $description, $active);
 			}
 			}
+			// URL Images
+			$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
+			$image_fields = array("url_image_1", "url_image_2", "url_image_3");
+			foreach ($image_fields as $image_field) {
+				if ($_FILES[$image_field]['error'] == 0) {
+					// Hardcoded: only PNG files allowed
+					if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
+						move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
+					}
+					// else fail silently
+				}
+				// else fail silently
+			}
 			$url_to_go='access_urls.php';
 			$url_to_go='access_urls.php';
 			$message=get_lang('URLEdited');
 			$message=get_lang('URLEdited');
 		} else {
 		} else {
@@ -61,6 +74,21 @@ if( $form->validate()) {
 				$url_to_go='access_url_edit.php';
 				$url_to_go='access_url_edit.php';
 				$message = get_lang('URLAlreadyAdded');
 				$message = get_lang('URLAlreadyAdded');
 			}
 			}
+			// URL Images
+			$url .= (substr($url,strlen($url)-1, strlen($url))=='/') ? '' : '/';
+			$url_id = UrlManager::get_url_id($url);
+			$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
+			$image_fields = array("url_image_1", "url_image_2", "url_image_3");
+			foreach ($image_fields as $image_field) {
+				if ($_FILES[$image_field]['error'] == 0) {
+					// Hardcoded: only PNG files allowed
+					if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
+						move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
+					}
+					// else fail silently
+				}
+				// else fail silently
+			}
 		}
 		}
 		Security::clear_token();
 		Security::clear_token();
 		$tok = Security::get_token();
 		$tok = Security::get_token();
@@ -122,6 +150,11 @@ if (isset ($_GET['action'])) {
 	}
 	}
 }
 }
 
 
+// URL Images
+$form->addElement('file','url_image_1','URL Image 1 (PNG)');
+$form->addElement('file','url_image_2','URL Image 2 (PNG)');
+$form->addElement('file','url_image_3','URL Image 3 (PNG)');
+
 // Submit button
 // Submit button
 $form->addElement('style_submit_button', 'submit', $submit_name, 'class="add"');
 $form->addElement('style_submit_button', 'submit', $submit_name, 'class="add"');
 $form->display();
 $form->display();

+ 17 - 0
main/inc/lib/custompages.lib.php

@@ -3,6 +3,8 @@
 // Used to implement the loading of custom pages
 // Used to implement the loading of custom pages
 // 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
 // 2011, Jean-Karim Bockstael <jeankarim@cblue.be>
 
 
+require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
+
 class CustomPages {
 class CustomPages {
 	
 	
 	public static function displayPage($page_name) {
 	public static function displayPage($page_name) {
@@ -16,5 +18,20 @@ class CustomPages {
 			error_log('CustomPages::displayPage : could not read file '.$file_name);
 			error_log('CustomPages::displayPage : could not read file '.$file_name);
 		}
 		}
 	}
 	}
+
+	public static function getURLImages($url_id = null) {
+		if (is_null($url_id)) {
+			$url = 'http://'.$_SERVER['HTTP_HOST'].'/';
+			$url_id = UrlManager::get_url_id($url);
+		}
+		$url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
+		$images = array();
+		for ($img_id = 1; $img_id <= 3; $img_id++) {
+			 if (file_exists($url_images_dir.$url_id.'_url_image_'.$img_id.'.png')) {
+			 	$images[] = api_get_path(WEB_PATH).'custompages/url-images/'.$url_id.'_url_image_'.$img_id.'.png';
+			 }
+		}
+		return $images;
+	}
 }
 }
 ?>
 ?>

+ 1 - 1
main/newscorm/js/storageapi.js

@@ -175,7 +175,7 @@ lms_storage_getAllUsers = function() {
 		type: "POST",
 		type: "POST",
 		url: "storageapi.php",
 		url: "storageapi.php",
 		data: {
 		data: {
-			action: "usersgetall",
+			action: "usersgetall"
 		},
 		},
 		success: function(data) {
 		success: function(data) {
 			result = eval(data);
 			result = eval(data);

+ 18 - 4
main/newscorm/storageapi.php

@@ -64,7 +64,12 @@ function storage_get($sv_user, $sv_course, $sv_sco, $sv_key) {
 	$res = Database::query($sql);
 	$res = Database::query($sql);
 	if (mysql_num_rows($res) > 0) {
 	if (mysql_num_rows($res) > 0) {
 		$row = Database::fetch_assoc($res);
 		$row = Database::fetch_assoc($res);
-		return stripslashes($row['sv_value']);
+		if (get_magic_quotes_gpc()) {
+			return stripslashes($row['sv_value']);
+		}
+		else {
+			return $row['sv_value'];
+		}
 	}
 	}
 	else {
 	else {
 		return null;
 		return null;
@@ -90,7 +95,9 @@ function storage_getall($sv_user, $sv_course, $sv_sco) {
 	$res = Database::query($sql);
 	$res = Database::query($sql);
 	$data = array();
 	$data = array();
 	while ($row = Database::fetch_assoc($res)) {
 	while ($row = Database::fetch_assoc($res)) {
-		$row['sv_value'] = stripslashes($row['sv_value']);
+		if (get_magic_quotes_gpc()) {
+			$row['sv_value'] = stripslashes($row['sv_value']);
+		}
 		$data[] = $row;
 		$data[] = $row;
 	}
 	}
 	return json_encode($data);
 	return json_encode($data);
@@ -147,7 +154,12 @@ function storage_stack_pop($sv_user, $sv_course, $sv_sco, $sv_key) {
 	$resdelete = Database::query($sqldelete);
 	$resdelete = Database::query($sqldelete);
 	if ($resselect && $resdelete) {
 	if ($resselect && $resdelete) {
 		Database::query("commit");
 		Database::query("commit");
-		return stripslashes($rowselect['sv_value']);
+		if (get_magic_quotes_gpc()) {
+			return stripslashes($rowselect['sv_value']);
+		}
+		else {
+			return $rowselect['sv_value'];
+		}
 	}
 	}
 	else {
 	else {
 		Database::query("rollback");
 		Database::query("rollback");
@@ -188,7 +200,9 @@ function storage_stack_getall($sv_user, $sv_course, $sv_sco, $sv_key) {
 	$res = Database::query($sql);
 	$res = Database::query($sql);
 	$results = array();
 	$results = array();
 	while ($row = Database::fetch_assoc($res)) {
 	while ($row = Database::fetch_assoc($res)) {
-		$row['value'] = stripslashes($row['value']);
+		if (get_magic_quotes_gpc()) {
+			$row['value'] = stripslashes($row['value']);
+		}
 		$results[] = $row;
 		$results[] = $row;
 	}
 	}
 	return json_encode($results);
 	return json_encode($results);

+ 4 - 2
main/reports/reports.php

@@ -108,8 +108,10 @@ if (is_array($reports_template[$_REQUEST['type']])) {
 
 
 	// check number of result
 	// check number of result
 	$numberOfResult = multiquery_num_rows($result);
 	$numberOfResult = multiquery_num_rows($result);
-	if ($numberOfResult == 0) 
-		die(get_lang('NoDataAvailable'));
+	if ($numberOfResult == 0) {
+		// This case should be taken care of by the display template itself, we should let the script run
+		//die(get_lang('NoDataAvailable'));
+	}
 } else {
 } else {
 	die('<b>'.get_lang('ErrorWhileBuildingReport').'</b>');
 	die('<b>'.get_lang('ErrorWhileBuildingReport').'</b>');
 }
 }