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