';
// Init arrays
$OC_hooksAR = array();
$OC_cssAR = array();
$OC_jsAR = array();
$OC_extraHeaderAR = array();
$OC_onloadAR = array();
$OC_configAR = array();
$OC_statusAR = array();
$OC_modulesAR = array();
$OC_activeModulesAR = array();
$OC_localeAR = array();
// sanitize PHP_SELF
$_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
// Baseline version - set for install, updated from db below once installed
$GLOBALS['OC_configAR']['OC_version'] = '4.x'; ###
// Check whether it's home page or a subdir we're in
if (basename($_SERVER['PHP_SELF']) == "openconf.php") {
$pfx = "";
} else {
$pfx = "../";
}
define('OCC_LIB_DIR', $pfx . 'lib/'); // lib dir
define('OCC_PLUGINS_DIR', $pfx . 'plugins/'); // plugins dir
define('OCC_CONFIG_FILE', $pfx . 'config.php'); // config file location
define('OCC_FORM_INC_FILE', $pfx . 'include-forms.inc'); // forms include file location
define('OCC_SUBMISSION_INC_FILE', $pfx . 'author/submission.inc'); // submission include file
define('OCC_REVIEW_INC_FILE', $pfx . 'review/review.inc'); // review include file
define('OCC_COMMITTEE_INC_FILE', $pfx . 'review/committee.inc'); // review include file
define('OCC_COUNTRY_FILE', OCC_LIB_DIR . 'countries/countries.php'); // country file location
define('OCC_ZONE_FILE', OCC_LIB_DIR . 'zones/zones.php'); // time zone file location
define('OCC_MIME_FILE', OCC_LIB_DIR . 'mime.php'); // mime types file location
define('OCC_UTF8CASECONV_FILE', OCC_LIB_DIR . 'UTF8CaseConv.php'); // UTF8CaseConv file location
define('SALT_LENGTH', 10); // password hash salt length
/* DO NOT MODIFY THE LINE BELOW OR OTHERWISE FALSELY DEFINE OR MAKE UP OCC_LICENSE */
(file_exists($pfx . 'license.php') ? require_once($pfx . 'license.php') : define('OCC_LICENSE', 'Public')); // License type
/* DO NOT MODIFY THE LINE ABOVE */
// Set OC_formatAR with mime types - moved to OCC_MIME_FILE in 4.00
require_once OCC_MIME_FILE;
// Row Array - used for toggling row style
$rowAR = array();
$rowAR[1] = 2;
$rowAR[2] = 1;
// Yes/No Array
$yesNoAR = array(
1 => 'Yes',
0 => 'No'
);
// Status Array
$OC_statusValueAR = array(
1 => 'Open',
0 => 'Closed',
);
// Context
$OC_context = stream_context_create(array('http'=>array('timeout'=>20)));
// Strip slashes if magic_gpc enabled
function fix_magic_gpc(&$var) {
if (is_array($var)) {
array_walk($var, 'fix_magic_gpc');
} else {
$var = stripslashes($var);
}
}
if (ini_get('magic_quotes_gpc') || ini_get('magic_quotes_runtime')) {
array_walk($_GET, 'fix_magic_gpc');
array_walk($_POST, 'fix_magic_gpc');
array_walk($_REQUEST, 'fix_magic_gpc');
// cookies & files are skipped as no relevant data \'d
}
// i18n routines
function oc_($s, $d='') { // s|ource d|omain
if (function_exists('gettext')) {
if (!empty($d)) {
return(dgettext($d, $s));
} else {
return(_($s));
}
}
else { return($s); }
/*
elseif (empty($t)) {
return(T_($s));
} else {
return(T_dgettext($domain, $s));
}
*/
}
function oc_n($s, $p, $c, $d='') { // s|ource p|lural c|ount d|omain
if (function_exists('ngettext')) {
if (!empty($d)) {
return(dngettext($d, $s, $p, $c));
} else {
return(ngettext($s, $p, $c));
}
}
elseif ($c > 1) { return $p; }
else { return $s; }
/*
elseif (empty($d)) {
return(T_ngettext($s, $p, $c));
} else {
return(T_dngettext($d, $s, $p, $c));
}
*/
}
// Returns a string with double-quotes (only) slashes
function slashQuote($s) {
return(preg_replace('/"/','\\"',$s));
}
// Checks whether the script is close to timing out
function oc_checkTimeout() {
if (($GLOBALS['OC_timeStamp'] > 0)
&& ((time() - $GLOBALS['OC_timeStamp']) > ($GLOBALS['OC_maxRunTime'] - 5)) // timeout if within 5 seconds
) {
return TRUE;
}
return FALSE;
}
// Returns a string containing define statements with an updated constant value
function replaceConstantValue($constName, $newValue, &$string) {
$string = preg_replace('/(define\("' . $constName . '",\s?"?).*?("?\);)/', '${1}' . slashQuote(stripslashes($newValue)) . '${2}', $string);
}
// Returns true/false on whether a named hook is set
function oc_hookSet($hook) {
if (isset($GLOBALS['OC_hooksAR'][$hook]) && !empty($GLOBALS['OC_hooksAR'][$hook])) {
return true;
} else {
return false;
}
}
// Adds a hook for additional functionality; typically used with modules
function oc_addHook($name, $value) {
if (!isset($GLOBALS['OC_hooksAR'][$name])) { // init if first hook for name
$GLOBALS['OC_hooksAR'][$name] = array($value);
} elseif (!in_array($value, $GLOBALS['OC_hooksAR'][$name])) { // add only if not duplicate
$GLOBALS['OC_hooksAR'][$name][] = $value;
}
}
// Add CSS file to be read in by header
function oc_addCSS($file,$moduleId='') {
if (!empty($moduleId)) {
$GLOBALS['OC_cssAR'][] = 'modules/' . $moduleId . '/' . $file;
} else {
$GLOBALS['OC_cssAR'][] = $file;
}
}
// Add JS file to be read in by header
function oc_addJS($file,$moduleId='') {
if (!empty($moduleId)) {
$GLOBALS['OC_jsAR'][] = 'modules/' . $moduleId . '/' . $file;
} else {
$GLOBALS['OC_jsAR'][] = $file;
}
}
// Add body onLoad to be included in header
function oc_addOnLoad($js) {
$GLOBALS['OC_onloadAR'][] = $js;
}
// Add extra headers
function oc_addHeader($hdr) {
$GLOBALS['OC_extraHeaderAR'][] = $hdr;
}
// Return the current or specified month name
function oc_monthName($m='') {
if (!empty($m)) {
return(strftime('%B', mktime(12, 0, 0, $m)));
} else {
return(strftime('%B')); }
}
// Return an array of months
function oc_getMonths($cal=0) {
$calinfo = cal_info($cal);
return($calinfo['months']);
}
// Returns an array of database tables
function getTables() {
$constAR = get_defined_constants();
preg_match_all("/(OCC_TABLE_\w+)/",implode('\0',array_keys($constAR)),$tAR);
foreach ($tAR[0] as $t) { $tableAR[] = constant($t); }
return($tableAR);
}
// hashPassword - returns a hash of $pw, including a salt
function hashPassword($pw, $salt=NULL) {
if ($salt === NULL) {
$salt = substr(md5(uniqid(rand(),TRUE)), 0, SALT_LENGTH);
} else {
$salt = substr($salt,0,SALT_LENGTH);
}
return $salt . sha1($salt . $pw);
}
// newPassword - creates & returns a new random password
function newPassword() {
return(substr(md5(uniqid(rand(),TRUE)),5,rand(8,10)));
}
// Format number
// $n = number of bytes
function oc_formatNumber($n) {
if ($n > 1048576) { // > 1 MB
return(number_format(($n/1048576),1) . "MB");
} else {
return(number_format(($n/1024),0) . "KB");
}
}
// Convert units
function toMB($n) {
if (preg_match("/^(\d+)(\w?)[bB]?$/",$n,$matches)) {
switch (strtoupper($matches[2])) {
case '':
case 'B': return(number_format(($matches[1]/1048576),1) . "MB"); break;
case 'K': return(number_format(($matches[1]/1024),2) . "MB"); break;
case 'M': return($matches[1] . "MB"); break;
}
}
return($n);
}
// Returns the value of a var if it exists in the specified array, or a default value
// if safe=true and array value exists, it's returned safeHTMLstr()
function varValue($varName, &$ar, $default='', $safe=false) {
if (isset($ar[$varName])) {
if ($safe) {
return(safeHTMLstr($ar[$varName]));
} else {
return($ar[$varName]);
}
}
return($default);
}
// Displays page header
function printHeader($what, $function="0") {
require_once $GLOBALS['pfx'] . (isset($GLOBALS['OC_configAR']['OC_headerFile']) ? $GLOBALS['OC_configAR']['OC_headerFile'] : 'header.php');
print '
';
if (isset($GLOBALS['OC_displayTop']) && !empty($GLOBALS['OC_displayTop'])) {
print $GLOBALS['OC_displayTop'];
}
print '
';
}
// Displays page footer
function printFooter() {
global $pfx;
print '
' .
//T: %2s = OpenConf
sprintf(oc_('Powered by
%2$s ® '), 'http://www.OpenConf.com', 'OpenConf') . '
' .
//T: %1s-%2s = YYYY-YYYY, %4$s = Zakon Group LLC
sprintf(oc_('Copyright ©%1$s-%2$s
%4$s '), '2002', '2011', 'http://www.ZakonGroup.com/technology/', 'Zakon Group LLC') . '
';
require_once $pfx . 'footer.php';
}
// Displays warning and exits
function warn($warnmsg, $hdr='', $hdrfn=0) {
if (!empty($hdr)) {
printHeader($hdr,$hdrfn);
}
print '' . $warnmsg . '
';
printFooter();
exit;
}
// Displays error and exits
function err($errmsg, $hdr='', $hdrfn=0, $contact=true) {
global $OC_configAR;
if (!empty($hdr)) {
printHeader($hdr,$hdrfn);
}
print '
' . oc_('We have encountered a problem:') . '
' . $errmsg . '
';
if ($contact) {
if (! isset($_SESSION[OCC_SESSION_VAR_NAME]['chairlast'])) {
print sprintf(oc_('Please contact the
Program Chair .'), varValue('OC_pcemail', $OC_configAR), htmlspecialchars($errmsg));
} else {
print oc_('Please contact the system administrator.');
}
}
print "
\n";
printFooter();
exit;
}
// Makes database connection
function dbConnect($printHeaderFunction=0) {
// Return if already connected
if (isset($GLOBALS['OC_db']) && !empty($GLOBALS['OC_db'])) { return; }
// Connect to DB server
$GLOBALS['OC_db'] = mysql_connect(OCC_DB_HOST, OCC_DB_USER, OCC_DB_PASSWORD) or err("could not connect to database " . mysql_errno(), 'Error', $printHeaderFunction);
// Specify UTF-8 use for connection
if (function_exists('mysql_set_charset')) {
mysql_set_charset('utf8', $GLOBALS['OC_db']);
} else {
mysql_query("SET NAMES 'utf8'");
}
// Select DB
mysql_select_db(OCC_DB_NAME) or err("could not select database " . mysql_errno(), 'Error', $printHeaderFunction);
}
// Custom db query function to enable logging
function ocsql_query($q) {
global $OC_configAR;
if ($GLOBALS['OC_configAR']['OC_logSQL'] && preg_match("/^(?:INSERT|UPDATE|DELETE|ALTER|TRUNCATE|DELETE|CREATE|DROP)/", $q)) {
// log DB updates
$logq = "INSERT INTO `" . OCC_TABLE_LOG . "` SET `datetime`=UTC_TIMESTAMP(), `entry`='" . safeSQLstr($q) . "', `type`='sql'";
if (!mysql_query($logq)) {
return(FALSE);
}
}
return(mysql_query($q));
}
// Retrieve a file's content
function ocGetFile($f) {
return(file_get_contents($f, 0, $GLOBALS['OC_context']));
}
// updates a setting in the config table
function updateConfigSetting($setting, $value, $module='OC') {
$q = "UPDATE `" . OCC_TABLE_CONFIG . "` SET `value`='" . safeSQLstr(trim($value)) . "' WHERE `module`='" . safeSQLstr($module) . "' AND `setting`='" . safeSQLstr($setting) . "'";
return(ocsql_query($q));
}
// cycles through an array of config settings and updates them if needed
function updateAllConfigSettings(&$varAR, &$valAR, $module='OC') {
global $OC_configAR;
foreach ($varAR as $v) {
if (isset($valAR[$v]) && isset($OC_configAR[$v]) && ($OC_configAR[$v] != $valAR[$v])) {
updateConfigSetting($v, $valAR[$v], $module) or err('Unable to update setting ' . safeHTMLstr($v));
$OC_configAR[$v] = $valAR[$v];
}
}
}
// updates a setting in the status table
function updateStatusSetting($setting, $value) {
$q = "UPDATE `" . OCC_TABLE_STATUS . "` SET `status`='" . safeSQLstr($value) . "' WHERE `setting`='" . safeSQLstr($setting) . "'";
if (ocsql_query($q)) {
$q = "INSERT INTO `" . OCC_TABLE_LOG . "` (`datetime`, `entry`, `type`) SELECT UTC_TIMESTAMP(), CONCAT_WS(' ', `name`, '" . (($value == 1) ? 'opened' : 'closed') . "') AS `entry`, 'status' FROM `" . OCC_TABLE_STATUS . "` WHERE `setting`='" . safeSQLstr($setting) . "'";
ocsql_query($q);
return(true);
}
return(false);
}
// cycles through an array of status settings and updates them if needed
function updateAllStatusSettings(&$varAR, &$valAR) {
global $OC_statusAR;
foreach ($varAR as $v) {
if (isset($valAR[$v]) && isset($OC_statusAR[$v]) && preg_match("/^[01]$/", $valAR[$v]) && ($OC_statusAR[$v] != $valAR[$v])) {
updateStatusSetting($v, $valAR[$v]) or err('Unable to update setting ' . safeHTMLstr($v));
$OC_statusAR[$v] = $valAR[$v];
}
}
}
// Issues a SQL call
// intended for use by chair functions only as it exposes SQL statements
function issueSQL($s) {
ocsql_query($s) or err("unable to issue: $s");
}
// safeSQLstr - return a string safe for db insertion
function safeSQLstr ($s) {
return mysql_real_escape_string($s);
}
// safeHTMLstr - return a string safe for html display
function safeHTMLstr ($s) {
return htmlspecialchars($s, ENT_COMPAT); // , 'UTF-8'); ## UTF-8 results in empty string if invalid characters in string
}
// generateSelectOptions - Creates series of tags based on input array values
function generateSelectOptions(&$optionAR, $selected='', $usekey=TRUE, $multiple=FALSE) {
$options = '';
foreach ($optionAR as $key => $val) {
// if key is numeric, then just use value
if ($usekey) {
$options .= ' ';
}
return($options);
}
// generateBoxNRadioOptions - Creates a series of radio or checkboxes based on input array values
function generateBoxNRadioOptions($name, $type, &$optionAR, $selected='', $usekey=1, $extra='', $break=' ', $multiple=FALSE) {
$boxes = '';
$i = 1;
foreach ($optionAR as $key => $val) {
// if key is numeric, then just use value
if ($usekey) {
$comp = $key;
} else {
$comp = $val;
}
$boxes .= ' ' . $val . ' ' . $break;
}
return($boxes);
}
function generateRadioOptions($name, &$checkboxAR, $selected='', $usekey=1, $extra='', $break=' ', $multiple=FALSE) {
return(generateBoxNRadioOptions($name, 'radio', $checkboxAR, $selected, $usekey, $extra, $break, $multiple));
}
function generateCheckboxOptions($name, &$checkboxAR, $selected='', $usekey=1, $extra='', $break=' ', $multiple=FALSE) {
return(generateBoxNRadioOptions($name, 'checkbox', $checkboxAR, $selected, $usekey, $extra, $break, $multiple));
}
// Shorten a string w/o splitting a word
// Implemented for use in 's
function shortenStr($s,$l) {
if (($l==0) || (($slen=oc_strlen($s)) < $l)) {
return($s);
} else {
$news = substr($s,0,$l);
// Don't break string mid-word
if (!preg_match("/[^\w\']$/",$news)) {
$pos = $l;
while (($pos < $slen) && preg_match("/[\w\']/",($c=substr($s,$pos,1)))) {
$news .= $c;
$pos++;
}
}
if (oc_strlen($news) < $slen) { $news .= "..."; }
return($news);
}
}
// Checks whether a string is multi-byte
function oc_isMultibyte($s) {
return (bool)preg_match('/[\x80-\xff]/', $s);
}
// str case conversion to properly handle UTF-8
function oc_caseConvert($s, $f) {
static $ocUpperChars, $ocLowerChars;
if (! oc_isMultibyte($s)) {
switch ($f) {
case 'strtoupper':
return strtoupper($s);
break;
case 'strtolower':
return strtolower($s);
break;
default:
err('string function unknown');
break;
}
} elseif (function_exists('mb_strtoupper')) {
switch ($f) {
case 'strtoupper':
return mb_strtoupper($s);
break;
case 'strtolower':
return mb_strtolower($s);
break;
default:
err('string function unknown');
break;
}
} else {
require_once OCC_UTF8CASECONV_FILE;
switch ($f) {
case 'strtoupper':
return preg_replace( "/([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
"strtr(\"\$1\", \$ocUpperChars)",
$s
);
break;
case 'strtolower':
return preg_replace( "/([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
"strtr(\"\$1\", \$ocLowerChars)",
$s
);
break;
default:
err('string function unknown');
break;
}
}
}
// Safe UTF8 strtoupper
function oc_strtoupper($s) {
return oc_caseConvert($s, 'strtoupper');
}
// Safe UTF8 strtolower
function oc_strtolower($s) {
return oc_caseConvert($s, 'strtolower');
}
// Safe UTF8 strlen
function oc_strlen($s) {
return strlen(utf8_decode((string) $s));
}
// Inserts to format number
function padNumber($num, $size) {
$padsize = $size - oc_strlen((string) $num);
for ($i=$padsize;$i>0;$i--) {
$num = " " . $num;
}
return($num);
}
// Validate email address
function validEmail($email,$len=0) {
// Note: ? and ' left out of regex below due to issues with HTML mailto: displays and SQL code, respectively
if (!preg_match("/^[\!\#\$\%\&\*\-\/\=\+\_\`\{\|\}\~a-z0-9]+(\.[\!\#\$\%\&\*\-\/\=\+\_\`\{\|\}\~a-z0-9]+)*@([a-z0-9-]+\.)+([a-z]{1,6})$/i",$email)) {
return(false);
} elseif (($len>0) && (oc_strlen($email) > $len)) {
return(false);
}
return(true);
}
// Encode text into quoted-printable format
function oc_qpencode($what, $linelenmax = 75) {
$eol = "\n"; // using \n instead of \r\n to avoid double-spaced messages in Outlook
$encoded = '';
$lines = preg_split("/(?:\r\n|\r|\n)/", $what);
while(list(, $line) = each($lines)) {
$linelen = strlen($line);
$encline = '';
for ($i=0; $i<$linelen; $i++) {
$c = substr($line, $i, 1);
$cdec = ord($c);
if (($cdec == 32) && ($i == ($linelen - 1))) {
$c = '=20';
} elseif (($cdec == 61) || ($cdec < 32) || ($cdec > 126)) {
$c = '=' . strtoupper(sprintf('%02s', dechex($cdec)));
}
if ((strlen($encline) + strlen($c)) >= $linelenmax) {
$encoded .= $encline . '=' . $eol;
$encline = '';
}
$encline .= $c;
}
$encoded .= $encline . $eol;
}
$encoded = substr($encoded, 0, -1 * strlen($eol));
return $encoded;
}
// Sends out optionally utf-8 enabled email
// Note: headers are not converted except for subject
// We are defaulting to QP so bounced messages can be more easily read (for non-CJK)
function oc_mail($to, $subject, $body, $hdr='', $enc='quoted-printable') {
global $OC_configAR;
$headers = (empty($hdr) ? $OC_configAR['OC_mailHeaders'] : $hdr);
if ($OC_configAR['OC_mailUTF8']) {
$headers = "MIME-Version: 1.0\r\n" . $headers . "\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: " . $enc;
$headers = preg_replace("/\r/", "", $headers);
switch ($enc) {
case 'base64':
$body = chunk_split(base64_encode($body));
$subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
break;
default:
$body = oc_qpencode($body);
$subject = "=?UTF-8?Q?" . rtrim(preg_replace(array("/[\r\n].*$/", "/\s+/", "/\?/"), array("", "_", "=3f"), oc_qpencode($subject)), '= ') . "?="; // only use first line for subject and replace spaces/?s
break;
}
} else {
$body = wordwrap($body, $OC_configAR['OC_emailWrap']);
}
return(mail($to, $subject, $body, $headers, $OC_configAR['OC_mailParams']));
}
// Sends an email message, adding OC_confName to beginning of subject line, and cc'ing OC_confirmmail and including IP address if requested
function sendEmail($to, $subject, $body, $ccConfirm=0) {
global $OC_configAR, $OC_mailHeaders, $OC_mailParams;
// include confirm address?
if ($ccConfirm) {
$to .= ',' . $OC_configAR['OC_confirmmail'];
// trim in case no $to passed
$to = ltrim($to,',');
}
// Bail out successfully(?) if no one to email
if (empty($to)) { return(TRUE); }
// Add conf name to beginning of subject
$subject = "[" . $OC_configAR['OC_confName'] . "] " . $subject;
// Include IP in message body?
if ($OC_configAR['OC_notifyIncludeIP']) {
$body .= "\n\nIP Address: " . $_SERVER['REMOTE_ADDR'] . "\n";
}
// Send message & return whether successful
return(oc_mail($to, $subject, $body));
}
// Generates a unique ID
function generateID() {
return(md5(uniqid(rand(), TRUE)));
}
// Returns short topic if !empty, else full topic name
function useTopic($short, $full, $cut=0) {
if (!empty($short)) { return($short); }
elseif ($cut) {
if ($cut == 1) { $cut = 30; } // default cut length
return(substr($full,0,$cut));
}
return($full);
}
// Checks whether form token is valid
function validToken($type) {
if (isset($_SESSION[OCC_SESSION_VAR_NAME][$type . 'token']) && isset($_REQUEST['token']) && ($_REQUEST['token'] == $_SESSION[OCC_SESSION_VAR_NAME][$type . 'token'])) {
return(TRUE);
} else {
return(FALSE);
}
}
// Sends no cache headers
function oc_sendNoCacheHeaders() {
header("Expires: Mon, 18 Sep 2003 13:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
// Display (retrieve) file
function oc_displayFile($path, $format) {
if (oc_hookSet('display_file')) {
foreach ($GLOBALS['OC_hooksAR']['display_file'] as $hook) {
require_once $hook;
}
}
if (file_exists($path)) {
header("Content-type: " . $GLOBALS['OC_mimeTypeAR'][$format]);
header("Content-Disposition: ; filename=" . basename($path));
header("Content-Length: " . filesize($path));
header("Cache-control: private");
header("Pragma: public"); // IE issue work around
readfile($path);
exit;
} else {
return false;
}
return true;
}
// Save uploaded file
function oc_saveFile($src, $dest, $type) {
if (move_uploaded_file($src, $dest)) {
chmod($dest, 0666);
if (oc_hookSet('save_file')) {
return call_user_func($GLOBALS['OC_hooksAR']['save_file'][0], $src, $dest, $type); // only one hook allowed here
}
return true;
} else {
return false;
}
}
// Create directory
function oc_createDir($dir, $htaccess=FALSE) {
if (oc_hookSet('create_directory')) {
return call_user_func($GLOBALS['OC_hooksAR']['create_directory'][0], $dir); // only one hook allowed here
} elseif (! is_dir($dir)) {
$umask = umask(0);
if (! mkdir($dir, 0755, TRUE)) {
return(FALSE);
}
umask($umask);
// Create .htaccess
if ($htaccess) {
if (! ($fp = fopen($dir . '/.htaccess', 'w')) || ! fwrite($fp, "deny from all\n")) {
return(FALSE);
}
}
}
return(TRUE);
}
// Delete directory and subdirectories
function oc_deleteDir($dir, $pass=0) {
if (($pass == 0) && oc_hookSet('delete_directory')) { // only call hook once
return call_user_func($GLOBALS['OC_hooksAR']['delete_directory'][0], $dir); // only one hook allowed here
} elseif (is_dir($dir)) {
$dir = rtrim($dir, '/');
$dirPtr = dir($dir);
while (($name = $dirPtr->read()) !== false) {
if (!preg_match("/^\.\.?$/", $name)) {
is_dir($dir . '/' . $name) ? oc_deleteDir($dir . '/' . $name, ++$pass) : unlink($dir . '/' . $name);
}
}
$dirPtr->close();
return rmdir($dir);
}
}
// Delete file
function oc_deleteFile($path) {
if (oc_hookSet('delete_file')) {
return call_user_func($GLOBALS['OC_hooksAR']['delete_file'][0], $path); // only one hook allowed here
} elseif (is_file($path)) {
return unlink($path);
}
}
// Rename file
function oc_renameFile($oldFileName, $newFileName) {
if (oc_hookSet('rename_file')) {
return call_user_func($GLOBALS['OC_hooksAR']['rename_file'][0], $oldFileName, $newFileName); // only one hook allowed here
} else {
return rename($oldFileName, $newFileName);
}
}
// Check if file exists
function oc_isFile($path) {
if (oc_hookSet('is_file')) {
return call_user_func($GLOBALS['OC_hooksAR']['is_file'][0], $path); // only one hook allowed here
} else {
return is_file($path);
}
}
// get file size
function oc_fileSize($path) {
if (oc_hookSet('filesize')) {
return call_user_func($GLOBALS['OC_hooksAR']['filesize'][0], $path); // only one hook allowed here
} else {
return filesize($path);
}
}
// get file size
function oc_fileMtime($path) {
if (oc_hookSet('filemtime')) {
return call_user_func($GLOBALS['OC_hooksAR']['filemtime'][0], $path); // only one hook allowed here
} else {
return filemtime($path);
}
}
// get count of data files in dir (with name number.ext)
function oc_fileCount($dir) {
$count = 0;
if (oc_hookSet('file_count')) {
$count = call_user_func($GLOBALS['OC_hooksAR']['file_count'][0], $dir); // only one allowed
} else {
if ($pdh = opendir($dir)) {
while(($f = readdir($pdh)) !== false) {
if (preg_match("/^\d+\.\w+$/",$f)) {
$count++;
}
}
closedir($pdh);
}
}
return($count);
}
// prints out a table cell with link to file if available
function oc_printFileCells(&$sub, $chair=false) {
$str = '';
if (oc_hookSet('print_file_cells')) {
$str = call_user_func($GLOBALS['OC_hooksAR']['print_file_cells'][0], $sub, $chair); // only one hook allowed here
} else {
$paper = $sub['paperid'] . '.' . $sub['format'];
$file = $GLOBALS['OC_configAR']['OC_paperDir'] . $paper;
if (!empty($sub['format']) && oc_isFile($file)) {
$str = ' (' . oc_formatNumber(oc_fileSize($file)) . ') ';
} else {
$str = ' ';
}
}
return($str);
}
// Get list of reviewer & advocate emails for a paper
function getPaperReviewersEmail($pid) {
$emailAR = array();
$r = ocsql_query("SELECT `email` FROM `" . OCC_TABLE_REVIEWER . "`, `" . OCC_TABLE_PAPERREVIEWER . "` WHERE `" . OCC_TABLE_PAPERREVIEWER . "`.`paperid`=$pid AND `" . OCC_TABLE_PAPERREVIEWER . "`.`reviewerid`=`" . OCC_TABLE_REVIEWER . "`.`reviewerid`") or err("Unable to retrieve reviewer email addresses");
while ($l = mysql_fetch_array($r)) {
$emailAR[] = $l['email'];
}
$r = ocsql_query("SELECT `email` FROM `" . OCC_TABLE_REVIEWER . "`, `" . OCC_TABLE_PAPERADVOCATE . "` WHERE `" . OCC_TABLE_PAPERADVOCATE . "`.`paperid`=$pid AND `" . OCC_TABLE_PAPERADVOCATE . "`.`advocateid`=`" . OCC_TABLE_REVIEWER . "`.`reviewerid`") or err("Unable to retrieve advocate email addresses");
if (mysql_num_rows($r) == 1) {
$l = mysql_fetch_array($r);
if (!in_array($l['email'],$emailAR)) {
$emailAR[] = $l['email'];
}
}
return(implode(",",$emailAR));
}
/* Do not modify this line */if (isset($_POST['submit']) && preg_match("/\/chair\/s.gnin\.php/", $_SERVER['PHP_SELF']) && ini_get('allow_url_fopen') && ($v=ocGetFile('http://www.openconf.com/license.php?v='.urlencode($GLOBALS['OC_configAR']['OC_version']).'&l='.urlencode(constant('OCC_L'.'ICENSE')).'&s='.urlencode($_SERVER['HTTP_HOST']).'&m='.(file_exists($pfx.'modules/oc_bid')?1:0).'&p='.urlencode($_SERVER['PHP_SELF']))) && ($v=='x')){print base64_decode('VGhpcyBPcGVuQ29uZiBpbnN0YWxsIGlzIGluIHZpb2xhdGlvbiBvZiB0aGUgc29mdHdhcmUgbGljZW5zZTsgcHVyY2hhc2UgYSBwcm9wZXIgbGljZW5zZSBhdCB3d3cuT3BlbkNvbmYuY29tLg==');exit;
}
// Display single review
function displayReview($review, $rid) {
$sq = "SELECT `topicid` FROM `" . OCC_TABLE_PAPERSESSION . "` WHERE `" . OCC_TABLE_PAPERSESSION . "`.`paperid`='" . $review['paperid'] . "' AND `" . OCC_TABLE_PAPERSESSION . "`.`reviewerid`='" . $rid . "'";
$sr = ocsql_query($sq) or err('Unable to retrieve sessions');
$review['sessions'] = array();
while ($sl = mysql_fetch_array($sr)) {
$review['sessions'][] = $sl['topicid'];
}
print '';
require_once OCC_FORM_INC_FILE;
if (isset($review['value']) && !is_array($review['value'])) {
$review['value'] = explode(',', $review['value']);
}
oc_showFieldSet($GLOBALS['OC_reviewQuestionsFieldsetAR'], $GLOBALS['OC_reviewQuestionsAR'], $review);
print '
Completed: ' . (($review['completed'] == "T") ? 'Yes' : 'No') . '
Last Update: ' . $review['updated'] . '
';
}
// Display reviews
function displayReviews($pid, $r) {
while ($l = mysql_fetch_array($r)) {
print '
Reviewer: ';
if (isset($_SESSION[OCC_SESSION_VAR_NAME]['chairlast']) && preg_match("/chair\//",$_SERVER['PHP_SELF'])) {
print ''.$l['reviewerid'].' - ' . safeHTMLstr($l['name']) . ' ';
} elseif (isset($l['email']) && !empty($l['email'])) {
if ($GLOBALS['OC_configAR']['OC_reviewerSeeOtherReviewers'] || ($_SESSION[OCC_SESSION_VAR_NAME]['acpc'] == 'T')) {
print '' . $l['reviewerid'] . ' - ' . safeHTMLstr($l['name']) . ' ';
} else {
print $l['reviewerid'];
}
} else {
if ($GLOBALS['OC_configAR']['OC_reviewerSeeOtherReviewers'] || ($_SESSION[OCC_SESSION_VAR_NAME]['acpc'] == 'T')) {
print $l['reviewerid'] . ' - ' . safeHTMLstr($l['name']);
} else {
print $l['reviewerid'];
}
}
print '
Score: '.$l['recommendation'].'
';
displayReview($l, $l['reviewerid']);
print "
";
}
}
// Returns an array of paper-reviewer pairs with conflicts
// $sameorg = whether to mark as conflict if from the same org
// $rid = limit query to a single reviewerid
function getConflicts($rid=0) {
$conflictAR = array();
$assignedAR = array();
// Get curr rev/adv assignments & exclude them as conflicts
if ($GLOBALS['OC_configAR']['OC_allowConflictOverride'] && ($rid != 0)) {
// reviews
$r = ocsql_query("SELECT `paperid` FROM `" . OCC_TABLE_PAPERREVIEWER . "` WHERE `reviewerid`=" . $rid) or err("Unable to retrieve rev assignments");
while ($l = mysql_fetch_array($r)) {
$assignedAR[] = $l['paperid'];
}
// advocating
$r = ocsql_query("SELECT `paperid` FROM `" . OCC_TABLE_PAPERADVOCATE . "` WHERE `advocateid`=" . $rid) or err("Unable to retrieve adv assignments");
while ($l = mysql_fetch_array($r)) {
if (!in_array($l['paperid'], $assignedAR)) {
$assignedAR[] = $l['paperid'];
}
}
}
// Get manually assigned conflicts
$q = "SELECT * FROM `" . OCC_TABLE_CONFLICT . "`";
if ($rid) { $q .= " WHERE `reviewerid`=" . $rid; } // limit to $rid
$r = ocsql_query($q) or err("Unable to retrieve conflicts ".mysql_errno());
while ($l=mysql_fetch_array($r)) {
if (!in_array($l['paperid'],$assignedAR)) {
$conflictAR[] = $l['paperid'] . '-' . $l['reviewerid'];
}
}
// Get additional conflicts - email & optionally org
$q = "SELECT `paperid`, `reviewerid` FROM `" . OCC_TABLE_AUTHOR . "`, `" . OCC_TABLE_REVIEWER . "` WHERE ";
if ($rid) { $q .= "`reviewerid`=" . $rid . " AND "; } // limit to $rid
$q .= "(`" . OCC_TABLE_AUTHOR . "`.`email`=`" . OCC_TABLE_REVIEWER . "`.`email`";
if (! $GLOBALS['OC_configAR']['OC_allowOrgConflict']) {
$q .= " OR (`" . OCC_TABLE_AUTHOR . "`.`organization` <> '' AND `" . OCC_TABLE_AUTHOR . "`.`organization`=`" . OCC_TABLE_REVIEWER . "`.`organization`)";
}
$q .= ") GROUP BY `paperid`, `reviewerid`";
$r = ocsql_query($q) or err("Unable to get paper/reviewer conflicts ".mysql_errno());
while ($l=mysql_fetch_array($r)) {
if (!in_array($l['paperid']."-".$l['reviewerid'],$conflictAR) && !in_array($l['paperid'],$assignedAR)) {
$conflictAR[] = $l['paperid']."-".$l['reviewerid'];
}
}
// Conflict hooks
if (oc_hookSet('include-get_conflicts')) {
foreach ($GLOBALS['OC_hooksAR']['include-get_conflicts'] as $hook) {
require_once $hook;
}
}
return($conflictAR);
}
// Begin reviewer session
function beginSession() {
if (empty($_SESSION[OCC_SESSION_VAR_NAME]['acusername']) || empty($_SESSION[OCC_SESSION_VAR_NAME]['acreviewerid']) || (($GLOBALS['OC_configAR']['OC_ReviewerTimeout'] > 0) && ((time() - $_SESSION[OCC_SESSION_VAR_NAME]['aclast']) > (60 * $GLOBALS['OC_configAR']['OC_ReviewerTimeout']))) ) {
$addheader = '';
// Was a review/recommendation being filled out when timed out?
// If so, save results so we can recover -- assuming we have the reviewerid
if (!empty($_SESSION[OCC_SESSION_VAR_NAME]['acusername']) && !empty($_SESSION[OCC_SESSION_VAR_NAME]['acreviewerid']) && isset($_POST['submit']) && (($_POST['submit'] == "Submit Review") || ($_POST['submit'] == "Submit Recommendation"))) {
$_SESSION[OCC_SESSION_VAR_NAME]['POST'] = $_POST;
$addheader .= '&' . strip_tags(SID);
}
if ($_SESSION[OCC_SESSION_VAR_NAME]['acpc'] == "T") {
$addheader .= "&cmt=pc";
} else {
$addheader .= "&cmt=rev";
}
session_write_close();
header("Location: ../review/signin.php?e=exp" . $addheader);
exit;
}
$_SESSION[OCC_SESSION_VAR_NAME]['aclast'] = time();
}
// Begin chair session
function beginChairSession() {
// Expired session?
if (!isset($_SESSION[OCC_SESSION_VAR_NAME]['chairlast']) || (($GLOBALS['OC_configAR']['OC_ChairTimeout'] > 0) && ((time() - $_SESSION[OCC_SESSION_VAR_NAME]['chairlast']) > (60 * $GLOBALS['OC_configAR']['OC_ChairTimeout']))) ) {
header("Location: ../chair/signin.php?e=exp");
exit;
}
$_SESSION[OCC_SESSION_VAR_NAME]['chairlast'] = time();
}
// Read in config file settings
if (is_file(OCC_CONFIG_FILE)) {
require_once OCC_CONFIG_FILE;
// Define DB Tables
define("OCC_TABLE_ACCEPTANCE", OCC_DB_PREFIX . "acceptance");
define("OCC_TABLE_AUTHOR", OCC_DB_PREFIX . "author");
define("OCC_TABLE_CONFIG", OCC_DB_PREFIX . "config");
define("OCC_TABLE_CONFLICT", OCC_DB_PREFIX . "conflict");
define("OCC_TABLE_EMAIL_QUEUE", OCC_DB_PREFIX . "email_queue");
define("OCC_TABLE_LOG", OCC_DB_PREFIX . "log");
define("OCC_TABLE_MODULES", OCC_DB_PREFIX . "modules");
define("OCC_TABLE_PAPER", OCC_DB_PREFIX . "paper");
define("OCC_TABLE_PAPERADVOCATE", OCC_DB_PREFIX . "paperadvocate");
define("OCC_TABLE_PAPERREVIEWER", OCC_DB_PREFIX . "paperreviewer");
define("OCC_TABLE_PAPERSESSION", OCC_DB_PREFIX . "papersession");
define("OCC_TABLE_PAPERTOPIC", OCC_DB_PREFIX . "papertopic");
define("OCC_TABLE_REVIEWER", OCC_DB_PREFIX . "reviewer");
define("OCC_TABLE_REVIEWERTOPIC", OCC_DB_PREFIX . "reviewertopic");
define("OCC_TABLE_STATUS", OCC_DB_PREFIX . "status");
define("OCC_TABLE_TEMPLATE", OCC_DB_PREFIX . "template");
define("OCC_TABLE_TOPIC", OCC_DB_PREFIX . "topic");
define("OCC_TABLE_WITHDRAWN", OCC_DB_PREFIX . "withdrawn");
// Read in config & status settings & acceptance values from DB
if ((basename($_SERVER['PHP_SELF']) != 'install-db.php') && defined('OCC_DB_NAME') && (OCC_DB_NAME != '')) {
dbConnect();
$parseAR = array();
$r = mysql_query("SELECT `setting`, `value`, `parse` FROM `" . OCC_TABLE_CONFIG . "`") or err('Unable to retrieve config settings', 'Error');
while ($l = mysql_fetch_assoc($r)) {
$OC_configAR[$l['setting']] = $l['value'];
$$l['setting'] = $l['value']; // backward compatabiility
if ($l['parse']) {
$parseAR[] = $l['setting'];
}
}
// Special OC Settings
$OC_configAR['OC_extar'] = explode(",", $OC_configAR['OC_extar']);
$OC_extar = $OC_configAR['OC_extar'];
if (!preg_match("/^\//", $OC_configAR['OC_dataDir'])) {
$OC_configAR['OC_dataDir'] = $pfx . $OC_configAR['OC_dataDir'];
}
ini_set('date.timezone', $OC_configAR['OC_timeZone']);
// Config options to parse
foreach ($parseAR as $setting) {
$OC_configAR[$setting] = preg_replace("/\\\$(\w+)\\\$?/e", "\$OC_configAR['\\1']", $OC_configAR[$setting]);
$$setting = $OC_configAR[$setting];
}
$r = mysql_query("SELECT * FROM `" . OCC_TABLE_STATUS . "`") or err('Unable to retrieve status settings', 1);
while ($l = mysql_fetch_assoc($r)) {
$OC_statusAR[$l['setting']] = $l['status'];
$$l['setting'] = $OC_statusValueAR[$l['status']]; // backward compatabiility
}
// Read in acceptance values
$OC_acceptanceValuesAR = array();
$OC_acceptanceColorAR = array();
$OC_acceptancePublishAR = array();
$r = mysql_query("SELECT * FROM `" . OCC_TABLE_ACCEPTANCE . "` ORDER BY `value`") or err('Unable to retrieve acceptance values', 1);
while ($l = mysql_fetch_assoc($r)) {
$OC_acceptanceValuesAR[] = array(
'value' => $l['value'],
'color' => $l['color'],
'publish' => $l['publish'],
'title' => $l['title']
);
$OC_acceptanceColorAR[$l['value']] = $l['color'];
if ($l['publish'] == 1) {
$OC_acceptancePublishAR[$l['value']] = $l['title'];
}
}
// Initiate session
session_name('OPENCONF');
session_start();
// Setup i18n
require_once OCC_LIB_DIR . 'locale/locale.inc';
$OC_locale = $OC_configAR['OC_localeDefault'];
$OC_localeDomain = 'OpenConf' . $OC_configAR['OC_version'];
if (isset($_GET['locale'])
&& !empty($_GET['locale'])
&& isset($OC_localeAR[$_GET['locale']])
&& preg_match("/\b" . $_GET['locale'] . "\b/", $OC_configAR['OC_locales'])
&& is_dir(OCC_LIB_DIR . 'locale/' . $_GET['locale'])
) {
$OC_locale = $_GET['locale'];
$_SESSION['OPENCONF']['locale'] = $_GET['locale'];
} elseif (isset($_SESSION['OPENCONF']['locale'])
&& preg_match("/\b" . $_SESSION['OPENCONF']['locale'] . "\b/", $OC_configAR['OC_locales'])
) {
$OC_locale = $_SESSION['OPENCONF']['locale'];
}
putenv('LANG=' . $OC_locale);
putenv('LANGUAGE=' . $OC_locale);
putenv('LC_ALL=' . $OC_locale);
if (function_exists('gettext')) {
setlocale(LC_ALL, $OC_localeAR[$OC_locale]);
bindtextdomain($OC_localeDomain, OCC_LIB_DIR . 'locale');
textdomain($OC_localeDomain);
}
/*
elseif (is_file(OCC_PLUGINS_DIR . 'php-gettext/gettext.inc')) { // use php-gettext plugin if available
require_once(OCC_PLUGINS_DIR . 'php-gettext/gettext.inc');
T_setlocale(LC_MESSAGES, $OC_localeAR[$OC_locale]);
T_bindtextdomain($OC_localeDomain, OCC_LIB_DIR . 'locale');
T_bind_textdomain_codeset($OC_localeDomain, 'UTF-8');
T_textdomain($OC_localeDomain);
}
*/
// setup modules
require_once $pfx . 'modules/module.php';
}
}
?>