From 405f01ee2d9227a6984706f1baa6ebf512f09a79 Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 1 Jan 2005 16:00:35 +0000 Subject: [PATCH] Emailing is now working well, and more GUI cleanups --- lang/en/message.php | 1 + message/index.php | 8 +++++ message/lib.php | 79 ++++++++++++++++++++++++++++++++++++++++----- message/user.php | 14 ++------ 4 files changed, 82 insertions(+), 20 deletions(-) diff --git a/lang/en/message.php b/lang/en/message.php index ec1a770cf1..f766d9d279 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -11,6 +11,7 @@ $string['blockedmessages'] = '$a message(s) to/from blocked users'; $string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted'; $string['discussion'] = 'Discussion'; $string['emailmessages'] = 'Email messages when I am offline'; +$string['emailtagline'] = 'This email is a copy of a message sent to you at \"$a\"'; $string['emptysearchstring'] = 'You must search for something'; $string['includeblockedusers'] = 'Include blocked users'; $string['incomingcontacts'] = 'Incoming Contacts ($a)'; diff --git a/message/index.php b/message/index.php index fd3983f369..2fecc81243 100644 --- a/message/index.php +++ b/message/index.php @@ -12,6 +12,14 @@ $addcontact = optional_param('addcontact', 0, PARAM_INT); // adding a co $removecontact = optional_param('removecontact', 0, PARAM_INT); // removing a contact $blockcontact = optional_param('blockcontact', 0, PARAM_INT); // blocking a contact $unblockcontact = optional_param('unblockcontact', 0, PARAM_INT); // unblocking a contact +$popup = optional_param('popup', false, PARAM_ALPHA); // If set then starts a new popup window + +if ($popup) { + print_header(); + echo '"; + redirect("$CFG->wwwroot/"); + exit; +} if ($addcontact and confirm_sesskey()) { add_to_log(SITEID, 'message', 'add contact', 'history.php?user1='.$addcontact.'&user2='.$USER->id, $addcontact); diff --git a/message/lib.php b/message/lib.php index 46006a2f4e..1ace85cf68 100644 --- a/message/lib.php +++ b/message/lib.php @@ -64,7 +64,9 @@ function message_print_contacts() { print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow'); echo ''; echo ''; - link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", $fullnamelink, 400, 400, get_string('sendmessageto', 'message', $fullname)); + link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", + $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), + 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); echo ''; echo ''.$strcontact.''; echo ''; @@ -97,7 +99,9 @@ function message_print_contacts() { print_user_picture($contact->id, SITEID, $contact->picture, 20, false, true, 'userwindow'); echo ''; echo ''; - link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", $fullnamelink, 400, 400, get_string('sendmessageto', 'message', $fullname)); + link_to_popup_window("/message/user.php?id=$contact->id", "message_$contact->id", + $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), + 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); echo ''; echo ''.$strcontact.''; echo ''; @@ -154,7 +158,9 @@ function message_print_contacts() { print_user_picture($messageuser->useridfrom, SITEID, $messageuser->picture, 20, false, true, 'userwindow'); echo ''; echo ''; - link_to_popup_window("/message/user.php?id=$messageuser->useridfrom", "message_$messageuser->useridfrom", $fullnamelink, 400, 400, get_string('sendmessageto', 'message', $fullname)); + link_to_popup_window("/message/user.php?id=$messageuser->useridfrom", "message_$messageuser->useridfrom", + $fullnamelink, 500, 500, get_string('sendmessageto', 'message', $fullname), + 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); echo ''; echo ''.$strcontact.' '.$strblock.''; echo ''; @@ -224,7 +230,7 @@ function message_print_settings() { set_user_preferences($pref); - redirect($ME, get_string('settingssaved', 'message'), 3); + redirect($ME, get_string('settingssaved', 'message'), 1); } $cbshowmessagewindow = (get_user_preferences('message_showmessagewindow', 1) == '1') ? 'checked="checked"' : ''; @@ -337,7 +343,9 @@ function message_print_search_results($frm) { print_user_picture($user->id, SITEID, $user->picture, 20, false, true, 'userwindow'); echo ''; echo ''; - link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user))); + link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", fullname($user), + 500, 500, get_string('sendmessageto', 'message', fullname($user)), + 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); echo ''; echo ''.$strcontact.''; @@ -500,7 +508,9 @@ function message_print_user ($user=false, $iscontact=false, $isblocked=false) { message_contact_link($user->id, 'block'); } echo '
'; - link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user))); + link_to_popup_window("/message/user.php?id=$user->id", "message_$user->id", + fullname($user), 400, 400, get_string('sendmessageto', 'message', fullname($user)), + 'menubar=0,location=0,status,scrollbars,resizable,width=500,height=500'); } } @@ -819,11 +829,64 @@ function message_get_history($user1, $user2) { function message_format_message(&$message, &$user, $format='') { if (empty($format)) { - $format = get_string('strftimemessage', 'chat'); + $format = get_string('strftimedaytime'); } $time = userdate($message->timecreated, $format); - return '

'.addslashes($user->firstname).' ['.$time.']: '.format_text($message->message, $message->format).'

'; + return '

'.s($user->firstname).' ['.$time.']: '. + format_text($message->message, $message->format).'

'; } +/* + * Inserts a message into the database, but also forwards it + * via other means if appropriate. + */ +function message_post_message($userfrom, $userto, $message, $format, $messagetype) { + + global $CFG, $SITE; + +/// Save the new message in the database + + $savemessage = NULL; + $savemessage->useridfrom = $userfrom->id; + $savemessage->useridto = $userto->id; + $savemessage->message = $message; + $savemessage->format = $format; + $savemessage->timecreated = time(); + $savemessage->messagetype = 'direct'; + + if (!insert_record('message', $savemessage)) { + return false; + } + + +/// Check to see if anything else needs to be done with it + + $preference = (object)get_user_preferences(NULL, NULL, $userto->id); + + if (!empty($preference->message_emailmessages)) { // Receiver wants mail forwarding + if ((time() - $userto->lastaccess) > ((int)$preference->message_emailtimenosee * 60)) { // Long enough + + $message = stripslashes_safe($message); + $tagline = get_string('emailtagline', 'message', $SITE->shortname); + + $messagesubject = message_shorten_message(strip_tags($message), 30).'...'; + + $messagetext = format_text_email($message, $format). + "\n\n--\n".$tagline."\n"."$CFG->wwwroot/message/index.php?popup=1"; + + if ($preference->message_emailformat == FORMAT_HTML) { + $messagehtml = format_text($message, $format); + $messagehtml .= '

'.$tagline.'

'; + } else { + $messagehtml = NULL; + } + + $userto->email = $preference->message_emailaddress; // Use custom messaging address + email_to_user($userto, $userfrom, $messagesubject, $messagetext, $messagehtml); + } + } + + return true; +} ?> diff --git a/message/user.php b/message/user.php index 37db3d8f25..645c32d0cc 100644 --- a/message/user.php +++ b/message/user.php @@ -80,7 +80,7 @@ if ($messages = get_records_select('message', "useridto = '$USER->id' AND useridfrom = '$user->id'", 'timecreated')) { foreach ($messages as $message) { - $time = userdate($message->timecreated, get_string('strftimemessage', 'chat')); + $time = userdate($message->timecreated, get_string('strftimedaytime')); $options = NULL; $options->para = false; @@ -131,17 +131,7 @@ if ($message and confirm_sesskey()) { /// Current user has just sent a message /// Save it to the database... - $savemessage = NULL; - $savemessage->useridfrom = $USER->id; - $savemessage->useridto = $user->id; - $savemessage->message = $message; - $savemessage->format = $format; - $savemessage->timecreated = time(); - $savemessage->messagetype = 'direct'; - - if (!insert_record('message', $savemessage)) { - notify('Error: Message was not sent!!'); - } + message_post_message($USER, $user, $message, $format, 'direct'); /// Format the message as HTML $options = NULL; -- 2.39.5