made a copy
[atutor.git] / tools / chat / start_transcript.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
7 /* http://atutor.ca                                                                                                             */
8 /*                                                                                                                                              */
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 /************************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17
18
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);
23         }
24
25         $fp = @fopen(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings', 'w+');
26         if (!$fp) {
27                 // error
28                 return 0;
29         }
30
31         $settings = '';
32         foreach ($admin as $prefKey => $prefValue) {
33                 $settings .= $prefKey.'='.$prefValue."\n";
34         }
35
36         flock($fp, LOCK_EX);
37         if (!@fwrite($fp, $settings)) {
38                 return 0;
39         }
40         flock($fp, LOCK_UN);
41         chmod(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings', 0600);
42
43         return 1;
44 }
45
46 function getAdminSettings() {
47         if (!file_exists(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings')) {
48                 return 0;
49         }
50
51         $admin = array();
52
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]);
57         }
58
59     if ($admin['returnT'] && $admin['returnL']) {
60         $admin['returnLink'] = '<a href="'.$admin['returnL'].'" onFocus="this.className=\'highlight\'" onBlur="this.className=\'\'">'.$admin['returnT'].'</a>';
61     } else {
62         $admin['returnLink'] = '';
63     }
64
65         return $admin;
66 }
67
68 function defaultAdminSettings() {
69         $admin = array();
70
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';
82
83         return $admin;
84 }
85
86 $admin = getAdminSettings();
87 if ($admin === 0) {
88         $admin = defaultAdminSettings();
89 }
90
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);
101
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');
110                 } else {
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">';
116                                 
117                         $fp = fopen(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/'.$admin['tranFile'], 'w+');
118
119                         flock($fp, LOCK_EX);
120                         if (!fwrite($fp, $tran)) {
121                                 return 0;
122                         }
123                         flock($fp, LOCK_UN);
124
125                         header('Location: index.php');
126                         exit;
127                 }
128         } else if ($_POST['function'] == 'stopTran') {
129                 $admin['produceTran'] = 0;
130                 writeAdminSettings($admin);
131                         
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');
134
135                 @flock($fp, LOCK_EX); 
136                 if (!@fwrite($fp, $tran)) {
137                         return 0;
138                 }
139                 flock($fp, LOCK_UN);
140
141                 header('Location: index.php');
142                 exit;
143         }
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);
154                         }
155                 }
156         }
157 }
158
159
160 require(AT_INCLUDE_PATH.'header.inc.php');
161
162         if ($return != '') {
163                 echo '<code>'.$return.'</code>';
164         }
165         
166         if ($admin['msgLifeSpan'] < 650) {
167         $m10 = ' selected ';
168     } else if ($admin['msgLifeSpan'] < 950) {
169         $m30 = ' selected ';
170     } else if ($admin['msgLifeSpan'] < 1850) {
171         $m60 = ' selected ';
172     } else if ($admin['msgLifeSpan'] < 10850) {
173         $m180 = ' selected ';
174     } else {
175         $m1D = ' selected ';
176     }
177
178     if ($admin['chatSessionLifeSpan'] < 650) {
179         $s10 = ' selected ';
180     } else if ($admin['chatSessionLifeSpan'] < 950) {
181         $s30 = ' selected ';
182     } else if ($admin['chatSessionLifeSpan'] < 1850) {
183         $s60 = ' selected ';
184     } else if ($admin['chatSessionLifeSpan'] < 10850) {
185         $s180 = ' selected ';
186     } else {
187         $s1D = ' selected ';
188     }
189     if ($admin['chatIDLifeSpan'] < 86450) {
190         $i1D = ' selected ';
191     } else if ($admin['chatIDLifeSpan'] < 1728050) {
192         $i20D = ' selected ';
193     } else if ($admin['chatIDLifeSpan'] < 2592050) {
194         $i1M = ' selected ';
195     } else {
196         $i1Y = ' selected ';
197     } 
198 ?>
199
200 <form name="f1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
201 <div class="input-form">
202         <div class="row">
203                 <?php echo _AT('chat_keep_tran'); ?>
204         </div>
205
206 <?php
207         echo '<input type="hidden" name="adminPass" value="'.$adminPass.'" />';
208
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>';
213                 echo '</div>';
214
215                 echo '<div class="row buttons">';
216                 echo '<input type="submit" value="'._AT('chat_stop_tran').'" name="submit2" />';
217                 echo '</div>';
218
219     } else {
220         echo '<input type="hidden" name="function" value="startTran" />';
221
222                 echo '<div class="row">';
223                         echo _AT('chat_tran_file_name').' ';
224                         echo '<input type="text" name="tranFile" class="formfield" />';
225                 echo '</div>';          
226
227                 echo '<div class="row buttons">';
228                 echo '<input type="submit" value="'._AT('chat_start_tran').'" name="submit2" />';
229                 echo '</div>';
230     }
231         echo '</div>';
232         echo '</form>';
233         
234         require(AT_INCLUDE_PATH.'footer.inc.php');
235 ?>