updated emodal (#2085)
[openemr.git] / portal / index.php
blobc038e917b2db37e7c31619005f1b6fda52917429
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
108 $css = $GLOBALS['css_header'];
109 $GLOBALS['css_header'] = "";
110 Header::setupHeader(['datetime-picker']);
111 //$GLOBALS['css_header'] = $css;
113 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/gritter/js/jquery.gritter.min.js"></script>
114 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['assets_static_relative']; ?>/gritter/css/jquery.gritter.css" />
115 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/emodal/dist/eModal.min.js"></script>
116 <link rel="stylesheet" type="text/css" href="assets/css/base.css?v=<?php echo $v_js_includes; ?>" />
117 <link rel="stylesheet" type="text/css" href="assets/css/register.css?v=<?php echo $v_js_includes; ?>" />
118 <script type="text/javascript">
119 function process() {
120 if (!(validate())) {
121 alert ('<?php echo addslashes(xl('Field(s) are missing!')); ?>');
122 return false;
125 function validate() {
126 var pass=true;
127 if (document.getElementById('uname').value == "") {
128 document.getElementById('uname').style.border = "1px solid red";
129 pass=false;
131 if (document.getElementById('pass').value == "") {
132 document.getElementById('pass').style.border = "1px solid red";
133 pass=false;
135 return pass;
137 function process_new_pass() {
138 if (!(validate_new_pass())) {
139 alert ('<?php echo addslashes(xl('Field(s) are missing!')); ?>');
140 return false;
142 if (document.getElementById('pass_new').value != document.getElementById('pass_new_confirm').value) {
143 alert ('<?php echo addslashes(xl('The new password fields are not the same.')); ?>');
144 return false;
146 if (document.getElementById('pass').value == document.getElementById('pass_new').value) {
147 alert ('<?php echo addslashes(xl('The new password can not be the same as the current password.')); ?>');
148 return false;
152 function validate_new_pass() {
153 var pass=true;
154 if (document.getElementById('uname').value == "") {
155 document.getElementById('uname').style.border = "1px solid red";
156 pass=false;
158 if (document.getElementById('pass').value == "") {
159 document.getElementById('pass').style.border = "1px solid red";
160 pass=false;
162 if (document.getElementById('pass_new').value == "") {
163 document.getElementById('pass_new').style.border = "1px solid red";
164 pass=false;
166 if (document.getElementById('pass_new_confirm').value == "") {
167 document.getElementById('pass_new_confirm').style.border = "1px solid red";
168 pass=false;
170 return pass;
172 </script>
173 </head>
174 <body class="skin-blue">
175 <br><br>
176 <div class="container text-center">
177 <?php if (isset($_SESSION['password_update']) || isset($_GET['password_update'])) {
178 $_SESSION['password_update']=1;
180 <div id="wrapper" class="centerwrapper" style="text-align:center;">
181 <h2 class="title"><?php echo xlt('Please Enter a New Password'); ?></h2>
182 <form action="get_patient_info.php" method="POST" onsubmit="return process_new_pass()" >
183 <table style="width:100%">
184 <tr>
185 <td class="algnRight"><?php echo xlt('User Name'); ?></td>
186 <td><input name="uname" id="uname" type="text" autocomplete="off" value="<?php echo attr($_SESSION['portal_username']); ?>"/></td>
187 </tr>
188 <tr>
189 <td class="algnRight"><?php echo xlt('Current Password');?></td>
190 <td>
191 <input name="pass" id="pass" type="password" autocomplete="off" value="" />
192 </td>
193 </tr>
194 <tr>
195 <td class="algnRight"><?php echo xlt('New Password');?></td>
196 <td>
197 <input name="pass_new" id="pass_new" type="password" />
198 </td>
199 </tr>
200 <tr>
201 <td class="algnRight"><?php echo xlt('Confirm New Password');?></td>
202 <td>
203 <input name="pass_new_confirm" id="pass_new_confirm" type="password" />
204 </td>
205 </tr>
206 <?php if ($GLOBALS['enforce_signin_email']) { ?>
207 <tr>
208 <td class="algnRight"><?php echo xlt('Confirm Email Address');?></td>
209 <td>
210 <input name="passaddon" id="passaddon" placeholder="<?php echo xla('Your on file email address'); ?>" type="email" autocomplete="off" value="" />
211 </td>
212 </tr>
213 <?php } ?>
214 <tr>
215 <td colspan=2><br><input class="pull-right" type="submit" value="<?php echo xla('Log In');?>" /></td>
216 </tr>
217 </table>
218 </form>
219 <div class="copyright"><?php echo xlt('Powered by');?> OpenEMR</div>
220 </div>
221 <?php } elseif (isset($_GET['requestNew'])) { ?>
222 <div id="wrapper" class="centerwrapper" style="text-align:center;" >
223 <form class="form-inline" id="resetPass" action="" method="" >
224 <div class="row">
225 <div class="col-sm-10 col-md-offset-1 text-center">
226 <fieldset>
227 <legend class='bg-primary'><h3><?php echo xlt('Patient Credentials Reset') ?></h3></legend>
228 <div class="well">
229 <div class="row">
230 <div class="form-group inline">
231 <label class="control-label" for="fname"><?php echo xlt('First')?></label>
232 <div class="controls inline-inputs">
233 <input type="text" class="form-control" id="fname" required placeholder="<?php echo xla('First Name'); ?>">
234 </div>
235 </div>
236 <div class="form-group inline">
237 <label class="control-label" for="lname"><?php echo xlt('Last Name')?></label>
238 <div class="controls inline-inputs">
239 <input type="text" class="form-control" id="lname" required placeholder="<?php echo xla('Enter Last'); ?>">
240 </div>
241 </div>
242 <div class="form-group inline">
243 <label class="control-label" for="dob"><?php echo xlt('Birth Date')?></label>
244 <div class="controls inline-inputs">
245 <div class="input-group">
246 <input id="dob" type="text" required class="form-control datepicker" placeholder="<?php echo xla('YYYY-MM-DD'); ?>" />
247 </div>
248 </div>
249 </div></div>
250 <div class="row">
251 <div class="col-sm-12 form-group">
252 <label class="control-label" for="emailInput"><?php echo xlt('Enter E-Mail Address')?></label>
253 <div class="controls inline-inputs">
254 <input id="emailInput" type="email" class="form-control" style="width: 100%" required
255 placeholder="<?php echo xla('Must be current email address on file.'); ?>" maxlength="100">
256 </div>
257 </div>
258 </div>
259 </div>
260 <button id="submitRequest" class="btn btn-primary nextBtn btn-sm pull-right" type="button"><?php echo xlt('Verify') ?></button>
261 </fieldset>
262 </div>
263 </div>
264 </form>
265 </div>
266 <?php } else {
267 ?> <!-- Main logon -->
268 <div id="wrapper" class="row centerwrapper text-center">
269 <img style="width:65%" src='<?php echo $GLOBALS['images_static_relative']; ?>/login-logo.png'/>
270 <form class="form-inline text-center" action="get_patient_info.php" method="POST" onsubmit="return process()">
271 <div class="row">
272 <div class="col-sm-12 text-center">
273 <fieldset>
274 <legend class="bg-primary"><h3><?php echo xlt('Patient Portal Login'); ?></h3></legend>
275 <div class="well">
276 <div class="row">
277 <div class="col-sm-12">
278 <div class="form-group inline">
279 <label class="control-label" for="uname"><?php echo xlt('Username')?></label>
280 <div class="controls inline-inputs">
281 <input type="text" class="form-control" name="uname" id="uname" type="text" autocomplete="on" required>
282 </div>
283 </div>
284 <div class="form-group inline">
285 <label class="control-label" for="pass"><?php echo xlt('Password')?></label>
286 <div class="controls inline-inputs">
287 <input class="form-control" name="pass" id="pass" type="password" required autocomplete="on">
288 </div>
289 </div>
290 </div>
291 </div>
292 <div class="row">
293 <?php if ($GLOBALS['enforce_signin_email']) { ?>
294 <div class="col-sm-12 form-group">
295 <label class="control-label" for="passaddon"><?php echo xlt('E-Mail Address')?></label>
296 <div class="controls inline-inputs">
297 <input class="form-control" style="width: 100%" name="passaddon" id="passaddon" placeholder="<?php echo xla('on file email'); ?>" type="email" autocomplete="on" />
298 </div>
299 </div>
300 <?php } ?>
301 </div>
302 <?php if ($GLOBALS['language_menu_login']) { ?>
303 <?php if (count($result3) != 1) { ?>
304 <div class="form-group row">
305 <label for="selLanguage"><?php echo xlt('Language'); ?></label>
306 <select class="form-control" id="selLanguage" name="languageChoice">
307 <?php
308 echo "<option selected='selected' value='" . htmlspecialchars($defaultLangID, ENT_QUOTES) . "'>" .
309 htmlspecialchars(xl('Default') . " - " . xl($defaultLangName), ENT_NOQUOTES) . "</option>\n";
310 foreach ($result3 as $iter) {
311 if ($GLOBALS['language_menu_showall']) {
312 if (! $GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
313 continue; // skip the dummy language
315 echo "<option value='" . htmlspecialchars($iter['lang_id'], ENT_QUOTES) . "'>" .
316 htmlspecialchars($iter['trans_lang_description'], ENT_NOQUOTES) . "</option>\n";
317 } else {
318 if (in_array($iter['lang_description'], $GLOBALS['language_menu_show'])) {
319 if (! $GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
320 continue; // skip the dummy language
322 echo "<option value='" . htmlspecialchars($iter['lang_id'], ENT_QUOTES) . "'>" .
323 htmlspecialchars($iter['trans_lang_description'], ENT_NOQUOTES) . "</option>\n";
328 </select>
329 </div>
330 <?php } } ?>
331 </div>
332 <div class="col-sm-12 col-md-12">
333 <?php if ($GLOBALS['portal_onsite_two_register']) { ?>
334 <button class="btn btn-default pull-left" onclick="location.replace('./account/register.php')"><?php echo xlt('Register');?></button>
335 <?php } ?>
336 <?php if ($GLOBALS['portal_two_pass_reset'] && isset($_GET['w']) && (isset($_GET['u']) || isset($_GET['p']))) { ?>
337 <button class="btn btn-danger" onclick="location.replace('./index.php?requestNew=1')" style="margin-left:10px"><?php echo xlt('Reset Credentials');?></button>
338 <?php } ?>
339 <button class="btn btn-success pull-right" type="submit" ><?php echo xlt('Log In');?></button>
340 </div>
341 </fieldset>
342 </div>
343 </div>
344 <?php if (!(empty($hiddenLanguageField))) {
345 echo $hiddenLanguageField; } ?>
346 </form>
347 </div><!-- div wrapper -->
348 <?php } ?> <!-- logon wrapper -->
349 </div><!-- container -->
351 <script type="text/javascript">
352 $(document).ready(function() {
354 <?php // if something went wrong
355 if (isset($_GET['requestNew'])) {
356 $_SESSION['register'] = true;
357 $_SESSION['authUser'] = 'portal-user';
358 $_SESSION['pid'] = true;
360 $('.datepicker').datetimepicker({
361 <?php $datetimepicker_timepicker = false; ?>
362 <?php $datetimepicker_showseconds = false; ?>
363 <?php $datetimepicker_formatInput = false; ?>
364 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
366 $(document.body).on('hidden.bs.modal', function () {
367 callServer('cleanup');
369 $("#submitRequest").click(function () {
370 callServer('is_new', '');
372 <?php } ?>
373 <?php if (isset($_GET['w'])) { ?>
374 var unique_id = $.gritter.add({
375 title: '<span class="red"><?php echo xlt('Oops!');?></span>',
376 text: '<?php echo xlt('Something went wrong. Please try again.'); ?>',
377 sticky: false,
378 time: '5000',
379 class_name: 'my-nonsticky-class'
381 <?php } ?>
382 <?php // if successfully logged out
383 if (isset($_GET['logout'])) { ?>
384 var unique_id = $.gritter.add({
385 title: '<span class="green"><?php echo xlt('Success');?></span>',
386 text: '<?php echo xlt('You have been successfully logged out.');?>',
387 sticky: false,
388 time: '5000',
389 class_name: 'my-nonsticky-class'
391 <?php } ?>
393 return false;
395 /* Test Data
396 $("#emailInput").val("me@me.com");
397 $("#fname").val("Jerry");
398 $("#lname").val("Padgett");
399 $("#dob").val("1919-03-03"); */
401 function callServer(action, value, value2, last, first) {
402 var data = {
403 'action' : action,
404 'value' : value,
405 'dob' : $("#dob").val(),
406 'last' : $("#lname").val(),
407 'first' : $("#fname").val(),
408 'email' : $("#emailInput").val()
410 if (action == 'do_signup') {
411 data = {
412 'action': action,
413 'pid': value
416 else if (action == 'notify_admin') {
417 data = {
418 'action': action,
419 'pid': value,
420 'provider': value2
423 else if (action == 'cleanup') {
424 data = {
425 'action': action
428 $.ajax({
429 type : 'GET',
430 url : './account/account.php',
431 data : data
432 }).done(function (rtn) {
433 if (action == "cleanup") {
434 window.location.href = "./index.php" // Goto landing page.
436 else if (action == "is_new") {
437 if (parseInt(rtn) > 0) {
438 var yes = confirm('<?php echo xls("Account is validated. Send new credentials?") ?>');
439 if(!yes)
440 callServer('cleanup');
441 else
442 callServer('do_signup', parseInt(rtn));
444 else {
445 // After error alert app exit to landing page.
446 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.'); ?>";
447 eModal.alert(message);
450 else if (action == 'do_signup') {
451 if (rtn == "") {
452 var message = "<?php echo xlt('Unable to either create credentials or send email.'); ?>";
453 alert(message);
454 return false;
456 //alert(rtn); // sync alert.. rtn holds username and password for testing.
457 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."); ?>"
458 eModal.alert(message); // This is an async call. The modal close event exits us to portal landing page after cleanup.
460 }).fail(function (err) {
461 var message = "<?php echo xls('Something went wrong.') ?>";
462 alert(message);
465 </script>
466 </body>
467 </html>