Some new features
[openemr.git] / portal / index.php
bloba3bd098502e6e8f75f0140c1ad53274546faf805
1 <?php
2 /**
3 * import_template.php
5 * @package OpenEMR
6 * @link https://www.open-emr.org
7 * @author Cassian LUP <cassi.lup@gmail.com>
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @author Brady Miller <brady.g.miller@gmail.com>
10 * @copyright Copyright (c) 2011 Cassian LUP <cassi.lup@gmail.com>
11 * @copyright Copyright (c) 2016-2017 Jerry Padgett <sjpadgett@gmail.com>
12 * @copyright Copyright (c) 2019 Brady Miller <brady.g.miller@gmail.com>
13 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 //setting the session & other config options
18 // Will start the (patient) portal OpenEMR session/cookie.
19 require_once(dirname(__FILE__) . "/../src/Common/Session/SessionUtil.php");
20 OpenEMR\Common\Session\SessionUtil::portalSessionStart();
22 //don't require standard openemr authorization in globals.php
23 $ignoreAuth = 1;
25 //For redirect if the site on session does not match
26 $landingpage = "index.php?site=" . urlencode($_GET['site']);
28 //includes
29 require_once('../interface/globals.php');
31 use OpenEMR\Core\Header;
33 //exit if portal is turned off
34 if (!(isset($GLOBALS['portal_onsite_two_enable'])) || !($GLOBALS['portal_onsite_two_enable'])) {
35 echo xlt('Patient Portal is turned off');
36 exit;
39 // security measure -- will check on next page.
40 $_SESSION['itsme'] = 1;
44 // Deal with language selection
46 // collect default language id (skip this if this is a password update)
47 if (!(isset($_SESSION['password_update']) || isset($_GET['requestNew']))) {
48 $res2 = sqlStatement("select * from lang_languages where lang_description = ?", array($GLOBALS['language_default']));
49 for ($iter = 0; $row = sqlFetchArray($res2); $iter++) {
50 $result2[$iter] = $row;
53 if (count($result2) == 1) {
54 $defaultLangID = $result2[0]{"lang_id"};
55 $defaultLangName = $result2[0]{"lang_description"};
56 } else {
57 //default to english if any problems
58 $defaultLangID = 1;
59 $defaultLangName = "English";
62 // set session variable to default so login information appears in default language
63 $_SESSION['language_choice'] = $defaultLangID;
64 // collect languages if showing language menu
65 if ($GLOBALS['language_menu_login']) {
66 // sorting order of language titles depends on language translation options.
67 $mainLangID = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
68 if ($mainLangID == '1' && !empty($GLOBALS['skip_english_translation'])) {
69 $sql = "SELECT * FROM lang_languages ORDER BY lang_description, lang_id";
70 $res3=SqlStatement($sql);
71 } else {
72 // Use and sort by the translated language name.
73 $sql = "SELECT ll.lang_id, " .
74 "IF(LENGTH(ld.definition),ld.definition,ll.lang_description) AS trans_lang_description, " .
75 "ll.lang_description " .
76 "FROM lang_languages AS ll " .
77 "LEFT JOIN lang_constants AS lc ON lc.constant_name = ll.lang_description " .
78 "LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
79 "ld.lang_id = ? " .
80 "ORDER BY IF(LENGTH(ld.definition),ld.definition,ll.lang_description), ll.lang_id";
81 $res3=SqlStatement($sql, array($mainLangID));
83 for ($iter = 0; $row = sqlFetchArray($res3); $iter++) {
84 $result3[$iter] = $row;
86 if (count($result3) == 1) {
87 //default to english if only return one language
88 $hiddenLanguageField = "<input type='hidden' name='languageChoice' value='1' />\n";
90 } else {
91 $hiddenLanguageField = "<input type='hidden' name='languageChoice' value='" . attr($defaultLangID) . "' />\n";
95 <!DOCTYPE html>
96 <html>
97 <head>
98 <title><?php echo xlt('Patient Portal Login'); ?></title>
99 <?php
100 Header::setupHeader(['no_main-theme', 'datetime-picker']);
102 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/gritter/js/jquery.gritter.min.js"></script>
103 <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS['assets_static_relative']; ?>/gritter/css/jquery.gritter.css" />
104 <script type="text/javascript" src="<?php echo $GLOBALS['assets_static_relative']; ?>/emodal/dist/eModal.min.js"></script>
105 <link rel="stylesheet" type="text/css" href="assets/css/base.css?v=<?php echo $v_js_includes; ?>" />
106 <link rel="stylesheet" type="text/css" href="assets/css/register.css?v=<?php echo $v_js_includes; ?>" />
107 <script type="text/javascript">
108 function process() {
109 if (!(validate())) {
110 alert (<?php echo xlj('Field(s) are missing!'); ?>);
111 return false;
114 function validate() {
115 var pass=true;
116 if (document.getElementById('uname').value == "") {
117 document.getElementById('uname').style.border = "1px solid red";
118 pass=false;
120 if (document.getElementById('pass').value == "") {
121 document.getElementById('pass').style.border = "1px solid red";
122 pass=false;
124 return pass;
126 function process_new_pass() {
127 if (!(validate_new_pass())) {
128 alert (<?php echo xlj('Field(s) are missing!'); ?>);
129 return false;
131 if (document.getElementById('pass_new').value != document.getElementById('pass_new_confirm').value) {
132 alert (<?php echo xlj('The new password fields are not the same.'); ?>);
133 return false;
135 if (document.getElementById('pass').value == document.getElementById('pass_new').value) {
136 alert (<?php echo xlj('The new password can not be the same as the current password.'); ?>);
137 return false;
141 function validate_new_pass() {
142 var pass=true;
143 if (document.getElementById('uname').value == "") {
144 document.getElementById('uname').style.border = "1px solid red";
145 pass=false;
147 if (document.getElementById('pass').value == "") {
148 document.getElementById('pass').style.border = "1px solid red";
149 pass=false;
151 if (document.getElementById('pass_new').value == "") {
152 document.getElementById('pass_new').style.border = "1px solid red";
153 pass=false;
155 if (document.getElementById('pass_new_confirm').value == "") {
156 document.getElementById('pass_new_confirm').style.border = "1px solid red";
157 pass=false;
159 return pass;
161 </script>
162 </head>
163 <body class="skin-blue">
164 <br><br>
165 <div class="container text-center">
166 <?php if (isset($_SESSION['password_update']) || isset($_GET['password_update'])) {
167 $_SESSION['password_update']=1;
169 <div id="wrapper" class="centerwrapper" style="text-align:center;">
170 <h2 class="title"><?php echo xlt('Please Enter a New Password'); ?></h2>
171 <form action="get_patient_info.php" method="POST" onsubmit="return process_new_pass()" >
172 <table style="width:100%">
173 <tr>
174 <td class="algnRight"><?php echo xlt('User Name'); ?></td>
175 <td><input name="uname" id="uname" type="text" autocomplete="off" value="<?php echo attr($_SESSION['portal_username']); ?>"/></td>
176 </tr>
177 <tr>
178 <td class="algnRight"><?php echo xlt('Current Password');?></td>
179 <td>
180 <input name="pass" id="pass" type="password" autocomplete="off" value="" />
181 </td>
182 </tr>
183 <tr>
184 <td class="algnRight"><?php echo xlt('New Password');?></td>
185 <td>
186 <input name="pass_new" id="pass_new" type="password" />
187 </td>
188 </tr>
189 <tr>
190 <td class="algnRight"><?php echo xlt('Confirm New Password');?></td>
191 <td>
192 <input name="pass_new_confirm" id="pass_new_confirm" type="password" />
193 </td>
194 </tr>
195 <?php if ($GLOBALS['enforce_signin_email']) { ?>
196 <tr>
197 <td class="algnRight"><?php echo xlt('Confirm Email Address');?></td>
198 <td>
199 <input name="passaddon" id="passaddon" placeholder="<?php echo xla('Your on file email address'); ?>" type="email" autocomplete="off" value="" />
200 </td>
201 </tr>
202 <?php } ?>
203 <tr>
204 <td colspan=2><br><input class="pull-right" type="submit" value="<?php echo xla('Log In');?>" /></td>
205 </tr>
206 </table>
207 </form>
208 <div class="copyright"><?php echo xlt('Powered by');?> OpenEMR</div>
209 </div>
210 <?php } elseif (isset($_GET['requestNew'])) { ?>
211 <div id="wrapper" class="centerwrapper" style="text-align:center;" >
212 <form class="form-inline" id="resetPass" action="" method="" >
213 <div class="row">
214 <div class="col-sm-10 col-md-offset-1 text-center">
215 <fieldset>
216 <legend class='bg-primary'><h3><?php echo xlt('Patient Credentials Reset') ?></h3></legend>
217 <div class="well">
218 <div class="row">
219 <div class="form-group inline">
220 <label class="control-label" for="fname"><?php echo xlt('First')?></label>
221 <div class="controls inline-inputs">
222 <input type="text" class="form-control" id="fname" required placeholder="<?php echo xla('First Name'); ?>">
223 </div>
224 </div>
225 <div class="form-group inline">
226 <label class="control-label" for="lname"><?php echo xlt('Last Name')?></label>
227 <div class="controls inline-inputs">
228 <input type="text" class="form-control" id="lname" required placeholder="<?php echo xla('Enter Last'); ?>">
229 </div>
230 </div>
231 <div class="form-group inline">
232 <label class="control-label" for="dob"><?php echo xlt('Birth Date')?></label>
233 <div class="controls inline-inputs">
234 <div class="input-group">
235 <input id="dob" type="text" required class="form-control datepicker" placeholder="<?php echo xla('YYYY-MM-DD'); ?>" />
236 </div>
237 </div>
238 </div></div>
239 <div class="row">
240 <div class="col-sm-12 form-group">
241 <label class="control-label" for="emailInput"><?php echo xlt('Enter E-Mail Address')?></label>
242 <div class="controls inline-inputs">
243 <input id="emailInput" type="email" class="form-control" style="width: 100%" required
244 placeholder="<?php echo xla('Must be current email address on file.'); ?>" maxlength="100">
245 </div>
246 </div>
247 </div>
248 </div>
249 <button id="submitRequest" class="btn btn-primary nextBtn btn-sm pull-right" type="button"><?php echo xlt('Verify') ?></button>
250 </fieldset>
251 </div>
252 </div>
253 </form>
254 </div>
255 <?php } else {
256 ?> <!-- Main logon -->
257 <div id="wrapper" class="row centerwrapper text-center">
258 <img style="width:65%" src='<?php echo $GLOBALS['images_static_relative']; ?>/login-logo.png'/>
259 <form class="form-inline text-center" action="get_patient_info.php" method="POST" onsubmit="return process()">
260 <div class="row">
261 <div class="col-sm-12 text-center">
262 <fieldset>
263 <legend class="bg-primary"><h3><?php echo xlt('Patient Portal Login'); ?></h3></legend>
264 <div class="well">
265 <div class="row">
266 <div class="col-sm-12">
267 <div class="form-group inline">
268 <label class="control-label" for="uname"><?php echo xlt('Username')?></label>
269 <div class="controls inline-inputs">
270 <input type="text" class="form-control" name="uname" id="uname" type="text" autocomplete="on" required>
271 </div>
272 </div>
273 <div class="form-group inline">
274 <label class="control-label" for="pass"><?php echo xlt('Password')?></label>
275 <div class="controls inline-inputs">
276 <input class="form-control" name="pass" id="pass" type="password" required autocomplete="on">
277 </div>
278 </div>
279 </div>
280 </div>
281 <div class="row">
282 <?php if ($GLOBALS['enforce_signin_email']) { ?>
283 <div class="col-sm-12 form-group">
284 <label class="control-label" for="passaddon"><?php echo xlt('E-Mail Address')?></label>
285 <div class="controls inline-inputs">
286 <input class="form-control" style="width: 100%" name="passaddon" id="passaddon" placeholder="<?php echo xla('on file email'); ?>" type="email" autocomplete="on" />
287 </div>
288 </div>
289 <?php } ?>
290 </div>
291 <?php if ($GLOBALS['language_menu_login']) { ?>
292 <?php if (count($result3) != 1) { ?>
293 <div class="form-group row">
294 <label for="selLanguage"><?php echo xlt('Language'); ?></label>
295 <select class="form-control" id="selLanguage" name="languageChoice">
296 <?php
297 echo "<option selected='selected' value='" . attr($defaultLangID) . "'>" .
298 text(xl('Default') . " - " . xl($defaultLangName)) . "</option>\n";
299 foreach ($result3 as $iter) {
300 if ($GLOBALS['language_menu_showall']) {
301 if (! $GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
302 continue; // skip the dummy language
304 echo "<option value='" . attr($iter['lang_id']) . "'>" .
305 text($iter['trans_lang_description']) . "</option>\n";
306 } else {
307 if (in_array($iter['lang_description'], $GLOBALS['language_menu_show'])) {
308 if (! $GLOBALS['allow_debug_language'] && $iter['lang_description'] == 'dummy') {
309 continue; // skip the dummy language
311 echo "<option value='" . attr($iter['lang_id']) . "'>" .
312 text($iter['trans_lang_description']) . "</option>\n";
317 </select>
318 </div>
319 <?php } } ?>
320 </div>
321 <div class="col-sm-12 col-md-12">
322 <?php if ($GLOBALS['portal_onsite_two_register']) { ?>
323 <button class="btn btn-default pull-left" onclick="location.replace('./account/register.php')"><?php echo xlt('Register');?></button>
324 <?php } ?>
325 <?php if ($GLOBALS['portal_two_pass_reset'] && isset($_GET['w']) && (isset($_GET['u']) || isset($_GET['p']))) { ?>
326 <button class="btn btn-danger" onclick="location.replace('./index.php?requestNew=1')" style="margin-left:10px"><?php echo xlt('Reset Credentials');?></button>
327 <?php } ?>
328 <button class="btn btn-success pull-right" type="submit" ><?php echo xlt('Log In');?></button>
329 </div>
330 </fieldset>
331 </div>
332 </div>
333 <?php if (!(empty($hiddenLanguageField))) {
334 echo $hiddenLanguageField; } ?>
335 </form>
336 </div><!-- div wrapper -->
337 <?php } ?> <!-- logon wrapper -->
338 </div><!-- container -->
340 <script type="text/javascript">
341 $(function() {
343 <?php // if something went wrong
344 if (isset($_GET['requestNew'])) {
345 $_SESSION['register'] = true;
346 $_SESSION['authUser'] = 'portal-user';
347 $_SESSION['pid'] = true;
349 $('.datepicker').datetimepicker({
350 <?php $datetimepicker_timepicker = false; ?>
351 <?php $datetimepicker_showseconds = false; ?>
352 <?php $datetimepicker_formatInput = false; ?>
353 <?php require($GLOBALS['srcdir'] . '/js/xl/jquery-datetimepicker-2-5-4.js.php'); ?>
355 $(document.body).on('hidden.bs.modal', function () {
356 callServer('cleanup');
358 $("#submitRequest").click(function () {
359 callServer('is_new', '');
361 <?php } ?>
362 <?php if (isset($_GET['w'])) { ?>
363 var unique_id = $.gritter.add({
364 title: '<span class="red">' + <?php echo xlj('Oops!');?> + '</span>',
365 text: <?php echo xlj('Something went wrong. Please try again.'); ?>,
366 sticky: false,
367 time: '5000',
368 class_name: 'my-nonsticky-class'
370 <?php } ?>
371 <?php // if successfully logged out
372 if (isset($_GET['logout'])) { ?>
373 var unique_id = $.gritter.add({
374 title: '<span class="green">' + <?php echo xlj('Success');?> + '</span>',
375 text: <?php echo xlj('You have been successfully logged out.');?>,
376 sticky: false,
377 time: '5000',
378 class_name: 'my-nonsticky-class'
380 <?php } ?>
382 return false;
384 /* Test Data
385 $("#emailInput").val("me@me.com");
386 $("#fname").val("Jerry");
387 $("#lname").val("Padgett");
388 $("#dob").val("1919-03-03"); */
390 function callServer(action, value, value2, last, first) {
391 var data = {
392 'action' : action,
393 'value' : value,
394 'dob' : $("#dob").val(),
395 'last' : $("#lname").val(),
396 'first' : $("#fname").val(),
397 'email' : $("#emailInput").val()
399 if (action == 'do_signup') {
400 data = {
401 'action': action,
402 'pid': value
405 else if (action == 'notify_admin') {
406 data = {
407 'action': action,
408 'pid': value,
409 'provider': value2
412 else if (action == 'cleanup') {
413 data = {
414 'action': action
417 $.ajax({
418 type : 'GET',
419 url : './account/account.php',
420 data : data
421 }).done(function (rtn) {
422 if (action == "cleanup") {
423 window.location.href = "./index.php" // Goto landing page.
425 else if (action == "is_new") {
426 if (parseInt(rtn) > 0) {
427 var yes = confirm(<?php echo xlj("Account is validated. Send new credentials?") ?>);
428 if(!yes)
429 callServer('cleanup');
430 else
431 callServer('do_signup', parseInt(rtn));
433 else {
434 // After error alert app exit to landing page.
435 var message = <?php echo xlj('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.'); ?>;
436 eModal.alert(message);
439 else if (action == 'do_signup') {
440 if (rtn == "") {
441 var message = <?php echo xlj('Unable to either create credentials or send email.'); ?>;
442 alert(message);
443 return false;
445 //alert(rtn); // sync alert.. rtn holds username and password for testing.
446 var message = <?php echo xlj("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."); ?>;
447 eModal.alert(message); // This is an async call. The modal close event exits us to portal landing page after cleanup.
449 }).fail(function (err) {
450 var message = <?php echo xlj('Something went wrong.') ?>;
451 alert(message);
454 </script>
455 </body>
456 </html>