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 // +------------------------------------------------------------------------------+
29 //SANITIZE ALL ESCAPES
30 $sanitize_all_escapes=true;
33 //STOP FAKE REGISTER GLOBALS
34 $fake_register_globals=false;
36 require_once("../../globals.php");
37 require_once("$srcdir/sql.inc");
38 require_once("$srcdir/formdata.inc.php");
39 require_once("$srcdir/sha1.js");
40 require_once("$srcdir/classes/postmaster.php");
42 // Collect portalsite parameter (either off for offsite or on for onsite); only allow off or on
43 isset($_GET['portalsite']) ?
$portalsite = $_GET['portalsite'] : $portalsite = "off";
44 if ($portalsite != "off" && $portalsite != "on") $portalsite = "off";
46 $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));
48 function generatePassword($length=6, $strength=1) {
49 $consonants = 'bdghjmnpqrstvzacefiklowxy';
50 $numbers = '0234561789';
56 for ($i = 0; $i < $length/3; $i++
) {
58 $password .= $consonants[(rand() %
strlen($consonants))].$numbers[(rand() %
strlen($numbers))].$specials[(rand() %
strlen($specials))];
61 $password .= $numbers[(rand() %
strlen($numbers))].$specials[(rand() %
strlen($specials))].$consonants[(rand() %
strlen($consonants))];
68 function validEmail($email){
69 if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
75 function messageCreate($uname,$pass,$site){
76 $message = htmlspecialchars( xl("Patient Portal Web Address"),ENT_NOQUOTES
) . ":<br>";
78 $message .= "<a href='" . htmlspecialchars($GLOBALS['portal_onsite_address'],ENT_QUOTES
) . "'>" .
79 htmlspecialchars($GLOBALS['portal_onsite_address'],ENT_NOQUOTES
) . "</a><br><br>";
82 $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
);
83 $message .= "<a href='" . $offsite_portal_patient_link . "'>" .
84 $offsite_portal_patient_link . "</a><br><br>";
85 $message .= htmlspecialchars(xl("Provider Id"),ENT_NOQUOTES
) . ": " .
86 htmlspecialchars($GLOBALS['portal_offsite_providerid'],ENT_NOQUOTES
) . "<br><br>";
89 $message .= htmlspecialchars(xl("User Name"),ENT_NOQUOTES
) . ": " .
90 htmlspecialchars($uname,ENT_NOQUOTES
) . "<br><br>" .
91 htmlspecialchars(xl("Password"),ENT_NOQUOTES
) . ": " .
92 htmlspecialchars($pass,ENT_NOQUOTES
) . "<br><br>";
96 function emailLogin($patient_id,$message){
97 $patientData = sqlQuery("SELECT * FROM `patient_data` WHERE `pid`=?", array($patient_id) );
98 if ( $patientData['hipaa_allowemail'] != "YES" ||
empty($patientData['email']) ||
empty($GLOBALS['patient_reminder_sender_email']) ) {
101 if (!(validEmail($patientData['email']))) {
104 if (!(validEmail($GLOBALS['patient_reminder_sender_email']))) {
108 $mail = new MyMailer();
109 $pt_name=$patientData['fname'].' '.$patientData['lname'];
110 $pt_email=$patientData['email'];
111 $email_subject=xl('Access Your Patient Portal');
112 $email_sender=$GLOBALS['patient_reminder_sender_email'];
113 $mail->AddReplyTo($email_sender, $email_sender);
114 $mail->SetFrom($email_sender, $email_sender);
115 $mail->AddAddress($pt_email, $pt_name);
116 $mail->Subject
= $email_subject;
117 $mail->MsgHTML("<html><body><div class='wrapper'>".$message."</div></body></html>");
119 $mail->AltBody
= $message;
124 $email_status = $mail->ErrorInfo
;
125 error_log("EMAIL ERROR: ".$email_status,0);
130 function displayLogin($patient_id,$message,$emailFlag){
131 $patientData = sqlQuery("SELECT * FROM `patient_data` WHERE `pid`=?", array($patient_id) );
133 $message = "<br><br>" .
134 htmlspecialchars(xl("Email was sent to following address"),ENT_NOQUOTES
) . ": " .
135 htmlspecialchars($patientData['email'],ENT_NOQUOTES
) . "<br><br>" .
138 echo "<html><body onload='window.print();'>" . $message . "</body></html>";
141 if(isset($_REQUEST['form_save']) && $_REQUEST['form_save']=='SUBMIT'){
142 $res = sqlStatement("SELECT * FROM patient_access_" . add_escape_custom($portalsite) . "site WHERE pid=?",array($pid));
143 if(sqlNumRows($res)){
144 sqlStatement("UPDATE patient_access_" . add_escape_custom($portalsite) . "site SET portal_username=?,portal_pwd=?,portal_pwd_status=0 WHERE pid=?",array($_REQUEST['uname'],$_REQUEST['authpwd'],$pid));
147 sqlStatement("INSERT INTO patient_access_" . add_escape_custom($portalsite) . "site SET portal_username=?,portal_pwd=?,portal_pwd_status=0,pid=?",array($_REQUEST['uname'],$_REQUEST['authpwd'],$pid));
150 // Create the message
151 $message = messageCreate($_REQUEST['uname'],$_REQUEST['pwd'],$portalsite);
152 // Email and display/print the message
153 if ( emailLogin($pid,$message) ) {
155 displayLogin($pid,$message,true);
159 displayLogin($pid,$message,false);
166 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
167 <script type
="text/javascript">
168 function convertPass(){
169 document
.getElementById('authpwd').value
=SHA1(document
.getElementById('pwd').value
);
170 document
.getElementById('form_save').value
='SUBMIT';
171 top
.restoreSession();
172 document
.forms
[0].submit();
176 <body
class="body_top">
177 <form name
="portallogin" action
="" method
="POST">
178 <table align
="center" style
="margin-top:10px">
180 <th colspan
="5" align
="center"><?php
echo htmlspecialchars(xl("Generate Username And Password For")." ".$row['fname'],ENT_QUOTES
);?
></th
>
183 if($portalsite == 'off'){
186 <td
><?php
echo htmlspecialchars(xl('Provider Id').':',ENT_QUOTES
);?
></td
>
187 <td
><span
><?php
echo htmlspecialchars($GLOBALS['portal_offsite_providerid'],ENT_QUOTES
);?
></span
></td
>
193 <td
><?php
echo htmlspecialchars(xl('User Name').':',ENT_QUOTES
);?
></td
>
194 <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
>
197 <td
><?php
echo htmlspecialchars(xl('Password').':',ENT_QUOTES
);?
></td
>
199 $pwd = generatePassword();
201 <input type
="hidden" name
="authpwd" id
="authpwd">
202 <td
><input type
="text" name
="pwd" id
="pwd" value
="<?php echo htmlspecialchars($pwd,ENT_QUOTES);?>" size
="10" readonly
></td
>
203 <td
><a href
="#" class="css_button" onclick
="top.restoreSession(); javascript:document.location.reload()"><span
><?php
echo htmlspecialchars(xl('Change'),ENT_QUOTES
);?
></span
></a
></td
>
206 <td
><input type
="hidden" name
="form_save" id
="form_save"></td
>
207 <td colspan
="5" align
="center">
208 <a href
="#" class="css_button" onclick
="return convertPass()"><span
><?php
echo htmlspecialchars(xl('Save'),ENT_QUOTES
);?
></span
></a
>
209 <input type
="hidden" name
="form_cancel" id
="form_cancel">
210 <a href
="#" class="css_button" onclick
="top.restoreSession(); parent.$.fn.fancybox.close();"><span
><?php
echo htmlspecialchars(xl('Cancel'),ENT_QUOTES
);?
></span
></a
>