1<?php
2include('../Code/confHeader.inc');
3$_SESSION[Me] -> goIfInvalid($Conf->paperSite);
4$_SESSION[Me] -> goIfNotPC($Conf->paperSite);
5$Conf -> connect();
6
7include('../Code/confConfigReview.inc');
8include('gradeNames.inc');
9
10function showReviewerOkay ( $Conf )
11{
12 return ($_SESSION[Me]->isChair ) ||
13     ($_SESSION[Me]->isPC );
14// return ($_SESSION[Me]->isChair && $_SESSION[SeeReviewerInfo]==1) ||
15//     ($_SESSION[Me]->isPC && $Conf->validTimeFor('PCGradePapers', 0));
16}
17
18?>
19
20<html>
21
22<?php  $Conf->header("See all the reviews for Paper #" . $_REQUEST[paperId]) ?>
23
24<body>
25<?php
26//
27// No one ever gets to see a paper review for which they
28// have a conflict using this interface.
29//
30if ( $_SESSION[Me]->checkConflict($_REQUEST[paperId], $Conf)) {
31
32  $Conf -> errorMsg("The program chairs have registered a conflict "
33		    . " of interest for you to read this paper."
34		    . " If you think this is incorrect, contact the "
35		    . " program chair " );
36  exit();
37}
38
39//
40// Check if this person is supposed to be able to review this paper
41//
42
43if ( ! $Conf->validTimeFor('AtTheMeeting', 0) ) {
44  if ( !($_SESSION[Me] -> iCanReview($_REQUEST[paperId], $Conf) || $_SESSION[Me] -> isChair)) {
45    $Conf -> errorMsg("You are unable to view all the reviews for this paper "
46		      . " since you were not a primary or secondary reviwer for it." );
47    exit();
48  }
49}
50
51if ( 0 && $Conf->validTimeFor('AtTheMeeting',0) ) {
52  $pcConflicts = $Conf->allPCConflicts();
53
54  if ($pcConflicts[$_REQUEST[paperId]] && ! $_SESSION[Me] -> isChair ) {
55    $Conf -> errorMsg("You are unable to view all the reviews for this paper "
56		      . "at the program committee meeting" );
57    exit();
58
59  }
60}
61
62//
63// Check if they're a primary reviewer (they need to review it), but
64// they haven't yet finalized their reviews.
65//
66
67$query="SELECT paperId FROM PrimaryReviewer WHERE "
68. " reviewer='" . $_SESSION[Me]->contactId . "' AND paperId=" . $_REQUEST[paperId] . " ";
69;
70
71$result = $Conf->q($query);
72
73if (!DB::isError($result) && $result->numRows() > 0) {
74  //
75  // Ok, I'm a primary reviewer for it
76  //
77  $row = $result->fetchRow(DB_FETCHMODE_ASSOC);
78
79    //
80    // OK, check if they've done the review
81    //
82    $query="SELECT finalized FROM PaperReview WHERE "
83      . " PaperReview.reviewer=" . $_SESSION[Me]->contactId. " "
84      . " AND PaperReview.paperId=" . $_REQUEST[paperId] . " ";
85    ;
86    $result = $Conf->q($query);
87    $finalized = 0;
88
89    if ( $result ) {
90      while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
91	$finalized=$row['finalized'];
92      }
93    }
94
95    if ( ! $finalized ) {
96      $Conf->errorMsg("You can not view all the reviews for this paper "
97		      . "since you have not yet finalized your own review. ");
98      print "<center>";
99      print "<a href=\"CheckAssignedPapers.php\"> Click here to continue to check reviews </a>";
100      print "</center>";
101      exit();
102    } else {
103#      $Conf->infoMsg("You're cool");
104    }
105}
106
107
108//
109// Fix logic to allow PC members to see reviewers at PC meeting
110//
111$doTable = 0;
112if ($Conf->okSeeReviewers()
113    || $Conf->okSeeUnfinishedReviews()
114    || $Conf->okSeeAuthorInfo() )
115{
116  $doTable = 1;
117}
118
119if ( $doTable ) {
120
121  if (IsSet($UpdateView)) {
122    //
123    // Update viewing preferences if they pressed UpdateView
124    //
125    $_SESSION[SeeReviewerInfo]=$_REQUEST[SeeReviewerInfo];
126    $_SESSION[SeeUnfinishedReviews]=$_REQUEST[SeeUnfinishedReviews];
127    $_SESSION[SeeAuthorInfo]=$_REQUEST[SeeAuthorInfo];
128  }
129
130  print "<FORM METHOD=POST ACTION=\"$_SERVER[PHP_SELF]\">";
131  print "<table align=center>";
132  print "<tr><td>";
133
134  if ($Conf->okSeeReviewers()) {
135    print "<INPUT type=checkbox name=SeeReviewerInfo value=1";
136    if ($_REQUEST[SeeReviewerInfo]) {
137      echo " checked";
138    }
139    print "> See Reviewer Info<br>";
140  }
141
142  if ($Conf->okSeeUnfinishedReviews()) {
143      print "<INPUT type=checkbox name=SeeUnfinishedReviews value=1";
144      if ($_REQUEST[SeeUnfinishedReviews]) {
145	echo " checked";
146      }
147      print "> See Unfinished Reviews<br>";
148  }
149
150  if ($Conf->okSeeAuthorInfo()) {
151    print "<INPUT type=checkbox name=SeeAuthorInfo value=1";
152    if ($_REQUEST[SeeAuthorInfo]) {
153      echo " checked";
154    }
155    print "> See Author Info<br>";
156  }
157
158  print $Conf->mkHiddenVar('paperId', $_REQUEST[paperId]);
159  print "<INPUT TYPE=SUBMIT name=UpdateView value=\"Update View\">";
160  print "</FORM>";
161
162  print "</td>";
163
164  print "<td>\n";
165  print $Conf->buttonWithPaperId("Modify Paper",
166			       "../Chair/ModifyPaper.php",
167			       $_REQUEST[paperId]);
168  print "</td><td>\n";
169  print $Conf->buttonWithPaperId("Delete Paper\n (requires confirmation) ",
170			       "../Chair/DeletePaper2.php",
171			       $_REQUEST[paperId]);
172  print "</td>\n";
173
174  print "</tr>";
175  print "</table>";
176}
177
178if ( showReviewerOkay($Conf) ){
179?>
180<table border=1 align=center>
181<tr bgcolor=<?php echo $Conf->contrastColorOne?>>
182<td>
183   Primary Reviewers:
184</td>
185<td>
186<?php
187   $query="SELECT firstName, lastName, email "
188   . " FROM ContactInfo, PrimaryReviewer "
189   . " WHERE PrimaryReviewer.reviewer=ContactInfo.contactId "
190   . " AND PrimaryReviewer.paperId='" . $_REQUEST[paperId] . "'";
191    $result = $Conf->qe($query);
192    if (!DB::isError($result)) {
193      $sep = "";
194      while($row=$result->fetchRow()) {
195	print "<a href=\"mailto:$row[2]?Subject=Concerning%20Paper%20" . $_REQUEST[paperId] . "\">";
196	print "$sep$row[0] $row[1] ($row[2]) ";
197	print "</a>";
198	$sep ="<br>";
199      }
200    }
201?>
202</td>
203</tr>
204<tr bgcolor=<?php echo $Conf->contrastColorTwo?>>
205<td>
206   Secondary Reviewers:
207</td>
208<td>
209<?php
210   $query="SELECT firstName, lastName, email "
211   . " FROM ContactInfo, SecondaryReviewer "
212   . " WHERE SecondaryReviewer.reviewer=ContactInfo.contactId "
213   . " AND SecondaryReviewer.paperId='" . $_REQUEST[paperId] . "'";
214    $result = $Conf->qe($query);
215    if (!DB::isError($result)) {
216      $sep = "";
217      while($row=$result->fetchRow()) {
218	print "<a href=\"mailto:$row[2]?Subject=Concerning%20Paper%20" . $_REQUEST[paperId] . "\">";
219	print "$sep$row[0] $row[1] ($row[2]) ";
220	print "</a>";
221	$sep ="<br>";
222      }
223    }
224?>
225</td>
226</tr>
227<tr bgcolor=<?php echo $Conf->contrastColorOne?>>
228<td>
229   Reviews requested from:
230</td>
231<td>
232<?php
233   $query="SELECT firstName, lastName, email "
234   . " FROM ContactInfo, ReviewRequest "
235   . " WHERE ReviewRequest.asked=ContactInfo.contactId "
236   . " AND ReviewRequest.paperId='" . $_REQUEST[paperId] . "'";
237    $result = $Conf->qe($query);
238    if (!DB::isError($result)) {
239      $sep = "";
240      while($row=$result->fetchRow()) {
241	print "<a href=\"mailto:$row[2]?Subject=Concerning%20Paper%20" . $_REQUEST[paperId] . "\">";
242	print "$sep$row[0] $row[1] ($row[2]) ";
243	print "</a>";
244	$sep ="<br>";
245      }
246    }
247    print "</td>";
248    print "</tr>";
249    print "</table>";
250    print "<br><br>";
251}
252
253//
254// Store or delete any comments that were made (after security checks above)
255//
256if (IsSet($_REQUEST['storeComment']) && IsSet($_REQUEST[paperId]) && IsSet($_REQUEST['theComment'])) {
257  if (IsSet($_REQUEST['forEveryone']) ){
258    $_REQUEST['forReviewer'] = 1;
259    $_REQUEST['forAuthor'] = 1;
260  }
261  if( IsSet($_REQUEST['forReviewer']) ) {
262    $forReviewer=1;
263  } else {
264    $forReviewer=0;
265  }
266
267  if (IsSet($_REQUEST['forAuthor'])) {
268    $forAuthor=1;
269  } else {
270    $forAuthor=0;
271  }
272
273  $query="INSERT INTO PaperComments "
274    . " SET paperId=" . $_REQUEST[paperId] . ", contactId=" . $_SESSION[Me]->contactId. ", "
275    . " forAuthor=$forAuthor, forReviewers=$forReviewer, "
276    . " comment='" . addslashes($_REQUEST['theComment']) . "'";
277
278  $Conf->qe($query);
279}
280
281if (IsSet($_REQUEST['killCommentId'])) {
282  $query="DELETE FROM PaperComments WHERE commentId='" . addSlashes($_REQUEST['killCommentId']) . "';";
283  $Conf->qe($query);
284}
285
286//
287// Print header using dummy review
288//
289
290$Review=ReviewFactory($Conf, $_SESSION[Me]->contactId, $_REQUEST[paperId]);
291
292if ( ! $Review -> valid ) {
293  $Conf->errorMsg("You've stumbled on to an invalid review? -- contact chair");
294  exit;
295}
296if ($Review->paperFields['outcome'] != "undecided") {
297  $Conf->infoMsg("<center> Paper Outcome Is : "
298		 . $Review->paperFields['outcome']
299		 . "</center>"
300		 );
301}
302
303print "<center>";
304if ( ($_SESSION[Me]->isChair && $_SESSION[SeeAuthorInfo]) || (!$_SESSION[Me]->isChair && $Conf->validTimeFor('AtTheMeeting', 0)) ) {
305  $Review->printVisibleReviewHeader($Conf);
306} else {
307  $Review->printAnonReviewHeader($Conf,1);
308}
309print "</center>";
310
311
312$Conf->log("View all reviews (blind) for $_REQUEST[paperId]", $_SESSION[Me]);
313
314//
315  // Now print all the reviews
316  //
317$fin= " AND PaperReview.finalized=1 ";
318if ($_SESSION[Me]->isChair && $_SESSION[SeeUnfinishedReviews]) {
319  $fin = "";
320}
321
322$result = $Conf->qe("SELECT PaperReview.reviewer, "
323		    . " PaperReview.paperReviewId, "
324		    . " ContactInfo.firstName, ContactInfo.lastName, "
325		    . " ContactInfo.email "
326		    . " FROM PaperReview, ContactInfo "
327		    . " WHERE PaperReview.paperId='$_REQUEST[paperId]'"
328		    . " AND PaperReview.reviewer=ContactInfo.contactId"
329		    . $fin
330		    );
331
332if (!DB::isError($result) && $result->numRows() > 0) {
333  $header = 0;
334  $reviewerId = array();
335
336  $i = 1;
337  while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
338    $reviewer=$row['reviewer'];
339    $reviewId=$row['paperReviewId'];
340    $first=$row['firstName'];
341    $last=$row['lastName'];
342    $email=$row['email'];
343
344    $Review=ReviewFactory($Conf, $reviewer, $_REQUEST[paperId]);
345
346    $lastModified=$Conf->printTime($Review->reviewFields['timestamp']);
347
348    print "<table width=100%>";
349    if ($i & 0x1 ) {
350      $color = $Conf->contrastColorOne;
351    } else {
352      $color = $Conf->contrastColorTwo;
353    }
354
355    print "<tr bgcolor=$color>";
356    if ( $_SESSION[Me]->isChair ) {
357
358      if ( $Review->reviewFields['finalized'] ) {
359	$word = "unfinalize";
360      } else {
361	$word = "finalize";
362      }
363
364      $extra = "<a href=\"../Chair/UnfinalizeReview.php?paperId=$_REQUEST[paperId]\" target=_blank> "
365	. " Click here to $word review </a>";
366
367      print "<th> <big> <big> Review #$reviewId For Paper #$_REQUEST[paperId] </big></big> $extra  </th>";
368
369    } else {
370      print "<th> <big> <big> Review #$reviewId For Paper #$_REQUEST[paperId] </big></big> </th>";
371    }
372
373    print "</tr>";
374
375    if ( showReviewerOkay($Conf) ){
376      print "<tr bgcolor=$color>";
377      print "<th> <big <big> By $first $last ($email) </big> </big> </th>";
378      print "</tr>";
379    }
380
381    print "<tr bgcolor=$color>";
382    print "<th> (review last modified $lastModified) </th> </tr>\n";
383
384    $paperId = addSlashes( $_REQUEST['paperId'] );
385
386    $gradeRes = $Conf -> qe("SELECT grade"
387			  . " FROM PaperGrade "
388			  . " WHERE paperId='$paperId' "
389			  . "       AND contactId=$reviewer ");
390
391    if (! $gradeRes ) {
392      $Conf->errorMsg("Error in SQL " . $result->getMessage());
393    }
394
395    if ($gradeRow = $gradeRes->fetchRow(DB_FETCHMODE_ASSOC)) {
396      $grade = "<EM>" . $gradeName[$gradeRow['grade']] . "</EM>";
397    } else {
398      $grade = "not entered yet";
399    }
400
401    print "<tr bgcolor=$color>";
402    print "<th> Grade is $grade </th> </tr>\n";
403
404    print "<tr bgcolor=$color> <td> ";
405
406    if ($Review->valid) {
407      $Review -> printViewable();
408    }
409
410    print "</td> </tr>";
411
412    print "<tr> <td> <br> <br> <br> </td> </tr>";
413    print "</table>";
414    $i++;
415  }
416}
417//
418// Now, print out the comments
419//
420
421$result = $Conf -> qe("SELECT PaperComments.*, UNIX_TIMESTAMP(time) as unixtime , ContactInfo.firstName, ContactInfo.lastName, ContactInfo.email "
422		      . " FROM PaperComments, ContactInfo "
423		      . " WHERE paperId=$_REQUEST[paperId] AND PaperComments.contactId = ContactInfo.contactId "
424		      . " ORDER BY time ");
425if (! $result ) {
426  $Conf->errorMsg("Error in SQL " . $result->getMessage());
427}
428
429if ($result->numRows() == 0 ) {
430  //
431  // No comment if there are none...
432  //
433  $Conf->infoMsg("There are no comments");
434} else {
435  while ($row=$result->fetchRow(DB_FETCHMODE_ASSOC)) {
436    print "<table width=75% align=center>\n";
437
438    $when = date ("l dS of F Y h:i:s A",
439		  $row['unixtime']);
440
441    print "<tr bgcolor=$Conf->infoColor>";
442    print "<th align=left> $when </th>";
443    print "<th align=right> For PC";
444    if ($row['forReviewers']) {
445      print ", Reviewers";
446    }
447    if ($row['forAuthor']) {
448      print " and Author.";
449    }
450    print ". </th>";
451    if (showReviewerOkay($Conf)) {
452      print "<th>" . htmlEntities($row['firstName']) . " " .
453            htmlEntities($row['lastName']) . " (" .
454	    htmlEntities($row['email']) . ")</th>";
455    }
456    //if ( $row['contactId'] == $_SESSION[Me]->contactId ) {
457    if ( $_SESSION[Me]->isChair ) {
458      print "<th>";
459      $id=$row['commentId'];
460      $Conf->textButton("Delete?",
461			"$_SERVER[PHP_SELF]?paperId=$_REQUEST[paperId]>",
462			"<input type=hidden NAME=killCommentId value=$id>");
463      print "</th>";
464    }
465    print "</tr>";
466    print "<tr bgcolor=$Conf->contrastColorOne>\n";
467    print "<td colspan=3>";
468    print nl2br($row['comment']);
469    print "</td>";
470    print "</tr>";
471    print "</table>";
472    print "<br> <br>";
473  }
474}
475
476print "<br> <br>\n";
477print "<hr>\n";
478//$Conf->infoMsg("You can enter new comments below. Although your "
479//		  . " identity is stored, it is not displayed unless "
480//		  . " you choose to identify yourself. ");
481?>
482
483<FORM METHOD=POST ACTION=<?php echo $_SERVER[PHP_SELF]?>>
484<INPUT TYPE=hidden name=paperId value="<?php  echo $_REQUEST[paperId]?>">
485<INPUT TYPE=submit name=storeComment value="Store Comment">
486<table width=80% align=center bgcolor=<?php echo $Conf->contrastColorTwo?>>
487<tr> <th colspan=2 bgcolor=<?php echo $Conf->infoColor?>> Add a new comment </th> </tr>
488<tr> <th colspan=2>
489 All comments will be viewable by the Program Committee.</th> </tr>
490<tr> <th>
491Do you want to also make the comment viewable by the Authors?
492</th> <td> <INPUT TYPE=CHECKBOX NAME=forEveryone> </td> </tr>
493<!--
494<tr> <th> The Reviewers? </th> <td> <INPUT TYPE=CHECKBOX NAME=forReviewer> </td> </tr>
495<tr> <th> The Authors? </th> <td> <INPUT TYPE=CHECKBOX NAME=forAuthor> </td> </tr>
496-->
497
498<tr> <th> Your Comment.<br> HTML OK. </th>
499<td><TEXTAREA NAME=theComment rows=10 cols=50 wrap=virtual></TEXTAREA> </td>
500</tr>
501</table>
502<INPUT TYPE=submit name=storeComment value="Store Comment">
503</FORM>
504
505<?php  $Conf->footer() ?>
506</body>
507</html>
508
509