diff --git a/main/document/document.php b/main/document/document.php
index 986525113e..469300a824 100755
--- a/main/document/document.php
+++ b/main/document/document.php
@@ -31,7 +31,7 @@
 
 /*	INIT SECTION */
 
-// Name of the language file that needs to be included
+// Language files that need to be included
 $language_file = array('document', 'slideshow', 'gradebook');
 
 require_once '../inc/global.inc.php';
@@ -41,9 +41,9 @@ require_once 'document.inc.php';
 $lib_path = api_get_path(LIBRARY_PATH);
 
 require_once $lib_path.'usermanager.lib.php';
-require_once api_get_path(LIBRARY_PATH).'document.lib.php';
-require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
-require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
+require_once $lib_path.'document.lib.php';
+require_once $lib_path.'fileUpload.lib.php';
+require_once $lib_path.'sortabletable.class.php';
 
 api_protect_course_script(true);
 $htmlHeadXtra[] = ''; //jQuery
@@ -58,40 +58,39 @@ $(document).ready( function() {
 	}
  } );
  ';
-//session
+// Session
 if (isset($_GET['id_session'])) {
 	$_SESSION['id_session'] = intval($_GET['id_session']);
 }
-//create directory certificates
-$course_id=api_get_course_id();
+// Create directory certificates
+$course_id = api_get_course_id();
 DocumentManager::create_directory_certificate_in_course($course_id);
 
-//show preview
-if (isset($_GET['curdirpath']) && $_GET['curdirpath']=='/certificates' && isset($_GET['set_preview']) && $_GET['set_preview']==strval(intval($_GET['set_preview']))) {
+// Show preview
+if (isset($_GET['curdirpath']) && $_GET['curdirpath'] == '/certificates' && isset($_GET['set_preview']) && $_GET['set_preview'] == strval(intval($_GET['set_preview']))) {
 	if (isset($_GET['set_preview'])) {
-			//generate document HTML
-			$course_id=api_get_course_id();
-			$content_html=DocumentManager::replace_user_info_into_html($course_id);
+		// Generate document HTML
+		$course_id = api_get_course_id();
+		$content_html = DocumentManager::replace_user_info_into_html($course_id);
 
-			$new_content_html=$content_html;
+		$new_content_html = $content_html;
 
-			$path_image=api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
-			$new_content_html=str_replace('../images/gallery',$path_image,$new_content_html);
+		$path_image = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/images/gallery';
+		$new_content_html = str_replace('../images/gallery', $path_image, $new_content_html);
 
-			$path_image_in_default_course=api_get_path(WEB_CODE_PATH).'default_course_document';
-			$new_content_html=str_replace('/main/default_course_document',$path_image_in_default_course,$new_content_html);
+		$path_image_in_default_course = api_get_path(WEB_CODE_PATH).'default_course_document';
+		$new_content_html = str_replace('/main/default_course_document', $path_image_in_default_course, $new_content_html);
 
-			$path_image_in_dokeos_main=api_get_path(WEB_IMG_PATH);
-			$new_content_html=str_replace('/main/img/',$path_image_in_dokeos_main,$new_content_html);
-			echo '
-			';
-			echo '
 ' . get_lang('Print') . '';
-			print_r($new_content_html);
-			exit;
+		$new_content_html = str_replace('/main/img/', api_get_path(WEB_IMG_PATH), $new_content_html);
+		echo '
+		';
+		echo '
 ' . get_lang('Print') . '';
+		print_r($new_content_html);
+		exit;
 	}
 }
 
@@ -133,7 +132,7 @@ if (isset($_GET['curdirpath']) && $_GET['curdirpath'] != '') {
 }
 $curdirpathurl = urlencode($curdirpath);
 
-//I'm in the certification module?
+// I'm in the certification module?
 $is_certificate_mode = DocumentManager::is_certificate_mode($curdirpath);
 
 $course_dir      = $_course['path'].'/document';
@@ -146,12 +145,12 @@ $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
 $group_member_with_upload_rights = false;
 
 // If the group id is set, we show them group documents
-if (isset($_SESSION['_gid']) && $_SESSION['_gid']!='') {
+if (isset($_SESSION['_gid']) && $_SESSION['_gid'] != '') {
 	// Needed for group related stuff
-	require_once($lib_path. 'groupmanager.lib.php');
+	require_once $lib_path.'groupmanager.lib.php';
 	// Get group info
 	$group_properties = GroupManager::get_group_properties($_SESSION['_gid']);
-	$noPHP_SELF=true;
+	$noPHP_SELF = true;
 	// Let's assume the user cannot upload files for the group
 	$group_member_with_upload_rights = false;
 
@@ -170,13 +169,13 @@ if (isset($_SESSION['_gid']) && $_SESSION['_gid']!='') {
 	} elseif ($group_properties['doc_state'] == 1) {  // Documents are public
 		$to_group_id = $_SESSION['_gid'];
 		$req_gid = '&gidReq='.$_SESSION['_gid'];
-		$interbreadcrumb[] = array ('url' => '../group/group.php', 'name' => get_lang('Groups'));
-		$interbreadcrumb[] = array ('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' ('.$group_properties['name'].')');
+		$interbreadcrumb[] = array('url' => '../group/group.php', 'name' => get_lang('Groups'));
+		$interbreadcrumb[] = array('url' => '../group/group_space.php?gidReq='.$_SESSION['_gid'], 'name' => get_lang('GroupSpace').' ('.$group_properties['name'].')');
 		//allowed to upload?
 		if ($is_allowed_to_edit || GroupManager::is_subscribed($_user['user_id'], $_SESSION['_gid'])) { // Only courseadmin or group members can upload
 			$group_member_with_upload_rights = true;
 		}
-	} else { //documents not active for this group
+	} else { // Documents not active for this group
 		$to_group_id = 0;
 		$req_gid = '';
 	}
@@ -212,7 +211,7 @@ if ($to_group_id != 0 && $curdirpath == '/') {
 }
 
 // Check visibility of the current dir path. Don't show anything if not allowed
-if (!(DocumentManager::is_visible($curdirpath, $_course)||$is_allowed_to_edit)) {
+if (!(DocumentManager::is_visible($curdirpath, $_course) || $is_allowed_to_edit)) {
     api_not_allowed();
 }
 
@@ -247,7 +246,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'download') {
 		$error404 .= '
The requested URL was not found on this server.
'; $error404 .= '