Пример #1
0
 public function signup()
 {
     global $db;
     // check the anti-spam control
     expValidator::check_antispam($this->params, gt("Anti-spam verification failed.  Please try again."));
     // make sure we have what we need.
     if (empty($this->params['email'])) {
         expQueue::flashAndFlow('error', 'You must supply an email address to sign up for email alerts.');
     }
     if (empty($this->params['ealerts'])) {
         expQueue::flashAndFlow('error', 'You did not select any E-Alert topics to subscribe to.');
     }
     // find or create the subscriber
     $id = $db->selectValue('subscribers', 'id', 'email="' . $this->params['email'] . '"');
     $subscriber = new subscribers($id);
     if (empty($subscriber->id)) {
         $subscriber->email = trim($this->params['email']);
         $subscriber->hash = md5($subscriber->email . time());
         $subscriber->save();
     }
     // delete any old subscriptions and add the user to new subscriptions
     $db->delete('expeAlerts_subscribers', 'subscribers_id=' . $subscriber->id);
     foreach ($this->params['ealerts'] as $ea_id) {
         $obj = null;
         $obj->subscribers_id = $subscriber->id;
         $obj->expeAlerts_id = $ea_id;
         $db->insertObject($obj, 'expeAlerts_subscribers');
     }
     // send a confirmation email to the user.
     $ealerts = $db->selectObjects('expeAlerts', 'id IN (' . implode(',', $this->params['ealerts']) . ')');
     $body = get_template_for_action($this, 'confirmation_email', $this->loc);
     $body->assign('ealerts', $ealerts);
     $body->assign('subscriber', $subscriber);
     $mail = new expMail();
     $mail->quickSend(array('html_message' => $body->render(), 'to' => $subscriber->email, 'from' => SMTP_FROMADDRESS, 'subject' => 'Please confirm your E-Alert subscriptions'));
     redirect_to(array('controller' => 'ealert', 'action' => 'pending', 'id' => $subscriber->id));
 }