$message = Message::find_by_id($_GET['id']); //If not found, return to 'mailbox' page... if (!$message) { redirect_to('inbox'); } //If message gound, find its sender... $sender = User::find_by_id($message->sender_id); } else { redirect_to('inbox'); } //Check type of mail... //Type = 'inbox'|'sent'|'draft' //If it is from 'inbox', mark it as 'read'... if ($_GET['type'] == 'inbox') { $message_receiver = new Receiver(); $message_receiver = Receiver::find_by_user_msg($_SESSION['user_id'], $_GET['id']); $message_receiver->is_read = 'true'; $message_receiver->update(); } ?> <?php //Count the no. of unread messages... $count = User::count_unread_messages($user->id); ?> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
foreach ($selected_message_ids as $message_id) { //Fetch and delete the entry from trash table... //It will remove the message permanantly from 'this' user's perspective... //But it will be stored in 'Messages' table for others... $message_to_remove = Trash::find_by_user_msg($_SESSION['user_id'], $message_id); $message_to_remove->delete(); } //foreach... } } } } else { if ($action == 'mark_as_read') { //for( $i=0 ; $i<count($selected_messages) ; $i++ ) foreach ($selected_message_ids as $message_id) { $message = Receiver::find_by_user_msg($_SESSION['user_id'], $message_id); //Avoid if ($message->is_read == 'false') { $message->is_read = 'true'; $message->update(); } } } else { if ($action == 'recover') { foreach ($selected_message_ids as $message_id) { //Fetch the entry from 'trash' table... $message_to_remove = Trash::find_by_user_msg($_SESSION['user_id'], $message_id); //See from where it came... (type = inbox|sent) $type = $message_to_remove->type == 'inbox' ? 'inbox' : 'sent'; //Add a message entry to 'inbox' table if it is type=inbox... if ($type == 'inbox') {