private function sendPasswordResetMail($ps_password_reset_token) { if (!($this->getPrimaryKey() > 0)) { return false; } global $g_request; $vs_user_email = $this->get('email'); $vs_app_name = $this->getAppConfig()->get("app_name"); return caSendMessageUsingView($g_request, $vs_user_email, __CA_ADMIN_EMAIL__, "[{$vs_app_name}] " . _t("Information regarding your password"), 'forgot_password.tpl', array('password_reset_token' => $ps_password_reset_token, 'user_name' => $this->get('user_name'), 'site_host' => $this->getAppConfig()->get('site_host'))); }
/** * Perform client services-related periodic tasks */ public function hookPeriodicTask(&$pa_params) { $t_log = new Eventlog(); $o_db = new Db(); if (!(bool) $this->opo_config->get('enable_library_services')) { return true; } if ((bool) $this->opo_config->get('enable_object_checkout')) { $t_user = new ca_users(); $t_checkout = new ca_object_checkouts(); $vs_app_name = $this->opo_config->get('app_display_name'); $vs_sender_name = $this->opo_library_services_config->get('notification_sender_name'); $vs_sender_email = $this->opo_library_services_config->get('notification_sender_email'); if (!is_array($va_administrative_email_addresses = $this->opo_library_services_config->getList('administrative_email_addresses'))) { $va_administrative_email_addresses = array(); } // Periodic "coming due" notices if ($this->opo_library_services_config->get('send_coming_due_notices') && ($vs_interval = $this->opo_library_services_config->get('coming_due_interval'))) { try { $va_items_by_user = ca_object_checkouts::getItemsDueWithin($vs_interval, array('groupBy' => 'user_id', 'template' => $this->opo_library_services_config->get('coming_due_item_display_template'), 'notificationInterval' => $this->opo_library_services_config->get('coming_due_notification_interval'))); foreach ($va_items_by_user as $vn_user_id => $va_items_for_user) { if ($t_user->load($vn_user_id)) { if ($vs_user_email = $t_user->get('email')) { $vs_subject = _t('Notice of items coming due for return'); if (caSendMessageUsingView(null, $vs_user_email, $vs_sender_email, "[{$vs_app_name}] {$vs_subject}", "library_coming_due.tpl", array('subject' => $vs_subject, 'from_user_id' => $vn_user_id, 'sender_name' => $vs_sender_name, 'sender_email' => $vs_sender_email, 'sent_on' => time(), 'items' => $va_items_for_user), null, $va_administrative_email_addresses)) { // mark record foreach ($va_items_for_user as $va_item) { if ($t_checkout->load($va_item['checkout_id'])) { $t_checkout->setMode(ACCESS_WRITE); $t_checkout->set('last_sent_coming_due_email', _t('now')); $t_checkout->update(); if ($t_checkout->numErrors()) { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not mark checkout coming due message sent time because update failed: %1', join("; ", $t_checkout->getErrors())), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } else { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not mark checkout coming due message sent time because checkout id %1 was not found', $va_item['checkout_id']), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } } else { // no email $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('No email address set for user %1 (%2)', $t_user->get('user_name'), trim($t_user->get('fname') . ' ' . $t_user->get('lname'))), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } else { // invalid user $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('User id %1 does not exist', $vn_user_id), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } catch (Exception $e) { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Invalid interval (%1) specified for coming due notices', $vs_interval), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } // Periodic overdue notices if ($this->opo_library_services_config->get('send_overdue_notices')) { try { $va_items_by_user = ca_object_checkouts::getOverdueItems(array('groupBy' => 'user_id', 'template' => $this->opo_library_services_config->get('overdue_item_display_template'), 'notificationInterval' => $this->opo_library_services_config->get('overdue_notification_interval'))); foreach ($va_items_by_user as $vn_user_id => $va_items_for_user) { if ($t_user->load($vn_user_id)) { if ($vs_user_email = $t_user->get('email')) { $vs_subject = _t('Notice of overdue items'); if (caSendMessageUsingView(null, $vs_user_email, $vs_sender_email, "[{$vs_app_name}] {$vs_subject}", "library_overdue.tpl", array('subject' => $vs_subject, 'from_user_id' => $vn_user_id, 'sender_name' => $vs_sender_name, 'sender_email' => $vs_sender_email, 'sent_on' => time(), 'items' => $va_items_for_user), null, $va_administrative_email_addresses)) { // mark record foreach ($va_items_for_user as $va_item) { if ($t_checkout->load($va_item['checkout_id'])) { $t_checkout->setMode(ACCESS_WRITE); $t_checkout->set('last_sent_overdue_email', _t('now')); $t_checkout->update(); if ($t_checkout->numErrors()) { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not mark checkout overdue message sent time because update failed: %1', join("; ", $t_checkout->getErrors())), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } else { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not mark checkout overdue message sent time because checkout id %1 was not found', $va_item['checkout_id']), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } } else { // no email $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('No email address set for user %1 (%2)', $t_user->get('user_name'), trim($t_user->get('fname') . ' ' . $t_user->get('lname'))), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } else { // invalid user $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('User id %1 does not exist', $vn_user_id), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } catch (Exception $e) { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Failed to get overdue list'), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } // Notice when reservation becomes available if ($this->opo_library_services_config->get('send_reservation_available_notices')) { try { $va_items_by_user = ca_object_checkouts::getReservedAvailableItems(array('groupBy' => 'user_id', 'template' => $this->opo_library_services_config->get('overdue_item_display_template'), 'notificationInterval' => $this->opo_library_services_config->get('reservation_available_notification_interval'))); foreach ($va_items_by_user as $vn_user_id => $va_items_for_user) { if ($t_user->load($vn_user_id)) { if ($vs_user_email = $t_user->get('email')) { $vs_subject = _t('Notice of reserved available items'); if (caSendMessageUsingView(null, $vs_user_email, $vs_sender_email, "[{$vs_app_name}] {$vs_subject}", "library_reservation_available.tpl", array('subject' => $vs_subject, 'from_user_id' => $vn_user_id, 'sender_name' => $vs_sender_name, 'sender_email' => $vs_sender_email, 'sent_on' => time(), 'items' => $va_items_for_user), null, $va_administrative_email_addresses)) { // mark record foreach ($va_items_for_user as $va_item) { if ($t_checkout->load($va_item['checkout_id'])) { $t_checkout->setMode(ACCESS_WRITE); $t_checkout->set('last_reservation_available_email', _t('now')); $t_checkout->update(); if ($t_checkout->numErrors()) { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not mark reserved available message sent time because update failed: %1', join("; ", $t_checkout->getErrors())), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } else { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not mark reserved available message sent time because checkout id %1 was not found', $va_item['checkout_id']), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } } else { // no email $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('No email address set for user %1 (%2)', $t_user->get('user_name'), trim($t_user->get('fname') . ' ' . $t_user->get('lname'))), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } else { // invalid user $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('User id %1 does not exist', $vn_user_id), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } catch (Exception $e) { $t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Failed to get reserved available list'), 'SOURCE' => 'libraryServicesPlugin->hookPeriodicTask')); } } } return true; }
/** * @param int $pn_transaction_id, * @param string $ps_type = "O" for sales order, "L" for library loans * @param int $pn_source * @param string $ps_subject * @param string $ps_message * @param array $pa_options */ public static function sendMessage($pn_transaction_id, $ps_type, $pn_source, $pn_user_id, $ps_subject, $ps_message, $pa_options = null) { global $g_request; $t_comm = new ca_commerce_communications(); $t_comm->setMode(ACCESS_WRITE); $t_comm->set('transaction_id', $pn_transaction_id); $t_comm->set('communications_type', $ps_type); $t_comm->set('source', $pn_source); $t_comm->set('subject', $ps_subject); $t_comm->set('message', $ps_message); $t_comm->set('from_user_id', $pn_user_id); $t_comm->insert(); if ($pn_source == __CA_COMMERCE_COMMUNICATION_SOURCE_INSTITUTION__ && $g_request) { $t_trans = new ca_commerce_transactions($pn_transaction_id); $t_from_user = new ca_users($pn_user_id); $t_to_user = new ca_users($t_trans->get('user_id')); $vs_sender_email = $t_from_user->get('email'); $vs_to_email = $t_to_user->get('email'); caSendMessageUsingView($g_request, $vs_to_email, $vs_sender_email, "[" . $t_from_user->getAppConfig()->get('app_display_name') . "] {$ps_subject}", "commerce_communication.tpl", array('subject' => $ps_subject, 'message' => $ps_message, 'from_user_id' => $pn_user_id, 'sender_name' => $t_from_user->get('fname') . ' ' . $t_from_user->get('lname'), 'sender_email' => $t_from_user->get('email'), 'sent_on' => time(), 'login_url' => $t_from_user->getAppConfig()->get('site_host') . '/' . $t_from_user->getAppConfig()->get('ca_url_root'))); } return $t_comm; }
/** * */ public function sendEmailPaymentNotification($pb_success, $ps_payment_gateway, $pa_payment_response) { global $g_request; if (!$g_request) { return null; } $va_administrative_email_addresses = array(); $vs_login_url = $this->opo_client_services_config->get('notification_login_url'); $vs_app_name = $this->getAppConfig()->get('app_display_name'); $t_trans = new ca_commerce_transactions($this->get('transaction_id')); $t_to_user = new ca_users($t_trans->get('user_id')); $vs_to_email = $t_to_user->get('email'); $vs_sender_name = $this->opo_client_services_config->get('notification_sender_name'); $vs_sender_email = $this->opo_client_services_config->get('notification_sender_email'); $vs_order_date = date("m/d/Y@g:i a", (int) $this->get('created_on', array('GET_DIRECT_DATE' => true))); if (!is_array($va_administrative_email_addresses = $this->opo_client_services_config->getList('administrative_email_addresses'))) { return false; } if ($pb_success) { $vs_subject = _t('Payment for order (%2) posted on %1 has been processed successfully', $vs_order_date, $this->getOrderNumber()); caSendMessageUsingView($g_request, $va_administrative_email_addresses, $vs_sender_email, "[{$vs_app_name}] {$vs_subject}", "commerce_order_payment_success.tpl", array('subject' => $vs_subject, 'sent_on' => time(), 'login_url' => $vs_login_url, 't_order' => $this, 'gateway' => $ps_payment_gateway, 'response' => $pa_payment_response)); } else { $vs_subject = _t('Payment for order (%2) posted on %1 failed', $vs_order_date, $this->getOrderNumber()); caSendMessageUsingView($g_request, $va_administrative_email_addresses, $vs_sender_email, "[{$vs_app_name}] {$vs_subject}", "commerce_order_payment_failure.tpl", array('subject' => $vs_subject, 'sent_on' => time(), 'login_url' => $vs_login_url, 't_order' => $this, 'gateway' => $ps_payment_gateway, 'response' => $pa_payment_response)); } return true; }
/** * Import metadata using a mapping * * @param RequestHTTP $po_request The current request * @param string $ps_source A path to a file or directory of files to import * @param string $ps_importer The code of the importer (mapping) to use * @param string $ps_input_format The format of the source data * @param array $pa_options * progressCallback = * reportCallback = * sendMail = * dryRun = * importAllDatasets = * log = log directory path * logLevel = KLogger constant for minimum log level to record. Default is KLogger::INFO. Constants are, in descending order of shrillness: * KLogger::EMERG = Emergency messages (system is unusable) * KLogger::ALERT = Alert messages (action must be taken immediately) * KLogger::CRIT = Critical conditions * KLogger::ERR = Error conditions * KLogger::WARN = Warnings * KLogger::NOTICE = Notices (normal but significant conditions) * KLogger::INFO = Informational messages * KLogger::DEBUG = Debugging messages */ public static function importMetadata($po_request, $ps_source, $ps_importer, $ps_input_format, $pa_options = null) { $va_errors = $va_noticed = array(); $vn_start_time = time(); $o_config = Configuration::load(); if (!ca_data_importers::mappingExists($ps_importer)) { $va_errors['general'] = array('idno' => "*", 'label' => "*", 'errors' => array(_t('Importer %1 does not exist', $ps_importer)), 'status' => 'ERROR'); return false; } $vs_log_dir = caGetOption('log', $pa_options, null); $vs_log_level = caGetOption('logLevel', $pa_options, "INFO"); $vb_import_all_datasets = caGetOption('importAllDatasets', $pa_options, false); $vb_dry_run = caGetOption('dryRun', $pa_options, false); $vn_log_level = BatchProcessor::_logLevelStringToNumber($vs_log_level); if (!isURL($ps_source) && is_dir($ps_source)) { $va_sources = caGetDirectoryContentsAsList($ps_source, true, false, false, false); } else { $va_sources = array($ps_source); } $vn_file_num = 0; foreach ($va_sources as $vs_source) { $vn_file_num++; if (!ca_data_importers::importDataFromSource($vs_source, $ps_importer, array('fileNumber' => $vn_file_num, 'numberOfFiles' => sizeof($va_sources), 'logDirectory' => $o_config->get('batch_metadata_import_log_directory'), 'request' => $po_request, 'format' => $ps_input_format, 'showCLIProgressBar' => false, 'useNcurses' => false, 'progressCallback' => isset($pa_options['progressCallback']) ? $pa_options['progressCallback'] : null, 'reportCallback' => isset($pa_options['reportCallback']) ? $pa_options['reportCallback'] : null, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level, 'dryRun' => $vb_dry_run, 'importAllDatasets' => $vb_import_all_datasets))) { $va_errors['general'][] = array('idno' => "*", 'label' => "*", 'errors' => array(_t("Could not import source %1", $ps_source)), 'status' => 'ERROR'); return false; } else { $va_notices['general'][] = array('idno' => "*", 'label' => "*", 'errors' => array(_t("Imported data from source %1", $ps_source)), 'status' => 'SUCCESS'); //return true; } } $vn_elapsed_time = time() - $vn_start_time; if (isset($pa_options['sendMail']) && $pa_options['sendMail']) { if ($vs_email = trim($po_request->user->get('email'))) { caSendMessageUsingView($po_request, array($vs_email => $po_request->user->get('fname') . ' ' . $po_request->user->get('lname')), __CA_ADMIN_EMAIL__, _t('[%1] Batch metadata import completed', $po_request->config->get('app_display_name')), 'batch_metadata_import_completed.tpl', array('notices' => $va_notices, 'errors' => $va_errors, 'numErrors' => sizeof($va_errors), 'numProcessed' => sizeof($va_notices), 'subjectNameSingular' => _t('row'), 'subjectNamePlural' => _t('rows'), 'startedOn' => caGetLocalizedDate($vn_start_time), 'completedOn' => caGetLocalizedDate(time()), 'elapsedTime' => caFormatInterval($vn_elapsed_time))); } } if (isset($pa_options['sendSMS']) && $pa_options['sendSMS']) { SMS::send($po_request->getUserID(), _t("[%1] Metadata import processing for begun at %2 is complete", $po_request->config->get('app_display_name'), caGetLocalizedDate($vn_start_time))); } return array('errors' => $va_errors, 'notices' => $va_notices, 'processing_time' => caFormatInterval($vn_elapsed_time)); }
/** * @param array $pa_options * progressCallback = * reportCallback = * sendMail = * log = log directory path * logLevel = KLogger loglevel. Default is "INFO" */ public static function importMetadata($po_request, $ps_source, $ps_importer, $ps_input_format, $pa_options = null) { $va_errors = $va_noticed = array(); $vn_start_time = time(); $o_config = Configuration::load(); if (!ca_data_importers::mappingExists($ps_importer)) { $va_errors['general'] = array('idno' => "*", 'label' => "*", 'errors' => array(_t('Importer %1 does not exist', $ps_importer)), 'status' => 'ERROR'); return false; } $vs_log_dir = isset($pa_options['log']) ? $pa_options['log'] : null; $vn_log_level = KLogger::INFO; switch ($vs_log_level = isset($pa_options['logLevel']) ? $pa_options['logLevel'] : "INFO") { case 'DEBUG': $vn_log_level = KLogger::DEBUG; break; case 'NOTICE': $vn_log_level = KLogger::NOTICE; break; case 'WARN': $vn_log_level = KLogger::WARN; break; case 'ERR': $vn_log_level = KLogger::ERR; break; case 'CRIT': $vn_log_level = KLogger::CRIT; break; case 'ALERT': $vn_log_level = KLogger::ALERT; break; default: case 'INFO': $vn_log_level = KLogger::INFO; break; } if (!ca_data_importers::importDataFromSource($ps_source, $ps_importer, array('logDirectory' => $o_config->get('batch_metadata_import_log_directory'), 'request' => $po_request, 'format' => $ps_input_format, 'showCLIProgressBar' => false, 'useNcurses' => false, 'progressCallback' => isset($pa_options['progressCallback']) ? $pa_options['progressCallback'] : null, 'reportCallback' => isset($pa_options['reportCallback']) ? $pa_options['reportCallback'] : null, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level))) { $va_errors['general'] = array('idno' => "*", 'label' => "*", 'errors' => array(_t("Could not import source %1", $vs_data_source)), 'status' => 'ERROR'); return false; } else { $va_notices['general'] = array('idno' => "*", 'label' => "*", 'errors' => array(_t("Imported data from source %1", $vs_data_source)), 'status' => 'SUCCESS'); //return true; } $vn_elapsed_time = time() - $vn_start_time; if (isset($pa_options['sendMail']) && $pa_options['sendMail']) { if ($vs_email = trim($po_request->user->get('email'))) { caSendMessageUsingView($po_request, array($vs_email => $po_request->user->get('fname') . ' ' . $po_request->user->get('lname')), __CA_ADMIN_EMAIL__, _t('[%1] Batch metadata import completed', $po_request->config->get('app_display_name')), 'batch_metadata_import_completed.tpl', array('notices' => $va_notices, 'errors' => $va_errors, 'numErrors' => sizeof($va_errors), 'numProcessed' => sizeof($va_notices), 'subjectNameSingular' => _t('row'), 'subjectNamePlural' => _t('rows'), 'startedOn' => $vs_started_on, 'completedOn' => caGetLocalizedDate(time()), 'elapsedTime' => caFormatInterval($vn_elapsed_time))); } } if (isset($pa_options['sendSMS']) && $pa_options['sendSMS']) { SMS::send($po_request->getUserID(), _t("[%1] Metadata import processing for begun at %2 is complete", $po_request->config->get('app_display_name'), $vs_started_on)); } return array('errors' => $va_errors, 'notices' => $va_notices, 'processing_time' => caFormatInterval($vn_elapsed_time)); }