/** * 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; }
/** * */ public function SaveTransaction() { $ps_item_list = $this->request->getParameter('item_list', pString); $pa_item_list = json_decode($ps_item_list, true); $t_checkout = new ca_object_checkouts(); $va_ret = array('status' => 'OK', 'errors' => array(), 'checkins' => array()); foreach ($pa_item_list as $vn_i => $va_item) { if ($t_checkout->load($va_item['checkout_id'])) { $vn_object_id = $t_checkout->get('object_id'); $t_object = new ca_objects($vn_object_id); if ($t_checkout->isOut()) { try { $t_checkout->checkin($vn_object_id, $va_item['note'], array('request' => $this->request)); $t_user = new ca_users($t_checkout->get('user_id')); $vs_user_name = $t_user->get('ca_users.fname') . ' ' . $t_user->get('ca_users.lname'); $vs_borrow_date = $t_checkout->get('ca_object_checkouts.checkout_date', array('timeOmit' => true)); if ($t_checkout->numErrors() == 0) { $va_ret['checkins'][] = _t('Returned <em>%1</em> (%2) borrowed by %3 on %4', $t_object->get('ca_objects.preferred_labels.name'), $t_object->get('ca_objects.idno'), $vs_user_name, $vs_borrow_date); } else { $va_ret['errors'][] = _t('Could not check in <em>%1</em> (%2): %3', $t_object->get('ca_objects.preferred_labels.name'), $t_object->get('ca_objects.idno'), join("; ", $t_checkout->getErrors())); } } catch (Exception $e) { $va_ret['errors'][] = _t('<em>%1</em> (%2) is not out', $t_object->get('ca_objects.preferred_labels.name'), $t_object->get('ca_objects.idno')); } } else { $va_ret['errors'][] = _t('<em>%1</em> (%2) is not out', $t_object->get('ca_objects.preferred_labels.name'), $t_object->get('ca_objects.idno')); } } } $this->view->setVar('data', $va_ret); $this->render('checkin/ajax_data_json.php'); }