/**
  * @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;
 }