made a copy
[atutor.git] / inbox / index.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg        */
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 $_user_location = 'public';
15
16 define('AT_INCLUDE_PATH', '../include/');
17 require (AT_INCLUDE_PATH.'vitals.inc.php');
18
19 if (!$_SESSION['valid_user']) {
20         require(AT_INCLUDE_PATH.'header.inc.php');
21         $msg->printInfos('INVALID_USER');
22         require(AT_INCLUDE_PATH.'footer.inc.php');
23         exit;
24 }
25
26 $_GET['view'] = intval($_GET['view']);
27
28 if ($_GET['view']) {
29         $result = mysql_query("UPDATE ".TABLE_PREFIX."messages SET new=0, date_sent=date_sent WHERE to_member_id=$_SESSION[member_id] AND message_id=$_GET[view]",$db);
30 }
31
32 if (isset($_GET['delete'])) {
33         $_GET['delete'] = intval($_GET['delete']);
34
35         if($result = mysql_query("DELETE FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] AND message_id=$_GET[delete]",$db)){
36                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
37         }
38
39         header('Location: index.php');
40         exit;
41 } else if (isset($_POST['submit_yes'], $_POST['ids'])) {
42         $ids = $addslashes($_POST['ids']);
43
44         $sql = "DELETE FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] AND message_id IN ($ids)";
45         mysql_query($sql, $db);
46
47         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
48
49         header('Location: index.php');
50         exit;
51 } else if (isset($_POST['submit_no'])) {
52         $msg->addFeedback('CANCELLED');
53
54         header('Location: index.php');
55         exit;
56 } else if (isset($_POST['delete']) && !isset($_POST['id'])) {
57         $msg->addError('NO_ITEM_SELECTED');
58         header('Location: index.php');
59         exit;
60 }
61
62 require(AT_INCLUDE_PATH.'header.inc.php');
63
64 if (isset($_GET['view']) && $_GET['view']) {
65         $sql    = "SELECT * FROM ".TABLE_PREFIX."messages WHERE message_id=$_GET[view] AND to_member_id=$_SESSION[member_id]";
66         $result = mysql_query($sql, $db);
67
68         if ($row = mysql_fetch_assoc($result)) {
69 ?>
70         <ul id="inbox-msg">
71         <li>
72                 <div class="forum-post-author">
73                         <a href="profile.php?id=<?php echo $row['from_member_id']; ?>" class="title"><?php echo get_display_name($row['from_member_id']); ?></a><br />
74                         <?php print_profile_img($row['from_member_id']); ?>
75                 </div>
76
77                 <div class="forum-post-content">
78                         <h3><?php echo AT_Print(htmlspecialchars($row['subject'], ENT_COMPAT, "UTF-8"), 'messages.subject'); ?></h3>
79                         <div>
80                                 <div class="forum-post-ctrl">
81                                         <a href="inbox/send_message.php?reply=<?php echo $_GET['view']; ?>"><?php echo _AT('reply'); ?></a> | <a href="<?php echo $_SERVER['PHP_SELF']; ?>?delete=<?php echo $_GET['view']; ?>"><?php echo _AT('delete'); ?></a>
82                                 </div>
83                                 <p class="date"><?php echo AT_date(_AT('forum_date_format'), $row['date_sent'], AT_DATE_MYSQL_DATETIME); ?></p>
84                         </div>
85
86                         <div class="body">
87                                 <p><?php echo AT_print(htmlspecialchars($row['body'], ENT_COMPAT, "UTF-8"), 'messages.body'); ?></p>
88                         </div>
89                 </div>
90
91         </li>
92         </ul><br /><br />
93         <?php
94         }
95 } else if (isset($_POST['delete'], $_POST['id'])) {
96         $hidden_vars['ids'] = implode(',', $_POST['id']);
97
98         $msg->addConfirm('DELETE_MSGS', $hidden_vars);
99         $msg->printConfirm();
100 }
101
102 $sql    = "SELECT * FROM ".TABLE_PREFIX."messages WHERE to_member_id=$_SESSION[member_id] ORDER BY date_sent DESC";
103 $result = mysql_query($sql,$db);
104 ?>
105 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form" >
106 <table class="data" summary="" rules="rows" width="55%">
107 <thead>
108 <tr>
109         <th scope="col">&nbsp;</th>
110         <th scope="col">&nbsp;</th>
111         <th scope="col" ><?php echo _AT('from');   ?></th>
112         <th scope="col" ><?php echo _AT('subject');?></th>
113         <th scope="col" ><?php echo _AT('date');   ?></th>
114 </tr>
115 </thead>
116 <tfoot>
117 <tr>
118         <td colspan="5"><input type="submit" name="delete" value="<?php echo _AT('delete'); ?>"/></td>
119 </tr>
120 </tfoot>
121 <tbody>
122 <?php if ($row = mysql_fetch_assoc($result)): ?>
123         <?php do { ?>
124                 <?php if ($row['message_id'] == $_GET['view']): ?>
125                         <tr class="selected">
126                 <?php else: ?>
127                         <tr onmousedown="document.form['m<?php echo $row['message_id']; ?>'].checked = !document.form['m<?php echo $row['message_id']; ?>'].checked; rowselectbox(this, document.form['m<?php echo $row['message_id']; ?>'].checked, '');" id="r_<?php echo $row['message_id']; ?>_1">
128                 <?php endif; ?>
129                 <td><input type="checkbox" name="id[]" value="<?php echo $row['message_id']; ?>" id="m<?php echo $row['message_id']; ?>" <?php if (isset($_POST['id']) && in_array($row['message_id'], $_POST['id'])) { echo 'checked="checked"'; } ?> title="<?php echo _AT('delete').': '.AT_print($row['subject'], 'messages.subject');?>"/></td>
130                 <td valign="middle">
131                 <?php
132                 if ($row['new'] == 1)   {
133                         echo _AT('new');
134                 } else if ($row['replied'] == 1) {
135                         echo _AT('replied');
136                 }
137                 echo '</td>';
138
139                 $name = get_display_name($row['from_member_id']);
140
141                 echo '<td align="left" valign="middle">';
142
143                 if ($_GET['view'] != $row['message_id']) {
144                         echo $name;
145                 } else {
146                         echo '<strong>'.$name.'</strong>';
147                 }
148                 echo '</td>';
149
150                 echo '<td><label for="m'.$row['message_id'].'">';
151                 if ($_GET['view'] != $row['message_id']) {
152                         echo '<a href="'.$_SERVER['PHP_SELF'].'?view='.$row['message_id'].'">'.AT_print($row['subject'], 'messages.subject').'</a>';
153                 } else {
154                         echo '<strong>'.AT_print($row['subject'], 'messages.subject').'</strong>';
155                 }
156                 echo '</label></td>';
157         
158                 echo '<td valign="middle" align="left" nowrap="nowrap">';
159                 echo AT_date(_AT('inbox_date_format'),  $row['date_sent'], AT_DATE_MYSQL_DATETIME);
160                 echo '</td>';
161                 echo '</tr>';
162         } while ($row = mysql_fetch_assoc($result)); ?>
163 <?php else: ?>
164         <tr>
165                 <td colspan="5"><?php echo _AT('none_found'); ?></td>
166         </tr>
167 <?php endif; ?>
168 </tbody>
169 </table>
170 </form>
171
172 <?php
173 // since Inbox isn't a module, it can't have a cron job.
174 // so, we delete the expires sent messages with P =  1/7.
175 if (!rand(0, 6)) {
176         $sql = "DELETE FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] AND TO_DAYS(date_sent) < (TO_DAYS(NOW()) - {$_config['sent_msgs_ttl']}) LIMIT 100";
177         mysql_query($sql, $db);
178 }
179 ?>
180
181 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>