tagging as ATutor 1.5.4-release
[atutor.git] / inbox / sent_messages.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 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['delete']) {
29         $_GET['delete'] = intval($_GET['delete']);
30
31         if($result = mysql_query("DELETE FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] AND message_id=$_GET[delete]",$db)){
32                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
33         }
34
35         header('Location: '.$_SERVER['PHP_SELF']);
36         exit;
37 } else if (isset($_POST['submit_yes'], $_POST['ids'])) {
38         $ids = $addslashes($_POST['ids']);
39
40         $sql = "DELETE FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] AND message_id IN ($ids)";
41         mysql_query($sql, $db);
42
43         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
44
45         header('Location: '.$_SERVER['PHP_SELF']);
46         exit;
47 } else if (isset($_POST['submit_no'])) {
48         $msg->addFeedback('CANCELLED');
49
50         header('Location: '.$_SERVER['PHP_SELF']);
51         exit;
52 } else if (isset($_POST['move'])) {
53         $_POST['id'][] = 0; // to make it non-empty
54         $_POST['id'] = implode(',', $_POST['id']);
55         $ids = $addslashes($_POST['id']);
56
57         $sql = "INSERT INTO ".TABLE_PREFIX."messages SELECT 0, course_id, from_member_id, {$_SESSION['member_id']}, date_sent, 0, 0, subject, body FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] AND message_id IN ($ids)";
58         mysql_query($sql, $db);
59
60         $sql = "DELETE FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] AND message_id IN ($ids)";
61         mysql_query($sql, $db);
62
63         $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
64
65         header('Location: '.$_SERVER['PHP_SELF']);
66         exit;
67 }
68
69 require(AT_INCLUDE_PATH.'header.inc.php');
70
71 if (isset($_GET['view']) && $_GET['view']) {
72         $sql    = "SELECT * FROM ".TABLE_PREFIX."messages_sent WHERE message_id=$_GET[view] AND from_member_id=$_SESSION[member_id]";
73         $result = mysql_query($sql, $db);
74
75         if ($row = mysql_fetch_assoc($result)) {
76 ?>
77         <ul id="inbox-msg">
78         <li>
79                 <div class="forum-post-author">
80                         <a href="profile.php?id=<?php echo $row['to_member_id']; ?>" class="title"><?php echo get_display_name($row['to_member_id']); ?></a><br />
81                         <?php print_profile_img($row['to_member_id']); ?>
82                 </div>
83
84                 <div class="forum-post-content">
85                         <h3><?php echo AT_Print($row['subject'], 'messages.subject'); ?></h3>
86                         <div>
87                                 <div class="forum-post-ctrl">
88                                         <a href="inbox/send_message.php?forward=<?php echo $_GET['view']; ?>"><?php echo _AT('forward'); ?></a> | <a href="<?php echo $_SERVER['PHP_SELF']; ?>?delete=<?php echo $_GET['view']; ?>"><?php echo _AT('delete'); ?></a>
89                                 </div>
90                                 <p class="date"><?php echo AT_date(_AT('forum_date_format'), $row['date'], AT_DATE_MYSQL_DATETIME); ?></p>
91                         </div>
92
93                         <div class="body">
94                                 <p><?php echo AT_print($row['body'], 'messages.body'); ?></p>
95                         </div>
96                         <div style="clear: both; font-size:0.1em"></div>
97                 </div>
98         </div>
99         </li>
100         </ul>
101         <?php
102         }
103 } else if (isset($_POST['delete'], $_POST['id'])) {
104         $hidden_vars['ids'] = implode(',', $_POST['id']);
105
106         $msg->addConfirm('DELETE_MSGS', $hidden_vars);
107         $msg->printConfirm();
108 }
109
110 $msg->printInfos(array('INBOX_SENT_MSGS_TTL', $_config['sent_msgs_ttl']));
111
112 $sql    = "SELECT * FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] ORDER BY date_sent DESC";
113 $result = mysql_query($sql,$db);
114 ?>
115
116 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
117 <table class="data" summary="" rules="rows">
118 <thead>
119 <tr>
120         <th scope="col">&nbsp;</th>
121         <th scope="col" ><?php echo _AT('to');   ?></th>
122         <th scope="col" ><?php echo _AT('subject');?></th>
123         <th scope="col" ><?php echo _AT('date');   ?></th>
124 </tr>
125 </thead>
126 <tfoot>
127 <tr>
128         <td colspan="4">
129                 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>"/>
130                 <input type="submit" name="move" value="<?php echo _AT('move_to_inbox'); ?>"/>
131         </td>
132 </tr>
133 </tfoot>
134 <tbody>
135 <?php if ($row = mysql_fetch_assoc($result)): ?>
136         <?php do { ?>
137                 <?php if ($row['message_id'] == $_GET['view']): ?>
138                         <tr class="selected">
139                 <?php else: ?>
140                         <tr>
141                 <?php endif; ?>
142                 <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>
143                 <?php
144
145                 $name = get_display_name($row['to_member_id']);
146
147                 echo '<td align="left" valign="middle">';
148
149                 if ($_GET['view'] != $row['message_id']) {
150                         echo $name;
151                 } else {
152                         echo '<strong>'.$name.'</strong>';
153                 }
154                 echo '</td>';
155
156                 echo '<td>';
157                 if ($_GET['view'] != $row['message_id']) {
158                         echo '<a href="'.$_SERVER['PHP_SELF'].'?view='.$row['message_id'].'">'.AT_print($row['subject'], 'messages.subject').'</a>';
159                 } else {
160                         echo '<strong>'.AT_print($row['subject'], 'messages.subject').'</strong>';
161                 }
162                 echo '</td>';
163         
164                 echo '<td valign="middle" align="left" nowrap="nowrap">';
165                 echo AT_date(_AT('inbox_date_format'),  $row['date_sent'], AT_DATE_MYSQL_DATETIME);
166                 echo '</td>';
167                 echo '</tr>';
168         } while ($row = mysql_fetch_assoc($result)); ?>
169 <?php else: ?>
170         <tr>
171                 <td colspan="4"><?php echo _AT('none_found'); ?></td>
172         </tr>
173 <?php endif; ?>
174 </tbody>
175 </table>
176 </form>
177
178 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>