function confirm_success($ALERT) { global $PAGE, $this_page, $THEUSER; $this_page = 'alertconfirmsucceeded'; $criteria = $ALERT->criteria_pretty(true); $email = $ALERT->email(); $extra = null; $PAGE->page_start(); $PAGE->stripe_start(); ?> <p>Your alert has been confirmed.</p> <p>You will now receive email alerts for the following criteria:</p> <ul><?php echo $criteria; ?> </ul> <p>This is normally the day after, but could conceivably be later due to issues at our or parliament.uk's end.</p> <?php $extra = alert_confirmation_advert(array('email' => $email, 'pid' => strstr($ALERT->criteria(), 'speaker:'))); if ($extra) { $extra = "advert={$extra}"; } $PAGE->stripe_end(); $PAGE->page_end($extra); }
function add_alert($details) { global $ALERT, $PAGE, $THEUSER, $this_page; $extra = null; // Instantiate an instance of ALERT $ALERT = new ALERT(); $external_auth = auth_verify_with_shared_secret($details['email'], OPTION_AUTH_SHARED_SECRET, get_http_var('sign')); if ($external_auth) { $site = get_http_var('site'); if ($site != 'wtt' && $site != 'hfymp') { $site = 'unknown'; } $extra = 'from_' . $site . '=1'; $confirm = false; } elseif ($THEUSER->loggedin()) { $confirm = false; } else { $confirm = true; } // If this goes well, the alert will be added to the database and a confirmation email // will be sent to them. $success = $ALERT->add($details, $confirm); // Display results message on blank page for both success and failure $this_page = 'alertwelcome'; $URL = new URL('alertwelcome'); $backlink = $URL->generate(); $PAGE->page_start(); $PAGE->stripe_start(); $advert = false; if ($success > 0 && !$confirm) { if ($details['pid']) { $MEMBER = new MEMBER(array('person_id' => $details['pid'])); $criteria = $MEMBER->full_name(); if ($details['keyword']) { $criteria .= ' mentions \'' . $details['keyword'] . '\''; } else { $criteria .= ' contributes'; } } elseif ($details['keyword']) { $criteria = '\'' . $details['keyword'] . '\' is mentioned'; } $message = array('title' => 'Your alert has been added', 'text' => 'You will now receive email alerts on any day when ' . $criteria . ' in parliament.'); $advert = true; } elseif ($success > 0) { $message = array('title' => "We're nearly done...", 'text' => "You should receive an email shortly which will contain a link. You will need to follow that link to confirm your email address to receive the alert. Thanks."); } elseif ($success == -2) { $message = array('title' => 'You already have this alert', 'text' => 'You already appear to be subscribed to this email alert, so we have not signed you up to it again.'); $advert = true; } else { $message = array('title' => "This alert has not been accepted", 'text' => "Sorry, we were unable to create this alert. Please <a href=\"mailto:" . CONTACTEMAIL . "\">let us know</a>. Thanks."); } $PAGE->message($message); if ($advert) { $advert_shown = alert_confirmation_advert($details); if ($extra) { $extra .= "; "; } $extra .= "advert={$advert_shown}"; } suggest_alerts($details['email'], $details['pid'], 5); $PAGE->stripe_end(); $PAGE->page_end($extra); }