2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2011 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the 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 General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Jacob T Paul <jacob@zhservices.com>
25 // Paul Simon <paul@zhservices.com>
27 // +------------------------------------------------------------------------------+
30 require_once("../../globals.php");
32 // Collect portalsite parameter (either off for offsite or on for onsite); only allow off or on
33 $portalsite = isset($_GET['portalsite']) ?
$_GET['portalsite'] : $portalsite = "off";
34 if ($portalsite != "off" && $portalsite != "on") $portalsite = "off";
36 $row = sqlQuery("SELECT pd.*,pao.portal_username,pao.portal_pwd,pao.portal_pwd_status FROM patient_data AS pd LEFT OUTER JOIN patient_access_" . add_escape_custom($portalsite) . "site AS pao ON pd.pid=pao.pid WHERE pd.pid=?",array($pid));
38 function generatePassword($length=6, $strength=1) {
39 $consonants = 'bdghjmnpqrstvzacefiklowxy';
40 $numbers = '0234561789';
46 for ($i = 0; $i < $length/3; $i++
) {
48 $password .= $consonants[(rand() %
strlen($consonants))].$numbers[(rand() %
strlen($numbers))].$specials[(rand() %
strlen($specials))];
51 $password .= $numbers[(rand() %
strlen($numbers))].$specials[(rand() %
strlen($specials))].$consonants[(rand() %
strlen($consonants))];
58 function validEmail($email){
59 if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)) {
65 function messageCreate($uname,$pass,$site){
66 $message = htmlspecialchars( xl("Patient Portal Web Address"),ENT_NOQUOTES
) . ":<br>";
68 if ($GLOBALS['portal_onsite_enable']) {
69 $message .= "<a href='" . htmlspecialchars($GLOBALS['portal_onsite_address'],ENT_QUOTES
) . "'>" .
70 htmlspecialchars($GLOBALS['portal_onsite_address'],ENT_NOQUOTES
) . "</a><br>";
72 if ($GLOBALS['portal_onsite_two_enable']) {
73 $message .= "<a href='" . htmlspecialchars($GLOBALS['portal_onsite_two_address'],ENT_QUOTES
) . "'>" .
74 htmlspecialchars($GLOBALS['portal_onsite_two_address'],ENT_NOQUOTES
) . "</a><br>";
79 $offsite_portal_patient_link = $GLOBALS['portal_offsite_address_patient_link'] ?
htmlspecialchars($GLOBALS['portal_offsite_address_patient_link'],ENT_QUOTES
) : htmlspecialchars("https://mydocsportal.com",ENT_QUOTES
);
80 $message .= "<a href='" . $offsite_portal_patient_link . "'>" .
81 $offsite_portal_patient_link . "</a><br><br>";
82 $message .= htmlspecialchars(xl("Provider Id"),ENT_NOQUOTES
) . ": " .
83 htmlspecialchars($GLOBALS['portal_offsite_providerid'],ENT_NOQUOTES
) . "<br><br>";
86 $message .= htmlspecialchars(xl("User Name"),ENT_NOQUOTES
) . ": " .
87 htmlspecialchars($uname,ENT_NOQUOTES
) . "<br><br>" .
88 htmlspecialchars(xl("Password"),ENT_NOQUOTES
) . ": " .
89 htmlspecialchars($pass,ENT_NOQUOTES
) . "<br><br>";
93 function emailLogin($patient_id,$message){
94 $patientData = sqlQuery("SELECT * FROM `patient_data` WHERE `pid`=?", array($patient_id) );
95 if ( $patientData['hipaa_allowemail'] != "YES" ||
empty($patientData['email']) ||
empty($GLOBALS['patient_reminder_sender_email']) ) {
98 if (!(validEmail($patientData['email']))) {
101 if (!(validEmail($GLOBALS['patient_reminder_sender_email']))) {
105 $mail = new MyMailer();
106 $pt_name=$patientData['fname'].' '.$patientData['lname'];
107 $pt_email=$patientData['email'];
108 $email_subject=xl('Access Your Patient Portal');
109 $email_sender=$GLOBALS['patient_reminder_sender_email'];
110 $mail->AddReplyTo($email_sender, $email_sender);
111 $mail->SetFrom($email_sender, $email_sender);
112 $mail->AddAddress($pt_email, $pt_name);
113 $mail->Subject
= $email_subject;
114 $mail->MsgHTML("<html><body><div class='wrapper'>".$message."</div></body></html>");
116 $mail->AltBody
= $message;
121 $email_status = $mail->ErrorInfo
;
122 error_log("EMAIL ERROR: ".$email_status,0);
127 function displayLogin($patient_id,$message,$emailFlag){
128 $patientData = sqlQuery("SELECT * FROM `patient_data` WHERE `pid`=?", array($patient_id) );
130 $message = "<br><br>" .
131 htmlspecialchars(xl("Email was sent to following address"),ENT_NOQUOTES
) . ": " .
132 htmlspecialchars($patientData['email'],ENT_NOQUOTES
) . "<br><br>" .
135 echo "<html><body onload='top.printLogPrint(window);'>" . $message . "</body></html>";
138 if(isset($_REQUEST['form_save']) && $_REQUEST['form_save']=='SUBMIT'){
139 require_once("$srcdir/authentication/common_operations.php");
141 $clear_pass=$_REQUEST['pwd'];
143 $res = sqlStatement("SELECT * FROM patient_access_" . add_escape_custom($portalsite) . "site WHERE pid=?",array($pid));
144 $query_parameters=array($_REQUEST['uname']);
146 if($portalsite=='on')
148 // For onsite portal create a blowfish based hash and salt.
149 $new_salt = oemr_password_salt();
150 $salt_clause = ",portal_salt=? ";
151 array_push($query_parameters,oemr_password_hash($clear_pass,$new_salt),$new_salt);
155 // For offsite portal still create and SHA1 hashed password
156 // When offsite portal is updated to handle blowfish, then both portals can use the same execution path.
157 array_push($query_parameters,SHA1($clear_pass));
159 array_push($query_parameters,$pid);
160 if(sqlNumRows($res)){
161 sqlStatement("UPDATE patient_access_" . add_escape_custom($portalsite) . "site SET portal_username=?,portal_pwd=?,portal_pwd_status=0 " . $salt_clause . " WHERE pid=?",$query_parameters);
164 sqlStatement("INSERT INTO patient_access_" . add_escape_custom($portalsite) . "site SET portal_username=?,portal_pwd=?,portal_pwd_status=0" . $salt_clause . " ,pid=?",$query_parameters);
167 // Create the message
168 $message = messageCreate($_REQUEST['uname'],$clear_pass,$portalsite);
169 // Email and display/print the message
170 if ( emailLogin($pid,$message) ) {
172 displayLogin($pid,$message,true);
176 displayLogin($pid,$message,false);
183 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
185 <script type
="text/javascript" src
="<?php echo $GLOBALS['assets_static_relative']; ?>/jquery-min-1-7-2/index.js"></script
>
186 <script type
="text/javascript">
189 // get a public key to encrypt the password info and send
190 document
.getElementById('form_save').value
='SUBMIT';
191 document
.forms
[0].submit();
195 <body
class="body_top">
196 <form name
="portallogin" action
="" method
="POST">
197 <table align
="center" style
="margin-top:10px">
199 <th colspan
="5" align
="center"><?php
echo htmlspecialchars(xl("Generate Username And Password For")." ".$row['fname'],ENT_QUOTES
);?
></th
>
202 if($portalsite == 'off'){
205 <td
><?php
echo htmlspecialchars(xl('Provider Id').':',ENT_QUOTES
);?
></td
>
206 <td
><span
><?php
echo htmlspecialchars($GLOBALS['portal_offsite_providerid'],ENT_QUOTES
);?
></span
></td
>
212 <td
><?php
echo htmlspecialchars(xl('User Name').':',ENT_QUOTES
);?
></td
>
213 <td
><input type
="text" name
="uname" value
="<?php if($row['portal_username']) echo htmlspecialchars($row['portal_username'],ENT_QUOTES); else echo htmlspecialchars($row['fname'].$row['id'],ENT_QUOTES);?>" size
="10" readonly
></td
>
216 <td
><?php
echo htmlspecialchars(xl('Password').':',ENT_QUOTES
);?
></td
>
218 $pwd = generatePassword();
220 <td
><input type
="text" name
="pwd" id
="pwd" value
="<?php echo htmlspecialchars($pwd,ENT_QUOTES);?>" size
="10"/>
222 <td
><a href
="#" class="css_button" onclick
="top.restoreSession(); javascript:document.location.reload()"><span
><?php
echo htmlspecialchars(xl('Change'),ENT_QUOTES
);?
></span
></a
></td
>
225 <td
><input type
="hidden" name
="form_save" id
="form_save"></td
>
226 <td colspan
="5" align
="center">
227 <a href
="#" class="css_button" onclick
="return transmit()"><span
><?php
echo htmlspecialchars(xl('Save'),ENT_QUOTES
);?
></span
></a
>
228 <input type
="hidden" name
="form_cancel" id
="form_cancel">
229 <a href
="#" class="css_button" onclick
="top.restoreSession(); parent.$.fn.fancybox.close();"><span
><?php
echo htmlspecialchars(xl('Cancel'),ENT_QUOTES
);?
></span
></a
>