Ai
4 Star 0 Fork 0

softwareengineering1/software

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Masterserver.php 6.56 KB
一键复制 编辑 原始数据 按行查看 历史
softwareengineering1 提交于 2021-05-30 19:41 +08:00 . contents of comment
<?php
include ("functions.php");
function updatecoursepeople($link,$courseid)
{
$result = $link->query("update course set nowpeople=(SELECT COUNT(*)
FROM sc
where courseid='$courseid') where courseid='$courseid'"
);
return $result;
}
function getnowcreditnumfromusername($link,$username)
{
//通过username获取用户已选修的积分总和
$result = $link->query("select *
FROM sc,course as c
where sc.username='$username' and sc.courseid=c.courseid ");
$num=0;
if(!$result)return 9999;
while($row=mysqli_fetch_assoc($result))
{
$num+=$row['credit'];
}
return $num;
}
function getmajorcreditlimitfromusername($link,$username)
{
//通过username获取用户专业的积分选修总分限制
$result = $link->query("select *
FROM accounts as a,major as m
where a.username='$username' and a.majorid=m.majorid ");
$row=mysqli_fetch_assoc($result);
return $row['creditlimit'];
}
function getcoursecredit($link,$courseid)
{
//通过courseid获取该课程的学分
$result = $link->query("select *
FROM course
where courseid='$courseid' ");
$row=mysqli_fetch_assoc($result);
return $row['credit'];
}
function checkcourselimit($link,$username,$courseid)
{
//判断该username的专业majorid是否有限制electivelimit不能选课
//1通过username 找到 专业$majorid 和 年级(1/2/3/4)
$result = $link->query("select *
from accounts
where username='$username' ");
$row=mysqli_fetch_assoc($result);
$majorid1=$row['majorid'];
$grade=gettoyear()-$row['enteryear']+1;
//2查找limit规则中是否存在满足courseid majorid grade 三要素的的记录 有就是没限制 没有就是限制
$result = $link->query("select *
FROM electivelimit
where courseid='$courseid' and (majorid='$majorid1' or majorid='0') and (grade='$grade' or grade='0')");
while($row=mysqli_fetch_assoc($result))
{
return true;
}
return false;
}
header("Content-type:application/json");
//在发送数据到服务器前简单的进行编码
header('Access-Control-Allow-Origin:*');
if(!isset($_GET['action']))
{
//来访若没有定义action 那么就忽略
exit();
}
include_once ("./conn.php");
//获取操作数据
$action=$_GET['action'];//操作类型
$results="0000";
if($action=="takeapart")
{
//添加选修课程
if(!isset($_COOKIE['username']))
{
$results="请先登录账户!";
} else {
//获取课程号
$courseid=$_GET['courseid'];
//判断课程是否满人
$result = $link->query("SELECT COUNT(*)
FROM course
where courseid='$courseid' and nowpeople < numpeople"
);
if(!$result)
{
$results="fail";
}else{
list($row_num) = $result->fetch_row();
if($row_num<=0)
{
$results="fail-full";
}else{
//是否已加入课程?
$username=$_COOKIE['username'];
$result2 = $link->query("SELECT COUNT(*)
FROM sc
where username='$username' and courseid='$courseid'"
);
if(!$result2)
{
$results="fail";
}else if(!checkcourselimit($link,$username,$courseid)){
$results="由于您的专业或年级的限制,您不能选修该门课程。";
}else{
list($row_num2) = $result2->fetch_row();
// $row_num2 = mysqli_num_rows($result2);
if($row_num2>0)
{
$results="fail-already";
}else{
//判断用户选修积分有没有超额度
if(getnowcreditnumfromusername($link,$username)+getcoursecredit($link,$courseid)>getmajorcreditlimitfromusername($link,$username))
{
//学分超限
$results="你能选修的学分已超过每学年的限制,请退掉其他课程再选修本课程,或者等下学期再选修。";
}else {
//学分足够
//加入课程
$result = $link->query("insert into sc
values('$username','$courseid','0')"
);
if(!$result)
{
$results="fail";
}else {
if(updatecoursepeople($link,$courseid))
{
$results = "ok";
}else{
$results="fail";
}
}
}
}
}
}
//加入课程
}
}
}
else if($action=="savepms"){
//用户更新个人资料
if(isset($_COOKIE['username']))
{
$username=$_COOKIE['username'];
}else exit();
$realname=$_GET['realname'];
$email=$_GET['email'];
date_default_timezone_set("PRC");//消除时差
$birthday=(int)strtotime($_GET['birthday']);
$identity=$_GET['identity'];
$address=$_GET['address'];
$tel=$_GET['tel'];
if($_GET['gender']=='男')
{
$gender=0;
}
else{
$gender=1;
}
$result = $link->query("update accounts
set gender='$gender', realname='$realname',email='$email',birthday='$birthday',identity='$identity',address='$address',tel='$tel'
where username='$username'"
);
if(!$result) {
$results = "fail";
}else{
$results="ok";
}
}
else if($action=="dropcourse"){
//退课操作
if(isset($_COOKIE['username']))
{
$username=$_COOKIE['username'];
}else exit();
$courseid=$_GET['courseid'];
$result = $link->query("delete from sc
where username='$username' and courseid='$courseid'"
);
if(!$result) {
$results = "fail";
}else{
updatecoursepeople($link,$courseid);
$results="ok";
}
}else $results= "???";
$link->close();
echo json_encode($results);
//最后返回数据给前端
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/softwareengineering1/software.git
git@gitee.com:softwareengineering1/software.git
softwareengineering1
software
software
master

搜索帮助