Odyssey
hcuViewNotice.prg
1 <?php
2 /*
3  * hcuViewNotice.prg
4  *
5  * Purpose:
6  * This script will allow the viewing of a Notice / Marketing Message/
7  * Survey / Promo.
8  * This script can ONLY be viewed if the user is currently authenticated
9  * The main authentication can come from the cookie information that should
10  * be accompanying the request
11  *
12  * Parameters:
13  * There should be only one parameter
14  * x - This is a two way encrypted value containing a json array with
15  * the following parameters
16  *
17  * docsid
18  * docstype {M/S/P, C}
19  * device
20  * noticeOnly {1 / 0}
21  * expireTime?
22  * noticeStrReplace - a matched pair of arrays for search/replace on a notice
23  *
24  */
25 
26  // ** SET SCRIPT LEVEL VARIABLES
27  $serviceShowInfo = false;
28  $serviceLoadMenu = false;
29  $serviceShowMenu = false;
30  $serviceAllowReadonly = false;
31  $serviceSkipSecurity = true;
32 
33  // ** INCLUDE MAIN GLOBAL SCRIPT -- Handles security / global variable values
34  require_once(dirname(__FILE__) . '/../library/hcuService.i');
35 
36  $string= array("filter" => FILTER_DEFAULT);
37  HCU_ImportVars($HB_ENV, "HCUPOST", array("cu" => $string, "notice_type" => $string, "notice_id" => $string, "notice_link" => $string, "notice_device" => $string, "notice_msg_show" => $string,
38  "notice_response" => HCUFILTER_INPUT_ARRAY, "x" => $string, "notice_cancel" => $string, "tooLong" => $string, "notice_accountnumber" => $string));
39 
40  /*
41  * First - Decide if we are updating or VIEWING
42  *
43  * Update - if 'x' is empty and 'notice_id' is set
44  */
45 
46  if (empty($HB_ENV['HCUPOST']['x']) && isset($HB_ENV['HCUPOST']['notice_id'])) {
47  $retJson_ary = Array(
48  'homecuInfo' => 'CLOSE',
49  'homecuErrors' => Array(),
50  'homecuData' => ''
51  );
52 
53  try {
54  /*
55  * UPDATE NOTICE
56  */
57 
58  // * Update the notice
59 
60  $retStatus_ary = Update_NoticeInfo($dbh, $HB_ENV, $MC);
61 
62  // * based on the notice response, build the response
63  // ** UPDATE -- WHAT NOW??
64  // ** Now that we are back check to see what we should send back to the form
65  if ($retStatus_ary['status']['code'] == '000') {
66  // ** SUCCESS -- POSSIBLY RETURN EXTRA INFORMATION
67  if ($retStatus_ary['response']['notice_action'] == 'DISPLAY') {
68  // ** We are told there are results to display
69  // ** Configure those here
70  if (is_array($retStatus_ary['response']['notice_results'])) {
71  // ** NOW CHECK FOR ANSWERS -- if NO answers --- nothing should be displayed
72  if (count($retStatus_ary['response']['notice_results'][0]['notice_answers']) > 0) {
73  $answer_html = "";
74  foreach ($retStatus_ary['response']['notice_results'][0]['notice_answers'] as $answer_idx => $answer_row) {
75  $answer_html .= "
76  <div class='col-xs-12 hcu-nopadding'>{$answer_row['answer_text']}</div>
77  <div class='col-xs-12 hcu-nopadding'>
78  <div class='survey-result-show'>
79  <div id='ansid{$answer_idx}' dms-value='{$answer_row['answer_votes']}'></div>
80  </div>
81  </div>
82  ";
83  }
84  if ($answer_html != '') {
85  $answer_html = "
86  <html>
87  <body>
88  <div id='s-result' class='container-fluid'>
89  <div class='row'>
90  <div class='col-xs-12 hcu-nopadding h4'>
91  {$retStatus_ary['response']['notice_results'][0]['notice_text']}
92  </div>
93  </div>
94  <div class='row'>
95  <div class='survey-results'>
96  {$answer_html}
97  </div>
98  </div>
99  <div class='row'>
100  <div class='col-xs-12 hcu-nopadding'>
101  <p class='total-votes'>
102  ({$MC->msg("Total Votes", HCU_DISPLAY_AS_HTML)}:&nbsp;{$retStatus_ary['response']['notice_results'][0]['notice_answervotes_ttl']})
103  </p>
104  </div>
105  </div>
106 
107  <div class='row'>
108  <div class='col-xs-12 hcu-nopadding'>
109  <hr style='text-align:left; margin-left:0; color:rgba(0,0,0,.57); height:1px;'/>
110  </div>
111  </div>
112  <div class='row'>
113  <div class='col-xs-12 hcu-nopadding' style='text-align:right;'>
114  <button type='button' class='k-button hcu-xs-100-only' id='btnNeutral' onClick='NeutralBtnNotice(\$(this), \"\");'><span class=\"fa fa-arrow-right\"></span>&nbsp;{$MC->msg('Continue', HCU_DISPLAY_AS_HTML)}</button>
115  </div>
116  </div>
117  </div>
118 
119  <style>
120  #s-result .k-progressbar-horizontal {
121  width:100%;
122  max-width: 27em;
123  }
124  .survey-result-show {
125  margin: 3px 0 10px 5px;
126  }
127  #s-result .hcu-nopadding {
128  padding: 0;
129  }
130  </style>
131  <script>
132  var progressbars = [];
133  $('.survey-results .survey-result-show div').each(function () {
134  var pb = $(this).kendoProgressBar({
135  type: \"value\",
136  min: 0,
137  max: {$retStatus_ary['response']['notice_results'][0]['notice_answervotes_ttl']},
138  animation: {
139  duration: 600
140  }
141  }).data(\"kendoProgressBar\");
142  progressbars.push(pb);
143  });
144  $.each(progressbars, function (i, pb) {
145  if (pb.wrapper.attr('dms-value') !== 0) {
146  pb.value(pb.wrapper.attr('dms-value'));
147  }
148  });
149  </script>
150  </body>
151  </html>
152  ";
153  $retJson_ary['homecuInfo'] = 'DISPLAY';
154  $retJson_ary['homecuData'] = $answer_html;
155  }
156 
157  }
158  }
159  }
160  } else {
161  // ** AN ERROR OCCURRED -- SET ACCORDINGLY
162  $retJson_ary['homecuErrors'] = $retStatus_ary['status']['errors'];
163  }
164 
165  // ** Return the data
166  header('Content-type: application/json');
167  print HCU_JsonEncode($retJson_ary);
168 
169  } catch (Exception $err) {
170  // ** Some PHP Exception occurred.
171  // ** For this type, I will need to still allow them to close the pop-up...
172  $retJson_ary['homecuErrors'] = $MC->msg('Errors found', HCU_DISPLAY_AS_RAW);
173  $retJson_ary['homecuInfo'] = 'CLOSE';
174 
175  // ** Return the data
176  header('Content-type: application/json');
177  print HCU_JsonEncode($retJson_ary);
178  }
179 
180  // * END OF UPDATE RESPONSE --
181  exit;
182  } elseif (isset($HB_ENV['HCUPOST']['x'])) {
183 
184  try {
185  /*
186  * VIEW NOTICE
187  */
188  $localValues = Array (
189  'docsid' => '',
190  'docstype' => '',
191  'device' => '',
192  'noticeOnly' => '',
193  'expireTime' => '',
194  'noticeStrReplace' => ''
195  );
196  // ** Decrypt x and set the values accordingly
197  $docValues= HCU_PayloadDecode($HB_ENV["Cu"], $HB_ENV['HCUPOST']['x']);
198  if ($docValues['expireTime'] < mktime()) {
199  throw new Exception($MC->msg('Link Expired', HCU_DISPLAY_AS_HTML));
200  }
201  switch ($docValues['docstype']) {
202  case "M":
203  case "S":
204  $noticeAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, $docValues['device'], $docValues['docstype'], 1, $docValues['docsid']);
205  break;
206  case "C":
207  // see if there is any string replacing
208  if ( HCU_array_key_value("noticeStrReplace", $docValues) != '' ) {
209  $HB_ENV["noticeStrReplace"] = HCU_JsonDecode( $docValues["noticeStrReplace"] );
210  }
211  $noticeAry = Get_NoticeInfo($dbh, $HB_ENV, $MC, $docValues['device'], 'loadcms', 1, $docValues['docsid']);
212  break;
213  }
214  /*
215  * pageOption -- Array of options that will be used in the html that is printed
216  * noticeTitle - This is the text of the title for the page, really doesn't get shown
217  * noticeText - This is the main body of the notice. It will should contain all
218  * the text with html mark up to show on the form.
219  * negativeAction - This is the area on the form in the lower left. It is on the
220  * same line as the confirm button. This could also be the 'do not show again'
221  * checkbox or a button vote later type button
222  * positiveAction - This is the form action for the positive event -
223  * noticeScript - This is any javascript that is needed for the form to work
224  */
225 
226  $pageOption = Array (
227  'noticeText' => '',
228  'noticeTitle' => '',
229  'negativeAction' => '',
230  'positiveAction' => '',
231  'noticeScript' => '',
232  'checkboxScript' => '',
233  'promoScript' => ''
234  );
235 
236  if ($noticeAry['status']['code'] != '000' ) {
237  // ** Something went wrong..
238  throw new Exception($MC->msg('Errors found', HCU_DISPLAY_AS_HTML));
239  } else {
240  // ** we now need to load the values into the form
241  $noticeDetail = $noticeAry['notice'][0];
242  $pageOption['noticeText'] = '<div style="padding-bottom: 20px">' . $noticeAry['notice'][0]['notice_text'] . '</div>';
243  $pageOption['noticeTitle'] = $noticeAry['notice'][0]['notice_title'];
244  $notice_answers = "";
245  $notice_type = ($noticeDetail['notice_answertype'] == 'O' ? 'radio' : 'checkbox');
246 
247  /*
248  * Survey / Mkt Msg
249  * These two types should still be posting back to the server if the member
250  * presses cancel. The reason is to set a temp flag on the cookie, so they
251  * aren't bothered again by a message when they come back to the screen
252  *
253  * if the button has the parameter data-always-post set to true, then
254  * regardless if it is the positive or negative, a post will be sent to
255  * the server
256  */
257 
258  switch ($noticeDetail['notice_type']) {
259  case 'S':
260  // ** First look at the intro
261  if (strlen($noticeDetail['notice_intro']) > 0) {
262  $pageOption['noticeText'] = "<div><h4>{$noticeDetail['notice_intro']}</h4></div>{$pageOption['noticeText']}";
263  }
264  if (count($noticeDetail['notice_answers']) > 0) {
265  foreach ($noticeDetail['notice_answers'] as $notice_answer_key => $notice_answer_array) {
266  $notice_answers .="<div class='row'><div class='{$notice_type}'><label for='response{$notice_answer_array['answer_id']}'><input type='{$notice_type}' class='noticeRequired' name='notice_response[]' id='response{$notice_answer_array['answer_id']}' value='{$notice_answer_array['answer_id']}'/>&nbsp;{$notice_answer_array['answer_text']}</label></div></div>";
267  }
268  // ** I have the answers -- NOW wrap them in the correct display tags
269  $notice_answers = "<div id='survey-lines'>
270  {$notice_answers}
271  </div>";
272  }
273  $pageOption['noticeText'] .= $notice_answers;
274  $pageOption['noticeScript'] = <<< printjs
275  $(document).ready(function() {
276  $('.noticeRequired').click(function() {
277  $('#btnPositive').removeClass('k-state-disabled');
278  });
279  });
280 printjs;
281 
282  $pageOption['negativeAction'] = "<button type='button' class='k-button hcu-xs-100-only' id='btnNegative' data-always-post='true' onClick='NegativeBtnNotice(\$(this), \"{$noticeDetail['notice_posttarget']}\");'><span class=\"fa fa-times\"></span>&nbsp;{$noticeDetail["notice_negative_caption"]}</button>";
283 
284  $pageOption['positiveAction'] = "<button type='button' class='k-button k-primary k-state-disabled hcu-xs-100-only' id='btnPositive' onClick='PositiveBtnNotice(\$(this), \"{$noticeDetail['notice_posttarget']}\");'><span class=\"fa fa-arrow-right\"></span>&nbsp;{$noticeDetail["notice_positive_caption"]}</button>";
285 
286  break;
287  case 'M':
288 
289  $pageOption['noticeText'] = "<h4 style='text-align:center'>{$pageOption['noticeTitle']}</h4>{$pageOption['noticeText']}";
290  $pageOption['negativeAction'] = "<label style='cursor:pointer;'><input type='checkbox' id='msgDone' name='notice_response[]' value='{$noticeDetail["notice_answers"][0]["answer_id"]}' class='noticeOptional'>&nbsp;{$noticeDetail["notice_answers"][0]["answer_text"]}</label>";
291 
292  $pageOption['positiveAction'] = "<button type='button' class='k-button k-primary hcu-xs-100-only' id='btnPositive' data-always-post='true' onClick='PositiveBtnNotice(\$(this), \"{$noticeDetail['notice_posttarget']}\");'><span class=\"fa fa-arrow-right\"></span>&nbsp;{$noticeDetail["notice_positive_caption"]}</button>";
293 
294  break;
295  case 'C':
296  /*
297  * CMS Notice
298  * D - Disclosures
299  * N - Notices
300  */
301  // allow the user to override the type
302  if ( in_array($noticeDetail["notice_subtype"], Array('D', 'A', 'E', 'P'))) {
303  $dataPost = "";
304  if ( in_array($noticeDetail["notice_subtype"], Array('A', 'E', 'P'))) {
305  $dataPost = "data-always-post='true'";
306 
307  // if an estatement promo have the promo handle a click to get to the estatement page
308  if ( $noticeDetail["notice_subtype"] == "E" ) {
309  $pageOption["promoScript"] = "
310  $(document).ready(function() {
311  $('#ViewContent').click( function () {
312  location.href='{$HB_ENV['loginpath']}/hcuStatement.prg?{$HB_ENV['cuquery']}';
313  });
314  $('#ViewContent').css('cursor','pointer');
315  });
316  ";
317  }
318  }
319  if (intval($docValues['noticeOnly']) != 1 && $noticeDetail["notice_subtype"] != 'P') {
320  $pageOption['negativeAction'] = "<label style='cursor:pointer;'><input type='checkbox' id='msgDone' name='notice_response[]' value='{$noticeDetail["notice_answers"][0]["answer_id"]}' class='noticeOptional'>&nbsp;{$noticeDetail["notice_answers"][0]["answer_text"]}</label>";
321  }
322  $pageOption['positiveAction'] = "<button type='button' class='k-button k-primary hcu-xs-100-only' {$dataPost} id='btnPositive' onClick='PositiveBtnNotice(\$(this), \"{$noticeDetail['notice_posttarget']}\");'><span class=\"fa fa-arrow-right\"></span>&nbsp;{$noticeDetail["notice_positive_caption"]}</button>";
323  } else {
324  if (intval($docValues['noticeOnly']) != 1) {
325  $pageOption['negativeAction'] = "<label style='cursor:pointer;'><input type='checkbox' id='msgDone' name='notice_response[]' value='{$noticeDetail["notice_answers"][0]["answer_id"]}' class='noticeOptional'>&nbsp;{$noticeDetail["notice_answers"][0]["answer_text"]}</label>";
326  // set up some javascript to handle the checkbox state
327  $pageOption["checkboxScript"] = "
328  $(document).ready(function() {
329  $('#msgDone').click(function() {
330  if ( $('#msgDone').prop('checked') ) {
331  $('#btnPositive').css('display', 'inline');
332  $('#btnNegative').css('display', 'none');
333  } else {
334  $('#btnPositive').css('display', 'none');
335  $('#btnNegative').css('display', 'inline');
336  }
337  });
338  }); ";
339  // give both positive and negative buttons to provide for different behavior when checkbox checked
340  $pageOption['positiveAction'] = "<button type='button' class='k-button k-primary hcu-xs-100-only' id='btnPositive' onClick='PositiveBtnNotice(\$(this), \"{$noticeDetail['notice_posttarget']}\");' style='display:none;'><span class=\"fa fa-arrow-right\"></span>&nbsp;{$noticeDetail["notice_positive_caption"]}</button>" .
341  "<button type='button' class='k-button hcu-xs-100-only' id='btnNegative' onClick='NegativeBtnNotice(\$(this), \"{$noticeDetail['notice_posttarget']}\");'><span class=\"fa fa-times\"></span>&nbsp;{$noticeDetail["notice_negative_caption"]}</button>";
342  } else {
343  // for notice-only use neutral button info, but in positive button location
344  $pageOption['positiveAction'] = "<button type='button' class='k-button k-primary hcu-xs-100-only' id='btnPositive' onClick='NeutralBtnNotice(\$(this), \"\");'><span class=\"fa fa-arrow-right\"></span>&nbsp;{$noticeDetail["notice_neutral_caption"]}</button>";
345  }
346  }
347  break;
348  }
349 
350  $tooLong = HCU_array_key_exists("tooLong", $docValues) ? $docValues["tooLong"] == true : false;
351  $tooLong = $tooLong ? "tooLong" : "";
352 
353  $accountnumber = HCU_array_key_value("accountnumber", $docValues);
354  $accountnumberInput = $accountnumber === false ? "" : "<input type='hidden' name='notice_accountnumber' value='" . trim($accountnumber) . "'>";
355 
356  // build the contents of the page
357  $pageBody = <<< printHtml
358 <?xml version="1.0"?><!DOCTYPE html>
359  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
360  <head>
361  <title>{$pageOption['noticeTitle']}</title>
362  <meta charset="ISO-8859-1"/>
363  <meta name="robots" content="noindex,nofollow" />
364  <meta http-equiv="X-UA-Compatible" content="IE=8" />
365  <script>
366  {$pageOption['noticeScript']}
367  {$pageOption['checkboxScript']}
368  {$pageOption['promoScript']}
369  </script>
370  <style>
371  .hcu-nopadding {
372  padding: 0;
373  }
374  .hcu-notice-button-right {
375  text-align: right;
376  }
377  #notice-window .row .col-xs-12 {
378  margin-top: 5px;
379  }
380  #notice-window .row ul {
381  margin-left: 15px;
382  }
383  </style>
384  </head>
385  <body>
386  <div id='notice-window' class="container-fluid $tooLong">
387  <form id='noticeForm'>
388  <input type='hidden' name='notice_type' value='{$noticeDetail['notice_type']}'>
389  <input type='hidden' name='notice_id' value='{$noticeDetail['notice_id']}'>
390  <input type='hidden' name='notice_device' value='{$docValues['device']}'>
391  <input type='hidden' id='notice_cancel' name='notice_cancel' value='0'>
392  $accountnumberInput
393 
394  <div id="ViewContent">
395  <div class="row">
396  {$pageOption['noticeText']}
397  </div></div>
398  <hr class="hrBar" style='text-align:left; margin-left:0; color:rgba(0,0,0,0.54); height:1px;'/>
399  <div class="acceptability container-fluid">
400  <div class="row acceptability">
401  <div class="col-xs-12 col-sm-6 hcu-nopadding">
402  {$pageOption['negativeAction']}
403  </div>
404  <div class="col-xs-12 col-sm-6 hcu-nopadding hcu-notice-button-right">
405  {$pageOption['positiveAction']}
406  </div>
407  </div></div>
408  </form>
409  </div>
410  </body>
411  </html>
412 printHtml;
413 
414 
415 
416  }
417 
418  // ** PRINT the html contents to the file stream
419  print $pageBody;
420 
421  } catch (Exception $err) {
422  // ** Some PHP Exception occurred.
423  // ** For this type, I will need to still allow them to close the pop-up...
424 
425  // * Include the Error page and finish
426  $serviceErrorTitle = "";
427  $serviceErrorString = $err->getMessage();
428  $serviceErrorCode = '916';
429 
430  require_once(dirname(__FILE__) . '/../includes/hcuErrorPage.i');
431  }
432  // ** END OF DOCUMENT REQUEST
433  exit;
434  } else if ( $_REQUEST["action"] === "close_embedded" ) {
435  // return nothing, but as a json object
436  header('Content-Type: application/json');
437 
438  // set the flag regardless of whether it is already set
439  $PROMO_CLOSED = 0x8000;
440  $Fmsg_tx = $HB_ENV["Fmsg_tx"] |= $PROMO_CLOSED;
441 
442  SetTicket($HB_ENV, $_COOKIE['Ticket'],"Fmsg_tx=$Fmsg_tx");
443 
444  exit;
445  } else {
446 
447  /*
448  * ERROR
449  * INCORRECT PARAMETERS SET
450  */
451  $notice_text = "<H1>Not Found</H1>
452  The requested file was not found on this server<P>
453  <HR>
454  <ADDRESS>{$_SERVER['SERVER_SIGNATURE']}</ADDRESS>";
455  $notice_title = "404 Not Found";
456 
457  print <<< EOF
458  <?xml version="1.0"?><!DOCTYPE html>
459  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
460  <head>
461  <title>{$notice_title}</title>
462  <meta name="robots" content="noindex,nofollow" />
463  <meta http-equiv="X-UA-Compatible" content="IE=8" />
464  </head>
465  <body>
466  <div id='ViewContent'>
467  {$notice_text}
468  </div>
469  </body>
470  </html>
471 EOF;
472  }