function sendEmail($to, $from, $message) { global $interface; global $user; //Load the list $list = new User_list(); $list->id = $_REQUEST['listId']; if ($list->find(true)) { // Build Favorites List $titles = $list->getResources(null); // Load the User object for the owner of the list (if necessary): if ($user && $user->id == $list->user_id || $list->public == 1) { //The user can access the list $favoriteHandler = new FavoriteHandler($titles, $user); $titleDetails = $favoriteHandler->getTitles(); $interface->assign('titles', $titleDetails); $interface->assign('list', $list); } else { $interface->assign('error', 'You do not have access to this list.'); } } else { $interface->assign('error', 'Unable to read list'); } $interface->assign('from', $from); $interface->assign('message', $message); $body = $interface->fetch('Emails/my-list.tpl'); $mail = new VuFindMailer(); $subject = $list->title; return $mail->send($to, $from, $subject, $body); }
function sendEmail($url, $to, $from, $message) { global $interface; $subject = translate('Library Catalog Search Result'); $interface->assign('from', $from); $interface->assign('message', $message); $interface->assign('msgUrl', $url); $body = $interface->fetch('Emails/share-link.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
function sendEmail($to, $from, $message) { global $interface; global $configArray; $subject = translate("Library Catalog Record") . ": " . $this->recordDriver->getBreadcrumb(); $interface->assign('from', $from); $interface->assign('emailDetails', $this->recordDriver->getEmail()); $interface->assign('recordID', $this->recordDriver->getUniqueID()); $interface->assign('message', $message); $body = $interface->fetch('Emails/catalog-record.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $configArray['Site']['email'], $subject, $body, $from); }
function launch() { global $interface; global $configArray; global $user; global $analytics; $interface->setPageTitle('eContent Support'); if (isset($_REQUEST['submit'])) { //E-mail the library with details of the support request require_once ROOT_DIR . '/sys/Mailer.php'; $mail = new VuFindMailer(); $userLibrary = Library::getPatronHomeLibrary(); if ($userLibrary == null) { $to = $configArray['Site']['email']; } else { $to = $userLibrary->eContentSupportAddress; } $name = $_REQUEST['name']; $interface->assign('bookAuthor', $_REQUEST['bookAuthor']); $interface->assign('device', $_REQUEST['device']); $interface->assign('format', $_REQUEST['format']); $interface->assign('operatingSystem', $_REQUEST['operatingSystem']); $interface->assign('problem', $_REQUEST['problem']); $subject = 'eContent Support Request from ' . $name; $from = $_REQUEST['email']; $body = $interface->fetch('Help/eContentSupportEmail.tpl'); if ($mail->send($to, $configArray['Site']['email'], $subject, $body, $from)) { $analytics->addEvent("Emails", "eContent Support Succeeded", $_REQUEST['device'], $_REQUEST['format'], $_REQUEST['operatingSystem']); echo json_encode(array('title' => "Support Request Sent", 'message' => "<p>Your request was sent to our support team. We will respond to your request as quickly as possible.</p><p>Thank you for using the catalog.</p>")); } else { $analytics->addEvent("Emails", "eContent Support Failed", $_REQUEST['device'], $_REQUEST['format'], $_REQUEST['operatingSystem']); echo json_encode(array('title' => "Support Request Not Sent", 'message' => "<p>We're sorry, but your request could not be submitted to our support team at this time.</p><p>Please try again later.</p>")); } } else { if (isset($_REQUEST['lightbox'])) { $interface->assign('lightbox', true); if ($user) { $interface->assign('name', $user->cat_username); $interface->assign('email', $user->email); } $result = array('title' => 'eContent Support', 'modalBody' => $interface->fetch('Help/eContentSupport.tpl'), 'modalButtons' => "<button class='btn btn-sm btn-primary' onclick='return VuFind.EContent.submitHelpForm();'>Submit</button>"); echo json_encode($result); } else { $interface->assign('lightbox', false); $interface->setTemplate('eContentSupport.tpl'); $interface->assign('sidebar', 'Search/home-sidebar.tpl'); $interface->display('layout.tpl'); } } }
function launch() { global $interface; global $configArray; global $user; global $analytics; $interface->setPageTitle('eContent Support'); if (isset($_REQUEST['submit'])) { //E-mail the library with details of the support request require_once ROOT_DIR . '/sys/Mailer.php'; $mail = new VuFindMailer(); $userLibrary = Library::getPatronHomeLibrary(); if ($userLibrary == null) { $to = $configArray['Site']['email']; } else { $to = $userLibrary->eContentSupportAddress; } $name = $_REQUEST['name']; $interface->assign('bookAuthor', $_REQUEST['bookAuthor']); $interface->assign('device', $_REQUEST['device']); $interface->assign('format', $_REQUEST['format']); $interface->assign('operatingSystem', $_REQUEST['operatingSystem']); $interface->assign('problem', $_REQUEST['problem']); $subject = 'eContent Support Request from ' . $name; $from = $_REQUEST['email']; $body = $interface->fetch('Help/eContentSupportEmail.tpl'); if ($mail->send($to, $configArray['Site']['email'], $subject, $body, $from)) { $analytics->addEvent("Emails", "eContent Support Succeeded", $_REQUEST['device'], $_REQUEST['format'], $_REQUEST['operatingSystem']); echo "<p>Your request was sent to our support team. We will respond to your request as quickly as possible.</p><p>Thank you for using the catalog.</p><input type='button' onclick='hideLightbox()' value='Close'/>"; } else { $analytics->addEvent("Emails", "eContent Support Failed", $_REQUEST['device'], $_REQUEST['format'], $_REQUEST['operatingSystem']); echo "<p>We're sorry, but your request could not be submitted to our support team at this time.</p><p>Please try again later.</p><input type='button' onclick='hideLightbox()' value='Close' />"; } } else { if (isset($_REQUEST['lightbox'])) { if ($user) { $interface->assign('name', $user->cat_username); $interface->assign('email', $user->email); } $interface->assign('popupTitle', 'eContent Support'); $popupContent = $interface->fetch('Help/eContentSupport.tpl'); $interface->assign('popupContent', $popupContent); $interface->display('popup-wrapper.tpl'); } else { $interface->setTemplate('eContentSupport.tpl'); $interface->display('layout.tpl'); } } }
function sendEmail($to, $from, $message) { global $interface; global $configArray; $id = $_REQUEST['id']; $eContentRecord = new EContentRecord(); $eContentRecord->id = $id; $eContentRecord->find(true); $subject = translate("Library Catalog Record") . ": " . $eContentRecord->title; $interface->assign('from', $from); $emailDetails = $eContentRecord->title . "\n"; if (strlen($eContentRecord->author) > 0) { $emailDetails .= "by: {$eContentRecord->author}\n"; } $interface->assign('emailDetails', $emailDetails); $interface->assign('id', $id); $interface->assign('message', $message); $body = $interface->fetch('Emails/eContent-record.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $configArray['Site']['email'], $subject, $body, $from); }
function sendEmail() { global $interface; global $configArray; $to = strip_tags($_REQUEST['to']); $from = strip_tags($_REQUEST['from']); $message = $_REQUEST['message']; $id = $_REQUEST['id']; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $recordDriver = new GroupedWorkDriver($id); $interface->assign('recordDriver', $recordDriver); if (isset($_REQUEST['related_record'])) { $relatedRecord = $_REQUEST['related_record']; require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php'; $recordDriver = new GroupedWorkDriver($id); $relatedRecords = $recordDriver->getRelatedRecords(); foreach ($relatedRecords as $curRecord) { if ($curRecord['id'] = $relatedRecord) { if (isset($curRecord['callNumber'])) { $interface->assign('callnumber', $curRecord['callNumber']); } if (isset($curRecord['shelfLocation'])) { $interface->assign('shelfLocation', strip_tags($curRecord['shelfLocation'])); } } } } $subject = translate("Library Catalog Record") . ": " . $recordDriver->getTitle(); $interface->assign('from', $from); $interface->assign('emailDetails', $recordDriver->getEmail()); $interface->assign('recordID', $recordDriver->getUniqueID()); if (strpos($message, 'http') === false && strpos($message, 'mailto') === false && $message == strip_tags($message)) { $interface->assign('message', $message); $body = $interface->fetch('Emails/grouped-work-email.tpl'); require_once ROOT_DIR . '/sys/Mailer.php'; $mail = new VuFindMailer(); $emailResult = $mail->send($to, $configArray['Site']['email'], $subject, $body, $from); if ($emailResult === true) { $result = array('result' => true, 'message' => 'Your e-mail was sent successfully.'); } elseif (PEAR_Singleton::isError($emailResult)) { $result = array('result' => false, 'message' => "Your e-mail message could not be sent: {$emailResult}."); } else { $result = array('result' => false, 'message' => 'Your e-mail message could not be sent due to an unknown error.'); } } else { $result = array('result' => false, 'message' => 'Sorry, we can't send e-mails with html or other data in it.'); } return json_encode($result); }
/** * Send feedback on record. * * @param string $from Message sender address * @param string $message Message to send * * @return mixed Boolean true on success, PEAR_Error on failure. * @access public */ public function sendEmail($from, $message) { global $interface; global $configArray; $institutionDetails = $this->recordDriver->getInstitutionDetails(); $datasources = getExtraConfigArray('datasources'); $to = $institutionDetails['datasource'] == '' ? $configArray['Site']['email'] : $datasources[$institutionDetails['datasource']]['feedbackEmail']; $subject = translate('Feedback on Record') . ': ' . $this->recordDriver->getBreadcrumb(); $interface->assign('from', $from); $interface->assign('emailDetails', $interface->fetch($this->recordDriver->getSearchResult('email'))); $interface->assign('recordID', $this->recordDriver->getUniqueID()); $interface->assign('message', $message); $body = $interface->fetch('Emails/catalog-record.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
function launch() { global $configArray; global $interface; global $user; //Load status information $materialsRequestStatus = new MaterialsRequestStatus(); $materialsRequestStatus->orderBy('isDefault DESC, isOpen DESC, description ASC'); if ($user->hasRole('library_material_requests')) { $homeLibrary = Library::getPatronHomeLibrary(); $materialsRequestStatus->libraryId = $homeLibrary->libraryId; } else { $libraryList[-1] = 'Default'; } $materialsRequestStatus->find(); $allStatuses = array(); $availableStatuses = array(); $defaultStatusesToShow = array(); while ($materialsRequestStatus->fetch()) { $availableStatuses[$materialsRequestStatus->id] = $materialsRequestStatus->description; $allStatuses[$materialsRequestStatus->id] = clone $materialsRequestStatus; if ($materialsRequestStatus->isOpen == 1 || $materialsRequestStatus->isDefault == 1) { $defaultStatusesToShow[] = $materialsRequestStatus->id; } } $interface->assign('availableStatuses', $availableStatuses); if (isset($_REQUEST['statusFilter'])) { $statusesToShow = $_REQUEST['statusFilter']; $_SESSION['materialsRequestStatusFilter'] = $statusesToShow; } elseif (isset($_SESSION['materialsRequestStatusFilter'])) { $statusesToShow = $_SESSION['materialsRequestStatusFilter']; } else { $statusesToShow = $defaultStatusesToShow; } $interface->assign('statusFilter', $statusesToShow); //Process status change if needed if (isset($_REQUEST['updateStatus']) && isset($_REQUEST['select'])) { //Look for which titles should be modified $selectedRequests = $_REQUEST['select']; $statusToSet = $_REQUEST['newStatus']; require_once ROOT_DIR . '/sys/Mailer.php'; $mail = new VuFindMailer(); foreach ($selectedRequests as $requestId => $selected) { $materialRequest = new MaterialsRequest(); $materialRequest->id = $requestId; if ($materialRequest->find(true)) { $materialRequest->status = $statusToSet; $materialRequest->dateUpdated = time(); $materialRequest->update(); if ($allStatuses[$statusToSet]->sendEmailToPatron == 1 && $materialRequest->email) { $body = '*****This is an auto-generated email response. Please do not reply.*****'; $body .= "\r\n" . $allStatuses[$statusToSet]->emailTemplate; //Replace tags with appropriate values $materialsRequestUser = new User(); $materialsRequestUser->id = $materialRequest->createdBy; $materialsRequestUser->find(true); foreach ($materialsRequestUser as $fieldName => $fieldValue) { if (!is_array($fieldValue)) { $body = str_replace('{' . $fieldName . '}', $fieldValue, $body); } } foreach ($materialRequest as $fieldName => $fieldValue) { if (!is_array($fieldValue)) { $body = str_replace('{' . $fieldName . '}', $fieldValue, $body); } } $materialsRequestUser->find(true); $mail->send($materialRequest->email, $configArray['Site']['email'], "Your Materials Request Update", $body, $configArray['Site']['email']); } } } } $availableFormats = MaterialsRequest::getFormats(); $interface->assign('availableFormats', $availableFormats); $defaultFormatsToShow = array_keys($availableFormats); if (isset($_REQUEST['formatFilter'])) { $formatsToShow = $_REQUEST['formatFilter']; $_SESSION['materialsRequestFormatFilter'] = $formatsToShow; } elseif (isset($_SESSION['materialsRequestFormatFilter'])) { $formatsToShow = $_SESSION['materialsRequestFormatFilter']; } else { $formatsToShow = $defaultFormatsToShow; } $interface->assign('formatFilter', $formatsToShow); //Get a list of all materials requests for the user $allRequests = array(); if ($user) { $materialsRequests = new MaterialsRequest(); $materialsRequests->joinAdd(new Location(), "LEFT"); $materialsRequests->joinAdd(new MaterialsRequestStatus()); $materialsRequests->joinAdd(new User(), 'INNER', 'user'); $materialsRequests->selectAdd(); $materialsRequests->selectAdd('materials_request.*, description as statusLabel, location.displayName as location, firstname, lastname, ' . $configArray['Catalog']['barcodeProperty'] . ' as barcode'); if ($user->hasRole('library_material_requests')) { //Need to limit to only requests submitted for the user's home location $userHomeLibrary = Library::getPatronHomeLibrary(); $locations = new Location(); $locations->libraryId = $userHomeLibrary->libraryId; $locations->find(); $locationsForLibrary = array(); while ($locations->fetch()) { $locationsForLibrary[] = $locations->locationId; } $materialsRequests->whereAdd('user.homeLocationId IN (' . implode(', ', $locationsForLibrary) . ')'); } if (count($availableStatuses) > count($statusesToShow)) { $statusSql = ""; foreach ($statusesToShow as $status) { if (strlen($statusSql) > 0) { $statusSql .= ","; } $statusSql .= "'" . $materialsRequests->escape($status) . "'"; } $materialsRequests->whereAdd("status in ({$statusSql})"); } if (count($availableFormats) > count($formatsToShow)) { //At least one format is disabled $formatSql = ""; foreach ($formatsToShow as $format) { if (strlen($formatSql) > 0) { $formatSql .= ","; } $formatSql .= "'" . $materialsRequests->escape($format) . "'"; } $materialsRequests->whereAdd("format in ({$formatSql})"); } //Add filtering by date as needed if (isset($_REQUEST['startDate']) && strlen($_REQUEST['startDate']) > 0) { $startDate = strtotime($_REQUEST['startDate']); $materialsRequests->whereAdd("dateCreated >= {$startDate}"); $interface->assign('startDate', $_REQUEST['startDate']); } if (isset($_REQUEST['endDate']) && strlen($_REQUEST['endDate']) > 0) { $endDate = strtotime($_REQUEST['endDate']); $materialsRequests->whereAdd("dateCreated <= {$endDate}"); $interface->assign('endDate', $_REQUEST['endDate']); } $materialsRequests->find(); while ($materialsRequests->fetch()) { $allRequests[] = clone $materialsRequests; } } else { $interface->assign('error', "You must be logged in to manage requests."); } $interface->assign('allRequests', $allRequests); if (isset($_REQUEST['exportSelected'])) { $this->exportToExcel($_REQUEST['select'], $allRequests); } else { $interface->setTemplate('manageRequests.tpl'); $interface->setPageTitle('Manage Materials Requests'); $interface->display('layout.tpl'); } }
/** * Process transactions. Try to register unregistered transactions * and inform on expired transactions. * * @return void * @access public */ public function process() { global $configArray; global $interface; ini_set('display_errors', true); $configArray = $mainConfig = readConfig(); $datasourceConfig = getExtraConfigArray('datasources'); // Set up time zone. N.B. Don't use msg() or other // functions requiring date before this. date_default_timezone_set($configArray['Site']['timezone']); $this->msg("OnlinePayment monitor started"); // Setup Local Database Connection ConnectionManager::connectToDatabase(); // Initialize Mailer $mailer = new VuFindMailer(); $now = new DateTime(); $expiredCnt = 0; $failedCnt = 0; $registeredCnt = 0; $remindCnt = 0; $user = false; $report = array(); // Attempt to re-register paid transactions whose registration has failed. $tr = new Transaction(); foreach ($tr->getFailedTransactions() as $t) { $this->msg(" Registering transaction id {$t->id} / {$t->transaction_id}"); // check if the transaction has not been registered for too long $paid_time = new DateTime($t->paid); $diff = $now->diff($paid_time); $diffHours = $diff->days * 24 + $diff->h; if ($diffHours > $this->expireHours) { if (!isset($report[$t->driver])) { $report[$t->driver] = 0; } $report[$t->driver]++; $expiredCnt++; if (!$t->setTransactionReported($t->transaction_id)) { $this->err(' Failed to update transaction ' . $t->transaction_id . 'as reported'); } $transaction = clone $t; $transaction->complete = Transaction::STATUS_REGISTRATION_EXPIRED; if ($transaction->update($t) === false) { $this->err(' Failed to update transaction ' . $t->transaction_id . 'as expired.'); } else { $this->msg(' Transaction ' . $t->transaction_id . ' expired.'); } } else { if ($user === false || $t->user_id != $user->id) { $user = User::staticGet($t->user_id); } $catalog = ConnectionManager::connectToCatalog(); if ($catalog && $catalog->status) { $account = new User_account(); $account->user_id = $t->user_id; $account->cat_username = $t->cat_username; if ($account->find(true)) { if (!($patron = $catalog->patronLogin($t->cat_username, $account->cat_password))) { $this->err(' Could not perform patron login for transaction ' . $t->transaction_id); $failedCnt++; continue; } } $res = $catalog->markFeesAsPaid($patron, $t->amount); if ($res === true) { if (!$t->setTransactionRegistered($t->transaction_id)) { $this->err(' Failed to update transaction ' . $t->transaction_id . 'as registered'); } $registeredCnt++; } else { $t->setTransactionRegistrationFailed($t->transaction_id, $res); $failedCnt++; $this->msg(' Registration of transaction ' . $t->transaction_id . ' failed'); $this->msg(" {$res}"); } } else { $this->err("Failed to connect to catalog ({$patronId})"); continue; } } } // Report paid and unregistered transactions whose registration // can not be re-tried: $tr = new Transaction(); foreach ($tr->getUnresolvedTransactions($this->reportIntervalHours) as $t) { $this->msg(" Transaction id {$t->transaction_id} still unresolved."); if (!$t->setTransactionReported($t->transaction_id)) { $this->err(' Failed to update transaction ' . $t->transaction_id . ' as reported'); } if (!isset($report[$t->driver])) { $report[$t->driver] = 0; } $report[$t->driver]++; $remindCnt++; } if ($registeredCnt) { $this->msg(" Total registered: {$registeredCnt}"); } if ($expiredCnt) { $this->msg(" Total expired: {$expiredCnt}"); } if ($failedCnt) { $this->msg(" Total failed: {$failedCnt}"); } if ($remindCnt) { $this->msg(" Total to be reminded: {$remindCnt}"); } $configArray = readConfig(); $siteLocal = $configArray['Site']['local']; $interface = new UInterface($siteLocal); // Send report of transactions that need to be resolved manually: foreach ($report as $driver => $cnt) { if ($cnt) { $settings = getExtraConfigArray("VoyagerRestful_{$driver}"); if (!$settings || !isset($settings['OnlinePayment']['errorEmail'])) { $this->err(" Error email for expired transactions not defined for driver {$driver} ({$cnt} expired transactions)"); continue; } $email = $settings['OnlinePayment']['errorEmail']; $this->msg(" [{$driver}] Inform {$cnt} expired transactions for driver {$driver} to {$email}"); $mailer = new VuFindMailer(); $subject = "Finna: ilmoitus tietokannan {$driver} epäonnistuneista verkkomaksuista"; $interface->assign('driver', $driver); $interface->assign('cnt', $cnt); $msg = $interface->fetch('Emails/online-payment-error.tpl'); if (!($result = $mailer->send($email, $this->fromEmail, $subject, $msg))) { $this->err(" Failed to send error email to customer: {$email}"); } } } $this->msg("OnlinePayment monitor completed"); $this->reportErrors(); }
/** * Email the user's pin number to the account on record if any exists. */ function emailPin($barcode) { global $configArray; if ($this->useDb) { $sql = "SELECT name, borrower.borrower#, bbarcode, pin#, email_name, email_address from borrower inner join borrower_barcode on borrower.borrower# = borrower_barcode.borrower# inner join borrower_address on borrower.borrower# = borrower_address.borrower# where bbarcode= '" . mysql_escape_string($barcode) . "'"; try { $sqlStmt = $this->_query($sql); $foundPatron = false; while ($row = $this->_fetch_assoc($sqlStmt)) { $pin = $row['pin#']; $email = $row['email_address']; $foundPatron = true; break; } if ($foundPatron) { if (strlen($email) == 0) { return array('error' => 'Your account does not have an email address on record. Please visit your local library to retrieve your PIN number.'); } require_once ROOT_DIR . '/sys/Mailer.php'; $mailer = new VuFindMailer(); $subject = "PIN number for your Library Card"; $body = "The PIN number for your Library Card is {$pin}. You may use this PIN number to login to your account."; $mailer->send($email, $configArray['Site']['email'], $subject, $body); return array('success' => true, 'pin' => $pin, 'email' => $email); } else { return array('error' => 'Sorry, we could not find an account with that barcode.'); } } catch (PDOException $e) { return array('error' => 'Unable to ready you PIN from the database. Please try again later.'); } } else { $result = array('error' => 'This functionality requires a connection to the database.'); } return $result; }
function sendEmail() { global $interface; $subject = translate('Library Catalog Search Result'); $url = $_REQUEST['sourceUrl']; $to = $_REQUEST['to']; $from = $_REQUEST['from']; $message = $_REQUEST['message']; $interface->assign('from', $from); if (strpos($message, 'http') === false && strpos($message, 'mailto') === false && $message == strip_tags($message)) { $interface->assign('message', $message); $interface->assign('msgUrl', $url); $body = $interface->fetch('Emails/share-link.tpl'); require_once ROOT_DIR . '/sys/Mailer.php'; $mail = new VuFindMailer(); $emailResult = $mail->send($to, $from, $subject, $body); if ($emailResult === true) { $result = array('result' => true, 'message' => 'Your e-mail was sent successfully.'); } elseif (PEAR_Singleton::isError($emailResult)) { $result = array('result' => false, 'message' => "Your e-mail message could not be sent: {$emailResult->message}."); } else { $result = array('result' => false, 'message' => 'Your e-mail message could not be sent due to an unknown error.'); } } else { $result = array('result' => false, 'message' => 'Sorry, we can't send e-mails with html or other data in it.'); } echo json_encode($result); }
/** * Send scheduled alerts * * @return void */ public function send() { global $configArray; global $interface; global $translator; $iso8601 = 'Y-m-d\\TH:i:s\\Z'; ini_set('display_errors', true); $configArray = $mainConfig = readConfig(); $datasourceConfig = getExtraConfigArray('datasources'); $siteLocal = $configArray['Site']['local']; // Set up time zone. N.B. Don't use msg() or other functions requiring date before this. date_default_timezone_set($configArray['Site']['timezone']); $this->msg('Sending scheduled alerts'); // Setup Local Database Connection ConnectionManager::connectToDatabase(); // Initialize Mailer $mailer = new VuFindMailer(); // Find all scheduled alerts $sql = 'SELECT * FROM "search" WHERE "schedule" > 0 ORDER BY user_id'; $s = new SearchEntry(); $s->query($sql); $this->msg('Processing ' . $s->N . ' searches'); $user = false; $interface = false; $institution = false; $todayTime = new DateTime(); while ($s->fetch()) { $lastTime = new DateTime($s->last_executed); if ($s->schedule == 1) { // Daily if ($todayTime->format('Y-m-d') == $lastTime->format('Y-m-d')) { $this->msg('Bypassing search ' . $s->id . ': previous execution too recent (daily, ' . $lastTime->format($iso8601) . ')'); continue; } } elseif ($s->schedule == 2) { // Weekly $diff = $todayTime->diff($lastTime); if ($diff->days < 6) { $this->msg('Bypassing search ' . $s->id . ': previous execution too recent (weekly, ' . $lastTime->format($iso8601) . ')'); continue; } } else { $this->msg('Search ' . $s->id . ': unknown schedule: ' . $s->schedule); continue; } if ($user === false || $s->user_id != $user->id) { $user = User::staticGet($s->user_id); } if (!$user->email || trim($user->email) == '') { $this->msg('User ' . $user->username . ' does not have an email address, bypassing alert ' . $s->id); continue; } $userInstitution = reset(explode(':', $user->username, 2)); if (!$institution || $institution != $userInstitution) { $institution = $userInstitution; if (!isset($datasourceConfig[$institution])) { foreach ($datasourceConfig as $code => $values) { if (isset($values['institution']) && strcasecmp($values['institution'], $institution) == 0) { $institution = $code; break; } } } if (!($configArray = $this->readInstitutionConfig($institution))) { continue; } $configArray['Site']['url'] = $s->schedule_base_url; // Start Interface $interface = new UInterface($siteLocal); $validLanguages = array_keys($configArray['Languages']); $dateFormat = new VuFindDate(); } $language = $user->language; if (!in_array($user->language, $validLanguages)) { $language = $configArray['Site']['language']; } $translator = new I18N_Translator(array($configArray['Site']['local'] . '/lang', $configArray['Site']['local'] . '/lang_local'), $language, $configArray['System']['debug']); $interface->setLanguage($language); $minSO = unserialize($s->search_object); // Check minified search object type $searchObject = SearchObjectFactory::deminify($minSO); if (!$searchObject instanceof SearchObject_Solr) { $this->msg('Search ' . $s->id . ': search object type not supported'); continue; } // Create a new search object to avoid cached defaults for e.g. // hidden filters. $searchObject = SearchObjectFactory::initSearchObject(); $searchObject->deminify($minSO); $searchObject->setSort('first_indexed desc'); $searchTime = time(); $searchDate = gmdate($iso8601, time()); $searchObject->setLimit(50); $searchObject->disableLogging(); $results = $searchObject->processSearch(); if (PEAR::isError($results)) { $this->msg('Search ' . $s->id . ' failed: ' . $results->getMessage()); continue; } if ($searchObject->getResultTotal() < 1) { $this->msg('No results found for search ' . $s->id); continue; } $newestRecordDate = date($iso8601, strtotime($results['response']['docs'][0]['first_indexed'])); $lastExecutionDate = $lastTime->format($iso8601); if ($newestRecordDate < $lastExecutionDate) { $this->msg('No new results for search ' . $s->id . ": {$newestRecordDate} < {$lastExecutionDate}"); } else { $this->msg('New results for search ' . $s->id . ": {$newestRecordDate} >= {$lastExecutionDate}"); $interface->assign('summary', $searchObject->getResultSummary()); $interface->assign('searchDate', $dateFormat->convertToDisplayDate("U", floor($searchTime))); $interface->assign('lastSearchDate', $dateFormat->convertToDisplayDate("U", floor($lastTime->getTimestamp()))); $records = array(); foreach ($results['response']['docs'] as &$doc) { $docDate = date($iso8601, strtotime($doc['first_indexed'])); if ($docDate < $lastExecutionDate) { break; } $record = RecordDriverFactory::initRecordDriver($doc); $records[] = $interface->fetch($record->getSearchResult('email')); } $interface->assign('recordSet', $records); $key = $this->getSecret($user, $s->id); $params = array('id' => $s->id, 'type' => 'alert', 'key' => $key); $unsubscribeUrl = $configArray['Site']['url'] . '/MyResearch/Unsubscribe?' . http_build_query($params); $interface->assign('info', array('time' => $dateFormat->convertToDisplayDate("U", floor($searchObject->getStartTime())), 'url' => $searchObject->renderSearchUrl(), 'searchId' => $searchObject->getSearchId(), 'description' => $searchObject->displayQuery(), 'filters' => $searchObject->getFilterList(), 'hits' => $searchObject->getResultTotal(), 'speed' => round($searchObject->getQuerySpeed(), 2) . "s", 'schedule' => $s->schedule, 'last_executed' => $s->last_executed, 'recordCount' => count($records), 'unsubscribeUrl' => $unsubscribeUrl)); $searchObject->close(); // Load template $message = $interface->fetch('MyResearch/alert-email.tpl'); if (strstr($message, 'Warning: Smarty error:')) { $this->msg("Message template processing failed: {$message}"); continue; } $result = $mailer->send($user->email, $configArray['Site']['email'], translate('Scheduled Alert Results'), $message); if (PEAR::isError($result)) { $this->msg("Failed to send message to {$user->email}: " . $result->getMessage()); continue; } } // Update search date $s->changeLastExecuted($searchDate); } $this->reportErrors(); $this->msg('Scheduled alerts execution completed'); }
/** * Send a Summon email. * * @param string $to Message recipient address * @param string $from Message sender address * @param string $message Message to send * * @return mixed Boolean true on success, PEAR_Error on failure. * @access public */ public function sendEmail($to, $from, $message) { global $interface; $subject = translate("Library Catalog Record") . ": " . $this->record['Title'][0]; $interface->assign('from', $from); $interface->assign('title', $this->record['Title'][0]); $interface->assign('recordID', $_REQUEST['id']); $interface->assign('message', $message); $body = $interface->fetch('Emails/summon-record.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
/** * Send feedback email. * * @return mixed Boolean true on success, PEAR_Error on failure. * @access public */ protected function sendEmail() { global $interface, $configArray; $to = $configArray['Site']['email']; $subject = translate('Feedback') . ': ' . translate($_POST['category']); $name = empty($_POST['name']) ? translate('Anonymous') : $_POST['name']; $email = empty($_POST['email']) ? $configArray['Site']['email'] : $_POST['email']; $from = $email; $body = $interface->fetch('Emails/general-feedback.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
function sendMyListEmail() { // TODO: Implements sending emails of list global $interface, $user; // Get data from AJAX request if (isset($_REQUEST['listId']) && ctype_digit($_REQUEST['listId'])) { $listId = $_REQUEST['listId']; } else { // Invalid listId // TODO } $to = $_REQUEST['to']; $from = $_REQUEST['from']; $message = $_REQUEST['message']; //Load the list require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php'; $list = new UserList(); $list->id = $listId; if ($list->find(true)) { // Build Favorites List $titles = $list->getListTitles(); $interface->assign('listEntries', $titles); // TODO: if not used, i would like to remove // Load the User object for the owner of the list (if necessary): if ($list->public == true || $user && $user->id == $list->user_id) { //The user can access the list require_once ROOT_DIR . '/services/MyResearch/lib/FavoriteHandler.php'; // $favoriteHandler = new FavoriteHandler($titles, $user, $list->id, false); $favoriteHandler = new FavoriteHandler($list, $user, false); $titleDetails = $favoriteHandler->getTitles(count($titles)); // get all titles for email list, not just a page's worth $interface->assign('titles', $titleDetails); $interface->assign('list', $list); if (strpos($message, 'http') === false && strpos($message, 'mailto') === false && $message == strip_tags($message)) { $interface->assign('message', $message); $body = $interface->fetch('Emails/my-list.tpl'); require_once ROOT_DIR . '/sys/Mailer.php'; $mail = new VuFindMailer(); $subject = $list->title; $emailResult = $mail->send($to, $from, $subject, $body); if ($emailResult === true) { $result = array('result' => true, 'message' => 'Your e-mail was sent successfully.'); } elseif (PEAR_Singleton::isError($emailResult)) { $result = array('result' => false, 'message' => "Your e-mail message could not be sent: {$emailResult->message}."); } else { $result = array('result' => false, 'message' => 'Your e-mail message could not be sent due to an unknown error.'); } } else { $result = array('result' => false, 'message' => 'Sorry, we can't send e-mails with html or other data in it.'); } } else { $result = array('result' => false, 'message' => 'You do not have access to this list.'); } } else { $result = array('result' => false, 'message' => 'Unable to read list.'); } return $result; }
/** * Send address change request email * * @param array $patron Patron * @param array $data Array of information to send * @param array $subject String Subject * @param array $template String Email template * * @return mixed Boolean true on success, PEAR_Error on failure. * @access protected */ protected function sendEmail($patron, $data, $subject, $template) { global $interface; global $configArray; $driver = explode('.', $patron['cat_username'], 2); $datasources = getExtraConfigArray('datasources'); if (is_array($driver) && isset($driver[0]) && isset($datasources[$driver[0]]) && (isset($datasources[$driver[0]]['feedbackEmail']) || isset($datasources[$driver[0]]['patronSettingsChangeRequestEmail']))) { $emailSource = $datasources[$driver[0]]; $to = isset($emailSource['patronSettingsChangeRequestEmail']) ? $emailSource['patronSettingsChangeRequestEmail'] : $emailSource['feedbackEmail']; } else { $to = $configArray['Site']['email']; } $profile = $this->catalog->getMyProfile($patron); if (PEAR::isError($profile)) { return $profile; } list($library, $username) = explode('.', $patron['cat_username']); $library = translate(array('text' => $library, 'prefix' => 'source_')); $name = trim((isset($profile['firstname']) ? $profile['firstname'] : '') . ' ' . (isset($profile['lastname']) ? $profile['lastname'] : '')); $interface->assign('library', $library); $interface->assign('username', $username); $interface->assign('name', $name); $interface->assign('email', isset($patron['email']) ? $patron['email'] : ''); $interface->assign('data', $data); $body = $interface->fetch($template); $mail = new VuFindMailer(); return $mail->send($to, $configArray['Site']['email'], $subject, $body); }
/** * Send error email if errors were reported. * * @return void */ protected function reportErrors() { if (!$this->errEmail) { $this->msg('Failed to send error report: no email address specified'); return false; } if ($this->errs) { $mailer = new VuFindMailer(); $from = $this->mainConfig['Site']['email']; $to = $this->errEmail; $subject = 'ReminderTask error <' . gethostname() . '> : ' . get_class($this); $msg = implode(PHP_EOL, $this->errs); $this->msg('--------------'); $this->msg(count($this->errs) . " errors, report sent to {$to}:"); $this->msg($msg); $msg = date('Y-m-d H:i:s') . ' [' . getmypid() . "] " . PHP_EOL . "{$msg}\n"; if (!($result = $mailer->send($to, $from, $subject, $msg))) { $this->msg("Failed to send error email to {$to}"); } $this->msg('--------------'); return $result; } }
/** * Send a record email. * * @param string $to Message recipient address * @param string $from Message sender address * @param string $message Message to send * * @return mixed Boolean true on success, PEAR_Error on failure. * @access public */ public function sendEmail($to, $from, $message) { global $interface; $id = $_POST['recordId']; $record = $this->getRecord($id); $record['id'] = $id; $interface->assign('record', $record); $subject = translate("Library Catalog Record") . ": " . (isset($record['Title'][0]) ? $record['Title'][0] : translate('Title not available')); $interface->assign('from', $from); $interface->assign('emailDetails', $interface->fetch('MetaLib/result-email.tpl')); $interface->assign('recordID', $id); $interface->assign('message', $message); $body = $interface->fetch('Emails/catalog-record.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
/** * Send a record email. * * @param string $to Message recipient address * @param string $from Message sender address * @param string $message Message to send * * @return mixed Boolean true on success, PEAR_Error on failure. * @access public */ public function sendEmail($to, $from, $message) { global $interface; $title = ''; if ($field = $this->record->getField('245')) { if ($sfield = $field->getSubfield('a')) { $title .= $sfield->getData() . ' '; } if ($sfield = $field->getSubfield('b')) { $title .= $sfield->getData(); } } $title = trim($title); $subject = translate("Library Catalog Record") . ": " . $title; $interface->assign('from', $from); $interface->assign('title', $title); $interface->assign('recordID', $this->id); $interface->assign('message', $message); $body = $interface->fetch('Emails/worldcat-record.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
/** * Send due date reminders * * @return void */ public function send() { global $configArray; global $interface; global $translator; $iso8601 = 'Y-m-d\\TH:i:s\\Z'; ini_set('display_errors', true); $configArray = $mainConfig = readConfig(); $datasourceConfig = getExtraConfigArray('datasources'); $siteLocal = $configArray['Site']['local']; // Set up time zone. N.B. Don't use msg() or other functions requiring date before this. date_default_timezone_set($configArray['Site']['timezone']); $this->msg('Sending due date reminders'); // Setup Local Database Connection ConnectionManager::connectToDatabase(); // And index $db = ConnectionManager::connectToIndex(); // Initialize Mailer $mailer = new VuFindMailer(); // Find all scheduled alerts $sql = 'SELECT * FROM "user" WHERE "due_date_reminder" > 0 ORDER BY id'; $user = new User(); $user->query($sql); $this->msg('Processing ' . $user->N . ' users'); $interface = false; $institution = false; $todayTime = new DateTime(); $catalog = ConnectionManager::connectToCatalog(); while ($user->fetch()) { if (!$user->email || trim($user->email) == '') { $this->msg('User ' . $user->username . ' does not have an email address, bypassing due date reminders'); continue; } // Initialize settings and interface $userInstitution = reset(explode(':', $user->username, 2)); if (!$institution || $institution != $userInstitution) { $institution = $userInstitution; if (!isset($datasourceConfig[$institution])) { foreach ($datasourceConfig as $code => $values) { if (isset($values['institution']) && strcasecmp($values['institution'], $institution) == 0) { $institution = $code; break; } } } if (!($configArray = $this->readInstitutionConfig($institution))) { continue; } // Start Interface $interface = new UInterface($siteLocal); $validLanguages = array_keys($configArray['Languages']); $dateFormat = new VuFindDate(); } $language = $user->language; if (!in_array($user->language, $validLanguages)) { $language = $configArray['Site']['language']; } $translator = new I18N_Translator(array($configArray['Site']['local'] . '/lang', $configArray['Site']['local'] . '/lang_local'), $language, $configArray['System']['debug']); $interface->setLanguage($language); // Go through accounts and check loans $account = new User_account(); $account->user_id = $user->id; if (!$account->find(false)) { continue; } $remindLoans = array(); while ($account->fetch()) { $patron = $catalog->patronLogin($account->cat_username, $account->cat_password); if ($patron === null || PEAR::isError($patron)) { $this->msg('Catalog login failed for user ' . $user->id . ', account ' . $account->id . ' (' . $account->cat_username . '): ' . ($patron ? $patron->getMessage() : 'patron not found')); continue; } $loans = $catalog->getMyTransactions($patron); if (PEAR::isError($loans)) { $this->msg('Could not fetch loans for user ' . $user->id . ', account ' . $account->id . ' (' . $account->cat_username . ')'); continue; } foreach ($loans as $loan) { $dueDate = new DateTime($loan['duedate']); if ($todayTime >= $dueDate || $dueDate->diff($todayTime)->days <= $user->due_date_reminder) { // Check that a reminder hasn't been sent already $reminder = new Due_date_reminder(); $reminder->user_id = $user->id; $reminder->loan_id = $loan['item_id']; $reminder->due_date = $dueDate->format($iso8601); if ($reminder->find(false)) { // Reminder already sent continue; } // Store also title for display in email $title = isset($loan['title']) ? $loan['title'] : translate('Title not available'); if (isset($loan['id'])) { $record = $db->getRecord($loan['id']); if ($record && isset($record['title'])) { $title = $record['title']; } } $remindLoans[] = array('loanId' => $loan['item_id'], 'dueDate' => $loan['duedate'], 'dueDateFormatted' => $dueDate->format(isset($configArray['Site']['displayDateFormat']) ? $configArray['Site']['displayDateFormat'] : "m-d-Y"), 'title' => $title); } } } if ($remindLoans) { $this->msg(count($remindLoans) . ' new loans to remind for user ' . $user->id); $interface->assign('date', $dateFormat->convertToDisplayDate("U", floor(time()))); $interface->assign('loans', $remindLoans); $key = $this->getSecret($user, $user->id); $params = array('id' => $user->id, 'type' => 'reminder', 'key' => $key); $unsubscribeUrl = $configArray['Site']['url'] . '/MyResearch/Unsubscribe?' . http_build_query($params); $interface->assign(compact('unsubscribeUrl')); // Load template $message = $interface->fetch('MyResearch/due-date-email.tpl'); if (strstr($message, 'Warning: Smarty error:')) { $this->msg("Message template processing failed: {$message}"); continue; } $result = $mailer->send($user->email, $configArray['Site']['email'], translate('due_date_email_subject'), $message); if (PEAR::isError($result)) { $this->msg("Failed to send message to {$user->email}: " . $result->getMessage()); continue; } // Mark reminders sent foreach ($remindLoans as $loan) { $reminder = new Due_date_reminder(); $reminder->user_id = $user->id; $reminder->loan_id = $loan['loanId']; $reminder->delete(); $dueDate = new DateTime($loan['dueDate']); $reminder->due_date = $dueDate->format($iso8601); $reminder->notification_date = gmdate($iso8601, time()); $reminder->insert(); } } else { $this->msg('No loans to remind for user ' . $user->id); } } $this->reportErrors(); $this->msg('Due date reminders execution completed'); }
/** * Send the email. * * @param string $url URL to include in message * @param string $to Message recipient * @param string $from Message sender * @param string $message Extra note to add to message * @param array $records Details of records to send * * @return mixed Boolean true on success, PEAR_Error on failure. * @access public */ public function sendEmail($url, $to, $from, $message, $records = null) { global $interface; if (!isset($records)) { $records = $this->getRecordDetails($_POST['ids']); } $subject = translate('bulk_email_title'); $interface->assign('from', $from); $interface->assign('message', $message); $interface->assign('msgUrl', $url); $interface->assign('records', $records); $body = $interface->fetch('Emails/records.tpl'); $mail = new VuFindMailer(); return $mail->send($to, $from, $subject, $body); }
function launch() { global $interface; global $configArray; $suggestion = isset($_REQUEST['suggestion']) ? $_REQUEST['suggestion'] : ''; $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : ''; $email = isset($_REQUEST['email']) ? $_REQUEST['email'] : ''; if (isset($_REQUEST['submit'])) { $isValid = true; //Perform validation if (isset($email) && strlen($email) > 0) { if (!preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $_REQUEST['email'])) { $interface->assign('message', 'The email address provided does not appear to be valid.'); $isValid = false; } } if ($isValid && (!isset($suggestion) || strlen($suggestion) == 0)) { $interface->assign('message', 'You must enter a suggestion.'); $isValid = false; } if ($isValid) { //Process the submission $privatekey = $configArray['ReCaptcha']['privateKey']; $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $interface->assign('message', 'The CAPTCHA response was incorrect, please try again.'); $isValid = false; } } if ($isValid) { //Save the form. $userSuggestion = new UserSuggestion(); $userSuggestion->name = $name; $userSuggestion->email = $email; $userSuggestion->suggestion = $suggestion; $userSuggestion->hide = 0; $userSuggestion->internalNotes = ''; $userSuggestion->insert(); //After the suggestion has been inserted, e-mail it to the appropriate user. if (isset($configArray['Site']['suggestionEmail']) && strlen($configArray['Site']['suggestionEmail']) > 0) { $mail = new VuFindMailer(); $to = $configArray['Site']['suggestionEmail']; $from = $configArray['Site']['email']; $replyTo = $email; $subject = "New Suggestion within VuFind"; $body = "Suggestion from: {$name} ({$email})\r\n{$suggestion}"; $mail->send($to, $from, $subject, $body, $replyTo); } //Redirect to the confirmation page header("Location: " . $configArray['Site']['path'] . '/Help/SuggestionConfirm'); die; } } //Display the form asking for input $publickey = $configArray['ReCaptcha']['publicKey']; $captchaCode = recaptcha_get_html($publickey); $interface->assign('captcha', $captchaCode); $interface->assign('name', $name); $interface->assign('email', $email); $interface->assign('suggestion', $suggestion); if (isset($_REQUEST['lightbox'])) { $interface->assign('popupTitle', 'Make a Suggestion'); $interface->assign('lightbox', true); $popupContent = $interface->fetch('Help/suggestion.tpl'); $interface->assign('popupContent', $popupContent); $interface->display('popup-wrapper.tpl'); } else { $interface->assign('lightbox', false); $interface->setPageTitle('Make a Suggestion'); $interface->setTemplate('suggestion.tpl'); $interface->display('layout.tpl'); } }
/** * Email a list of items from the book carts. * * @return void * @access public */ public function emailCartItems() { require_once ROOT_DIR . '/sys/Mailer.php'; // Load the appropriate module based on the "type" parameter: global $configArray; $ids = $_REQUEST['id']; global $configArray; $searchObject = SearchObjectFactory::initSearchObject(); $searchObject->init(); $cartContents = array(); if (count($ids) > 0) { $searchObject->setQueryIDs($ids); $result = $searchObject->processSearch(); $matchingRecords = $searchObject->getResultRecordSet(); foreach ($matchingRecords as $record) { $record['url'] = $configArray['Site']['url'] . "/Record/{$record['id']}/Home"; $cartContents[] = $record; } } global $interface; $subject = translate("Your Book Cart Contents"); $interface->assign('cartContents', $cartContents); $body = $interface->fetch('Emails/bookcart-contents.tpl'); $mail = new VuFindMailer(); $to = $_REQUEST['to']; $from = $configArray['Site']['email']; $result = $mail->send($to, $from, $subject, $body); $this->output(translate('email_success'), JSON::STATUS_OK); }