";} else {echo " We just got through cleaning room " . $roomclean;} } } function lobby() {global $logout_script,$CL_login,$third_login,$Pro_login; $link_id=db_connect(); $randevent=rand(0,100); $randroom=rand(1,23);cleanuproom($randroom); if($_SESSION['listing_only']==1) {echo "Sorry, you are registered as a listing-only member,therefore, you do not have access to the secure chat feature.
"; } else { db_connect(); echo "You are at the reception desk. You cannot chat at the reception desk. If you are early for your appointment, you can go into a room that is not being used. If you want to log out click here. "; if(!empty($_SESSION['userCLid'])){echo "If you are a client, look for the room with your health care provider's name. You can only chat to health care providers, not to clients, because of confidentiality concerns. The health care provider will enter the room when she or he arrives. ";} echo "If you want to close this window, click "; $QRec="SELECT room, occup_id, therapist FROM chat_room ORDER BY room"; $RRec=mysql_query($QRec); $roomnow=0; $no_occ=0; while($Recarray=mysql_fetch_array($RRec)) { $room=$Recarray['room']; if($room != $roomnow) { if($no_occ >= 2) {echo " is in use";} else if(($no_occ==1) && ($therapist==1)) {echo " " . $occup . " is waiting";} else if(($no_occ==1 && !$therapist) && (empty($_SESSION['userProid']))){echo " a client is waiting";} else if($no_occ==1 && !$therapist) {echo " " . $occup . " is waiting";} else {} $no_occ=0; echo "
Room $room"; $no_occ++; $therapist=$Recarray['therapist']; } else { $no_occ++; } $roomnow = $room; $occup=$Recarray['occup_id']; } if($no_occ >= 2) {echo " is in use";} else if($no_occ==1 && $therapist) {echo " " . $occup . " is waiting";} else if(($no_occ==1 && !$therapist) && (empty($_SESSION['userProid']))){echo " a client is waiting";} else if($no_occ==1 && !$therapist) {echo " " . $occup . " is waiting";} else {} }//end of else listing_only } function retrieve_id($room_no) { $link_id = db_connect(); if(!$link_id) die(sql_error()); $chat_sql="SELECT occup_id, therapist FROM chat_room WHERE room=$room_no"; $occup_result=mysql_query($chat_sql); if(!empty($_SESSION['userProid'])) { $display_id=$_SESSION['userProid']; }/// end of if else if(!empty($_SESSION['user3id1'])) { $display_id=$_SESSION['user3id1']; }///end of else if else if(!empty($_SESSION['userCLid'])) { $display_id=$_SESSION['userCLid']; }///end of else if else {} while($occup_array=mysql_fetch_array($occup_result)) {$occupt=$occup_array['occup_id']; $istherapist=$occup_array['therapist']; if($occupt != $display_id && $istherapist) { $return_id=$occupt; } else if(($occupt != $display_id && !$istherapist) && empty($_SESSION['userProid'])) { $return_id="a client (cannot chat)"; } else if(($occupt != $display_id && !$istherapist) && !empty($_SESSION['userProid'])) { $return_id=$occupt; } else { } } return $return_id; } function get_suser_id() { if (!empty($_SESSION['userProid'])) { $display_id=$_SESSION['userProid']; }/// end of if else if(!empty($_SESSION['user3id1'])) { $display_id=$_SESSION['user3id1']; }///end of else if else if(!empty($_SESSION['userCLid'])) { $display_id=$_SESSION['userCLid']; }///end of else if else {} return $display_id; } function get_iv() { $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); srand((float) microtime() * 1000000); $result_iv = mcrypt_create_iv($size, MCRYPT_RAND); return $result_iv; }///////end function get_iv function chat_form($room_no, $me) { add_msg_form($room_no, $me); leave_room_form(); } function add_msg_form($room_no, $me) { echo "
"; echo ""; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; }///end of function add_msg_form function enter_room_form() { echo ""; echo "
Your ID"; echo $display_id; if(!empty($room_no)) echo ", you are in room " . $room_no; $recipient_id=retrieve_id($room_no); if(!empty($recipient_id)) echo " with " . $recipient_id; echo "
"; display_chat($room_no, $me); echo "
message"; echo "
to:"; echo "
"; echo "
"; echo "
"; echo "Enter a room: "; echo ""; echo "
"; echo ""; } function add_msg() { global $mcrypt_key; $link_id = db_connect(); if(!$link_id) die(sql_error()); $temp_room=$_SESSION['room_no']; $temp_sender=$_POST['sender_id2']; $temp_recipient=$_POST['recipient_id']; $temp_msg_input=$_POST['msg_input']; $temp_msg_input=ereg_replace(";","", $temp_msg_input); $todaytime=time(); $temp_time=strftime('%Y-%m-%d %H:%M:%S', $todaytime); $mcrypt_module = mcrypt_module_open('rijndael-256', '', 'cbc', ''); $mcrypt_iv=get_iv(); mcrypt_generic_init($mcrypt_module, $mcrypt_key, $mcrypt_iv); $temp_msg_input=base64_encode(mcrypt_generic($mcrypt_module, $temp_msg_input)); mcrypt_generic_deinit($mcrypt_module); $mcrypt_iv64=base64_encode($mcrypt_iv); $am_query="INSERT INTO chat (chat_id, sender, recipient, time, room, msg, msg_key) VALUES(NULL,'$temp_sender', '$temp_recipient', NULL, '$temp_room', '$temp_msg_input', '$mcrypt_iv64')"; $result_iq=mysql_query($am_query); if(!$result_iq) error_message(sql_error()); } /////////////////////DISPLAY CHAT function display_chat($room_no, $me) { db_connect(); global $mcrypt_key, $timelimit; $qchat="SELECT * FROM chat where room='$room_no' and ((recipient='$me' OR sender='$me' OR (recipient='All')) and (time > $timelimit) ) ORDER BY time ASC"; $rchat=mysql_query($qchat); if(!$rchat) error_message(sql_error()); else { $mcrypt_module = mcrypt_module_open('rijndael-256', '', 'cbc', ''); if(!$mcrypt_module) error_message('no mcrypt module'); while($marray=mysql_fetch_array($rchat)) { $sender=$marray['sender']; $msg=$marray['msg']; $msg_key=$marray['msg_key']; $mcrypt_iv_un64=base64_decode($msg_key); mcrypt_generic_init($mcrypt_module, $mcrypt_key, $mcrypt_iv_un64); $d_msg=mdecrypt_generic($mcrypt_module, base64_decode($msg)); $d_msg=rtrim($d_msg, "\0"); $d_msg = preg_replace("(\r\n|\n|\r)", "#", $d_msg); $d_msg = preg_replace("/[^0-9a-z@.,?' -#]/i",'', $d_msg); //strip unwanted $d_msg = str_replace("#", "
", $d_msg); $time_msg=$marray['time']; echo "
" . $sender . ": " . $d_msg; } mcrypt_generic_deinit($mcrypt_module); } } function enter_room($room_no, $suser_id) {global $mcrypt_key; db_connect(); $checkroom_q="SELECT occup_id FROM chat_room WHERE room=$room_no"; $checkroom_r=mysql_query($checkroom_q); if(!$checkroom_r) error_message(sql_error()); $no_in_room=mysql_num_rows($checkroom_r); if(!empty($_SESSION['userProid'])){$ther=1;} else {$ther=0;} if($no_in_room > 1) { $marker=0; while($occup_array=mysql_fetch_array($checkroom_r)) { $occup=$occup_array['occup_id']; if($occup==$suser_id) {$marker=1;} } if($marker==1) { $dquery="DELETE FROM chat_room WHERE occup_id='$suser_id' AND room !=$room_no"; $dresult=mysql_query($dquery); if(!$dresult) error_message(sql_error()); $rquery="INSERT INTO chat_room (entry_id,occup_id, room, therapist) VALUES(NULL, '$suser_id', $room_no, $ther)"; $rresult=mysql_query($rquery); if(!$rresult) error_message(sql_error()); $_SESSION['room_no']=$room_no; $mcrypt_module = mcrypt_module_open('rijndael-256', '', 'cbc', ''); $mcrypt_iv=get_iv(); $temp_msg_input="....has entered the room"; if(empty($_SESSION['userProid'])){$suser1="a client";} else {$suser1=$suser_id;} mcrypt_generic_init($mcrypt_module, $mcrypt_key, $mcrypt_iv); $temp_msg_input=base64_encode(mcrypt_generic($mcrypt_module, $temp_msg_input)); mcrypt_generic_deinit($mcrypt_module); $mcrypt_iv64=base64_encode($mcrypt_iv); $am_query="INSERT INTO chat (chat_id, sender, recipient, time, room, msg, msg_key) VALUES(NULL,'$suser1', 'All', NULL, '$room_no', '$temp_msg_input', '$mcrypt_iv64')"; $result_iq=mysql_query($am_query); if(!$result_iq) error_message(sql_error()); mcrypt_generic_deinit($mcrypt_module); } else if($marker==0) { error_message("Sorry that room is full!"); } } else { $dquery="DELETE FROM chat_room WHERE occup_id='$suser_id' AND room !=$room_no"; $dresult=mysql_query($dquery); if(!$dresult) error_message(sql_error()); $rquery="INSERT INTO chat_room (entry_id,occup_id, room, therapist) VALUES(NULL, '$suser_id', $room_no, $ther)"; $rresult=mysql_query($rquery); if(!$rresult) error_message(sql_error()); $_SESSION['room_no']=$room_no; $mcrypt_module = mcrypt_module_open('rijndael-256', '', 'cbc', ''); $mcrypt_iv=get_iv(); $temp_msg_input="....has entered the room"; if(empty($_SESSION['userProid'])){$suser1="a client";} else {$suser1=$suser_id;} mcrypt_generic_init($mcrypt_module, $mcrypt_key, $mcrypt_iv); $temp_msg_input=base64_encode(mcrypt_generic($mcrypt_module, $temp_msg_input)); mcrypt_generic_deinit($mcrypt_module); $mcrypt_iv64=base64_encode($mcrypt_iv); $am_query="INSERT INTO chat (chat_id, sender, recipient, time, room, msg, msg_key) VALUES(NULL,'$suser1', 'All', NULL, '$room_no', '$temp_msg_input', '$mcrypt_iv64')"; $result_iq=mysql_query($am_query); if(!$result_iq) error_message(sql_error()); mcrypt_generic_deinit($mcrypt_module); } } function leave_room($suser_id) {global $mcrypt_key, $timelimit; db_connect(); $rquery="DELETE FROM chat_room WHERE occup_id='$suser_id'"; $rresult=mysql_query($rquery); if(!$rresult) error_message(sql_error()); $room_no=$_SESSION['room_no']; $_SESSION['room_no']=''; if(empty($_SESSION['userProid'])){$suser1="a client";} else {$suser1=$suser_id;} $mcrypt_module = mcrypt_module_open('rijndael-256', '', 'cbc', ''); $mcrypt_iv=get_iv(); $temp_msg_input="....has left the room"; mcrypt_generic_init($mcrypt_module, $mcrypt_key, $mcrypt_iv); $temp_msg_input=base64_encode(mcrypt_generic($mcrypt_module, $temp_msg_input)); mcrypt_generic_deinit($mcrypt_module); $mcrypt_iv64=base64_encode($mcrypt_iv); $am_query="INSERT INTO chat (chat_id, sender, recipient, time, room, msg, msg_key) VALUES(NULL,'$suser1', 'All', NULL, '$room_no', '$temp_msg_input', '$mcrypt_iv64')"; $result_iq=mysql_query($am_query); if(!$result_iq) error_message(sql_error()); mcrypt_generic_deinit($mcrypt_module); $cleanQ="DELETE FROM chat WHERE time < '$timelimit'"; $cleanR=mysql_query($cleanQ); if(!$cleanR) error_message("Cannot clean up the room"); } function leave_room_form() { echo "
"; echo "
"; echo "Leave the room "; echo ""; echo "
"; echo ""; echo "
"; echo "
"; echo "Refresh the browser "; echo ""; echo "
"; echo "
"; echo "
"; } ////////////BODY BODY BODY BODY//////////// session_start(); global $PHP_SELF; echo ""; echo ""; echo ""; ?> here for access.");} $me=get_suser_id(); if(empty($me)){echo "No user logged in!"; echo "
If you are a client or patient, log in here!"; echo "
If you are a health care or service provider, log in here!"; } else if ($_POST['action_msg']=="added_msg") { add_msg(); $me=get_suser_id(); $room_no=$_SESSION['room_no']; chat_form($room_no, $me); } else if ($_POST['action_msg']=="enter_room") { $room_no=$_POST['room_no']; $suser_id=get_suser_id(); enter_room($room_no, $suser_id); $room_no=$_SESSION['room_no']; chat_form($room_no, $suser_id); } else if ($_POST['action_msg']=="leave_room") { $suser_id=get_suser_id(); leave_room($suser_id); lobby(); enter_room_form(); } else { $me=get_suser_id(); $room_no=$_SESSION['room_no']; if(!empty($room_no)) { chat_form($room_no, $me); } else { lobby(); enter_room_form(); } } //////////////////////END echo "";