Julio Montoya 14 years ago
parent
commit
69f3633f3e

+ 19 - 19
main/forum/download.php

@@ -1,16 +1,16 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-*	This file is responsible for  passing requested documents to the browser.
-*	Html files are parsed to fix a few problems with URLs,
-*	but this code will hopefully be replaced soon by an Apache URL
-*	rewrite mechanism.
-*
-*	@package chamilo.document
-*/
+ * This file is responsible for  passing requested documents to the browser.
+ * Html files are parsed to fix a few problems with URLs,
+ * but this code will hopefully be replaced soon by an Apache URL
+ * rewrite mechanism.
+ *
+ * @package chamilo.document
+ */
 
 /*
-		MAIN CODE
+        MAIN CODE
 */
 
 session_cache_limiter('public');
@@ -37,21 +37,21 @@ $doc_url = str_replace(' ', '+', $doc_url);
 $doc_url = str_replace('/..', '', $doc_url); //echo $doc_url;
 
 if (! isset($_course)) {
-	api_not_allowed(true);
+    api_not_allowed(true);
 }
 
 $full_file_name = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/'.$doc_url;
 
 //if the rewrite rule asks for a directory, we redirect to the document explorer
 if (is_dir($full_file_name)) {
-	//remove last slash if present
-	//$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
-	//mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
-	while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
-	//create the path
-	$document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
-	//redirect
-	header('Location: '.$document_explorer);
+    //remove last slash if present
+    //$doc_url = ($doc_url{strlen($doc_url)-1}=='/')?substr($doc_url,0,strlen($doc_url)-1):$doc_url;
+    //mod_rewrite can change /some/path/ to /some/path// in some cases, so clean them all off (René)
+    while ($doc_url{$dul = strlen($doc_url)-1}=='/') $doc_url = substr($doc_url,0,$dul);
+    //create the path
+    $document_explorer = api_get_path(WEB_COURSE_PATH).api_get_course_path(); // home course path
+    //redirect
+    header('Location: '.$document_explorer);
 }
 
 $tbl_forum_attachment 	= Database::get_course_table(TABLE_FORUM_ATTACHMENT);
@@ -61,7 +61,7 @@ $tbl_forum_post 	= Database::get_course_table(TABLE_FORUM_POST);
 event_download($doc_url);
 
 $sql='SELECT thread_id, forum_id,filename FROM '.$tbl_forum_post.'  f  INNER JOIN '.$tbl_forum_attachment.' a
-  	  ON a.post_id=f.post_id WHERE path LIKE BINARY "'.$doc_url.'"';
+        ON a.post_id=f.post_id WHERE path LIKE BINARY "'.$doc_url.'"';
 
 $result = Database::query($sql);
 $row    = Database::fetch_array($result);
