support multi provider with auto create event
[openemr.git] / portal / index.php
bloba2a1dedbbe08937aa790aac188f803b1293e60f8
1 <?php
2 /**
4 * Copyright (C) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
5 * Copyright (C) 2011 Cassian LUP <cassi.lup@gmail.com>
7 * LICENSE: This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @package OpenEMR
21 * @author Jerry Padgett <sjpadgett@gmail.com>
22 * @author Cassian LUP <cassi.lup@gmail.com>
23 * @link http://www.open-emr.org
26 //setting the session & other config options
27 session_start();
29 //don't require standard openemr authorization in globals.php
30 $ignoreAuth = 1;
32 //For redirect if the site on session does not match
33 $landingpage = "index.php?site=".$_GET['site'];
35 //includes
36 require_once('../interface/globals.php');
38 use OpenEMR\Core\Header;
40 ini_set("error_log", E_ERROR || ~E_NOTICE);
41 //exit if portal is turned off
42 if (!(isset($GLOBALS['portal_onsite_two_enable'])) || !($GLOBALS['portal_onsite_two_enable'])) {
43 echo htmlspecialchars(xl('Patient Portal is turned off'), ENT_NOQUOTES);
44 exit;
47 // security measure -- will check on next page.
48 $_SESSION['itsme'] = 1;
52 // Deal with language selection
54 // collect default language id (skip this if this is a password update)
55 if (!(isset($_SESSION['password_update']) || isset($_GET['requestNew']))) {
56 $res2 = sqlStatement("select * from lang_languages where lang_description = ?", array($GLOBALS['language_default']));
57 for ($iter = 0; $row = sqlFetchArray($res2); $iter++) {
58 $result2[$iter] = $row;
61 if (count($result2) == 1) {
62 $defaultLangID = $result2[0]{"lang_id"};
63 $defaultLangName = $result2[0]{"lang_description"};
64 } else {
65 //default to english if any problems
66 $defaultLangID = 1;
67 $defaultLangName = "English";
70 // set session variable to default so login information appears in default language
71 $_SESSION['language_choice'] = $defaultLangID;
72 // collect languages if showing language menu
73 if ($GLOBALS['language_menu_login']) {
74 // sorting order of language titles depends on language translation options.
75 $mainLangID = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
76 if ($mainLangID == '1' && !empty($GLOBALS['skip_english_translation'])) {
77 $sql = "SELECT * FROM lang_languages ORDER BY lang_description, lang_id";
78 $res3=SqlStatement($sql);
79 } else {
80 // Use and sort by the translated language name.
81 $sql = "SELECT ll.lang_id, " .
82 "IF(LENGTH(ld.definition),ld.definition,ll.lang_description) AS trans_lang_description, " .
83 "ll.lang_description " .
84 "FROM lang_languages AS ll " .
85 "LEFT JOIN lang_constants AS lc ON lc.constant_name = ll.lang_description " .
86 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
87 "ld.lang_id = ? " .
88 "ORDER BY IF(LENGTH(ld.definition),ld.definition,ll.lang_description), ll.lang_id";
89 $res3=SqlStatement($sql, array($mainLangID));
91 for ($iter = 0; $row = sqlFetchArray($res3); $iter++) {
92 $result3[$iter] = $row;
94 if (count($result3) == 1) {
95 //default to english if only return one language
96 $hiddenLanguageField = "<input type='hidden' name='languageChoice' value='1' />\n";
98 } else {
99 $hiddenLanguageField = "<input type='hidden' name='languageChoice' value='".htmlspecialchars($defaultLangID, ENT_QUOTES)."' />\n";
103 <!DOCTYPE html>
104 <html>
105 <head>
106 <title><?php echo xlt('Patient Portal Login'); ?></title>
107 <?php Header::setupHeader(['datetime-picker']); ?>
108 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery.gritter-1-7-4/js/jquery.gritter.min.js"></script>
109 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery.gritter-1-7-4/css/jquery.gritter.css" />
110 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/emodal-1-2-65/dist/eModal.js"></script>
111 <link rel="stylesheet" type="text/css" href="assets/css/base.css?v=<?php echo $v_js_includes; ?>" />
112 <link rel="stylesheet" type="text/css" href="assets/css/register.css?v=<?php echo $v_js_includes; ?>" />
113 <script type="text/javascript">
114 function process() {
115 if (!(validate())) {
116 alert ('<?php echo addslashes(xl('Field(s) are missing!')); ?>');
117 return false;
120 function validate() {
121 var pass=true;
122 if (document.getElementById('uname').value == "") {
123 document.getElementById('uname').style.border = "1px solid red";
124 pass=false;
126 if (document.getElementById('pass').value == "") {
127 document.getElementById('pass').style.border = "1px solid red";
128 pass=false;
130 return pass;
132 function process_new_pass() {
133 if (!(validate_new_pass())) {
134 alert ('<?php echo addslashes(xl('Field(s) are missing!')); ?>');
135 return false;
137 if (document.getElementById('pass_new').value != document.getElementById('pass_new_confirm').value) {
138 alert ('<?php echo addslashes(xl('The new password fields are not the same.')); ?>');
139 return false;
141 if (document.getElementById('pass').value == document.getElementById('pass_new').value) {
142 alert ('<?php echo addslashes(xl('The new password can not be the same as the current password.')); ?>');
143 return false;
147 function validate_new_pass() {
148 var pass=true;
149 if (document.getElementById('uname').value == "") {
150 document.getElementById('uname').style.border = "1px solid red";
151 pass=false;
153 if (document.getElementById('pass').value == "") {
154 document.getElementById('pass').style.border = "1px solid red";
155 pass=false;
157 if (document.getElementById('pass_new').value == "") {
158 document.getElementById('pass_new').style.border = "1px solid red";
159 pass=false;
161 if (document.getElementById('pass_new_confirm').value == "") {
162 document.getElementById('pass_new_confirm').style.border = "1px solid red";
163 pass=false;
165 return pass;
167 </script>
168 </head>
169 <body>
170 <br><br>
171 <div class="container text-center">
172 <?php if (isset($_SESSION['password_update']) || isset($_GET['password_update'])) {
173 $_SESSION['password_update']=1;
175 <div id="wrapper" class="centerwrapper" style="text-align:center;">
176 <h2 class="title"><?php echo xlt('Please Enter a New Password'); ?></h2>
177 <form action="get_patient_info.php" method="POST" onsubmit="return process_new_pass()" >
178 <table style="width:100%">
179 <tr>
180 <td class="algnRight"><?php echo xlt('User Name'); ?></td>
181 <td><input name="uname" id="uname" type="text" autocomplete="off" value="<?php echo attr($_SESSION['portal_username']); ?>"/></td>
182 </tr>
183 <tr>
184 <td class="algnRight"><?php echo xlt('Current Password');?></td>
185 <td>
186 <input name="pass" id="pass" type="password" autocomplete="off" value="" />
187 </td>
188 </tr>
189 <tr>
190 <td class="algnRight"><?php echo xlt('New Password');?></td>
191 <td>
192 <input name="pass_new" id="pass_new" type="password" />
193 </td>
194 </tr>
195 <tr>
196 <td class="algnRight"><?php echo xlt('Confirm New Password');?></td>
197 <td>
198 <input name="pass_new_confirm" id="pass_new_confirm" type="password" />
199 </td>
200 </tr>
201 <tr>
202 <td class="algnRight"><?php echo xlt('Confirm Email Address');?></td>
203 <td>
204 <input name="passaddon" id="passaddon" placeholder="<?php echo xla('Your on file email address'); ?>" type="email" autocomplete="off" value="" />
205 </td>
206 </tr>
207 <tr>
208 <td colspan=2><br><input class="pull-right" type="submit" value="<?php echo xla('Log In');?>" /></td>
209 </tr>
210 </table>
211 </form>
212 <div class="copyright"><?php echo xlt('Powered by');?> OpenEMR</div>
213 </div>
214 <?php } elseif (isset($_GET['requestNew'])) { ?>
215 <div id="wrapper" class="centerwrapper" style="text-align:center;" >
216 <form class="form-inline" id="resetPass" action="" method="" >
217 <div class="row">
218 <div class="col-sm-10 col-md-offset-1 text-center">
219 <fieldset>
220 <legend class='bg-primary'><h3><?php echo xlt('Patient Credentials Reset') ?></h3></legend>
221 <div class="well">
222 <div class="row">
223 <div class="form-group inline">
224 <label class="control-label" for="fname"><?php echo xlt('First')?></label>
225 <div class="controls inline-inputs">
226 <input type="text" class="form-control" id="fname" required placeholder="<?php echo xla('First Name'); ?>">
227 </div>
228 </div>
229 <div class="form-group inline">
230 <label class="control-label" for="lname"><?php echo xlt('Last Name')?></label>
231 <div class="controls inline-inputs">
232 <input type="text" class="form-control" id="lname" required placeholder="<?php echo xla('Enter Last'); ?>">
233 </div>
234 </div>
235 <div class="form-group inline">
236 <label class="control-label" for="dob"><?php echo xlt('Birth Date')?></label>
237 <div class="controls inline-inputs">
238 <div class="input-group">
239 <input id="dob" type="text" required class="form-control datepicker" placeholder="<?php echo xla('YYYY-MM-DD'); ?>" />
240 </div>
241 </div>
242 </div></div>
243 <div class="row">
244 <div class="col-sm-12 form-group">
245 <label class="control-label" for="emailInput"><?php echo xlt('Enter E-Mail Address')?></label>
246 <div class="controls inline-inputs">
247 <input id="emailInput" type="email" class="form-control" style="width: 100%" required
248 placeholder="<?php echo xla('Must be current email address on file.'); ?>" maxlength="100">
249 </div>
250 </div>
251 </div>
252 </div>
253 <button id="submitRequest" class="btn btn-primary nextBtn btn-sm pull-right" type="button"><?php echo xlt('Verify') ?></button>
254 </fieldset>
255 </div>
256 </div>
257 </form>
258 </div>
259 <?php } else {
260 ?> <!-- Main logon -->
261 <div id="wrapper" class="row centerwrapper text-center">
262 <img style="width:65%" src='<?php echo $GLOBALS['images_static_relative']; ?>/login-logo.png'/>
263 <form class="form-inline text-center" action="get_patient_info.php" method="POST" onsubmit="return process()">
264 <div class="row">
265 <div class="col-sm-12 text-center">
266 <fieldset>
267 <legend class="bg-primary"><h3><?php echo xlt('Patient Portal Login'); ?></h3></legend>
268 <div class="well">
269 <div class="row">
270 <div class="col-sm-12">
271 <div class="form-group inline">
272 <label class="control-label" for="uname"><?php echo xlt('Username')?></label>
273 <div class="controls inline-inputs">
274 <input type="text" class="form-control" name="uname" id="uname" type="text" autocomplete="on" required>
275 </div>
276 </div>
277 <div class="form-group inline">
278 <label class="control-label" for="pass"><?php echo xlt('Password')?></label>
279 <div class="controls inline-inputs">
280 <input class="form-control" name="pass" id="pass" type="password" required autocomplete="on">
281 </div>
282 </div>
283 </div>
284 </div>
285 <div class="row">
286 <div class="col-sm-12 form-group">
287 <label class="control-label" for="passaddon"><?php echo xlt('E-Mail Address')?></label>
288 <div class="controls inline-inputs">
289 <input class="form-control" style="width: 100%" name="passaddon" id="passaddon" placeholder="<?php echo xla('on file email'); ?>" type="email" autocomplete="on" />
290 </div>
291 </div>
292 </div>
293 <?php if ($GLOBALS['language_menu_login']) { ?>
294 <?php if (count($result3) != 1) { ?>
295 <div class="form-group row">
296 <label for="selLanguage"><?php echo xlt('Language'); ?></label>
297 <select class="form-control" id="selLanguage" name="languageChoice">
298 <?php
299 echo "<option selected='selected' value='" . htmlspecialchars($defaultLangID, ENT_QUOTES) . "'>" .
300 htmlspecialchars(xl('Default') . " - " . xl($defaultLangName), ENT_NOQUOTES) . "</option>\n";
301 foreach ($result3 as $iter) {
302 if ($GLOBALS['language_menu_showall']) {
303 if (! $GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
304 continue; // skip the dummy language
306 echo "<option value='" . htmlspecialchars($iter['lang_id'], ENT_QUOTES) . "'>" .
307 htmlspecialchars($iter['trans_lang_description'], ENT_NOQUOTES) . "</option>\n";
308 } else {
309 if (in_array($iter['lang_description'], $GLOBALS['language_menu_show'])) {
310 if (! $GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
311 continue; // skip the dummy language
313 echo "<option value='" . htmlspecialchars($iter['lang_id'], ENT_QUOTES) . "'>" .
314 htmlspecialchars($iter['trans_lang_description'], ENT_NOQUOTES) . "</option>\n";
319 </select>
320 </div>
321 <?php } } ?>
322 </div>
323 <div class="col-sm-12 col-md-12">
324 <?php if ($GLOBALS['portal_onsite_two_register']) { ?>
325 <button class="btn btn-default pull-left" onclick="location.replace('./account/register.php')"><?php echo xlt('Register');?></button>
326 <?php } ?>
327 <?php if ($GLOBALS['portal_two_pass_reset'] && isset($_GET['w']) && (isset($_GET['u']) || isset($_GET['p']))) { ?>
328 <button class="btn btn-danger" onclick="location.replace('./index.php?requestNew=1')" style="margin-left:10px"><?php echo xlt('Reset Credentials');?></button>
329 <?php } ?>
330 <button class="btn btn-success pull-right" type="submit" ><?php echo xlt('Log In');?></button>
331 </div>
332 </fieldset>
333 </div>
334 </div>
335 <?php if (!(empty($hiddenLanguageField))) {
336 echo $hiddenLanguageField; } ?>
337 </form>
338 </div><!-- div wrapper -->
339 <?php } ?> <!-- logon wrapper -->
340 </div><!-- container -->
342 <script type="text/javascript">
343 $(document).ready(function() {
345 <?php // if something went wrong
346 if (isset($_GET['requestNew'])) {
347 $_SESSION['patient_portal_onsite_two'] = true;
348 $_SESSION['authUser'] = 'portal-user';
349 $_SESSION['pid'] = true;
351 $('.datepicker').datetimepicker({
352 <?php $datetimepicker_timepicker = false; ?>
353 <?php $datetimepicker_showseconds = false; ?>
354 <?php $datetimepicker_formatInput = false; ?>
355 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
357 $(document.body).on('hidden.bs.modal', function () {
358 callServer('cleanup');
360 $("#submitRequest").click(function () {
361 callServer('is_new', '');
363 <?php } ?>
364 <?php if (isset($_GET['w'])) { ?>
365 var unique_id = $.gritter.add({
366 title: '<span class="red"><?php echo xlt('Oops!');?></span>',
367 text: '<?php echo xlt('Something went wrong. Please try again.'); ?>',
368 sticky: false,
369 time: '5000',
370 class_name: 'my-nonsticky-class'
372 <?php } ?>
373 <?php // if successfully logged out
374 if (isset($_GET['logout'])) { ?>
375 var unique_id = $.gritter.add({
376 title: '<span class="green"><?php echo xlt('Success');?></span>',
377 text: '<?php echo xlt('You have been successfully logged out.');?>',
378 sticky: false,
379 time: '5000',
380 class_name: 'my-nonsticky-class'
382 <?php } ?>
384 return false;
386 /* Test Data
387 $("#emailInput").val("me@me.com");
388 $("#fname").val("Jerry");
389 $("#lname").val("Padgett");
390 $("#dob").val("1919-03-03"); */
392 function callServer(action, value, value2, last, first) {
393 var data = {
394 'action' : action,
395 'value' : value,
396 'dob' : $("#dob").val(),
397 'last' : $("#lname").val(),
398 'first' : $("#fname").val(),
399 'email' : $("#emailInput").val()
401 if (action == 'do_signup') {
402 data = {
403 'action': action,
404 'pid': value
407 else if (action == 'notify_admin') {
408 data = {
409 'action': action,
410 'pid': value,
411 'provider': value2
414 else if (action == 'cleanup') {
415 data = {
416 'action': action
419 $.ajax({
420 type : 'GET',
421 url : './account/account.php',
422 data : data
423 }).done(function (rtn) {
424 if (action == "cleanup") {
425 window.location.href = "./index.php" // Goto landing page.
427 else if (action == "is_new") {
428 if (parseInt(rtn) > 0) {
429 var yes = confirm('<?php echo xls("Account is validated. Send new credentials?") ?>');
430 if(!yes)
431 callServer('cleanup');
432 else
433 callServer('do_signup', parseInt(rtn));
435 else {
436 // After error alert app exit to landing page.
437 var message = "<?php echo xls('Unable to find your records. Be sure to use your correct Dob, First and Last name and Email of record. If you have opted out of email with none on file then leave blank.'); ?>";
438 eModal.alert(message);
441 else if (action == 'do_signup') {
442 if (rtn == "") {
443 var message = "<?php echo xlt('Unable to either create credentials or send email.'); ?>";
444 alert(message);
445 return false;
447 //alert(rtn); // sync alert.. rtn holds username and password for testing.
448 var message = "<?php echo xls(" Your new credentials have been sent. Check your email inbox and also possibly your spam folder. Once you log into your patient portal feel free to make an appointment or send us a secure message. We look forward to seeing you soon."); ?>"
449 eModal.alert(message); // This is an async call. The modal close event exits us to portal landing page after cleanup.
451 }).fail(function (err) {
452 var message = "<?php echo xls('Something went wrong.') ?>";
453 alert(message);
456 </script>
457 </body>
458 </html>