/** * Send an email message. * * @access public * @param string $to Recipient email address * @param string $from Sender email address * @param string $subject Subject line for message * @param string $body Message body * @param string $replyTo Someone to reply to * * @return mixed PEAR error on error, boolean true otherwise */ public function send($to, $from, $subject, $body, $replyTo = null) { global $logger; // Validate sender and recipient $validator = new Mail_RFC822(); //Allow the to address to be split $validator->_splitAddresses($to); foreach ($validator->addresses as $tmpAddress) { if (!$validator->isValidInetAddress($tmpAddress['address'])) { return new PEAR_Error('Invalid Recipient Email Address ' . $tmpAddress); } } if (!$validator->isValidInetAddress($from)) { return new PEAR_Error('Invalid Sender Email Address'); } $headers = array('To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Content-Type' => 'text/plain; charset="UTF-8"'); if (isset($this->settings['fromAddress'])) { $logger->log("Overriding From address, using " . $this->settings['fromAddress'], PEAR_LOG_INFO); $headers['From'] = $this->settings['fromAddress']; $headers['Reply-To'] = $from; } else { $headers['From'] = $from; } if ($replyTo != null) { $headers['Reply-To'] = $replyTo; } // Get mail object if ($this->settings['host'] != false) { $mailFactory = new Mail(); $mail =& $mailFactory->factory('smtp', $this->settings); if (PEAR_Singleton::isError($mail)) { return $mail; } // Send message return $mail->send($to, $headers, $body); } else { //Mail to false just emits the information to screen $formattedMail = ''; foreach ($headers as $key => $header) { $formattedMail .= $key . ': ' . $header . '<br />'; } $formattedMail .= $body; $logger->log("Sending e-mail", PEAR_LOG_INFO); $logger->log("From = {$from}", PEAR_LOG_INFO); $logger->log("To = {$to}", PEAR_LOG_INFO); $logger->log($subject, PEAR_LOG_INFO); $logger->log($formattedMail, PEAR_LOG_INFO); return true; } }
/** * Send an email message. * * @param string $to Recipient email address * @param string $from Sender email address * @param string $subject Subject line for message * @param string $body Message body * * @return mixed PEAR error on error, boolean true otherwise * @access public */ public function send($to, $from, $subject, $body) { // Validate sender and recipient if (!Mail_RFC822::isValidInetAddress($to)) { return new PEAR_Error('Invalid Recipient Email Address'); } if (!Mail_RFC822::isValidInetAddress($from)) { return new PEAR_Error('Invalid Sender Email Address'); } // Change error handling behavior to avoid termination during mail // process.... PEAR::setErrorHandling(PEAR_ERROR_RETURN); // Get mail object $mail =& Mail::factory('smtp', $this->settings); if (PEAR::isError($mail)) { return $mail; } // Send message $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject, 'Date' => date('D, d M Y H:i:s O'), 'Content-Type' => 'text/plain; charset="UTF-8"'); $result = $mail->send($to, $headers, $body); return $result; }
/** * Get Patron Profile * * This is responsible for retrieving the profile for a specific patron. * * @param array $patron The patron array * * @return mixed Array of the patron's profile data on success, * PEAR_Error otherwise. * @access public */ public function getMyProfile($patron) { $sql = "SELECT PATRON.LAST_NAME, PATRON.FIRST_NAME, " . "PATRON.HISTORICAL_CHARGES, PATRON_ADDRESS.ADDRESS_LINE1, " . "PATRON_ADDRESS.ADDRESS_LINE2, PATRON_ADDRESS.ZIP_POSTAL, " . "PATRON_ADDRESS.CITY, PATRON_ADDRESS.COUNTRY, " . "PATRON_PHONE.PHONE_NUMBER, PATRON_GROUP.PATRON_GROUP_NAME " . "FROM {$this->dbName}.PATRON, {$this->dbName}.PATRON_ADDRESS, " . "{$this->dbName}.PATRON_PHONE, {$this->dbName}.PATRON_BARCODE, " . "{$this->dbName}.PATRON_GROUP " . "WHERE PATRON.PATRON_ID = PATRON_ADDRESS.PATRON_ID (+) " . "AND PATRON_ADDRESS.ADDRESS_ID = PATRON_PHONE.ADDRESS_ID (+) " . "AND PATRON.PATRON_ID = PATRON_BARCODE.PATRON_ID (+) " . "AND PATRON_BARCODE.PATRON_GROUP_ID = " . "PATRON_GROUP.PATRON_GROUP_ID (+) " . "AND PATRON.PATRON_ID = :id"; try { $sqlStmt = $this->db->prepare($sql); $this->debugLogSQL(__FUNCTION__, $sql, array(':id' => $patron['id'])); $sqlStmt->execute(array(':id' => $patron['id'])); $patron = array(); while ($row = $sqlStmt->fetch(PDO::FETCH_ASSOC)) { if (!empty($row['FIRST_NAME'])) { $patron['firstname'] = utf8_encode($row['FIRST_NAME']); } if (!empty($row['LAST_NAME'])) { $patron['lastname'] = utf8_encode($row['LAST_NAME']); } if (!empty($row['PHONE_NUMBER'])) { $patron['phone'] = utf8_encode($row['PHONE_NUMBER']); } if (!empty($row['PATRON_GROUP_NAME'])) { $patron['group'] = utf8_encode($row['PATRON_GROUP_NAME']); } include_once 'Mail/RFC822.php'; $addr1 = utf8_encode($row['ADDRESS_LINE1']); if (Mail_RFC822::isValidInetAddress($addr1)) { $patron['email'] = $addr1; } else { if (!isset($patron['address1'])) { if (!empty($addr1)) { $patron['address1'] = $addr1; } if (!empty($row['ADDRESS_LINE2'])) { $patron['address2'] = utf8_encode($row['ADDRESS_LINE2']); } $patron['zip'] = !empty($row['ZIP_POSTAL']) ? utf8_encode($row['ZIP_POSTAL']) : ''; if (!empty($row['CITY'])) { if ($patron['zip']) { $patron['zip'] .= ' '; } $patron['zip'] .= utf8_encode($row['CITY']); } if (!empty($row['COUNTRY'])) { if ($patron['zip']) { $patron['zip'] .= ', '; } $patron['zip'] .= utf8_encode($row['COUNTRY']); } } } } return empty($patron) ? null : $patron; } catch (PDOException $e) { return new PEAR_Error($e->getMessage()); } }
print "</form>\n</body>\n</html>\n"; exit; } // // Verify email adresses include_once 'Mail/RFC822.php'; $email_var = get_form_var('Field_email', 'string'); if (!isset($email_var)) { $email_var = ''; } $emails = explode(',', $email_var); $valid_email = new Mail_RFC822(); foreach ($emails as $email) { // if no email address is entered, this is OK, even if isValidInetAddress // does not return TRUE if (!$valid_email->isValidInetAddress($email, $strict = FALSE) && '' != $email_var) { // Now display this form again with an error message Header("Location: edit_users.php?Action=Edit&Id={$Id}&invalid_email=1"); exit; } } // if ($Id >= 0) { $operation = "replace into {$tbl_users} values ("; } else { $operation = "insert into {$tbl_users} values ("; $Id = sql_query1("select max(id) from {$tbl_users};") + 1; /* Use the last index + 1 */ /* Note: If the table is empty, sql_query1 returns -1. So use index 0. */ } $i = 0;
print get_vocab("passwords_not_eq") . "<br>\n"; print "<form method=post action=\"" . basename($PHP_SELF) . "\">\n"; print " <input type=submit value=\" " . get_vocab("ok") . " \" /> <br />\n"; print "</form>\n</body>\n</html>\n"; exit; } // // Verify email adresses include_once 'Mail/RFC822.php'; !isset($Field[3]) ? $Field[3] = '' : ''; $emails = explode(',', $Field[3]); $valid_email = new Mail_RFC822(); foreach ($emails as $email) { // if no email address is entered, this is OK, even if isValidInetAddress // does not return TRUE if (!$valid_email->isValidInetAddress($email, $strict = FALSE) && '' != $Field[3]) { // Now display this form again with an error message Header("Location: edit_users.php?Action=Edit&Id={$Id}&invalid_email=1"); exit; } } // if ($Id >= 0) { $operation = "replace into {$tbl_users} values ("; } else { $operation = "insert into {$tbl_users} values ("; $Id = sql_query1("select max(id) from {$tbl_users};") + 1; /* Use the last index + 1 */ /* Note: If the table is empty, sql_query1 returns -1. So use index 0. */ } for ($i = 0; $i < $nfields; $i++) {
<?php } ?> <?php if (!empty($area)) { include_once 'Mail/RFC822.php'; !isset($area_admin_email) ? $area_admin_email = '' : ''; $emails = explode(',', $area_admin_email); $valid_email = TRUE; $email_validator = new Mail_RFC822(); foreach ($emails as $email) { // if no email address is entered, this is OK, even if isValidInetAddress // does not return TRUE if (!$email_validator->isValidInetAddress($email, $strict = FALSE) && '' != $area_admin_email) { $valid_email = FALSE; } } // if (isset($change_area) && FALSE != $valid_email) { $sql = "UPDATE {$tbl_area} SET area_name='" . addslashes($area_name) . "', area_admin_email='" . addslashes($area_admin_email) . "' WHERE id={$area}"; if (sql_command($sql) < 0) { fatal_error(0, get_vocab("update_area_failed") . sql_error()); } } $res = sql_query("SELECT * FROM {$tbl_area} WHERE id={$area}"); if (!$res) { fatal_error(0, get_vocab("error_area") . $area . get_vocab("not_found")); } $row = sql_row_keyed($res, 0);
/** * Checks to see if email address is valid. * * This function checks to see if an email address is in the correct from. * * @param string $email Email address to verify * @return boolean True if valid otherwise false * */ function COM_isEmail($email) { require_once 'Mail/RFC822.php'; $rfc822 = new Mail_RFC822(); return $rfc822->isValidInetAddress($email) ? true : false; }
/** * Process incoming parameters for account creation. * * @return mixed True on successful account creation, PEAR_Error otherwise. * @access private */ private function _processInput() { // Validate Input if (trim($_POST['username']) == '') { return new PEAR_Error('Username cannot be blank'); } if (trim($_POST['password']) == '') { return new PEAR_Error('Password cannot be blank'); } if ($_POST['password'] != $_POST['password2']) { return new PEAR_Error('Passwords do not match'); } if (!Mail_RFC822::isValidInetAddress($_POST['email'])) { return new PEAR_Error('Email address is invalid'); } // Create Account $user = new User(); $user->username = $_POST['username']; if (!$user->find()) { // No username match found -- check for duplicate email: $user = new User(); $user->email = $_POST['email']; if (!$user->find()) { // We need to reassign the username since we cleared it out when // we did the search for duplicate email addresses: $user->username = $_POST['username']; $user->password = $_POST['password']; $user->firstname = $_POST['firstname']; $user->lastname = $_POST['lastname']; $user->created = date('Y-m-d h:i:s'); $user->insert(); } else { return new PEAR_Error('That email address is already used'); } } else { return new PEAR_Error('That username is already taken'); } return true; }
/** * Send an email message. * * @param string $to Recipient email address * @param string $from Sender email address * @param string $subject Subject line for message * @param string $body Message body * * @return mixed PEAR error on error, boolean true otherwise * @access public */ public function send($to, $from, $subject, $body) { // Validate sender and recipient foreach (explode(',', $to) as $address) { if (!Mail_RFC822::isValidInetAddress($address)) { return new PEAR_Error('Invalid Recipient Email Address'); } } if (!Mail_RFC822::isValidInetAddress($from)) { return new PEAR_Error('Invalid Sender Email Address'); } // Change error handling behavior to avoid termination during mail // process.... PEAR::setErrorHandling(PEAR_ERROR_RETURN); // Get mail object $mail =& Mail::factory('smtp', $this->settings); if (PEAR::isError($mail)) { return $mail; } $body = $this->getFlowedBody($body); // Send message $headers = array('From' => $this->mimeEncodeAddress($from), 'To' => $this->mimeEncodeAddress($to), 'Subject' => $this->mimeEncodeHeaderValue($subject), 'Date' => date('D, d M Y H:i:s O'), 'Content-Type' => 'text/plain; charset="UTF-8"; format=flowed', 'Content-Transfer-Encoding' => '8bit', 'X-Mailer' => 'VuFind'); $result = $mail->send($to, $headers, $body); return $result; }
/** * Process parameters and display the page. * * @return void * @access public */ public function launch() { global $configArray; global $interface; global $user; // Collect all messages so that nothing is overwritten $userMessages = array(); $userErrors = array(); // These require just a login if (UserAccount::isLoggedIn()) { // Update email address if (isset($_POST['email'])) { if ($user->changeEmailAddress($_POST['email'])) { $userMessages[] = 'profile_update'; } } $interface->assign('email', $user->email); // Update due date reminder if (isset($_POST['due_date_reminder'])) { $interval = $_POST['due_date_reminder']; if (is_numeric($interval) && $interval >= 0) { if ($user->changeDueDateReminder($_POST['due_date_reminder'])) { $userMessages[] = 'profile_update'; } } } $interface->assign('dueDateReminder', $user->due_date_reminder); } // Get My Profile if ($patron = UserAccount::catalogLogin()) { if (PEAR::isError($patron)) { $this->handleCatalogError($patron); } else { // Address change request form if (isset($_POST['changeAddressRequest'])) { $profile = $this->catalog->getMyProfile($patron); if (!PEAR::isError($profile)) { $interface->assign('address1', isset($profile['address1']) ? $profile['address1'] : ''); $interface->assign('zip', isset($profile['zip']) ? $profile['zip'] : ''); } $interface->display('/MyResearch/change-address.tpl'); return; } // Address change request if (isset($_POST['changeAddressLine1']) && isset($_POST['changeAddressZip'])) { $profile = $this->catalog->getMyProfile($patron); $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); $data['oldAddress1'] = isset($profile['address1']) ? $profile['address1'] : ''; $data['oldZip'] = isset($profile['zip']) ? $profile['zip'] : ''; $result = $this->sendEmail($patron, $data, 'Osoitteenmuutospyyntö', 'Emails/change-address.tpl'); if (!PEAR::isError($result)) { $userMessages[] = 'request_change_email_sent'; } else { error_log('Sending of address change request mail failed: ' . $result->getMessage()); $userErrors[] = 'request_change_email_failed'; } } // Messaging settings request form if (isset($_POST['changeMessagingSettingsRequest'])) { $profile = $this->catalog->getMyProfile($patron); if (isset($profile['messagingServices'])) { $interface->assign('services', $profile['messagingServices']); $emailDays = array(); foreach (array(1, 2, 3, 4, 5) as $day) { if ($day == 1) { $label = translate("messaging_settings_num_of_days"); } else { $label = translate("messaging_settings_num_of_days_plural"); $label = str_replace('{1}', $day, $label); } $emailDays[] = $label; } $interface->assign('emailDays', $emailDays); $interface->assign('days', array(1, 2, 3, 4, 5)); $interface->display('/MyResearch/change-messaging-settings.tpl'); return; } } // Messaging settings request if (isset($_POST['changeMessagingSettings'])) { // Translator for email message (always in Finnish) $translator = new I18N_Translator(array('lang', 'lang_local'), 'fi', $configArray['System']['debug']); $data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); $data['pickUpNotice'] = $translator->translate('messaging_settings_method_' . $data['pickUpNotice']); $data['overdueNotice'] = $translator->translate('messaging_settings_method_' . $data['overdueNotice']); if ($data['dueDateAlert'] == 0) { $data['dueDateAlert'] = $translator->translate('messaging_settings_method_none'); } else { if ($data['dueDateAlert'] == 1) { $data['dueDateAlert'] = $translator->translate('messaging_settings_num_of_days'); } else { $txt = $translator->translate('messaging_settings_num_of_days_plural'); $txt = str_replace('{1}', $data['dueDateAlert'], $txt); $data['dueDateAlert'] = $txt; } } $result = $this->sendEmail($patron, $data, 'Viestiasetusten muutospyyntö', 'Emails/change-messaging-settings.tpl'); if (!PEAR::isError($result)) { $userMessages[] = 'request_change_email_sent'; } else { error_log('Sending of messaging settings change request mail failed: ' . $result->getMessage()); $userErrors[] = 'request_change_email_failed'; } } // Change home library if (isset($_POST['home_library']) && $_POST['home_library'] != "") { $home_library = $_POST['home_library']; if ($user->changeHomeLibrary($home_library)) { $userMessages[] = 'profile_update'; } else { $userErrors[] = 'profile_update_failed'; } } // Change Password if (isset($_POST['oldPassword']) && isset($_POST['newPassword']) && isset($_POST['newPassword2'])) { if ($_POST['newPassword'] !== $_POST['newPassword2']) { $userErrors[] = 'change_password_error_verification'; } else { $result = $this->changePassword($_POST['oldPassword'], $_POST['newPassword']); if (PEAR::isError($result)) { $userErrors[] = $result->getMessage(); } else { if ($result['success']) { $userMessages[] = 'change_password_ok'; $user->changeCatalogPassword($_POST['newPassword']); // Re-retrieve patron to make sure it's up to date $patron = UserAccount::catalogLogin(); } else { $userErrors[] = $result['status']; } } } } // Change phone number if (isset($_POST['phone_number'])) { $phoneNumber = trim($_POST['phone_number']); if (preg_match('/^[\\+]?[ \\d\\-]+\\d+$/', $phoneNumber)) { $result = $this->catalog->setPhoneNumber($patron, $phoneNumber); if ($result['success']) { $userMessages[] = 'phone_updated'; // Re-retrieve patron to make sure it's up to date $patron = UserAccount::catalogLogin(); } else { $userErrors[] = $result['sys_message']; } } else { $userErrors[] = 'Phone Number is invalid'; } } // Change email address if (isset($_POST['email_address'])) { $email = trim($_POST['email_address']); if (Mail_RFC822::isValidInetAddress($email)) { $result = $this->catalog->setEmailAddress($patron, $email); if ($result['success']) { $userMessages[] = 'email_updated'; // Re-retrieve patron to make sure it's up to date $patron = UserAccount::catalogLogin(); } else { $userErrors[] = $result['sys_message']; } } else { $userErrors[] = 'Email address is invalid'; } } $result = $this->catalog->getMyProfile($patron); if (!PEAR::isError($result)) { $result['home_library'] = $user->home_library; $libs = $this->catalog->getPickUpLocations($patron); $defaultPickUpLocation = $this->catalog->getDefaultPickUpLocation($patron); $interface->assign('defaultPickUpLocation', $defaultPickUpLocation); $interface->assign('pickup', $libs); $interface->assign('profile', $result); } else { $userErrors[] = $result->getMessage(); } $result = $this->catalog->checkFunction('changePassword'); if ($result !== false) { $interface->assign('changePassword', $result); } $driver = isset($patron['driver']) ? $patron['driver'] : ''; $interface->assign('driver', $driver); } } $interface->assign('userMsg', array_unique($userMessages)); $interface->assign('userError', array_unique($userErrors)); $interface->assign('hideDueDateReminder', isset($configArray['Site']['hideDueDateReminder']) && (bool) $configArray['Site']['hideDueDateReminder']); $interface->assign('hideProfileEmailAddress', isset($configArray['Site']['hideProfileEmailAddress']) && (bool) $configArray['Site']['hideProfileEmailAddress']); Login::setupLoginFormVars(); $interface->setTemplate('profile.tpl'); $interface->setPageTitle('My Profile'); $interface->display('layout.tpl'); }