2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 /* @See ./admin.php */
20 function writeAdminSettings(&$admin) {
21 if (file_exists(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings')) {
22 chmod(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings', 0755);
25 $fp = @fopen(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings', 'w+');
32 foreach ($admin as $prefKey => $prefValue) {
33 $settings .= $prefKey.'='.$prefValue."\n";
37 if (!@fwrite($fp, $settings)) {
41 chmod(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings', 0600);
46 function getAdminSettings() {
47 if (!file_exists(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings')) {
53 $file_prefs = file(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings');
54 foreach ($file_prefs as $pref) {
55 $pref = explode('=', $pref, 2);
56 $admin[$pref[0]] = trim($pref[1]);
59 if ($admin['returnT'] && $admin['returnL']) {
60 $admin['returnLink'] = '<a href="'.$admin['returnL'].'" onFocus="this.className=\'highlight\'" onBlur="this.className=\'\'">'.$admin['returnT'].'</a>';
62 $admin['returnLink'] = '';
68 function defaultAdminSettings() {
71 //$admin['cgiURL'] = 'http://dev.atutor.ca/chat/';
72 //$admin['htmlDir'] = '/usr/webserver/content/snow/chat/';
73 //$admin['htmlURL'] = 'http://dev.atutor.ca/discussions/achat/';
74 $admin['msgLifeSpan'] = 1800; /* 30 min */
75 $admin['chatIDLifeSpan'] = 2678400; /* 1 month */
76 $admin['chatSessionLifeSpan'] = 3600; /* 1 hour */
77 //$admin['chatName'] = 'Accessible Chat';
78 //$admin['chatIDListFlag'] = 0;
79 // $admin['returnL'] = 'http://dev.atutor.ca';
80 //$admin['returnT'] = 'Return to the ATRC';
81 //$admin['adminPass'] = 'temppass';
86 $admin = getAdminSettings();
88 $admin = defaultAdminSettings();
91 if (isset($_POST['submit'])) {
92 $admin['adminPass'] = $_POST['newAdminPass'];
93 $adminPass = $_POST['newAdminPass'];
94 $admin['chatName'] = $_POST['chatName'];
95 $admin['returnL'] = $_POST['returnL'];
96 $admin['returnT'] = $_POST['returnT'];
97 $admin['msgLifeSpan'] = $_POST['msgLifeSpan'];
98 $admin['chatSessionLifeSpan'] = $_POST['chatSessionLifeSpan'];
99 $admin['chatIDLifeSpan'] = $_POST['chatIDLifeSpan'];
100 writeAdminSettings($admin);
102 } else if (isset($_POST['submit2'])) {
103 @mkdir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'] . '/tran');
104 if(file_exists(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/'.$_POST['tranFile'].'.html')){
105 $warnings = array('CHAT_TRAN_EXISTS', $_POST['tranFile']); //'file already exists';
106 $msg->addWarning($warnings);
107 } else if ($_POST['function'] == 'startTran') {
108 if (!(eregi("^[a-zA-Z0-9_]([a-zA-Z0-9_])*$", $_POST['tranFile']))){
109 $msg->addError('CHAT_TRAN_REJECTED');
111 $admin['produceTran'] = 1;
112 $admin['tranFile'] = $_POST['tranFile'] . '.html';
113 writeAdminSettings($admin);
114 $tran = '<p>'._AT('chat_transcript_start').' '.date('Y-M-d H:i').'</p>';
115 $tran .= '<table border="0" cellpadding="3" summary="" class="chat-transcript">';
117 $fp = fopen(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/'.$admin['tranFile'], 'w+');
120 if (!fwrite($fp, $tran)) {
125 header('Location: index.php');
128 } else if ($_POST['function'] == 'stopTran') {
129 $admin['produceTran'] = 0;
130 writeAdminSettings($admin);
132 $tran = '<p>'._AT('chat_transcript_end').' '.date('Y-M-d H:i').'</p>';
133 $fp = @fopen(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/'.$admin['tranFile'], 'a');
135 @flock($fp, LOCK_EX);
136 if (!@fwrite($fp, $tran)) {
141 header('Location: index.php');
144 } else if ($_GET['function'] == 'clearOldChatIDs') {
145 $return = clearOutOldChatPrefs();
146 } else if ($_POST['submit3']) {
147 deleteUser($_POST['delName']);
148 } else if ($_POST['submit4']) {
149 if ($dir = @opendir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/users/')) {
150 while (($file = readdir($dir)) !== false) {
151 if (substr($file, -strlen('.prefs')) == '.prefs') {
152 $chatName = substr($file, 0, -strlen('.prefs'));
153 deleteUser($chatName);
160 require(AT_INCLUDE_PATH.'header.inc.php');
163 echo '<code>'.$return.'</code>';
166 if ($admin['msgLifeSpan'] < 650) {
168 } else if ($admin['msgLifeSpan'] < 950) {
170 } else if ($admin['msgLifeSpan'] < 1850) {
172 } else if ($admin['msgLifeSpan'] < 10850) {
173 $m180 = ' selected ';
178 if ($admin['chatSessionLifeSpan'] < 650) {
180 } else if ($admin['chatSessionLifeSpan'] < 950) {
182 } else if ($admin['chatSessionLifeSpan'] < 1850) {
184 } else if ($admin['chatSessionLifeSpan'] < 10850) {
185 $s180 = ' selected ';
189 if ($admin['chatIDLifeSpan'] < 86450) {
191 } else if ($admin['chatIDLifeSpan'] < 1728050) {
192 $i20D = ' selected ';
193 } else if ($admin['chatIDLifeSpan'] < 2592050) {
200 <form name="f1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
201 <div class="input-form">
203 <?php echo _AT('chat_keep_tran'); ?>
207 echo '<input type="hidden" name="adminPass" value="'.$adminPass.'" />';
209 if ($admin['produceTran'] > 0) {
210 echo '<input type="hidden" name="function" value="stopTran" />';
211 echo '<div class="row">';
212 echo _AT('chat_current_tran').' <a href="tools/chat/view_transcript.php?t='.str_replace('.html', '', $admin['tranFile']).'" >'.str_replace('.html', '', $admin['tranFile']).'</a>.</p>';
215 echo '<div class="row buttons">';
216 echo '<input type="submit" value="'._AT('chat_stop_tran').'" name="submit2" />';
220 echo '<input type="hidden" name="function" value="startTran" />';
222 echo '<div class="row">';
223 echo _AT('chat_tran_file_name').' ';
224 echo '<input type="text" name="tranFile" class="formfield" />';
227 echo '<div class="row buttons">';
228 echo '<input type="submit" value="'._AT('chat_start_tran').'" name="submit2" />';
234 require(AT_INCLUDE_PATH.'footer.inc.php');