加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
select.php 6.81 KB
一键复制 编辑 原始数据 按行查看 历史
wenxin lai 提交于 2022-05-27 16:38 . 患者预约挂号查看导出处方
<?php
// check the input 患者预约挂号 在medicalrecord里记录下来
function check($value)
{
if (get_magic_quotes_gpc()) {
$value = htmlspecialchars(trim($value));
} else {
$value = addslashes(htmlspecialchars(trim($value)));
}
return $value;
}
session_start();
if (!isset($_SESSION['username']) or !isset($_SESSION['identity']) or $_SESSION['identity'] != 0) {
header("Location:login.php");
exit();
}
date_default_timezone_set('PRC'); //北京时间
$username = $_SESSION['username'];
$Sno = check($_POST['Sno']);
$operation = $_POST['operation_choice'];
if ($operation == 1) { // select
if ($Sno == "") {
echo "
<script>
alert('未选择号源!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
} else {
$db = @mysqli_connect("localhost", "root", "123456", "MIS");
if (!$db) {
die("Fail to connect the database!!" . mysqli_connect_error());
}
mysqli_query($db, "begin");
mysqli_query($db, "set names utf8");
$check_MedicalRecord = mysqli_query($db, "SELECT * FROM MedicalRecord WHERE Sno='$Sno' AND Pno='$username' for update");
if (mysqli_fetch_array($check_MedicalRecord)) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('该号已预约成功,无需重复预约!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
}
//别人已约的号不能再约
$check_Sno = mysqli_query($db, "SELECT * FROM Schedule WHERE Sno='$Sno' for update");
$schedule_info = mysqli_fetch_array($check_Sno);
if ($schedule_info) {
$appointed = $schedule_info['AppointedOrNot'];
if (!strcmp("已约",$appointed)) { //这里应该appointed不用引号?
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('该号已被他人预约!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
} else {
$result1 = mysqli_query($db, " UPDATE Schedule SET AppointedOrNot = '已约' WHERE Sno='$Sno' ");
$Dno = $schedule_info['Dno'];
$result2 = mysqli_query($db, "INSERT INTO MedicalRecord(Pno, Sno,Dno) VALUES ('$username', '$Sno','$Dno')"); //还有Dno
$result3 = mysqli_query($db, "INSERT INTO Prescription(Pno, Sno) VALUES ('$username', '$Sno')");
if ($result1 && $result2 && $result3) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('挂号成功!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
} else {
echo '挂号失败!!', mysqli_error($db), '<br />';
echo 'Click here to <a href="javascript:history.back(-1);">go back</a> and retry..';
mysqli_query($db, "rollback");
mysqli_close($db);
exit();
}
}
} else {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('该号源不存在!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
}
}
} elseif ($operation == -1) { // withdraw 撤销预约挂号
if ($Sno == "") {
echo "
<script>
alert('未选择号源!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
} else {
$db = @mysqli_connect("localhost", "root", "123456", "MIS");
if (!$db) {
die("Fail to connect the database!!" . mysqli_connect_error());
}
mysqli_query($db, "begin");
mysqli_query($db, "set names utf8");
$check_MedicalRecord = mysqli_query($db, "SELECT * FROM MedicalRecord WHERE Sno='$Sno' AND Pno='$username' for update");
$medicalrecord = mysqli_fetch_array($check_MedicalRecord);
$current_time = date("y-m-d h:i:s");
$check_time = mysqli_query($db, "SELECT * FROM Schedule WHERE Sno='$Sno' for update");
$schedule_info = mysqli_fetch_array($check_time);
$start_time = $schedule_info['StartTime'];
if ($medicalrecord) {
if (strtotime($current_time)>= strtotime($start_time) ) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('当前时间晚于预约时间,该预约已经无法撤销!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
} // 可能还有点问题 主要是mysql timestamp,不知道能不能用strtotime
$result1 = mysqli_query($db, "UPDATE Schedule SET AppointedOrNot ='未约' WHERE Sno='$Sno'");
$result2 = mysqli_query($db, "DELETE FROM MedicalRecord WHERE Sno='$Sno' AND Pno='$username'");
$result3 = mysqli_query($db, "DELETE FROM Prescription WHERE Sno='$Sno' AND Pno='$username'");
if ($result1 && $result2) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('预约取消成功!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
} else {
echo '取消失败!!', mysqli_error($db), '<br />';
echo 'Click here to <a href="javascript:history.back(-1);">go back</a> and retry..';
mysqli_query($db, "rollback");
mysqli_close($db);
exit();
}
} else {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('相应挂号信息不存在!!');
window.location.href = 'patient_schedule.php';
</script>
";
exit();
}
}
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化