Odyssey
hcuAccountSelector.i
1 <?php
2 
3  /*
4  * hcuAccountSelector.i
5  *
6  * Purpose: This inline include script is used as a speedbump for selecting an account before going
7  * into certain features. It will check if an account number has been selected. If one has not been
8  * selected it will get a list of account numbers for that user for that feature. If only one account
9  * number it will continue and leave the script as if it has been selected. If there are multiple
10  * accounts it will show a speedbump page and exit the script.
11  *
12  * Entry requirements: A variable needs to be supplied, $SPEEDBUMP_FEATURE.
13  *
14  * Exit State: If this script exits without showing the speedbump it will have injected an element into the
15  * $HB_ENV structure, "selected_account";
16  */
17 
18  // see if the account number has been passed in (it will be encoded)
19  $inputVars = array();
20  $varOk = array(
21  "account" => array('filter' => FILTER_SANITIZE_STRING)
22  );
23 
24  HCU_ImportVars( $inputVars, "", $varOk );
25 
26  // get the account list here becasue needed either way
27  $accountList = Get_FeatureAccounts( $HB_ENV, $SPEEDBUMP_FEATURE, "D" );
28 
29  $accountToUse = "";
30  // these checks are before any screen output in case of re-direct
31  if ( !isset( $inputVars["account"] ) || is_null( $inputVars["account"] ) ) {
32  // determine if one or more accounts are available to this user
33 
34  if ( count( $accountList ) == 1 ) {
35  // most likely case first
36  $accountToUse = $accountList[0];
37  } else if ( count( $accountList ) > 1 ) {
38  // show speedbump
39  // include hcuPrecontent just in case
40  require_once(dirname(__FILE__) . '/../includes/hcuPreContent.i');
41 ?>
42 <script type="text/javascript">
43 
44  $(document).ready(function() {
45 
46  $("#lnkCancel").click( function() {
47  // go to the accounts page
48  location.href = "<?php echo $HB_ENV['loginpath'] . "/" . $HB_ENV['defaultScript'] . "?" . $HB_ENV['cuquery']; ?>";
49  });
50 
51  $( ".account-selector li" ).hover(
52  function() {
53  $( this ).addClass( "k-primary" );
54  }, function() {
55  $( this ).removeClass( "k-primary" );
56  }
57  );
58 
59  $(".local-list-element").kendoTouch({
60  tap: function (e) {
61  var value = $(e.event.target).data("value");
62  AddAccount( value );
63  }
64  });
65 
66  });
67  function AddAccount( account ) {
68  $("#account").val( account );
69 
70  // submit the form
71  $("#formAccount").submit();
72  };
73 </script>
74 <style>
75  .local-list-spacer {
76  margin-top: 20px;
77  }
78  .local-selector-width {
79  max-width: 525px;
80  }
81  .list-group li {
82  cursor:pointer;
83  font-weight: 400;
84  padding: 10px 15px;
85  }
86 </style>
87  <!-- HTML CONTENT -->
88  <div class="container-fluid">
89  <div class="row">
90  <div class=" col-xs-12 col-sm-10 col-md-8">
91  <div class="well well-sm">
92 
93  <!-- HEADER -->
94  <div>
95  <h3><?php echo $MC->msg('Please select an account', HCU_DISPLAY_AS_HTML); ?></h3>
96  </div>
97 
98  <!-- FORM CONTENT -->
99  <form id='formAccount' name='formAccount' method="GET" action="<?php echo $HB_ENV['loginpath'] . "/" . $HB_ENV['currentscript'] . "?" ?>">
100 <?php
101  // make sure all parameters are back on the url command line
102  $getKeys = array_keys( $_GET );
103  for ( $i = 0; $i < count( $getKeys ); $i++ ) {
104  print "<input type='hidden' name='{$getKeys[$i]}' value='{$_GET[$getKeys[$i]]}'>";
105  }
106 ?>
107  <input type="hidden" name="account" id="account" value="">
108  </form>
109  <ul class="list-group local-list-spacer account-selector">
110 <?php
111  // show the account choices as radio buttons
112  for ( $i = 0; $i < count( $accountList ); $i++ ) {
113  $encryptedAccount = hcu_encrypturl( $accountList[$i], $HB_ENV['historyHash'] );
114  print "<li data-value='{$encryptedAccount}' class='list-group-item local-list-element'>{$accountList[$i]}</li>";
115  }
116 ?>
117  </ul>
118  </div>
119  </div>
120  </div>
121  <div class="row">
122  <div class="col-xs-12 col-sm-3 col-md-2">
123  <span href="##" class="k-button hcu-all-100 hcu-xs-margin-top hcu-xs-btn-pad" id="lnkCancel"><?php echo $MC->msg("Cancel", HCU_DISPLAY_AS_HTML); ?></a>
124  </div>
125  </div>
126  </div>
127 <?
128  // ** INCLUDE POST CONTENT SCRIPT
129  require_once(dirname(__FILE__) . '/../includes/hcuPostContent.i');
130 
131  // need to exit because we painted the whole page
132  exit;
133  } else {
134  // no access allowed - treat like not having permissions
135  header ("Location: hcuPermNotice.prg?cu=" . $HB_ENV["Cu"] );
136  exit;
137  }
138  } else {
139  // decode the account number
140  $accountToUse = hcu_decrypturl( $inputVars["account"], $HB_ENV['historyHash'] );
141 
142  // make sure it is in the list of approved accounts
143  if ( !in_array( $accountToUse, $accountList ) ) {
144  // treat it like an error
145  $accountToUse = "";
146  }
147  }
148 
149  // if got here without an account, don't go on
150  if ( $accountToUse == "" ) {
151  $serviceErrorMsg = "An error was encountered trying to determine account to use.";
152  $serviceErrorCode = '915';
153 
154  require_once(dirname(__FILE__) . '/../includes/hcuErrorPage.i');
155  // ** DO NOT CONTINUE
156  exit;
157  }
158  $HB_ENV["selected_account"] = $accountToUse;