<?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 356 2005-02-04 19:16:57Z shozubq $
define('AC_INCLUDE_PATH', '../include/');
require(AC_INCLUDE_PATH.'vitals.inc.php');
authenticate(USER_GROUP_ADMIN);
/* @See ./admin.php */
function writeAdminSettings(&$admin) {
if (file_exists('../chat/'.$_SESSION['group_id'].'.admin.settings')) {
@chmod('../chat/'.$_SESSION['group_id'].'admin.settings', 0755);
}
$fp = @fopen('../chat/'.$_SESSION['group_id'].'.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/'.$_SESSION['group_id'].'.admin.settings', 0600);
return 1;
}
function getAdminSettings() {
if (!file_exists('../chat/'.$_SESSION['group_id'].'.admin.settings')) {
touch('../chat/'.$_SESSION['group_id'].'.admin.settings');
}
$admin = array();
$file_prefs = @file('../chat/'.$_SESSION['group_id'].'.admin.settings');
if (is_array($file_prefs)) {
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'] = $_POST['newAdminPass'];
$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/'.$_SESSION['group_id'].'/'.$_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">';
@mkdir('../chat/tran/'.$_SESSION['group_id']);
$fp = @fopen('../chat/tran/'.$_SESSION['group_id'].'/'.$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/'.$_SESSION['group_id'].'/'.$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);
}
}
}
}
if (authenticate(USER_ADMIN, USER_RETURN_CHECK)) {
$group_info = get_group($_SESSION['group_id']);
$_SECTION[0][0] = _AC('administration');
$_SECTION[0][1] = 'admin/index.php';
$_SECTION[1][0] = _AC('groups');
$_SECTION[1][1] = 'admin/groups.php';
$_SECTION[2][0] = $group_info['title'];
$_SECTION[2][1] = 'group_admin/index.php';
$_SECTION[3][0] = _AC('chat_settings');
$_SECTION[3][1] = 'group_admin/chat.php';
require(AC_INCLUDE_PATH.'admin/header.inc.php');
} else {
$_SECTION[0][0] = _AC('home');
$_SECTION[0][1] = 'home.php';
$_SECTION[1][0] = _AC('administration');
$_SECTION[1][1] = 'group_admin/';
$_SECTION[2][0] = _AC('chat_settings');
$_SECTION[2][1] = 'group_admin/chat.php';
require(AC_INCLUDE_PATH.'header.inc.php');
}
if (isset($errors)) {
print_errors($errors);
unset($errors);
}
if ($return != '') {
echo '<code>'.$return.'</code>';
}
if ($admin['msgLifeSpan'] < 650) {
$m10 = ' selected="selected" ';
} else if ($admin['msgLifeSpan'] < 950) {
$m30 = ' selected="selected" ';
} else if ($admin['msgLifeSpan'] < 1850) {
$m60 = ' selected="selected" ';
} else if ($admin['msgLifeSpan'] < 10850) {
$m180 = ' selected="selected" ';
} else {
$m1D = ' selected="selected" ';
}
if ($admin['chatSessionLifeSpan'] < 650) {
$s10 = ' selected="selected" ';
} else if ($admin['chatSessionLifeSpan'] < 950) {
$s30 = ' selected="selected" ';
} else if ($admin['chatSessionLifeSpan'] < 1850) {
$s60 = ' selected="selected" ';
} else if ($admin['chatSessionLifeSpan'] < 10850) {
$s180 = ' selected="selected" ';
} else {
$s1D = ' selected="selected" ';
}
if ($admin['chatIDLifeSpan'] < 86450) {
$i1D = ' selected="selected" ';
} else if ($admin['chatIDLifeSpan'] < 1728050) {
$i20D = ' selected="selected" ';
} else if ($admin['chatIDLifeSpan'] < 2592050) {
$i1M = ' selected="selected" ';
} else {
$i1Y = ' selected="selected" ';
}
?>
<h3><?php echo _AC('transcripts'); ?></h3>
<p><?php echo _AC('keep_tran'); ?></p>
<?php
if ($admin['produceTran'] > 0) {
echo '<p>'._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>';
} 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>';
}
if ($admin['tranFile'] && $admin['produceTran'] < 1) {
echo '<p>'._AC('last_tran').':
<a href="chat/tran/'.$_SESSION['group_id'].'/'.$admin['tranFile'].'" target="_new" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'">tran/'.$_SESSION['group_id'].'/'.$admin['tranFile'].'</a>.</p>';
}
echo '<form name="f1" method="post" action="' . $_SERVER['PHP_SELF'] . '">';
echo '<input type="hidden" name="adminPass" value="'.$adminPass.'" />';
echo '<br /><p>'._AC('message_life_details').'<br />';
echo '<b>'._AC('message_lifespan').':</b>';
echo '<select name="msgLifeSpan">';
echo '<option value="600" ' . $m10 . ' >10 minutes</option>';
echo '<option value="900" ' . $m30 . ' >30 minutes</option>';
echo '<option value="1800" ' . $m60 . ' >60 minutes</option>';
echo '<option value="10800" ' . $m180 . ' >180 minutes</option>';
echo '<option value="86400" ' . $m1D . ' >1 day</option>';
echo '</select></p>';
echo '<p>'._AC('session_life_details').'<br />';
echo '<b>'._AC('session_lifespan').':</b>';
echo '<select name="chatSessionLifeSpan">';
echo '<option value="600" ' . $s10 . ' >10 minutes</option>';
echo '<option value="900" ' . $s30 . ' >30 minutes</option>';
echo '<option value="1800" ' . $s60 . ' >60 minutes</option>';
echo '<option value="10800" ' . $s180 . ' >180 minutes</option>';
echo '<option value="86400" ' . $s1D . ' >1 day</option>';
echo '</select></p>';
echo '<p>'._AC('chatid_life_details').'<br />';
echo '<b>'._AC('chatid_lifespan').':</b>';
echo '<select name="chatIDLifeSpan">';
echo '<option value="86400" ' . $i1D . ' >1 Day</option>';
echo '<option value="1728000" ' . $i20D . ' >20 Days</option>';
echo '<option value="2592000" ' . $i1M . ' >1 Month</option>';
echo '<option value="31104000" ' . $i1Y . ' >12 Months</option>';
echo '</select></p>';
echo '<p align="center"><input type="submit" value="'._AC('submit').'" name="submit" class="submitY" /> - ';
echo '<input type="reset" value="'._AC('reset').'" class="submitN" /></form></p>';
require(AC_INCLUDE_PATH.'footer.inc.php');
?>