ATutor 2.0
[atutor.git] / mods / _standard / chat / manage / index.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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: index.php 8901 2009-11-11 19:10:19Z cindy $
14
15 define('AT_INCLUDE_PATH', '../../../../include/');
16
17 $CACHE_DEBUG=0;
18 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 require(AT_INCLUDE_PATH.'../mods/_standard/chat/lib/chat.inc.php');
20
21 if (isset($_GET['view'], $_GET['file'])) {
22         header("Location:view_transcript.php?t=".$_GET['file']);
23         exit;
24 } else if ((isset($_GET['view']) || isset($_GET['delete'])) && !isset($_GET['file'])) {
25         $msg->addError('NO_ITEM_SELECTED');
26 }
27
28 $admin = getAdminSettings();
29
30 if (isset($_GET['delete'], $_GET['file'])) {
31
32         if (($_GET['file'].'.html' == $admin['tranFile']) && ($admin['produceTran'])) {
33                 $msg->addError('TRANSCRIPT_ACTIVE');
34         } else {
35                 header("Location:delete_transcript.php?m=".$_GET['file']);
36                 exit;
37         }
38 }
39 require(AT_INCLUDE_PATH.'header.inc.php');
40
41 $orders = array('asc' => 'desc', 'desc' => 'asc');
42 $cols   = array('name' => 1, 'date' => 1);
43
44 if (isset($_GET['asc'])) {
45         $order = 'asc';
46         $col   = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'date';
47 } else if (isset($_GET['desc'])) {
48         $order = 'desc';
49         $col   = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'date';
50 } else {
51         // no order set
52         $order = 'desc';
53         $col   = 'date';
54 }
55
56 $tran_files = array();
57 if (!@opendir(AT_CONTENT_DIR . 'chat/')){
58         mkdir(AT_CONTENT_DIR . 'chat/', 0777);
59 }
60
61 if(!file_exists(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings')){
62         @mkdir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'], 0777);
63         @mkdir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/', 0776);
64         @mkdir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/msgs/', 0776);
65         @mkdir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/users/', 0776);
66         @copy('admin.settings.default', AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings');
67         @chmod (AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/admin.settings', 0777);
68
69 }
70         
71 if ($dir = @opendir(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/')) {
72         while (($file = readdir($dir)) !== false) {
73                 if (substr($file, -strlen('.html')) == '.html') {
74                         $la     = stat(AT_CONTENT_DIR . 'chat/'.$_SESSION['course_id'].'/tran/'.$file);
75
76                         $file = str_replace('.html', '', $file);
77                         $tran_files[$file] = $la['ctime'];
78                 }
79         }
80 }
81
82 if (count($tran_files) == 0) {
83         echo '<div style="width:90%;" class="input-form"><p>'._AT('chat_none_found').'</p></div>';
84 } else {?>
85         
86 <form name="form" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
87
88         <table class="data" rules="cols" summary="">
89         <colgroup>
90                 <?php if ($col == 'name'): ?>
91                         <col />
92                         <col class="sort" />
93                         <col span="2" />
94                 <?php elseif($col == 'date'): ?>
95                         <col span="3" />
96                         <col class="sort" />
97                 <?php endif; ?>
98         </colgroup>
99         <thead>
100         <tr>
101                 <th scope="col">&nbsp;</th>
102                 <th scope="col"><a href="mods/_standard/chat/index.php?<?php echo $orders[$order]; ?>=name"><?php echo _AT('chat_transcript');?></a></th>
103                 <th scope="col"><?php echo _AT('status'); ?></th>
104                 <th scope="col"><a href="mods/_standard/chat/index.php?<?php echo $orders[$order]; ?>=date"><?php echo _AT('date'); ?></a></th> 
105                 </th> 
106         </tr>
107         </thead>
108         <?php
109
110         if (($col == 'date') && ($order == 'asc')) {
111                 asort($tran_files);
112         } else if (($col == 'date') && ($order == 'desc')) {
113                 arsort($tran_files);
114         } else if (($col == 'name') && ($order == 'asc')) {
115                 ksort($tran_files);
116         } else if (($col == 'name') && ($order == 'desc')) {
117                 krsort($tran_files);
118         }
119         reset ($tran_files);
120         ?>
121
122         <tbody>
123         <?php foreach ($tran_files as $file => $date) { ?>
124                 <tr onmousedown="document.form['<?php echo $file; ?>'].checked = true; rowselect(this);" id="r_<?php echo $file; ?>">
125                         <td><input type="radio" name="file" value="<?php echo $file; ?>" id="<?php echo $file; ?>" /></td>
126
127                         <td><label for="<?php echo $file; ?>"><?php echo $file; ?></label></td>
128                         <td>
129                                 <?php if (($file.'.html' == $admin['tranFile']) && ($admin['produceTran'])) { 
130                                         echo _AT('chat_currently_active');
131                                 } else {
132                                         echo _AT('chat_inactive');
133                                 }?>
134                         </td>
135         
136                         <td><?php echo AT_DATE(_AT('server_date_format'), $date); ?></td>
137                 </tr>
138         <?php } ?>
139         </tbody>
140
141         <tfoot>
142         <tr>
143                 <td colspan="4"><input type="submit" name="view" value="<?php echo _AT('view'); ?>" /> <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" /></td>
144         </tr>
145         </tfoot>
146
147         </table>
148 </form>
149 <?php
150 }
151
152 require(AT_INCLUDE_PATH.'footer.inc.php'); ?>