⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 att.php

📁 基于数据库设计一个网页,实现基本功能:增删改、查询、统计报表的功能要有.管理信息
💻 PHP
字号:
<?php header("Content-Type: text/html; charset=UTF8");?>
<?php putenv("NLS_LANG=AMERICAN_AMERICA.AL32UTF8");?>
<html>
<head>
<title>Teacher Assistant System</title>
<link href="tas.css" rel="stylesheet" type="text/css">
</head>

<body><center>
<a href=index.php><span class=red>[INDEX]</span></a>
<a href=lec.php><span class=red>[LECTURES]</span></a>
<?php
	//connect to oracle db
	$conn=oci_connect("zhangsan","p06123456","//127.0.0.1/XE");
	if(!$conn)
	{
		echo "<h2>db connection error.</h2>".var_dump(oci_error());
		die();
	}
	
	//read selected major from URL (the m= phrase in "att.php?m=###")
	if( !isset($_REQUEST['m']) or $_REQUEST['m']=="")
	{
		header( 'Location: index.php' );
	}
	$class_selected=htmlentities($_REQUEST['m']);
	
	//read current selected student, the s= phrase
	$student_selected=0;
	if( isset($_REQUEST['s']) && $_REQUEST['s']!="" && $_REQUEST['s']!="0")
	{
		$student_selected=htmlentities($_REQUEST['s']);
	}
	//the status= phrase to update status of current student
	$student_status="";
	if(isset($_REQUEST['status']) && $_REQUEST['status']!="" )
	{
		$student_status=htmlentities($_REQUEST['status']);
		
		$query="select lecture_no as newid from lectures where trunc(lecture_date)=trunc(SYSDATE)";
		$sql=oci_parse($conn,$query);
		$ret=oci_execute($sql,OCI_DEFAULT);
		if (!$ret) {
			echo 'SQL:'.$query;
		    	echo 'Could not run query: ' . oci_error();
		    	exit;
		}
		$newid=0;
		if( $row=oci_fetch_array($sql,OCI_BOTH) )
		{
			$newid = $row['NEWID'];
		}else{
			$query="select count(*) as numid,max(lecture_no)+1 as newid from lectures";
			$sql=oci_parse($conn,$query);
			if(!oci_execute($sql,OCI_DEFAULT)){
				echo 'Could not run query: ' . oci_error();
				exit;
			}
			$row=oci_fetch_array($sql,OCI_BOTH);
			if($row['NUMID']>0)
				$newid=$row['NEWID'];
			else
				$newid=1;
			$query="insert into lectures values(".$newid.",SYSDATE,'A TOPIC')";
			$sql=oci_parse($conn,$query);
			if(!oci_execute($sql,OCI_COMMIT_ON_SUCCESS)){
				echo 'Could not run query: ' . oci_error();
				exit;
			}
		}
		
		$sql=oci_parse($conn,"select * from attend where student_no=".$student_selected." and lecture_no=".$newid);
		$ret=oci_execute($sql,OCI_DEFAULT);
		if (!$ret) {
			echo 'Could not run query: ' . oci_error();
			exit;
		}		
		if( oci_fetch_array($sql,OCI_BOTH) )
		{
			$sql=oci_parse($conn,"update attend set status='".$student_status."' where student_no=".$student_selected." and lecture_no=".$newid);
		}else
		{
			$sql=oci_parse($conn,"insert into attend values(".$student_selected.",".$newid.",'".$student_status."')");
		}
		if(!oci_execute($sql,OCI_COMMIT_ON_SUCCESS)){
		    echo 'Could not run query: ' . oci_error();
		    exit;
		}
	}
	//query major name
	$sql="select upper(NAME)||' '||YEAR as CLASS_NAME ".
		"from classes left join majors using (MAJOR_NO) ".
		"where (MAJOR_NO,YEAR)=(($class_selected))";
	$s=oci_parse($conn,$sql);
	$result=oci_execute($s,OCI_DEFAULT);
	if (!$result) {
		echo 'SQL:'.$sql;
	    echo 'Could not run query:' . oci_error();
	    exit;
	}	
	$row=oci_fetch_array($s,OCI_BOTH);
?>

<form name=fs action=att.php method=get>
<h2>major in <?=$row['CLASS_NAME']?></h2>
<?php	
	$query="SELECT lpad(student_no,8,'0') as sid ".
		"from students ".
		"where (class_major,class_year)=(($class_selected)) ".
		"order by student_no";
 	echo "<p><spen class=green>".$query."</span><p>"; ?>
Student ID: 
<select name='s'  onchange="fs.status.value='';fs.submit()">
<option value='0'>no student selected</option>
<?php
	$sql=oci_parse($conn,$query);
	$result=oci_execute($sql);
	while( $row=oci_fetch_array($sql,OCI_BOTH) )
	{
		echo "<option value='".$row['SID']."' ";
		if ( $row['SID']==$student_selected ) echo "selected";
		echo ">";
		echo $row['SID'];
		echo "</option>";
	}
?>
</select>
<input type=hidden name="status" value="absence">
<input type=hidden name="m" value="<?=$class_selected?>">
<a href="javascript:void(0)" onclick="fs.status.value='';fs.s.selectedIndex++;fs.submit();"><span class=red>[NEXT]</span></a>/<a href="javascript:void(0)" onclick="fs.status.value='';fs.s.selectedIndex+=Math.ceil(5*Math.random());fs.submit();"><span class=red>[RANDOM]</span></a>

<?php
	$query="SELECT lpad(student_no,8,'0') as sid,last_name||first_name as name,pinyin,status FROM students left join (attend a join lectures l on (a.lecture_no=l.lecture_no and trunc(lecture_date)=trunc(SYSDATE) )) using(student_no) where student_no=".$student_selected;
	echo "<p><spen class=green>".$query."</span><p>";
	$sql=oci_parse($conn,$query);
	if(!oci_execute($sql,OCI_DEFAULT)){
	    echo 'Could not run query:' . oci_error();
	    exit;
	}	
	$row=oci_fetch_array($sql,OCI_BOTH);
?>

<h1><font size=128px><?=$row['NAME']?></font></h1>
<h2><?=$row['PINYIN']?> <? if (isset($row['STATUS']) && $row['STATUS']!=NULL) echo " (".$row['STATUS'].")"; ?></h2>

<a href="javascript:void(0)" onclick="fs.status.value='leave';fs.submit();"><span class=red>[LEAVE]</span></a>
<a href="javascript:void(0)" onclick="fs.status.value='late';fs.submit();"><span class=red>[LATE]</span></a>
<a href="javascript:void(0)" onclick="fs.status.value='absence';fs.submit();"><span class=red>[ABSENCE]</span></a>
<a href="javascript:void(0)" onclick="fs.status.value='leave early';fs.submit();"><span class=red>[LEAVE EARLY]</span></a>
</form>
<?php 	oci_close($conn); ?>
</center></body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -