77 $monLibrary= dirname(__FILE__) .
"/../library";
78 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
79 require_once(
"$monLibrary/cu_top.i");
80 require_once(
"$monLibrary/ck_hticket.i");
81 require_once(
"$sharedLibrary/errormail.i");
93 $retStatus_ary = Array(
94 'status' => Array(
'code'=>
'000',
'severity'=>
'SUCCESS',
'errors' => Array(),
'messages' => Array()),
99 if (!CheckPerm($link, $Hu,
'monitor_notes', $_SERVER[
'REMOTE_ADDR'])) {
102 throw new Exception(
'Invalid permissions to view, update or add notes');
105 $dms_ok=array(
'frmViewBy'=>
'string',
'frmViewOrder'=>
'string',
'frmViewRange'=>
'string',
106 'frmPostComment'=>
'string',
'frmParentId'=>
'digits',
'frmSubmitBy'=>
'string',
107 'frmNotify'=>
'string',
'frmTopic'=>
'string',
'frmComment'=>
'string',
108 'frmNotifyNote'=>
'string',
'frmHideNote'=>
'string',
'frmSearchFor'=>
'string',
109 'frmSearchType'=>
'string',
'frmSearchIn'=>
'string',
'cuid'=>
'string',
110 'frmParentTopic'=>
'string',
'frmNoteId'=>
'digits',
'user_name' =>
'string',
111 'frmPostOrder'=>
'string');
113 $frmParentId = isset($frmParentId) ? $frmParentId : 0;
114 $frmNoteId = isset($frmNoteId) ? $frmNoteId : 0;
117 $data_notes_list = Array();
119 $returnDefaults =
true;
123 if (function_exists(
'dms_import')) {
129 $form_return_msgs = Array();
134 $dataNoteTopics_ary = Array(
"Contract Notes",
135 "Android App Implementation",
136 "Appliance Settings",
140 "Implementation Notes",
141 "iPhone App Implementation",
142 "Mobile Web Implementation",
143 "On-site IVR Settings",
150 $dataSearchFields_ary = Array(0 => Array(
"field_dbname" =>
"cuinfo_notes.author",
"field_display" =>
"Author"),
151 1 => Array(
"field_dbname" =>
"cuinfo_notes.subject",
"field_display" =>
"Topic"),
152 2 => Array(
"field_dbname" =>
"cuinfo_notes.messagetext",
"field_display" =>
"Note"));
157 if (basename($_SERVER[
'SCRIPT_NAME']) ==
'imp_main.prg') {
158 $dataScriptName = $_SERVER[
'PHP_SELF'] .
"?cuid=$cuid&wc=$wc";
161 $dataScriptName = $_SERVER[
'PHP_SELF'] .
"?user_name=$user_name&wc=$wc";
167 if ($frmPostComment !=
'') {
169 $returnDefaults =
false;
170 if ($frmPostComment !=
'') {
180 if ($FORM_ERRORS ==
"") {
181 if(intval($frmHideNote) == 0) {
189 $db_set_origination = (basename($_SERVER[
'SCRIPT_NAME']) ==
'imp_main.prg' ? 2 : 1);
194 $save_subject = prep_save((intval($frmParentId) > 0 ? $frmParentTopic : $frmTopic), 5000);
195 if (intval($frmNoteId) == 0) {
197 $sql =
"INSERT INTO cuinfo_notes 198 (parentid, author, assignee, createddate, origination, subject, messagetext, activitydate, cu) 200 (" . ($frmParentId ==
'' ?
'NULL' : intval($frmParentId)) .
", '" . prep_save($frmSubmitBy, 12) .
"', 201 '" . prep_save($frmNotify, 12) .
"', now(), '$db_set_origination', '$save_subject', 202 '" . prep_save($frmComment, 5000) .
"', now(), '" . prep_save($user_name, 10) .
"'); ";
204 if (intval($frmParentId) > 0) {
206 $sql .=
"UPDATE cuinfo_notes 207 SET activitydate = now() 208 WHERE parentid = " . intval($frmParentId) .
" ";
212 $sql =
"UPDATE cuinfo_notes 213 SET messagetext = '" . prep_save($frmComment, 5000) .
"' 214 WHERE messageid = '" . intval($frmNoteId) .
"'; ";
217 if (intval($frmParentId) > 0) {
219 $sql .=
"UPDATE cuinfo_notes 220 SET activitydate = now() 221 WHERE messageid = '" . intval($frmParentId) .
"'; ";
224 } elseif ($frmHideNote == 1) {
226 $sql =
"UPDATE cuinfo_notes 227 SET dontshowafter = current_date 228 WHERE messageid = '" . intval($frmNoteId) .
"'; ";
232 $notes_upd_rs = db_query($sql, $link);
234 if ($notes_upd_rs !== FALSE) {
238 $form_return_msgs[] =
"Your request was successful.";
240 if ($frmNotify !=
'') {
244 WHERE user_name = '" . prep_save($frmNotify, 12) .
"' ";
245 $notify_rs = db_query($sql, $link);
246 if ($notify_rs !== FALSE) {
247 $notify_row = db_fetch_array($notify_rs);
248 if (trim($notify_row[
'notifyemail']) !==
'') {
251 $notify_SendTo = trim($notify_row[
'notifyemail']);
256 WHERE user_name = '$Hu' ";
257 $author_rs = db_query($sql, $link);
258 $author_row = db_fetch_array($author_rs);
259 if (trim($author_row[
'notifyemail']) !=
'') {
260 $notify_SendFrm = trim($author_row[
'notifyemail']);
262 $notify_SendFrm =
"nobody@homecu.net";
265 $notify_Subject =
"There is a HomeCU note you should see.";
267 $notify_Message =
"";
268 if ($frmNotifyNote !=
'') {
270 $notify_Message .=
"NOTE**: $frmNotifyNote";
273 $notify_Message .=
"\n\nCU - " . $user_name .
"\n";
274 $notify_Message .=
"Entered by " . $Hu;
275 $notify_Message .=
"\n\n" . $frmComment;
278 $notify->mailto = $notify_SendTo;
279 $notify->replyto = $notify_SendFrm;
280 $notify->mailfrom = $notify_SendFrm;
282 $notify->subject = $notify_Subject;
283 $notify->msgbody = $notify_Message;
284 $notify->file = __FILE__;
285 $notify->cu = $user_name;
292 $form_return_msgs[] =
"The user " . dms_disphtml($frmNotify) .
" does not have an email setup for notification.";
299 $FORM_ERRORS =
"Unable to update data at this time.";
302 } elseif ($frmPostOrder !=
'') {
304 $returnDefaults =
false;
323 $sql_WHERE =
"WHERE cuinfo_notes.trackitem_id = 0 and cuinfo_notes.track_id = 0 ";
348 $sql_WHERE_SEARCH =
"";
349 if ($frmSearchFor !=
'') {
351 if ($dataSearchFields_ary[$frmSearchIn][
'field_dbname'] !=
'') {
353 switch (intval($frmSearchType)) {
356 $sql_WHERE_SEARCH =
" LOWER(" . $dataSearchFields_ary[$frmSearchIn][
'field_dbname'] .
") LIKE ('%" . strtolower(prep_save($frmSearchFor, 200)) .
"%') ";
362 $data_frmSearchFor = trim($frmSearchFor);
363 $data_frmSearchFor = prep_save(preg_replace(
'/\s+/',
'|', $data_frmSearchFor), 200);
365 if (intval($frmSearchType) == 2) {
367 $data_frmSearchFor =
" " . str_replace(
'|',
' | ', $data_frmSearchFor) .
" ";
369 $sql_WHERE_SEARCH =
" LOWER(" . $dataSearchFields_ary[$frmSearchIn][
'field_dbname'] .
") SIMILAR TO '%(" . strtolower($data_frmSearchFor) .
")%' ";
373 $sql_WHERE_SEARCH =
" " . $dataSearchFields_ary[$frmSearchIn][
'field_dbname'] .
" ~* '" . prep_save($frmSearchFor, 200) .
"' ";
383 $sql_WHERE_SEARCH .= ($sql_WHERE_SEARCH !=
'' ?
" AND " :
" " ) .
" cuinfo_notes.cu = '" . prep_save($user_name, 12) .
"' ";
386 $sql_WHERE_SEARCH .= ($sql_WHERE_SEARCH !=
'' ?
" AND " :
" " ) .
" (cuinfo_notes.dontshowafter is NULL OR cuinfo_notes.dontshowafter > current_date) ";
394 switch (intval($frmViewBy)) {
419 $sql_WHERE .= ($sql_WHERE_SEARCH ==
"" ?
"" : ($sql_WHERE ==
'' ?
" WHERE " :
" AND ") . $sql_WHERE_SEARCH);
421 switch (intval($frmViewOrder)) {
423 $sql_ORDER =
" ORDER BY cuinfo_notes.activitydate ";
426 $sql_ORDER =
" ORDER BY cuinfo_notes.activitydate DESC ";
429 $sql =
"SELECT messageid, parentid, author, assignee, to_char(createddate, 'MM/DD/YYYY HH24:MI:SS') as createddate, 430 unread, origination, subject, messagetext, to_char(dontshowafter, 'MM/DD/YYYY HH24:MI:SS') as dontshowafter, 431 to_char(activitydate, 'MM/DD/YYYY HH24:MI:SS') as activitydate 461 $sql_WHERE .= ($sql_WHERE_SEARCH ==
"" ?
"" : ($sql_WHERE ==
'' ?
" WHERE " :
" AND ") . $sql_WHERE_SEARCH);
463 $sql_ORDER =
" ORDER BY subject ";
464 switch (intval($frmViewOrder)) {
466 $sql_ORDER .=
", cuinfo_notes.createddate ";
469 $sql_ORDER .=
", cuinfo_notes.createddate DESC ";
472 $sql =
"SELECT messageid, parentid, author, assignee, to_char(createddate, 'MM/DD/YYYY HH24:MI:SS') as createddate, 473 unread, origination, subject, messagetext, to_char(dontshowafter, 'MM/DD/YYYY HH24:MI:SS') as dontshowafter, 474 to_char(activitydate, 'MM/DD/YYYY HH24:MI:SS') as activitydate 511 $sql_WHERE .= ($sql_WHERE_SEARCH ==
"" ?
"" : ($sql_WHERE ==
'' ?
" WHERE " :
" AND ") . $sql_WHERE_SEARCH);
513 switch (intval($frmViewOrder)) {
515 $sql_ORDER .=
" ORDER BY 1, cuinfo_notes.messageid, 2 ";
518 $sql_ORDER .=
" ORDER BY 1 DESC, cuinfo_notes.messageid, 2 DESC ";
521 $sql =
"SELECT COALESCE(cuinfo_notes.parentid, cuinfo_notes.messageid) as nodeid, COALESCE(parent_note.activitydate, cuinfo_notes.activitydate) as lastnodeactivity, 522 cuinfo_notes.messageid, cuinfo_notes.parentid, cuinfo_notes.author, cuinfo_notes.assignee, 523 TO_CHAR(cuinfo_notes.createddate, 'MM/DD/YYYY HH24:MI:SS') as createddate, 524 cuinfo_notes.unread, cuinfo_notes.origination, cuinfo_notes.subject, cuinfo_notes.messagetext, TO_CHAR(cuinfo_notes.dontshowafter, 'MM/DD/YYYY HH24:MI:SS') as dontshowafter, 525 TO_CHAR(cuinfo_notes.activitydate, 'MM/DD/YYYY HH24:MI:SS') as activitydate 528 LEFT JOIN cuinfo_notes as parent_note on parent_note.messageid = cuinfo_notes.messageid 535 $notes_rs = db_query($sql, $link);
543 while ($notesRow = db_fetch_assoc($notes_rs, $data_notes_idx)) {
547 $notesRow[
'author'] = dms_disphtml($notesRow[
'author']);
548 $notesRow[
'subject'] = dms_disphtml($notesRow[
'subject']);
549 $notesRow[
'messagetext'] = nl2br(dms_disphtml(preg_replace(
'/[^(\x00-\x7F)]*/',
'', $notesRow[
'messagetext'])));
550 $data_notes_list[] = $notesRow;
555 $sql =
"SELECT user_name 557 ORDER BY upper(user_name) ";
558 $users_rs = db_query($sql, $link);
559 $data_users_list = db_fetch_all($users_rs);
562 header(
'Content-type: application/json');
565 if ($returnDefaults) {
566 $retStatus_ary[
'data'] = Array(
567 "users" => $data_users_list,
568 "notes" => $data_notes_list,
569 "topics" => $dataNoteTopics_ary,
570 "searchfields" => $dataSearchFields_ary
573 $retStatus_ary[
'data'] = Array(
574 "notes" => $data_notes_list
577 if (count($form_return_msgs) > 0) {
578 $retStatus_ary[
'status'][
'messages'] = $form_return_msgs;
580 print json_encode($retStatus_ary);
586 $retStatus_ary = array();
587 header(
'Content-type: application/json');
588 $retStatus_ary = Array(
589 'status' => Array(
'code'=>
'999',
'severity'=>
'FAILURE',
'errors' => Array(),
'action' =>
''),
592 $retStatus_ary[
'status'][
'errors'][] = $ex->getMessage();
593 print json_encode($retStatus_ary);