<?php

// +----------------------------------------------------------------------+
// | OpenConf                                                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2012 Zakon Group LLC.  All Rights Reserved.       |
// +----------------------------------------------------------------------+
// | This source file is subject to the OpenConf License, available on    |
// | the OpenConf web site: www.OpenConf.com                              |
// +----------------------------------------------------------------------+

require_once "../include.php";
require_once OCC_COUNTRY_FILE;

beginChairSession();

if (isset($_REQUEST['cmt']) && ($_GET['cmt'] == "rev")) {
	$cmtSQL = " WHERE `onprogramcommittee`='F'";
	$hdr = "Review Committee Members";
} elseif (isset($_REQUEST['cmt']) && ($_GET['cmt'] == "pc")) {
	$cmtSQL = " WHERE `onprogramcommittee`='T'";
	$hdr = "Program Committee Members";
} elseif ($OC_configAR['OC_paperAdvocates']) {
	$cmtSQL = '';
	$hdr = "Review &amp; Program Committee Members";
} else {
	$cmtSQL = '';
	$hdr = "Review Committee Members";
}

$cmtURL = (isset($_GET['cmt']) ? ('&cmt=' . urlencode($_GET['cmt'])) : '');


printHeader($hdr." Country Count",1);

$q = "SELECT `country`, COUNT(`reviewerid`) AS `num` FROM `" . OCC_TABLE_REVIEWER . "` $cmtSQL GROUP BY `country` ORDER BY `num` DESC";
$r = ocsql_query($q) or err("Unable to get information");
if (mysql_num_rows($r) == 0) {
        print '<span class="warn">No committee members have signed up yet</span><p>';
} else {
	print '
<p style="text-align: center" class="note">Note: Only the country of the contact author is used for reporting</p>
<table border="0" cellpadding="5" cellspacing="1" style="margin: 0 auto">
';
	if (!isset($_GET['s']) || ($_GET['s'] == "country")) {
		print '<tr class="rowheader"><th valign="top">Country<br />' . $OC_sortImg . '</th><th valign="top"><a href="' . $_SERVER['PHP_SELF'] . '?s=num&' . $cmtURL . '">Count</a></th></tr>';
		$resAR = array();
		$nocountry = 0;
		while ($l = mysql_fetch_array($r)) {
			if (!empty($l['country']) && isset($OC_countryAR[$l['country']])) {
				$resAR[$OC_countryAR[$l['country']]] = $l['num'];
			} else {
				$nocountry = $l['num'];
			}
		}
		ksort($resAR, SORT_LOCALE_STRING);
		$row = 1;
		foreach ($resAR as $country => $num) {
			print '<tr class="row' . $row . '"><td>' . $country . '</td><td align="right">' . $num . "</td></tr>\n";
			if ($row==1) { $row=2; } else { $row=1; }
		}
		if ($nocountry > 0) {
			print '<tr class="row' . $row . '"><td style="font-style: italic;">unknown</td><td align="right">' . $nocountry . "</td></tr>\n";
		}
	} else {
		print '<tr class="rowheader"><th valign="top"><a href="' . $_SERVER['PHP_SELF'] . '?s=country&' . $cmtURL . '">Country</a></th><th valign="top">Count<br />' . $OC_sortImg . '</th></tr>';
		$resAR = array();
		$nocountry = 0;
		while ($l = mysql_fetch_array($r)) {
			if (empty($l['country']) || !isset($OC_countryAR[$l['country']])) {
				$nocountry += $l['num'];
			} else {
				if (!isset($resAR[$l['num']])) {
					$resAR[$l['num']] = array();
				}
				$resAR[$l['num']][] = $OC_countryAR[$l['country']];
			}
		}
		$row = 1;
		foreach ($resAR as $num => $countries) {
			sort($countries, SORT_LOCALE_STRING);
			print '<tr class="row'  .$row . '"><td>' . implode('<br />', $countries) . '</td><td align="right">' . $num . "</td></tr>\n";
			if ($row==1) { $row=2; } else { $row=1; }
		}
		if ($nocountry > 0) {
			print '<tr class="row' . $row . '"><td style="font-style: italic;">unknown</td><td align="right">' . $nocountry . "</td></tr>\n";
		}
	}
	
	print "</table>\n";
}

printFooter();

?>