Odyssey
surveyMntc.prg
1 <?php
2 /**
3  * File: surveyMntc.prg
4  * Version 2 for survey maintenance and marketing messages using the favorite Kendo.
5  */
6 
7 $parameters= array("a" => array("page" => "", "mode" => "", "answerid" => "", "language" => "", "surveyid" => "", "languageArray" => "", "startdate" => "", "stopdate" => "",
8  "surveyname" => "", "surveytitle" => "", "runstat" => "","employee" => "", "incBalances" => "", "dontshow" => "", "questions" => "", "answers" => "", "answerid" => ""));
9 $string= array("filter" => FILTER_DEFAULT);
10 HCU_ImportVars($parameters, "a", array("page" => $string, "surveyid" => $string, "mode" => $string, "answerid" => $string, "language" => $string, "languageArray" => $string,
11  "startdate" => $string, "stopdate" => $string, "surveyname" => $string, "surveytitle" => $string, "runstat" => $string, "employee" => $string, "incBalances" => $string,
12  "dontshow" => $string, "questions" => $string, "answers" => $string, "answerid" => $string));
13 extract($parameters["a"]);
14 
15 $page= isset($page) ? trim($page) : "";
16 $mode= isset($mode) ? trim($mode) : "";
17 $operation= isset($operation) ? trim($operation) : "";
18 $showSQL= $SYSENV["devmode"];
19 $self= "$menu_link?ft=$ft";
20 $isMarketing= $ft == 37;
21 
22 require_once("surveyMntc.data");
23 
24 if ($operation == "")
25 {
26  switch($page)
27  {
28  case "edit":
29  printEditPage($isMarketing, $self, $surveyid);
30  break;
31  case "results":
32  $isMarketing ? print "Page is only available for survey maintenance." : printResultsPage($self, $mode, $surveyid);
33  break;
34  case "resultDetails":
35  $isMarketing ? print "Page is only available for survey maintenance." : printResultDetailPage($self, $surveyid, $language, $answerid);
36  break;
37  case "extendDates":
38  printExtendDatesPage($isMarketing, $self, $surveyid);
39  break;
40  case "intro":
41  $isMarketing ? print "Page is only available for survey maintenance." : printIntroPage($self);
42  break;
43  case "preview":
44  $previewData= readView($isMarketing, $dbh, $Cu, $surveyid, $mode, false);
45  printPreviewPage($isMarketing, $self, $previewData);
46  break;
47  case "main":
48  case "default":
49  case "":
50  printMainPage($isMarketing, $self, $mode);
51  break;
52  default:
53  print "Page $page not found.";
54  break;
55  }
56 }
57 else
58 {
59  switch($operation)
60  {
61  case "readMain":
62  $returnArray= readMain($isMarketing, $dbh, $Cu);
63  break;
64  case "readEdit":
65  $returnArray= readEdit($isMarketing, $dbh, $Cu, $surveyid);
66  break;
67  case "readNew":
68  $returnArray= readNew($dbh, $Cu);
69  break;
70  case "readView":
71  $returnArray= readView($isMarketing, $dbh, $Cu, $surveyid, $mode, false);
72  break;
73  case "readExtendDates":
74  $returnArray= readView($isMarketing, $dbh, $Cu, $surveyid, $mode, true);
75  break;
76  case "readResults":
77  $returnArray= readResults($isMarketing, $dbh, $Cu, $mode, $surveyid);
78  break;
79  case "readResultDetails":
80  $returnArray= readResultDetails($isMarketing, $dbh, $Cu, $surveyid, $language, $answerid);
81  break;
82  case "delete":
83  $returnArray= delete($dbh, $Cu, $surveyid);
84  break;
85  case "save":
86  $returnArray= save($isMarketing, $dbh, $Cu, $surveyid, $startdate, $stopdate, $surveyname, $surveytitle, $runstat, $employee, $incBalances, $dontshow, $questions, $answers, false);
87  break;
88  case "extendDates":
89  $returnArray= save($isMarketing, $dbh, $Cu, $surveyid, $startdate, $stopdate, $surveyname, $surveytitle, $runstat, $employee, $incBalances, $dontshow, $questions, $answers, true);
90  break;
91  case "readIntro":
92  $returnArray= readIntro($isMarketing, $dbh, $Cu);
93  break;
94  case "saveIntro":
95  $returnArray= saveIntro($isMarketing, $dbh, $Cu, $languageArray);
96  break;
97  default: // Won't get here
98  $returnArray= array("error" => array("Operation not specified: '$operation'"), "record" => array(), "sql" => array());
99  break;
100  }
101 
102  header('Content-type: application/json');
103  if (!$showSQL)
104  unset($returnArray["sql"]);
105  print HCU_JsonEncode($returnArray);
106 }
107 
108 function printDeleteAllConfirm($isMarketing, $self, $fromMain)
109 {
110  $text= !$isMarketing ? "survey" : "marketing message";
111  $warnText= !$isMarketing ? "Warning! This action will delete all data (question, answers, and member responses) for survey" : "Warning! This action will delete all data for marketing message";
112  $statusText= (!$isMarketing ? "Survey" : "Marketing message") . " deleted correctly.";
113  ?>
114  function openDeleteAllTemplate(surveyid, surveyname, tr)
115  {
116  var deleteConfirmDialog= $("#deleteConfirmDialog").data("kendoDialog");
117 
118  if (deleteConfirmDialog == null)
119  {
120  deleteConfirmDialog= $("<div id='deleteConfirmDialog'></div>").appendTo("body").kendoDialog({
121  title: "Confirm Deletion",
122  content: "Are you sure you want to delete these sub-accounts?",
123  actions: [
124  {text: "No"},
125  {text: "Yes", primary: true, action: function() {
126  deleteConfirmDialog.close();
127  var surveyid= Number($("#deleteConfirmDialog").data("surveyid"));
128  showWaitWindow();
129  $.post("<?php echo $self ?>&operation=delete", {surveyid: surveyid}, function(data) {
130  hideWaitWindow();
131 
132  if (data.error.length > 0)
133  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
134  else
135  {
136  <?php if ($fromMain) { ?>
137  $.homecuValidator.displayMessage("<?php echo $statusText; ?>", $.homecuValidator.settings.statusInfo );
138  $("#surveyGrid").data("kendoGrid").removeRow($("#deleteConfirmDialog").data("tr"));
139  <?php } else { ?>
140  window.location.href= "<?php echo $self; ?>&mode=deleted";
141  <?php } ?>
142  }
143  });
144  return false;
145  }
146  }
147  ],
148  visible: false,
149  open: function() {
150  if (window.activeWindows != null)
151  window.activeWindows.push(this);
152  },
153  close: function() {
154  if (window.activeWindows != null)
155  window.activeWindows.pop();
156  }
157  }).data("kendoDialog");
158  }
159 
160  var template= kendo.template('<p><?php echo $warnText; ?> "<b>#: surveyname #</b>."</p>'
161  + '<p>Do you wish to continue?</p>');
162 
163  $("#deleteConfirmDialog").data({surveyid: surveyid, tr: tr});
164  deleteConfirmDialog.content(template({surveyname: surveyname})).open();
165  }
166 
167 <?php }
168 
169 /**
170  * function printMainPage($isMarketing, $self, $mode)
171  * This prints out the main page. There are a couple of changes if $isMarketing.
172  *
173  * @param boolean $isMarketing -- If false, Survey Intro and Results links will be displayed.
174  * @param string $self -- The URL of the page, including FT which determines $isMarketing.
175  * @param string $mode -- If this is non-empty, then a info message will show at the top of the page (if a survey was deleted or saved successfully.)
176  */
177 function printMainPage($isMarketing, $self, $mode)
178 {
179  $text= $isMarketing ? "Marketing" : "Surveys";
180  $addText= $isMarketing ? "Marketing Message" : "Survey";
181  $modeText= $mode == "" ? "" : "$text message $mode correctly.";
182  ?>
183  <script type="text/javascript">
184  <?php // Library javascript functions
185  getShowWaitFunctions();
186  printDeleteAllConfirm($isMarketing, $self, true);
187  ?>
188 
189  var detailRecords= [];
190  var rowA= 0;
191 
192  <?php
193  /**
194  * function init()
195  * Initializes the main grid and any click events needed. If !$isMarketing, Results link exists.
196  */ ?>
197  function init()
198  {
199  $.homecuValidator.setup({formValidate: "surveyMntcMainForm", formStatusField: "mainValidateDiv"});
200  var grid= $("#surveyGrid").kendoGrid({
201  dataSource: {
202  transport: {
203  read: function (options)
204  {
205  options.success(detailRecords);
206  }
207  },
208  schema: {
209  model: {
210  id: "surveyid",
211  fields: {
212  surveyid: {type: "number"},
213  startdate: {type: "date"},
214  stopdate: {type: "date"},
215  surveyname: {type: "string"},
216  status: {type: "string"},
217  range: {type: "string"},
218  surveyType: {type: "string"},
219  sortid: {type: "number"}
220  }
221  }
222  },
223  sort: {field: "sortid", dir: "desc"}
224  },
225  columns: [{title: "Title"}, {title: "Type", headerAttributes: {"class": "hidden-xs"}}, {title: "Status", headerAttributes: {"class": "hidden-xs"}},
226  {title: "Range", headerAttributes: {"class": "hidden-xs"}}, {headerTemplate: "&nbsp;"}],
227  rowTemplate: $("#rowTemplate").html(),
228  autoBind: false,
229  sortable: true
230  }).data("kendoGrid");
231 
232  $("#surveyGrid colgroup").each(function() {
233  $(this).html(kendo.template($("#colTemplate").html()));
234  });
235 
236  showWaitWindow();
237  $.post("<?php echo $self; ?>&operation=readMain", {}, function(data) {
238  hideWaitWindow();
239  if (data.error.length > 0)
240  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
241  else
242  {
243  <?php if ($modeText != "") { ?>
244  $.homecuValidator.displayMessage("<?php echo $modeText; ?>", $.homecuValidator.settings.statusInfo );
245  <?php } ?>
246 
247  detailRecords= data.record;
248  grid.dataSource.read();
249  detailRecords= [];
250  }
251  });
252 
253  $("#surveyGrid").on("click", ".surveyExtendBtn", function() {
254  var dataItem= grid.dataItem($(this).closest("tr"));
255  window.location.href= "<?php echo $self; ?>&page=extendDates&surveyid=" + dataItem.surveyid;
256  return false;
257  });
258 
259  $("#surveyGrid").on("click", ".surveyEditBtn", function() {
260  var dataItem= grid.dataItem($(this).closest("tr"));
261  window.location.href= "<?php echo $self; ?>&page=edit&surveyid=" + dataItem.surveyid;
262  return false;
263  });
264 
265  $("#surveyGrid").on("click", ".surveyResultsBtn", function() {
266  var dataItem= grid.dataItem($(this).closest("tr"));
267  window.location.href= "<?php echo $self; ?>&page=results&surveyid=" + dataItem.surveyid;
268  return false;
269  });
270 
271  $("#main-container").on("click", ".surveyNewBtn", function() {
272  window.location.href= "<?php echo $self; ?>&page=edit";
273  return false;
274  });
275 
276  $("#surveyGrid").on("click", ".surveyDeleteBtn", function() {
277  var tr= $(this).closest("tr");
278  var dataItem= grid.dataItem(tr);
279  openDeleteAllTemplate(dataItem.surveyid, dataItem.surveyname, tr);
280  return false;
281  });
282 
283  $("#surveyGrid").on("click", ".surveyViewBtn", function() {
284  var dataItem= $("#surveyGrid").data("kendoGrid").dataItem($(this).closest("tr"));
285  window.location.href= "<?php echo $self; ?>&page=preview&surveyid=" + dataItem.surveyid;
286  return false;
287  });
288  }
289 
290  var activeWindows= [];
291  $(document).ready(function() {
292  init();
293  <?php printClickOverlayEvent(); ?>
294  });
295  </script>
296  <script type="text/x-kendo-template" id="rowTemplate">
297  # var extendDateLink= status != "Draft" ? "<a href='\\#' class='surveyExtendBtn'>Extend Date</a>" : "Extend Date";
298  var viewLink= status != "Past" ? "<a href='\\#' class='surveyViewBtn'>View</a>" : "View"; #
299  <tr data-uid='#: uid #'><td>#: surveyname # <span class="visible-xs-inline"><br><b>Range</b> #: range #<br><b>Status</b> #: status #</span></td>
300  <td class="hidden-xs">#: surveyType #</td>
301  <td class="hidden-xs">#: status #</td>
302  <td class="hidden-xs">#: range #</td>
303  <td class='linkTD'>
304  <div class="dropdown">
305  <a href="\\#" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span>
306  <ul class="dropdown-menu" aria-labelledby="actionMenu">
307  <li><a href='\\#' class='surveyEditBtn'>Edit</a></li>
308  # if (status != "Past") { # <li><a href='\\#' class='surveyViewBtn'>View</a></li> # } #
309  # if (status != "Draft") { # <li><a href='\\#' class='surveyExtendBtn'>Extend Date</a></li> # } #
310  <?php if (!$isMarketing) { ?> <li><a href='\\#' class='surveyResultsBtn'>Results</a></li> <?php } ?>
311  <li><a href='\\#' class='surveyDeleteBtn'>Delete</a></li>
312  </ul>
313  </a>
314  </div>
315  </td>
316  </tr>
317  </script>
318  <script type="text/x-kendo-template" id="colTemplate">
319  <col class="col-xs-8 col-sm-4 col-lg-2">
320  <col class="hidden-xs col-sm-2 col-lg-1">
321  <col class="hidden-xs col-sm-1 col-lg-1">
322  <col class="hidden-xs col-sm-3 col-lg-1">
323  <col class="col-xs-4 col-sm-2 col-lg-1">
324  </script>
325  <div class="container hcu-all-100">
326  <div id="mainValidateDiv"></div>
327  <div class="row"><div class="col-xs-12"><a href='#' class='surveyNewBtn'>New <?php echo $addText; ?></a>
328  <?php if (!$isMarketing) { ?>
329  <div class="row"><div class="col-xs-12"><a href="<?php echo $self; ?>&page=intro">Survey Intro</a></div></div>
330  <div class="row"><div class="col-xs-12"><b> See Results: </b>
331  <a href="<?php echo $self; ?>&page=results&mode=all" id="allSurveys">All Surveys</a>&nbsp;|&nbsp;
332  <a href="<?php echo $self; ?>&page=results&mode=past" id="pastSurveys">Past Surveys</a>&nbsp;|&nbsp;
333  <a href="<?php echo $self; ?>&page=results&mode=present" id="presentSurveys">Present Surveys</a>&nbsp;
334  </div></div>
335  <?php } ?>
336  <div class="row"><div class="col-xs-12"><b> Preview: </b>
337  <a href="<?php echo $self; ?>&page=preview&mode=all">All <?php echo $text; ?></a>&nbsp;|&nbsp;
338  <a href="<?php echo $self; ?>&page=preview&mode=draft">Draft <?php echo $text; ?></a>&nbsp;|&nbsp;
339  <a href="<?php echo $self; ?>&page=preview&mode=present">Present <?php echo $text; ?></a>&nbsp;|&nbsp;
340  <a href="<?php echo $self; ?>&page=preview&mode=future">Future <?php echo $text; ?></a>&nbsp;
341  </div></div>
342  <div class="row">
343  <div class="col-xs-12">
344  <div id="surveyGrid" class="hcu-all-100"></div>
345  </div>
346  </div>
347  <form id="surveyMntcMainForm"></form> <?php //Needs a form to send display messages to. ?>
348  </div>
349 <?php }
350 
351 /**
352  * function printPreviewPage($isMarketing, $self, $previewData)
353  * Prints out the preview page (was a popup)
354  *
355  * @param $isMarketing -- whether this is marketing or not.
356  * @param $self -- the URL of this page.
357  * @param $previewData -- the data from the data call.
358  */
359 function printPreviewPage($isMarketing, $self, $previewData)
360 {
361  $text= $isMarketing ? "Marketing" : "Surveys"; ?>
362  <script type="text/javascript">
363  <?php // Library javascript functions
364  getShowWaitFunctions(); ?>
365 
366  function init()
367  {
368  $.homecuValidator.setup({formValidate:'previewDIV', formStatusField: 'formValidate'});
369  var template= kendo.template($("#previewTemplate").html());
370  var data= <?php echo HCU_JsonEncode($previewData); ?>;
371  if (data.error.length > 0)
372  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
373  else
374  $("#previewDIV").html(template({languages: data.data}));
375  }
376 
377  $(document).ready(function() {
378  init();
379  });
380  </script>
381  <script type="text/x-kendo-template" id="previewTemplate">
382  # var l=0; if (languages.length == 0) { # (No Records Found) # } else {
383  for(var i=0, iLength= languages.length; i!= iLength; i++) { var lang= languages[i];
384  if (lang.surveys.length == 0 <?php if (!$isMarketing) { ?> && lang.surveyintro == ""<?php } ?>) continue; #
385  <div class="container-fluid" data-language="#: lang.language #" data-description="#: lang.description #">
386  # if (lang.language != "en_US") { # <div class="row"><div class="col-xs-12 h4">#: lang.description # </div></div> # } #
387  <?php if (!$isMarketing) { ?> <div class="row"><div class="col-xs-12"><b>Intro:</b> #: lang.surveyintro #</div></div> <?php } ?>
388 
389  # if (lang.surveys.length == 0) { # <div class="col-xs-12">(No Results)</div> # } else {
390  for (var j=0, jLength= lang.surveys.length; j!= jLength; j++) { var survey= lang.surveys[j];
391  var question= survey.question == null || survey.question.trim() == '' ? "(No question)" : survey.question; #
392  <div class="well well-sm row">
393  <div class="container-fluid" data-id="#: survey.surveyid #">
394  <div class="col-xs-12 hcu-no-padding"><?php if (!$isMarketing) { ?>#: question #<?php } else { ?> #= question # <?php } ?></div>
395  <?php if (!$isMarketing) { ?>
396  # if (survey.answers.length == 0) { # (No answers) # } else {
397  l++; for (var k=0, kLength= survey.answers.length; k != kLength; k++) { var answer= survey.answers[k]; #
398  <div class="col-xs-12 hcu-no-padding"><div class="radio radio-inline radio-spacer"><label><input type='radio' name='radio#: l #'>&nbsp;#: answer.text #</label></div></div>
399  # }} #
400  <?php } ?>
401  </div></div>
402  # }} #
403  </div>
404  # }} #
405  </script>
406 
407  <div id="formValidate"></div>
408  <div class="container-fluid">
409  <div class="row hcuSpacer"><div class="col-xs-12">
410  <a href="<?php echo $self; ?>" id="surveyMenu"><?php if ($isMarketing) { ?> Marketing Messages <?php } else { ?> Survey Menu <?php } ?></a>&nbsp;&nbsp;&nbsp;<b> See Results: </b>
411  <a href="<?php echo $self; ?>&page=preview&mode=all">All <?php echo $text; ?></a>&nbsp;|&nbsp;
412  <a href="<?php echo $self; ?>&page=preview&mode=draft">Draft <?php echo $text; ?></a>&nbsp;|&nbsp;
413  <a href="<?php echo $self; ?>&page=preview&mode=present">Present <?php echo $text; ?></a>&nbsp;|&nbsp;
414  <a href="<?php echo $self; ?>&page=preview&mode=future">Future <?php echo $text; ?></a>&nbsp;
415  </div></div>
416  <div class="row">
417  <div id="previewDIV" class="col-xs-12"></div>
418  </div>
419  </div>
420 
421 <?php }
422 
423 /**
424  * function printExtendDatesPage($isMarketing, $self, $surveyid)
425  * Prints out the extend dates page.
426  *
427  * @param $isMarketing -- If false, dontShow div and answers are displayed. If true, questions are not bolded and are not HTML encoded.
428  * @param $self -- the URL of the page.
429  * @param $surveyid -- the surveyid to extend dates for.
430  */
431 function printExtendDatesPage($isMarketing, $self, $surveyid)
432 {
433  $surveyid= intval($surveyid);
434  $text= $isMarketing ? "Marketing" : "Survey";
435  $modeText= $mode == "" ? "" : "$text message $mode correctly.";
436  ?>
437  <script type="text/javascript">
438  <?php // Library javascript functions
439  getShowWaitFunctions();
440 
441  /**
442  * function init()
443  * Sets up validation for the dates, and populates data for the page.
444  */
445  ?>
446  function init()
447  {
448  $.homecuValidator.setup({formValidate:'surveyMntcEditForm', formStatusField: 'mainValidateDiv'});
449 
450  var fromDatePicker= $("[name='from']").kendoDatePicker({}).data("kendoDatePicker");
451  var toDatePicker= $("[name='to']").kendoDatePicker({}).data("kendoDatePicker");
452 
453  $("#saveBtn").click(function() {
454  if ($.homecuValidator.validate())
455  {
456  var parameters= {surveyid: <?php echo $surveyid; ?>};
457  parameters.startdate= kendo.toString(fromDatePicker.value(), "yyyy-MM-dd");
458  parameters.stopdate= kendo.toString(toDatePicker.value(), "yyyy-MM-dd");
459  parameters.dontshow= $("[name='dontShowUsers']").prop("checked") ? "Y" : "N";
460  parameters.surveyname= $("[name='name']").val().trim();
461 
462  showWaitWindow();
463  $.post("<?php echo $self; ?>&operation=extendDates", parameters, function(data) {
464  hideWaitWindow();
465 
466  if (data.error.length > 0)
467  $.homecuValidator.displayMessage( data.error, $.homecuValidator.settings.statusError );
468  else
469  window.location.href= "<?php echo $self; ?>&mode=saved";
470  });
471  }
472  return false;
473  });
474 
475  $("#cancelBtn").click(function() {
476  window.location.href= "<?php echo $self; ?>";
477  return false;
478  });
479 
480  var templateQuestion= "# if (language.question == null || language.question.trim() == '') { # (No question) # } else { # ";
481  <?php if ($isMarketing) { ?>
482  templateQuestion= templateQuestion + "#= language.question #" + " # } #"; <?php // Need to not encode the HTML in the question. ?>
483  var templateAnswers= "";
484  <?php } else { ?>
485  templateQuestion= "<b>" + templateQuestion + "#: language.question #" + " # } #</b>"; <?php // Bold it only when it is a survey. ?>
486  var templateAnswers= "# if (language.answers.length == 0) { # (No answers) # } else { for (var j=0; j!= language.answers.length; j++) { var answer= language.answers[j]; #"
487  + "<div class='row radio radio-spacer'><label><input type='radio' name='radio#: i #' disabled>&nbsp;#: answer.text #</label></div> # }} # <div class='row'><hr></div></div>"
488  <?php } ?>
489  var template= kendo.template("<div class='container' style='width:100%'> # for (var i=0, iLength= languages.length; i!= iLength; i++) { var language= languages[i]; #"
490  + "<div class='languageWrapper' data-id='#: language.language #'> # if (language.language != 'en_US') { # <div class='row'>( #: language.description # )</div> # } #"
491  + "<div class='row'>" + templateQuestion + "</div>" + templateAnswers + "# } # </div>");
492 
493  showWaitWindow();
494  $.post("<?php echo $self; ?>&operation=readExtendDates", {surveyid: <?php echo $surveyid; ?>}, function(data) {
495  hideWaitWindow();
496  if (data.error.length > 0)
497  $.homecuValidator.displayMessage( data.error, $.homecuValidator.settings.statusError );
498  else
499  {
500  var masterData= data.data[0];
501  $("#surveyNameInput").text(masterData.surveyname);
502  fromDatePicker.value(masterData.startdate);
503  toDatePicker.value(masterData.stopdate);
504  $("[name='dontShowUsers']").prop("checked", masterData.dontShow);
505  $("[name='name']").val(masterData.surveyname);
506 
507  $("#surveyPreview").html(template(masterData));
508  }
509  });
510  }
511  $(document).ready(function() {
512  init();
513  });
514  </script>
515  <style>
516  .radio-spacer input {
517  margin-top: 2px;
518  }
519  .check input {
520  margin-top: -4px;
521  margin-right: 3px;
522  }
523  .radio-spacer {
524  margin-left: 0;
525  float: initial;
526  }
527 
528  .surveyMntcMax {
529  max-width: 1100px;
530  }
531  </style>
532  <div class="surveyMntcMax"><div id="surveyMntcContainer" class="container-fluid hcu-template"><form id="surveyMntcEditForm">
533  <div class="row">
534  <div id="mainValidateDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
535  </div>
536  <div class="row"><div class="col-xs-12 h3"><?php echo $text; ?> Details</div></div>
537  <div class="row hcuSpacer">
538  <div class="col-xs-12 col-sm-2"><?php echo $text; ?> Name</div>
539  <div class="col-xs-12 col-sm-10"><input type="text" class="k-input k-textbox hcu-all-100" name="name" maxlength="50"></div>
540  </div>
541  <div class="row hcuSpacer">
542  <div class="col-xs-12 col-sm-2">Run Dates</div>
543  <div class="col-xs-12 col-sm-10 hcu-no-padding">
544  <div class="col-xs-5"><input id="from" name="from" required class="hcu-all-100" homecu-match="date" data-homecuCustomMatch-msg="From date is invalid"></div>
545  <div class="col-xs-2"><center>To</center></div>
546  <div class="col-xs-5"><input id="to" name="to" required class="hcu-all-100" homecu-match="date" data-homecuCustomMatch-msg="To date is invalid" homecu-dategtvalue="from"
547  homecu-dategttype="field" data-homecuCustomDateGTValue-msg="Invalid range"></div>
548  </div>
549  </div>
550 
551  <?php if (!$isMarketing) { ?>
552  <div class="row">
553  <div class="check"><label class="col-xs-12"><input type="checkbox" name="dontShowUsers"> Suppress survey results from the member?</label></div>
554  </div>
555  <?php } ?>
556  <div class="row"><hr class="col-xs-12"></div>
557  <div class='row'>
558  <div class="col-xs-12 col-sm-2">Preview</div>
559  <div class="col-xs-12 col-sm-10"><div class="well well-sm"><div id='surveyPreview' class="hcu-all-100"></div></div></div>
560  </div>
561 
562  <div class="hcu-edit-buttons k-state-default row">
563  <a id='cancelBtn' href="#">Cancel</a>&nbsp;&nbsp;&nbsp;
564  <a id="saveBtn" class="k-button k-primary" href="#">Save Dates</a>
565  </div>
566  </form></div></div>
567 <?php }
568 
569 /**
570  * function printValidateQuestionsAnswers()
571  * Adds validation for the answer grid and question tab strip. This is only used for survey maintenance, not for marketing messages.
572  */
573 function printValidateQuestionsAnswers()
574 {
575  /**
576  * validateAnswers: function(input)
577  * This function will validate the answer grid. It is on two hidden inputs: "[name='answerGridValidate']" for the whole grid and ".answerRowValidate" for validation of the row.
578  * @return boolean -- false if there is an error. Here are the possible error messages:
579  * answerGridValidate-- "There must be at least one answer.", "There must be at least one English answer.", (For when there are no records or no English records)
580  * "There must be at least one Spanish answer.", "There must be at least one Polish answer." (If the corresponding question is non-empty)
581  * answerRowValidate-- "English answer must be populated when Spanish or Polish is populated.", "Spanish answer must be populated when Spanish question is populated.",
582  * "Polish answer must be populated when Polish question is populated."
583  */ ?>
584  validateAnswers: function(input)
585  {
586  if (input.is("[name='validateAnswers']"))
587  {
588  var showSpanish= !$("#surveyMntcContainer").hasClass("hideBB");
589  var showPolish= !$("#surveyMntcContainer").hasClass("hideCC");
590  var valid= true;
591  $("#surveyQuestionTabStrip .question[data-language]").each(function() {
592  if ($(this).val() != "")
593  return true;
594 
595  switch($(this).data("language"))
596  {
597  case "en_US":
598  $(input).attr("data-validateAnswers-msg", "English question must be populated.");
599  valid= false;
600  return false;
601  break;
602  case "es_US":
603  if (showSpanish)
604  {
605  $(input).attr("data-validateAnswers-msg", "Spanish question must be populated.");
606  valid= false;
607  return false;
608  }
609  break;
610  case "pl_US":
611  if (showPolish)
612  {
613  $(input).attr("data-validateAnswers-msg", "Spanish question must be populated.");
614  valid= false;
615  return false;
616  }
617  break;
618  }
619  });
620 
621  if (!valid)
622  return false;
623 
624  $("#answerGrid tbody tr td").each(function() {
625  var emptyEnglish= $(this).find("[data-language='en_US'] input").val().trim() == "";
626  var emptySpanish= $(this).find("[data-language='es_US'] input").val().trim() == "";
627  var emptyPolish= $(this).find("[data-language='pl_US'] input").val().trim() == "";
628 
629  if (emptyEnglish && ((showSpanish && !emptySpanish) || (showPolish && !emptyPolish)))
630  {
631  valid= false;
632  $(input).attr("data-validateAnswers-msg", "English answers must be populated when other languages are filled in.");
633  return false;
634  }
635 
636  if (!emptyEnglish && showSpanish && emptySpanish)
637  {
638  valid= false;
639  $(input).attr("data-validateAnswers-msg", "Spanish answers must be populated.");
640  return false;
641  }
642 
643  if (!emptyEnglish && showPolish && emptyPolish)
644  {
645  valid= false;
646  $(input).attr("data-validateAnswers-msg", "Polish answers must be populated.");
647  return false;
648  }
649  });
650 
651  if (!valid)
652  return false;
653  }
654  return true;
655  }
656 <?php }
657 
658 /**
659  * function printSurveyOnlyExtraFunctions()
660  * These are extra functions that are only added to the edit page when the page is survey maintenance, not marketing messages.
661  */
662 function printSurveyOnlyExtraFunctions()
663 { ?>
664  var answers= [];
665 
666  <?php
667  /**
668  * function initAnswerGrid()
669  * This function initializes the answer grid, all click events associated to it, the answer delete window,
670  * and adds the data-language attribute to "colgroup col." (needed to show/hide languages)
671  */ ?>
672  function initAnswerGrid()
673  {
674  var rowid= 0;
675  var answerGrid= $("#answerGrid").kendoGrid({
676  dataSource: {
677  data: [],
678  schema: {
679  model: {
680  id: "rowid",
681  fields: {
682  rowid: {type: "number"},
683  english: {type: "string"},
684  spanish: {type: "string"},
685  polish: {type: "string"}
686  }
687  }
688  }
689  },
690  columns: [{headerTemplate: kendo.template($("#answerGridHeaderTemplate").html())}],
691  rowTemplate: $("#answerGridRowTemplate").html(),
692  noRecords: {
693  template: "<tr><td>No Records Found!</td></tr>"
694  },
695  toolbar: "<a class='k-grid-add' href='\\#'>Add Answer Row</a>",
696  editable: {
697  mode: "inline",
698  createAt: "bottom",
699  confirmation: false
700  }
701  }).data("kendoGrid");
702 
703  var inAdd= false; <?php //Prevent benign javascript error. ?>
704  $("#answerGrid").on("click", ".k-grid-add", function() {
705  inAdd= true;
706  answerGrid.addRow();
707  answerGrid.saveChanges();
708  inAdd= false;
709  return false;
710  });
711 
712  $("#answerGrid .k-grid-header").addClass("hidden-xs");
713 
714  $("<div id='answerDeleteWindow'></div>").appendTo("body");
715 
716  $("#answerGrid").on("click", ".k-grid-custdelete", function() {
717  var deleteWindow= $("#answerDeleteWindow").data("kendoDialog");
718 
719  if (deleteWindow == null)
720  {
721  var deleteWindow= $("<div id='answerDeleteWindow'></div>").kendoDialog({
722  content: "<p>Are you sure you want to remove this answer?</p>",
723  visible: false,
724  modal: true,
725  title: "Confirm Removal",
726  width: 405,
727  open: function() {
728  if (window.activeWindows != null)
729  window.activeWindows.push(this);
730  },
731  close: function() {
732  if (window.activeWindows != null)
733  window.activeWindows.pop();
734  },
735  actions: [
736  {text: "No"},
737  {text: "Yes", primary: true, action: function() {
738  deleteWindow.close();
739  var tr= $("#answerDeleteWindow").data("tr");
740  $("#answerGrid").data("kendoGrid").removeRow(tr);
741  }}
742  ]
743  }).data("kendoDialog");
744  }
745  $("#answerDeleteWindow").data("tr", $(this).closest("tr"));
746  deleteWindow.open();
747  return false;
748  });
749 
750  $("#answerGrid").on("blur", "tbody [data-language] input", function() {
751  if (inAdd) <?php // Prevent benign javascript error. ?>
752  return;
753 
754  var value= $(this).val().trim();
755  var tr= $(this).closest("tr");
756  var language= $(this).closest("[data-language]").attr("data-language").trim();
757  var dataItem= answerGrid.dataItem(tr);
758  switch(language)
759  {
760  case "en_US":
761  dataItem.english= value;
762  break;
763  case "es_US":
764  dataItem.spanish= value;
765  break;
766  case "pl_US":
767  dataItem.polish= value;
768  break;
769  }
770  });
771  }
772 <?php }
773 
774 /**
775  * function printMarketingMessageOnlyExtraFunctions()
776  * This function prints extra functions only needed for marketing messages, not survey maintenance
777  */
778 function printMarketingMessageOnlyExtraFunctions()
779 {
780  /**
781  * function initTinyMCE()
782  * This function initializes the tinymce editors are were in the days of old and antiquity.
783  */
784  ?>
785  function initTinyMCE()
786  {
787  tinymce.init({
788  selector: "#surveyQuestionTabStrip textarea",
789  relative_urls: false,
790  remove_script_host : false,
791  plugins: [
792  "advlist autolink link image lists preview anchor pagebreak",
793  "searchreplace visualblocks visualchars code insertdatetime nonbreaking",
794  "table contextmenu directionality template textcolor homecuchar paste textcolor"
795  ],
796  toolbar1: "code newdocument | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | fontselect fontsizeselect | bullist numlist",
797  toolbar2: "outdent indent blockquote | undo redo | link unlink image | preview | forecolor backcolor | removeformat | homecuchar | nonbreaking",
798  toolbar3: "",
799  menubar : false,
800  toolbar_items_size: "small",
801  valid_children : "+body[style]"
802  });
803  }
804 <?php }
805 
806 /**
807  * function printEditPage($isMarketing, $self, $cloudfrontDomainName, $surveyid=0)
808  * This prints out the edit page. It varies based on the $isMarketing variable and if the $surveyid == 0 or not.
809  *
810  * @param boolean $isMarketing -- this changes quite a bit on this page. The variable affects the wording on the annoying popup.
811  * If true, the tinyMCE editor is initialized for the questions and there is different logic for getting the different languages on a save.
812  * If false, the answers are displayed and there are additional functions to validate and save.
813  * @param string $self -- the URL of the page.
814  * @param integer $surveyid -- the ID of the survey/marketing message that we are editing. An ID of zero means that it is a new survey/marketing message.
815  */
816 function printEditPage($isMarketing, $self, $surveyid=0)
817 {
818  $cloudfrontDomainName = GetCloudFrontDomainName();
819  $tinymceVersion = GetTinyMCEVersion ();
820  $surveyid= intval($surveyid);
821  $text= $isMarketing ? "Message" : "Survey";
822  $saveInfo= $isMarketing ? "Changing this marketing message will cause all members to see the message!" : "Saving this survey will remove survey results!";
823  $confirmSaveText= $isMarketing ? "marketing message" : "survey";
824  ?>
825  <?php if ($isMarketing) { ?>
826  <script type="text/javascript" src="https://<?php echo $cloudfrontDomainName; ?>/homecu/js/tinymce/<?php echo $tinymceVersion; ?>/tinymce.min.js"></script>
827  <script type="text/javascript" src="https://<?php echo $cloudfrontDomainName; ?>/homecu/js/tinymce/homecuchar.plugin.js"></script>
828  <?php } ?>
829  <script type="text/javascript">
830  <?php // Library javascript functions
831  getShowWaitFunctions();
832 
833  printDeleteAllConfirm($isMarketing, $self, false);
834  $isMarketing ? printMarketingMessageOnlyExtraFunctions() : printSurveyOnlyExtraFunctions(); ?>
835 
836  var answers= [];
837 
838  <?php
839  /**
840  * function init()
841  * This function sets up validation, adds click events, and populates page with data for the survey/marketing message.
842  */ ?>
843  function init()
844  {
845  $.homecuValidator.setup({formValidate:'surveyMntcEditForm', formStatusField: 'mainValidateDiv', homecuCustomRules: {
846  <?php if (!$isMarketing) { printValidateQuestionsAnswers(); } ?>
847  }});
848 
849  var fromDatePicker= $("[name='fromEdit']").kendoDatePicker({}).data("kendoDatePicker");
850  var toDatePicker= $("[name='toEdit']").kendoDatePicker({}).data("kendoDatePicker");
851 
852  <?php if (!$isMarketing) { ?>
853  initAnswerGrid();
854  <?php }
855 
856  /**
857  * $("#saveBtn").click(function()
858  * This function tries to save the survey/marketing message. If the validation doesn't fail, it checks the "hasResults" attribute. The "hasResults" attribute comes from the
859  * read data call. For a marketing message, it is one that isn't a draft. For a survey, it is one that has a record in the cusurveysays table. If this is true,
860  * then a dialog will popup to confirm the save. Otherwise, the save will happen without a popup.
861  */ ?>
862  $("#saveBtn").click(function() {
863  if ($.homecuValidator.validate())
864  {
865  var saveWindow= $("#saveWindow").data("kendoDialog");
866  if (saveWindow == null)
867  {
868  saveWindow= $("<div id='saveWindow'></div>").appendTo("body").kendoDialog({
869  content: "<p>Are you sure you want to save this <?php echo $confirmSaveText; ?>?</p>" + ($(this).data("hasResults") ? "<p><?php echo $saveInfo; ?></p>" : ""),
870  visible: false,
871  modal: true,
872  title: "Confirm Save",
873  width: 400,
874  resizable: false,
875  open: function() {
876  if (window.activeWindows != null)
877  window.activeWindows.push(this);
878  },
879  close: function() {
880  if (window.activeWindows != null)
881  window.activeWindows.pop();
882  },
883  actions: [
884  {text: "Cancel"},
885  {text: "Save", primary: true, action: function() {
886  saveWindow.close();
887  doSave(fromDatePicker, toDatePicker, questionTabStrip);
888  }}
889  ]
890  }).data("kendoDialog");
891  }
892  saveWindow.open();
893  }
894 
895  return false;
896  });
897 
898  $("#cancelBtn").click(function() {
899  window.location.href= "<?php echo $self; ?>";
900  return false;
901  });
902 
903  var questionTabStrip= $("#surveyQuestionTabStrip").kendoTabStrip({
904  dataTextField: "description",
905  dataContentField: "template",
906  dataSource: {
907  data: [],
908  schema: {
909  model: {
910  id: "language",
911  fields: {
912  language: {type: "string"},
913  description: {type: "string"},
914  question: {type: "string"},
915  template: {type: "string"},
916  index: {type: "number"}
917  }
918  }
919  }
920  },
921  activate: function(e)
922  {
923  <?php if ($isMarketing) { ?>
924  if (tinymce.editors.length > 0)
925  {
926  var index= $(e.item).index();
927  tinymce.editors[index].focus();
928  }
929  <?php } else { ?>
930  $("#surveyQuestionTabStrip textarea:visible").focus();
931  <?php } ?>
932  }
933  }).data("kendoTabStrip");
934 
935  <?php // Add hide classes so that Spanish and Polish aren't shown initially. ?>
936  setTimeout(function() {
937  $(questionTabStrip.wrapper).find(".k-tabstrip-items li").each(function(index) {
938  var classClass= index == 0 ? "aa" : (index == 1 ? "bb" : "cc");
939  $(this).addClass(classClass);
940  });
941  }, 200);
942 
943  $("#addSpanishBtn").click(function() {
944  if ($(this).text().trim() == "Add Spanish")
945  {
946  $("#surveyMntcContainer").removeClass("hideBB");
947  $(this).text("Remove Spanish");
948  }
949  else
950  {
951  $("#surveyMntcContainer").addClass("hideBB");
952  $(this).text("Add Spanish");
953  }
954 
955  <?php if (!$isMarketing) { ?>
956  var grid= $("#answerGrid").data("kendoGrid");
957  var options= grid.getOptions();
958  options.columns[0].headerAttributes= kendo.template($("#answerGridHeaderTemplate").html());
959  grid.saveChanges();
960  grid.setOptions(options);
961  $("#answerGrid .k-grid-header").addClass("hidden-xs");
962  <?php } ?>
963  return false;
964  });
965 
966  $("#addPolishBtn").click(function() {
967  if ($(this).text().trim() == "Add Polish")
968  {
969  $("#surveyMntcContainer").removeClass("hideCC");
970  $(this).text("Remove Polish");
971  }
972  else
973  {
974  $("#surveyMntcContainer").addClass("hideCC");
975  $(this).text("Add Polish");
976  }
977 
978  <?php if (!$isMarketing) { ?>
979  var grid= $("#answerGrid").data("kendoGrid");
980  var options= grid.getOptions();
981  options.columns[0].headerAttributes= kendo.template($("#answerGridHeaderTemplate").html());
982  grid.saveChanges();
983  grid.setOptions(options);
984  $("#answerGrid .k-grid-header").addClass("hidden-xs");
985  <?php } ?>
986  return false;
987  });
988 
989  <?php if (!$isMarketing) { ?>
990  $("#surveyQuestionTabStrip").on("blur", "textarea", function() {
991  $("[name='validateQuestions']").blur();
992  var data= questionTabStrip.dataSource.data();
993  var row= data[$(this).closest(".questionTemplateBody").data("index")];
994  row.question= $(this).val();
995  });
996  <?php } ?>
997 
998  var questionTemplate= '<div data-index="#:index#" class="questionTemplateBody"><textarea class="question" data-language="#: language #" style="width:100%" maxlength="2000">'
999  + '#:question#</textarea></div>';
1000 
1001  <?php
1002  /**
1003  * if ($surveyid != 0)
1004  * If editing an existing survey/marketing message, do this. It calls the readEdit data call. On return, data is populated. If $isMarketing, initMCE. Otherwise, populate answers.
1005  */
1006  if ($surveyid != 0) { ?>
1007  showWaitWindow();
1008  $.post("<?php echo $self; ?>&operation=readEdit", {surveyid: <?php echo $surveyid; ?>}, function(data) {
1009  hideWaitWindow();
1010  if (data.error.length > 0)
1011  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1012  else
1013  {
1014  $("[name='name']").val(data.masterData.surveyname);
1015  fromDatePicker.value(data.masterData.startdate);
1016  toDatePicker.value(data.masterData.stopdate);
1017  $("[name='draft']").prop("checked", data.masterData.isDraft);
1018  $("[name='includeEmps']").prop("checked", data.masterData.affectsEmployees);
1019  $("[name='type']:eq(" + (data.masterData.isPopup ? 0 : 1) + ")").prop("checked", true);
1020  $("[name='dontShowUsers']").prop("checked", data.masterData.dontShow);
1021 
1022  questionTemplate= kendo.template(questionTemplate);
1023  var englishIndex= -1;
1024  for(var i=0; i!= data.questionData.length; i++)
1025  {
1026  var row= data.questionData[i];
1027  row.index= i;
1028  row.template= questionTemplate(row);
1029  row.changed= false;
1030 
1031  if (row.language == "en_US")
1032  englishIndex= i;
1033  }
1034 
1035  questionTabStrip.dataSource.data(data.questionData);
1036  questionTabStrip.select(englishIndex);
1037 
1038  if (data.hasSpanish)
1039  {
1040  $("#surveyMntcContainer").removeClass("hideBB");
1041  $("#addSpanishBtn").text("Remove Spanish");
1042  }
1043  if (data.hasPolish)
1044  {
1045  $("#surveyMntcContainer").removeClass("hideCC");
1046  $("#addPolishBtn").text("Remove Polish");
1047  }
1048 
1049  <?php if (!$isMarketing) { ?>
1050  rowid= data.nextAnswerRowid;
1051  $("#answerGrid").data("kendoGrid").dataSource.data(data.answerData);
1052 
1053  if (data.hasSpanish || data.hasPolish)
1054  {
1055  var grid= $("#answerGrid").data("kendoGrid");
1056  var options= grid.getOptions();
1057  options.columns[0].headerAttributes= kendo.template($("#answerGridHeaderTemplate").html());
1058  grid.saveChanges();
1059  grid.setOptions(options);
1060  $("#answerGrid .k-grid-header").addClass("hidden-xs");
1061  }
1062  <?php } else { ?>
1063  $("[name='title']").val(data.masterData.surveytitle);
1064  initTinyMCE();
1065  <?php } ?>
1066 
1067  if (data.hasResults)
1068  {
1069  $("#saveNotice").show();
1070  openAnnoyingPopup();
1071  }
1072 
1073  $("#saveBtn").data("hasResults", data.hasResults);
1074 
1075  $("#deleteBtn").click(function() {
1076  openDeleteAllTemplate(<?php echo $surveyid; ?>, data.masterData.surveyname);
1077  return false;
1078  });
1079  }
1080  });
1081  <?php
1082  /**
1083  * if ($surveyid == 0)
1084  * If creating a new survey/marketing message, do this. It calls the readNew data call. On return, populates the question tab strip with valid languages and empty strings.
1085  * If $isMarketing, initMCE. Otherwise, populate answers.
1086  */
1087  } else { ?>
1088  showWaitWindow();
1089  $.post("<?php echo $self; ?>&operation=readNew", {}, function(data) {
1090  hideWaitWindow();
1091  if (data.error.length > 0)
1092  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1093  else
1094  {
1095  questionTemplate= kendo.template(questionTemplate);
1096  var englishIndex= -1;
1097  for(var i=0; i!= data.questionData.length; i++)
1098  {
1099  var row= data.questionData[i];
1100  row.index= i;
1101  row.template= questionTemplate(row);
1102  row.changed= false;
1103 
1104  if (row.language == "en_US")
1105  englishIndex= i;
1106  }
1107 
1108  questionTabStrip.dataSource.data(data.questionData);
1109  questionTabStrip.select(englishIndex);
1110 
1111  <?php if (!$isMarketing) { ?>
1112  rowid= 1;
1113  $("#answerGrid").data("kendoGrid").dataSource.data([]);
1114  <?php } else { ?>
1115  initTinyMCE();
1116  <?php } ?>
1117 
1118  $("#saveBtn").data("hasResults", false);
1119 
1120  }
1121  });
1122 
1123 
1124  <?php } ?>
1125  }
1126 
1127  <?php
1128  /**
1129  * function openAnnoyingPopup()
1130  * This function opens the annoying popup. This is the one that first opens when going to the edit page. Clicking the "okay" button closes the window.
1131  * Clicking the "X" or clicking on the grey background redirects to the main page.
1132  */ ?>
1133  function openAnnoyingPopup()
1134  {
1135  var annoyingPopup= $("#annoyingPopup").data("kendoDialog");
1136  if (annoyingPopup == null)
1137  {
1138  $("<div id='annoyingPopup'></div>").appendTo("body");
1139  annoyingPopup= $("#annoyingPopup").kendoDialog({
1140  content: "<?php echo $saveInfo; ?>",
1141  visible: false,
1142  modal: true,
1143  title: "Warning",
1144  width: 400,
1145  resizable: false,
1146  actions: [
1147  {text: "Okay", primary: true}
1148  ],
1149  open: function() {
1150  if (window.activeWindows != null)
1151  window.activeWindows.push(this);
1152  },
1153  close: function() {
1154  if (window.activeWindows != null)
1155  window.activeWindows.pop();
1156  }
1157  }).data("kendoDialog");
1158  }
1159  annoyingPopup.open();
1160  }
1161 
1162  <?php
1163  /**
1164  * function doSave(fromDatePicker, toDatePicker, questionTabStrip)
1165  * This function prepares the page for saving and then sends the data to the save data call. If $isMarketing, the question data is gathered from the tinyMCE editors.
1166  * If !$isMarketing, the question data is gathered from the questionTabStrip.
1167  *
1168  * @param KendoDatePicker fromDatePicker -- the from
1169  * @param KendoDatePicker toDatePicker -- the to
1170  * @param KendoTabStrip questionTabStrip -- the tab strip with the questions
1171  */ ?>
1172  function doSave(fromDatePicker, toDatePicker, questionTabStrip)
1173  {
1174  var parameters= {surveyid: <?php echo $surveyid; ?>};
1175  parameters.startdate= kendo.toString(fromDatePicker.value(), "yyyy-MM-dd");
1176  parameters.stopdate= kendo.toString(toDatePicker.value(), "yyyy-MM-dd");
1177  parameters.surveyname= $("[name='name']").val();
1178  parameters.runstat= $("[name='draft']").prop("checked") ? 0 : 1;
1179  parameters.employee= $("[name='includeEmps']").prop("checked") ? "Y" : "N";
1180  parameters.incBalances= $("[name='type']:checked").data("val") == "balances" ? "Y" : "N";
1181  parameters.dontshow= $("[name='dontShowUsers']").prop("checked") ? "Y" : "N";
1182 
1183  <?php if (!$isMarketing) { ?>
1184  var data= questionTabStrip.dataSource.data();
1185  var condensed= [];
1186  var showSpanish= !$("#surveyMntcContainer").hasClass("hideBB");
1187  var showPolish= !$("#surveyMntcContainer").hasClass("hideCC");
1188  for(var i=0; i!= data.length; i++)
1189  {
1190  var row= data[i];
1191  var language= row.language.trim();
1192  var question= row.question.trim();
1193  if (language == "en_US" || (showSpanish && language == "es_US") || (showPolish && language == "pl_US"))
1194  condensed.push({question: row.question.trim(), language: row.language.trim()});
1195  }
1196  parameters.questions= kendo.stringify(condensed);
1197 
1198  condensed= [];
1199  answers= $("#answerGrid").data("kendoGrid").dataSource.view();
1200 
1201  for(var i=0; i!= answers.length; i++)
1202  {
1203  var row= answers[i];
1204  var english= row.english.trim();
1205  var spanish= showSpanish ? row.spanish.trim() : "";
1206  var polish= showPolish ? row.polish.trim() : "";
1207 
1208  if (english != "" || spanish != "" || polish != "")
1209  condensed.push({english: english, spanish: spanish, polish: polish});
1210  }
1211 
1212  parameters.answers= kendo.stringify(condensed);
1213  <?php } else { ?>
1214  var tinyData= [];
1215  for(var i=0; i != tinymce.editors.length; i++)
1216  {
1217  var editor= tinymce.editors[i];
1218  var value= editor.getContent().trim();
1219  var language= null;
1220  switch(i)
1221  {
1222  case 0:
1223  language= "en_US";
1224  break;
1225  case 1:
1226  language= "es_US";
1227  break;
1228  case 2:
1229  language= "pl_US";
1230  break;
1231  }
1232  tinyData.push({question: value, language: language});
1233  }
1234  parameters.questions= kendo.stringify(tinyData);
1235  parameters.surveytitle= $("[name='title']").val();
1236  <?php } ?>
1237 
1238  showWaitWindow();
1239  $.post("<?php echo $self; ?>&operation=save", parameters, function(data) {
1240  if (data.error.length > 0)
1241  {
1242  hideWaitWindow();
1243  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1244  }
1245  else
1246  window.location.href= "<?php echo $self; ?>&mode=saved";
1247  });
1248  }
1249 
1250  var activeWindows= [];
1251  $(document).ready(function() {
1252  init();
1253  <?php printClickOverlayEvent(); ?>
1254  });
1255 
1256  </script>
1257  <?php if (!$isMarketing) { ?>
1258  <script type="text/x-kendo-template" id="answerGridRowTemplate">
1259  <tr data-uid="#=uid#">
1260  <td class="container-fluid">
1261 
1262  # var showSpanish= !$("\\#surveyMntcContainer").hasClass("hideBB");
1263  var showPolish= !$("\\#surveyMntcContainer").hasClass("hideCC");
1264  var division= showSpanish ? (showPolish ? "col-sm-4" : "col-sm-6") : (showPolish ? "col-sm-6" : "col-sm-12"); #
1265 
1266  <div class="col-xs-12 col-sm-10 hcu-no-padding">
1267  <div class="aa col-xs-12 #= division #" data-language="en_US">
1268  <label class="col-xs-12 hidden-sm hidden-md hidden-lg hcu-no-padding">English</label>
1269  <div class="col-xs-12 hcu-no-padding"><input type="text" class="k-input k-textbox hcu-all-100" value="#:english#" maxlength="255"></div>
1270  </div>
1271  <div class="bb col-xs-12 #= division #" data-language="es_US">
1272  <label class="col-xs-12 hidden-sm hidden-md hidden-lg hcu-no-padding">Spanish</label>
1273  <div class="col-xs-12 hcu-no-padding"><input type="text" class="k-input k-textbox hcu-all-100" value="#:spanish#" maxlength="255"></div>
1274  </div>
1275  <div class="cc col-xs-12 #= division #" data-language="pl_US">
1276  <label class="col-xs-12 hidden-sm hidden-md hidden-lg hcu-no-padding">Polish</label>
1277  <div class="col-xs-12 hcu-no-padding"><input type="text" class="k-input k-textbox hcu-all-100" value="#:polish#" maxlength="255"></div>
1278  </div>
1279  </div>
1280  <div class="col-xs-12 col-sm-2"><a href="\\#" class="k-grid-custdelete">Remove</a></div>
1281  </td>
1282  </tr>
1283  </script>
1284  <script type="text/x-kendo-template" id="answerGridHeaderTemplate">
1285  <div class="container-fluid">
1286  # var showSpanish= !$("\\#surveyMntcContainer").hasClass("hideBB");
1287  var showPolish= !$("\\#surveyMntcContainer").hasClass("hideCC");
1288  var division= showSpanish ? (showPolish ? "col-sm-4" : "col-sm-6") : (showPolish ? "col-sm-6" : "col-sm-12"); #
1289 
1290  <div class="col-sm-10 hcu-no-padding">
1291  <div class="aa #= division #" data-language="english">English</div>
1292  <div class="bb #= division #" data-language="spanish">Spanish</div>
1293  <div class="cc #= division #" data-language="polish">Polish</div>
1294  </div>
1295  <div class="col-sm-2">&nbsp;</div>
1296  </div>
1297  </script>
1298  <?php } ?>
1299  <style>
1300  .radio-spacer input {
1301  margin-top: 2px;
1302  }
1303  .check input {
1304  margin-top: -4px;
1305  margin-right: 3px;
1306  }
1307  .radio-spacer {
1308  margin-left: 0;
1309  }
1310 
1311  .surveyMntcMax {
1312  max-width: 1100px;
1313  }
1314  </style>
1315  <div class="surveyMntcMax"><div id="surveyMntcContainer" class="container-fluid hcu-template hideBB hideCC"><form id="surveyMntcEditForm">
1316  <div class="row">
1317  <div id="mainValidateDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
1318  </div>
1319  <div class="row"><div class="col-xs-12 h3"><?php echo $text; ?> Details</div></div>
1320  <div class="row hcuSpacer">
1321  <div class="col-xs-12 col-sm-2"><?php echo $text; ?> Name</div>
1322  <div class="col-xs-12 col-sm-10"><input type="text" class="k-input k-textbox hcu-all-100" name="name" maxlength="50"></div>
1323  </div>
1324  <?php if ($isMarketing) { ?>
1325  <div class="row hcuSpacer">
1326  <div class="col-xs-12 col-sm-2"><?php echo $text; ?> Title</div>
1327  <div class="col-xs-12 col-sm-10"><input type="text" class="k-input k-textbox hcu-all-100" name="title"></div>
1328  </div>
1329  <?php } ?>
1330  <div class="row hcuSpacer">
1331  <div class="col-xs-12 col-sm-2">Run Dates</div>
1332  <div class="col-xs-12 col-sm-10 hcu-no-padding">
1333  <div class="col-xs-5"><input id="fromEdit" name="fromEdit" required class="hcu-all-100" homecu-match="date" data-homecuCustomMatch-msg="From date is invalid"
1334  data-required-msg="From date is required"></div>
1335  <div class="col-xs-2"><center>To</center></div>
1336  <div class="col-xs-5"><input id="toEdit" name="toEdit" required class="hcu-all-100" homecu-match="date" data-homecuCustomMatch-msg="To date is invalid"
1337  homecu-dategtvalue="fromEdit" homecu-dategttype="field" data-homecuCustomDateGTValue-msg="Invalid range" data-required-msg="To date is required"></div>
1338  </div>
1339  </div>
1340 
1341  <div class="row">
1342  <div class="col-xs-12 col-sm-6 hcu-no-padding">
1343  <div class="check"><label class="col-xs-12"><input type="checkbox" name="draft"> Save As Draft?</label></div>
1344  <div class="check"><label class="col-xs-12"><input type="checkbox" name="includeEmps"> CU Employees?</label></div>
1345  <?php if (!$isMarketing) { ?>
1346  <div class="check"><label class="col-xs-12"><input type="checkbox" name="dontShowUsers"> Suppress survey results from the member?</label></div>
1347  <?php } ?>
1348  </div>
1349  <div class="col-xs-12 col-sm-6 hcu-no-padding">
1350  <div class="col-xs-12"><div class="radio radio-spacer"><label><input type="radio" name="type" data-val="popup" checked>Popup <?php echo $text; ?> upon member login</label>
1351  </div></div>
1352  <div class="col-xs-12"><div class="radio radio-spacer"><label><input type="radio" name="type" data-val="balances">Include <?php echo $text; ?> in Balances screen</label>
1353  </div></div>
1354  </div>
1355  </div>
1356 
1357  <div class="row"><div class="col-xs-12 h3"><?php echo $isMarketing ? "Message" : "Question"; ?></div></div>
1358  <div class="row">
1359  <div class="col-xs-12"><div id="surveyQuestionTabStrip" class="hcu-all-100"></div></div>
1360  <div class="col-xs-12"><a href="#" id="addSpanishBtn">Add Spanish</a> &nbsp;|&nbsp; <a href="#" id="addPolishBtn">Add Polish</a></div>
1361  </div>
1362 
1363  <?php if (!$isMarketing) { ?>
1364  <div class="row"><div class="col-xs-12 h3">Possible Answers</div></div>
1365  <div class="row">
1366  <div class="col-xs-12"><div id="answerGrid" class="hcu-all-100"></div></div>
1367  </div>
1368  <input type="hidden" name="validateAnswers">
1369  <?php } ?>
1370 
1371  <div class="hcu-edit-buttons k-state-default row">
1372  <?php if ($surveyid != 0) { ?><span class="hcu-icon-delete"><a id='deleteBtn' href="#"><i class="fa fa-trash-o fa-lg"></i></a></span><?php } ?>
1373  <a id='cancelBtn' href="#">Cancel</a>&nbsp;&nbsp;&nbsp;
1374  <a id="saveBtn" class="k-button k-primary" href="#">Save</a>
1375  </div>
1376  </form></div></div>
1377 <?php }
1378 
1379 /**
1380  * function printResultsPage($self, $mode="single", $surveyid=0)
1381  * This prints the results page for either one survey or for all, present, future, past, draft results. It is only available for survey maintenance, not marketing messages
1382  *
1383  * @param string $self -- the URL of the page.
1384  * @param string $mode -- this can be "single", "all", "present", "future", "past", or "draft".
1385  * @param integer $surveyid -- this only matters if the $mode is "single."
1386  */
1387 function printResultsPage($self, $mode="single", $surveyid=0)
1388 {
1389  $surveyid= intval($surveyid);
1390  $mode= trim($mode);
1391  ?>
1392 
1393  <style>
1394  .row {
1395  padding: 0;
1396  margin-left: 0;
1397  margin-right: 0;
1398  }
1399 
1400  .answerRow {
1401  margin-bottom: 10px;
1402  }
1403 
1404  progress, progress[value], progress:not([value]) {
1405  -webkit-appearance: none;
1406  -moz-appearance: none;
1407  appearance: none;
1408  }
1409 
1410  progress, progress::-webkit-progress-bar {
1411  background: #EEE;
1412  box-shadow: 0 2px 3px rgba(0,0,0,0.2) inset;
1413  border-radius: 3px;
1414  }
1415 
1416  html.k-ie progress {
1417  margin-left: -5px;
1418  margin-top: -5px;
1419  zoom: 1;
1420  filter: progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=0),
1421  progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=90),
1422  progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=180),
1423  progid:DXImageTransform.Microsoft.Shadow(Color=#cccccc, Strength=5, Direction=270);
1424  }
1425 
1426  .colorBar label {
1427  position: absolute;
1428  left: 10px;
1429  top: 0;
1430  z-index: 2;
1431  color: white;
1432  height: 25px;
1433  mix-blend-mode: exclusion;
1434  margin-left: 5px;
1435  font-weight: normal;
1436  }
1437 
1438  .colorBar progress {
1439  position: absolute;
1440  left: 12px;
1441  top: 0;
1442  z-index: 1;
1443  height: 25px;
1444  width: 100%;
1445  }
1446 
1447  progress::-webkit-progress-value {
1448  border-radius: 3px;
1449  }
1450 
1451  progress::-moz-progress-bar {
1452  border-radius: 3px;
1453  }
1454 
1455 
1456  <?php
1457  $colorList= array('Green','Red','Blue','Orange','Purple');
1458  foreach($colorList as $color)
1459  { ?>
1460  progress.<?php echo $color; ?>::-webkit-progress-value {
1461  background-color: <?php echo $color; ?>;
1462  }
1463 
1464  progress.<?php echo $color; ?>::-moz-progress-bar {
1465  background-color: <?php echo $color; ?>;
1466  }
1467 
1468  <?php //For IE ?>
1469  progress.<?php echo $color; ?> {
1470  color: <?php echo $color; ?>;
1471  }
1472 
1473  <?php } ?>
1474 
1475  .surveyMntcMax {
1476  max-width: 1100px;
1477  }
1478 
1479  .a {
1480  left: 16.5px;
1481  position: relative;
1482  }
1483 
1484  #resultsGrid tr:not(.k-state-selected):hover {
1485  background: none;
1486  color: inherit;
1487  }
1488 
1489  #resultsGrid tr.k-alt:not(.k-state-selected):hover {
1490  background: #f1f1f1;
1491  }
1492 
1493  #resultsGrid .well {
1494  margin-bottom: 0;
1495  }
1496 
1497  #resultsGrid, #resultsGrid td {
1498  border-width: 0 !important;
1499  }
1500  </style>
1501  <script type="text/javascript">
1502  <?php // Library javascript functions
1503  getShowWaitFunctions();
1504  ?>
1505 
1506  <?php
1507  /**
1508  * function init()
1509  * This initializes the page with colorful results (or colourful if you are in the UK.)
1510  */
1511  ?>
1512  function init()
1513  {
1514  var grid= $("#resultsGrid").kendoGrid({
1515  dataSource: {
1516  transport: {
1517  read: {
1518  url: "<?php echo $self; ?>&operation=readResults",
1519  dataType: "json",
1520  type: "POST",
1521  data: {
1522  mode: "<?php echo $mode; ?>"
1523  <?php if ($mode == "single" || $mode == "") { ?>, surveyid: <?php echo $surveyid; ?> <?php } ?>
1524  }
1525  }
1526  },
1527  schema: {
1528  model: {
1529  id: "surveyid",
1530  fields: {
1531  surveyid: {type: "number"},
1532  range: {type: "string"},
1533  surveyname: {type: "string"},
1534  details: {type: "odata"},
1535  sort: {type: "number"}
1536  }
1537  },
1538  parse: function(data) {
1539  hideWaitWindow();
1540  if (data.error.length > 0)
1541  {
1542  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1543  return [];
1544  }
1545  else return data.data;
1546  }
1547  },
1548  sort: {field: "sort", dir: "asc"}
1549  },
1550  columns: [{}],
1551  rowTemplate: $("#rowTemplate").html(),
1552  noRecords: {
1553  template: "<tr><td>No Records Found</td></tr>"
1554  },
1555  scrollable: false
1556  }).data("kendoGrid");
1557 
1558  $("#resultsGrid").find(".k-grid-header").remove();
1559 
1560  $("#showEmptyBtn").click(function() {
1561  if ($(this).text().trim() == "Show Empty")
1562  {
1563  $(".surveyMaintenanceContainer").removeClass("hideAA");
1564  $(this).text("Hide Empty");
1565  }
1566  else
1567  {
1568  $(".surveyMaintenanceContainer").addClass("hideAA");
1569  $(this).text("Show Empty");
1570  }
1571  return false;
1572  });
1573 
1574  $("#resultsGrid").on("click", ".detailLink", function() {
1575  <?php if ($mode == "single" || $mode == "") { ?>
1576  var url= "<?php echo $self; ?>&page=resultDetails&surveyid=<?php echo $surveyid; ?>";
1577  <?php } else { ?>
1578  var url= "<?php echo $self; ?>&page=resultDetails&surveyid=" + $(this).closest("tr").data("surveyid");
1579  <?php } ?>
1580  url+= "&answerid=" + $(this).closest(".answerRow").data("answerid") + "&language=" + $(this).closest("[data-language]").data("language");
1581  window.location.href= url;
1582  return false;
1583  });
1584  }
1585 
1586  $(document).ready(function() {
1587  init();
1588  });
1589  </script>
1590  <script type="text/x-kendo-template" id="rowTemplate">
1591  <tr data-uid="#= uid #" data-surveyid="#: surveyid #"><td><div class="well well-sm row">
1592  <div class="row"><div class="col-xs-12 h4">#: surveyname #</div></div>
1593  <div class="row"><div class="col-xs-12 vsgSecondary">#: range #</div></div>
1594  # for (var i=0, iLength= details.length; i != iLength; i++) { var iRow= details[i]; #
1595  <div class="row"><div class="col-xs-12" data-language="#: iRow.language #">
1596  # if (iLength > 1) { # <div class="col-xs-12 h5 vsgSecondary">#: iRow.description #</div> # } #
1597  <div class="col-xs-12 h5">#: iRow.question #</div>
1598  # for(var j=0, jLength= iRow.answers.length; j!= jLength; j++) { var jRow= iRow.answers[j]; #
1599  <div class="# if (jRow.percentage == 0) { # aa # } # answerRow col-xs-12 hcu-no-padding" data-answerid="#: jRow.answerid #">
1600  <div class="col-xs-12 col-sm-6"><a href=\\# class="detailLink">#: jRow.text #</a></div>
1601  <div class="col-xs-12 col-sm-4 colorBar">
1602  <label>#: kendo.toString(jRow.percentage, "p2") #</label>
1603  <progress value="#: jRow.percentage #" class="#: jRow.color #"></progress>
1604  &nbsp;
1605  </div>
1606  <div class="col-xs-12 col-sm-2 col-md-2 amount">
1607  <span class="hidden-xs">&nbsp;&nbsp;&nbsp;</span>
1608  <span><a href=\\# class="detailLink">#: jRow.count #</a> votes</span>
1609  </div>
1610  </div>
1611  # } #
1612  <hr class="hidden-xs col-sm-12">
1613  <div class="col-xs-12 hcu-no-padding">
1614  <div class="hidden-xs col-sm-6">&nbsp;</div>
1615  <div class="col-xs-6 col-sm-4"><b>Total Votes</b></div>
1616  <div class="col-xs-6 col-sm-2 col-md-2 total amount">
1617  <span class="a">#: iRow.total # votes</span>
1618  </div>
1619  </div>
1620  <div class="col-xs-12 hidden-sm hidden-md hidden-lg">&nbsp;</div>
1621  </div>
1622  # } #
1623  </div></td></tr>
1624  </script>
1625  <div class="surveyMntcMax"><div class="container-fluid surveyMaintenanceContainer">
1626  <div class="row">
1627  <div id="mainValidateDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
1628  </div>
1629  <div class="row">
1630  <a href="<?php echo $self; ?>" id="surveyMenu">Survey Menu</a>&nbsp;&nbsp;&nbsp;<b> See Results: </b>
1631  <a href="<?php echo $self; ?>&page=results&mode=all" id="allSurveys">All Surveys</a>&nbsp;|&nbsp;
1632  <a href="<?php echo $self; ?>&page=results&mode=past" id="pastSurveys">Past Surveys</a>&nbsp;|&nbsp;
1633  <a href="<?php echo $self; ?>&page=results&mode=present" id="presentSurveys">Present Surveys</a>&nbsp;
1634  </div>
1635  <div class="row">
1636  <a href="#" id="showEmptyBtn">Hide Empty</a>
1637  </div>
1638  <div class="row">
1639  <div id="resultsGrid"></div>
1640  </div>
1641  </div></div>
1642 <?php }
1643 
1644 /**
1645  * function printResultDetailPage($self, $surveyid, $language, $answerid)
1646  * This prints the results detail page.
1647  *
1648  * @param string $self -- the url of the page
1649  * @param integer $surveyid -- the surveyid of the detail
1650  * @param string $language -- the language of the detail
1651  * @param integer $answerid -- the answerid of the detail
1652  */
1653 function printResultDetailPage($self, $surveyid, $language, $answerid)
1654 {
1655  $surveyid= isset($surveyid) ? intval($surveyid) : 0;
1656  $answerid= isset($answerid) ? intval($answerid) : 0;
1657  $language= isset($language) ? trim($language) : "";
1658  ?>
1659  <script type="text/javascript">
1660  <?php // Library javascript functions
1661  getShowWaitFunctions();
1662 
1663  /**
1664  * function init()
1665  * This initializes the page for the details
1666  */
1667  ?>
1668  function init()
1669  {
1670  $.homecuValidator.setup({formValidate: 'surveyMntcForm', formStatusField: 'mainValidateDiv'});
1671 
1672  showWaitWindow();
1673 
1674  var template= kendo.template($("#topTemplate").html());
1675  var grid= $("#usersGrid").kendoGrid({
1676  dataSource: {
1677  transport: {
1678  read: {
1679  url: "<?php echo $self; ?>&operation=readResultDetails",
1680  dataType: "json",
1681  type: "POST",
1682  data: {surveyid: <?php echo $surveyid; ?>, language: "<?php echo $language; ?>", answerid: <?php echo $answerid; ?>}
1683  }
1684  },
1685  schema: {
1686  model: {
1687  id: "user_id",
1688  fields: {
1689  user_id: {type: "number"},
1690  user_name: {type: "string"},
1691  optin: {type: "boolean"},
1692  email: {type: "string"}
1693  }
1694  },
1695  parse: function(data) {
1696  hideWaitWindow();
1697  if (data.error.length > 0)
1698  {
1699  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1700  return [];
1701  }
1702  else
1703  {
1704  $("#usersGrid").parent().parent().before(template(data.topData[0]));
1705  return data.bottomData;
1706  }
1707  }
1708  },
1709  sort: {field: "user_id", dir: "asc"}
1710  },
1711  columns: [
1712  {field: "user_name", title: "User"},
1713  {field: "email", title: "Email"},
1714  {field: "optin", title: "Optin", template: "# if (optin) { # Y # } else { # N # } #", width: 100}
1715  ],
1716  noRecords: {
1717  template: "<tr><td colspan='3'>No Records Found!</td></tr>"
1718  }
1719  }).data("kendoGrid");
1720  }
1721 
1722  $(document).ready(function() {
1723  init();
1724  });
1725  </script>
1726  <style>
1727  .iPickYou {
1728  max-width: 1100px;
1729  }
1730  </style>
1731  <script type="text/x-kendo-template" id="topTemplate">
1732  <div class="col-xs-12 hcuSpacer iPickYou"><div class="row well well-sm"><div class="row">
1733  <div class="col-xs-6 col-md-4 hcuSpacer hcu-no-padding">
1734  <div class="col-xs-12 col-sm-3">Survey</div>
1735  <div class="col-xs-12 col-sm-9"><b>#: question #</b></div>
1736  </div>
1737  <div class="col-xs-6 col-md-4 hcuSpacer hcu-no-padding">
1738  <div class="col-xs-12 col-sm-3">Response</div>
1739  <div class="col-xs-12 col-sm-9"><b>#: answer #</b></div>
1740  </div>
1741  <div class="col-xs-6 col-md-4 hcuSpacer hcu-no-padding">
1742  <div class="col-xs-12 col-sm-4">Run Dates</div>
1743  <div class="col-xs-12 col-sm-8"><b>#: range #</b></div>
1744  </div>
1745  <div class="col-xs-6 col-md-4 hcuSpacer hcu-no-padding">
1746  <div class="col-xs-12 col-sm-3">Votes</div>
1747  <div class="col-xs-12 col-sm-9"><b>#: votes # <span class="vsgSecondary">(#: kendo.toString(percentage, "p2") #)</b></div>
1748  </div>
1749  </div></div></div>
1750  </script>
1751  <div class="container-fluid surveyMntcReportDetailDiv"><form id="surveyMntcForm"></form>
1752  <div class="row">
1753  <div id="mainValidateDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
1754  </div>
1755  <div class="row"><div class="col-xs-12">
1756  <a href="<?php echo $self; ?>" id="surveyMenu">Survey Menu</a>&nbsp;&nbsp;&nbsp;<b> See Results: </b>
1757  <a href="<?php echo $self; ?>&page=results&mode=all" id="allSurveys">All Surveys</a>&nbsp;|&nbsp;
1758  <a href="<?php echo $self; ?>&page=results&mode=past" id="pastSurveys">Past Surveys</a>&nbsp;|&nbsp;
1759  <a href="<?php echo $self; ?>&page=results&mode=present" id="presentSurveys">Present Surveys</a>&nbsp;
1760  </div></div>
1761  <div class="row">
1762  <div class="col-xs-12"><div class="iPickYou" id="usersGrid"></div></div>
1763  </div>
1764  </div>
1765 <?php }
1766 
1767 /**
1768  * function printIntroPage($self)
1769  * This prints the intro page. It is only available for survey maintenance, not marketing messages
1770  *
1771  * @param string $self -- the URL of the page
1772  */
1773 function printIntroPage($self)
1774 { ?>
1775  <script type="text/javascript">
1776  <?php // Library javascript functions
1777  getShowWaitFunctions();
1778 
1779  /**
1780  * function init()
1781  * This initializes the intro page which includes creating the tab strip and adding events
1782  */ ?>
1783  function init()
1784  {
1785  $.homecuValidator.setup({formValidate:'surveyMntcForm', formStatusField: 'surveyMntcDiv'});
1786 
1787  var template= kendo.template('<div data-index="#:index#" class="introTemplateBody"><textarea class="question" data-language="#: language #" style="width:100%" maxlength="2000">'
1788  + '#:surveyintro#</textarea></div>');
1789 
1790  var surveyIntroStrip= $("#surveyIntroStrip").kendoTabStrip({
1791  dataTextField: "description",
1792  dataContentField: "blank",
1793  dataSource: {
1794  data: [],
1795  schema: {
1796  model: {
1797  id: "language",
1798  fields: {
1799  language: {type: "string"},
1800  description: {type: "string"},
1801  surveyintro: {type: "string"},
1802  blank: {type: "string"},
1803  changed: {type: "boolean"},
1804  index: {type: "number"},
1805  exists: {type: "boolean"}
1806  }
1807  }
1808  }
1809  },
1810  select: function(e)
1811  {
1812  var index= $(e.item).index();
1813  var dataItem= this.dataSource.data()[index];
1814  $(e.contentElement).html(template(dataItem));
1815  }
1816  }).data("kendoTabStrip");
1817 
1818  $("#surveyIntroStrip").on("blur", "textarea", function() {
1819  var data= surveyIntroStrip.dataSource.data();
1820  var row= data[$(this).closest(".introTemplateBody").data("index")];
1821  row.surveyintro= $(this).val();
1822  row.changed= true;
1823  });
1824 
1825  $("#saveBtn").click(function() {
1826  var data= surveyIntroStrip.dataSource.data();
1827  var condensed= [];
1828  for(var i=0; i!= data.length; i++)
1829  {
1830  var row= data[i];
1831  if (row.changed)
1832  {
1833  condensed.push({language: row.language, surveyintro: row.surveyintro, exists: row.exists ? "Y" : "N"});
1834  }
1835  }
1836  if (condensed.length > 0) <?php // No need to save if no records ?>
1837  {
1838  var saveWindow= $("#saveWindow").data("kendoDialog");
1839  if (saveWindow == null)
1840  {
1841  saveWindow= $("<div id='saveWindow'></div>").appendTo("body").kendoDialog({
1842  content: "<p>Are you sure you want to save this survey introduction? </p>",
1843  visible: false,
1844  modal: true,
1845  title: "Confirm Save",
1846  width: 400,
1847  resizable: false,
1848  open: function() {
1849  if (window.activeWindows != null)
1850  window.activeWindows.push(this);
1851  },
1852  close: function() {
1853  if (window.activeWindows != null)
1854  window.activeWindows.pop();
1855  },
1856  actions: [
1857  {text: "Cancel"},
1858  {text: "Save", primary: true, action: function() {
1859  saveWindow.close();
1860  var parameters= {};
1861  parameters.languageArray= kendo.stringify(condensed);
1862 
1863  showWaitWindow();
1864  $.post("<?php echo $self; ?>&operation=saveIntro", parameters, function(data) {
1865  hideWaitWindow();
1866  if (data.error.length > 0)
1867  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1868  else
1869  window.location.href= "<?php echo $self; ?>&mode=saved";
1870  });
1871  }}
1872  ]
1873  }).data("kendoDialog");
1874  }
1875  saveWindow.open();
1876  }
1877 
1878  return false;
1879  });
1880 
1881  $("#cancelBtn").click(function() {
1882  window.location.href= "<?php echo $self; ?>";
1883  return false;
1884  });
1885 
1886  showWaitWindow();
1887  $.post("<?php echo $self; ?>&operation=readIntro", {}, function(data) {
1888  hideWaitWindow();
1889  if (data.error.length > 0)
1890  $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
1891  else
1892  {
1893  surveyIntroStrip.dataSource.data(data.languageArray);
1894  surveyIntroStrip.select(0);
1895  }
1896  });
1897  }
1898 
1899  $(document).ready(function() {
1900  init();
1901  });
1902  </script>
1903  <div class="container-fluid hcu-template"><form id="surveyMntcForm">
1904 
1905  <div class="row">
1906  <div id="surveyMntcDiv" class="k-block k-error-colored formValidateDiv" style="display:none;"></div>
1907  </div>
1908  <div class="row"><div class="col-xs-12 h3">Introductory Text View Help</div></div>
1909  <div class="row vsgSecondary hcuSpacer"><div class="col-xs-12">shows at the top of the survey popup</div></div>
1910  <div class="row">
1911  <div class="col-xs-12"><div id="surveyIntroStrip" class="hcu-all-100"></div></div>
1912  </div>
1913  <div class="hcu-edit-buttons k-state-default row">
1914  <a id='cancelBtn' href="#">Cancel</a>&nbsp;&nbsp;&nbsp;
1915  <a id="saveBtn" class="k-button k-primary" href="#">Save Intro</a>
1916  </div>
1917  </form></div>
1918 <?php }