@@ -71,7 +71,7 @@ $forum_forum_visibility  = api_get_item_visibility(api_get_course_info($course_c
 
 if ($forum_thread_visibility==1 && $forum_forum_visibility==1) {
     if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/')) {
-	   DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
+       DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
     }
 }
 exit;

+ 108 - 108
main/forum/editpost.php

@@ -2,28 +2,28 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@Copyright Ghent University
-*	@Copyright Patrick Cool
-*
-* 	@package chamilo.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @Copyright Ghent University
+ * @Copyright Patrick Cool
+ *
+ *  @package chamilo.forum
+ */
 
 /*
-		INIT SECTION
+        INIT SECTION
 */
 // name of the language file that needs to be included
 $language_file = array ('forum','group');
@@ -47,7 +47,7 @@ require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 $nameTools=get_lang('ToolForum');
 
 /*
-	Including necessary files
+    Including necessary files
 */
 include 'forumconfig.inc.php';
 include 'forumfunction.inc.php';
@@ -55,29 +55,29 @@ include 'forumfunction.inc.php';
 //
 $origin = '';
 if(isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
 // javascript
 $htmlHeadXtra[] = '<script>
 
-		function advanced_parameters() {
-			if(document.getElementById(\'id_qualify\').style.display == \'none\') {
-				document.getElementById(\'id_qualify\').style.display = \'block\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+        function advanced_parameters() {
+            if(document.getElementById(\'id_qualify\').style.display == \'none\') {
+                document.getElementById(\'id_qualify\').style.display = \'block\';
+                document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
 
-			} else {
-				document.getElementById(\'id_qualify\').style.display = \'none\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			}
-		}
+            } else {
+                document.getElementById(\'id_qualify\').style.display = \'none\';
+                document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            }
+        }
 </script>';
 
 /*
-		MAIN DISPLAY SECTION
+        MAIN DISPLAY SECTION
 */
 /*
-	Retrieving forum and forum categorie information
+    Retrieving forum and forum categorie information
 */
 // we are getting all the information about the current forum and forum category.
 // note pcool: I tried to use only one sql statement (and function) for this
@@ -87,62 +87,62 @@ $current_forum=get_forum_information($_GET['forum']); // note: this has to be va
 $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
 $current_post=get_post_information($_GET['post']);
 /*
-	Header and Breadcrumbs
+    Header and Breadcrumbs
 */
 if (isset($_SESSION['gradebook'])){
-	$gradebook=	$_SESSION['gradebook'];
+    $gradebook=	$_SESSION['gradebook'];
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
-if ($origin=='group') {	
-	$_clean['toolgroup']=(int)$_SESSION['toolgroup'];
-	$group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
-	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
-	$interbreadcrumb[] = array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
-	$interbreadcrumb[] = array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
+if ($origin=='group') {
+    $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
+    $group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
+    $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
+    $interbreadcrumb[] = array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
+    $interbreadcrumb[] = array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
 
 } else {
-	$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
-	$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => prepare4display($current_forum_category['cat_title']));
-	$interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
-	$interbreadcrumb[]=array("url" => "viewthread.php?gradebook=$gradebook&amp;origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
-	$interbreadcrumb[]=array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
+    $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
+    $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => prepare4display($current_forum_category['cat_title']));
+    $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
+    $interbreadcrumb[]=array("url" => "viewthread.php?gradebook=$gradebook&amp;origin=".$origin."&amp;forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
+    $interbreadcrumb[]=array("url" => "javascript: void (0);","name" => get_lang('EditPost'));
 }
 /*
-	Resource Linker
+    Resource Linker
 */
 if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
-	$_SESSION['formelements']=$_POST;
-	$_SESSION['origin']=$_SERVER['REQUEST_URI'];
-	$_SESSION['breadcrumbs']=$interbreadcrumb;
-	header("Location: ../resourcelinker/resourcelinker.php");
+    $_SESSION['formelements']=$_POST;
+    $_SESSION['origin']=$_SERVER['REQUEST_URI'];
+    $_SESSION['breadcrumbs']=$interbreadcrumb;
+    header("Location: ../resourcelinker/resourcelinker.php");
 }
 $table_link 			= Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 /*
-	Header
+    Header
 */
 //are we in a lp ?
 $origin = '';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
 if ($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	Display :: display_header(null);
-	//api_display_tool_title($nameTools);
+    Display :: display_header(null);
+    //api_display_tool_title($nameTools);
 }
 //echo '<link href="forumstyles.css" rel="stylesheet" type="text/css" />';
 /*
-	Is the user allowed here?
+    Is the user allowed here?
 */
 // the user is not allowed here if
 // 1. the forumcategory, forum or thread is invisible (visibility==0)
@@ -153,47 +153,47 @@ if ($origin=='learnpath') {
 // I have split this is several pieces for clarity.
 //if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0) OR ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)))
 if (!api_is_allowed_to_edit(null,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 if (!api_is_allowed_to_edit(null,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 if (!api_is_allowed_to_edit(null,true) AND $current_forum['allow_edit']==0) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
 
 // action links
 if ($origin!='learnpath') {
-	echo '<div class="actions">';
-	echo '<span style="float:right;">'.search_link().'</span>';
-	if ($origin=='group') {		
-		echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';	
-	}
-	else{
-		echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32' ).'</a>';
-	}
-	echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin='.$origin.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
-	echo '</div>';
+    echo '<div class="actions">';
+    echo '<span style="float:right;">'.search_link().'</span>';
+    if ($origin=='group') {
+        echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
+    }
+    else{
+        echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32' ).'</a>';
+    }
+    echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin='.$origin.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
+    echo '</div>';
 }
 
 /*
-	Display Forum Category and the Forum information
+    Display Forum Category and the Forum information
 */
 echo "<table class=\"forum_table\" width='100%'>\n";
 // the forum category
@@ -208,26 +208,26 @@ echo '</table>';
 $values=show_edit_post_form($current_post, $current_thread, $current_forum, isset($_SESSION['formelements'])?$_SESSION['formelements']:'');
 
 if (!empty($values) and isset($_POST['SubmitPost'])) {
-	store_edit_post($values);
-
-	$option_chek=isset($values['thread_qualify_gradebook'])?$values['thread_qualify_gradebook']:null;// values 1 or 0
-	if ( 1== $option_chek ) {
-			$id=$values['thread_id'];
-			$title_gradebook=$values['calification_notebook_title'];
-			$value_calification=$values['numeric_calification'];
-			$weight_calification=$values['weight_calification'];
-			$description="";
-			$session_id=api_get_session_id();
-			$link_id=is_resource_in_course_gradebook(api_get_course_id(),5,$id,$session_id);
-			if (!$link_id) {
-				add_resource_to_course_gradebook(api_get_course_id(), 5, $id, $title_gradebook,$weight_calification,$value_calification,$description,time(),1,api_get_session_id());
-			} else {
-				Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
-			}
-
-	}
+    store_edit_post($values);
+
+    $option_chek=isset($values['thread_qualify_gradebook'])?$values['thread_qualify_gradebook']:null;// values 1 or 0
+    if ( 1== $option_chek ) {
+            $id=$values['thread_id'];
+            $title_gradebook=$values['calification_notebook_title'];
+            $value_calification=$values['numeric_calification'];
+            $weight_calification=$values['weight_calification'];
+            $description="";
+            $session_id=api_get_session_id();
+            $link_id=is_resource_in_course_gradebook(api_get_course_id(),5,$id,$session_id);
+            if (!$link_id) {
+                add_resource_to_course_gradebook(api_get_course_id(), 5, $id, $title_gradebook,$weight_calification,$value_calification,$description,time(),1,api_get_session_id());
+            } else {
+                Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
+            }
+
+    }
 }
 // footer
 if ($origin!='learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 23 - 23
main/forum/forumbody.inc.php

@@ -1,4 +1,4 @@
-<?php  
+<?php
 /* For licensing terms, see /license.txt */
 $current_thread		= get_thread_information($_GET['thread']);
 $my_cid_req		 	= Security::remove_XSS($_GET['cidReq']);
@@ -12,50 +12,50 @@ $to_origin			= Security::remove_XSS($_GET['origin']);
 
 $output = <<<EOF
 <div class="forum-body-form">
- 	<table>
- 		<form id="forum-thread-qualify" name="forum-thread-qualify" action="forumqualify.php">
- 		<input type="hidden" name="cidReq" value="{$my_cid_req}">
- 		<input type="hidden" name="forum" value="{$my_forum}">
- 		<input type="hidden" name="thread" value="{$my_thread}">
- 		<input type="hidden" name="user" value="{$user}">
- 		<input type="hidden" name="user_id" value="{$my_user_id}">
- 		<input type="hidden" name="gradebook" value="{$my_gradebook}">
-  		<input type="hidden" name="origin" value="{$to_origin}">
-    	<tr>
+     <table>
+         <form id="forum-thread-qualify" name="forum-thread-qualify" action="forumqualify.php">
+         <input type="hidden" name="cidReq" value="{$my_cid_req}">
+         <input type="hidden" name="forum" value="{$my_forum}">
+         <input type="hidden" name="thread" value="{$my_thread}">
+         <input type="hidden" name="user" value="{$user}">
+         <input type="hidden" name="user_id" value="{$my_user_id}">
+         <input type="hidden" name="gradebook" value="{$my_gradebook}">
+          <input type="hidden" name="origin" value="{$to_origin}">
+        <tr>
 EOF;
 
 $output .= '
-			<td width="40%" class="forum-thread-header">'.get_lang('User').'&nbsp;:</td >
-        	<td width="60%" class="forum-thread-body"><div align="left">'.get_name_user_by_id($userid).'</div></td>
+            <td width="40%" class="forum-thread-header">'.get_lang('User').'&nbsp;:</td >
+            <td width="60%" class="forum-thread-body"><div align="left">'.get_name_user_by_id($userid).'</div></td>
         </tr>
         <tr>
-    		<td width="40%" class="forum-thread-header">'.get_lang('Thread').'&nbsp;:</td >
+            <td width="40%" class="forum-thread-header">'.get_lang('Thread').'&nbsp;:</td >
             <td  width="60%" class="forum-thread-body">
                 <div align="left">'.$current_thread['thread_title'].'</div>
             </td>
         </tr>
 
-       	<tr>
-    		<td width="40%" class="forum-thread-header">'.get_lang('CourseUsers').'&nbsp;:</td >
+           <tr>
+            <td width="40%" class="forum-thread-header">'.get_lang('CourseUsers').'&nbsp;:</td >
             <td  width="60%" class="forum-thread-body">
                 <div align="left">'.$result['user_course'].'</div>
             </td>
         </tr>
 
-		<tr>
-    		<td width="40%" class="forum-thread-header">'.get_lang('PostsNumber').'&nbsp;:</td >
+        <tr>
+            <td width="40%" class="forum-thread-header">'.get_lang('PostsNumber').'&nbsp;:</td >
             <td  width="60%" class="forum-thread-body">
                 <div align="left">'.$result['post'].'</div>
             </td>
         </tr>
                 <tr>
-    		<td width="40%" class="forum-thread-header">'.get_lang('NumberOfPostsForThisUser').'&nbsp;:</td >
+            <td width="40%" class="forum-thread-header">'.get_lang('NumberOfPostsForThisUser').'&nbsp;:</td >
             <td  width="60%" class="forum-thread-body">
                 <div align="left">'.$result['user_post'].'</div>
             </td>
         </tr>
                 <tr>
-    		<td width="40%" class="forum-thread-header">'.get_lang('AveragePostPerUser').'&nbsp;:</td >
+            <td width="40%" class="forum-thread-header">'.get_lang('AveragePostPerUser').'&nbsp;:</td >
             <td  width="60%" class="forum-thread-body">
                 <div align="left">'.round($result['user_post']/$result['post'],2).'</div>
             </td>
@@ -63,14 +63,14 @@ $output .= '
         <tr>
             <td width="40%" class="forum-thread-header"><div align="left">'.get_lang('Qualification').'&nbsp;:</div></td >
             <td  width="60%" class="forum-thread-body"><div align="left">
-            	<input type="text" maxlength="8" id="idtextqualify" style="width:60px;" name="idtextqualify" value="'.$my_idtextqualify.'" />&nbsp;&nbsp;'.get_lang('MaxScore').'&nbsp;: '.$max_qualify.'</div>
+                <input type="text" maxlength="8" id="idtextqualify" style="width:60px;" name="idtextqualify" value="'.$my_idtextqualify.'" />&nbsp;&nbsp;'.get_lang('MaxScore').'&nbsp;: '.$max_qualify.'</div>
             </td>
         </tr>
-    	<tr>
+        <tr>
             <td width="40%"></td>
             <td width="60%"><div align="left"><button type="button" class="save" id="idbutton_qualify" name="idbutton_qualify"  value="'.get_lang('QualifyThisThread').'" onclick="javascript:if(document.getElementById(\'idtextqualify\').value>=0){if(confirm(\''.get_lang('ConfirmUserQualification').'\')){document.getElementById(\'forum-thread-qualify\').submit();}else{return false;};}else{alert(\''.get_lang('InsertQualificationCorrespondingToMaxScore').'\')};" >'.get_lang('QualifyThisThread').'</button></div></td>
         </tr>
         </form>
     </table>
-</div>'; 
+</div>';
 echo $output;

+ 6 - 6
main/forum/forumconfig.inc.php

@@ -1,4 +1,4 @@
-<?php  
+<?php
 /* For licensing terms, see /license.txt */
 
 /**
@@ -12,7 +12,7 @@
 
 
 /*
-	Database Variables
+    Database Variables
 */
 $table_categories 		= Database :: get_course_table(TABLE_FORUM_CATEGORY);
 $table_forums 			= Database :: get_course_table(TABLE_FORUM);
@@ -27,7 +27,7 @@ $table_item_property 	= Database :: get_course_table(TABLE_ITEM_PROPERTY);
 $table_users 			= Database :: get_main_table(TABLE_MAIN_USER);
 
 /*
-	Constants
+    Constants
 */
 define('TOOL_FORUM_CATEGORY','forum_category');
 //define('TOOL_FORUM','forum'); defined in main_api
@@ -36,8 +36,8 @@ define('TOOL_FORUM_POST','forum_post');
 define('TOOL_FORUM_ATTACH','forum_attachment');
 define('TOOL_FORUM_THREAD_QUALIFY','forum_thread_qualify');
 /*
-	Some configuration settings
-	(these can go to the dokeos config settings afterwards)
+    Some configuration settings
+    (these can go to the dokeos config settings afterwards)
 */
 // if this setting is true then an I-frame will be displayed when replying
 $forum_setting['show_thread_iframe_on_reply']=true;
@@ -49,4 +49,4 @@ $forum_setting['allow_sticky']=true;
 // when this setting is true there will be a column that displays the latest post (date and poster) of the given forum. This requires quite some sql statements that
 // might slow down the page with the fora.
 // note: I'm currently investigating how it would be possible to increase the performance of this part.
-$forum_setting['show_last_post']=false; 
+$forum_setting['show_last_post']=false;

File diff suppressed because it is too large
+ 489 - 489
main/forum/forumfunction.inc.php


+ 206 - 205
main/forum/forumqualify.php

@@ -2,10 +2,11 @@
 /* For licensing terms, see /license.txt */
 
 /**
-* 	@package chamilo.forum
-*/
+ * 	@package chamilo.forum
+ */
+
 // name of the language file that needs to be included
-$language_file=array('admin','forum');
+$language_file = array('admin', 'forum');
 require_once '../inc/global.inc.php';
 require_once 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
@@ -14,14 +15,14 @@ $this_section = SECTION_COURSES;
 
 $allowed_to_edit = api_is_allowed_to_edit(null,true);
 if (!$allowed_to_edit) {
-	api_not_allowed(true);
+    api_not_allowed(true);
 }
 
 //are we in a lp ?
 $origin = '';
 $origin_string='';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
 // including additional library scripts
@@ -31,19 +32,19 @@ include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
 $nameTools=get_lang('ToolForum');
 
 /*
-	Including necessary files
+    Including necessary files
 */
 
 $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/jquery.js" ></script>';
 $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
-										$(document).ready(function(){ $(\'.hide-me\').slideUp() });
-									function hidecontent(content){ $(content).slideToggle(\'normal\'); }
-									</script>';
+                                        $(document).ready(function(){ $(\'.hide-me\').slideUp() });
+                                    function hidecontent(content){ $(content).slideToggle(\'normal\'); }
+                                    </script>';
 /*
-		MAIN DISPLAY SECTION
+        MAIN DISPLAY SECTION
 */
 /*
-	Retrieving forum and forum categorie information
+    Retrieving forum and forum categorie information
 */
 // we are getting all the information about the current forum and forum category.
 // note pcool: I tried to use only one sql statement (and function) for this
@@ -54,246 +55,246 @@ $current_forum_category=get_forumcategory_information($current_forum['forum_cate
 $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
 /*
 -----------------------------------------------------------
-	Header and Breadcrumbs
+    Header and Breadcrumbs
 -----------------------------------------------------------
 */
 if (isset($_SESSION['gradebook'])){
-	$gradebook=	$_SESSION['gradebook'];
+    $gradebook=	$_SESSION['gradebook'];
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 if ($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	if (!empty($_SESSION['toolgroup'])) {
-
-		$_clean['toolgroup']=(int)$_SESSION['toolgroup'];
-		$group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
-		$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-		$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
-		$interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
-		if ($message<>'PostDeletedSpecial') {
-			$interbreadcrumb[]=array("url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
-		}
-		$interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
-		// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-		Display :: display_header('');
-		api_display_tool_title($nameTools);
-	} else {
-
-		$info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
-		$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => $nameTools);
-		$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum_category['cat_title']));
-
-		$interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
-
-		if ($message<>'PostDeletedSpecial') {
-			if (isset($_GET['gradebook']) and $_GET['gradebook']=='view') {
-				$info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
-				$interbreadcrumb[]=array("url" => "viewthread.php?forum=".$info_thread['forum_id']."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
-			} else {
-				$interbreadcrumb[]=array("url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
-			}
-		}
-		// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-		$interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
-		Display :: display_header('');
-		api_display_tool_title($nameTools);
-
-	}
+    if (!empty($_SESSION['toolgroup'])) {
+
+        $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
+        $group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
+        $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
+        $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
+        $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
+        if ($message<>'PostDeletedSpecial') {
+            $interbreadcrumb[]=array("url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
+        }
+        $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
+        // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
+        Display :: display_header('');
+        api_display_tool_title($nameTools);
+    } else {
+
+        $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
+        $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => $nameTools);
+        $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum_category['cat_title']));
+
+        $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
+
+        if ($message<>'PostDeletedSpecial') {
+            if (isset($_GET['gradebook']) and $_GET['gradebook']=='view') {
+                $info_thread=get_thread_information(Security::remove_XSS($_GET['thread']));
+                $interbreadcrumb[]=array("url" => "viewthread.php?forum=".$info_thread['forum_id']."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
+            } else {
+                $interbreadcrumb[]=array("url" => "viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => prepare4display($current_thread['thread_title']));
+            }
+        }
+        // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
+        $interbreadcrumb[]=array("url" => "#","name" => get_lang('QualifyThread'));
+        Display :: display_header('');
+        api_display_tool_title($nameTools);
+
+    }
 }
 
 /*
-	Is the user allowed here?
+    Is the user allowed here?
 */
 // if the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
 if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
 
 /*
-	Actions
+    Actions
 */
 if ($_GET['action']=='delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
-	$message=delete_post($_GET['id']); // note: this has to be cleaned first
+    $message=delete_post($_GET['id']); // note: this has to be cleaned first
 }
 if (($_GET['action']=='invisible' || $_GET['action']=='visible') && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
-	$message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
+    $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
 }
 if ($_GET['action']=='move' and isset($_GET['post'])) {
-	$message=move_post_form();
+    $message=move_post_form();
 }
 
 /*
-	Display the action messages
+    Display the action messages
 */
 if (!empty($message)) {
-	Display :: display_confirmation_message(get_lang($message));
+    Display :: display_confirmation_message(get_lang($message));
 }
 
 if ($message<>'PostDeletedSpecial') {// in this case the first and only post of the thread is removed
-	// this increases the number of times the thread has been viewed
-	increase_thread_view($_GET['thread']);
+    // this increases the number of times the thread has been viewed
+    increase_thread_view($_GET['thread']);
 
-	/*
-		Action Links
-	*/
+    /*
+        Action Links
+    */
 /*	echo '<div style="float:right;">';
-	$my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;origin='.$origin.'&amp;search='.Security::remove_XSS(urlencode($_GET['search']));
-	echo $my_url.'&amp;view=flat&origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
-	echo $my_url.'&amp;view=threaded&origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
-	echo $my_url.'&amp;view=nested&origin='.$origin.'">'.get_lang('NestedView').'</a>';
-	$my_url = null;
-	echo '</div>';*/
-	// the reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
-	// if one of the three levels is locked then the link should not be displayed
-	if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
-		// The link should only appear when the user is logged in or when anonymous posts are allowed.
-		if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
-			//reply link
-			/*echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.get_lang('ReplyToThread').'</a>';*/
-
-			//new thread link
-			if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
-				if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
-					echo '&nbsp;&nbsp;';
-					/*echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('new_thread.png','','','32').'</a>';*/
-				} else {
-					echo get_lang('ForumLocked');
-				}
-			}
-		}
-	}
-	// note: this is to prevent that some browsers display the links over the table (FF does it but Opera doesn't)
-	echo '&nbsp;';
-
-	/*	
-		Display Forum Category and the Forum information	
-	*/
-	if (!$_SESSION['view']) {
-		$viewmode=$current_forum['default_view'];
-	} else {
-		$viewmode=$_SESSION['view'];
-	}
-
-	$viewmode_whitelist=array('flat', 'threaded', 'nested');
-	if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
-		$viewmode=Database::escape_string($_GET['view']);
-		$_SESSION['view']=$viewmode;
-	}
-	if (empty($viewmode)) {
-		$viewmode = 'flat';
-	}
-
-	/*	
-		Display Forum Category and the Forum information	
-	*/
-	// we are getting all the information about the current forum and forum category.
-	// note pcool: I tried to use only one sql statement (and function) for this
-	// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
-	echo "<table class=\"data_table\" width=\"100%\">";
-
-	// the thread
-	echo "<tr><th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
-	echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
-
-	if ($origin!='learnpath') {
-		echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
-	}
-
-	echo prepare4display($current_forum['forum_title']).'<br />';
-	echo "</th>";
-	echo "</tr>";
-	echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
-	echo "</table>";
-
-	include_once('viewpost.inc.php');
+    $my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;origin='.$origin.'&amp;search='.Security::remove_XSS(urlencode($_GET['search']));
+    echo $my_url.'&amp;view=flat&origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
+    echo $my_url.'&amp;view=threaded&origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
+    echo $my_url.'&amp;view=nested&origin='.$origin.'">'.get_lang('NestedView').'</a>';
+    $my_url = null;
+    echo '</div>';*/
+    // the reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
+    // if one of the three levels is locked then the link should not be displayed
+    if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
+        // The link should only appear when the user is logged in or when anonymous posts are allowed.
+        if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
+            //reply link
+            /*echo '<a href="reply.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.get_lang('ReplyToThread').'</a>';*/
+
+            //new thread link
+            if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
+                if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
+                    echo '&nbsp;&nbsp;';
+                    /*echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('new_thread.png','','','32').'</a>';*/
+                } else {
+                    echo get_lang('ForumLocked');
+                }
+            }
+        }
+    }
+    // note: this is to prevent that some browsers display the links over the table (FF does it but Opera doesn't)
+    echo '&nbsp;';
+
+    /*
+        Display Forum Category and the Forum information
+    */
+    if (!$_SESSION['view']) {
+        $viewmode=$current_forum['default_view'];
+    } else {
+        $viewmode=$_SESSION['view'];
+    }
+
+    $viewmode_whitelist=array('flat', 'threaded', 'nested');
+    if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
+        $viewmode=Database::escape_string($_GET['view']);
+        $_SESSION['view']=$viewmode;
+    }
+    if (empty($viewmode)) {
+        $viewmode = 'flat';
+    }
+
+    /*
+        Display Forum Category and the Forum information
+    */
+    // we are getting all the information about the current forum and forum category.
+    // note pcool: I tried to use only one sql statement (and function) for this
+    // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
+    echo "<table class=\"data_table\" width=\"100%\">";
+
+    // the thread
+    echo "<tr><th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
+    echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
+
+    if ($origin!='learnpath') {
+        echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
+    }
+
+    echo prepare4display($current_forum['forum_title']).'<br />';
+    echo "</th>";
+    echo "</tr>";
+    echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
+    echo "</table>";
+
+    include_once('viewpost.inc.php');
 } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
 
 
 $userinf=api_get_user_info(api_get_user_id());
 if ($allowed_to_edit) {
-	//echo "<strong>".get_lang('QualifyThread')."</strong>";
-	//echo "<br />";
-	$current_thread=get_thread_information($_GET['thread']);
-	$userid=(int)$_GET['user_id'];
-	$threadid=$current_thread['thread_id'];
-	//show current qualify in my form
-	$qualify=current_qualify_of_thread($threadid,api_get_session_id());
-	//show max qualify in my form
-	$max_qualify=show_qualify('2',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
-	require_once 'forumbody.inc.php';
-	$value_return = store_theme_qualify($userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id(),date("Y-m-d H:i:s"),api_get_session_id());
-	$url='cidReq='.Security::remove_XSS($_GET['cidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&post='.Security::remove_XSS($_GET['post']).'&origin='.$origin.'&user_id='.Security::remove_XSS($_GET['user_id']);
-	$current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
-
-	if ($value_return[0]!=$_REQUEST['idtextqualify'] && $value_return[1]=='update') {
-		store_qualify_historical('1','',$_GET['forum'],$userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id());
-	}
-
-	if (!empty($_REQUEST['idtextqualify']) && $_REQUEST['idtextqualify'] > $max_qualify) {
-		$return_message = get_lang('QualificationCanNotBeGreaterThanMaxScore');
-		Display :: display_error_message($return_message,false);
-	}
-	// show qualifications history
-	$user_id_thread = (int)$_GET['user_id'];
-	$opt=Database::escape_string($_GET['type']);
-	$qualify_historic = get_historical_qualify($user_id_thread, $threadid, $opt);
-	$counter= count($qualify_historic);
-	$act_qualify = $_REQUEST['idtextqualify'];
-	if ($counter>0) {
-		if (isset($_GET['gradebook'])){
-			$view_gradebook='&gradebook=view';
-		}
-		echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
-		if ($_GET['type'] == 'false') {
-
-			echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:<a href="forumqualify.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.$threadid.'&user='.Security::remove_XSS($_GET['user']).'&user_id='.Security::remove_XSS($_GET['user_id']).'&type=true&idtextqualify='.$act_qualify.$view_gradebook.'#history">'.get_lang('MoreRecent').'</a>&nbsp;|
-					'.get_lang('Older').'
-				  </div>';
-		} else {
-			echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:'.get_lang('MoreRecent').' |
-					<a href="forumqualify.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.$threadid.'&user='.Security::remove_XSS($_GET['user']).'&user_id='.Security::remove_XSS($_GET['user_id']).'&type=false&idtextqualify='.$act_qualify.$view_gradebook.'#history">'.get_lang('Older').'</a>&nbsp;
-				  </div>';
-		}
-		$table_list.= '<a name="history" /><br /><br /><table class="data_table" style="width:100%">';
-		$table_list.= '<tr>';
-		$table_list.= '<th width="50%">'.get_lang('WhoChanged').'</th>';
-		$table_list.= '<th width="10%">'.get_lang('NoteChanged').'</th>';
-		$table_list.= '<th width="40%">'.get_lang('DateChanged').'</th>';
-		$table_list.= '</tr>';
-
-		for($i=0;$i<count($qualify_historic);$i++) {
-			    $my_user_info=api_get_user_info($qualify_historic[$i]['qualify_user_id']);
-				$name = api_get_person_name($my_user_info['firstName'], $my_user_info['lastName']);
-				$table_list.= '<tr class="'.$class.'"><td>'.$name.'</td>';
-				$table_list.= '<td>'.$qualify_historic[$i]['qualify'].'</td>';
-				$table_list.= '<td>'.$qualify_historic[$i]['qualify_time'].'</td></tr>';
-		}
-		$table_list.= '</table>';
-		echo $table_list;
-
-	} else {
-		echo get_lang('NotChanged');
-	}
+    //echo "<strong>".get_lang('QualifyThread')."</strong>";
+    //echo "<br />";
+    $current_thread=get_thread_information($_GET['thread']);
+    $userid=(int)$_GET['user_id'];
+    $threadid=$current_thread['thread_id'];
+    //show current qualify in my form
+    $qualify=current_qualify_of_thread($threadid,api_get_session_id());
+    //show max qualify in my form
+    $max_qualify=show_qualify('2',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
+    require_once 'forumbody.inc.php';
+    $value_return = store_theme_qualify($userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id(),date("Y-m-d H:i:s"),api_get_session_id());
+    $url='cidReq='.Security::remove_XSS($_GET['cidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&post='.Security::remove_XSS($_GET['post']).'&origin='.$origin.'&user_id='.Security::remove_XSS($_GET['user_id']);
+    $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
+
+    if ($value_return[0]!=$_REQUEST['idtextqualify'] && $value_return[1]=='update') {
+        store_qualify_historical('1','',$_GET['forum'],$userid,$threadid,$_REQUEST['idtextqualify'],api_get_user_id());
+    }
+
+    if (!empty($_REQUEST['idtextqualify']) && $_REQUEST['idtextqualify'] > $max_qualify) {
+        $return_message = get_lang('QualificationCanNotBeGreaterThanMaxScore');
+        Display :: display_error_message($return_message,false);
+    }
+    // show qualifications history
+    $user_id_thread = (int)$_GET['user_id'];
+    $opt=Database::escape_string($_GET['type']);
+    $qualify_historic = get_historical_qualify($user_id_thread, $threadid, $opt);
+    $counter= count($qualify_historic);
+    $act_qualify = $_REQUEST['idtextqualify'];
+    if ($counter>0) {
+        if (isset($_GET['gradebook'])){
+            $view_gradebook='&gradebook=view';
+        }
+        echo '<h4>'.get_lang('QualificationChangesHistory').'</h4>';
+        if ($_GET['type'] == 'false') {
+
+            echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:<a href="forumqualify.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.$threadid.'&user='.Security::remove_XSS($_GET['user']).'&user_id='.Security::remove_XSS($_GET['user_id']).'&type=true&idtextqualify='.$act_qualify.$view_gradebook.'#history">'.get_lang('MoreRecent').'</a>&nbsp;|
+                    '.get_lang('Older').'
+                  </div>';
+        } else {
+            echo '<div style="float:left; clear:left">'.get_lang('OrderBy').'&nbsp;:'.get_lang('MoreRecent').' |
+                    <a href="forumqualify.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.$threadid.'&user='.Security::remove_XSS($_GET['user']).'&user_id='.Security::remove_XSS($_GET['user_id']).'&type=false&idtextqualify='.$act_qualify.$view_gradebook.'#history">'.get_lang('Older').'</a>&nbsp;
+                  </div>';
+        }
+        $table_list.= '<a name="history" /><br /><br /><table class="data_table" style="width:100%">';
+        $table_list.= '<tr>';
+        $table_list.= '<th width="50%">'.get_lang('WhoChanged').'</th>';
+        $table_list.= '<th width="10%">'.get_lang('NoteChanged').'</th>';
+        $table_list.= '<th width="40%">'.get_lang('DateChanged').'</th>';
+        $table_list.= '</tr>';
+
+        for($i=0;$i<count($qualify_historic);$i++) {
+                $my_user_info=api_get_user_info($qualify_historic[$i]['qualify_user_id']);
+                $name = api_get_person_name($my_user_info['firstName'], $my_user_info['lastName']);
+                $table_list.= '<tr class="'.$class.'"><td>'.$name.'</td>';
+                $table_list.= '<td>'.$qualify_historic[$i]['qualify'].'</td>';
+                $table_list.= '<td>'.$qualify_historic[$i]['qualify_time'].'</td></tr>';
+        }
+        $table_list.= '</table>';
+        echo $table_list;
+
+    } else {
+        echo get_lang('NotChanged');
+    }
 } else {
-	api_not_allowed();
+    api_not_allowed();
 }
 
 /*
-		FOOTER
+        FOOTER
 */
 if ($origin!='learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 46 - 46
main/forum/forumsearch.php

@@ -2,33 +2,33 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@copyright Ghent University
-*
-* 	@package chamilo.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                       moderation of posts (approval)
+ *                       reply only forums (students cannot create new threads)
+ *                       multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @copyright Ghent University
+ *
+ *  @package chamilo.forum
+ */
 
 // name of the language file that needs to be included
-$language_file = array ('forum','group');
+$language_file = array ('forum', 'group');
 
 // including the global dokeos file
-require_once ('../inc/global.inc.php');
+require_once '../inc/global.inc.php';
 
 // the section (tabs)
-$this_section=SECTION_COURSES;
+$this_section = SECTION_COURSES;
 
 // notice for unauthorized people.
 api_protect_course_script(true);
@@ -36,53 +36,53 @@ api_protect_course_script(true);
 // including additional library scripts
 require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
 include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
-include('forumfunction.inc.php');
-include('forumconfig.inc.php');
+include 'forumfunction.inc.php';
+include 'forumconfig.inc.php';
 
 //are we in a lp ?
 $origin = '';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
 // name of the tool
-$nameTools=get_lang('ToolForum');
+$nameTools = get_lang('ToolForum');
 
 // breadcrumbs
 
 if (isset($_SESSION['gradebook'])){
-	$gradebook=	$_SESSION['gradebook'];
+    $gradebook = $_SESSION['gradebook'];
 }
 
-if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
-			'name' => get_lang('ToolGradebook')
-		);
+if (!empty($gradebook) && $gradebook == 'view') {
+    $interbreadcrumb[] = array (
+            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 if (!empty ($_GET['gidReq'])) {
-	$toolgroup = Database::escape_string($_GET['gidReq']);
-	api_session_register('toolgroup');
+    $toolgroup = Database::escape_string($_GET['gidReq']);
+    api_session_register('toolgroup');
 }
 
 if ($origin=='group') {
-	$_clean['toolgroup']=(int)$_SESSION['toolgroup'];
-	$group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
-	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
-	$interbreadcrumb[] = array ("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
-	$interbreadcrumb[]=array('url' => 'forumsearch.php','name' => get_lang('ForumSearch'));
+    $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
+    $group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
+    $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
+    $interbreadcrumb[] = array ("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;forum=".Security::remove_XSS($_GET['forum']),"name" => prepare4display($current_forum['forum_title']));
+    $interbreadcrumb[]=array('url' => 'forumsearch.php','name' => get_lang('ForumSearch'));
 } else {
-	$interbreadcrumb[]=array('url' => 'index.php?gradebook='.$gradebook.'','name' => $nameTools);
-	$interbreadcrumb[]=array('url' => 'forumsearch.php','name' => get_lang('ForumSearch'));
+    $interbreadcrumb[]=array('url' => 'index.php?gradebook='.$gradebook.'','name' => $nameTools);
+    $interbreadcrumb[]=array('url' => 'forumsearch.php','name' => get_lang('ForumSearch'));
 }
 
 // Display the header
-if ($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+if ($origin == 'learnpath') {
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	Display :: display_header($nameTools);
+    Display :: display_header($nameTools);
 }
 
 // Display the tool title
@@ -98,6 +98,6 @@ event_access_tool(TOOL_FORUM);
 forum_search();
 
 // footer
-if ($origin!='learnpath') {
-	Display :: display_footer();
+if ($origin != 'learnpath') {
+    Display :: display_footer();
 }

+ 79 - 91
main/forum/iframe_thread.php

@@ -2,51 +2,52 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@copyright Ghent University
-*
-* 	@package chamilo.forum
-*/
-/*
-		INIT SECTION
-*/
-/*
-	Language Initialisation
-*/
-// name of the language file that needs to be included
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @copyright Ghent University
+ *
+ * @package chamilo.forum
+ */
+
+/* INIT SECTION */
+
+/* Language Initialisation */
+
+// Name of the language file that needs to be included
 $language_file = 'forum';
-//$this_section=SECTION_COURSES;
+
+//$this_section = SECTION_COURSES;
+
 require_once '../inc/global.inc.php';
 
-/* ------------	ACCESS RIGHTS ------------ */
+/* ACCESS RIGHTS */
 
-// notice for unauthorized people.
+// A notice for unauthorized people.
 api_protect_course_script(true);
 
-require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
-include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
+require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
+include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 
-$nameTools=get_lang('ToolForum');
+$nameTools = get_lang('ToolForum');
 ?>
 <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
-	<title></title>
+    <title></title>
 <style type="text/css" media="screen, projection">
 /*<![CDATA[*/
 @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/<?php echo api_get_setting('stylesheets');?>/default.css";
@@ -56,78 +57,65 @@ $nameTools=get_lang('ToolForum');
 <body>
 <?php
 
-/*
------------------------------------------------------------
-	Including necessary files
------------------------------------------------------------
-*/
+/* Including necessary files */
+
 require 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
 
 
-/*
-==============================================================================
-		MAIN DISPLAY SECTION
-==============================================================================
-*/
-/*
------------------------------------------------------------
-	Retrieving forum and forum categorie information
------------------------------------------------------------
-*/
-// we are getting all the information about the current forum and forum category.
-// note pcool: I tried to use only one sql statement (and function) for this
-// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
-$current_thread=get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
-$current_forum=get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
+/* MAIN DISPLAY SECTION */
+
+/* Retrieving forum and forum categorie information */
+
+// We are getting all the information about the current forum and forum category.
+// Note pcool: I tried to use only one sql statement (and function) for this,
+// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
+$current_thread=get_thread_information($_GET['thread']); // Note: this has to be validated that it is an existing thread.
+$current_forum=get_forum_information($current_thread['forum_id']); // Note: this has to be validated that it is an existing forum.
 $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
 
-/*
------------------------------------------------------------
-	Is the user allowed here?
------------------------------------------------------------
-*/
+/* Is the user allowed here? */
+
 // if the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
-if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+if (!api_is_allowed_to_edit(false, true) AND ($current_forum['visibility'] == 0 OR $current_thread['visibility'] == 0)) {
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
-/*
-	Display Forum Category and the Forum information
-*/
-// we are getting all the information about the current forum and forum category.
-// note pcool: I tried to use only one sql statement (and function) for this
-// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
+/* Display Forum Category and the Forum information */
 
-$sql="SELECT * FROM $table_posts posts, $table_users users
-		WHERE posts.thread_id='".$current_thread['thread_id']."'
-		AND posts.poster_id=users.user_id
-		ORDER BY posts.post_id ASC";
-$result=Database::query($sql);
+// We are getting all the information about the current forum and forum category.
+// Note pcool: I tried to use only one sql statement (and function) for this,
+// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
+
+$sql = "SELECT * FROM $table_posts posts, $table_users users
+        WHERE posts.thread_id='".$current_thread['thread_id']."'
+        AND posts.poster_id=users.user_id
+        ORDER BY posts.post_id ASC";
+$result = Database::query($sql);
 
 echo "<table width=\"100%\" cellspacing=\"5\" border=\"0\">";
-while ($row=Database::fetch_array($result)) {
-	echo "<tr>";
-	echo "<td rowspan=\"2\" class=\"forum_message_left\">";
-	if ($row['user_id']=='0') {
-		$name=$row['poster_name'];
-	} else {
-		$name=api_get_person_name($row['firstname'], $row['lastname']);
-	}
-	echo $name.'<br />';
-	echo $row['post_date'].'<br /><br />';
-
-	echo "</td>";
-	echo "<td class=\"forum_message_post_title\">".Security::remove_XSS($row['post_title'])."</td>";
-	echo "</tr>";
-
-	echo "<tr>";
-	echo "<td class=\"forum_message_post_text\">".Security::remove_XSS($row['post_text'],STUDENT)."</td>";
-	echo "</tr>";
+while ($row = Database::fetch_array($result)) {
+    echo "<tr>";
+    echo "<td rowspan=\"2\" class=\"forum_message_left\">";
+    if ($row['user_id']=='0') {
+        $name = $row['poster_name'];
+    } else {
+        $name = api_get_person_name($row['firstname'], $row['lastname']);
+    }
+    echo $name.'<br />';
+    echo $row['post_date'].'<br /><br />';
+
+    echo "</td>";
+    echo "<td class=\"forum_message_post_title\">".Security::remove_XSS($row['post_title'])."</td>";
+    echo "</tr>";
+
+    echo "<tr>";
+    echo "<td class=\"forum_message_post_text\">".Security::remove_XSS($row['post_text'], STUDENT)."</td>";
+    echo "</tr>";
 }
 echo "</table>";
 

+ 345 - 345
main/forum/index.php

@@ -2,24 +2,24 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
+* These files are a complete rework of the forum. The database structure is
+* based on phpBB but all the code is rewritten. A lot of new functionalities
+* are added:
+* - forum categories and forums can be sorted up or down, locked or made invisible
+* - consistent and integrated forum administration
+* - forum options:     are students allowed to edit their post?
+*                      moderation of posts (approval)
+*                      reply only forums (students cannot create new threads)
+*                      multiple forums per group
+* - sticky messages
+* - new view option: nested view
+* - quoting a message
 *
-*	@Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@Copyright Ghent University
-*	@Copyright Patrick Cool
+* @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+* @Copyright Ghent University
+* @Copyright Patrick Cool
 *
-* 	@package chamilo.forum
+* @package chamilo.forum
 */
 
 // name of the language file that needs to be included
@@ -29,21 +29,21 @@ $language_file = 'forum';
 require_once '../inc/global.inc.php';
 $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/jquery.js" ></script>';
 $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
-	$(document).ready(function(){ $(\'.hide-me\').slideUp() });
-	function hidecontent(content){ $(content).slideToggle(\'normal\'); }
-	</script>';
+    $(document).ready(function(){ $(\'.hide-me\').slideUp() });
+    function hidecontent(content){ $(content).slideToggle(\'normal\'); }
+    </script>';
 $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
 
-		function advanced_parameters() {
-			if(document.getElementById(\'options\').style.display == \'none\') {
-					document.getElementById(\'options\').style.display = \'block\';
-					document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			} else {
-					document.getElementById(\'options\').style.display = \'none\';
-					document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			}
-		}
-	</script>';
+        function advanced_parameters() {
+            if(document.getElementById(\'options\').style.display == \'none\') {
+                    document.getElementById(\'options\').style.display = \'block\';
+                    document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            } else {
+                    document.getElementById(\'options\').style.display = \'none\';
+                    document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            }
+        }
+    </script>';
 // the section (tabs)
 $this_section=SECTION_COURSES;
 
@@ -56,31 +56,31 @@ require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 $nameTools=get_lang('Forums');
 
 /*
-	Including necessary files
+    Including necessary files
 */
 require_once 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
 
 /*
-		MAIN DISPLAY SECTION
+        MAIN DISPLAY SECTION
 */
 /*
-	Header
+    Header
 */
 
 if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
-	$_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
-	$gradebook=	$_SESSION['gradebook'];
+    $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
+    $gradebook=	$_SESSION['gradebook'];
 } elseif (empty($_GET['gradebook'])) {
-	unset($_SESSION['gradebook']);
-	$gradebook=	'';
+    unset($_SESSION['gradebook']);
+    $gradebook=	'';
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[] = array (
-		'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
-		'name' => get_lang('ToolGradebook')
-	);
+    $interbreadcrumb[] = array (
+        'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
+        'name' => get_lang('ToolGradebook')
+    );
 }
 
 $search_forum=isset($_GET['search']) ? Security::remove_XSS($_GET['search']) : '';
@@ -88,11 +88,11 @@ $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".$sear
 
 if (isset($_GET['action']) && $_GET['action']=='add' ) {
 
-	switch ($_GET['content']) {
-		case 'forum':	$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum', 'name' => get_lang('AddForum')); break;
-		case 'forumcategory':$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory', 'name' => get_lang('AddForumCategory'));break;
-		default: break;
-	}
+    switch ($_GET['content']) {
+        case 'forum':	$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum', 'name' => get_lang('AddForum')); break;
+        case 'forumcategory':$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory', 'name' => get_lang('AddForumCategory'));break;
+        default: break;
+    }
 }
 
 Display :: display_header('');
@@ -107,329 +107,329 @@ $form_count=0;
 
 
 /*
-	ACTIONS
+    ACTIONS
 */
 $get_actions=isset($_GET['action']) ? $_GET['action'] : '';
 if (api_is_allowed_to_edit(false,true)) {
-	handle_forum_and_forumcategories();
+    handle_forum_and_forumcategories();
 }
 
 // notification
 if (isset($_GET['action']) && $_GET['action'] == 'notify' AND isset($_GET['content']) AND isset($_GET['id'])) {
-	if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
-		api_not_allowed();
-	}
-	$return_message = set_notification($_GET['content'],$_GET['id']);
-	Display :: display_confirmation_message($return_message,false);
+    if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
+        api_not_allowed();
+    }
+    $return_message = set_notification($_GET['content'],$_GET['id']);
+    Display :: display_confirmation_message($return_message,false);
 }
 
-	get_whats_new();
-	$whatsnew_post_info = array();
-	$whatsnew_post_info = $_SESSION['whatsnew_post_info'];
-
-	/*
-	  			TRACKING
-	*/
-	event_access_tool(TOOL_FORUM);
-
-	/*
-			RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
-	note: we do this here just after het handling of the actions to be sure that we already incorporate the
-	latest changes
-	*/
-	// Step 1: We store all the forum categories in an array $forum_categories
-	$forum_categories=array();
-	$forum_categories_list=get_forum_categories();
-
-	// step 2: we find all the forums (only the visible ones if it is a student)
-	$forum_list	= array();
-	$forum_list	= get_forums();
-
-
-	/*
-			RETRIEVING ALL GROUPS AND THOSE OF THE USER
-
-	*/
-	// the groups of the user
-	$groups_of_user=array();
-	$groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
-	// all groups in the course (and sorting them as the id of the group = the key of the array
-	if (!api_is_anonymous()) {
-		$all_groups=GroupManager::get_group_list();
-		if(is_array($all_groups)) {
-			foreach ($all_groups as $group) {
-				$all_groups[$group['id']]=$group;
-			}
-		}
-	}
-
-	/*
-		CLEAN GROUP ID FOR AJAXFILEMANAGER
-	*/
-	if(isset($_SESSION['_gid'])) {
-		unset($_SESSION['_gid']);
+    get_whats_new();
+    $whatsnew_post_info = array();
+    $whatsnew_post_info = $_SESSION['whatsnew_post_info'];
+
+    /*
+                  TRACKING
+    */
+    event_access_tool(TOOL_FORUM);
+
+    /*
+            RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
+    note: we do this here just after het handling of the actions to be sure that we already incorporate the
+    latest changes
+    */
+    // Step 1: We store all the forum categories in an array $forum_categories
+    $forum_categories=array();
+    $forum_categories_list=get_forum_categories();
+
+    // step 2: we find all the forums (only the visible ones if it is a student)
+    $forum_list	= array();
+    $forum_list	= get_forums();
+
+
+    /*
+            RETRIEVING ALL GROUPS AND THOSE OF THE USER
+
+    */
+    // the groups of the user
+    $groups_of_user=array();
+    $groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
+    // all groups in the course (and sorting them as the id of the group = the key of the array
+    if (!api_is_anonymous()) {
+        $all_groups=GroupManager::get_group_list();
+        if(is_array($all_groups)) {
+            foreach ($all_groups as $group) {
+                $all_groups[$group['id']]=$group;
+            }
+        }
+    }
+
+    /*
+        CLEAN GROUP ID FOR AJAXFILEMANAGER
+    */
+    if(isset($_SESSION['_gid'])) {
+        unset($_SESSION['_gid']);
     }
 
-	/*
-		ACTION LINKS
-	*/
-		$session_id=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : false;
-		//if (api_is_allowed_to_edit() and !$_GET['action'])
-		echo '<div class="actions">';
-		echo '<span>'.search_link().'</span>';
-		if (api_is_allowed_to_edit(false,true)) {
-			echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory"> '.Display::return_icon('new_folder.png', get_lang('AddForumCategory'),'','32').'</a>';
-			if (is_array($forum_categories_list) and !empty($forum_categories_list)) {
-				echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum"> '.Display::return_icon('new_forum.png', get_lang('AddForum'),'','32').'</a>';
-			}
-			//echo ' | <a href="forum_migration.php">'.get_lang('MigrateForum').'</a>';
-		}
-		echo '</div>';
-
-	/*
-		Display Forum Categories and the Forums in it
-	*/
-
-	// Step 3: we display the forum_categories first
-	if (is_array($forum_categories_list)) {
-		foreach ($forum_categories_list as $forum_category_key => $forum_category) {
-            
+    /*
+        ACTION LINKS
+    */
+        $session_id=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : false;
+        //if (api_is_allowed_to_edit() and !$_GET['action'])
+        echo '<div class="actions">';
+        echo '<span>'.search_link().'</span>';
+        if (api_is_allowed_to_edit(false,true)) {
+            echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forumcategory"> '.Display::return_icon('new_folder.png', get_lang('AddForumCategory'),'','32').'</a>';
+            if (is_array($forum_categories_list) and !empty($forum_categories_list)) {
+                echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gradebook='.$gradebook.'&action=add&amp;content=forum"> '.Display::return_icon('new_forum.png', get_lang('AddForum'),'','32').'</a>';
+            }
+            //echo ' | <a href="forum_migration.php">'.get_lang('MigrateForum').'</a>';
+        }
+        echo '</div>';
+
+    /*
+        Display Forum Categories and the Forums in it
+    */
+
+    // Step 3: we display the forum_categories first
+    if (is_array($forum_categories_list)) {
+        foreach ($forum_categories_list as $forum_category_key => $forum_category) {
+
              // the forums in this category
             $forums_in_category=get_forums_in_category($forum_category['cat_id']);
-            
+
              echo '<table class="forum_table">';
 
-			//validacion when belongs to a session
-			$session_img = api_get_session_image($forum_category['session_id'], $_user['status']);
+            //validacion when belongs to a session
+            $session_img = api_get_session_image($forum_category['session_id'], $_user['status']);
 
-			if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum_category['session_name'])) {
-				$session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
-			} else {
-				$session_displayed = '';
-			}
+            if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum_category['session_name'])) {
+                $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
+            } else {
+                $session_displayed = '';
+            }
             echo '<thead>';
-			echo '<tr><th class="forum_head" colspan="5">';
-			echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.prepare4display($forum_category['cat_id']).'" '.class_visible_invisible(prepare4display($forum_category['visibility'])).'>'.prepare4display($forum_category['cat_title']).$session_displayed.'</a>'. $session_img .'<br />';
-
-			if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>'&nbsp;') {
-				echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
-			}
-			echo '</th>';
-
-			echo '<th style="vertical-align: top;" align="center" >';
-			if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($session_id)!=0)) {
-				echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=edit&amp;content=forumcategory&amp;id=".intval($forum_category['cat_id'])."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
-				echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=delete&amp;content=forumcategory&amp;id=".intval($forum_category['cat_id'])."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForumCategory"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-				display_visible_invisible_icon('forumcategory', prepare4display($forum_category['cat_id']), prepare4display($forum_category['visibility']));
-				display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id']), prepare4display($forum_category['locked']));
-				display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id']), $forum_categories_list);
-			}
-			echo '</th>';
-			echo '</tr>';            
+            echo '<tr><th class="forum_head" colspan="5">';
+            echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.prepare4display($forum_category['cat_id']).'" '.class_visible_invisible(prepare4display($forum_category['visibility'])).'>'.prepare4display($forum_category['cat_title']).$session_displayed.'</a>'. $session_img .'<br />';
+
+            if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>'&nbsp;') {
+                echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
+            }
+            echo '</th>';
+
+            echo '<th style="vertical-align: top;" align="center" >';
+            if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($session_id)!=0)) {
+                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=edit&amp;content=forumcategory&amp;id=".intval($forum_category['cat_id'])."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=delete&amp;content=forumcategory&amp;id=".intval($forum_category['cat_id'])."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForumCategory"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+                display_visible_invisible_icon('forumcategory', prepare4display($forum_category['cat_id']), prepare4display($forum_category['visibility']));
+                display_lock_unlock_icon('forumcategory',prepare4display($forum_category['cat_id']), prepare4display($forum_category['locked']));
+                display_up_down_icon('forumcategory',prepare4display($forum_category['cat_id']), $forum_categories_list);
+            }
+            echo '</th>';
+            echo '</tr>';
             echo '</thead>';
-            
-            if (!empty($forums_in_category)) { 
-
-			// step 4: the interim headers (for the forum)
-			echo '<tr class="forum_header">';
-			echo "<td colspan=\"2\">".get_lang('Forum')."</td>";
-			echo "<td>".get_lang('Topics')."</td>";
-			echo "<td>".get_lang('Posts')."</td>";
-			echo "<td>".get_lang('LastPosts')."</td>";
-			echo "<td>".get_lang('Actions')."</td>";
-			echo "</tr>";
-
-		
-            
-
-			// step 5: we display all the forums in this category.
-			$forum_count=0;
-                       
-                
-    			foreach ($forum_list as $key=>$forum) {
-    				// Here we clean the whatnew_post_info array a little bit because to display the icon we
-    				// test if $whatsnew_post_info[$forum['forum_id']] is empty or not.
-    				if (!empty($whatsnew_post_info)) {
-    					if (is_array(isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null)) {
-    						foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) {
-    							if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id]))	{
-    								unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]);
-    								unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]);
-    							}
-    						}
-    					}
-    				}
-                    
-    
-    				// note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key.
-    				if ($forum['forum_category'] == $forum_category['cat_id']) {
-    				// the forum has to be showed if
-    					// 1.v it is a not a group forum (teacher and student)
-    					// 2.v it is a group forum and it is public (teacher and student)
-    					// 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
-    					// if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed
-    					//if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
-    					//{
-    					$show_forum=false;
-    
-    					// SHOULD WE SHOW THIS PARTICULAR FORUM
-    					// you are teacher => show forum
-    
-    					if (api_is_allowed_to_edit(false,true)) {
-    						//echo 'teacher';
-    						$show_forum=true;
-    					} else {
-    						// you are not a teacher
-    						//echo 'student';
-    						// it is not a group forum => show forum (invisible forums are already left out see get_forums function)
-    						if ($forum['forum_of_group']=='0') {
-    							//echo '-gewoon forum';
-    							$show_forum=true;
-    						} else {
-    							// it is a group forum
-    							//echo '-groepsforum';
-    							// it is a group forum but it is public => show
-    							if ($forum['forum_group_public_private']=='public') {
-    								$show_forum=true;
-    								//echo '-publiek';
-    							} else if ($forum['forum_group_public_private']=='private') {
-    								// it is a group forum and it is private
-    								//echo '-prive';
-    								// it is a group forum and it is private but the user is member of the group
-    								if (in_array($forum['forum_of_group'],$groups_of_user)) {
-    									//echo '-is lid';
-    									$show_forum=true;
-    								} else {
-    									//echo '-is GEEN lid';
-    									$show_forum=false;
-    								}
-    							} else {
-    								$show_forum=false;
-    							}
-    
-    						}
-    					}
-    
-    					if ($show_forum) {
-    						$form_count++;
-    						$mywhatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']]: null;
-    						echo '<tr class="forum">';
-    
-    						// Showing the image
-    						if(!empty($forum['forum_image'])) {
-    
-    							$image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$forum['forum_image'];
-    							$image_size = api_getimagesize($image_path);
-    
-    							$img_attributes = '';
-    							if (!empty($image_size)) {
-    								if ($image_size[0] > 100 || $image_size[1] > 100) {
-    									//limit display width and height to 100px
-    									$img_attributes = 'width="100" height="100"';
-    								}
-    								echo "<img src=\"$image_path\" $img_attributes>";
-    							}
-    						}
-    						echo "</td>";
-    						echo "<td width=\"20\">";
-    
-    						if ($forum['forum_of_group']!=='0') {
-    							if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
-    								echo icon('../img/forumgroupnew.gif');
-    							} else {
-    								echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
-    							}
-    						} else {
-    							if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
-    								echo icon('../img/forum.gif', get_lang('Forum'));
-    							} else {
-    								echo icon('../img/forum.gif');
-    							}
-    						}
-    						echo "</td>";
-    
-    						//validacion when belongs to a session
-    						$session_img = api_get_session_image($forum['session_id'], $_user['status']);
-    
-    						if ($forum['forum_of_group'] <> '0') {
-    							$my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
-    							$my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
-    							$group_title = api_substr($my_all_groups_forum_name, 0, 30);
-    							$forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$forum['forum_of_group'].'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)' . $session_img;
-    						} else {
-    							$forum_title_group_addition = '';
-    						}
-    
-    						if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
-    							$session_displayed = ' ('.$forum['session_name'].')';
-    						} else {
-    							$session_displayed = '';
-    						}
-    						$forum['forum_of_group']==0?$groupid='':$groupid=$forum['forum_of_group'];
-    
-    
-    						echo "<td><a href=\"viewforum.php?".api_get_cidreq()."&gidReq=".intval($groupid)."&forum=".intval($forum['forum_id'])."\" ".class_visible_invisible(prepare4display($forum['visibility'])).">";
-    						//Forum title
-    
-    						echo prepare4display($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />';
+
+            if (!empty($forums_in_category)) {
+
+            // step 4: the interim headers (for the forum)
+            echo '<tr class="forum_header">';
+            echo "<td colspan=\"2\">".get_lang('Forum')."</td>";
+            echo "<td>".get_lang('Topics')."</td>";
+            echo "<td>".get_lang('Posts')."</td>";
+            echo "<td>".get_lang('LastPosts')."</td>";
+            echo "<td>".get_lang('Actions')."</td>";
+            echo "</tr>";
+
+
+
+
+            // step 5: we display all the forums in this category.
+            $forum_count=0;
+
+
+                foreach ($forum_list as $key=>$forum) {
+                    // Here we clean the whatnew_post_info array a little bit because to display the icon we
+                    // test if $whatsnew_post_info[$forum['forum_id']] is empty or not.
+                    if (!empty($whatsnew_post_info)) {
+                        if (is_array(isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null)) {
+                            foreach ($whatsnew_post_info[$forum['forum_id']] as $key_thread_id => $new_post_array) {
+                                if (empty($whatsnew_post_info[$forum['forum_id']][$key_thread_id]))	{
+                                    unset($whatsnew_post_info[$forum['forum_id']][$key_thread_id]);
+                                    unset($_SESSION['whatsnew_post_info'][$forum['forum_id']][$key_thread_id]);
+                                }
+                            }
+                        }
+                    }
+
+
+                    // note: this can be speeded up if we transform the $forum_list to an array that uses the forum_category as the key.
+                    if ($forum['forum_category'] == $forum_category['cat_id']) {
+                    // the forum has to be showed if
+                        // 1.v it is a not a group forum (teacher and student)
+                        // 2.v it is a group forum and it is public (teacher and student)
+                        // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
+                        // if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed
+                        //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
+                        //{
+                        $show_forum=false;
+
+                        // SHOULD WE SHOW THIS PARTICULAR FORUM
+                        // you are teacher => show forum
+
+                        if (api_is_allowed_to_edit(false,true)) {
+                            //echo 'teacher';
+                            $show_forum=true;
+                        } else {
+                            // you are not a teacher
+                            //echo 'student';
+                            // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
+                            if ($forum['forum_of_group']=='0') {
+                                //echo '-gewoon forum';
+                                $show_forum=true;
+                            } else {
+                                // it is a group forum
+                                //echo '-groepsforum';
+                                // it is a group forum but it is public => show
+                                if ($forum['forum_group_public_private']=='public') {
+                                    $show_forum=true;
+                                    //echo '-publiek';
+                                } else if ($forum['forum_group_public_private']=='private') {
+                                    // it is a group forum and it is private
+                                    //echo '-prive';
+                                    // it is a group forum and it is private but the user is member of the group
+                                    if (in_array($forum['forum_of_group'],$groups_of_user)) {
+                                        //echo '-is lid';
+                                        $show_forum=true;
+                                    } else {
+                                        //echo '-is GEEN lid';
+                                        $show_forum=false;
+                                    }
+                                } else {
+                                    $show_forum=false;
+                                }
+
+                            }
+                        }
+
+                        if ($show_forum) {
+                            $form_count++;
+                            $mywhatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']]) ? $whatsnew_post_info[$forum['forum_id']]: null;
+                            echo '<tr class="forum">';
+
+                            // Showing the image
+                            if(!empty($forum['forum_image'])) {
+
+                                $image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$forum['forum_image'];
+                                $image_size = api_getimagesize($image_path);
+
+                                $img_attributes = '';
+                                if (!empty($image_size)) {
+                                    if ($image_size[0] > 100 || $image_size[1] > 100) {
+                                        //limit display width and height to 100px
+                                        $img_attributes = 'width="100" height="100"';
+                                    }
+                                    echo "<img src=\"$image_path\" $img_attributes>";
+                                }
+                            }
+                            echo "</td>";
+                            echo "<td width=\"20\">";
+
+                            if ($forum['forum_of_group']!=='0') {
+                                if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
+                                    echo icon('../img/forumgroupnew.gif');
+                                } else {
+                                    echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
+                                }
+                            } else {
+                                if (is_array($mywhatsnew_post_info) and !empty($mywhatsnew_post_info)) {
+                                    echo icon('../img/forum.gif', get_lang('Forum'));
+                                } else {
+                                    echo icon('../img/forum.gif');
+                                }
+                            }
+                            echo "</td>";
+
+                            //validacion when belongs to a session
+                            $session_img = api_get_session_image($forum['session_id'], $_user['status']);
+
+                            if ($forum['forum_of_group'] <> '0') {
+                                $my_all_groups_forum_name = isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
+                                $my_all_groups_forum_id = isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
+                                $group_title = api_substr($my_all_groups_forum_name, 0, 30);
+                                $forum_title_group_addition = ' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$forum['forum_of_group'].'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)' . $session_img;
+                            } else {
+                                $forum_title_group_addition = '';
+                            }
+
+                            if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
+                                $session_displayed = ' ('.$forum['session_name'].')';
+                            } else {
+                                $session_displayed = '';
+                            }
+                            $forum['forum_of_group']==0?$groupid='':$groupid=$forum['forum_of_group'];
+
+
+                            echo "<td><a href=\"viewforum.php?".api_get_cidreq()."&gidReq=".intval($groupid)."&forum=".intval($forum['forum_id'])."\" ".class_visible_invisible(prepare4display($forum['visibility'])).">";
+                            //Forum title
+
+                            echo prepare4display($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />';
                             echo '<span class="forum_description">'.prepare4display($forum['forum_comment']).'</span>';
-    						echo '</td>';
-    						//$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
-    						// the number of topics and posts
-    						$number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : null;
-    						$number_posts  =isset($forum['number_of_posts']) ? $forum['number_of_posts'] : null;
-    						echo "<td>".$number_threads."</td>";
-    						echo "<td>".$number_posts."</td>";
-    						// the last post in the forum
-    						if ($forum['last_poster_name']<>'') {
-    							$name=$forum['last_poster_name'];
-    							$poster_id=0;
-    						} else {
-    							$name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
-    							$poster_id=$forum['last_poster_id'];
-    						}
-    						echo "<td nowrap=\"nowrap\">";
-    
-    						if (!empty($forum['last_post_id'])) {
-    							echo api_convert_and_format_date($forum['last_post_date'], null, date_default_timezone_get())."<br /> ".get_lang('By').' '.display_user_link($poster_id, $name);
-    						}
-    						echo "</td>";
-    						echo "<td nowrap=\"nowrap\" align=\"center\">";
-    						if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval($session_id)!=0)) {
-    							echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
-    							echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=delete&amp;content=forum&amp;id=".$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForum"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-    							display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility']);
-    							display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked']);
-    							display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
-    						}
-    						$iconnotify = 'send_mail.gif';
-    						$session_forum_noti=isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : false;
-    						if (is_array($session_forum_noti)) {
-    							if (in_array($forum['forum_id'],$session_forum_noti)) {
-    								$iconnotify = 'send_mail_checked.gif';
-    							}
-    						}
-    
-    						if (!api_is_anonymous()  && api_is_allowed_to_session_edit(false,true) ) {
-    							echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
-    						}
-    						echo "</td>";
-    						echo "</tr>";
-    					}
-    				}
-    			}
+                            echo '</td>';
+                            //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
+                            // the number of topics and posts
+                            $number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : null;
+                            $number_posts  =isset($forum['number_of_posts']) ? $forum['number_of_posts'] : null;
+                            echo "<td>".$number_threads."</td>";
+                            echo "<td>".$number_posts."</td>";
+                            // the last post in the forum
+                            if ($forum['last_poster_name']<>'') {
+                                $name=$forum['last_poster_name'];
+                                $poster_id=0;
+                            } else {
+                                $name = api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
+                                $poster_id=$forum['last_poster_id'];
+                            }
+                            echo "<td nowrap=\"nowrap\">";
+
+                            if (!empty($forum['last_post_id'])) {
+                                echo api_convert_and_format_date($forum['last_post_date'], null, date_default_timezone_get())."<br /> ".get_lang('By').' '.display_user_link($poster_id, $name);
+                            }
+                            echo "</td>";
+                            echo "<td nowrap=\"nowrap\" align=\"center\">";
+                            if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval($session_id)!=0)) {
+                                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+                                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=delete&amp;content=forum&amp;id=".$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForum"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+                                display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility']);
+                                display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked']);
+                                display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
+                            }
+                            $iconnotify = 'send_mail.gif';
+                            $session_forum_noti=isset($_SESSION['forum_notification']['forum']) ? $_SESSION['forum_notification']['forum'] : false;
+                            if (is_array($session_forum_noti)) {
+                                if (in_array($forum['forum_id'],$session_forum_noti)) {
+                                    $iconnotify = 'send_mail_checked.gif';
+                                }
+                            }
+
+                            if (!api_is_anonymous()  && api_is_allowed_to_session_edit(false,true) ) {
+                                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&gradebook=$gradebook&action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
+                            }
+                            echo "</td>";
+                            echo "</tr>";
+                        }
+                    }
+                }
             } else {
-			//if (count($forum_list)==0) {
-				echo "<tr><td>".get_lang('NoForumInThisCategory')."</td>".(api_is_allowed_to_edit(false,true)?'<td colspan="6"></td>':'<td colspan="6"></td>')."</tr>";
-			//}
+            //if (count($forum_list)==0) {
+                echo "<tr><td>".get_lang('NoForumInThisCategory')."</td>".(api_is_allowed_to_edit(false,true)?'<td colspan="6"></td>':'<td colspan="6"></td>')."</tr>";
+            //}
             }
             echo '</table>';
-		}
-        
-	}
-	//echo "</table>";
+        }
+
+    }
+    //echo "</table>";
 
 /*
-		FOOTER
+        FOOTER
 */
 Display :: display_footer();

+ 109 - 135
main/forum/newthread.php

@@ -2,25 +2,25 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@Copyright Ghent University
-*	@Copyright Patrick Cool
-*
-* 	@package dokeos.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @Copyright Ghent University
+ * @Copyright Patrick Cool
+ *
+ * @package chamilo.forum
+ */
 
 // name of the language file that needs to be included
 $language_file = array('forum','document');
@@ -39,114 +39,95 @@ api_protect_course_script(true);
 require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
 require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
 
-$nameTools	= get_lang('ToolForum');
+$nameTools = get_lang('ToolForum');
+
+/* Including necessary files */
 
-/*
------------------------------------------------------------
-	Including necessary files
------------------------------------------------------------
-*/
 require_once 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
 
 //are we in a lp ?
 $origin = '';
 if(isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
 // javascript
 $htmlHeadXtra[] = '<script>
 
-		function advanced_parameters() {
-				if(document.getElementById(\'id_qualify\').style.display == \'none\') {
-				document.getElementById(\'id_qualify\').style.display = \'block\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+        function advanced_parameters() {
+                if(document.getElementById(\'id_qualify\').style.display == \'none\') {
+                document.getElementById(\'id_qualify\').style.display = \'block\';
+                document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
 
-			} else {
-				document.getElementById(\'id_qualify\').style.display = \'none\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			}
-		}
+            } else {
+                document.getElementById(\'id_qualify\').style.display = \'none\';
+                document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            }
+        }
 </script>';
-/*
-==============================================================================
-		MAIN DISPLAY SECTION
-==============================================================================
-*/
-/*
------------------------------------------------------------
-	Retrieving forum and forum categorie information
------------------------------------------------------------
-*/
+
+/* MAIN DISPLAY SECTION */
+
+/* Retrieving forum and forum categorie information */
+
 $current_forum=get_forum_information($_GET['forum']); // note: this has to be validated that it is an existing forum.
 $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
 
-/*
------------------------------------------------------------
-	Breadcrumbs
------------------------------------------------------------
-*/
+/* Breadcrumbs */
 
 if (isset($_SESSION['gradebook'])){
-	$gradebook = Security::remove_XSS($_SESSION['gradebook']);
+    $gradebook = Security::remove_XSS($_SESSION['gradebook']);
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 if (!empty($_GET['gidReq'])) {
-	$toolgroup = intval($_GET['gidReq']);
-	api_session_register('toolgroup');
+    $toolgroup = intval($_GET['gidReq']);
+    api_session_register('toolgroup');
 }
 
 $session_toolgroup = 0;
 if ($origin=='group') {
-	$session_toolgroup = intval($_SESSION['toolgroup']);
-	$group_properties  = GroupManager :: get_group_properties($session_toolgroup);
-	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$session_toolgroup, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
-	$interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$session_toolgroup."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
-	$interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
+    $session_toolgroup = intval($_SESSION['toolgroup']);
+    $group_properties  = GroupManager :: get_group_properties($session_toolgroup);
+    $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$session_toolgroup, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
+    $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&amp;gidReq=".$session_toolgroup."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
+    $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
 } else {
-	$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
-	$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
-	$interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
-	$interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
+    $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
+    $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
+    $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
+    $interbreadcrumb[]=array("url" => "newthread.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => get_lang('NewTopic'));
 }
-/*
------------------------------------------------------------
-	Resource Linker
------------------------------------------------------------
-*/
+
+/* Resource Linker */
+
 if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
-	$_SESSION['formelements']	= $_POST;
-	$_SESSION['origin']			= $_SERVER['REQUEST_URI'];
-	$_SESSION['breadcrumbs']	= $interbreadcrumb;
-	header("Location: ../resourcelinker/resourcelinker.php");
+    $_SESSION['formelements']	= $_POST;
+    $_SESSION['origin']			= $_SERVER['REQUEST_URI'];
+    $_SESSION['breadcrumbs']	= $interbreadcrumb;
+    header("Location: ../resourcelinker/resourcelinker.php");
 }
 
-/*
------------------------------------------------------------
-	Header
------------------------------------------------------------
-*/
+/* Header */
+
 if($origin=='learnpath') {
-	require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
+    require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
 } else {
-	Display :: display_header(null);
-	//api_display_tool_title($nameTools);
+    Display :: display_header(null);
+    //api_display_tool_title($nameTools);
 }
-/*
------------------------------------------------------------
-	Is the user allowed here?
------------------------------------------------------------
-*/
-// the user is not allowed here if:
+
+/* Is the user allowed here? */
+
+// The user is not allowed here if:
 // 1. the forumcategory or forum is invisible (visibility==0) and the user is not a course manager
 // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
 // 3. new threads are not allowed and the user is not a course manager
@@ -154,86 +135,79 @@ if($origin=='learnpath') {
 // I have split this is several pieces for clarity.
 
 if (!api_is_allowed_to_edit(false,true) && (($current_forum_category['visibility']==0 || $current_forum['visibility']==0))) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 // 2. the forumcategory or forum is locked (locked <>0) and the user is not a course manager
 if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 // 3. new threads are not allowed and the user is not a course manager
 if (!api_is_allowed_to_edit(false,true) AND $current_forum['allow_new_threads']<>1) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 // 4. anonymous posts are not allowed and the user is not logged in
 if (!$_user['user_id']  AND $current_forum['allow_anonymous']<>1) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
-/*
------------------------------------------------------------
-	Display forms / Feedback Messages
------------------------------------------------------------
-*/
+/* Display forms / Feedback Messages */
+
 handle_forum_and_forumcategories();
 // action links
 echo '<div class="actions">';
 echo '<span style="float:right;">'.search_link().'</span>';
 
-if ($origin=='group') {	
-	echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';	
+if ($origin=='group') {
+    echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
 }
 else{
-	echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
+    echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
 }
 echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin=group">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
 echo '</div>';
 
-/*
------------------------------------------------------------
-	Display Forum Category and the Forum information
------------------------------------------------------------
-*/
+/* Display Forum Category and the Forum information */
+
 echo "<table class=\"data_table\" width='100%'>\n";
 
 if ($origin != 'learnpath') {
-	echo "<tr>\n<th align=\"left\"  colspan=\"2\">";
+    echo "<tr>\n<th align=\"left\"  colspan=\"2\">";
 
-	echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
+    echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
 
-	if (!empty ($current_forum['forum_comment'])) {
-		echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
-	}
+    if (!empty ($current_forum['forum_comment'])) {
+        echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
+    }
 
-	if (!empty ($current_forum_category['cat_title'])) {
-		echo '<br /><span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])."</span><br />";
-	}
-	echo "</th>\n";
-	echo "</tr>\n";
+    if (!empty ($current_forum_category['cat_title'])) {
+        echo '<br /><span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])."</span><br />";
+    }
+    echo "</th>\n";
+    echo "</tr>\n";
 }
 echo '</table>';
 
 $values=show_add_post_form('newthread','', isset($_SESSION['formelements'])?$_SESSION['formelements']:null);
 
 if (!empty($values) and isset($values['SubmitPost'])) {
-	//add new thread in table forum_thread
-	store_thread($values);
+    //add new thread in table forum_thread
+    store_thread($values);
 }
 
-/*
-		FOOTER
-*/
+/* FOOTER */
+
 if ($origin!='learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 85 - 84
main/forum/reply.php

@@ -1,21 +1,21 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-* 	@package chamilo.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @package chamilo.forum
+ */
 
 // name of the language file that needs to be included
 $language_file = array('forum','document');
@@ -32,12 +32,12 @@ api_protect_course_script(true);
 // including additional library scripts
 require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
 require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
-$nameTools=get_lang('ToolForum');
+$nameTools = get_lang('ToolForum');
 
 $origin = '';
-if(isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
-	$origin_string = '&origin='.$origin;
+if (isset($_GET['origin'])) {
+    $origin =  Security::remove_XSS($_GET['origin']);
+    $origin_string = '&origin='.$origin;
 }
 
 /* Including necessary files */
@@ -47,19 +47,20 @@ require_once 'forumfunction.inc.php';
 // javascript
 $htmlHeadXtra[] = '<script>
 
-		function advanced_parameters() {
-			if(document.getElementById(\'id_qualify\').style.display == \'none\') {
-				document.getElementById(\'id_qualify\').style.display = \'block\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+        function advanced_parameters() {
+            if(document.getElementById(\'id_qualify\').style.display == \'none\') {
+                document.getElementById(\'id_qualify\').style.display = \'block\';
+                document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
 
-			} else {
-				document.getElementById(\'id_qualify\').style.display = \'none\';
-				document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			}
-		}
+            } else {
+                document.getElementById(\'id_qualify\').style.display = \'none\';
+                document.getElementById(\'img_plus_and_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            }
+        }
 </script>';
 
 /* MAIN DISPLAY SECTION */
+
 /* Retrieving forum and forum categorie information */
 // We are getting all the information about the current forum and forum category.
 // note pcool: I tried to use only one sql statement (and function) for this
@@ -70,45 +71,45 @@ $current_forum_category = get_forumcategory_information(Security::remove_XSS($cu
 
 /* Breadcrumbs */
 if (isset($_SESSION['gradebook'])){
-	$gradebook = Security::remove_XSS($_SESSION['gradebook']);
+    $gradebook = Security::remove_XSS($_SESSION['gradebook']);
 }
 
 if (!empty($gradebook) && $gradebook == 'view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 if ($origin=='group') {
-	$_clean['toolgroup']=(int)$_SESSION['toolgroup'];
-	$group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
-	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
-	$interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
-	$interbreadcrumb[]=array("url" => "viewthread.php?origin=".$origin."&gradebook=".$gradebook."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => $current_thread['thread_title']);
-	$interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
+    $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
+    $group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
+    $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] = array ("url" => "../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
+    $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
+    $interbreadcrumb[]=array("url" => "viewthread.php?origin=".$origin."&gradebook=".$gradebook."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => $current_thread['thread_title']);
+    $interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
 } else {
-	$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
-	$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
-	$interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
-	$interbreadcrumb[]=array("url" => "viewthread.php?origin=".$origin."&gradebook=".$gradebook."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => $current_thread['thread_title']);
-	$interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
+    $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook","name" => $nameTools);
+    $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id'],"name" => $current_forum_category['cat_title']);
+    $interbreadcrumb[]=array("url" => "viewforum.php?origin=".$origin."&forum=".Security::remove_XSS($_GET['forum']),"name" => $current_forum['forum_title']);
+    $interbreadcrumb[]=array("url" => "viewthread.php?origin=".$origin."&gradebook=".$gradebook."&forum=".Security::remove_XSS($_GET['forum'])."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => $current_thread['thread_title']);
+    $interbreadcrumb[]=array("url" => "javascript: void(0);","name" => get_lang('Reply'));
 }
 /* Resource Linker */
 if (isset($_POST['add_resources']) AND $_POST['add_resources']==get_lang('Resources')) {
-	$_SESSION['formelements']  = $_POST;
-	$_SESSION['origin']        = $_SERVER['REQUEST_URI'];
-	$_SESSION['breadcrumbs']   = $interbreadcrumb;
-	header("Location: ../resourcelinker/resourcelinker.php");
+    $_SESSION['formelements']  = $_POST;
+    $_SESSION['origin']        = $_SERVER['REQUEST_URI'];
+    $_SESSION['breadcrumbs']   = $interbreadcrumb;
+    header("Location: ../resourcelinker/resourcelinker.php");
 }
 /* Header */
 if($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-	Display :: display_header('');
-	api_display_tool_title($nameTools);
+    // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
+    Display :: display_header('');
+    api_display_tool_title($nameTools);
 }
 /* Is the user allowed here? */
 // The user is not allowed here if
@@ -119,42 +120,42 @@ if($origin=='learnpath') {
 // I have split this is several pieces for clarity.
 //if (!api_is_allowed_to_edit() AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0) OR ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)))
 if (!api_is_allowed_to_edit(false,true) AND (($current_forum_category['visibility']==0 OR $current_forum['visibility']==0))) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['locked']<>0 OR $current_forum['locked']<>0 OR $current_thread['locked']<>0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 if (!$_user['user_id'] AND $current_forum['allow_anonymous']==0) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 /* Action links */
 if ($origin != 'learnpath') {
-	echo '<div class="actions">';
-	echo '<span style="float:right;">'.search_link().'</span>';
-	if ($origin=='group') {	
-		echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
-	}
-	else{
-		echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
-		
-	}
-	echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin='.$origin.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
-	echo '<a href="viewthread.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin='.$origin.'">'.Display::return_icon('thread.png',get_lang('BackToThread'),'','32').'</a>';
-	
-	echo '</div>';
+    echo '<div class="actions">';
+    echo '<span style="float:right;">'.search_link().'</span>';
+    if ($origin=='group') {
+        echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
+    }
+    else{
+        echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
+
+    }
+    echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin='.$origin.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
+    echo '<a href="viewthread.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&origin='.$origin.'">'.Display::return_icon('thread.png',get_lang('BackToThread'),'','32').'</a>';
+
+    echo '</div>';
 } else {
-	echo '<div style="height:15px">&nbsp;</div>';
+    echo '<div style="height:15px">&nbsp;</div>';
 }
-/* Display Forum Category and the Forum information */ 
+/* Display Forum Category and the Forum information */
 echo "<table class=\"data_table\" width='100%'>\n";
 
 // the forum category
@@ -162,7 +163,7 @@ echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"2\">"
 echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
 
 if (!empty ($current_forum_category['cat_title'])) {
-	echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])." - </span>";
+    echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])." - </span>";
 }
 echo "</th>\n";
 echo "\t</tr>\n";
@@ -176,9 +177,9 @@ $my_elements = isset($_SESSION['formelements']) ? $_SESSION['formelements'] : ''
 $values      = show_add_post_form($my_action,$my_post, $my_elements); // note: this has to be cleaned first
 
 if (!empty($values) AND isset($_POST['SubmitPost'])) {
-	store_reply($values);
+    store_reply($values);
 }
 
-if($origin!='learnpath') {
-	Display :: display_footer();
+if ($origin!='learnpath') {
+    Display :: display_footer();
 }

+ 297 - 298
main/forum/viewforum.php

@@ -2,25 +2,25 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@Copyright Ghent University
-*	@Copyright Patrick Cool
-*
-* 	@package chamilo.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @Copyright Ghent University
+ * @Copyright Patrick Cool
+ *
+ *  @package chamilo.forum
+ */
 
 // name of the language file that needs to be included
 $language_file = array ('forum','group');
@@ -44,12 +44,12 @@ $nameTools=get_lang('ToolForum');
 $origin = '';
 $origin_string='';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
-	$origin_string = '&origin='.$origin;
+    $origin =  Security::remove_XSS($_GET['origin']);
+    $origin_string = '&origin='.$origin;
 }
 
 /*
-	Including necessary files
+    Including necessary files
 */
 require 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
@@ -58,12 +58,12 @@ $userid=api_get_user_id();
 $userinf=api_get_user_info($userid);
 
 /*
-		MAIN DISPLAY SECTION
+        MAIN DISPLAY SECTION
 */
 
 
 /*
-	Retrieving forum and forum categorie information
+    Retrieving forum and forum categorie information
 */
 // we are getting all the information about the current forum and forum category.
 // note pcool: I tried to use only one sql statement (and function) for this
@@ -74,266 +74,266 @@ $my_forum=isset($_GET['forum'])?$_GET['forum']:'';
 $val=GroupManager::user_has_access($userid,$my_forum_group,GROUP_TOOL_FORUM);
 
 if(!empty($my_forum_group)){
-		if (api_is_allowed_to_edit(false, true) || $val) {
-			$current_forum=get_forum_information($my_forum); // note: this has to be validated that it is an existing forum.
-			$current_forum_category=get_forumcategory_information($current_forum['forum_category']);
-		}
+        if (api_is_allowed_to_edit(false, true) || $val) {
+            $current_forum=get_forum_information($my_forum); // note: this has to be validated that it is an existing forum.
+            $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
+        }
 } else {
-	$result=get_forum_information($my_forum);
-	if($result['forum_of_group']==0){
-		$current_forum=get_forum_information($my_forum); // note: this has to be validated that it is an existing forum.
-		$current_forum_category=get_forumcategory_information($current_forum['forum_category']);
-	}
+    $result=get_forum_information($my_forum);
+    if($result['forum_of_group']==0){
+        $current_forum=get_forum_information($my_forum); // note: this has to be validated that it is an existing forum.
+        $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
+    }
 }
 
 
 /*
-	Header and Breadcrumbs
+    Header and Breadcrumbs
 */
 $my_search=isset($_GET['search'])?$_GET['search']:'';
 $my_action=isset($_GET['action'])?$_GET['action']:'';
 
 if (isset($_SESSION['gradebook'])){
-	$gradebook=	$_SESSION['gradebook'];
+    $gradebook=	$_SESSION['gradebook'];
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 if (!empty($_GET['gidReq'])) {
-	$toolgroup = Database::escape_string($_GET['gidReq']);
-	api_session_register('toolgroup');
+    $toolgroup = Database::escape_string($_GET['gidReq']);
+    api_session_register('toolgroup');
 }
 
 if ($origin=='group') {
-	$_clean['toolgroup']=(int)$_SESSION['toolgroup'];
-	$group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
-	$interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
-	//$interbreadcrumb[]=array("url" => "index.php?search=".Security::remove_XSS($my_search),"name" => $nameTools);
-	//$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => prepare4display($current_forum_category['cat_title']));
-	$interbreadcrumb[]=array("url" => "#","name" => get_lang('Forum').' '.Security::remove_XSS($current_forum['forum_title']));
+    $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
+    $group_properties  = GroupManager :: get_group_properties($_clean['toolgroup']);
+    $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
+    //$interbreadcrumb[]=array("url" => "index.php?search=".Security::remove_XSS($my_search),"name" => $nameTools);
+    //$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => prepare4display($current_forum_category['cat_title']));
+    $interbreadcrumb[]=array("url" => "#","name" => get_lang('Forum').' '.Security::remove_XSS($current_forum['forum_title']));
 
 //viewforum.php?forum=".Security::remove_XSS($my_forum)."&amp;origin=".$origin."&amp;gidReq=".$_SESSION['toolgroup']."&amp;search=".Security::remove_XSS(urlencode($my_search)),
 
 } else {
-	$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS($my_search),"name" => $nameTools);
-	$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => prepare4display($current_forum_category['cat_title']));
-	$interbreadcrumb[]=array("url" => "#","name" => Security::remove_XSS($current_forum['forum_title']));
-	//viewforum.php?forum=".Security::remove_XSS($my_forum)."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search))
+    $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS($my_search),"name" => $nameTools);
+    $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => prepare4display($current_forum_category['cat_title']));
+    $interbreadcrumb[]=array("url" => "#","name" => Security::remove_XSS($current_forum['forum_title']));
+    //viewforum.php?forum=".Security::remove_XSS($my_forum)."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search))
 }
 
 if ($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-	Display :: display_header('');
-	//api_display_tool_title($nameTools);
+    // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
+    Display :: display_header('');
+    //api_display_tool_title($nameTools);
 }
 
 /*
-	Actions
+    Actions
 */
-$table_link 			= Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
+$table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 // Change visibility of a forum or a forum category
 if (($my_action=='invisible' OR $my_action=='visible') AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true) && api_is_allowed_to_session_edit(false,true)) {
-	$message=change_visibility($_GET['content'], $_GET['id'],$_GET['action']);// note: this has to be cleaned first
+    $message=change_visibility($_GET['content'], $_GET['id'],$_GET['action']);// note: this has to be cleaned first
 }
 // locking and unlocking
 if (($my_action=='lock' OR $my_action=='unlock') AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true) && api_is_allowed_to_session_edit(false,true)) {
-	$message=change_lock_status($_GET['content'], $_GET['id'],$my_action);// note: this has to be cleaned first
+    $message=change_lock_status($_GET['content'], $_GET['id'],$my_action);// note: this has to be cleaned first
 }
 // deleting
 if ($my_action=='delete'  AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true) && api_is_allowed_to_session_edit(false,true)) {
-	$message=delete_forum_forumcategory_thread($_GET['content'],$_GET['id']); // note: this has to be cleaned first
-	//delete link
-	$sql_link='DELETE FROM '.$table_link.' WHERE ref_id='.intval($_GET['id']).' and type=5 and course_code="'.api_get_course_id().'";';
-	Database::query($sql_link);
+    $message=delete_forum_forumcategory_thread($_GET['content'],$_GET['id']); // note: this has to be cleaned first
+    //delete link
+    $sql_link='DELETE FROM '.$table_link.' WHERE ref_id='.intval($_GET['id']).' and type=5 and course_code="'.api_get_course_id().'";';
+    Database::query($sql_link);
 }
 // moving
 if ($my_action=='move' and isset($_GET['thread']) AND api_is_allowed_to_edit(false,true) && api_is_allowed_to_session_edit(false,true)) {
-	$message=move_thread_form();
+    $message=move_thread_form();
 }
 // notification
 if ($my_action == 'notify' AND isset($_GET['content']) AND isset($_GET['id']) && api_is_allowed_to_session_edit(false,true)) {
-	$return_message = set_notification($_GET['content'],$_GET['id']);
-	Display :: display_confirmation_message($return_message,false);
+    $return_message = set_notification($_GET['content'],$_GET['id']);
+    Display :: display_confirmation_message($return_message,false);
 }
 
 // student list
 
 if ($my_action == 'liststd' AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit(null,true)) {
 
-	switch($_GET['list']) {
-		case "qualify":
-			$student_list=get_thread_users_qualify($_GET['id']);
-			$nrorow3 =-2;
-			break;
-		case "notqualify":
-			$student_list=get_thread_users_not_qualify($_GET['id']);
-			$nrorow3 =-2;
-			break;
-		default:
-			$student_list=get_thread_users_details($_GET['id']);
-			$nrorow3 = Database::num_rows($student_list);
-			break;
-	}
-	$table_list = '<p><br /><h3>'.get_lang('ThreadUsersList').'&nbsp;:'.get_name_thread_by_id($_GET['id']).'</h3>';
-	if ($nrorow3>0 || $nrorow3==-2) {
-		$url = 'cidReq='.Security::remove_XSS($_GET['cidReq']).'&forum='.Security::remove_XSS($my_forum).'&action='.Security::remove_XSS($_GET['action']).'&content='.Security::remove_XSS($_GET['content'],STUDENT).'&id='.Security::remove_XSS($_GET['id']);
-		$table_list.= '<br />
-				 <div style="width:50%">
-				 <table class="data_table" border="0">
-					<tr>
-						<th height="22"><a href="viewforum.php?'.$url.'&origin='.$origin.'&list=all">'.get_lang('AllStudents').'</a></th>
-						<th><a href="viewforum.php?'.$url.'&origin='.$origin.'&list=qualify">'.get_lang('StudentsQualified').'</a></th>
-						<th><a href="viewforum.php?'.$url.'&origin='.$origin.'&list=notqualify">'.get_lang('StudentsNotQualified').'</a></th>
-					</tr>
-				 </table></div>
-				 <div style="border:1px solid gray; width:99%; margin-top:5px; padding:4px; float:left">
-				 ';
-
-		$icon_qualify = 'blog_new.gif';
-		$table_list.= '<center><br /><table class="data_table" style="width:50%">';
-		// The column headers (to do: make this sortable)
-		$table_list.= '<tr >';
-		$table_list.= '<th height="24">'.get_lang('NamesAndLastNames').'</th>';
-
-		if ($_GET['list']=='qualify') {
-			$table_list.= '<th>'.get_lang('Qualification').'</th>';
-		}
-		if (api_is_allowed_to_edit(null,true)) {
-			$table_list.= '<th>'.get_lang('Qualify').'</th>';
-		}
-		$table_list.= '</tr>';
-		$max_qualify=show_qualify('2',$_GET['cidReq'],$my_forum,$userid,$_GET['id']);
-		$counter_stdlist=0;
-
-		if (Database::num_rows($student_list)>0) {
-			while ($row_student_list=Database::fetch_array($student_list)) {
-				if ($counter_stdlist%2==0) {
-						 $class_stdlist="row_odd";
-				} else {
-						$class_stdlist="row_even";
-				}
-				$name_user_theme = 	api_get_person_name($row_student_list['firstname'], $row_student_list['lastname']);
-				$table_list.= '<tr class="$class_stdlist"><td><a href="../user/userInfo.php?uInfo='.$row_student_list['user_id'].'&tipo=sdtlist&'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($my_forum).$origin_string.'">'.$name_user_theme.'</a></td>';
-				if ($_GET['list']=='qualify') {
-					$table_list.= '<td>'.$row_student_list['qualify'].'/'.$max_qualify.'</td>';
-				}
-				if (api_is_allowed_to_edit(null,true)) {
-					$current_qualify_thread=show_qualify('1',$_GET['cidReq'],$my_forum,$row_student_list['user_id'],$_GET['id']);
-					$table_list.= '<td><a href="forumqualify.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($my_forum).'&thread='.Security::remove_XSS($_GET['id']).'&user='.$row_student_list['user_id'].'&user_id='.$row_student_list['user_id'].'&idtextqualify='.$current_qualify_thread.'&origin='.$origin.'">'.icon('../img/'.$icon_qualify,get_lang('Qualify')).'</a></td></tr>';
-				}
-				$counter_stdlist++;
-			}
-		} else {
-			if ($_GET['list']=='qualify'){
-				$table_list.='<tr><td colspan="2">'.get_lang('ThereIsNotQualifiedLearners').'</td></tr>';
-			} else {
-				$table_list.='<tr><td colspan="2">'.get_lang('ThereIsNotUnqualifiedLearners').'</td></tr>';
-			}
-		}
-
-		$table_list.= '</table></center>';
-		$table_list .= '<br /></div>';
-	} else {
-		$table_list .= get_lang('NoParticipation');
-	}
+    switch($_GET['list']) {
+        case "qualify":
+            $student_list=get_thread_users_qualify($_GET['id']);
+            $nrorow3 =-2;
+            break;
+        case "notqualify":
+            $student_list=get_thread_users_not_qualify($_GET['id']);
+            $nrorow3 =-2;
+            break;
+        default:
+            $student_list=get_thread_users_details($_GET['id']);
+            $nrorow3 = Database::num_rows($student_list);
+            break;
+    }
+    $table_list = '<p><br /><h3>'.get_lang('ThreadUsersList').'&nbsp;:'.get_name_thread_by_id($_GET['id']).'</h3>';
+    if ($nrorow3>0 || $nrorow3==-2) {
+        $url = 'cidReq='.Security::remove_XSS($_GET['cidReq']).'&forum='.Security::remove_XSS($my_forum).'&action='.Security::remove_XSS($_GET['action']).'&content='.Security::remove_XSS($_GET['content'],STUDENT).'&id='.Security::remove_XSS($_GET['id']);
+        $table_list.= '<br />
+                 <div style="width:50%">
+                 <table class="data_table" border="0">
+                    <tr>
+                        <th height="22"><a href="viewforum.php?'.$url.'&origin='.$origin.'&list=all">'.get_lang('AllStudents').'</a></th>
+                        <th><a href="viewforum.php?'.$url.'&origin='.$origin.'&list=qualify">'.get_lang('StudentsQualified').'</a></th>
+                        <th><a href="viewforum.php?'.$url.'&origin='.$origin.'&list=notqualify">'.get_lang('StudentsNotQualified').'</a></th>
+                    </tr>
+                 </table></div>
+                 <div style="border:1px solid gray; width:99%; margin-top:5px; padding:4px; float:left">
+                 ';
+
+        $icon_qualify = 'blog_new.gif';
+        $table_list.= '<center><br /><table class="data_table" style="width:50%">';
+        // The column headers (to do: make this sortable)
+        $table_list.= '<tr >';
+        $table_list.= '<th height="24">'.get_lang('NamesAndLastNames').'</th>';
+
+        if ($_GET['list']=='qualify') {
+            $table_list.= '<th>'.get_lang('Qualification').'</th>';
+        }
+        if (api_is_allowed_to_edit(null,true)) {
+            $table_list.= '<th>'.get_lang('Qualify').'</th>';
+        }
+        $table_list.= '</tr>';
+        $max_qualify=show_qualify('2',$_GET['cidReq'],$my_forum,$userid,$_GET['id']);
+        $counter_stdlist=0;
+
+        if (Database::num_rows($student_list)>0) {
+            while ($row_student_list=Database::fetch_array($student_list)) {
+                if ($counter_stdlist%2==0) {
+                         $class_stdlist="row_odd";
+                } else {
+                        $class_stdlist="row_even";
+                }
+                $name_user_theme = 	api_get_person_name($row_student_list['firstname'], $row_student_list['lastname']);
+                $table_list.= '<tr class="$class_stdlist"><td><a href="../user/userInfo.php?uInfo='.$row_student_list['user_id'].'&tipo=sdtlist&'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($my_forum).$origin_string.'">'.$name_user_theme.'</a></td>';
+                if ($_GET['list']=='qualify') {
+                    $table_list.= '<td>'.$row_student_list['qualify'].'/'.$max_qualify.'</td>';
+                }
+                if (api_is_allowed_to_edit(null,true)) {
+                    $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$my_forum,$row_student_list['user_id'],$_GET['id']);
+                    $table_list.= '<td><a href="forumqualify.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($my_forum).'&thread='.Security::remove_XSS($_GET['id']).'&user='.$row_student_list['user_id'].'&user_id='.$row_student_list['user_id'].'&idtextqualify='.$current_qualify_thread.'&origin='.$origin.'">'.icon('../img/'.$icon_qualify,get_lang('Qualify')).'</a></td></tr>';
+                }
+                $counter_stdlist++;
+            }
+        } else {
+            if ($_GET['list']=='qualify'){
+                $table_list.='<tr><td colspan="2">'.get_lang('ThereIsNotQualifiedLearners').'</td></tr>';
+            } else {
+                $table_list.='<tr><td colspan="2">'.get_lang('ThereIsNotUnqualifiedLearners').'</td></tr>';
+            }
+        }
+
+        $table_list.= '</table></center>';
+        $table_list .= '<br /></div>';
+    } else {
+        $table_list .= get_lang('NoParticipation');
+    }
 }
 
 
 /*
-	Is the user allowed here?
+    Is the user allowed here?
 */
 // if the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
 if (!api_is_allowed_to_edit(false,true) AND ($current_forum_category['visibility']==0 OR $current_forum['visibility']==0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
 if ($origin == 'learnpath') {
-	echo '<div style="height:15px">&nbsp;</div>';
+    echo '<div style="height:15px">&nbsp;</div>';
 }
 
 /*
-	Display the action messages
+    Display the action messages
 */
 if (!empty($message)) {
-	Display :: display_confirmation_message($message);
+    Display :: display_confirmation_message($message);
 }
 
 
 /*
-	Action Links
+    Action Links
 */
 if ($origin!='learnpath') {
-	echo '<div class="actions">';
-	if ($origin=='group') {
-		echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
-	}
-	else{
-		echo '<span style="float:right;">'.search_link().'</span>';
-		echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';		
-	}
-	// The link should appear when
-	// 1. the course admin is here
-	// 2. the course member is here and new threads are allowed
-	// 3. a visitor is here and new threads AND allowed AND  anonymous posts are allowed
-	if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
-		if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
-			if (!api_is_anonymous()) {
-				if ($my_forum==strval(intval($my_forum))) {
-					echo '<a href="newthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($my_forum).$origin_string.'">'.Display::return_icon('new_thread.png',get_lang('NewTopic'),'','32').'</a>';
-				} else {
-					$my_forum=strval(intval($my_forum));
-					echo '<a href="newthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$my_forum.$origin_string.'">'.Display::return_icon('new_thread.png',get_lang('NewTopic'),'','32').'</a>';
-				}
-
-			 }
-		} else {
-			echo get_lang('ForumLocked');
-		}
-	}
-	echo '</div>';
+    echo '<div class="actions">';
+    if ($origin=='group') {
+        echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
+    }
+    else{
+        echo '<span style="float:right;">'.search_link().'</span>';
+        echo '<a href="index.php">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
+    }
+    // The link should appear when
+    // 1. the course admin is here
+    // 2. the course member is here and new threads are allowed
+    // 3. a visitor is here and new threads AND allowed AND  anonymous posts are allowed
+    if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
+        if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
+            if (!api_is_anonymous()) {
+                if ($my_forum==strval(intval($my_forum))) {
+                    echo '<a href="newthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($my_forum).$origin_string.'">'.Display::return_icon('new_thread.png',get_lang('NewTopic'),'','32').'</a>';
+                } else {
+                    $my_forum=strval(intval($my_forum));
+                    echo '<a href="newthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$my_forum.$origin_string.'">'.Display::return_icon('new_thread.png',get_lang('NewTopic'),'','32').'</a>';
+                }
+
+             }
+        } else {
+            echo get_lang('ForumLocked');
+        }
+    }
+    echo '</div>';
 }
 
 /*
-					Display
+                    Display
 */
 echo '<table class="forum_table" >';
 
 // the current forum
-if ($origin != 'learnpath') {    
-    
+if ($origin != 'learnpath') {
+
     echo '<thead>';
-    
-	echo "<tr><th class=\"forum_head\" colspan=\"7\">";
-    
+
+    echo "<tr><th class=\"forum_head\" colspan=\"7\">";
+
     if (!empty ($current_forum_category['cat_title'])) {
-        
+
         //echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title'])."</span><br />";
-        
+
     }
-    
-    
-	echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
 
-	if (!empty ($current_forum['forum_comment'])) {
-		echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
-	}
+
+    echo '<span class="forum_title">'.prepare4display($current_forum['forum_title']).'</span>';
+
+    if (!empty ($current_forum['forum_comment'])) {
+        echo '<br><span class="forum_description">'.prepare4display($current_forum['forum_comment']).'</span>';
+    }
 
 
-	echo "</th>";
-	echo "</tr>";
-    
+    echo "</th>";
+    echo "</tr>";
+
     echo '</thead>';
 }
 
@@ -358,109 +358,108 @@ $whatsnew_post_info=isset($_SESSION['whatsnew_post_info'])?$_SESSION['whatsnew_p
 
 $counter=0;
 if(is_array($threads)) {
-	foreach ($threads as $row) {
-		// thread who have no replies yet and the only post is invisible should not be displayed to students.
-		if (api_is_allowed_to_edit(false,true) OR  !($row['thread_replies']=='0' AND $row['visible']=='0')) {
-			if($counter%2==0) {
-				 $class="row_odd";
-			} else {
-				$class="row_even";
-			}
-			echo "<tr class=\"$class\">";
-			echo "<td>";
-			$my_whatsnew_post_info=isset($whatsnew_post_info[$my_forum][$row['thread_id']])?$whatsnew_post_info[$my_forum][$row['thread_id']]:null;
-			if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
-				echo icon('../img/forumthread.gif');
-			} else {
-				echo icon('../img/forumthread.gif');
-			}
-
-			if ($row['thread_sticky']==1) {
-				echo icon('../img/exclamation.gif');
-			}
-			echo "</td>";
-			echo "<td>";
-			echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&forum=".Security::remove_XSS($my_forum)."&amp;origin=".$origin."&amp;thread=".$row['thread_id'].$origin_string."&amp;search=".Security::remove_XSS(urlencode($my_search))."\" ".class_visible_invisible($row['visibility']).">".prepare4display($row['thread_title'])."</a></td>";
-			echo "<td>".$row['thread_replies']."</td>";
-			if ($row['user_id']=='0') {
-				$name=prepare4display($row['thread_poster_name']);
-			} else {
-				$name=api_get_person_name($row['firstname'], $row['lastname']);
-			}
-			echo "<td>".$row['thread_views']."</td>";
-			if ($row['last_poster_user_id']=='0') {
-				$name=$row['poster_name'];
-			} else {
-				$name=api_get_person_name($row['last_poster_firstname'], $row['last_poster_lastname']);
-			}
-
-			if($origin != 'learnpath') {
-				echo "<td>".display_user_link($row['user_id'], api_get_person_name($row['firstname'], $row['lastname']))."</td>";
-			} else {
-				echo "<td>".api_get_person_name($row['firstname'], $row['lastname'])."</td>";
-			}
-
-			// if the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread
-			if (($row['visible']=='1' OR api_is_allowed_to_edit(false,true)) && $origin!='learnpath') {
-				$last_post=api_convert_and_format_date($row['thread_date'], null, date_default_timezone_get())." ".get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name);
-			} elseif ($origin!='learnpath') {
-				$last_post_sql="SELECT post.*, user.firstname, user.lastname FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' ORDER BY post_id DESC";
-				$last_post_result=Database::query($last_post_sql);
-				$last_post_row=Database::fetch_array($last_post_result);
-				$name=api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
-				$last_post=api_convert_and_format_date($last_post_row['post_date'], null, date_default_timezone_get())." ".get_lang('By').' '.display_user_link($last_post_row['poster_id'], $name);
-			} else {
-				$last_post_sql="SELECT post.*, user.firstname, user.lastname FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' ORDER BY post_id DESC";
-				$last_post_result=Database::query($last_post_sql);
-				$last_post_row=Database::fetch_array($last_post_result);
-				$name=api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
-				$last_post=api_convert_and_format_date($last_post_row['post_date'], null, date_default_timezone_get())." ".get_lang('By').' '.$name;
-			}
-
-			echo "<td>".$last_post."</td>";
-			echo "<td>";
-			// get attach id
-			$attachment_list=get_attachment($row['post_id']);
-			$id_attach = !empty($attachment_list)?$attachment_list['id']:'';
-
-			$sql_post_id="SELECT post_id FROM $table_posts WHERE post_title='".Database::escape_string($row['thread_title'])."'";
-			$result_post_id=Database::query($sql_post_id);
-			$row_post_id=Database::fetch_array($result_post_id);
-
-			if ($origin != 'learnpath') {
-				if (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
-					echo "<a href=\"editpost.php?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&amp;thread=".Security::remove_XSS($row['thread_id'])."&amp;post=".$row_post_id['post_id']."&amp;gidReq=".$_SESSION['toolgroup']."&origin=".$origin."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
-					echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&amp;action=delete&amp;content=thread&amp;gidReq=".$_SESSION['toolgroup']."&amp;id=".$row['thread_id'].$origin_string."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteCompleteThread"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-					display_visible_invisible_icon('thread', $row['thread_id'], $row['visibility'], array("forum"=>$my_forum,'origin'=>$origin,"gidReq"=>$_SESSION['toolgroup']));
-					display_lock_unlock_icon('thread',$row['thread_id'], $row['locked'], array("forum"=>$my_forum,'origin'=>$origin,"gidReq"=>$_SESSION['toolgroup']));
-					echo "<a href=\"viewforum.php?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&amp;action=move&amp;gidReq=".$_SESSION['toolgroup']."&amp;thread=".$row['thread_id'].$origin_string."\">".icon('../img/deplacer_fichier.gif',get_lang('MoveThread'))."</a>";
-				}
-			}
-			$iconnotify = 'send_mail.gif';
-			if (is_array(isset($_SESSION['forum_notification']['thread'])?$_SESSION['forum_notification']['thread']:null)) {
-				if (in_array($row['thread_id'],$_SESSION['forum_notification']['thread'])) {
-					$iconnotify = 'send_mail_checked.gif';
-				}
-			}
-			$icon_liststd = 'lp_users.png';
-			if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
-				echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;forum=".Security::remove_XSS($my_forum)."&origin=".$origin."&amp;action=notify&amp;content=thread&amp;gidReq=".$_SESSION['toolgroup']."&amp;id=".$row['thread_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
-			}
-
-			if (api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
-				echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($my_forum).'&origin='.$origin.'&amp;action=liststd&amp;content=thread&amp;gidReq='.$_SESSION['toolgroup'].'&amp;id='.$row['thread_id'].'">'.icon('../img/'.$icon_liststd,get_lang('StudentList')).'</a>';
-			}
-			echo "</td>";
-			echo "</tr>";
-		}
-		$counter++;
-	}
+    foreach ($threads as $row) {
+        // thread who have no replies yet and the only post is invisible should not be displayed to students.
+        if (api_is_allowed_to_edit(false,true) OR  !($row['thread_replies']=='0' AND $row['visible']=='0')) {
+            if($counter%2==0) {
+                 $class="row_odd";
+            } else {
+                $class="row_even";
+            }
+            echo "<tr class=\"$class\">";
+            echo "<td>";
+            $my_whatsnew_post_info=isset($whatsnew_post_info[$my_forum][$row['thread_id']])?$whatsnew_post_info[$my_forum][$row['thread_id']]:null;
+            if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
+                echo icon('../img/forumthread.gif');
+            } else {
+                echo icon('../img/forumthread.gif');
+            }
+
+            if ($row['thread_sticky']==1) {
+                echo icon('../img/exclamation.gif');
+            }
+            echo "</td>";
+            echo "<td>";
+            echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&gradebook=".Security::remove_XSS($_GET['gradebook'])."&forum=".Security::remove_XSS($my_forum)."&amp;origin=".$origin."&amp;thread=".$row['thread_id'].$origin_string."&amp;search=".Security::remove_XSS(urlencode($my_search))."\" ".class_visible_invisible($row['visibility']).">".prepare4display($row['thread_title'])."</a></td>";
+            echo "<td>".$row['thread_replies']."</td>";
+            if ($row['user_id']=='0') {
+                $name=prepare4display($row['thread_poster_name']);
+            } else {
+                $name=api_get_person_name($row['firstname'], $row['lastname']);
+            }
+            echo "<td>".$row['thread_views']."</td>";
+            if ($row['last_poster_user_id']=='0') {
+                $name=$row['poster_name'];
+            } else {
+                $name=api_get_person_name($row['last_poster_firstname'], $row['last_poster_lastname']);
+            }
+
+            if($origin != 'learnpath') {
+                echo "<td>".display_user_link($row['user_id'], api_get_person_name($row['firstname'], $row['lastname']))."</td>";
+            } else {
+                echo "<td>".api_get_person_name($row['firstname'], $row['lastname'])."</td>";
+            }
+
+            // if the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread
+            if (($row['visible']=='1' OR api_is_allowed_to_edit(false,true)) && $origin!='learnpath') {
+                $last_post=api_convert_and_format_date($row['thread_date'], null, date_default_timezone_get())." ".get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name);
+            } elseif ($origin!='learnpath') {
+                $last_post_sql="SELECT post.*, user.firstname, user.lastname FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' ORDER BY post_id DESC";
+                $last_post_result=Database::query($last_post_sql);
+                $last_post_row=Database::fetch_array($last_post_result);
+                $name=api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
+                $last_post=api_convert_and_format_date($last_post_row['post_date'], null, date_default_timezone_get())." ".get_lang('By').' '.display_user_link($last_post_row['poster_id'], $name);
+            } else {
+                $last_post_sql="SELECT post.*, user.firstname, user.lastname FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' ORDER BY post_id DESC";
+                $last_post_result=Database::query($last_post_sql);
+                $last_post_row=Database::fetch_array($last_post_result);
+                $name=api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
+                $last_post=api_convert_and_format_date($last_post_row['post_date'], null, date_default_timezone_get())." ".get_lang('By').' '.$name;
+            }
+
+            echo "<td>".$last_post."</td>";
+            echo "<td>";
+            // get attach id
+            $attachment_list=get_attachment($row['post_id']);
+            $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
+
+            $sql_post_id="SELECT post_id FROM $table_posts WHERE post_title='".Database::escape_string($row['thread_title'])."'";
+            $result_post_id=Database::query($sql_post_id);
+            $row_post_id=Database::fetch_array($result_post_id);
+
+            if ($origin != 'learnpath') {
+                if (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
+                    echo "<a href=\"editpost.php?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&amp;thread=".Security::remove_XSS($row['thread_id'])."&amp;post=".$row_post_id['post_id']."&amp;gidReq=".$_SESSION['toolgroup']."&origin=".$origin."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+                    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&amp;action=delete&amp;content=thread&amp;gidReq=".$_SESSION['toolgroup']."&amp;id=".$row['thread_id'].$origin_string."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteCompleteThread"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+                    display_visible_invisible_icon('thread', $row['thread_id'], $row['visibility'], array("forum"=>$my_forum,'origin'=>$origin,"gidReq"=>$_SESSION['toolgroup']));
+                    display_lock_unlock_icon('thread',$row['thread_id'], $row['locked'], array("forum"=>$my_forum,'origin'=>$origin,"gidReq"=>$_SESSION['toolgroup']));
+                    echo "<a href=\"viewforum.php?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&amp;action=move&amp;gidReq=".$_SESSION['toolgroup']."&amp;thread=".$row['thread_id'].$origin_string."\">".icon('../img/deplacer_fichier.gif',get_lang('MoveThread'))."</a>";
+                }
+            }
+            $iconnotify = 'send_mail.gif';
+            if (is_array(isset($_SESSION['forum_notification']['thread'])?$_SESSION['forum_notification']['thread']:null)) {
+                if (in_array($row['thread_id'],$_SESSION['forum_notification']['thread'])) {
+                    $iconnotify = 'send_mail_checked.gif';
+                }
+            }
+            $icon_liststd = 'lp_users.png';
+            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
+                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;forum=".Security::remove_XSS($my_forum)."&origin=".$origin."&amp;action=notify&amp;content=thread&amp;gidReq=".$_SESSION['toolgroup']."&amp;id=".$row['thread_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
+            }
+
+            if (api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
+                echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;forum='.Security::remove_XSS($my_forum).'&origin='.$origin.'&amp;action=liststd&amp;content=thread&amp;gidReq='.$_SESSION['toolgroup'].'&amp;id='.$row['thread_id'].'">'.icon('../img/'.$icon_liststd,get_lang('StudentList')).'</a>';
+            }
+            echo "</td>";
+            echo "</tr>";
+        }
+        $counter++;
+    }
 }
 echo "</table>";
 echo isset($table_list)?$table_list:'';
-/*
-		FOOTER
-*/
+
+/* FOOTER */
 if ($origin != 'learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 277 - 308
main/forum/viewforumcategory.php

@@ -2,25 +2,25 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@Copyright Ghent University
-*	@Copyright Patrick Cool
-*
-* 	@package chamilo.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @Author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @Copyright Ghent University
+ * @Copyright Patrick Cool
+ *
+ * @package chamilo.forum
+ */
 
 // name of the language file that needs to be included
 $language_file = 'forum';
@@ -28,21 +28,21 @@ $language_file = 'forum';
 require '../inc/global.inc.php';
 $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/jquery.js" ></script>';
 $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
-	$(document).ready(function(){ $(\'.hide-me\').slideUp() });
-	function hidecontent(content){ $(content).slideToggle(\'normal\'); }
-	</script>';
+    $(document).ready(function(){ $(\'.hide-me\').slideUp() });
+    function hidecontent(content){ $(content).slideToggle(\'normal\'); }
+    </script>';
 $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
 
-		function advanced_parameters() {
-			if(document.getElementById(\'options\').style.display == \'none\') {
-					document.getElementById(\'options\').style.display = \'block\';
-					document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			} else {
-					document.getElementById(\'options\').style.display = \'none\';
-					document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
-			}
-		}
-	</script>';
+        function advanced_parameters() {
+            if(document.getElementById(\'options\').style.display == \'none\') {
+                    document.getElementById(\'options\').style.display = \'block\';
+                    document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            } else {
+                    document.getElementById(\'options\').style.display = \'none\';
+                    document.getElementById(\'plus_minus\').innerHTML=\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedParameters').'\';
+            }
+        }
+    </script>';
 
 
 // including the global dokeos file
@@ -59,30 +59,24 @@ require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'
 include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
 $nameTools=get_lang('ToolForum');
 
-/*
-	Including necessary files
-*/
+/* Including necessary files */
 require 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
 
 
-/*
-		MAIN DISPLAY SECTION
-*/
+/* MAIN DISPLAY SECTION */
 
+/* Header and Breadcrumbs */
 
-/*
-	Header and Breadcrumbs
-*/
 if (isset($_SESSION['gradebook'])){
-	$gradebook=	$_SESSION['gradebook'];
+    $gradebook=	$_SESSION['gradebook'];
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 $current_forum_category=get_forum_categories($_GET['forumcategory']);
@@ -91,309 +85,284 @@ $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$curren
 
 
 if (!empty($_GET['action']) && !empty($_GET['content'])) {
-	if ($_GET['action']=='add' && $_GET['content']=='forum' ) {
-		$interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum', 'name' => get_lang('AddForum'));
-	}
+    if ($_GET['action']=='add' && $_GET['content']=='forum' ) {
+        $interbreadcrumb[] = array ("url" => api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum', 'name' => get_lang('AddForum'));
+    }
 }
 
-//are we in a lp ?
+// Are we in a lp ?
 $origin = '';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
 if ($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	Display :: display_header(null);
-	//api_display_tool_title($nameTools);
+    Display :: display_header(null);
+    //api_display_tool_title($nameTools);
 }
 
-/*
-------------------------------------------------------------------------------------------------------
-	ACTIONS
-------------------------------------------------------------------------------------------------------
-*/
-$whatsnew_post_info=$_SESSION['whatsnew_post_info'];
-
-/*
------------------------------------------------------------
-	Is the user allowed here?
------------------------------------------------------------
-*/
+/* ACTIONS */
+
+$whatsnew_post_info = $_SESSION['whatsnew_post_info'];
+
+/* Is the user allowed here? */
+
 // if the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
 if (!api_is_allowed_to_edit(false,true) AND $current_forum_category['visibility']==0) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
-/*
------------------------------------------------------------
-	Action Links
------------------------------------------------------------
-*/
+/* Action Links */
+
 echo '<div class="actions">';
 echo '<span style="float:right;">'.search_link().'</span>';
 echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
 if (api_is_allowed_to_edit(false,true)) {
-	//echo '<a href="'.api_get_self().'?forumcategory='.$_GET['forumcategory'].'&amp;action=add&amp;content=forumcategory">'.get_lang('AddForumCategory').'</a> | ';
-	echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum"> '.Display::return_icon('new_forum.png', get_lang('AddForum'),'','32').'</a>';
-	//echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=add&amp;content=forum">'.Display::return_icon('new_forum.png', get_lang('AddForum'),'','32').'</a>';
+    //echo '<a href="'.api_get_self().'?forumcategory='.$_GET['forumcategory'].'&amp;action=add&amp;content=forumcategory">'.get_lang('AddForumCategory').'</a> | ';
+    echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=add&amp;content=forum"> '.Display::return_icon('new_forum.png', get_lang('AddForum'),'','32').'</a>';
+    //echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&amp;action=add&amp;content=forum">'.Display::return_icon('new_forum.png', get_lang('AddForum'),'','32').'</a>';
 }
 echo '</div>';
 
-/*
-------------------------------------------------------------------------------------------------------
-	ACTIONS
-------------------------------------------------------------------------------------------------------
-*/
+/* ACTIONS */
+
 $action_forums=isset($_GET['action']) ? $_GET['action'] : '';
 if (api_is_allowed_to_edit(false,true)) {
-	handle_forum_and_forumcategories();
+    handle_forum_and_forumcategories();
 }
 
 // notification
 if ($action_forums == 'notify' AND isset($_GET['content']) AND isset($_GET['id'])) {
-	$return_message = set_notification($_GET['content'],$_GET['id']);
-	Display :: display_confirmation_message($return_message,false);
+    $return_message = set_notification($_GET['content'],$_GET['id']);
+    Display :: display_confirmation_message($return_message,false);
 }
 
 if ($action_forums!='add') {
-	/*
-	------------------------------------------------------------------------------------------------------
-		RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
-	------------------------------------------------------------------------------------------------------
-	note: we do this here just after het handling of the actions to be sure that we already incorporate the
-	latest changes
-	*/
-	// Step 1: We store all the forum categories in an array $forum_categories
-	$forum_categories=array();
-	$forum_category=get_forum_categories($_GET['forumcategory']);
-
-	// step 2: we find all the forums
-	$forum_list=array();
-	$forum_list=get_forums();
-
-	/*
-	------------------------------------------------------------------------------------------------------
-		RETRIEVING ALL GROUPS AND THOSE OF THE USER
-	------------------------------------------------------------------------------------------------------
-	*/
-	// the groups of the user
-	$groups_of_user=array();
-	$groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
-	// all groups in the course (and sorting them as the id of the group = the key of the array
-	$all_groups=GroupManager::get_group_list();
-	if(is_array($all_groups)) {
-		foreach ($all_groups as $group) {
-			$all_groups[$group['id']]=$group;
-		}
-	}
-
-	/*
-	------------------------------------------------------------------------------------------------------
-		CLEAN GROUP ID FOR AJAXFILEMANAGER
-	------------------------------------------------------------------------------------------------------
-	*/
-	if(isset($_SESSION['_gid']))
-	{
-		unset($_SESSION['_gid']);
+    /*
+    RETRIEVING ALL THE FORUM CATEGORIES AND FORUMS
+    Note: we do this here just after het handling of the actions to be sure that we already incorporate the
+    latest changes
+    */
+    // Step 1: We store all the forum categories in an array $forum_categories
+    $forum_categories=array();
+    $forum_category=get_forum_categories($_GET['forumcategory']);
+
+    // step 2: we find all the forums
+    $forum_list=array();
+    $forum_list=get_forums();
+
+    /* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
+
+    // the groups of the user
+    $groups_of_user=array();
+    $groups_of_user=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
+    // all groups in the course (and sorting them as the id of the group = the key of the array
+    $all_groups=GroupManager::get_group_list();
+    if(is_array($all_groups)) {
+        foreach ($all_groups as $group) {
+            $all_groups[$group['id']]=$group;
+        }
     }
 
-	/*
-	-----------------------------------------------------------
-		Display Forum Categories and the Forums in it
-	-----------------------------------------------------------
-	*/
-	echo '<table class="forum_table" width="100%">';
-	$my_session=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null;
-    
+    /* CLEAN GROUP ID FOR AJAXFILEMANAGER */
+
+    if(isset($_SESSION['_gid']))
+    {
+        unset($_SESSION['_gid']);
+    }
+
+    /* Display Forum Categories and the Forums in it */
+
+    echo '<table class="forum_table" width="100%">';
+    $my_session=isset($_SESSION['id_session']) ? $_SESSION['id_session'] : null;
+
     if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum_category['session_name'])) {
         $session_displayed = ' ('.Security::remove_XSS($forum_category['session_name']).')';
     } else {
         $session_displayed = '';
     }
-    
-    
-	$forum_categories_list='';
+
+
+    $forum_categories_list='';
     echo '<thead>';
-	echo "<tr><th class=\"forum_head\" ".(api_is_allowed_to_edit(null,true)?"colspan='5'":"colspan='6'").">";
-	    
+    echo "<tr><th class=\"forum_head\" ".(api_is_allowed_to_edit(null,true)?"colspan='5'":"colspan='6'").">";
+
     echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.prepare4display($forum_category['cat_id']).'" '.class_visible_invisible(prepare4display($forum_category['visibility'])).'>'.prepare4display($forum_category['cat_title']).$session_displayed.'</a>'. $session_img .'<br />';
-    
-	echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
-     
-	if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($my_session)!=0)) {
-		echo '<th style="vertical-align: top;" align="center" >';
-		echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=edit&amp;content=forumcategory&amp;id=".$forum_category['cat_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
-		echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=delete&amp;content=forumcategory&amp;amp;id=".$forum_category['cat_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForumCategory"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-		display_visible_invisible_icon('forumcategory', $forum_category['cat_id'], $forum_category['visibility'], array("forumcategory"=>$_GET['forumcategory']));
-		display_lock_unlock_icon('forumcategory',$forum_category['cat_id'], $forum_category['locked'], array("forumcategory"=>$_GET['forumcategory']));
-		display_up_down_icon('forumcategory',$forum_category['cat_id'], $forum_categories_list);
-		echo "</th>";
-	}
-	echo "</tr>";
-
-	// step 3: the interim headers (for the forum)
-	echo "<tr class=\"forum_header\">";
-	echo "<td colspan='2'>".get_lang('Forum')."</td>";
-	echo "<td>".get_lang('Topics')."</td>";
-	echo "<td>".get_lang('Posts')."</td>";
-	echo "<td>".get_lang('LastPosts')."</td>";
-	echo "<td>".get_lang('Actions')."</td>";
-	echo "</tr>";
-    
+
+    echo '<span class="forum_description">'.prepare4display($forum_category['cat_comment']).'</span>';
+
+    if (api_is_allowed_to_edit(false,true) && !($forum_category['session_id']==0 && intval($my_session)!=0)) {
+        echo '<th style="vertical-align: top;" align="center" >';
+        echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=edit&amp;content=forumcategory&amp;id=".$forum_category['cat_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+        echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=delete&amp;content=forumcategory&amp;amp;id=".$forum_category['cat_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForumCategory"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+        display_visible_invisible_icon('forumcategory', $forum_category['cat_id'], $forum_category['visibility'], array("forumcategory"=>$_GET['forumcategory']));
+        display_lock_unlock_icon('forumcategory',$forum_category['cat_id'], $forum_category['locked'], array("forumcategory"=>$_GET['forumcategory']));
+        display_up_down_icon('forumcategory',$forum_category['cat_id'], $forum_categories_list);
+        echo "</th>";
+    }
+    echo "</tr>";
+
+    // step 3: the interim headers (for the forum)
+    echo "<tr class=\"forum_header\">";
+    echo "<td colspan='2'>".get_lang('Forum')."</td>";
+    echo "<td>".get_lang('Topics')."</td>";
+    echo "<td>".get_lang('Posts')."</td>";
+    echo "<td>".get_lang('LastPosts')."</td>";
+    echo "<td>".get_lang('Actions')."</td>";
+    echo "</tr>";
+
     echo '</thead>';
-       
-
-	// the forums in this category
-	$forums_in_category=get_forums_in_category($forum_category['cat_id']);
-
-	// step 4: we display all the forums in this category.
-	$forum_count=0;
-	foreach ($forum_list as $key=>$forum) {
-		if ($forum['forum_category']==$forum_category['cat_id']) {
-			// the forum has to be showed if
-			// 1.v it is a not a group forum (teacher and student)
-			// 2.v it is a group forum and it is public (teacher and student)
-			// 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
-			// if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed
-			//if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
-			//{
-			$show_forum=false;
-			// SHOULD WE SHOW THIS PARTICULAR FORUM
-			// you are teacher => show forum
-
-			if (api_is_allowed_to_edit(false,true)) {
-				//echo 'teacher';
-				$show_forum=true;
-			} else {
-				// you are not a teacher
-				//echo 'student';
-				// it is not a group forum => show forum (invisible forums are already left out see get_forums function)
-				if ($forum['forum_of_group']=='0') {
-					//echo '-gewoon forum';
-					$show_forum=true;
-				} else {
-					// it is a group forum
-					//echo '-groepsforum';
-					// it is a group forum but it is public => show
-					if ($forum['forum_group_public_private']=='public') {
-						$show_forum=true;
-						//echo '-publiek';
-					} else {
-						// it is a group forum and it is private
-						//echo '-prive';
-						// it is a group forum and it is private but the user is member of the group
-						if (in_array($forum['forum_of_group'],$groups_of_user)) {
-							//echo '-is lid';
-							$show_forum=true;
-						} else {
-							//echo '-is GEEN lid';
-							$show_forum=false;
-						}
-					}
-
-				}
-			}
-			//echo '<hr>';
-			$form_count=isset($form_count)?$form_count:0;
-			if ($show_forum === true) {
-				$form_count++;
-				echo "<tr class=\"forum\">";
-				echo "<td width=\"20\">";
-				$my_whatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null;
-				if ($forum['forum_of_group']!=='0') {
-					if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
-						echo icon('../img/forumgroupnew.gif');
-					} else {
-						echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
-					}
-				} else {
-					if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
-						echo icon('../img/forum.gif', get_lang('Forum'));
-					} else {
-						echo icon('../img/forum.gif');
-					}
-				}
-				echo "</td>";
-
-				if ($forum['forum_of_group']<>'0')
-				{
-					$my_all_groups_forum_name=isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
-					$my_all_groups_forum_id=isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
-					$group_title=api_substr($my_all_groups_forum_name,0,30);
-					$forum_title_group_addition=' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$my_all_groups_forum_id.'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)';
-				}
-				else
-				{
-					$forum_title_group_addition='';
-				}
-
-
-				if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
-					$session_displayed = ' ('.$forum['session_name'].')';
-				} else {
-					$session_displayed = '';
-				}
-				echo "<td><a href=\"viewforum.php?".api_get_cidreq()."&forum=".$forum['forum_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode(isset($_GET['search'])?$_GET['search']:''))."\" ".class_visible_invisible($forum['visibility']).">".prepare4display($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />'.prepare4display($forum['forum_comment'])."</td>";
-
-				//$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
-				// the number of topics and posts
-				$my_number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : '';
-				$my_number_posts=isset($forum['number_of_posts']) ? $forum['number_of_posts'] : '';
-				echo "<td>".$my_number_threads."</td>";
-				echo "<td>".$my_number_posts."</td>";
-				// the last post in the forum
-				if ($forum['last_poster_name']<>'') {
-					$name=$forum['last_poster_name'];
-					$poster_id=0;
-				} else {
-					$name=api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
-					$poster_id=$forum['last_poster_id'];
-				}
-				echo "<td>";
-				if (!empty($forum['last_post_id'])) {
-					echo $forum['last_post_date']." ".get_lang('By').' '.display_user_link($poster_id, $name);
-				}
-				echo "</td>";
-				echo "<td NOWRAP align='center'>";
-				
-				if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval(isset($_SESSION['id_session'])?$_SESSION['id_session']:null)!=0)) {
-					echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
-					echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=delete&amp;content=forum&amp;id=".$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForum"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-					display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility'], array("forumcategory"=>$_GET['forumcategory']));
-					display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked'], array("forumcategory"=>$_GET['forumcategory']));
-					display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
-				}
-				
-				$iconnotify = 'send_mail.gif';
-				if (is_array(isset($_SESSION['forum_notification']['forum'])?$_SESSION['forum_notification']['forum']:null))	{
-					if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum'])) {
-						$iconnotify = 'send_mail_checked.gif';
-					}
-				}
-				if (!api_is_anonymous()) {
-					echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
-				}
-				echo "</td>";
-				echo "</tr>";
-			}
-		}
-	}
-	if (count($forum_list) == 0) {
-		echo "<tr><td>".get_lang('NoForumInThisCategory')."</td></tr>";
-	}
-
-	echo "</table>";
+
+
+    // the forums in this category
+    $forums_in_category=get_forums_in_category($forum_category['cat_id']);
+
+    // step 4: we display all the forums in this category.
+    $forum_count=0;
+    foreach ($forum_list as $key=>$forum) {
+        if ($forum['forum_category']==$forum_category['cat_id']) {
+            // the forum has to be showed if
+            // 1.v it is a not a group forum (teacher and student)
+            // 2.v it is a group forum and it is public (teacher and student)
+            // 3. it is a group forum and it is private (always for teachers only if the user is member of the forum
+            // if the forum is private and it is a group forum and the user is not a member of the group forum then it cannot be displayed
+            //if (!($forum['forum_group_public_private']=='private' AND !is_null($forum['forum_of_group']) AND !in_array($forum['forum_of_group'], $groups_of_user)))
+            //{
+            $show_forum=false;
+            // SHOULD WE SHOW THIS PARTICULAR FORUM
+            // you are teacher => show forum
+
+            if (api_is_allowed_to_edit(false,true)) {
+                //echo 'teacher';
+                $show_forum=true;
+            } else {
+                // you are not a teacher
+                //echo 'student';
+                // it is not a group forum => show forum (invisible forums are already left out see get_forums function)
+                if ($forum['forum_of_group']=='0') {
+                    //echo '-gewoon forum';
+                    $show_forum=true;
+                } else {
+                    // it is a group forum
+                    //echo '-groepsforum';
+                    // it is a group forum but it is public => show
+                    if ($forum['forum_group_public_private']=='public') {
+                        $show_forum=true;
+                        //echo '-publiek';
+                    } else {
+                        // it is a group forum and it is private
+                        //echo '-prive';
+                        // it is a group forum and it is private but the user is member of the group
+                        if (in_array($forum['forum_of_group'],$groups_of_user)) {
+                            //echo '-is lid';
+                            $show_forum=true;
+                        } else {
+                            //echo '-is GEEN lid';
+                            $show_forum=false;
+                        }
+                    }
+
+                }
+            }
+            //echo '<hr>';
+            $form_count=isset($form_count)?$form_count:0;
+            if ($show_forum === true) {
+                $form_count++;
+                echo "<tr class=\"forum\">";
+                echo "<td width=\"20\">";
+                $my_whatsnew_post_info=isset($whatsnew_post_info[$forum['forum_id']])?$whatsnew_post_info[$forum['forum_id']]:null;
+                if ($forum['forum_of_group']!=='0') {
+                    if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
+                        echo icon('../img/forumgroupnew.gif');
+                    } else {
+                        echo icon('../img/forumgroup.gif', get_lang('GroupForum'));
+                    }
+                } else {
+                    if (is_array($my_whatsnew_post_info) and !empty($my_whatsnew_post_info)) {
+                        echo icon('../img/forum.gif', get_lang('Forum'));
+                    } else {
+                        echo icon('../img/forum.gif');
+                    }
+                }
+                echo "</td>";
+
+                if ($forum['forum_of_group']<>'0')
+                {
+                    $my_all_groups_forum_name=isset($all_groups[$forum['forum_of_group']]['name']) ? $all_groups[$forum['forum_of_group']]['name'] : null;
+                    $my_all_groups_forum_id=isset($all_groups[$forum['forum_of_group']]['id']) ? $all_groups[$forum['forum_of_group']]['id'] : null;
+                    $group_title=api_substr($my_all_groups_forum_name,0,30);
+                    $forum_title_group_addition=' (<a href="../group/group_space.php?'.api_get_cidreq().'&gidReq='.$my_all_groups_forum_id.'" class="forum_group_link">'.get_lang('GoTo').' '.$group_title.'</a>)';
+                }
+                else
+                {
+                    $forum_title_group_addition='';
+                }
+
+
+                if((!isset($_SESSION['id_session']) || $_SESSION['id_session']==0) && !empty($forum['session_name'])) {
+                    $session_displayed = ' ('.$forum['session_name'].')';
+                } else {
+                    $session_displayed = '';
+                }
+                echo "<td><a href=\"viewforum.php?".api_get_cidreq()."&forum=".$forum['forum_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode(isset($_GET['search'])?$_GET['search']:''))."\" ".class_visible_invisible($forum['visibility']).">".prepare4display($forum['forum_title']).$session_displayed.'</a>'.$forum_title_group_addition.'<br />'.prepare4display($forum['forum_comment'])."</td>";
+
+                //$number_forum_topics_and_posts=get_post_topics_of_forum($forum['forum_id']); // deprecated
+                // the number of topics and posts
+                $my_number_threads=isset($forum['number_of_threads']) ? $forum['number_of_threads'] : '';
+                $my_number_posts=isset($forum['number_of_posts']) ? $forum['number_of_posts'] : '';
+                echo "<td>".$my_number_threads."</td>";
+                echo "<td>".$my_number_posts."</td>";
+                // the last post in the forum
+                if ($forum['last_poster_name']<>'') {
+                    $name=$forum['last_poster_name'];
+                    $poster_id=0;
+                } else {
+                    $name=api_get_person_name($forum['last_poster_firstname'], $forum['last_poster_lastname']);
+                    $poster_id=$forum['last_poster_id'];
+                }
+                echo "<td>";
+                if (!empty($forum['last_post_id'])) {
+                    echo $forum['last_post_date']." ".get_lang('By').' '.display_user_link($poster_id, $name);
+                }
+                echo "</td>";
+                echo "<td NOWRAP align='center'>";
+
+                if (api_is_allowed_to_edit(false,true) && !($forum['session_id']==0 && intval(isset($_SESSION['id_session'])?$_SESSION['id_session']:null)!=0)) {
+                    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=edit&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+                    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=delete&amp;content=forum&amp;id=".$forum['forum_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeleteForum"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+                    display_visible_invisible_icon('forum',$forum['forum_id'], $forum['visibility'], array("forumcategory"=>$_GET['forumcategory']));
+                    display_lock_unlock_icon('forum',$forum['forum_id'], $forum['locked'], array("forumcategory"=>$_GET['forumcategory']));
+                    display_up_down_icon('forum',$forum['forum_id'], $forums_in_category);
+                }
+
+                $iconnotify = 'send_mail.gif';
+                if (is_array(isset($_SESSION['forum_notification']['forum'])?$_SESSION['forum_notification']['forum']:null))	{
+                    if (in_array($forum['forum_id'],$_SESSION['forum_notification']['forum'])) {
+                        $iconnotify = 'send_mail_checked.gif';
+                    }
+                }
+                if (!api_is_anonymous()) {
+                    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;forumcategory=".Security::remove_XSS($_GET['forumcategory'])."&amp;action=notify&amp;content=forum&amp;id=".$forum['forum_id']."\">".icon('../img/'.$iconnotify,get_lang('NotifyMe'))."</a>";
+                }
+                echo "</td>";
+                echo "</tr>";
+            }
+        }
+    }
+    if (count($forum_list) == 0) {
+        echo "<tr><td>".get_lang('NoForumInThisCategory')."</td></tr>";
+    }
+
+    echo "</table>";
 }
-/*
-		FOOTER
-*/
-// footer
+
+/* FOOTER */
 if ($origin!='learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 86 - 87
main/forum/viewpost.inc.php

@@ -1,91 +1,91 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-* 	@package chamilo.forum
-*/
+ * @package chamilo.forum
+ */
 $course = api_get_course_info();
 $rows = get_thread_user_post($course['dbName'], $current_thread['thread_id'], $_GET['user']);
 
 $sw = true;
 
-if(isset($rows)){
-	foreach ($rows as $row) {
-		if ($row['status']=='0') {
-			$style =" id = 'post".$post_en."' class=\"hide-me\" style=\"border:1px solid red; display:none; background-color:#F7F7F7; width:95%; margin: 0px 0px 4px 40px; \" ";
-			$url_post ='';
-		} else {
-			$style = "";
-			$post_en = $row['post_parent_id'];
-			$url_post = '<a href="javascript:;" onclick="javascript:hidecontent(\'#post'.$row['post_parent_id'].'\')"> '.get_lang('ViewComentPost').'</a> ';
-		}
-
-		if ($row['user_id']=='0') {
-			$name=prepare4display($row['poster_name']);
-		} else {
-			$name=api_get_person_name($row['firstname'], $row['lastname']);
-		}
-		if($sw === true) {
-			echo "<div style=\"border: 1px solid #000000; padding: 4px 0px 0px 4px; margin-top:5px;\" > <h3> $name </h3> </div>";
-			$sw = false;
-		}
-		echo "<div ".$style."><table width=\"100%\" class=\"post\" cellspacing=\"5\" border=\"0\" >";
-		// the style depends on the status of the message: approved or not
-		//echo 'dd'.$row['status'];
-
-
-		if ($row['visible']=='0') {
-			$titleclass='forum_message_post_title_2_be_approved';
-			$messageclass='forum_message_post_text_2_be_approved';
-			$leftclass='forum_message_left_2_be_approved';
-		} else {
-			$titleclass='forum_message_post_title';
-			$messageclass='forum_message_post_text';
-			$leftclass='forum_message_left';
-		}
-
-		echo "<tr>";
-		echo "<td rowspan=\"3\" class=\"$leftclass\">";
-
-		echo '<br /><b>'.$row['post_date'].'</b><br />';
-
-		if (api_is_allowed_to_edit(null,true)) {
-			echo $url_post;
-		}
-
-		echo "</td>";
-
-		// The post title
-		echo "<td class=\"$titleclass\">".prepare4display($row['post_title'])."</td>";
-		echo "</tr>";
-
-		// The post message
-		echo "<tr >";
-		echo "<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>";
-		echo "</tr>";
-
-		// The check if there is an attachment
-		$attachment_list=get_attachment($row['post_id']);
-
-		if (!empty($attachment_list)) {
-			echo '<tr ><td height="50%">';
-			$realname=$attachment_list['path'];
-			$user_filename=$attachment_list['filename'];
-
-			echo Display::return_icon('attachment.gif',get_lang('Attachment'));
-			echo '<a href="download.php?file=';
-			echo $realname;
-			echo ' "> '.$user_filename.' </a>';
-			echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span><br />';
-			echo '</td></tr>';
-		}
-
-		// The post has been displayed => it can be removed from the what's new array
-		unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-		unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
-		unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-		unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
-		echo "</table></div>";
-	}
+if (isset($rows)){
+    foreach ($rows as $row) {
+        if ($row['status']=='0') {
+            $style =" id = 'post".$post_en."' class=\"hide-me\" style=\"border:1px solid red; display:none; background-color:#F7F7F7; width:95%; margin: 0px 0px 4px 40px; \" ";
+            $url_post ='';
+        } else {
+            $style = "";
+            $post_en = $row['post_parent_id'];
+            $url_post = '<a href="javascript:;" onclick="javascript:hidecontent(\'#post'.$row['post_parent_id'].'\')"> '.get_lang('ViewComentPost').'</a> ';
+        }
+
+        if ($row['user_id']=='0') {
+            $name=prepare4display($row['poster_name']);
+        } else {
+            $name=api_get_person_name($row['firstname'], $row['lastname']);
+        }
+        if ($sw === true) {
+            echo "<div style=\"border: 1px solid #000000; padding: 4px 0px 0px 4px; margin-top:5px;\" > <h3> $name </h3> </div>";
+            $sw = false;
+        }
+        echo "<div ".$style."><table width=\"100%\" class=\"post\" cellspacing=\"5\" border=\"0\" >";
+        // the style depends on the status of the message: approved or not
+        //echo 'dd'.$row['status'];
+
+
+        if ($row['visible']=='0') {
+            $titleclass='forum_message_post_title_2_be_approved';
+            $messageclass='forum_message_post_text_2_be_approved';
+            $leftclass='forum_message_left_2_be_approved';
+        } else {
+            $titleclass='forum_message_post_title';
+            $messageclass='forum_message_post_text';
+            $leftclass='forum_message_left';
+        }
+
+        echo "<tr>";
+        echo "<td rowspan=\"3\" class=\"$leftclass\">";
+
+        echo '<br /><b>'.$row['post_date'].'</b><br />';
+
+        if (api_is_allowed_to_edit(null,true)) {
+            echo $url_post;
+        }
+
+        echo "</td>";
+
+        // The post title
+        echo "<td class=\"$titleclass\">".prepare4display($row['post_title'])."</td>";
+        echo "</tr>";
+
+        // The post message
+        echo "<tr >";
+        echo "<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>";
+        echo "</tr>";
+
+        // The check if there is an attachment
+        $attachment_list=get_attachment($row['post_id']);
+
+        if (!empty($attachment_list)) {
+            echo '<tr ><td height="50%">';
+            $realname=$attachment_list['path'];
+            $user_filename=$attachment_list['filename'];
+
+            echo Display::return_icon('attachment.gif',get_lang('Attachment'));
+            echo '<a href="download.php?file=';
+            echo $realname;
+            echo ' "> '.$user_filename.' </a>';
+            echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span><br />';
+            echo '</td></tr>';
+        }
+
+        // The post has been displayed => it can be removed from the what's new array
+        unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
+        unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
+        unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
+        unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
+        echo "</table></div>";
+    }
 }
 
 $userid = (int)$_GET['user_id'];
@@ -96,15 +96,14 @@ $qualify = (int)$_POST['idtextqualify'];
 //return Max qualify thread
 $max_qualify=show_qualify('2',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
 $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$userid,$threadid);
-if(isset($_POST['idtextqualify']))
-{
-	store_theme_qualify($userid,$threadid,$qualify,$_SESSION['_user']['user_id'],date('Y-m-d H:i:s'),'');
+if (isset($_POST['idtextqualify'])) {
+    store_theme_qualify($userid,$threadid,$qualify,$_SESSION['_user']['user_id'],date('Y-m-d H:i:s'),'');
 }
 
 $result = get_statistical_information($current_thread['thread_id'], $_GET['user_id'], $_GET['cidReq']);
 if($userinf['status']!='1') {
-	echo '<div class="forum-qualification-input-box">';
-	require_once 'forumbody.inc.php';
-	//echo '<a href="forumqualify.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'&user_id='.$userid.'">'.get_lang('ViewHistoryChange').'</a>';
-	echo '</div>';
+    echo '<div class="forum-qualification-input-box">';
+    require_once 'forumbody.inc.php';
+    //echo '<a href="forumqualify.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'&user_id='.$userid.'">'.get_lang('ViewHistoryChange').'</a>';
+    echo '</div>';
 }

+ 118 - 151
main/forum/viewpost.php

@@ -1,8 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-* 	@package chamilo.forum
-*/
+ * @package chamilo.forum
+ */
 // name of the language file that needs to be included
 $language_file = 'forum';
 // including the global dokeos file
@@ -19,34 +19,26 @@ include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
 //require_once (api_get_path(LIBRARY_PATH).'resourcelinker.lib.php');
 $nameTools=get_lang('ToolForum');
 
-/*
------------------------------------------------------------
-	Including necessary files
------------------------------------------------------------
-*/
+/* Including necessary files */
 require 'forumconfig.inc.php';
 require_once 'forumfunction.inc.php';
+
 $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/jquery.js" ></script>';
 $htmlHeadXtra[] = '<script language="javascript">
-										$(document).ready(function(){ $(\'.hide-me\').slideUp() });
-									function hidecontent(content){ $(content).slideToggle(\'normal\'); }
-									</script>';
+                                        $(document).ready(function(){ $(\'.hide-me\').slideUp() });
+                                    function hidecontent(content){ $(content).slideToggle(\'normal\'); }
+                                    </script>';
 
-//are we in a lp ?
+// Are we in a lp ?
 $origin = '';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
-/*
-==============================================================================
-		MAIN DISPLAY SECTION
-==============================================================================
-*/
-/*
------------------------------------------------------------
-	Retrieving forum and forum categorie information
------------------------------------------------------------
-*/
+
+/* MAIN DISPLAY SECTION */
+
+/* Retrieving forum and forum categorie information */
+
 // we are getting all the information about the current forum and forum category.
 // note pcool: I tried to use only one sql statement (and function) for this
 // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
@@ -54,163 +46,138 @@ $current_thread=get_thread_information($_GET['thread']); // note: this has to be
 $current_forum=get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
 $current_forum_category=get_forumcategory_information($current_forum['forum_category']);
 $whatsnew_post_info=$_SESSION['whatsnew_post_info'];
-/*
------------------------------------------------------------
-	Header and Breadcrumbs
------------------------------------------------------------
-*/
+
+/* Header and Breadcrumbs */
 
 if (isset($_SESSION['gradebook'])){
-	$gradebook=	$_SESSION['gradebook'];
+    $gradebook=	$_SESSION['gradebook'];
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[]= array (
-			'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
-			'name' => get_lang('ToolGradebook')
-		);
+    $interbreadcrumb[]= array (
+            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
+            'name' => get_lang('ToolGradebook')
+        );
 }
 
 if ($origin=='learnpath') {
-	include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
+    include(api_get_path(INCLUDE_PATH).'reduced_header.inc.php');
 } else {
-	$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => $nameTools);
-	$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum_category['cat_title']));
-	$interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
+    $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => $nameTools);
+    $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum_category['cat_title']));
+    $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($_GET['search'])),"name" => prepare4display($current_forum['forum_title']));
 
-	// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-	Display :: display_header('');
-	api_display_tool_title($nameTools);
+    // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
+    Display :: display_header('');
+    api_display_tool_title($nameTools);
 }
 
-/*
------------------------------------------------------------
-	Is the user allowed here?
------------------------------------------------------------
-*/
+/* Is the user allowed here? */
+
 // if the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
 if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
-/*
------------------------------------------------------------
-	Actions
------------------------------------------------------------
-*/
+/* Actions */
+
 if ($_GET['action']=='delete' && isset($_GET['content']) && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
-	$message=delete_post($_GET['id']); // note: this has to be cleaned first
+    $message=delete_post($_GET['id']); // note: this has to be cleaned first
 }
 if (($_GET['action']=='invisible' || $_GET['action']=='visible') && isset($_GET['id']) && api_is_allowed_to_edit(false,true)) {
-	$message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
+    $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
 }
 if ($_GET['action']=='move' and isset($_GET['post'])) {
-	$message=move_post_form();
+    $message=move_post_form();
 }
 
-/*
------------------------------------------------------------
-	Display the action messages
------------------------------------------------------------
-*/
+/* Display the action messages */
+
 if (!empty($message)) {
-	Display :: display_confirmation_message(get_lang($message));
+    Display :: display_confirmation_message(get_lang($message));
 }
 
-if ($message<>'PostDeletedSpecial') {// in this case the first and only post of the thread is removed
-	// this increases the number of times the thread has been viewed
-	increase_thread_view($_GET['thread']);
-
-	/*
-	-----------------------------------------------------------
-		Action Links
-	-----------------------------------------------------------
-	*/
-	echo '<div style="float:right;">';
-	$my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;search='.Security::remove_XSS(urlencode($_GET['search']));
-	echo $my_url.'&amp;view=flat&origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
-	echo $my_url.'&amp;view=threaded&origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
-	echo $my_url.'&amp;view=nested&origin='.$origin.'">'.get_lang('NestedView').'</a>';
-	$my_url = null;
-	echo '</div>';
-	// the reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
-	// if one of the three levels is locked then the link should not be displayed
-	if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
-		// The link should only appear when the user is logged in or when anonymous posts are allowed.
-		if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
-			//reply link
-			echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.get_lang('ReplyToThread').'</a>';
-
-			//new thread link
-			if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
-				if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
-					echo '&nbsp;&nbsp;';
-					/*echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('new_thread.png','','','32').'</a>';*/
-				} else {
-					echo get_lang('ForumLocked');
-				}
-			}
-		}
-	}
-	// note: this is to prevent that some browsers display the links over the table (FF does it but Opera doesn't)
-	echo '&nbsp;';
-
-	/*
-	-----------------------------------------------------------
-		Display Forum Category and the Forum information
-	-----------------------------------------------------------
-	*/
-	if (!$_SESSION['view']) {
-		$viewmode=$current_forum['default_view'];
-	} else {
-		$viewmode=$_SESSION['view'];
-	}
-
-	$viewmode_whitelist=array('flat', 'threaded', 'nested');
-	if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
-		$viewmode=Database::escape_string($_GET['view']);
-		$_SESSION['view']=$viewmode;
-	}
-	if (empty($viewmode)) {
-		$viewmode = 'flat';
-	}
-
-	/*
-	-----------------------------------------------------------
-		Display Forum Category and the Forum information
-	-----------------------------------------------------------
-	*/
-	// we are getting all the information about the current forum and forum category.
-	// note pcool: I tried to use only one sql statement (and function) for this
-	// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
-	echo "<table class=\"data_table\" width=\"100%\">\n";
-
-	// the thread
-	echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
-	echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
-
-	if ($origin!='learnpath') {
-		echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
-	}
-
-	echo prepare4display($current_forum['forum_title']).'<br />';
-	echo "</th>\n";
-	echo "\t</tr>\n";
-	echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
-	echo "</table>";
-
-	include_once('viewpost.inc.php');
+if ($message <> 'PostDeletedSpecial') { // in this case the first and only post of the thread is removed
+    // this increases the number of times the thread has been viewed
+    increase_thread_view($_GET['thread']);
+
+    /* Action Links */
+
+    echo '<div style="float:right;">';
+    $my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;origin='.$origin.'&gradebook='.$gradebook.'&amp;search='.Security::remove_XSS(urlencode($_GET['search']));
+    echo $my_url.'&amp;view=flat&origin='.$origin.'">'.get_lang('FlatView').'</a> | ';
+    echo $my_url.'&amp;view=threaded&origin='.$origin.'">'.get_lang('ThreadedView').'</a> | ';
+    echo $my_url.'&amp;view=nested&origin='.$origin.'">'.get_lang('NestedView').'</a>';
+    $my_url = null;
+    echo '</div>';
+    // The reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
+    // If one of the three levels is locked then the link should not be displayed.
+    if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
+        // The link should only appear when the user is logged in or when anonymous posts are allowed.
+        if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
+            //reply link
+            echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.get_lang('ReplyToThread').'</a>';
+
+            //new thread link
+            if (api_is_allowed_to_edit(false,true) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
+                if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
+                    echo '&nbsp;&nbsp;';
+                    /*echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).$origin_string.'">'.Display::return_icon('new_thread.png','','','32').'</a>';*/
+                } else {
+                    echo get_lang('ForumLocked');
+                }
+            }
+        }
+    }
+    // Note: This is to prevent that some browsers display the links over the table (FF does it but Opera doesn't).
+    echo '&nbsp;';
+
+    /* Display Forum Category and the Forum information */
+
+    if (!$_SESSION['view']) {
+        $viewmode=$current_forum['default_view'];
+    } else {
+        $viewmode=$_SESSION['view'];
+    }
+
+    $viewmode_whitelist=array('flat', 'threaded', 'nested');
+    if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
+        $viewmode=Database::escape_string($_GET['view']);
+        $_SESSION['view']=$viewmode;
+    }
+    if (empty($viewmode)) {
+        $viewmode = 'flat';
+    }
+
+    /* Display Forum Category and the Forum information */
+
+    // we are getting all the information about the current forum and forum category.
+    // note pcool: I tried to use only one sql statement (and function) for this
+    // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
+    echo "<table class=\"data_table\" width=\"100%\">\n";
+
+    // The thread
+    echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
+    echo '<span class="forum_title">'.prepare4display($current_thread['thread_title']).'</span><br />';
+
+    if ($origin!='learnpath') {
+        echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' - ';
+    }
+
+    echo prepare4display($current_forum['forum_title']).'<br />';
+    echo "</th>\n";
+    echo "\t</tr>\n";
+    echo '<span>'.prepare4display($current_thread['thread_comment']).'</span>';
+    echo "</table>";
+
+    include_once('viewpost.inc.php');
 } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
 
-/*
-==============================================================================
-		FOOTER
-==============================================================================
-*/
+/* FOOTER */
 if ($origin!='learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 168 - 186
main/forum/viewthread.php

@@ -1,9 +1,9 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-*  @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
-* 	@package chamilo.forum
-*/
+ * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
+ * @package chamilo.forum
+ */
 // name of the language file that needs to be included
 $language_file = array ('forum','group');
 
@@ -29,234 +29,216 @@ $nameTools=get_lang('ToolForum');
 //are we in a lp ?
 $origin = '';
 if (isset($_GET['origin'])) {
-	$origin =  Security::remove_XSS($_GET['origin']);
+    $origin =  Security::remove_XSS($_GET['origin']);
 }
 
+/* MAIN DISPLAY SECTION */
 
-/*
-		MAIN DISPLAY SECTION
-*/
-/*
-	Retrieving forum and forum categorie information
-*/
-// we are getting all the information about the current forum and forum category.
-// note pcool: I tried to use only one sql statement (and function) for this
-// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
+/* Retrieving forum and forum categorie information */
+
+// We are getting all the information about the current forum and forum category.
+// Note pcool: I tried to use only one sql statement (and function) for this,
+// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
 $current_thread	= get_thread_information($_GET['thread']); // note: this has to be validated that it is an existing thread
 $current_forum	= get_forum_information($current_thread['forum_id']); // note: this has to be validated that it is an existing forum.
 $current_forum_category	= get_forumcategory_information($current_forum['forum_category']);
 
 $whatsnew_post_info	= $_SESSION['whatsnew_post_info']; //this variable should be deprecated?
 
-/*
-	Header and Breadcrumbs
-*/
-
-
+/* Header and Breadcrumbs */
 
 if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
-	$_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
-	$gradebook=	$_SESSION['gradebook'];
+    $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
+    $gradebook=	$_SESSION['gradebook'];
 }
 
 if (!empty($gradebook) && $gradebook=='view') {
-	$interbreadcrumb[] = array (
-		'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
-		'name' => get_lang('ToolGradebook')
-	);
+    $interbreadcrumb[] = array (
+        'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
+        'name' => get_lang('ToolGradebook')
+    );
 }
 
 if ($origin=='group') {
-	$session_toolgroup	= intval($_SESSION['toolgroup']);
-	$group_properties	= GroupManager :: get_group_properties($session_toolgroup);
-	$interbreadcrumb[] 	= array("url"=>"../group/group.php", "name" => get_lang('Groups'));
-	$interbreadcrumb[] 	= array("url"=>"../group/group_space.php?gidReq=".$session_toolgroup, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
-	$interbreadcrumb[] 	= array("url"=>"viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gidReq=".$session_toolgroup."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => Security::remove_XSS($current_forum['forum_title']));
-	$interbreadcrumb[] 	= array("url"=>"viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => Security::remove_XSS($current_thread['thread_title']));
+    $session_toolgroup	= intval($_SESSION['toolgroup']);
+    $group_properties	= GroupManager :: get_group_properties($session_toolgroup);
+    $interbreadcrumb[] 	= array("url"=>"../group/group.php", "name" => get_lang('Groups'));
+    $interbreadcrumb[] 	= array("url"=>"../group/group_space.php?gidReq=".$session_toolgroup, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
+    $interbreadcrumb[] 	= array("url"=>"viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;gidReq=".$session_toolgroup."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => Security::remove_XSS($current_forum['forum_title']));
+    $interbreadcrumb[] 	= array("url"=>"viewthread.php?forum=".Security::remove_XSS($_GET['forum'])."&gradebook=".$gradebook."&amp;thread=".Security::remove_XSS($_GET['thread']),"name" => Security::remove_XSS($current_thread['thread_title']));
 
-	Display :: display_header('');
-	//api_display_tool_title($nameTools);
+    Display :: display_header('');
+    //api_display_tool_title($nameTools);
 
 } else {
 
-	$my_search=isset($_GET['search']) ? $_GET['search'] : '';
-
-	if ($origin=='learnpath') {
-		require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
-	} else {
-		$interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($my_search)),"name" => $nameTools);
-		$interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => Security::remove_XSS($current_forum_category['cat_title']));
-		$interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => Security::remove_XSS($current_forum['forum_title']));
-		$message = isset($message) ? $message : '';
-		// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
-		Display :: display_header('');
-		//api_display_tool_title($nameTools);
-	}
+    $my_search=isset($_GET['search']) ? $_GET['search'] : '';
+
+    if ($origin=='learnpath') {
+        require_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
+    } else {
+        $interbreadcrumb[]=array("url" => "index.php?gradebook=$gradebook&search=".Security::remove_XSS(urlencode($my_search)),"name" => $nameTools);
+        $interbreadcrumb[]=array("url" => "viewforumcategory.php?forumcategory=".$current_forum_category['cat_id']."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => Security::remove_XSS($current_forum_category['cat_title']));
+        $interbreadcrumb[]=array("url" => "viewforum.php?forum=".Security::remove_XSS($_GET['forum'])."&amp;origin=".$origin."&amp;search=".Security::remove_XSS(urlencode($my_search)),"name" => Security::remove_XSS($current_forum['forum_title']));
+        $message = isset($message) ? $message : '';
+        // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
+        Display :: display_header('');
+        //api_display_tool_title($nameTools);
+    }
 }
-/*
-	Is the user allowed here?
-*/
+
+/* Is the user allowed here? */
+
 // if the user is not a course administrator and the forum is hidden
 // then the user is not allowed here.
 if (!api_is_allowed_to_edit(false,true) AND ($current_forum['visibility']==0 OR $current_thread['visibility']==0)) {
-	$forum_allow = forum_not_allowed_here();
-	if ($forum_allow === false) {
-		exit;
-	}
+    $forum_allow = forum_not_allowed_here();
+    if ($forum_allow === false) {
+        exit;
+    }
 }
 
-/*
-	Actions
-*/
+/* Actions */
+
 $my_action = isset($_GET['action']) ? $_GET['action'] : '';
 if ($my_action=='delete' AND isset($_GET['content']) AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true)) {
-	$message=delete_post($_GET['id']); // note: this has to be cleaned first
+    $message=delete_post($_GET['id']); // note: this has to be cleaned first
 }
 if (($my_action=='invisible' OR $my_action=='visible') AND isset($_GET['id']) AND api_is_allowed_to_edit(false,true)) {
-	$message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
+    $message=approve_post($_GET['id'],$_GET['action']); // note: this has to be cleaned first
 }
 if ($my_action=='move' AND isset($_GET['post'])) {
-	$message=move_post_form();
+    $message=move_post_form();
 }
 
-/*
-	Display the action messages
-*/
+/* Display the action messages */
+
 $my_message = isset($message) ? $message : '';
 if ($my_message) {
-	Display :: display_confirmation_message(get_lang($my_message));
+    Display :: display_confirmation_message(get_lang($my_message));
 }
 
-if ($my_message<>'PostDeletedSpecial') {
-	// in this case the first and only post of the thread is removed
-	// this increases the number of times the thread has been viewed
-	increase_thread_view($_GET['thread']);
-	/* 
-			Action Links
-	*/
-	if ($origin=='learnpath') {
-		echo '<div style="height:15px">&nbsp;</div>';
-	}
-	echo '<div class="actions">';
-	echo '<span style="float:right;">'.search_link().'</span>';
-	if ($origin != 'learnpath') {
-		
-		if ($origin=='group') {
-			echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
-			echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'&origin='.$origin.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
-		}
-		else{
-			echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';	
-			echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
-		}
-		
-	
-	}
-	// the reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
-	// if one of the three levels is locked then the link should not be displayed
-	if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
-		// The link should only appear when the user is logged in or when anonymous posts are allowed.
-		if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
-			//reply link
-			if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
-				echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.Display::return_icon('reply_thread.png',get_lang('ReplyToThread'),'','32').'</a>';
-			}
-			//new thread link
-			if ((api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
-				if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
-					echo '&nbsp;&nbsp;';
+if ($my_message <> 'PostDeletedSpecial') {
+    // in this case the first and only post of the thread is removed
+    // this increases the number of times the thread has been viewed
+    increase_thread_view($_GET['thread']);
+
+    /* Action Links */
+
+    if ($origin=='learnpath') {
+        echo '<div style="height:15px">&nbsp;</div>';
+    }
+    echo '<div class="actions">';
+    echo '<span style="float:right;">'.search_link().'</span>';
+    if ($origin != 'learnpath') {
+
+        if ($origin=='group') {
+            echo '<a href="../group/group_space.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('Groups'),'','32').'</a>';
+            echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'&origin='.$origin.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
+        }
+        else{
+            echo '<a href="index.php?gradebook='.$gradebook.'">'.Display::return_icon('back.png',get_lang('BackToForumOverview'),'','32').'</a>';
+            echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'">'.Display::return_icon('forum.png',get_lang('BackToForum'),'','32').'</a>';
+        }
+
+    }
+    // The reply to thread link should only appear when the forum_category is not locked AND the forum is not locked AND the thread is not locked.
+    // If one of the three levels is locked then the link should not be displayed.
+    if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
+        // The link should only appear when the user is logged in or when anonymous posts are allowed.
+        if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
+            //reply link
+            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
+                echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.Security::remove_XSS($_GET['forum']).'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;action=replythread&origin='.$origin.'">'.Display::return_icon('reply_thread.png',get_lang('ReplyToThread'),'','32').'</a>';
+            }
+            //new thread link
+            if ((api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) OR ($current_forum['allow_new_threads']==1 AND isset($_user['user_id'])) OR ($current_forum['allow_new_threads']==1 AND !isset($_user['user_id']) AND $current_forum['allow_anonymous']==1)) {
+                if ($current_forum['locked'] <> 1 AND $current_forum['locked'] <> 1) {
+                    echo '&nbsp;&nbsp;';
 /*					if ( isset($_GET['gradebook']) && $_GET['gradebook']!=""){
-						$info_thread=get_thread_information($_GET['thread']);
-						echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.$info_thread['forum_id'].'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'">'.Display::return_icon('new_thread.png', get_lang('NewTopic'),'','32').'</a>';
-					} else {
-						echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'">'.Display::return_icon('new_thread.png', get_lang('NewTopic'),'','32').'</a>';
-					} */
-				} else {
-					echo get_lang('ForumLocked');
-				}
-			}
-		}
-	}
-
-	// the different views of the thread
-	if ($origin != 'learnpath') {
-		$my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;search='.Security::remove_XSS(urlencode($my_search));
-		echo $my_url.'&amp;view=flat&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_listview.gif',get_lang('FlatView')).get_lang('FlatView').'</a>';
-		echo $my_url.'&amp;view=threaded&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_threadedview.gif',get_lang('ThreadedView')).get_lang('ThreadedView').'</a>';
-		echo $my_url.'&amp;view=nested&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_nestedview.gif',get_lang('NestedView')).get_lang('NestedView').'</a>';
-	}
-	$my_url = null;
-
-	echo '</div>&nbsp;';
-
-
-	/*
-	-----------------------------------------------------------
-		Display Forum Category and the Forum information
-	-----------------------------------------------------------
-	*/
-
-	if (!isset($_SESSION['view']))	{
-		$viewmode=$current_forum['default_view'];
-	} else {
-		$viewmode=$_SESSION['view'];
-	}
-
-	$viewmode_whitelist=array('flat', 'threaded', 'nested');
-	if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
-		$viewmode=$_GET['view'];
-		$_SESSION['view']=$viewmode;
-	}
-	if(empty($viewmode)) {
-		$viewmode = 'flat';
-	}
-
-	/*
-		Display Forum Category and the Forum information
-	*/
-	// we are getting all the information about the current forum and forum category.
-	// note pcool: I tried to use only one sql statement (and function) for this
-	// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table
-    
-	echo "<table class=\"forum_table_title\" width='100%'>";
-
-	// the thread
-	echo "<tr><th style=\"padding:5px;\" align=\"left\" colspan=\"6\">";
+                        $info_thread=get_thread_information($_GET['thread']);
+                        echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.$info_thread['forum_id'].'&origin='.$origin.'&gradebook='.Security::remove_XSS($_GET['gradebook']).'">'.Display::return_icon('new_thread.png', get_lang('NewTopic'),'','32').'</a>';
+                    } else {
+                        echo '<a href="newthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'">'.Display::return_icon('new_thread.png', get_lang('NewTopic'),'','32').'</a>';
+                    } */
+                } else {
+                    echo get_lang('ForumLocked');
+                }
+            }
+        }
+    }
+
+    // the different views of the thread
+    if ($origin != 'learnpath') {
+        $my_url = '<a href="viewthread.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;forum='.Security::remove_XSS($_GET['forum']).'&amp;origin='.$origin.'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']).'&amp;search='.Security::remove_XSS(urlencode($my_search));
+        echo $my_url.'&amp;view=flat&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_listview.gif',get_lang('FlatView')).get_lang('FlatView').'</a>';
+        echo $my_url.'&amp;view=threaded&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_threadedview.gif',get_lang('ThreadedView')).get_lang('ThreadedView').'</a>';
+        echo $my_url.'&amp;view=nested&origin='.$origin.'&amp;gradebook='.$gradebook.'">'.Display::return_icon('forum_nestedview.gif',get_lang('NestedView')).get_lang('NestedView').'</a>';
+    }
+    $my_url = null;
+
+    echo '</div>&nbsp;';
+
+    /* Display Forum Category and the Forum information */
+
+    if (!isset($_SESSION['view']))	{
+        $viewmode=$current_forum['default_view'];
+    } else {
+        $viewmode=$_SESSION['view'];
+    }
+
+    $viewmode_whitelist=array('flat', 'threaded', 'nested');
+    if (isset($_GET['view']) and in_array($_GET['view'],$viewmode_whitelist)) {
+        $viewmode=$_GET['view'];
+        $_SESSION['view']=$viewmode;
+    }
+    if(empty($viewmode)) {
+        $viewmode = 'flat';
+    }
+
+    /* Display Forum Category and the Forum information */
+
+    // We are getting all the information about the current forum and forum category.
+    // Note pcool: I tried to use only one sql statement (and function) for this,
+    // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
+
+    echo "<table class=\"forum_table_title\" width='100%'>";
+
+    // the thread
+    echo "<tr><th style=\"padding:5px;\" align=\"left\" colspan=\"6\">";
     echo '<div class="forum_title">';
         echo '<a href="viewforum.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gidReq='.$session_toolgroup.'&origin='.$origin.'">'.$current_forum['forum_title'].'</a><br />';
-        echo '<span class="forum_description">';        
+        echo '<span class="forum_description">';
         echo $current_forum['forum_comment'];
         echo '</span>';
-    echo '</div>';            
-                
-
-	if ($origin!='learnpath') {
-		//echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' ';
-	}  
-	
-	echo "</th>";
-	echo "</tr>";	
-	echo "</table>";
-
-	switch ($viewmode) {
-		case 'flat':
-			include_once('viewthread_flat.inc.php');
-			break;
-		case 'threaded':
-			include_once('viewthread_threaded.inc.php');
-			break;
-		case 'nested':
-			include_once('viewthread_nested.inc.php');
-			break;
-		default:
-			include_once('viewthread_flat.inc.php');
-			break;
-	} 
+    echo '</div>';
+
+
+    if ($origin!='learnpath') {
+        //echo '<span class="forum_low_description">'.prepare4display($current_forum_category['cat_title']).' ';
+    }
+
+    echo "</th>";
+    echo "</tr>";
+    echo "</table>";
+
+    switch ($viewmode) {
+        case 'flat':
+            include_once('viewthread_flat.inc.php');
+            break;
+        case 'threaded':
+            include_once('viewthread_threaded.inc.php');
+            break;
+        case 'nested':
+            include_once('viewthread_nested.inc.php');
+            break;
+        default:
+            include_once('viewthread_flat.inc.php');
+            break;
+    }
 } // if ($message<>'PostDeletedSpecial') // in this case the first and only post of the thread is removed
 
-/*
-		FOOTER
-*/
+/* FOOTER */
 if ($origin!='learnpath') {
-	Display :: display_footer();
+    Display :: display_footer();
 }

+ 134 - 134
main/forum/viewthread_flat.inc.php

@@ -2,159 +2,159 @@
 /* For licensing terms, see /license.txt */
 /**
  * This script manages the display of forum threads in flat view
- * @copyright Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes 
+ * @copyright Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
  * @package chamilo.forum
  */
 //delete attachment file
 if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
-	delete_attachment(0,$_GET['id_attach']);
+    delete_attachment(0,$_GET['id_attach']);
 }
 
 if (isset($current_thread['thread_id'])){
 
-	$rows=get_posts($current_thread['thread_id']);
-	$increment=0;
-		
-	$clean_forum_id  = intval($_GET['forum']);
-	$clean_thread_id = intval($_GET['thread']);
-	
-	foreach ($rows as $row) {
-		echo '<table width="100%" class="forum_table" cellspacing="5" border="0">';
-		// the style depends on the status of the message: approved or not
-		if ($row['visible']=='0') {
-			$titleclass='forum_message_post_title_2_be_approved';
-			$messageclass='forum_message_post_text_2_be_approved';
-			$leftclass='forum_message_left_2_be_approved';
-		} else {
-			$titleclass='forum_message_post_title';
-			$messageclass='forum_message_post_text';
-			$leftclass='forum_message_left';
-		}
-        
+    $rows=get_posts($current_thread['thread_id']);
+    $increment=0;
+
+    $clean_forum_id  = intval($_GET['forum']);
+    $clean_thread_id = intval($_GET['thread']);
+
+    foreach ($rows as $row) {
+        echo '<table width="100%" class="forum_table" cellspacing="5" border="0">';
+        // the style depends on the status of the message: approved or not
+        if ($row['visible']=='0') {
+            $titleclass='forum_message_post_title_2_be_approved';
+            $messageclass='forum_message_post_text_2_be_approved';
+            $leftclass='forum_message_left_2_be_approved';
+        } else {
+            $titleclass='forum_message_post_title';
+            $messageclass='forum_message_post_text';
+            $leftclass='forum_message_left';
+        }
+
        echo '<thead>';
        echo '<tr>';
        echo '<th class="forum_head" colspan="2">'.prepare4display($row['post_title'])."</th>";
        echo '</tr>';
        echo '</thead>';
-	   
-		echo "<tr>";
-		//echo "<td rowspan=\"3\" class=\"$leftclass\">";
+
+        echo "<tr>";
+        //echo "<td rowspan=\"3\" class=\"$leftclass\">";
         echo "<td rowspan=\"2\" class=\"$leftclass\">";
-		if ($row['user_id']=='0') {
-			$name=prepare4display($row['poster_name']);
-		} else {
-			$name=api_get_person_name($row['firstname'], $row['lastname']);
-		}
-		if($origin!='learnpath') {
-			if (api_get_course_setting('allow_user_image_forum')) {
-				echo '<br />'.display_user_image($row['user_id'],$name).'<br />';
-			}
-			echo display_user_link($row['user_id'], $name).'<br />';
-		} else {
-			echo $name. '<br />';
-		}
-		echo api_convert_and_format_date($row['post_date'], null, date_default_timezone_get()).'<br /><br />';
-		// get attach id
-		$attachment_list=get_attachment($row['post_id']);
-		$id_attach = !empty($attachment_list)?$attachment_list['id']:'';
-		// The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
-		// The course admin him/herself can do this off course always
-		if (($current_forum['allow_edit']==1 AND $row['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
-			if (api_is_allowed_to_session_edit(false,true)) {                                
-				echo "<a href=\"editpost.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;post=".$row['post_id']."&origin=".$origin."&edit=edition&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+        if ($row['user_id']=='0') {
+            $name=prepare4display($row['poster_name']);
+        } else {
+            $name=api_get_person_name($row['firstname'], $row['lastname']);
+        }
+        if($origin!='learnpath') {
+            if (api_get_course_setting('allow_user_image_forum')) {
+                echo '<br />'.display_user_image($row['user_id'],$name).'<br />';
+            }
+            echo display_user_link($row['user_id'], $name).'<br />';
+        } else {
+            echo $name. '<br />';
+        }
+        echo api_convert_and_format_date($row['post_date'], null, date_default_timezone_get()).'<br /><br />';
+        // get attach id
+        $attachment_list=get_attachment($row['post_id']);
+        $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
+        // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
+        // The course admin him/herself can do this off course always
+        if (($current_forum['allow_edit']==1 AND $row['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
+            if (api_is_allowed_to_session_edit(false,true)) {
+                echo "<a href=\"editpost.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;post=".$row['post_id']."&origin=".$origin."&edit=edition&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+            }
+        }
+
+        if ($origin != 'learnpath') {
+            if (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
+                echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;id=".$row['post_id']."&origin=".$origin."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+                display_visible_invisible_icon('post', $row['post_id'], $row['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id, 'origin'=>$origin ));
+                echo "";
+                if ($increment>0) {
+                    echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=move&amp;post=".$row['post_id']."&origin=".$origin."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>";
+                }
+            }
+        }
+
+        $userinf = api_get_user_info($row['user_id']);
+        $user_status = api_get_status_of_user_in_course($row['user_id'],api_get_course_id());
+        $current_qualify_thread = show_qualify('1',$_GET['cidReq'],$_GET['forum'],$row['poster_id'],$_GET['thread']);
+        if (api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
+            if( isset($_GET['gradebook'])){
+                if ($increment>0 && $user_status!=1 ) {
+                    $info_thread=get_thread_information($clean_thread_id);
+                    echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$info_thread['forum_id']."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$row['post_id']."&amp;user=".$row['poster_id']."&user_id=".$row['poster_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."&gradebook=".Security::remove_XSS($_GET['gradebook'])."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
+                 }
+            } else {
+                if ($increment>0 && $user_status!=1 ) {
+                    echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$row['post_id']."&amp;user=".$row['poster_id']."&user_id=".$row['poster_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
+                }
+            }
+        }
+        //echo '<br /><br />';
+        if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
+            if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
+                if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
+                    echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$row['post_id'].'&amp;action=replymessage&origin='.$origin.'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
+                    echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$row['post_id'].'&amp;action=quote&origin='.$origin.'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
+                }
             }
-		}
-	
-		if ($origin != 'learnpath') {
-			if (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
-				echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;id=".$row['post_id']."&origin=".$origin."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-				display_visible_invisible_icon('post', $row['post_id'], $row['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id, 'origin'=>$origin ));
-				echo "";
-				if ($increment>0) {
-					echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=move&amp;post=".$row['post_id']."&origin=".$origin."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>";
-				}
-			}
-		}
-	
-		$userinf = api_get_user_info($row['user_id']);
-		$user_status = api_get_status_of_user_in_course($row['user_id'],api_get_course_id());
-		$current_qualify_thread = show_qualify('1',$_GET['cidReq'],$_GET['forum'],$row['poster_id'],$_GET['thread']);
-		if (api_is_allowed_to_edit(null,true) && $origin != 'learnpath') {
-			if( isset($_GET['gradebook'])){
-				if ($increment>0 && $user_status!=1 ) {
-					$info_thread=get_thread_information($clean_thread_id);
-					echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$info_thread['forum_id']."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$row['post_id']."&amp;user=".$row['poster_id']."&user_id=".$row['poster_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."&gradebook=".Security::remove_XSS($_GET['gradebook'])."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
-				 }
-			} else {
-				if ($increment>0 && $user_status!=1 ) {
-					echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$row['post_id']."&amp;user=".$row['poster_id']."&user_id=".$row['poster_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
-				}
-			}
-		}
-		//echo '<br /><br />';
-		if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
-			if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
-				if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
-					echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$row['post_id'].'&amp;action=replymessage&origin='.$origin.'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
-					echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$row['post_id'].'&amp;action=quote&origin='.$origin.'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
-				}
-			}
-		} else {
-			if ($current_forum_category['locked']==1) {
-				echo get_lang('ForumcategoryLocked').'<br />';
-			}
-			if ($current_forum['locked']==1) {
-				echo get_lang('ForumLocked').'<br />';
-			}
-			if ($current_thread['locked']==1) {
-				echo get_lang('ThreadLocked').'<br />';
-			}
-		}
-		echo "</td>";
-		// prepare the notification icon
-		if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$row['thread_id']])) {
-			$post_image=icon('../img/forumpostnew.gif');
-		} else {
-			$post_image=icon('../img/forumpost.gif');
-		}
-		if ($row['post_notification']=='1' AND $row['poster_id']==$_user['user_id']) {
-			$post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
-		}
-		// The post title
-		
-		echo "</tr>";
-		
+        } else {
+            if ($current_forum_category['locked']==1) {
+                echo get_lang('ForumcategoryLocked').'<br />';
+            }
+            if ($current_forum['locked']==1) {
+                echo get_lang('ForumLocked').'<br />';
+            }
+            if ($current_thread['locked']==1) {
+                echo get_lang('ThreadLocked').'<br />';
+            }
+        }
+        echo "</td>";
+        // prepare the notification icon
+        if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$row['thread_id']])) {
+            $post_image=icon('../img/forumpostnew.gif');
+        } else {
+            $post_image=icon('../img/forumpost.gif');
+        }
+        if ($row['post_notification']=='1' AND $row['poster_id']==$_user['user_id']) {
+            $post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
+        }
+        // The post title
+
+        echo "</tr>";
+
         // The post message
         echo "<tr>";
         // see comments inside forumfunction.inc.php to lower filtering and allow more visual changes
         echo "<td class=\"$messageclass\">".prepare4display($row['post_text'])."</td>";
         echo "</tr>";
-	
-		// The check if there is an attachment
-		 
-		$attachment_list=get_attachment($row['post_id']);
-		if (!empty($attachment_list)) {
-			echo '<tr><td height="50%">';
-			$realname=$attachment_list['path'];
-			$user_filename=$attachment_list['filename'];
-	
-			echo Display::return_icon('attachment.gif',get_lang('Attachment'));
-			echo '<a href="download.php?file=';
-			echo $realname;
-			echo ' "> '.$user_filename.' </a>';
-			echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
-			if (($current_forum['allow_edit']==1 AND $row['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))	{
-			echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
-			}
-			echo '</td></tr>';
-		}
-	
-		// The post has been displayed => it can be removed from the what's new array
-		unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-		unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
-		unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-		unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
-		echo "</table>";
-		$increment++;
+
+        // The check if there is an attachment
+
+        $attachment_list=get_attachment($row['post_id']);
+        if (!empty($attachment_list)) {
+            echo '<tr><td height="50%">';
+            $realname=$attachment_list['path'];
+            $user_filename=$attachment_list['filename'];
+
+            echo Display::return_icon('attachment.gif',get_lang('Attachment'));
+            echo '<a href="download.php?file=';
+            echo $realname;
+            echo ' "> '.$user_filename.' </a>';
+            echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
+            if (($current_forum['allow_edit']==1 AND $row['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))	{
+            echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
+            }
+            echo '</td></tr>';
+        }
+
+        // The post has been displayed => it can be removed from the what's new array
+        unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
+        unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']]);
+        unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
+        unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']]);
+        echo "</table>";
+        $increment++;
     }
 }

+ 116 - 116
main/forum/viewthread_nested.inc.php

@@ -2,15 +2,15 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
-*	@copyright Ghent University
-*	@package chamilo.forum
-*/
+ * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
+ * @copyright Ghent University
+ * @package chamilo.forum
+ */
 
 require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
 
-//are we in a lp ?
+// Are we in a lp ?
 $origin = '';
 if(isset($_GET['origin'])) {
     $origin =  Security::remove_XSS($_GET['origin']);
@@ -18,10 +18,10 @@ if(isset($_GET['origin'])) {
 
 //delete attachment file
 if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
-	delete_attachment(0,$_GET['id_attach']);
+    delete_attachment(0,$_GET['id_attach']);
 }
 
-$rows=get_posts($_GET['thread']); // note: this has to be cleaned first
+$rows=get_posts($_GET['thread']); // Note: This has to be cleaned first.
 $rows=calculate_children($rows);
 $count=0;
 
@@ -29,119 +29,119 @@ $clean_forum_id  = intval($_GET['forum']);
 $clean_thread_id = intval($_GET['thread']);
 
 foreach ($rows as $post) {
-	// the style depends on the status of the message: approved or not
-	if ($post['visible']=='0') {
-		$titleclass='forum_message_post_title_2_be_approved';
-		$messageclass='forum_message_post_text_2_be_approved';
-		$leftclass='forum_message_left_2_be_approved';
-	} else {
-		$titleclass='forum_message_post_title';
-		$messageclass='forum_message_post_text';
-		$leftclass='forum_message_left';
-	}
+    // The style depends on the status of the message: approved or not.
+    if ($post['visible']=='0') {
+        $titleclass='forum_message_post_title_2_be_approved';
+        $messageclass='forum_message_post_text_2_be_approved';
+        $leftclass='forum_message_left_2_be_approved';
+    } else {
+        $titleclass='forum_message_post_title';
+        $messageclass='forum_message_post_text';
+        $leftclass='forum_message_left';
+    }
 
-	$indent=$post['indent_cnt']*'20';
-	echo "<div style=\"margin-left: ".$indent."px;\">";
-	echo "<table width=\"100%\"  class=\"post\" cellspacing=\"5\" border=\"0\">";
-	echo "<tr>";
-	echo "<td rowspan=\"3\" class=\"$leftclass\">";
-	if ($post['user_id']=='0') {
-		$name=$post['poster_name'];
-	} else {
-		$name=api_get_person_name($post['firstname'], $post['lastname']);
-	}
-	if (api_get_course_setting('allow_user_image_forum')) {
-		echo '<br />'.display_user_image($post['user_id'],$name,$origin).'<br />';
-	}
-	echo display_user_link($post['user_id'], $name, $origin).'<br />';
-	echo api_convert_and_format_date($post['post_date'], null, date_default_timezone_get()).'<br /><br />';
-	// get attach id
-	$attachment_list=get_attachment($post['post_id']);
-	$id_attach = !empty($attachment_list)?$attachment_list['id']:'';
-	// The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
-	// The course admin him/herself can do this off course always
-	if (($current_forum['allow_edit']==1 AND $post['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
-		echo "<a href=\"editpost.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;post=".$post['post_id']."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
-	}
-	if (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
-		echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;id=".$post['post_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-		display_visible_invisible_icon('post', $post['post_id'], $post['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id ));
-		echo "";
-		if ($count>0) {
-			echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=move&amp;origin=".$origin."&amp;post=".$post['post_id']."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>";
-		}
-	}
-	$userinf=api_get_user_info($post['user_id']);
-	$user_status=api_get_status_of_user_in_course($post['user_id'],api_get_course_id());
-	if (api_is_allowed_to_edit(null,true)) {
-		if ($count>0 && $user_status!=1) {
-			$current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$post['user_id'],$_GET['thread']);
-			echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$post['post_id']."&amp;user=".$post['user_id']."&user_id=".$post['user_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
-		}
-	}
-	//echo '<br /><br />';
-	//if (($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0) OR api_is_allowed_to_edit())
-	if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
-		if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
-			if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
-				echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$post['post_id'].'&amp;action=replymessage&amp;origin='. $origin .'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
-				echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$post['post_id'].'&amp;action=quote&amp;origin='. $origin .'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
-			}
-		}
-	} else {
-		if ($current_forum_category['locked']==1) {
-			echo get_lang('ForumcategoryLocked').'<br />';
-		}
-		if ($current_forum['locked']==1) {
-			echo get_lang('ForumLocked').'<br />';
-		}
-		if ($current_thread['locked']==1) {
-			echo get_lang('ThreadLocked').'<br />';
-		}
-	}
-	echo "</td>";
-	// note: this can be removed here because it will be displayed in the tree
-	if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])) {
-		$post_image=icon('../img/forumpostnew.gif');
-	} else {
-		$post_image=icon('../img/forumpost.gif');
-	}
-	if ($post['post_notification']=='1' AND $post['poster_id']==$_user['user_id']) {
-		$post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
-	}
-	// The post title
-	echo "<td class=\"$titleclass\">".prepare4display($post['post_title'])."</td>";
-	echo "</tr>";
+    $indent=$post['indent_cnt']*'20';
+    echo "<div style=\"margin-left: ".$indent."px;\">";
+    echo "<table width=\"100%\"  class=\"post\" cellspacing=\"5\" border=\"0\">";
+    echo "<tr>";
+    echo "<td rowspan=\"3\" class=\"$leftclass\">";
+    if ($post['user_id']=='0') {
+        $name=$post['poster_name'];
+    } else {
+        $name=api_get_person_name($post['firstname'], $post['lastname']);
+    }
+    if (api_get_course_setting('allow_user_image_forum')) {
+        echo '<br />'.display_user_image($post['user_id'],$name,$origin).'<br />';
+    }
+    echo display_user_link($post['user_id'], $name, $origin).'<br />';
+    echo api_convert_and_format_date($post['post_date'], null, date_default_timezone_get()).'<br /><br />';
+    // get attach id
+    $attachment_list=get_attachment($post['post_id']);
+    $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
+    // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
+    // The course admin him/herself can do this off course always
+    if (($current_forum['allow_edit']==1 AND $post['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
+        echo "<a href=\"editpost.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;post=".$post['post_id']."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+    }
+    if (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
+        echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;id=".$post['post_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+        display_visible_invisible_icon('post', $post['post_id'], $post['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id ));
+        echo "";
+        if ($count>0) {
+            echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=move&amp;origin=".$origin."&amp;post=".$post['post_id']."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>";
+        }
+    }
+    $userinf=api_get_user_info($post['user_id']);
+    $user_status=api_get_status_of_user_in_course($post['user_id'],api_get_course_id());
+    if (api_is_allowed_to_edit(null,true)) {
+        if ($count>0 && $user_status!=1) {
+            $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$post['user_id'],$_GET['thread']);
+            echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$post['post_id']."&amp;user=".$post['user_id']."&user_id=".$post['user_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
+        }
+    }
+    //echo '<br /><br />';
+    //if (($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0) OR api_is_allowed_to_edit())
+    if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
+        if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
+            if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
+                echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$post['post_id'].'&amp;action=replymessage&amp;origin='. $origin .'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
+                echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$post['post_id'].'&amp;action=quote&amp;origin='. $origin .'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
+            }
+        }
+    } else {
+        if ($current_forum_category['locked']==1) {
+            echo get_lang('ForumcategoryLocked').'<br />';
+        }
+        if ($current_forum['locked']==1) {
+            echo get_lang('ForumLocked').'<br />';
+        }
+        if ($current_thread['locked']==1) {
+            echo get_lang('ThreadLocked').'<br />';
+        }
+    }
+    echo "</td>";
+    // note: this can be removed here because it will be displayed in the tree
+    if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])) {
+        $post_image=icon('../img/forumpostnew.gif');
+    } else {
+        $post_image=icon('../img/forumpost.gif');
+    }
+    if ($post['post_notification']=='1' AND $post['poster_id']==$_user['user_id']) {
+        $post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
+    }
+    // The post title
+    echo "<td class=\"$titleclass\">".prepare4display($post['post_title'])."</td>";
+    echo "</tr>";
 
-	// The post message		
-	echo "<tr>";
-	echo "<td class=\"$messageclass\">".prepare4display($post['post_text'])."</td>";
-	echo "</tr>";
+    // The post message
+    echo "<tr>";
+    echo "<td class=\"$messageclass\">".prepare4display($post['post_text'])."</td>";
+    echo "</tr>";
 
 
-	// The check if there is an attachment
-	$attachment_list=get_attachment($post['post_id']);
+    // The check if there is an attachment
+    $attachment_list=get_attachment($post['post_id']);
 
-	if (!empty($attachment_list)) {
-		echo '<tr><td height="50%">';
-		$realname=$attachment_list['path'];
-		$user_filename=$attachment_list['filename'];
+    if (!empty($attachment_list)) {
+        echo '<tr><td height="50%">';
+        $realname=$attachment_list['path'];
+        $user_filename=$attachment_list['filename'];
 
-		echo Display::return_icon('attachment.gif',get_lang('Attachment'));
-		echo '<a href="download.php?file=';
-		echo $realname;
-		echo ' "> '.$user_filename.' </a>';
-		echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
-		if (($current_forum['allow_edit']==1 AND $post['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))	{
-		echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
-		}
-		echo '</td></tr>';
-	}
+        echo Display::return_icon('attachment.gif',get_lang('Attachment'));
+        echo '<a href="download.php?file=';
+        echo $realname;
+        echo ' "> '.$user_filename.' </a>';
+        echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
+        if (($current_forum['allow_edit']==1 AND $post['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))	{
+        echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
+        }
+        echo '</td></tr>';
+    }
 
-	// The post has been displayed => it can be removed from the what's new array
-	unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-	unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
-	echo "</table>";
-	echo "</div>";
-	$count++;
+    // The post has been displayed => it can be removed from the what's new array
+    unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
+    unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
+    echo "</table>";
+    echo "</div>";
+    $count++;
 }

+ 138 - 172
main/forum/viewthread_threaded.inc.php

@@ -2,53 +2,53 @@
 /* For licensing terms, see /license.txt */
 
 /**
-*	These files are a complete rework of the forum. The database structure is
-*	based on phpBB but all the code is rewritten. A lot of new functionalities
-*	are added:
-* 	- forum categories and forums can be sorted up or down, locked or made invisible
-*	- consistent and integrated forum administration
-* 	- forum options: 	are students allowed to edit their post?
-* 						moderation of posts (approval)
-* 						reply only forums (students cannot create new threads)
-* 						multiple forums per group
-*	- sticky messages
-* 	- new view option: nested view
-* 	- quoting a message
-*
-*	@author Patrick Cool <patrick.cool@UGent.be>, Ghent University
-*	@author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
-*
-* 	@package chamilo.forum
-*/
+ * These files are a complete rework of the forum. The database structure is
+ * based on phpBB but all the code is rewritten. A lot of new functionalities
+ * are added:
+ * - forum categories and forums can be sorted up or down, locked or made invisible
+ * - consistent and integrated forum administration
+ * - forum options:     are students allowed to edit their post?
+ *                      moderation of posts (approval)
+ *                      reply only forums (students cannot create new threads)
+ *                      multiple forums per group
+ * - sticky messages
+ * - new view option: nested view
+ * - quoting a message
+ *
+ * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @author Julio Montoya <gugli100@gmail.com> UI Improvements + lots of bugfixes
+ *
+ * @package chamilo.forum
+ */
 
 require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
 
-$rows	= get_posts($_GET['thread']); // note: this has to be cleaned first
-$rows	= calculate_children($rows);
+$rows = get_posts($_GET['thread']); // Note: This has to be cleaned first.
+$rows = calculate_children($rows);
 
 
 if ($_GET['post']) {
-	$display_post_id	= intval($_GET['post']); // note: this has to be cleaned first
+    $display_post_id = intval($_GET['post']); // note: this has to be cleaned first
 } else {
-	// we need to display the first post
-	reset($rows);
-	$current=current($rows);
-	$display_post_id=$current['post_id'];
+    // we need to display the first post
+    reset($rows);
+    $current = current($rows);
+    $display_post_id = $current['post_id'];
 }
 
-//are we in a lp ?
+// Are we in a lp ?
 $origin = '';
 if(isset($_GET['origin'])) {
     $origin =  Security::remove_XSS($_GET['origin']);
 }
 
-//delete attachment file
+// Delete attachment file.
 if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
-	delete_attachment(0,$_GET['id_attach']);
+    delete_attachment(0,$_GET['id_attach']);
 }
-// --------------------------------------
+
 // 		Displaying the thread (structure)
-// --------------------------------------
+
 $thread_structure="<div class=\"structure\">".get_lang('Structure')."</div>";
 $counter=0;
 $count=0;
@@ -58,45 +58,33 @@ $clean_forum_id  = intval($_GET['forum']);
 $clean_thread_id = intval($_GET['thread']);
 
 foreach ($rows as $post) {
-	$counter++;
-	$indent=$post['indent_cnt']*'20';
-	$thread_structure.= "<div style=\"margin-left: ".$indent."px;\">";
-
-	if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']]))
-	{
-		$post_image=icon('../img/forumpostnew.gif');
-	}
-	else
-	{
-		$post_image=icon('../img/forumpost.gif');
-	}
-	$thread_structure.= $post_image;
-	if ($_GET['post']==$post['post_id'] OR ($counter==1 AND !isset($_GET['post'])))
-	{
-		$thread_structure.='<strong>'.prepare4display($post['post_title']).'</strong></div>';
-		$prev_next_array[]=$post['post_id'];
-	}
-	else
-	{
-		if ($post['visible']=='0')
-		{
-			$class=' class="invisible"';
-		}
-		else
-		{
-			$class='';
-		}
-		$count_loop=($count==0)?'&id=1' : '';
-		$thread_structure.= "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;post=".$post['post_id']."&amp;origin=$origin$count_loop\" $class>".prepare4display($post['post_title'])."</a></div>";
-		$prev_next_array[]=$post['post_id'];
-	}
-	$count++;
+    $counter++;
+    $indent=$post['indent_cnt']*'20';
+    $thread_structure.= "<div style=\"margin-left: ".$indent."px;\">";
+
+    if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$post['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$post['thread_id']])) {
+        $post_image=icon('../img/forumpostnew.gif');
+    } else {
+        $post_image=icon('../img/forumpost.gif');
+    }
+    $thread_structure.= $post_image;
+    if ($_GET['post']==$post['post_id'] OR ($counter==1 AND !isset($_GET['post']))) {
+        $thread_structure.='<strong>'.prepare4display($post['post_title']).'</strong></div>';
+        $prev_next_array[]=$post['post_id'];
+    } else {
+        if ($post['visible']=='0') {
+            $class=' class="invisible"';
+        } else {
+            $class='';
+        }
+        $count_loop=($count==0)?'&id=1' : '';
+        $thread_structure.= "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;post=".$post['post_id']."&amp;origin=$origin$count_loop\" $class>".prepare4display($post['post_title'])."</a></div>";
+        $prev_next_array[]=$post['post_id'];
+    }
+    $count++;
 }
 
-/*--------------------------------------------------
-				 NAVIGATION CONTROLS
-----------------------------------------------------
-*/
+/* NAVIGATION CONTROLS */
 
 $current_id=array_search($display_post_id,$prev_next_array);
 $max=count($prev_next_array);
@@ -125,28 +113,25 @@ echo '<center>';
 //go to: first and previous
 if ((int)$current_id > 0)
 {
-	echo '<a href="'.$first_href.'" '.$class.' title='.$first_message.'>'.$first_img.' '.$first_message.'</a>';
-	echo '<a href="'.$prev_href.'" '.$class_prev.' title='.$prev_message.'>'.$prev_img.' '.$prev_message.'</a>';
+    echo '<a href="'.$first_href.'" '.$class.' title='.$first_message.'>'.$first_img.' '.$first_message.'</a>';
+    echo '<a href="'.$prev_href.'" '.$class_prev.' title='.$prev_message.'>'.$prev_img.' '.$prev_message.'</a>';
 }
 else
 {
-	echo '<b><span class="invisible">'.$first_img.' '.$first_message.'</b></span>';
-	echo '<b><span class="invisible">'.$prev_img.' '.$prev_message.'</b></span>';
+    echo '<b><span class="invisible">'.$first_img.' '.$first_message.'</b></span>';
+    echo '<b><span class="invisible">'.$prev_img.' '.$prev_message.'</b></span>';
 }
 
 //  current counter
 echo  ' [ '.($current_id+1).' / '.$max.' ] ';
 
 // go to: next and last
-if (($current_id+1) < $max)
-{
-	echo '<a href="'.$next_href.'" '.$class_next.' title='.$next_message.'>'.$next_message.' '.$next_img.'</a>';
-	echo '<a href="'.$last_href.'" '.$class.' title='.$last_message.'>'.$last_message.' '.$last_img.'</a>';
-}
-else
-{
-	echo '<b><span class="invisible">'.$next_message.' '.$next_img.'</b></span>';
-	echo '<b><span class="invisible">'.$last_message.' '.$last_img.'</b></span>';
+if (($current_id+1) < $max) {
+    echo '<a href="'.$next_href.'" '.$class_next.' title='.$next_message.'>'.$next_message.' '.$next_img.'</a>';
+    echo '<a href="'.$last_href.'" '.$class.' title='.$last_message.'>'.$last_message.' '.$last_img.'</a>';
+} else {
+    echo '<b><span class="invisible">'.$next_message.' '.$next_img.'</b></span>';
+    echo '<b><span class="invisible">'.$last_message.' '.$last_img.'</b></span>';
 }
 echo '</center>';
 
@@ -154,15 +139,13 @@ echo '</center>';
 
 // the style depends on the status of the message: approved or not
 if ($rows[$display_post_id]['visible']=='0') {
-	$titleclass='forum_message_post_title_2_be_approved';
-	$messageclass='forum_message_post_text_2_be_approved';
-	$leftclass='forum_message_left_2_be_approved';
-}
-else
-{
-	$titleclass='forum_message_post_title';
-	$messageclass='forum_message_post_text';
-	$leftclass='forum_message_left';
+    $titleclass='forum_message_post_title_2_be_approved';
+    $messageclass='forum_message_post_text_2_be_approved';
+    $leftclass='forum_message_left_2_be_approved';
+} else {
+    $titleclass='forum_message_post_title';
+    $messageclass='forum_message_post_text';
+    $leftclass='forum_message_left';
 }
 
 // 		Displaying the message
@@ -174,9 +157,9 @@ echo "<table width=\"100%\"  class=\"forum_table\"  cellspacing=\"5\" border=\"0
 echo "<tr>";
 echo "<td rowspan=\"3\" class=\"$leftclass\">";
 if ($rows[$display_post_id]['user_id']=='0') {
-	$name=prepare4display($rows[$display_post_id]['poster_name']);
+    $name=prepare4display($rows[$display_post_id]['poster_name']);
 } else {
-	$name=api_get_person_name($rows[$display_post_id]['firstname'], $rows[$display_post_id]['lastname']);
+    $name=api_get_person_name($rows[$display_post_id]['firstname'], $rows[$display_post_id]['lastname']);
 }
 
 if (api_get_course_setting('allow_user_image_forum')) {echo '<br />'.display_user_image($rows[$display_post_id]['user_id'],$name, $origin).'<br />';	}
@@ -188,84 +171,69 @@ $id_attach = !empty($attachment_list)?$attachment_list['id']:'';
 
 // The user who posted it can edit his thread only if the course admin allowed this in the properties of the forum
 // The course admin him/herself can do this off course always
-if (($current_forum['allow_edit']==1 AND $rows[$display_post_id]['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))
-{
-	echo "<a href=\"editpost.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;post=".$rows[$display_post_id]['post_id']."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
+if (($current_forum['allow_edit']==1 AND $rows[$display_post_id]['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))) {
+    echo "<a href=\"editpost.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;post=".$rows[$display_post_id]['post_id']."&id_attach=".$id_attach."\">".icon('../img/edit.gif',get_lang('Edit'))."</a>";
 }
-if (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session']))
-{
-	echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;id=".$rows[$display_post_id]['post_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
-	display_visible_invisible_icon('post', $rows[$display_post_id]['post_id'], $rows[$display_post_id]['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id, 'post'=>Security::remove_XSS($_GET['post']) ));
-	echo "";
-	//verified the post minor
-	$my_post=get_posts($_GET['thread']);
-	$id_posts=array();
-
-	foreach ($my_post as $post_value) {
-		$id_posts[]=$post_value['post_id'];
-	}
-
-	sort($id_posts,SORT_NUMERIC);
-	reset($id_posts);
-	//the post minor
-	$post_minor=(int)$id_posts[0];
-	$post_id = isset($_GET['post'])?(int)$_GET['post']:0;
-	if (!isset($_GET['id']) && $post_id>$post_minor) {
-		echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;action=move&amp;post=".$rows[$display_post_id]['post_id']."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>";
-	}
+if (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])) {
+    echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=delete&amp;content=post&amp;id=".$rows[$display_post_id]['post_id']."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("DeletePost"),ENT_QUOTES,$charset))."')) return false;\">".icon('../img/delete.gif',get_lang('Delete'))."</a>";
+    display_visible_invisible_icon('post', $rows[$display_post_id]['post_id'], $rows[$display_post_id]['visible'],array('forum'=>$clean_forum_id,'thread'=>$clean_thread_id, 'post'=>Security::remove_XSS($_GET['post']) ));
+    echo "";
+    //verified the post minor
+    $my_post=get_posts($_GET['thread']);
+    $id_posts=array();
+
+    foreach ($my_post as $post_value) {
+        $id_posts[]=$post_value['post_id'];
+    }
+
+    sort($id_posts,SORT_NUMERIC);
+    reset($id_posts);
+    //the post minor
+    $post_minor=(int)$id_posts[0];
+    $post_id = isset($_GET['post'])?(int)$_GET['post']:0;
+    if (!isset($_GET['id']) && $post_id>$post_minor) {
+        echo "<a href=\"viewthread.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;origin=".$origin."&amp;action=move&amp;post=".$rows[$display_post_id]['post_id']."\">".icon('../img/deplacer_fichier.gif',get_lang('MovePost'))."</a>";
+    }
 }
 $userinf=api_get_user_info($rows[$display_post_id]['user_id']);
 $user_status=api_get_status_of_user_in_course($rows[$display_post_id]['user_id'],api_get_course_id());
 if (api_is_allowed_to_edit(null,true)) {
-	if($post_id>$post_minor )
-	{
-		if($user_status!=1)
-		{
-			$current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$rows[$display_post_id]['user_id'],$_GET['thread']);
-			echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$rows[$display_post_id]['post_id']."&amp;user=".$rows[$display_post_id]['user_id']."&user_id=".$rows[$display_post_id]['user_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
-		}
-	}
+    if($post_id>$post_minor ) {
+        if($user_status!=1) {
+            $current_qualify_thread=show_qualify('1',$_GET['cidReq'],$_GET['forum'],$rows[$display_post_id]['user_id'],$_GET['thread']);
+            echo "<a href=\"forumqualify.php?".api_get_cidreq()."&amp;gidReq=".Security::remove_XSS($_GET['gidReq'])."&forum=".$clean_forum_id."&amp;thread=".$clean_thread_id."&amp;action=list&amp;post=".$rows[$display_post_id]['post_id']."&amp;user=".$rows[$display_post_id]['user_id']."&user_id=".$rows[$display_post_id]['user_id']."&origin=".$origin."&idtextqualify=".$current_qualify_thread."\" >".icon('../img/new_test_small.gif',get_lang('Qualify'))."</a>";
+        }
+    }
 }
 //echo '<br /><br />';
 //if (($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0) OR api_is_allowed_to_edit())
-if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true))
-{
-	if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id']))
-	{
-		if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
-			echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=replymessage&amp;origin='. $origin .'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
-			echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=quote&amp;origin='. $origin .'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
-		}
-	}
-}
-else
-{
-	if ($current_forum_category['locked']==1)
-{
-		echo get_lang('ForumcategoryLocked').'<br />';
-	}
-	if ($current_forum['locked']==1)
-	{
-		echo get_lang('ForumLocked').'<br />';
-}
-	if ($current_thread['locked']==1)
-	{
-		echo get_lang('ThreadLocked').'<br />';
-}
+if ($current_forum_category['locked']==0 AND $current_forum['locked']==0 AND $current_thread['locked']==0 OR api_is_allowed_to_edit(false,true)) {
+    if ($_user['user_id'] OR ($current_forum['allow_anonymous']==1 AND !$_user['user_id'])) {
+        if (!api_is_anonymous() && api_is_allowed_to_session_edit(false,true)) {
+            echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=replymessage&amp;origin='. $origin .'">'.Display :: return_icon('message_reply_forum.png', get_lang('ReplyToMessage'))."</a>";
+            echo '<a href="reply.php?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'&amp;post='.$rows[$display_post_id]['post_id'].'&amp;action=quote&amp;origin='. $origin .'">'.Display :: return_icon('quote.gif', get_lang('QuoteMessage'))."</a>";
+        }
+    }
+} else {
+    if ($current_forum_category['locked']==1) {
+        echo get_lang('ForumcategoryLocked').'<br />';
+    }
+    if ($current_forum['locked']==1) {
+        echo get_lang('ForumLocked').'<br />';
+    }
+    if ($current_thread['locked']==1) {
+        echo get_lang('ThreadLocked').'<br />';
+    }
 }
 echo "</td>";
 // note: this can be removed here because it will be displayed in the tree
-if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$rows[$display_post_id]['thread_id']]))
-{
-	$post_image=icon('../img/forumpostnew.gif');
+if (isset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) and !empty($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$rows[$display_post_id]['post_id']]) and !empty($whatsnew_post_info[$_GET['forum']][$rows[$display_post_id]['thread_id']])) {
+    $post_image=icon('../img/forumpostnew.gif');
+} else {
+    $post_image=icon('../img/forumpost.gif');
 }
-else
-{
-	$post_image=icon('../img/forumpost.gif');
-}
-if ($rows[$display_post_id]['post_notification']=='1' AND $rows[$display_post_id]['poster_id']==$_user['user_id'])
-{
-	$post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
+if ($rows[$display_post_id]['post_notification']=='1' AND $rows[$display_post_id]['poster_id']==$_user['user_id']) {
+    $post_image.=icon('../img/forumnotification.gif',get_lang('YouWillBeNotified'));
 }
 // The post title
 echo "<td class=\"$titleclass\">".prepare4display($rows[$display_post_id]['post_title'])."</td>";
@@ -280,23 +248,21 @@ echo "</tr>";
 $attachment_list = get_attachment($display_post_id);
 
 if (!empty($attachment_list)) {
-	echo '<tr><td height="50%">';
-	$realname=$attachment_list['path'];
-	$user_filename=$attachment_list['filename'];
-
-	echo Display::return_icon('attachment.gif',get_lang('Attachment'));
-	echo '<a href="download.php?file=';
-	echo $realname;
-	echo ' "> '.$user_filename.' </a>';
-	echo '<span class="forum_attach_comment" >'.Security::remove_XSS($attachment_list['comment'], STUDENT).'</span>';
-	if (($current_forum['allow_edit']==1 AND $rows[$display_post_id]['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))	{
-		echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
-	}
-	echo '</td></tr>';
+    echo '<tr><td height="50%">';
+    $realname=$attachment_list['path'];
+    $user_filename=$attachment_list['filename'];
+
+    echo Display::return_icon('attachment.gif',get_lang('Attachment'));
+    echo '<a href="download.php?file=';
+    echo $realname;
+    echo ' "> '.$user_filename.' </a>';
+    echo '<span class="forum_attach_comment" >'.Security::remove_XSS($attachment_list['comment'], STUDENT).'</span>';
+    if (($current_forum['allow_edit']==1 AND $rows[$display_post_id]['user_id']==$_user['user_id']) or (api_is_allowed_to_edit(false,true)  && !(api_is_course_coach() && $current_forum['session_id']!=$_SESSION['id_session'])))	{
+        echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;gidReq='.Security::remove_XSS($_GET['gidReq']).'&amp;origin='.Security::remove_XSS($_GET['origin']).'&amp;action=delete_attach&amp;id_attach='.$attachment_list['id'].'&amp;forum='.$clean_forum_id.'&amp;thread='.$clean_thread_id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
+    }
+    echo '</td></tr>';
 }
 
-
-
 // The post has been displayed => it can be removed from the what's new array
 unset($whatsnew_post_info[$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);
 unset($_SESSION['whatsnew_post_info'][$current_forum['forum_id']][$current_thread['thread_id']][$row['post_id']]);

Some files were not shown because too many files changed in this diff