public function Index() { AssetLoadManager::register('bundleableEditor'); $t_comm = new ca_commerce_communications(); $t_user = new ca_users(); $o_result_context = new ResultContext($this->request, 'ca_commerce_communications', 'basic_search_library'); $va_options = array(); $o_db = new Db(); // filtering options foreach (array('created_on' => 'string', 'search' => 'string', 'user_id' => 'int', 'read_status' => 'string') as $vs_f => $vs_type) { if (array_key_exists($vs_f, $_REQUEST)) { $vm_v = $this->request->getParameter($vs_f, pString); $o_result_context->setParameter('caClientCommunicationList_' . $vs_f, $vm_v); } else { $vm_v = $o_result_context->getParameter('caClientCommunicationList_' . $vs_f); } switch ($vs_type) { case 'int': if (strlen($vm_v)) { $vm_v = (int) $vm_v; } break; } if ($vs_f == 'read_status') { $va_options[$vs_f] = $vm_v; switch ($vm_v) { case 'read': $vs_f = 'readOnly'; $vm_v = true; break; case 'unread': $vs_f = 'unreadOnly'; $vm_v = true; break; default: break; } } if ($vs_f == 'user_id') { if (!$this->request->getParameter('client_user_id_autocomplete', pString)) { continue; } $o_search = new UserSearch(); $va_labels = caProcessRelationshipLookupLabel($o_search->search("ca_users.user_id:{$vm_v}"), $t_user, array('stripTags' => true)); if (sizeof($va_labels)) { $va_label = array_pop($va_labels); $va_options['_user_id_display'] = $va_label['label']; } } if ($vs_f != 'search') { $t_comm->set($vs_f, $vm_v); } $va_options[$vs_f] = $vm_v; } if ($pn_transaction_id = $this->request->getParameter('transaction_id', pInteger)) { // if set load messages for this transaction $va_options['transaction_id'] = $pn_transaction_id; } $this->view->setVar('t_communication', $t_comm); $this->view->setVar('filter_options', $va_options); $this->view->setVar('message_list', $t_comm->getMessages($this->request->getUserID(), $va_options)); //$o_result_context->setResultList($va_order_ids); $o_result_context->setAsLastFind(); $o_result_context->saveContext(); $this->render('list_communications_html.php'); }
<a href="#" class="button" style="float: right;" onclick="jQuery('#caClientCommunicationsMessageDisplay').load('<?php print caNavUrl($this->request, 'client/orders', 'Communications', 'ViewMessage', array('communication_id' => $pn_communication_id)); ?> ');"><?php print _t('Cancel'); ?> ›</a> <?php print caFormTag($this->request, 'SendReply', 'caClientCommunicationsReplyForm'); $t_comm = new ca_commerce_communications($pn_communication_id); $vn_to_user_id = $t_comm->get('from_user_id'); if (!preg_match('!' . _t("Re:") . '!i', $vs_subject = $t_comm->get('subject'))) { $vs_subject = _t("Re:") . ' ' . $vs_subject; } $t_comm->clear(); $t_comm->set('subject', $vs_subject); print "<div class='replyMessageHeader'><span class='replyMessageHeaderHeading'>" . _t('Date') . ':</span> ' . caGetLocalizedDateRange($t = time(), $t) . "</div>"; print "<div class='replyMessageHeader'><span class='replyMessageHeaderHeading'>" . _t('To') . ':</span> ' . caClientServicesGetSenderName(array('from_user_id' => $vn_to_user_id)) . "</div>"; foreach ($t_comm->getFormFields() as $vs_f => $va_info) { switch ($vs_f) { case 'subject': case 'message': case 'transaction_id': print $t_comm->htmlFormElement($vs_f) . "<br/>\n"; break; } } print caHTMLHiddenInput('transaction_id', array('value' => $t_transaction->getPrimaryKey())); print caFormSubmitButton($this->request, __CA_NAV_BUTTON_SAVE__, _t("Send"), 'caClientCommunicationsReplyForm'); ?> </form>
/** * @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; }