<?php
/*
==============================================================================
	Dokeos - elearning and course management software

	Copyright (c) Dokeos S.A.
	Copyright (c) Ghent University (UGent)
	Copyright (c) Universite catholique de Louvain (UCL)
	Copyright (c) Patrick Cool

	For a full list of contributors, see "credits.txt".
	The full license can be read in "license.txt".

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	See the GNU General Public License for more details.

	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/



// setting the global file that gets the general configuration, the databases, the languages, ...
include('../inc/claro_init_global.inc.php');

$url= "peerreviews.php?id=".$_GET['id'];
$interbredcrump[] = array ("url" => "work.php", "name" =>"Student publications");
$interbredcrump[] = array ("url" => $url, "name" =>"Peer Reviews");

Display::display_header($nameTools,'Agenda');

// notice for unauthorized people. 
api_protect_course_script();

$nameTools = "Peer Review"; // language variable in trad4all.inc.php

api_display_tool_title($nameTools);



// database variable
$work_table = Database::get_course_table(STUDENT_PUBLICATION_TABLE);
$user_table       = Database::get_main_table(MAIN_USER_TABLE);
// displaying the information of the document we are reviewing
$sql="SELECT * FROM $work_table WHERE id='".(int)$_GET['id']."' AND accepted='1'";
$result=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($result);
?>

<table>
	<tr>
		<td bgcolor="#EFEFEF">Title: </td>
		<td><?php echo $row['title'];?></td>
	</tr>
	<tr>
		<td bgcolor="#EFEFEF">Description: </td>
		<td><?php echo $row['description'];?></td>
	</tr>
	<tr>
		<td bgcolor="#EFEFEF">Authors: </td>
		<td><?php echo $row['author'];?></td>
	</tr>
	<tr>
		<td bgcolor="#EFEFEF">Date: </td>
		<td><?php echo $row['sent_date'];?></td>
	</tr>
</table>
<hr noshade size="1">
<?php 
$tbl_peer_reviews 	= $_course['dbNameGlu']."peer_reviews";
if (mysql_query("SELECT * FROM `$tbl_peer_reviews`")==false)
{
	//echo "we maken de tabel aan";
	$sql="CREATE TABLE `$tbl_peer_reviews` (
	  `id` int(11) NOT NULL auto_increment,
	  `publication_id` int(11) NOT NULL default '0',
	  `user_id` int(11) NOT NULL default '0',
	  `comment` text NOT NULL,
	  `score` varchar(255) NOT NULL default '',
	  PRIMARY KEY  (`id`)
	) ENGINE=MyISAM;";
	$result=mysql_query($sql) or die(mysql_error());
}

if ($_POST['Submit'])
{
	$sql="INSERT INTO `$tbl_peer_reviews` (publication_id, user_id, comment, score) VALUES ('".$_GET['id']."','".$_uid."','".$_POST['comment']."','".$_POST['rating']."')";
	$result=mysql_query($sql) or die(mysql_error());
	Display::display_normal_message("Your review has been stored");
}
?>
<form name="form1" method="post" action="">
  <table border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td valign="top" bgcolor="#EFEFEF">Your rating</td>
      <td width="335"><input name="rating" type="text" id="rating"></td>
    </tr>
    <tr>
      <td valign="top" bgcolor="#EFEFEF">Your comment</td>
      <td><textarea name="comment" cols="50" rows="5" id="comment"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
<hr noshade size="1">
<?php
$sql="SELECT * FROM `$tbl_peer_reviews` peerreviews, $user_table user  WHERE peerreviews.publication_id='".$_GET['id']."' AND peerreviews.user_id=user.user_id";
$result=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($result))
{
echo "<p><table>\n";
echo "\t<tr><td bgcolor=\"#EFEFEF\">rating: </td><td>".$row['score']."</td></tr>\n";
echo "\t<tr><td bgcolor=\"#EFEFEF\">comment: </td><td>".$row['comment']."</td></tr>\n";
echo "\t<tr><td bgcolor=\"#EFEFEF\">auteur: </td><td>".$row['lastname']." ".$row['firstname']."</td></tr>\n";
echo "</table>\n";

}
?>