Odyssey
welcome.prg
1 <?php
2 /**
3  * @package welcome.prg -- Shows survey questions and messages from HomeCU as well as after hour support and special email notification for the CU.
4  * This replaces welcome.prg, cu_notify.prg, ContMaint.prg
5  */
6 $main = $menu_link;
7 $self = "$menu_link?ft=$ft";
8 
9 $parameters = array("a" => array("email" => ""));
10 $string = array("filter" => FILTER_DEFAULT);
11 HCU_ImportVars($parameters, "a", array("email" => $string));
12 extract($parameters["a"]); // dms_import doesn't work anymore because this isn't in global scope anymore.
13 
14 require_once("$sharedLibrary/sFeatureMnu.i");
15 require_once(dirname(__FILE__) . "/cu_notify.data"); // The update function is used here.
16 
17 if ($operation != "") {
18  switch($operation) {
19  case "readWelcome":
20  $returnArray = readWelcome($dbh, $Cu, $live);
21  break;
22  case "updateSpecialNotification":
23  $returnArray = UpdateEmailNotify($dbh, $Cu, $Cn, "hcunotice", $email, true);
24  break;
25  default: $returnArray = array("sql" => array(), "error" => array("Operation not recognized: $operation."), "record" => array());
26  break;
27  }
28 
29  header('Content-type: application/json');
30  print HCU_JsonEncode($returnArray);
31 } else {
32  printWelcomePage($self, $main, $live);
33 }
34 
35 /**
36  * function readWelcome ($dbh, $Cu, $live)
37  * Gets data for the welcome screen which includes the special contact email, the after hours support, and any HomeCU notes.
38  *
39  * @param integer $dbh -- the database connection
40  * @param string $Cu -- the credit union
41  * @param string $live -- if the credit union is live or batch
42  * @return array --
43  * $error -- one or zero errors encountered
44  * $sql -- the SQLs used
45  * $messages -- the HomeCU notes found
46  * $afterHoursSupport -- the after hours support grid data
47  * $specialNotificationEmail -- the email for special notifications
48  */
49 function readWelcome ($dbh, $Cu, $live) {
50  $returnArray = array();
51 
52  try {
53  $sql = "select cu, email from cuadmnotify where role = 'hcunotice' and cu = '$Cu' limit 1";
54  $sth = db_query($sql, $dbh);
55  if (!$sth) {
56  throw new exception("Special notification email query failed.", 1);
57  }
58  $row = db_fetch_assoc($sth, 0);
59  $specialNotificationEmail = trim($row["email"]);
60 
61  $liveSQL = isset($live) ? ($live == "Y" ? "L" : "B") : "";
62  $liveSQL = $liveSQL == "" ? "" : " and (livebatch = 'A' or livebatch = '$liveSQL') ";
63  $sql = "select id as mid, active_date, message, subject, active_date >= now() - interval '30 days' as important from cuadmin_message where (expires_on is null or now() < expires_on)
64  $liveSQL and active_date <= now() order by active_date desc, id desc, subject";
65  $sth = db_query($sql, $dbh);
66  if (!$sth) {
67  throw new exception("cuadmin message query failed.", 2);
68  }
69  $messages = array();
70  for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
71  $row["important"] = trim($row["important"]) == "t";
72  $row["subject"] = strtr(hcu_displayHtml($row['subject'], ENT_QUOTES), array("\\r" => "\r", "\\n" => "\n"));
73  $row["message"] = strtr(trim($row['message']), array("\\r" => "\r", "\\n" => "\n"));
74  $messages[] = $row;
75  }
76 
77  $afterHoursSupport = readAfterHours($dbh, $Cu, false);
78 
79  // Check if the temporary email is still used in the from emails for cu notify. If it is, then show a popup message.
80  $results = ReadEmailNotify($dbh, $Cu);
81  if ($results ["status"] != "000") {
82  throw new exception ("Read email notify failed.", 3);
83  }
84  $nagPlease = false;
85  foreach($results["data"]["gridData"] as $record) {
86 
87  // It is sorted by the from email address at first. Do not care about the other emails.
88  if (!$record["single"]) {
89  break;
90  }
91 
92  if (trim(strtolower($record["email"])) == GetTemporaryEmail()) {
93  $nagPlease = true; // Oh my gosh! There is a temporary email left! Must nag the credit union then!
94  break;
95  }
96  }
97 
98 
99  } catch(exception $e) {
100  return array("error" => array($e->getMessage()), "messages" => array(), "afterHoursSupport" => array(), "specialNotificationEmail" => "", "nagPlease" => false);
101  }
102  return array("error" => array(), "messages" => $messages, "afterHoursSupport" => $afterHoursSupport, "specialNotificationEmail" => $specialNotificationEmail, "nagPlease" => $nagPlease);
103 }
104 
105 /**
106  * function readAfterHours($dbh, &$sqls, $Cu, $editable)
107  * Gets the after hour support data
108  *
109  * @param integer $dbh -- the database connection
110  * @param array $sqls -- the array to append the SQLs to
111  * @param string $Cu -- the credit union
112  * @param boolean $editable -- if true, we need an index apparently
113  * @return array -- the data for the after hours support grid
114  * @throws "phone is invalid" or "After Hours Support query failed!"
115  */
116 function readAfterHours($dbh, $Cu, $editable) {
117  $sql = "select contactid, priority, name, phone, comments from cucontact where user_name = '" . strtolower($Cu) . "' order by user_name, priority";
118  $sth = db_query($sql, $dbh);
119  if (!$sth) {
120  throw new exception("After Hours Support query failed.", 3);
121  }
122  $afterHoursSupport = array();
123  for($i = 0; $row = db_fetch_assoc($sth, $i); $i++) {
124  $row["phone"] = preg_replace('/[^0-9]*/', "", $row["phone"]);
125  if ($editable) {
126  $row["pid"] = $i + 1;
127  }
128  $length = strlen($row["phone"]);
129  $row["phone"] = $length == 10 ? "(" . substr($row["phone"], 0, 3) . ") " . substr($row["phone"], 3, 3) . "-" . substr($row["phone"], 6)
130  : ($length == 7 ? substr($row["phone"], 0, 3) . "-" . substr($row["phone"], 3) : "");
131 
132  if (trim($row["phone"]) == "") {
133  throw new exception("Phone is invalid.", 4);
134  }
135  $row["name"] = trim($row["name"]);
136  $row["comments"] = trim($row["comments"]);
137  $afterHoursSupport[] = $row;
138  }
139  return $afterHoursSupport;
140 }
141 
142 /**
143  * function printWelcomePage($self, $main, $live)
144  * Prints out the welcome page
145  *
146  * @param string $self -- the URL of this script
147  * @param string $main -- the URL to the main script
148  * @param string $live -- if the Credit Union is live or batch (If live, the after hours support is shown. Otherwise it is not included in the page.)
149  */
150 function printWelcomePage($self, $main, $live) {
151  ?>
152 
153  <style type="text/css">
154  <?php printTopCenterCss(300); ?>
155  </style>
156 
157  <script type="text/javascript">
158  <?php getShowWaitFunctions(); ?>
159 
160  var live = "<?php echo $live; ?>";
161  var activeWindows = [];
162  var action = "";
163 
164  var admDataSource = null;
165  var admDataWelcomeAHS = null;
166  var admDataWelcomeMSG = null;
167  var admDataWelcomeSNE = null;
168 
169  var admActionAddSpecialEmail = null;
170  var admActionEditSpecialEmail = null;
171  var admActionSaveSpecialEmail = null;
172  var admActionCancelSpecialEmail = null;
173  var admInputSpecialEmail = null;
174 
175  var admViewWhatsNew = null;
176  var admViewSpecialEmail = null;
177  var admViewSpecialEmailPopup = null;
178  var admViewSpecialEmailValidator = null;
179  var admViewAfterHours = null;
180  var admViewMessagesDialog = null;
181 
182  var admTemplateWhatsNew = null;
183  var admTemplateSpecialEmail = null;
184  var admTemplateSpecialEmailPopup = null;
185  var admTemplateMessagesPopup = null;
186 
187  function SaveSpecialEmail(e) {
188  var emailValue = admDataWelcomeSNE.email;
189  var emailNew = admInputSpecialEmail.val();
190 
191  if (emailValue != emailNew) {
192  if ($.homecuValidator.validate()) {
193  var updateEmailRequest = {
194  operation: "updateSpecialNotification",
195  email: emailNew
196  };
197 
198  admDataSource.transport.options.read.type = "POST";
199  admDataSource.read(updateEmailRequest);
200  admViewSpecialEmailPopup.close();
201  }
202  } else {
203  admViewSpecialEmailPopup.close();
204  }
205  }
206 
207  function OpenSpecialEmailPopup() {
208  admViewSpecialEmailPopup.center();
209  admViewSpecialEmailPopup.open();
210  }
211 
212  <?php
213  /**
214  * function BuildViewNagPlease()
215  * This creates and pops up a dialog to nag the CU when the temporary email is still set for one of the from emails in the CU Email Notify screen.
216  */
217  ?>
218  function BuildViewNagPlease() {
219  var address = "main.prg?ft=46";
220  var template = "";
221  template += "<p>There are emails that have not been verified. Please go to the <a href='" + address + "'>CU Email Notifications</a> screen ";
222  template += "and verify the email(s) you would like to use for sending Digital Banking emails to users.</p>";
223  template += "<p>Once the email is verified, select the email form the list where you see <?php echo GetTemporaryEmail(); ?>.";
224 
225  var nagPleaseDialog = $("<div id='nagPleaseDialog'></div>").appendTo("body").kendoDialog({
226  title: "Unverified Feature Emails",
227  content: template,
228  actions: [
229  {text: "Okay", primary: true}
230  ],
231  modal: true,
232  visible: false,
233  maxWidth: 700 <?php // Make sure that the dialog does not get too wide. ?>
234  }).data("kendoDialog");
235 
236  nagPleaseDialog.open().center();
237  }
238 
239  function BuildViewAfterHours() {
240  admViewAfterHours = $("#viewAfterHours").kendoGrid({
241  dataSource: {
242  data: admDataWelcomeAHS,
243  schema: {
244  model: {
245  id: "priority",
246  fields: {
247  priority: {type: "number"},
248  name: {type: "string"},
249  phone: {type: "string"},
250  comments: {type: "string"}
251  }
252  }
253  },
254  filter: {field: "priority", operator: "le", value: 3} <?php // Start with the top three options. ?>
255  },
256  columns: [
257  {field: "priority", title: "Priority"},
258  {field: "name", title: "Name"},
259  {field: "phone", title: "Phone"},
260  {field: "comments", title: "Comments"}
261  ]
262  }).data("kendoGrid");
263  }
264 
265  function BuildViewSpecialEmailPopup() {
266 
267  admViewSpecialEmailPopup = $("#viewSpecialEmailPopup").kendoWindow({
268  title: "Special Email Notification",
269  width: "400px",
270  modal: true,
271  visible: false,
272  resizable: false,
273  content: {
274  template: admTemplateSpecialEmailPopup
275  },
276  open: function(e) {
277  // on open set validator to use popup status bar
278  $.homecuValidator.setup({
279  formStatusField: 'viewSpecialEmailStatus',
280  formValidate:'viewSpecialEmailPopup'
281  });
282 
283  this.wrapper.css({ top: 100 });
284  admInputSpecialEmail.val(admDataWelcomeSNE.email);
285  activeWindows.push(this);
286  },
287  close: function(e) {
288 
289  // on close reset validator to use screen status bar
290  $.homecuValidator.setup({
291  formStatusField: 'admInfoBar',
292  formValidate:'welcomeDiv'
293  });
294 
295  admInputSpecialEmail.val("");
296  activeWindows.pop();
297  }
298  }).data("kendoWindow");
299  admActionSaveSpecialEmail = $("#viewSpecialEmailPopup #btnSpecialEmailSave");
300  admInputSpecialEmail = $("#viewSpecialEmailPopup #inpSpecialEmail");
301  }
302 
303  function BuildViewWhatsNew() {
304  for (var i = 0; i < admDataWelcomeMSG.length; i++) {
305  var templateData = admDataWelcomeMSG[i];
306  var templateResult = admTemplateWhatsNew(templateData);
307  admViewWhatsNew.append(templateResult);
308  }
309  }
310 
311  function BuildViewSpecialEmail() {
312 
313  admViewSpecialEmail.empty();
314  var templateData = admDataWelcomeSNE;
315  var templateResult = admTemplateSpecialEmail(templateData);
316  admViewSpecialEmail.append(templateResult);
317  admActionAddSpecialEmail = $("#btnSpecialEmailAdd");
318  admActionEditSpecialEmail = $("#btnSpecialEmailEdit");
319  admActionAddSpecialEmail.on("click", OpenSpecialEmailPopup);
320  admActionEditSpecialEmail.on("click", OpenSpecialEmailPopup);
321  }
322 
323  function InitDataActions() {
324  $(".specialEmailBtn").on("click", OpenSpecialEmailPopup);
325  admActionSaveSpecialEmail.on("click", SaveSpecialEmail);
326 
327  <?php // bash clients do not have $("#viewAfterHours") so need that check. ?>
328  var grid = $("#viewAfterHours").data("kendoGrid");
329  if (grid && grid.dataSource.data().length <= 3) {
330  $("#expandAfterHoursBtn").remove();
331  } else if (grid && $("#expandAfterHoursBtn:visible").length > 0) {
332  $("#expandAfterHoursBtn").on("click", function() {
333  var filter = $(this).text().trim() == "Show All" ? null : {field: "priority", operator: "le", value: 3};
334  grid.dataSource.filter(filter);
335  $(this).text($(this).text() == "Show All" ? "Show Top 3" : "Show All");
336  });
337  }
338 
339  }
340 
341  function InitDataViews(nagPlease) {
342  var templateData = null;
343  var templateResult = null;
344 
345  admViewWhatsNew = $("#viewWhatsNew");
346  admTemplateWhatsNew = kendo.template($("#templateWhatsNew").html());
347  BuildViewWhatsNew();
348 
349  admViewSpecialEmail = $("#viewSpecialEmail");
350  admTemplateSpecialEmail = kendo.template($("#templateSpecialEmail").html());
351  BuildViewSpecialEmail();
352 
353  admTemplateSpecialEmailPopup = $("#templateSpecialEmailPopup").html();
354  BuildViewSpecialEmailPopup();
355 
356  admTemplateMessagesPopup = kendo.template($("#templateMessagesPopup").html());
357 
358  if (live == "Y") {
359  BuildViewAfterHours();
360  }
361 
362  if (nagPlease) {
363  BuildViewNagPlease();
364  }
365  }
366 
367  function InitDataSources() {
368  admDataWelcomeAHS = [];
369  admDataWelcomeMSG = [];
370  admDataWelcomeSNE = {};
371 
372  admDataSource = new kendo.data.DataSource({
373  transport: {
374  read: {
375  url: "<?php echo $self; ?>&operation=readWelcome",
376  dataType: "json",
377  contentType: "application/x-www-form-urlencoded",
378  type: "GET"
379  }
380  },
381  requestStart: function(request) {
382  showWaitWindow();
383  },
384  requestEnd: function(response) {
385  try {
386  $.homecuValidator.setup({formValidate:'welcomeDiv', formStatusField: 'admInfoBar'});
387  if (response.hasOwnProperty("response")) {
388 
389  var results = response.response;
390  if (results.error.length > 0) {
391  throw response.response.error;
392  } else {
393  $.homecuValidator.displayMessage(results.info, $.homecuValidator.settings.statusInfo );
394  }
395  } else {
396  throw "Error Parsing Server";
397  }
398  } catch (error) {
399  $.homecuValidator.displayMessage(error, $.homecuValidator.settings.statusError);
400  }
401  },
402  schema: {
403  parse: function(response) {
404 
405  if (response.error.length == 0) {
406  if (response.hasOwnProperty("record")) {
407  admDataWelcomeSNE.email = response.record[0].email;
408  BuildViewSpecialEmail();
409  } else {
410  admDataWelcomeAHS = response.afterHoursSupport;
411  admDataWelcomeMSG = response.messages;
412  admDataWelcomeSNE = { email: response.specialNotificationEmail };
413  InitDataViews(response.nagPlease);
414  InitDataActions();
415  }
416  }
417 
418  hideWaitWindow();
419  setTimeout(function() {
420  if (admViewMessagesDialog) {
421  admViewMessagesDialog.open();
422  }
423  }, 500);
424  return [];
425  }
426  }
427  });
428  }
429 
430  $(document).ready(function() {
431  admInfoBar = $("#admInfoBar");
432 
433  InitDataSources();
434  admDataSource.read();
435 
436  <?php printClickOverlayEvent(); ?>
437  });
438  </script>
439 
440  <?php // **********************************
441  // **** local styles ****************?>
442  <style>
443 
444  <?php // Needed for the edit links to be inline with the header. ?>
445  .local-h3 {
446  display: inline;
447  }
448  </style>
449 
450  <div class="container-fluid" style="margin-bottom: 50px;" id="welcomeDiv">
451 
452  <div>&nbsp;</div>
453  <div class="well well-sm col-sm-12" id="admInfoBar" style="display: none;"></div>
454 
455  <?php if ($live == "Y") { ?>
456  <div class="well well-sm col-sm-12">
457  <h3 class="local-h3">After Hours Support</h3>&nbsp;&nbsp;&nbsp;<a href="<?php echo $main; ?>?ft=28">Edit</a>
458  <div class="col-sm-12">
459  <div>&nbsp;</div>
460  <div id="viewAfterHours"></div>
461  <a href="#" id="expandAfterHoursBtn">Show All</a>
462  </div>
463  </div>
464  <?php } ?>
465 
466 
467  <div class="well well-sm col-sm-12">
468 
469  <h3 class="local-h3">Special Notification Email</h3>&nbsp;&nbsp;&nbsp;<a class="specialEmailBtn" href="#">Edit</a>
470  <div id="viewSpecialEmail"></div>
471  </div>
472 
473  <div class="well well-sm col-sm-12">
474 
475  <h2>What's New at HomeCU?</h2>
476  <div id="viewWhatsNew"></div>
477  </div>
478  </div>
479 
480  <div id="viewSpecialEmailPopup" style="display: none;"></div>
481  <div id="viewMessagesDialog"></div>
482 
483  <script type="text/x-kendo-template" id="templateMessagesPopup">
484  <div class="well well-sm col-sm-12 k-success-colored">
485  <span>#= subject #</span>
486  </div>
487  </script>
488 
489  <script type="text/x-kendo-template" id="templateSpecialEmailPopup">
490  <div id="viewSpecialEmailStatus"></div>
491  <div class="col-sm-12 hcu-container-margin">
492  <div class="hcu-secondary">
493  <div class="small vsgSecondary">
494  <span>To enter a list of addresses, use a semi-colon (;) to separate multiple addresses.</span>
495  </div>
496  </div>
497  <br>
498  <label>Email:</label>
499  <input type="text" class="k-textbox hcu-full-width" id="inpSpecialEmail" name="inpSpecialEmail"
500  homecu-match-plus="email"
501  data-homecuCustomMatchPlus-msg="One of the emails is invalid."
502  data-required-msg="Special Email is required"
503  required>
504  </div>
505 
506  <div class="col-sm-4 hcu-container-margin"></div>
507  <div class="col-sm-4 hcu-container-margin">
508  <button id="btnSpecialEmailSave" class="k-button k-primary hcu-full-width">
509  <span class="fa fa-check"></span>
510  <span>Save</span>
511  </button>
512  </div>
513  <div class="col-sm-4 hcu-container-margin"></div>
514  </script>
515 
516  <script type="text/x-kendo-template" id="templateSpecialEmail">
517 
518  <div>&nbsp;</div>
519  <div class="col-sm-12">
520  # if (email == "") { #
521  <span>Special email notifications will not be sent. </span>
522  # } else { #
523  <span>Special email notifications will be sent to: </span>
524  <span id="emailText"><strong>#= email #</strong></span>
525  # } #
526  </div>
527 
528  </script>
529 
530  <script type="text/x-kendo-template" id="templateWhatsNew">
531 
532  <div>&nbsp;</div>
533  <div class="col-sm-12" id="msg#= mid #">
534  # if (important) { #
535  <div class="hcu-blog-post hcu-blog-post-important col-sm-12">
536  # } else { #
537  <div class="hcu-blog-post col-sm-12">
538  # } #
539  <h4 class="hcu-blog-title">#= subject #</h4>
540  <p class="hcu-blog-date">#= kendo.toString(active_date, "MMMM dd, yyyy") #</p>
541  <p>#= message #</p>
542  </div>
543  </div>
544 
545  </script>
546  <?php
547 }