1<?php
2include('../Code/confHeader.inc');
3$_SESSION[Me] -> goIfInvalid("../index.php");
4$_SESSION[Me] -> goIfNotPC('../index.php');
5$Conf -> connect();
6
7$isChair = $_SESSION['Me']->isChair;
8$meetingTime = $Conf->validTimeFor('AtTheMeeting', 0);
9
10$outcomeName = array(
11  "unspecified" => "Unspecified",
12  "accepted" => "Accept",
13  "rejected" => "Reject",
14  "acceptedShort" => "Short Paper"
15);
16
17$pcmodes = array(
18  "PCAll" => "Show All Papers",
19  "PCX" => "X Out PC Member Papers",
20  "PCHide" => "Hide PC Member Papers",
21  "PCOnly" => "Only Show PC Member Papers"
22);
23
24$pcmode = "";
25
26if( IsSet($_REQUEST['pcmode']) ){
27  $pcmode = $_REQUEST['pcmode'];
28}
29
30if( !IsSet($pcmodes[$pcmode]) ){
31  $pcmode = "PCAll";
32}
33
34$stats = array( "AVG" => "Average", "STDDEV" => "Standard Deviation" );
35
36$stat = "";
37
38if( IsSet($_REQUEST['stat']) ){
39  $stat = $_REQUEST['stat'];
40}
41
42if( !IsSet($stats[$stat]) ){
43  $stat = "AVG";
44}
45
46
47$graphs = array(
48  "grade" => "PC Grade",
49  "overAllMerit" => "Overall Merit",
50  "reviewerQualification" => "Reviewer Qualification",
51  "novelty" => "Novelty",
52  "technicalMerit" => "Technical Merit",
53  "grammar" => "Writing Quality"
54  );
55
56$target = "";
57
58if( IsSet($_REQUEST['target']) ){
59  $target = $_REQUEST['target'];
60}
61
62if( !IsSet($graphs[$target]) ){
63  $target = "grade";
64}
65
66if( 0 ){
67$group_order = array( "groupABC", "groupA-E", "groupRest", "groupCDE" );
68
69$groups = array(
70  "groupABC" => "Only A, B or C",
71  "groupA-E" => "At Least One A, No Es (has a D)",
72  "groupRest" => "At Least One B (has a D or an E)",
73  "groupCDE" => "Only C, D or E",
74  );
75} else {
76$group_order = array( "groupW", "groupX", "groupY", "groupZ");
77
78$groups = array(
79  "groupW" => "Group W",
80  "groupX" => "Group X",
81  "groupY" => "Group Y",
82  "groupZ" => "Group Z",
83  );
84}
85
86$kept_groups = array();
87
88if( IsSet($_REQUEST['groups']) ){
89  foreach( $_REQUEST['groups'] as $key => $val ){
90    if( IsSet($groups[$val]) ){
91      $kept_groups[$val] = 1;
92    }
93  }
94}
95
96if( IsSet($_REQUEST['use_groups']) ){
97  $use_groups = 1;
98} else {
99  $use_groups = 0;
100}
101
102if( (! $_SESSION['Me']->isChair) && ($Conf->validTimeFor('AtTheMeeting', 0)) ) {
103  $use_groups = 1;
104  foreach( $groups as $key => $val ){
105    $kept_groups[$key] = 1;
106  }
107}
108
109?>
110
111<html>
112
113<?php  $Conf->header("Distribution of " . $graphs[$target] . " Scores for Papers") ?>
114
115<body>
116<H1>Choose Sorting Order and View Options</H1>
117<FORM METHOD="POST" ACTION="<?php echo $_SERVER['PHP_SELF'] ?>" TARGET=_blank>
118<H2>Information to show</H2>
119<P>
120<?php
121$redCol = 0;
122$judgeCol = 0;
123$judgeData = "";
124$authorData = "";
125$authorSpace = "";
126$authorTable = "";
127$authorQual = "";
128
129if( $_SESSION['Me']->isChair ){
130  print "<INPUT TYPE='CHECKBOX' NAME='AuthorRow'";
131  if( IsSet($_REQUEST['AuthorRow']) ){
132    $authorRow = 1;
133    $authorSpace = " ROWSPAN=2 ";
134    $authorData = " , Paper.authorInformation, ContactInfo.email, ContactInfo.firstName, ContactInfo.lastName, ContactInfo.affiliation ";
135    $authorTable = " , ContactInfo ";
136    $authorQual = " AND ContactInfo.contactId = Paper.contactId ";
137    print " CHECKED";
138  }
139  print "> Author Info Row<BR>\n";
140  print "<INPUT TYPE='CHECKBOX' NAME='RedCol'";
141  if( IsSet($_REQUEST['RedCol']) ){
142    $redCol = 1;
143    print " CHECKED";
144  }
145  print "> Highlighted PC Paper Column<BR>\n";
146  print "<INPUT TYPE='CHECKBOX' NAME='GradeCol'";
147  if( IsSet($_REQUEST['GradeCol']) ){
148    $judgeCol = 1;
149    $judgeData = ", Paper.outcome ";
150    print " CHECKED";
151  }
152  print "> Judgement Column<BR>\n";
153}
154
155if( IsSet($_REQUEST['COLS']) ){
156  $kept_graphs = array();
157  foreach( $_REQUEST['COLS'] as $ind => $val ){
158    if( IsSet($graphs[$val]) ){
159      $kept_graphs[$val] = $graphs[$val];
160    }
161  }
162} else {
163  $kept_graphs = $graphs;
164}
165
166foreach($graphs as $val => $name){
167  print "<INPUT TYPE='CHECKBOX' NAME='COLS[]' VALUE='$val'";
168  if( IsSet($kept_graphs[$val]) ){
169    print " CHECKED";
170  }
171  print "> $name Column<BR>\n";
172}
173
174print "</P>\n";
175
176if( ($_SESSION['Me']->isChair) || (! $Conf->validTimeFor('AtTheMeeting', 0)) ) {
177?>
178<H2>Sort Order and Row Selection</H2>
179<SELECT NAME="target">
180<?php
181foreach($graphs as $val => $name){
182  print "<OPTION VALUE=\"$val\"";
183  if( $val == $target ){
184    print " SELECTED";
185  }
186  print ">$name</OPTION>\n";
187}
188?>
189</SELECT>
190<SELECT NAME="stat">
191<?php
192foreach($stats as $val => $name){
193  print "<OPTION VALUE=\"$val\"";
194  if( $val == $stat ){
195    print " SELECTED";
196  }
197  print ">$name</OPTION>\n";
198}
199
200?>
201</SELECT>
202<?php
203}
204
205if( $_SESSION['Me']->isChair ){
206  print '<SELECT NAME="pcmode">';
207
208  foreach($pcmodes as $val => $name){
209    print "<OPTION VALUE=\"$val\"";
210    if( $val == $pcmode ){
211      print " SELECTED";
212    }
213    print ">$name</OPTION>\n";
214  }
215  print '</SELECT>';
216}
217
218//if( ($_SESSION['Me']->isChair) || ($Conf->validTimeFor('AtTheMeeting', 0)) ) {
219if( ($_SESSION['Me']->isChair) ) {
220  print "<H2>Discussion Order</H2>\n";
221
222  print "<TABLE><TR><TD ALIGN=TOP><INPUT TYPE='CHECKBOX' NAME='use_groups'";
223  if( $use_groups ){
224    print " CHECKED";
225  }
226  print ">Enable Discussion Order: </TD><TD>\n";
227  foreach($group_order as $val ){
228    print "<INPUT TYPE='CHECKBOX' NAME='groups[]' VALUE='$val'";
229    if( IsSet($kept_groups[$val]) ){
230      print " CHECKED";
231    }
232    print "> " . $groups[$val] . "<BR>\n";
233  }
234  print "</TD></TR></TABLE>\n";
235}
236
237if( IsSet($_REQUEST['Order']) || IsSet($_REQUEST['Update']) ){
238  $optionsSet = 1;
239} else {
240  $optionsSet = 0;
241}
242
243?>
244<BR><INPUT TYPE="SUBMIT" VALUE="Select Ordering" NAME="Order">
245</FORM>
246<?php
247
248if( $_SESSION['Me']->isChair && IsSet($_REQUEST['judgement']) ){
249  $judgement = $_REQUEST['judgement'];
250
251  foreach( $outcomeName as $oc => $name ){
252    $query = "UPDATE Paper SET outcome = '$oc' WHERE paperId < 0 ";
253    foreach( $judgement as $paperId => $j ){
254      if( $j == $oc ){
255	$paperId = addSlashes( $paperId );
256        $query .= " OR paperId = '$paperId' ";
257      }
258    }
259
260      //$Conf->infoMsg($query);
261    $result=$Conf->qe( $query );
262
263    if (DB::isError($result)) {
264      $Conf->errorMsg("Error in sql " . $result->getMessage());
265    }
266  }
267}
268
269// $Conf->infoMsg("Chair: $isChair<BR>Meeting: $meetingTime");
270
271// Don't show anything until a view is chosen
272
273if( $optionsSet ){
274
275$Conf->infoMsg("This table is sorted by descending " . $stats[$stat] . " of " . $graphs[$target] . " scores.  ");
276
277$Conf->infoMsg("This display only shows information only for finalized reviews.  Also, if you sort on `PC Grade' then only graded papers will show.  If you select standard deviation then two values are required."
278	       );
279
280
281$extracond = "";
282$extrapaper = "";
283
284if( $target == 'grade' ){
285  $table = 'PaperGrade';
286  $qual = "";
287  $count = "";
288  $countOrd = "";
289} else {
290  $table = 'PaperReview';
291  $qual =  "   AND PaperReview.finalized=1 ";
292  $count = " , COUNT(PaperReview.finalized) AS count ";
293  $countOrd = " count DESC, ";
294}
295
296if( ! $isChair ){
297  if ( $meetingTime ) {
298    $pcmode = 'PCHide';
299    $Conf->infoMsg("PC member papers will not be shown.");
300  } else {
301    $pcmode = 'PCAll';
302    $me = addSlashes( $_SESSION['Me']->contactId );
303    $extrapaper = " , PrimaryReviewer AS prim, PaperReview AS other ";
304    $extracond =
305      " AND $table.paperId = prim.paperId AND prim.reviewer = '$me' " .
306      " AND $table.paperId = other.paperId AND other.reviewer = '$me' " .
307      " AND other.finalized ";
308
309    $Conf->infoMsg("As a PC member you can only see papers that you reviewed.");
310  }
311}
312
313if( $pcmode == 'PCOnly' ){
314  $qual .= ' AND Paper.pcPaper = 1 ';
315} else if( $pcmode == 'PCHide' ){
316  $qual .= ' AND Paper.pcPaper = 0 ';
317}
318
319$query  = "SELECT $table.paperId, Paper.title, Paper.pcPaper, "
320	. " $stat($table.$target) AS merit "
321	. $count . $judgeData . $authorData
322	. " FROM $table, Paper $extrapaper $authorTable "
323	. " WHERE Paper.paperId = $table.paperId $extracond "
324	. $qual . $authorQual
325	. " GROUP BY $table.paperId "
326	. " ORDER BY merit DESC, $countOrd $table.paperId ";
327
328//$Conf->infoMsg( $query  );
329
330$result=$Conf->qe( $query );
331
332
333if (DB::isError($result)) {
334  $Conf->errorMsg("Error in sql " . $result->getMessage());
335  exit();
336}
337
338if( $judgeCol ){
339  print "<FORM METHOD='POST' ACTION='" . $_SERVER['PHP_SELF'] . "'>\n";
340  print "<INPUT TYPE='HIDDEN' NAME='GradeCol' VALUE=1>\n";
341
342  if( $authorRow ){
343    print "<INPUT TYPE='HIDDEN' NAME='AuthorRow' VALUE=1>\n";
344  }
345
346  if( $redCol ){
347    print "<INPUT TYPE='HIDDEN' NAME='RedCol' VALUE=1>\n";
348  }
349
350  if( $use_groups ){
351    print "<INPUT TYPE='HIDDEN' NAME='use_groups' VALUE=1>\n";
352  }
353
354  foreach($kept_groups as $val => $name){
355    print "<INPUT TYPE='HIDDEN' NAME='groups[]' VALUE='$val'>\n";
356  }
357
358  foreach($kept_graphs as $val => $name){
359    print "<INPUT TYPE='HIDDEN' NAME='COLS[]' VALUE='$val'>\n";
360  }
361
362  print "<INPUT TYPE='HIDDEN' NAME='target' VALUE='$target'>\n";
363  print "<INPUT TYPE='HIDDEN' NAME='stat' VALUE='$stat'>\n";
364  print "<INPUT TYPE='HIDDEN' NAME='pcmode' VALUE='$pcmode'>\n";
365}
366
367foreach( $kept_graphs as $field => $name ){
368  if( $field == 'grade' ){
369    $meritRange[$field] = $Conf->reviewRange($field, 'PaperGrade');
370  } else {
371    $meritRange[$field] = $Conf->reviewRange($field, 'PaperReview');
372  }
373}
374
375$grouped_rows = array();
376
377if( $use_groups ){
378  foreach( $kept_groups as $x => $val ){
379    $grouped_rows[$x] = array();
380  }
381} else {
382  $group_order = array( 'all' );
383  $groups['all'] = 'All Selected Papers';
384  $grouped_rows['all'] = array();
385  $dest = 'all';
386}
387
388while ($row=$result->fetchRow(DB_FETCHMODE_ASSOC)) {
389  if( $use_groups ){
390    $query = "SELECT grade, COUNT(grade) AS count FROM PaperGrade WHERE " .
391	     "paperId = " . $row['paperId'] ." GROUP BY grade";
392    $grades = array();
393
394    $gresult=$Conf->qe( $query );
395
396    while ($grow=$gresult->fetchRow(DB_FETCHMODE_ASSOC)) {
397      $grades[$grow['grade']] = $grow['count'];
398    }
399
400if( 0 ){
401    if( !$grades[1] && !$grades[2] ){
402      $dest = "groupABC";
403    } else if( !$grades[1] && $grades[5] ){
404      $dest = "groupA-E";
405    } else if( !$grades[4] && !$grades[5] ){
406      $dest = "groupCDE";
407    } else {
408      $dest = "groupRest";
409    }
410}
411
412    if( !$grades[1] && !$grades[2] && !$grades[3] ){
413      $dest = "groupW";
414    } else if( !$grades[4] && !$grades[5] && !$grades[3] ){
415      $dest = "groupZ";
416    } else if( !$grades[4] && !$grades[5] && $grades[1] ){
417      $dest = "groupY";
418    } else {
419      $dest = "groupX";
420    }
421
422    if( $row['paperId'] == 89 ){
423      $dest = "groupX";
424    }
425    // print     "<P>Chose $dest for " . $row['paperId'] ."</P>\n";
426  }
427
428  if( IsSet($grouped_rows[$dest]) ){
429    $grouped_rows[$dest][] = $row;
430  }
431}
432
433foreach( $group_order as $group ){
434  if( IsSet($grouped_rows[$group]) && count($grouped_rows[$group]) ){
435?>
436
437<H1><?php echo $groups[$group]?></H1>
438<table border=1 align=center>
439<tr bgcolor=<?php echo $Conf->contrastColorOne?>>
440<th colspan=<?php echo count($kept_graphs)+2+$judgeCol ?>> Paper Ranking by <?php echo $stats[$stat] . " of " . $graphs[$target] ?></th> </tr>
441
442<tr>
443<th> Row#<BR>(Pap#)</th>
444<th> Paper </th>
445<?php
446
447  if( $judgeCol ){
448    print "<TH>Judgement</TH>";
449  }
450
451  foreach( $kept_graphs as $field => $name ){
452    print "<th>$name</th>";
453  }
454
455?>
456</tr>
457<td> <b>
458<?php
459$rowNum = 0;
460foreach( $grouped_rows[$group] as $row ){
461  $rowNum++;
462  $pcPaper=$row['pcPaper'];
463
464  $redText = "";
465
466  if( $pcPaper && $pcmode == 'PCX' ){
467    $paperId= 'X';
468  } else {
469    $paperId=$row['paperId'];
470    $paperTitle=$row['title'];
471  }
472
473  if( $pcPaper && $redCol ){
474    $redText = " BGCOLOR='Red' ";
475  }
476
477  $redText .= $authorSpace;
478
479  print "<tr> <td $redText> $rowNum<BR>($paperId)</td> ";
480
481  if( $paperId == 'X' ){
482    print "<TD $redText>X</TD>";
483  } else {
484    print "<td> <A HREF=\"/PC/PCAllAnonReviewsForPaper.php?paperId=$paperId&SeeUnfinishedReviews=1&SeeAuthorInfo=1&SeeReviewerInfo=1\" TARGET=\"_blank\">";
485    print htmlentities($paperTitle);
486    print "</A></td> \n";
487  }
488
489  if( $judgeCol ){
490    if( $paperId == 'X' ){
491      print "<TD>X</TD>";
492    } else {
493      $outcome = $row['outcome'];
494      print "<TD><SELECT NAME='judgement[$paperId]'>\n";
495      foreach( $outcomeName as $val => $name ){
496        print "<OPTION VALUE='$val'";
497	if ($val == $outcome) {
498	  print " SELECTED";
499	}
500	print ">$name</OPTION>\n";
501      }
502      print "</SELECT></TD>\n";
503    }
504  }
505
506  foreach( $kept_graphs as $field => $name ){
507    print "<td align=center>";
508    if( $paperId == 'X' ){
509      print 'X';
510    } else {
511      if( $field == 'grade' ){
512	$q = "SELECT $field FROM PaperGrade WHERE paperID='$paperId'";
513      } else {
514	$q = "SELECT $field FROM PaperReview WHERE paperID='$paperId' AND finalized = 1";
515      }
516
517      $Conf->graphValues($q, $field, $meritRange[$field]['min'], $meritRange[$field]['max']);
518    }
519    print "</td>";
520  }
521
522  print "</tr> \n";
523
524  if( $authorRow ){
525    print "<TR><TD COLSPAN='";
526    print count($kept_graphs)+1+$judgeCol;
527    print "'>" . $Conf->safeHtml($row['authorInformation']) . "<BR><EM>"
528	  . ($Conf->safeHtml($row['firstName'] . " " . $row['lastName'] . " (" . $row['email'] . "), " . $row['affiliation']))
529	  . "</EM></TD></TR>\n";
530  }
531}
532?>
533</table>
534
535<?php
536}
537}
538if( $judgeCol ){
539  print "<INPUT TYPE='SUBMIT' VALUE='Update Judgements' NAME='Update'>\n";
540  print "</FORM>\n";
541}
542
543}
544?>
545
546<?php  $Conf->footer() ?>
547</body>
548</html>
549
550