remove old readme
[atutor.git] / docs / mods / _standard / chat / display.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
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 session_write_close();
17 //authenticate(USER_CLIENT, USER_ADMIN);
18 require(AT_INCLUDE_PATH.'../mods/_standard/chat/lib/chat.inc.php');
19
20         $myPrefs = getPrefs($_SESSION['login']);
21
22         cleanUp();
23
24         howManyMessages($topMsgNum, $bottomMsgNum);
25
26         if ($_REQUEST['set']) {
27                 if (isset($_GET['set'])) {
28                         if ($_GET['set'] == $_POST['message']) {
29                                 $tmp_message = $_POST['tempField'];
30                         } else {
31                                 $tmp_message = $_POST['message'];
32                         }
33                 } else {
34                         $tmp_message = $_POST['message'];
35                 }
36                 //$message = $_POST['message'];
37                 postMessage($_SESSION['login'], $tmp_message, $topMsgNum, $bottomMsgNum);
38         } else if ($_REQUEST['firstLoginFlag'] > 0) {
39         postMessage(_AT('chat_system'), _AT('chat_user_logged_in', $_SESSION['login']), $topMsgNum, $bottomMsgNum);
40     }
41
42 require('include/html/chat_header.inc.php');
43         if ($myPrefs['refresh'] != 'manual') {
44 ?>
45         <script language="javascript" type="text/javascript">
46         <!--
47                 setTimeout("reDisplay()", <?php echo $myPrefs['refresh'] * 1000; ?>);
48                 function reDisplay() {
49                         window.location.href = "<?php echo $_SERVER[PHP_SELF]; ?>";
50                 }
51         //-->
52         </script>
53 <?php
54         } /* end if */
55 ?>
56 <a name="messages"></a>
57 <table width="100%" border="0" cellpadding="5" cellspacing="0">
58 <tr>
59         <th align="left"><?php echo _AT('chat_messages') ?></th>
60 </tr>
61 </table>
62
63 <?php
64         $min = 1;
65         if ($topMsgNum - 10 > 1) {
66                 $min = $topMsgNum - 10;
67         }
68         if ($myPrefs['onlyNewFlag'] > 0) {
69                 $min = $myPrefs['lastRead'] +1;
70         }
71         if ($min <= $topMsgNum) {
72            echo '<table border="0" cellpadding="2" cellspacing="0" width="98%" class="chat-display" align="center">';
73         } else {
74            echo '<p>'._AT('chat_no_new_messages').'</p>';
75         }
76
77         if ($myPrefs['newestFirstFlag'] > 0) {
78         for ($i = $topMsgNum; $i >= $min; $i--) {
79             showMessage($i, $myPrefs);
80         }
81     } else {
82         for ($i = $min; $i <= $topMsgNum ; $i++) {
83             showMessage($i, $myPrefs);
84         }
85     }
86
87     if ($min <= $topMsgNum) {
88                 echo '</table>';
89         }
90
91         echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">';
92         echo '<tr>';
93         echo '<td align="right">';
94     if ($myPrefs['navigationAidFlag'] > 0) {    
95                 echo '<a accesskey="m" href="display.php#messages" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'" title="'._AT('chat_jump_to_message').' Alt-m">'._AT('chat_jump_to_message').'</a> | ';
96         }
97
98         echo '<a accesskey="r" href="display.php" target="display" onfocus="this.className=\'highlight\'" onblur="this.className=\'\'" title="'._AT('chat_refresh_message').' Alt-r">'._AT('chat_refresh_message').'</a>';
99         echo '</td></tr>';
100         echo '</table>';
101     
102     echo '<br /><br />';
103     if ($myPrefs['refresh'] == 'manual') {
104                 echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
105            <tr><th align="left">'._AT('chat_compose_message').'</th></tr></table>';
106                 echo '<p>';
107
108                 echo '<form action="display.php" target="display" name="f1" method="post" onSubmit="return checkForm();">
109                            <input type="hidden" name="set" value="1" />
110                            <label accesskey="c" for="message"><input type="text" maxlength="200" size="50" id="message" name="message" value="" class="input" title="Alt-c" onfocus="this.className=\'input highlight\'" onblur="this.className=\'input\'" /></label>
111                            <input type="submit" name="submit" value="'._AT('send').'" class="button" title="'._AT('send').'" onfocus="this.className=\'submit highlight\'" onblur="this.className=\'submit\'" />';
112
113                 echo '</form></p>';
114                 echo '<script language="javascript"><!--
115                            function checkForm() {
116                                    if (document.f1.message.value == "" || !document.f1.message.value) return false;
117                                    return true;
118                            }';
119                 echo '//--></script>';
120     } else {
121         if ($myPrefs['bingFlag'] > 0 && $topMsgNum > $myPrefs['lastRead']) {
122             echo '<embed src="bings/chime.wav" loop="false" autoplay="true" play="true" hidden="true" width="1" height="1" />';
123         }
124         } 
125
126     $myPrefs['lastRead']        = $topMsgNum;
127     $myPrefs['lastChecked']     = $topMsgNum;
128     writePrefs($myPrefs, $_SESSION['login']);
129         require('include/html/chat_footer.inc.php');
130 ?>