10 require_once(
"$admLibrary/userSearch.i");
11 $parameters = array(
"a" => array(
"operation" =>
"",
"payload" =>
"",
"mode" =>
"",
"parentId" =>
"",
"message" =>
"",
"subject" =>
"",
"markUnread" =>
""));
12 $string = array(
"filter" => FILTER_DEFAULT);
13 HCU_ImportVars($parameters,
"a", array(
"operation" => $string,
"payload" => $string,
"mode" => $string,
"parentId" => $string,
"message" => $string,
"subject" => $string,
14 "markUnread" => $string));
15 extract($parameters[
"a"]);
17 $operation = isset($operation) ? trim($operation) :
"";
18 $payload = !isset($payload) ?
"" : trim($payload);
22 try { $userId = HCU_PayloadDecode($Cu, $payload); }
catch(exception $e) {}
23 $userId = isset($userId) ? $userId[
"user_id"] :
null;
26 $mode = isset($mode) ? trim($mode) :
"";
27 $parentId = isset($parentId) ? trim($parentId) :
"";
28 $message = isset($message) ? trim($message) :
"";
29 $subject = isset($subject) ? trim($subject) :
"";
31 if ($operation !=
"") {
33 if ($operation ==
"readSecureMessages" && $ft == 20) {
34 $returnArray = readSecureMessages($dbh, $Cu, $mode, $userId, $showSQL);
35 }
else if ($operation ==
"readThread" && $ft == 20) {
36 $returnArray = readThread($dbh, $Cu, $parentId, $userId,
true);
37 }
else if ($operation ==
"markReadState") {
38 $returnArray = MarkReadState($dbh, $Cu, $parentId, $markUnread);
39 }
else if (isset($userId)) {
41 case "readSecureMessages":
42 $returnArray = readSecureMessages($dbh, $Cu, $mode, $userId, $showSQL);
44 case "sendSecureMessage":
45 $returnArray = sendSecureMessage($dbh, $Cu, $Cn, $message, $subject, $userId, $parentId);
48 $returnArray = readThread($dbh, $Cu, $parentId, $userId);
51 $returnArray = deleteThread($dbh, $Cu, $parentId, $userId);
54 $returnArray = array(
"error" => array(
"Operation not specified: '$operation'"),
"record" => array(),
"sql" => array());
57 $returnArray = array(
"error" =>
"No User Found",
"record" => array(),
"sql" => array());
60 header(
'Content-type: application/json');
62 unset($returnArray[
"sql"]);
64 print HCU_JsonEncode($returnArray);
68 printPage(
"$menu_link?ft=$ft",
true, $payload, readSecureMessages($dbh, $Cu, 1, $userId, $showSQL));
70 <div
class=
'noUserFound'><div>No
User Found</div></div>
72 }
else if ($ft == 20) {
73 printPage(
"$menu_link?ft=$ft",
false,
"",
null);
88 function MarkReadState($dbh, $Cu, $parentId, $markUnread) {
91 if ($parentId ==
"") {
92 throw new exception(
"Parent id is required.", 1);
94 if (!is_numeric($parentId)) {
95 throw new exception(
"Parent id is not numeric.", 2);
97 if (!in_array($markUnread, array(
"Y",
"N"))) {
98 throw new exception(
"Mark unread is invalid.", 3);
100 $markUnreadDB = $markUnread ===
"Y" ?
"true" :
"false";
101 $sql =
"update cuadmeco set unread = $markUnreadDB where cu = '$Cu' and messageid = $parentId and origination = 1;";
103 $sth = db_query($sql, $dbh);
105 throw new exception(
"Check query failed.", 4);
107 $returnArray = array(
"error" => array(),
"code" =>
"000",
"sql" => $sqls,
"parentId" => $parentId,
"markUnread" => $markUnread);
108 }
catch (exception $e) {
109 $returnArray = array(
"error" => array($e->getMessage()),
"code" => $e->getCode(),
"sql" => $sqls);
127 function getSecureMessageFilterSort($dontCompile =
false) {
128 $parameters = array(
"a" => array(
"hasFilter" =>
"",
"duration" =>
"",
"show" =>
"",
"sortField" =>
"",
"sortDir" =>
""));
129 $string = array(
"filter" => FILTER_SANITIZE_STRING);
130 HCU_ImportVars($parameters,
"a", array(
"hasFilter" => $string,
"duration" => $string,
"show" => $string,
"sortField" => $string,
"sortDir" => $string));
131 extract($parameters[
"a"]);
132 $hasFilter = isset($hasFilter) ? trim($hasFilter) :
"";
133 $duration = isset($duration) ? trim($duration) :
"";
134 $show = isset($show) ? trim($show) :
"";
135 $showDir = isset($sortDir) ? trim($sortDir) :
"";
136 $sortField = isset($sortField) ? trim($sortField) :
"";
139 if ($hasFilter !=
"Y") {
140 throw new exception(
"Filter is not defined.", 1);
142 if ($duration ==
"") {
143 throw new exception(
"Duration is not defined.", 2);
146 throw new exception(
"Show is not defined.", 3);
148 if ($sortField ==
"") {
149 throw new exception(
"Sort field is not defined.", 5);
151 if ($sortDir ==
"") {
152 throw new exception(
"Sort dir is not defined.", 7);
154 if (!is_numeric($duration) || $duration < 1 || $duration > 3) {
155 throw new exception(
"Duration is invalid.", 4);
157 if (!is_numeric($show) || $show < 1 || $show > 3) {
158 throw new exception(
"Show is invalid.", 6);
160 if (!in_array($sortDir, array(
"asc",
"desc"))) {
161 throw new exception(
"Sort dir is invalid.", 8);
163 if (!in_array($sortField, array(
"messageid",
"parentid",
"date",
"unread",
"memdeleted",
"admdeleted",
"origination",
"subject",
"user_id"))) {
164 throw new exception(
"Sort field is invalid.", 9);
166 }
catch(exception $e) {
176 $filter[] = array(
"field" =>
"origination",
"operator" =>
"eq",
"value" => $show == 2 ? 0 : 1);
178 $filter[] = array(
"field" =>
"unread",
"operator" =>
"eq",
"value" =>
"Y");
180 $filter = HCU_JsonEncode($filter);
182 $sort = array(array(
"field" => $sortField,
"dir" => $sortDir));
183 $sort = HCU_JsonEncode($sort);
189 return array(
"filter" => $filter,
"sort" => $sort,
"show" => $show,
"duration" => $duration,
"sortDir" => $sortDir,
"sortField" => $sortField);
205 function deleteThread($dbh, $Cu, $parentId, $userId) {
208 if ($parentId ==
"") {
209 throw new exception(
"Parent id is required.", 1);
211 if (!is_numeric($parentId)) {
212 throw new exception(
"Parent id is not numeric.", 2);
214 $parentId = intval($parentId);
217 $sql =
"select 'FOUND' from cuadmeco where cu = '$Cu' and parentid = $parentId and user_id <> $userId";
219 $sth = db_query($sql, $dbh);
221 throw new exception(
"Check query failed.", 4);
223 if (db_num_rows($sth) > 0) {
224 throw new exception(
"Wrong user.", 5);
227 $updateSQL =
"update cuadmeco set admdeleted = true where cu = '$Cu' and parentid = $parentId";
228 $deleteSQL =
"delete from cuadmeco where cu = '$Cu' and parentid = $parentId and admdeleted and memdeleted";
229 $sqls[] = $updateSQL;
230 $sqls[] = $deleteSQL;
231 $sth = db_query(
"$updateSQL; $deleteSQL;",$dbh);
234 throw new exception(
"Deletion failed.", 3);
236 }
catch(exception $e) {
237 return array(
"error" => array($e->getMessage()),
"code" => $e->getCode(),
"sql" => $sqls);
239 return array(
"error" => array(),
"code" => 0,
"sql" => $sqls);
261 function readThread($dbh, $Cu, $parentId, $userId, $getUserPayload =
false) {
264 if ($parentId ==
"") {
265 throw new exception(
"Parent id is required.", 1);
267 if (!is_numeric($parentId)) {
268 throw new exception(
"Parent id is not numeric.", 2);
270 $parentId = intval($parentId);
273 if (isset($userId)) {
274 $sql =
"select 'FOUND' from cuadmeco where cu = '$Cu' and parentid = $parentId and user_id <> $userId";
276 $sth = db_query($sql, $dbh);
278 throw new exception(
"Check query failed.", 8);
280 if (db_num_rows($sth) > 0) {
281 throw new exception(
"Wrong user.", 9);
285 $tz = GetCreditUnionTimezone($dbh, $Cu);
287 $setSQL =
"set time zone '$tz'";
288 $querySQL =
"select a.messageid, a.user_id, u.user_name, a.date, to_char(a.date, 'TZ') as timezone, a.origination, a.subject, a.messagetext, a.admin, au.realname as adminname 289 from cuadmeco a left join {$Cu}user u on u.user_id = a.user_id left join cuadminusers au on a.admin = au.user_name and a.cu = au.cu 290 where a.cu = '$Cu' and a.parentid = $parentId order by a.date";
293 $sth = db_query(
"$setSQL; $querySQL;", $dbh);
295 throw new exception(
"Query failed.", 5);
298 $threadData = array();
302 $parentIdFound =
false;
303 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
304 if (intval($row[
"messageid"]) == $parentId) {
305 $userId = intval($row[
"user_id"]);
307 $username =
"NO USER";
309 $username = $row[
"user_name"];
311 $subject = $row[
"subject"];
312 $parentIdFound =
true;
314 $subject = convertMicrosoftCharacters($subject);
315 $subject = nl2br(htmlentities($subject, ENT_QUOTES,
"UTF-8",
false));
317 unset($row[
"user_name"]);
318 unset($row[
"subject"]);
319 unset($row[
"user_id"]);
321 $row[
"messagetext"] = convertMicrosoftCharacters($row[
"messagetext"]);
322 $row[
"messagetext"] = nl2br(htmlentities($row[
"messagetext"], ENT_QUOTES,
"UTF-8",
false));
323 $threadData[] = $row;
327 if ($getUserPayload) {
328 $payloadReturn = readUserSearch($dbh, $Cu, array(
"a" => array(
"id" => $userId)));
329 if ($payloadReturn[
"code"] != 0) {
330 throw new exception(
"Payload return failed.", 10);
332 $payload = $payloadReturn[
"encryption"];
336 $sql =
"update cuadmeco set unread = false where cu = '$Cu' and parentid = $parentId and origination = 1";
338 $sth = db_query($sql, $dbh);
340 throw new exception(
"update unread failed.", 7);
343 if (!$parentIdFound) {
344 throw new exception(
"Parent id not found.", 6);
346 }
catch(exception $e) {
347 return array(
"error" => array($e->getMessage()),
"code" => $e->getCode(),
"sql" => $sqls);
349 return array(
"error" => array(),
"code" => 0,
"sql" => $sqls,
"record" => array(
"username" => $username,
"subject" => $subject,
"userId" => $userId,
"threadData" => $threadData),
350 "payload" => $payload);
368 function sendSecureMessage($dbh, $Cu, $Cn, $message, $subject, $userId, $parentId) {
371 if ($message ==
"") {
372 throw new exception(
"Message is required.", 1);
374 if ($subject ==
"") {
375 throw new exception(
"Subject is required.", 2);
378 throw new exception(
"User id is required.", 203);
380 if ($parentId ==
"") {
381 $parentId = intval($parentId);
382 }
else if (!is_numeric($parentId)) {
383 throw new exception(
"Parent id is not numeric.", 4);
385 if (!is_numeric($userId)) {
386 throw new exception(
"User id is not numeric.", 205);
388 $sql =
"select user_name, email from {$Cu}user where user_id = $userId";
390 $sth = db_query($sql, $dbh);
393 throw new exception(
"Select query failed.", 206);
395 if (db_num_rows($sth) == 0) {
396 throw new exception(
"User not found.", 207);
398 list($username, $userEmail) = db_fetch_array($sth, 0);
401 $sql =
"select email from cuadmnotify where role = 'securemsgfrom' and cu = '$Cu'";
403 $sth = db_query($sql,$dbh);
406 throw new exception(
"From email query failed.", 111);
408 if (db_num_rows($sth) == 0) {
409 throw new exception(
"From email not found.", 112);
412 list($admFrom) = db_fetch_array($sth,0);
413 $admFrom = trim($admFrom);
415 if ($admFrom ==
"") {
416 throw new exception(
"From email is empty.", 113);
420 if (!validateEmail($admFrom)) {
421 throw new exception(
"From email is not valid.", 114);
423 if (!validateEmail($userEmail)) {
424 throw new exception(
"User email is not valid.", 215);
429 $sql =
"select orgname, pname from cuadmin where cu = '$Cu'";
431 $sth = db_query($sql,$dbh);
434 throw new exception(
"Cu query failed.", 16);
436 if (db_num_rows($sth) == 0) {
437 throw new exception(
"CU not found.", 17);
439 list($orgname, $pname) = db_fetch_array($sth, 0);
441 $sql =
"select nextval('cuadmeco_messageid_seq')";
443 $sth = db_query($sql,$dbh);
445 throw new exception(
"Nextval query failed.", 18);
447 if (db_num_rows($sth) == 0) {
448 throw new exception(
"Nextval query failed.", 19);
451 list($messageId) = db_fetch_array($sth, 0);
452 $parentId = $parentId == 0 ? $messageId : $parentId;
454 $tz = GetCreditUnionTimezone($dbh, $Cu);
456 $date =
new DateTime();
457 $date->setTimezone(
new DateTimeZone($tz));
458 $formattedDate = $date->format(
"Y-m-d H:i:s");
459 $formattedTz = $date->format(
"T");
461 $message = prep_save(hcu_displayHtml(preg_replace(
"/[\`\;]/",
"", $message)));
464 $sql =
"insert into cuadmeco (messageid, parentid, cu, user_id, date, unread, memdeleted, admdeleted, origination, subject, messagetext, admin) 465 values ($messageId, $parentId, '$Cu', '$userId', now(), true, false, false, 0, '" . prep_save($subject)
466 .
"', '$message', '$Cn')";
469 $sth = db_query($sql, $dbh);
471 throw new exception(
"Insert failed.", 10);
474 $newMessage = array(
"messageid" => $messageId,
"parentid" => $parentId,
"date" => $formattedDate,
"timezone" => $formattedTz,
475 "unread" =>
"N",
"memdeleted" =>
"N",
"admdeleted" =>
"N",
"origination" => 0,
"subject" => $subject,
"user_id" => $userId,
"username" => $username,
"originalsubject" => $subject);
478 $orgname = isset($orgname) ? trim($orgname) :
"";
479 $pname = isset($pname) ? trim($pname) :
"";
481 $notify->mailto = $userEmail;
482 $notify->mailfrom = $admFrom;
483 $notify->replyto = $admFrom;
484 $notify->subject =
"$orgname Secure Message";
485 $notify->msgbody =
"$orgname has sent you a secure message. Please sign in to $pname to read it.\n\n" . date(
"m/d/Y H:i:s T");
486 $notify->callingfunction = __FUNCTION__;
487 $notify->file = __FILE__;
491 }
catch(exception $e) {
493 if ($e->getCode() >= 200 && $e->getCode() < 300) {
494 $vagueError =
"User email is not set or is invalid. Please make sure the user has set up an email address.";
495 }
else if ($e->getCode() >= 100 && $e->getCode() < 200) {
496 $vagueError =
"Admin email is not set or is invalid. To ensure an email is sent to the user, please enter a 'Secure Message Notification Mailed From' email address.";
498 $vagueError =
"No email sent to user.";
500 return array(
"error" => array($vagueError),
"code" => $e->getCode(),
"sql" => $sqls);
502 return array(
"error" => array(),
"code" => 0,
"sql" => $sqls,
"newMessage" => $newMessage,
"info" =>
"Message has been sent successfully.");
520 function readSecureMessages($dbh, $Cu, $mode, $userId, $showSQL) {
525 throw new exception(
"Mode is required.", 3);
527 if (!is_numeric($mode) || $mode < 1 || $mode > 3) {
528 throw new exception(
"Mode is invalid.", 2);
531 if ($userId !=
"" && !is_numeric($userId)) {
532 throw new exception(
"User id needs to be numeric.", 6);
535 $tz = GetCreditUnionTimezone($dbh, $Cu);
537 $setSQL =
"set time zone '$tz'";
539 $querySQL =
"select o.parentid, b.date, to_char(b.date, 'TZ') as timezone, a.unread, b.origination, o.subject, b.user_id, u.user_name as username from 540 (select parentid, bool_or(unread and origination = 1) as unread, max(messageid) as messageid, bool_and(admdeleted) as deleted from cuadmeco 541 where cu = '$Cu' group by parentid) a 542 inner join cuadmeco b on a.messageid = b.messageid inner join ${Cu}user u on b.user_id = u.user_id inner join cuadmeco o on a.parentid = o.messageid and not a.deleted";
545 $querySQL .=
" and b.user_id = " . intval($userId);
549 $date =
new DateTime();
550 $date = DateTime::createFromFormat(
"Y-m-d", $date->format(
"Y-m-d"));
551 $date->modify(
"-" . ($mode*30) .
" days");
552 $date = $date->format(
"Y-m-d");
554 $querySQL .=
" and cast(b.date as date) >= '$date'";
558 $sth = db_query(
"$setSQL; $querySQL;", $dbh);
560 throw new exception(
"Select query failed.", 1);
562 for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
563 $row[
"unread"] = $row[
"unread"] ==
"t" ?
"Y" :
"N";
565 $row[
"subject"] = preg_replace(
"/[^[ !-~]/",
'', convertMicrosoftCharacters($row[
"subject"]));
568 $returnArray = array(
"error" => array(),
"code" => 0,
"messages" => $messages,
"sql" => $sqls);
569 }
catch(exception $e) {
570 $returnArray = array(
"error" => array($e->getMessage()),
"code" => $e->getCode(),
"messages" => array(),
"sql" => $sqls);
574 unset($returnArray[
"sql"]);
590 function printPage($self, $fromUserHub, $payload, $readData) { ?>
591 <script type=
"text/javascript">
593 <?php
if (!$fromUserHub) {
595 getShowWaitFunctions();
597 printUserSearch($self,
"secureMessagesSearchResponse");
600 var userSupportContents = {};
601 userSupportContents.secureMessages = [];
602 userSupportContents.maxDuration = -1;
603 userSupportContents.payload =
"<?php echo isset($payload) ? $payload : "null"; ?>";
613 $.homecuValidator.setup({ formStatusField:
"formValidateDiv", formValidate:
'filterDiv'});
614 $(
"#externalTabWindow").data(
"preferredHeight", 500);
615 <?php $sortFilter = getSecureMessageFilterSort(); ?>
616 var grid = $(
"#grid").kendoGrid({
619 read:
function (options) {
620 options.success(userSupportContents.secureMessages);
627 parentid: {type:
"number"},
628 date: {type:
"date"},
629 unread: {type:
"string"},
630 origination: {type:
"number"},
631 subject: {type:
"string"},
632 user_id: {type:
"string"},
633 timezone: {type:
"string"},
634 username: {type:
"string"}
638 filter: <?php echo $sortFilter[
"filter"]; ?>,
639 sort: <?php echo $sortFilter[
"sort"]; ?>
642 {field:
"origination", title:
" ", width:
"50px"},
643 {field:
"username", title:
"User", width:
"100px"},
644 {field:
"subject", title:
"Topic"},
645 {field:
"date", title:
"Date", width:
"175px"}
647 rowTemplate: $(
"#rowTemplate").html(),
648 sortable: {allowUnsort:
false},
649 toolbar:
'<a class="k-button k-button-icontext k-grid-createMessage" href="\\#"><span class="fa fa-plus"></span> Add Message</a>' 650 +
'<br><br><span class="hcu-secondary"><span class="vsgSecondary">To mark discussion unread, right-click on message.</span></span>',
652 template:
"<span class=\"hcu-secondary\"><span class=\"vsgSecondary\">No records found.</span></span>" 654 }).data(
"kendoGrid");
656 <?php
if ($fromUserHub) { ?>
657 $(
"#grid").css({maxHeight:
"400px"});
658 $(
"#grid .k-grid-content").css({maxHeight:
"310px"});
661 $(
".showOption:eq(<?php echo intval($sortFilter["show
"]) - 1; ?>)").addClass(
"selected");
662 $(
".durationOption:eq(<?php echo intval($sortFilter["duration
"]) - 1; ?>)").addClass(
"selected");
663 userSupportContents.maxDuration = <?php echo $sortFilter[
"duration"]; ?>;
665 $(
".selected span").addClass(
"fa fa-caret-right");
667 $(
".showOption").on(
"click",
"a",
function() {
668 if (!$(
this).hasClass(
"selected")) {
669 $(
".showOption.selected span").removeClass(
"fa fa-caret-right");
670 $(
".showOption.selected").removeClass(
"selected");
671 var showOption = $(
this).closest(
".showOption");
672 $(showOption).addClass(
"selected");
673 $(showOption).find(
"span").addClass(
"fa fa-caret-right");
674 filterSecureMessages();
679 $(
".durationOption").on(
"click",
"a",
function() {
680 if (!$(
this).hasClass(
"selected")) {
681 $(
".durationOption.selected span").removeClass(
"fa fa-caret-right");
682 $(
".durationOption.selected").removeClass(
"selected");
683 var durationOption = $(
this).closest(
".durationOption");
684 $(durationOption).addClass(
"selected");
685 $(durationOption).find(
"span").addClass(
"fa fa-caret-right");
686 filterSecureMessages();
691 $(
"#findInput").on(
"keyup keydown blur",
function() {
692 filterSecureMessages();
695 <?php
if ($fromUserHub) { ?>
696 $(
"#grid").on(
"click",
".k-grid-createMessage",
function() {
697 openSecureMessageWindow(0);
701 $(
"#grid").on(
"click",
".k-grid-createMessage",
function() {
707 $(
"#grid").on(
"click",
".k-grid-content tr",
function() {
709 var dataItem = grid.dataItem(tr);
710 openSecureMessageWindow(dataItem.parentid, dataItem.userId, dataItem.username);
715 parameters.mode = Number($(
".durationOption.selected").data(
"type"));
716 <?php
if ($fromUserHub) { ?>
717 var data = <?php echo HCU_JsonEncode($readData); ?>;
718 if (data.error.length > 0) {
719 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError )
721 userSupportContents.secureMessages = data.messages;
722 var grid = $(
"#grid").data(
"kendoGrid");
723 grid.dataSource.read();
727 $.post(
"<?php echo $self; ?>&operation=readSecureMessages", parameters,
function(data) {
729 if (data.error.length > 0) {
730 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError )
732 userSupportContents.secureMessages = data.messages;
733 var grid = $(
"#grid").data(
"kendoGrid");
734 grid.dataSource.read();
739 var contextMenu = $(
"#contextMenu").kendoContextMenu({
742 popupCollision:
false,
743 copyAnchorStyles:
false,
744 open:
function(e) { <?php
745 var dataItem = grid.dataItem($(e.target));
746 if (dataItem.unread ==
"Y") {
747 $(e.item).find(
".markReadLi").show();
748 $(e.item).find(
".markUnreadLi").hide();
750 $(e.item).find(
".markReadLi").hide();
751 $(e.item).find(
".markUnreadLi").show();
754 select:
function(e) {
755 var dataItem = grid.dataItem($(e.target));
756 switch($(e.item).text().trim()) {
758 openSecureMessageWindow(dataItem.parentid, dataItem.userId, dataItem.username);
761 MarkReadState(dataItem,
false);
764 MarkReadState(dataItem,
true);
768 }).data(
"kendoContextMenu");
780 function MarkReadState(dataItem, markUnread) {
781 markUnread = markUnread ===
true ?
"Y" :
"N";
782 var parameters = {markUnread: markUnread, parentId: dataItem.parentid};
784 $.post(
"<?php echo $self; ?>&operation=markReadState", parameters,
function(data) {
787 if (data.error.length > 0) {
788 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
792 for(var i = 0; i != userSupportContents.secureMessages.length; i++) {
793 var message = userSupportContents.secureMessages[i];
794 if (message.parentid == data.parentId) {
795 message.unread = data.markUnread;
800 var grid = $(
"#grid").data(
"kendoGrid");
801 grid.dataSource.read();
806 <?php
if (!$fromUserHub) {
812 function secureMessagesSearchResponse(mode, encryptedMessage, dataItem) {
814 case "successfulSelection":
815 case "successfulOneRecord":
816 openSecureMessageWindow(0, dataItem.user_id, dataItem.user_name, encryptedMessage);
833 function filterSecureMessages() {
834 var duration = Number($(
".durationOption.selected").data(
"type"));
835 var show = $(
".showOption.selected").data(
"type");
840 <?php
if (!$fromUserHub) { ?>
841 var find = $(
"#findInput").val().trim();
844 filter.push({logic:
"or", filters: [
846 {field:
"user_id",
operator:
"contains", value: find},
847 {field:
"username",
operator:
"contains", value: find},
848 {field:
"subject",
operator:
"contains", value: find} <?php
853 if (duration > userSupportContents.maxDuration) { <?php
855 }
else if (duration != 3) {
856 var date =
new Date();
857 date.setHours(0,0,0,0);
858 date.setDate(date.getDate() - duration * 30);
859 filter.push({field:
"date",
operator:
"gte", value: date});
864 filter.push({field:
"unread",
operator:
"eq", value:
"Y"}); <?php
866 filter.push({field:
"origination",
operator:
"eq", value: 1});
869 filter.push({field:
"origination",
operator:
"eq", value: 0});
873 var grid = $(
"#grid").data(
"kendoGrid");
876 var parameters = <?php echo !$fromUserHub ?
"{mode: duration}" :
"{mode: duration, payload: userSupportContents.payload}" ?>;
877 $.post(
"<?php echo $self; ?>&operation=readSecureMessages", parameters,
function(data) {
879 if (data.error.length > 0) {
880 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
882 userSupportContents.secureMessages = data.messages;
883 grid.dataSource.filter(filter);
884 grid.dataSource.read();
886 userSupportContents.maxDuration = duration;
890 grid.dataSource.filter(filter);
901 function openSecureMessageWindow(parentId, userId, username, payload) {
902 $(
"#secureMessageWindow").data(
"rereadGrid",
false);
903 var secureMessageWindow = $(
"#secureMessageWindow").data(
"kendoWindow");
904 if (secureMessageWindow ==
null) {
905 secureMessageWindow = $(
"<div id='secureMessageWindow'></div>").appendTo(
"body").kendoWindow({
907 title:
"Edit Thread",
914 if (!$(
"#secureMessageWindow").data(
"invalid")) {
915 if ($(
"#secureMessageWindow").data(
"rereadGrid")) {
916 $(
"#grid").data(
"kendoGrid").dataSource.read();
919 potentiallyCancelChanges();
924 if (window.activeWindows !=
null) {
925 window.activeWindows.pop();
929 $(
"#secureMessageWindow").data(
"invalid",
true);
930 if (window.activeWindows !=
null) {
931 window.activeWindows.push(
this);
933 var kWindow = $(this.wrapper);
934 var left = 1/2 * $(window).width() - 1/2 * $(kWindow).width();
935 $(kWindow).css({position:
"absolute", top:
"10px", left: left +
"px"});
937 activate:
function() {
938 window.setTimeout(scrollThread, 100);
939 thisA = $(
".k-icon.k-i-print").hide().parent();
940 $(thisA).append(
"<i class='fa fa-print fa-xs printBtn'></i>");
941 $(thisA).parent().find(
".printBtn,.k-i-close").css({verticalAlign:
"middle"});
943 actions: [
"print",
"Close"] <?php
944 }).data(
"kendoWindow");
946 $(
"#secureMessageWindow").on(
"click",
".sendBtn",
function() {
947 if ($.homecuValidator.validate()) {
948 $(
"#secureMessageWindow").data(
"invalid",
false);
949 $(
"#secureMessageWindow").removeClass(
"hasError");
951 parameters.message = $(
"#messageInput").val();
953 var dataItem = $(
"#secureMessageWindow").data(
"data");
954 var parentId = dataItem.parentId;
957 parameters.parentId = parentId;
958 parameters.subject =
"Re: " + dataItem.subject;
960 parameters.subject = $(
"[name='topicInput']").val();
962 <?php
if (!$fromUserHub) { ?>
963 parameters.payload = $(
"#secureMessageWindow").data(
"payload");
965 parameters.payload = userSupportContents.payload;
969 $.post(
"<?php echo $self; ?>&operation=sendSecureMessage", parameters,
function(data) {
972 if (data.error.length > 0) {
973 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
976 userSupportContents.secureMessages.push(data.newMessage);
977 $(
"#secureMessageWindow").data(
"rereadGrid",
true);
979 $.homecuValidator.setup({ formStatusField:
"formValidateDiv", formValidate:
'filterDiv'});
980 $.homecuValidator.displayMessage(data.info, $.homecuValidator.settings.statusSuccess);
982 secureMessageWindow.close();
990 $(
"#secureMessageWindow").on(
"click",
".cancelBtn",
function() {
991 secureMessageWindow.close();
995 $(
".k-window:has(#secureMessageWindow)").on(
"click",
".printBtn",
function() {
996 showPrintThreadPopup();
1000 $(
"#secureMessageWindow").on(
"click",
".deleteBtn",
function() {
1001 openDeleteDialogSecureMessages();
1006 $(
"#secureMessageWindow").data(
"data",
null);
1007 $(
"#secureMessageWindow").data(
"payload",
null);
1009 if (parentId == 0) {
1010 $(
"#secureMessageWindow").removeClass(
"hasParent");
1011 var
template = kendo.template($(
"#windowTemplate").html());
1012 var zeData = {parentId: Number(parentId), subject:
"", threadData: []};
1013 if (userId !=
null) {
1014 zeData.userId = userId;
1015 zeData.username = username;
1017 template =
template(zeData);
1018 $(
"#secureMessageWindow").data(
"data", zeData);
1019 secureMessageWindow.setOptions({title:
"Add Message"});
1020 secureMessageWindow.content(
template).open();
1022 $(
"#topicInput").attr(
"required",
"required");
1023 $(
"#topicInput").attr(
"data-required-msg",
"Topic cannot be blank");
1025 $.homecuValidator.setup({formValidate:
'secureMessageForm', formStatusField:
'editValidateDiv'});
1027 $(
".k-window:has(#secureMessageWindow) .k-window-action:eq(0)").hide();
1030 <?php
if (!$fromUserHub) { ?>
1031 $(
"#secureMessageWindow").data(
"payload", payload);
1034 $(
".k-window:has(#secureMessageWindow) .k-window-action:eq(0)").show();
1035 var parameters = {parentId: parentId};
1036 <?php
if ($fromUserHub) { ?>
1037 parameters.payload = userSupportContents.payload;
1040 $.post(
"<?php echo $self; ?>&operation=readThread", parameters,
function(data) {
1043 if (data.error.length > 0) {
1044 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1046 data.record.parentId = parentId;
1047 var
template = kendo.template($(
"#windowTemplate").html());
1048 template =
template(data.record);
1049 secureMessageWindow.setOptions({title:
"User Messages"});
1050 secureMessageWindow.content(
template).open();
1052 $(
"#secureMessageWindow").removeClass(
"hasError");
1053 $(
"#secureMessageWindow").addClass(
"hasParent");
1054 $(
"#secureMessageWindow").data(
"data", data.record);
1056 <?php
if (!$fromUserHub) { ?>
1057 $(
"#secureMessageWindow").data(
"payload", data.payload);
1060 $.homecuValidator.setup({formValidate:
'secureMessageForm', formStatusField:
'editValidateDiv'});
1063 for(var i = 0; i != userSupportContents.secureMessages.length; i++) {
1064 var message = userSupportContents.secureMessages[i];
1065 if (message.parentid == parentId) {
1066 message.unread =
"N";
1067 $(
"#secureMessageWindow").data(
"rereadGrid",
true);
1083 function potentiallyCancelChanges() {
1084 if ($(
"[name='messageInput']").val().trim() ==
"" && ($(
"#secureMessageWindow").data(
"parentId") != 0 || $(
"[name='topicInput']").val().trim() ==
"")) {
1085 $(
"#secureMessageWindow").data(
"invalid",
false);
1086 if ($(
"#secureMessageWindow").data(
"rereadGrid")) {
1087 $(
"#grid").data(
"kendoGrid").dataSource.read();
1089 $(
"#secureMessageWindow").data(
"kendoWindow").close();
1091 var discardChangesDialog = $(
"#discardChangesDialog").data(
"kendoDialog");
1092 if (discardChangesDialog ==
null) {
1093 discardChangesDialog = $(
"<div id='discardChangesDialog'></div>").appendTo(
"body").kendoDialog({
1094 title:
"Discard Changes",
1095 content:
"<p>Changes have been made to this message.</p><p>Do you wish to discard your changes?</p>",
1098 {text:
"Yes", primary:
true, action:
function() {
1099 $(
"#secureMessageWindow").data(
"invalid",
false);
1100 $(
"#secureMessageWindow").data(
"kendoWindow").close();
1101 if ($(
"#secureMessageWindow").data(
"rereadGrid")) {
1102 $(
"#grid").data(
"kendoGrid").dataSource.read();
1108 if (window.activeWindows !=
null) {
1109 window.activeWindows.push(
this);
1113 if (window.activeWindows !=
null) {
1114 window.activeWindows.pop();
1117 }).data(
"kendoDialog");
1119 discardChangesDialog.open();
1129 function showPrintThreadPopup() {
1130 var zeData = $(
"#secureMessageWindow").data(
"data");
1131 var
template = kendo.template($(
"#printTemplate").html());
1132 $(
"#printForm [name='shell']").val(
template(zeData));
1133 template = kendo.template($(
"#printTemplateTitle").html());
1134 $(
"#printForm [name='title']").val(
template(zeData));
1136 var printWindow = window.open(
"",
"printWindow");
1137 $(
"#printForm").submit();
1146 function openDeleteDialogSecureMessages() {
1147 var deleteDialog = $(
"#deleteDialog").data(
"kendoDialog");
1148 if (deleteDialog ==
null) {
1149 deleteDialog = $(
"<div id='deleteDialog'></div>").appendTo(
"body").kendoDialog({
1150 title:
"Delete Thread",
1151 content:
"<p>You are about to delete this thread</p><p>Do you wish to continue?</p>",
1154 {text:
"Yes", primary:
true, action:
function() {
1155 var parentId = $(
"#secureMessageWindow").data(
"data").parentId;
1156 var parameters = {parentId: parentId};
1157 <?php
if ($fromUserHub) { ?>
1158 parameters.payload = userSupportContents.payload;
1160 parameters.payload = $(
"#secureMessageWindow").data(
"payload");
1163 $.post(
"<?php echo $self; ?>&operation=deleteThread", parameters,
function(data) {
1165 if (data.error.length > 0) {
1166 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1168 $(
"#secureMessageWindow").data(
"invalid",
false);
1169 userSupportContents.secureMessages = $.grep(userSupportContents.secureMessages,
function(n,i) { return n.parentid != parentId; });
1170 $(
"#grid").data(
"kendoGrid").dataSource.read();
1171 $(
"#secureMessageWindow").data(
"kendoWindow").close();
1178 if (window.activeWindows !=
null) {
1179 window.activeWindows.push(
this);
1183 if (window.activeWindows !=
null) {
1184 window.activeWindows.pop();
1187 }).data(
"kendoDialog");
1189 deleteDialog.open();
1198 function scrollThread() {
1199 var selector = $(
".threadDiv");
1200 $(selector).height();
1201 $(selector).animate({scrollTop: $(selector).prop(
'scrollHeight')}, {duration: 2000});
1204 <?php
if (!$fromUserHub) { ?> var activeWindows = []; <?php } ?>
1205 $(document).ready(
function() {
1207 <?php
if (!$fromUserHub) { printClickOverlayEvent(); } ?>
1210 <script type=
"text/x-kendo-template" id=
"windowTemplate">
1211 # var editing = parentId != 0; # 1212 <div
class=
"container-fluid hcu-template">
1213 <div
id=
"editValidateDiv" class=
"formValidateDiv k-block k-error-colored row" style=
"display: none;"></div>
1216 <?php printThreadTemplate(); ?>
1219 <div
class=
"row well well-sm hcuSpacer">
1220 <form
id=
"secureMessageForm">
1221 <?php
if (!$fromUserHub) {
1222 dialogPrintInputLine(
"User",
"#: username #",
"userInput", 0,
"disabled",
"text",
true,
"",
false,
false,
true);
1224 dialogPrintInputLine(
"Topic",
"# if (editing) { # Re: #: subject # # } #",
"topicInput", 0,
"# if (editing) { # disabled # } #",
"text",
true,
"",
false,
false,
true); ?>
1226 <div
class=
"row hcuSpacer"><label
class=
"col-xs-3">Message</label><div
class=
"col-xs-9">
1227 <textarea
class=
"k-textbox hcu-all-100" id=
"messageInput" name=
"messageInput" rows=
"9" cols=
"75" wrap=
"physical" 1228 required data-required-msg=
"Message body cannot be blank" ></textarea>
1232 <div
class=
"hcu-edit-buttons k-state-default row">
1234 <span
class=
"hcu-icon-delete">
1235 <a
class=
"deleteBtn" href=
"\\#"><i
class=
"fa fa-trash-o fa-lg"></i></a>
1238 <a
class=
"cancelBtn" href=
"\\#">Cancel</a>
1240 <a
class=
"sendBtn k-button k-primary" href=
"\\#"><i
class=
"fa fa-check"></i>Send</a>
1244 <script type=
"text/x-kendo-template" id=
"printTemplate">
1245 <div
class=
"printDiv">
1246 <?php printThreadTemplate(
true); ?>
1249 <script type=
"text/x-kendo-template" id=
"printTemplateTitle">
1250 Thread
"#: subject #" with user #: username #
1252 <script type=
"text/x-kendo-template" id=
"rowTemplate">
1253 # var inTD = origination == 1 ? "<td class='inOutTD'><div class='k-success-colored'>In</div></td>" : "<td class='inOutTD'><div class='k-info-colored'>Out</div></td>"; # 1254 <tr data-uid=
'#: uid #' class=
'# if (unread == "Y") { # unreadThread # } #'>#= inTD #<td>#: username #</td><td>#: subject #</td>
1255 <td>#= kendo.toString(date,
"MM/dd/yyyy HH:mm") # #: timezone #</td></tr>
1257 <?php
if (!$fromUserHub) {
1258 printUserSearchTemplate();
1262 <div style=
"container-fluid">
1263 <div
id=
"formValidateDiv" class=
"col-xs-12 k-block k-error-colored formValidateDiv" style=
"display:none;"></div>
1264 <div
class=
"row hcuSpacer filterDiv userHub" id=
"filterDiv">
1265 <label
class=
"col-xs-2">Type</label>
1266 <div
class=
"col-xs-4">
1267 <span
class=
"showOption" data-type=
"in"><span></span><a href=
"#">in</a></span> | <span
class=
"showOption" data-type=
"out"><span></span><a href=
"#">out</a></span>
1268 | <span
class=
"showOption" data-type=
"unread"><span></span><a href=
"#">unread</a></span> | <span
class=
"showOption" data-type=
"all"><span></span><a href=
"#">all</a>
1270 <label
class=
"col-xs-2">Duration</label>
1271 <div
class=
"col-xs-4">
1272 <span
class=
"durationOption" data-type=
"1"><span></span><a href=
"#">30 days</a></span> | <span
class=
"durationOption" data-type=
"2"><span></span><a href=
"#">60 days</a></span>
1273 | <span
class=
"durationOption" data-type=
"3"><span></span><a href=
"#">all</a></span>
1276 <?php printSimple(
"<div id='grid' class='pointerGrid'></div>"); ?>
1279 <div style=
"container-fluid">
1280 <div
id=
"formValidateDiv" class=
"col-xs-12 k-block k-error-colored formValidateDiv" style=
"display:none;"></div>
1281 <div
class=
"hcuSpacer filterDiv standalone row" id=
"filterDiv">
1282 <div
class=
"col-xs-12 col-sm-6 hcuSpacer">
1283 <label
class=
"col-xs-4">
User/topic</label>
1284 <div
class=
"col-xs-8"><input type=
"text" class=
"k-input k-textbox hcu-all-100" id=
"findInput"></div>
1286 <div
class=
"col-xs-12 col-sm-6">
1287 <label
class=
"col-xs-4">Type</label>
1288 <div
class=
"col-xs-8">
1289 <span
class=
"showOption" data-type=
"in"><span></span><a href=
"#">in</a></span> | <span
class=
"showOption" data-type=
"out"><span></span><a href=
"#">out</a></span>
1290 | <span
class=
"showOption" data-type=
"unread"><span></span><a href=
"#">unread</a></span> | <span
class=
"showOption" data-type=
"all"><span></span><a href=
"#">all</a>
1293 <div
class=
"col-xs-12 col-sm-6 hcuSpacer">
1294 <label
class=
"col-xs-4">Duration</label>
1295 <div
class=
"col-xs-8">
1296 <span
class=
"durationOption" data-type=
"1"><span></span><a href=
"#">30 days</a></span>
1297 | <span
class=
"durationOption" data-type=
"2"><span></span><a href=
"#">60 days</a></span>
1298 | <span
class=
"durationOption" data-type=
"3"><span></span><a href=
"#">all</a></span>
1302 <?php printSimple(
"<div id='grid' class='pointerGrid'></div>"); ?>
1306 <ul
id=
"contextMenu">
1307 <li
class=
"markReadLi">Mark Read</li>
1308 <li
class=
"markUnreadLi">Mark Unread</li>
1309 <li
class=
"openLi">Open</li>
1312 <form
id=
"printForm" method=
"post" action=
"shell.prg" target=
"printWindow">
1313 <input type=
"hidden" name=
"shell" value=
"">
1314 <input type=
"hidden" name=
"title" value=
"">
1325 function printThreadTemplate($actuallyPrint =
false) {
1326 if ($actuallyPrint) { ?>
1328 <?php printHubLabelBlock(array(
"User" =>
"#: username #",
"Subject" =>
"#: subject #")); ?>
1334 <div
class=
"threadDiv row hcu-no-padding">
1335 # for (var i = 0; i != threadData.length; i++) { var row = threadData[i]; # 1336 <span
class=
'k-block k-shadow # if (row.origination == 0) { # threadCU k-info-colored # } else { # k-success-colored threadMember # } #'>
1337 <span
class=
'threadTitle'>#
if (row.origination == 0) {
if (row.adminname ==
null) { # #: row.admin # # }
1338 else { # #: row.adminname # # } # Said # }
else { #
User # } #</span>
1339 <span
class=
'threadDate'>#= kendo.toString(row.date,
"MM/dd/yyyy HH:mm") # #: row.timezone #</span>
1340 <br>#= row.messagetext #