<?php
/****************************************************************************************/
/* ACollab */
/****************************************************************************************/
/* Copyright (c) 2002-2004 Adaptive Technology Resource Centre / University of Toronto */
/* */
/* http://atutor.ca/acollab */
/* */
/* This program is free software. You may 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. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* See the GNU General Public License for more details. */
/* */
/* You may access the GNU General Public License at: */
/* http://www.opensource.org/licenses/gpl-license.php */
/* */
/* You may contact the Adaptive Technology Resource Centre at */
/* Robarts Library, University of Toronto */
/* 130 St. George Street, Toronto, Ontario, Canada M5S 1A5 */
/* Further contact information is available at http://www.utoronto.ca/atrc/ */
/****************************************************************************************/
/* Programmer: */
/* Joel Kronenberg - ATRC */
/****************************************************************************************/
// $Id: chat.php 235 2004-06-07 19:55:47Z boonhau $
define('AC_INCLUDE_PATH', '../include/');
require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_ADMIN);
$_SECTION[0][0] = _AC('administration');
$_SECTION[0][1] = 'admin/';
$_SECTION[1][0] = _AC('chat_settings');
$_SECTION[1][1] = 'admin/chat.php';
/* @See ./admin.php */
function writeAdminSettings(&$admin) {
if (file_exists('../chat/admin.settings')) {
chmod('../chat/admin.settings', 0755);
}
$fp = @fopen('../chat/admin.settings', 'w+');
if (!$fp) {
// error
return 0;
}
$settings = '';
foreach ($admin as $prefKey => $prefValue) {
$settings .= $prefKey.'='.$prefValue."\n";
}
flock($fp, LOCK_EX);
if (!@fwrite($fp, $settings)) {
return 0;
}
flock($fp, LOCK_UN);
chmod('../chat/admin.settings', 0600);
return 1;
}
function getAdminSettings() {
if (!file_exists('../chat/admin.settings')) {
return 0;
}
$admin = array();
$file_prefs = file('../chat/admin.settings');
foreach ($file_prefs as $pref) {
$pref = explode('=', $pref, 2);
$admin[$pref[0]] = trim($pref[1]);
}
if ($admin['returnT'] && $admin['returnL']) {
$admin['returnLink'] = '<a href="'.$admin['returnL'].'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.$admin['returnT'].'</a>';
} else {
$admin['returnLink'] = '';
}
return $admin;
}
$admin = getAdminSettings();
if ($admin === 0) {
$admin = defaultAdminSettings();
}
if ($_POST['submit']) {
$admin['adminPass']= $adminPass = $_POST['newAdminPass'];
$admin['chatName'] = $_POST['chatName'];
$admin['returnL'] = $_POST['returnL'];
$admin['returnT'] = $_POST['returnT'];
$admin['msgLifeSpan'] = $_POST['msgLifeSpan'];
$admin['chatSessionLifeSpan'] = $_POST['chatSessionLifeSpan'];
$admin['chatIDLifeSpan'] = $_POST['chatIDLifeSpan'];
writeAdminSettings($admin);
} else if ($_POST['submit2']) {
if ($_POST['function'] == 'startTran') {
if (!(eregi("^[a-zA-Z0-9_]([a-zA-Z0-9_])*$", $_POST['tranFile']))){
$errors[] = E_CHAT_TRAN;
} else {
/* check if this file already exists */
if (is_file('../chat/tran/'.$_POST['tranFile'].'.html')) {
$errors[] = E_CHAT_TRAN_EXIST;
} else {
$admin['produceTran'] = 1;
$admin['tranFile'] = $_POST['tranFile'] . '.html';
writeAdminSettings($admin);
$tran = '<h4>Transcript</h4>';
$tran .= '<p>Transcript Start: '.date('Y-M-d H:i').'</p>';
$tran .= '<table border="1" cellpadding="3">';
$fp = @fopen('../chat/tran/'.$admin['tranFile'], 'w+');
@flock($fp, LOCK_EX);
if (!@fwrite($fp, $tran)) {
return 0;
}
@flock($fp, LOCK_UN);
}
}
} else if ($_POST['function'] == 'stopTran') {
$admin['produceTran'] = 0;
writeAdminSettings($admin);
$tran = '</table><p>Transcript End: '.date('Y-M-d H:i').'</p>';
$fp = @fopen('../chat/tran/'.$admin['tranFile'], 'a');
@flock($fp, LOCK_EX);
if (!@fwrite($fp, $tran)) {
return 0;
}
flock($fp, LOCK_UN);
}
} else if ($_GET['function'] == 'clearOldChatIDs') {
$return = clearOutOldChatPrefs();
} else if ($_POST['submit3']) {
deleteUser($_POST['delName']);
} else if ($_POST['submit4']) {
if ($dir = @opendir('users/')) {
while (($file = readdir($dir)) !== false) {
if (substr($file, -strlen('.prefs')) == '.prefs') {
$chatName = substr($file, 0, -strlen('.prefs'));
deleteUser($chatName);
}
}
}
}
require(AC_INCLUDE_PATH.'admin/header.inc.php');
if (isset($errors)) {
print_errors($errors);
unset($errors);
}
if ($return != '') {
echo '<code>'.$return.'</code>';
}
if ($admin['msgLifeSpan'] < 650) {
$m10 = ' selected ';
} else if ($admin['msgLifeSpan'] < 950) {
$m30 = ' selected ';
} else if ($admin['msgLifeSpan'] < 1850) {
$m60 = ' selected ';
} else if ($admin['msgLifeSpan'] < 10850) {
$m180 = ' selected ';
} else {
$m1D = ' selected ';
}
if ($admin['chatSessionLifeSpan'] < 650) {
$s10 = ' selected ';
} else if ($admin['chatSessionLifeSpan'] < 950) {
$s30 = ' selected ';
} else if ($admin['chatSessionLifeSpan'] < 1850) {
$s60 = ' selected ';
} else if ($admin['chatSessionLifeSpan'] < 10850) {
$s180 = ' selected ';
} else {
$s1D = ' selected ';
}
if ($admin['chatIDLifeSpan'] < 86450) {
$i1D = ' selected ';
} else if ($admin['chatIDLifeSpan'] < 1728050) {
$i20D = ' selected ';
} else if ($admin['chatIDLifeSpan'] < 2592050) {
$i1M = ' selected ';
} else {
$i1Y = ' selected ';
}
?>
<h3><?php echo _AC('transcripts'); ?></h3>
<form name="f1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><?php echo _AC('keep_tran'); ?><br /><br />
<?php
if ($admin['produceTran'] > 0) {
echo _AC('current_tran').' <a href="chat/tran.php?t='.str_replace('.html', '', $admin['tranFile']).'" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">'.str_replace('.html', '', $admin['tranFile']).'</a></p>';
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="f8" style="margin: 0;">';
echo '<input type="hidden" name="function" value="stopTran" />';
echo '<input type="hidden" name="adminPass" value="'.$adminPass.'" />';
echo '<input type="submit" value="'._AC('stop_tran').'" name="submit2" class="submitY" /></form></p>';
} else {
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="f9" style="margin: 0;">';
echo '<input type="hidden" name="function" value="startTran" />';
echo '<input type="hidden" name="adminPass" value="'.$adminPass.'" />';
echo _AC('tran_file_name').': ';
echo '<input type="text" name="tranFile" class="input" value="'.$_POST['tranFile'].'" />';
echo '<input type="submit" value="'._AC('start_tran').'" name="submit2" class="submitY" /></form></p>';
}
if ($admin['tranFile'] && $admin['produceTran'] < 1) {
echo '<p>'._AC('last_tran').': <a href="chat/tran/'.$admin['tranFile'].'" target="_new" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">tran/'.$admin['tranFile'].'</a>.</p>';
}
require(AC_INCLUDE_PATH.'admin/footer.inc.php');
?>