made a copy
[atutor.git] / inbox / sent_messages.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['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'], $_POST['id'])) {
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 } else if ((isset($_POST['delete']) || isset($_POST['move'])) && !isset($_POST['id'])) {
68         $msg->addError('NO_ITEM_SELECTED');
69         header('Location: '.$_SERVER['PHP_SELF']);
70         exit;
71 }
72
73 require(AT_INCLUDE_PATH.'header.inc.php');
74
75 if (isset($_GET['view']) && $_GET['view']) {
76         $sql    = "SELECT * FROM ".TABLE_PREFIX."messages_sent WHERE message_id=$_GET[view] AND from_member_id=$_SESSION[member_id]";
77         $result = mysql_query($sql, $db);
78
79         if ($row = mysql_fetch_assoc($result)) {
80 ?>
81         <ul id="inbox-msg">
82         <li>
83                 <div class="forum-post-author">
84                         <a href="profile.php?id=<?php echo $row['to_member_id']; ?>" class="title"><?php echo get_display_name($row['to_member_id']); ?></a><br />
85                         <?php print_profile_img($row['to_member_id']); ?>
86                 </div>
87
88                 <div class="forum-post-content">
89                         <h3><?php echo AT_Print(htmlspecialchars($row['subject'], ENT_COMPAT, "UTF-8"), 'messages.subject'); ?></h3>
90                         <div>
91                                 <div class="forum-post-ctrl">
92                                         <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>
93                                 </div>
94                                 <p class="date"><?php echo AT_date(_AT('forum_date_format'), $row['date_sent'], AT_DATE_MYSQL_DATETIME); ?></p>
95                         </div>
96
97                         <div class="body">
98                                 <p><?php echo AT_print(htmlspecialchars($row['body'], ENT_COMPAT, "UTF-8"), 'messages.body'); ?></p>
99                         </div>
100                         <div style="clear: both; font-size:0.1em"></div>
101                 </div>
102         </div>
103         </li>
104         </ul>
105         <?php
106         }
107 } else if (isset($_POST['delete'], $_POST['id'])) {
108         $hidden_vars['ids'] = implode(',', $_POST['id']);
109
110         $msg->addConfirm('DELETE_MSGS', $hidden_vars);
111         $msg->printConfirm();
112 }
113
114 $msg->printInfos(array('INBOX_SENT_MSGS_TTL', $_config['sent_msgs_ttl']));
115
116 $sql    = "SELECT * FROM ".TABLE_PREFIX."messages_sent WHERE from_member_id=$_SESSION[member_id] ORDER BY date_sent DESC";
117 $result = mysql_query($sql,$db);
118 ?>
119
120 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
121 <table class="data" summary="" rules="rows">
122 <thead>
123 <tr>
124         <th scope="col">&nbsp;</th>
125         <th scope="col" ><?php echo _AT('to');   ?></th>
126         <th scope="col" ><?php echo _AT('subject');?></th>
127         <th scope="col" ><?php echo _AT('date');   ?></th>
128 </tr>
129 </thead>
130 <tfoot>
131 <tr>
132         <td colspan="4">
133                 <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>"/>
134                 <input type="submit" name="move" value="<?php echo _AT('move_to_inbox'); ?>"/>
135         </td>
136 </tr>
137 </tfoot>
138 <tbody>
139 <?php if ($row = mysql_fetch_assoc($result)): ?>
140         <?php do { ?>
141                 <?php if ($row['message_id'] == $_GET['view']): ?>
142                         <tr class="selected">
143                 <?php else: ?>
144                         <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">
145                 <?php endif; ?>
146                 <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>
147                 <?php
148
149                 $name = get_display_name($row['to_member_id']);
150
151                 echo '<td align="left" valign="middle">';
152
153                 if ($_GET['view'] != $row['message_id']) {
154                         echo $name;
155                 } else {
156                         echo '<strong>'.$name.'</strong>';
157                 }
158                 echo '</td>';
159
160                 echo '<td><label for="m'.$row['message_id'].'">';
161                 if ($_GET['view'] != $row['message_id']) {
162                         echo '<a href="'.$_SERVER['PHP_SELF'].'?view='.$row['message_id'].'">'.AT_print($row['subject'], 'messages.subject').'</a>';
163                 } else {
164                         echo '<strong>'.AT_print($row['subject'], 'messages.subject').'</strong>';
165                 }
166                 echo '</label></td>';
167         
168                 echo '<td valign="middle" align="left" nowrap="nowrap">';
169                 echo AT_date(_AT('inbox_date_format'),  $row['date_sent'], AT_DATE_MYSQL_DATETIME);
170                 echo '</td>';
171                 echo '</tr>';
172         } while ($row = mysql_fetch_assoc($result)); ?>
173 <?php else: ?>
174         <tr>
175                 <td colspan="4"><?php echo _AT('none_found'); ?></td>
176         </tr>
177 <?php endif; ?>
178 </tbody>
179 </table>
180 </form>
181
182 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>