function engagements_handle_sms_unstop
Search API
7.x engagements.module | engagements_handle_sms_unstop($user_id = 0, $cwid = '', $phone_number = '', $from_fp_phone_number = '') |
6.x engagements.module | engagements_handle_sms_unstop($user_id = 0, $cwid = '', $phone_number = '', $from_fp_phone_number = '') |
User opted-IN to receiving txt messages.
1 call to engagements_handle_sms_unstop()
- engagements_handle_incoming_sms in modules/
engagements/ engagements.module - This catches incoming sms messages from POST, but can also be used by our "sms_get_all_messages" function, but it is also used by the sms_get_all_messages to save/update information.
File
- modules/
engagements/ engagements.module, line 1496 - This is the primary module file for the engagements module.
Code
function engagements_handle_sms_unstop($user_id = 0, $cwid = '', $phone_number = '', $from_fp_phone_number = '') {
if ($user_id === 0) {
// Try to figure out what the user_id is based on the phone number.
$test = db_result(db_query("SELECT user_id FROM user_attributes WHERE name = 'mobile_phone' AND value = ?", array($from_fp_phone_number)));
$test = intval($test);
if ($test > 0) {
$user_id = $test;
}
}
$phone_number = engagements_convert_to_valid_phone_number($phone_number);
if (!$phone_number) {
// watchdog that there was an error because phone number not valid.
watchdog('engagements_sms', "User tried to opt-in to sms, but invalid phone number: $user_id, $cwid, $phone_number", array(), WATCHDOG_ERROR);
return FALSE;
}
if ($user_id) {
// Get current notification method for this user.
$notification_method = db_result(db_query("SELECT prev_notification_method FROM sms_do_not_txt WHERE phone_number = ?", array($phone_number)));
if ($notification_method) {
// Set their new defailt_notification_method to just email.
user_set_setting($user_id, 'default_notification_method', $notification_method);
}
// also set our opt-out setting value here, so the user can change it from within flightpath.
user_set_setting($user_id, "sms_opt_out__" . $phone_number, 'no');
}
// Save everything to do_not_txt table. (First, delete anything already there for this phone_number, which is the most important to keep track of)
db_query('DELETE FROM sms_do_not_txt WHERE phone_number = ?', array($phone_number));
// Send final sms back to number telling them how to re-enable.
$msg = t("You have opted-in to receiving text messages from @flightpath.\nReply STOP to opt-out.\n\nYou may also log into @flightpath and edit your notification settings.",
array("@flightpath" => variable_get("system_name", "FlightPath")));
engagements_send_sms_to_number($phone_number, $msg, '', $from_fp_phone_number, FALSE);
watchdog('engagements_sms', "User opted-out of sms: $user_id, $cwid, $phone_number");
}