 |
|
โค๊ดยาวหน่อยนะครับ พอดีโดนสั่งงานเป็นแบบคลาสอ่ะคับ แล้วเขียนครั้งแรกเลย งงๆครับ
หรือถ้าไงมีแนวดีๆสั้นๆช่วยแนะนำด้วยนะครับ ขอบคุณล่วงหน้า
-------------------------------login--------------------------------------------
Code (PHP)
<?php
@session_start();
if(session_is_registered("s_id"));
{
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
</style>
<script language="JavaScript">
function CheckData(form)
{
if (form.per_id.value == "")
{ alert("àÁÔ§äÁèä´éãÊèª×èÍ"); form.per_id.focus(); return; }
else if (form.per_passwd.value == "")
{ alert("àÁÔ§ãÊèÅ×Á¾ÒÊ"); form.per_passwd.focus(); return; }
else form.submit()
}
</script>
<meta name="generator" content="Namo WebEditor(Trial)"></head>
/
<body>
<?
include_once("connect.php");
?>
<form id="loginform" name="loginform" method="post" action="check.php" target="_top">
<table align="center">
<tr>
<td><table width="438" border="0" align="center" cellpadding="3" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#CCCCCC">
<tr>
<td colspan="2" bgcolor="#FFFFFF"><div align="center">เข้าสู่ระบบ</div></td>
</tr>
<tr>
<td width="205" bgcolor="#FFFFFF"> <div align="right" class="style18">
<span class="style19"><span class="style11 style13 style19">ชื่อผู้ใช้งาน</span> :</span></div>
</td>
<td width="218" bgcolor="#FFFFFF"><div align="left">
<input type="text" name="per_id" />
</div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><div align="right" class="style18"><span class="style19"><span class="style11 style13 style19">รหัสผ่าน</span> :</span></div></td>
<td bgcolor="#FFFFFF"><div align="left">
<input type="password" name="per_passwd" />
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2"><div align="center">
<input name="button" type="button" style="cursor:hand" title="ล็อกอินเข้าสู่ระบบ" onclick="CheckData(loginform)" value="ตกลง" border="0" />
</div></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>
<?
}
?>
-----------------------------------------------check------------------------------------------------
Code (PHP)
<?php
@session_start();
include("connect.php");
include("class/clsPerson.php");
$plogin = new Person();
$plogin->RSlogin($per_id,$per_passwd); // *** ตรวจสอบความถูกต้องของ User และ Password
$numrows=$plogin->NumRow(); // *** นับจำนวนแถว เพื่อตรวจสอบว่าพบหรือไม่
while($plogin->GetRecord()){ // >>> ตรวจสอบข้อมูล ***
$s_id=$plogin->per_id;
$s_name=$plogin->per_name;
$s_lassname=$plogin->per_lasname;
}
session_register("s_id"); // *** ค่ารหัสผู้ใช้
session_register("s_name"); // *** ค่าชื่อผู้ใช้
session_register("s_lasname"); // *** ค่านามสกุลผู้ใช้
if($numrows==0){ // *** ไม่พบข้อมูล
echo "<script language='javascript'> alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง'); window.history.back(); </script>";
echo"</center>";
?>
<meta http-equiv="refresh" content="2;url=index.php">
<?
}
else if($plogin->per_status=="2"){
echo "<script language='javascript'> alert('ผู้ใช้งานถูกระงับการใช้ระบ'); window.history.back(); </script>";
echo"</center>";
}
// *** พบข้อมูล
else{
$plogin->RSstatus($s_id); // *** ตรวจสอบความถูกต้องของ รหัสผู้ใช้กับตำแหน่ง
$rows=$plogin->NumRow(); // *** นับจำนวนแถว เพื่อตรวจสอบว่ามีกี่แถว
$id=1;
while($plogin->GetRecord()){ // >>> ตรวจสอบข้อมูล กำหนดค่าของตำแหน่ง ***
if($id==1){ // *** ตำแหน่งที่ 1
$sp_pid1=$plogin->position_id; // *** ค่าของตำแหน่งที่ 1
$p_name1=$plogin->position_name; // *** ค่าของชื่อตำแหน่งที่ 1
}
$id=$id+1;
}
if($rows==1){ // *** ผุ้ใช้มี 1 ตำแหน่ง
$number_pos=$rows;
session_register("number_pos"); // *** จำนวนตำแหน่งงาน
session_register("sp_pid1"); // *** ค่าตำแหน่งของผู้ใช้ที่ 1
session_register("p_name1"); // *** ชื่อตำแหน่งของผู้ใช้ที่ 1
if($sp_pid1==1){
echo"</center>";
?>
<meta http-equiv="refresh" content="1;url=index_member.html">
<?
}
else if($sp_pid1==2){
echo"</center>";
?>
<meta http-equiv="refresh" content="1;url=index_owner.html">
<?
}
else if($sp_pid1==3){
echo"</center>";
?>
<meta http-equiv="refresh" content="1;url=index_admin.html">
<?
}
}
}
$plogin->DisConnect();
?>
---------------------------------------------------------clsPerson------------------------------------------------------
Code (PHP)
<?php
class Person{
var $dbms;
var $result;
var $status;
var $per_id;
var $per_name;
var $per_lasname;
var $per_address;
var $per_phone;
var $positon_id;
var $per_user;
var $per_passwd;
var $per_status;
function Person(){
$this->dbms=new dbase;
}
function Delete(){
$this->status = 0;
}
function AddNew(){
$this->status=1;
}
function Edit(){
$this->status=2;
}
function Save(){
if($this->status=='1'){
$sql="insert into person values('$this->per_id','$this->per_name','$this->per_lasname','$this->per_address','$this->per_phone','$this->position_id','$this->per_user','$this->per_passwd','$this->per_status')";
}
else if($this->status == '0')
{
$sql = "delete from person where per_id = '$this->per_id'";
// echo $sql;
}else if($this->status=='2'){
if($this->per_image == ""){ // แก้ไขข้อมูล
$sql="update person set per_id='$this->per_id',
per_name='$this->per_name'
per_lasname='$this->per_lasname'
per_address='$this->per_address'
per_phone='$this->per_phone'
position_id='$this->position_id'
per_iser'$this->per_user'
per_password'$this->per_passwd'
per_status'$this->per_status'
where per_id='$this->per_id'";
}
else{ // แก้ไขข้อมูล
$sql="update per set per_id='$this->per_id',
per_name='$this->per_name'
per_lasname='$this->per_lasname'
per_address='$this->per_address'
per_phone='$this->per_phone'
position_id='$this->position_id'
per_iser'$this->per_user'
per_password'$this->per_passwd'
per_status'$this->per_status')
where per_id='$this->per_id'";
}
}
$this->dbms->SetQuery($sql);
}
function GetNextCode() {
//GetMaxIDเป็นฟังก์ชั่นที่รีเทิร์นค่าสูงสุดของตารางให้
$this->dbms->SetQuery("Select Max(per_id) as per_id from person ");
$this->GetRecord();
$code=substr("$this->per_id",1)+1;
return "E" .substr("000$code",-4,4);
}
function RSlogin($per_id,$per_passwd){
//$this->dbms->SetQuery("select * from person where per_id='$per_id' and per_passwd='$per_passwd'");
}
function RSper($per_id){
$this->dbms->SetQuery("select * from person where per_id='$per_id' ");
}
function RSloginper($login,$password){
$this->dbms->SetQuery("select * from person where per_id='$login' and per_passwd='$password'");
}
function RSstus($c_id){
$this->dbms->SetQuery("select * from person where per_id='$c_id'");
}
function PassGetRecord(){
//PassGetRecord เป็นฟังก์ชั่นนำค่าที่ได้จากการเอ็กซีคิวมากำหนดค่าให้กับตัวแปรของคลาส
if($this->result=$this->dbms->GetResult()){
$this->per_passwd=$this->result['per_passwd'];
return 1;
}else{
return 0;
}
}
function ChangPass($per_id,$per_passwd) {
$sql = "update person set per_passwd='$per_passwd' where per_id='$per_id' ";
$this->dbms->SetQuery($sql);
}
//**************************************************************************//
function RSstatus($s_id){
$this->dbms->SetQuery("select person.per_id , person.position_id , position.position_id , position.position_name from position left join person on position.position_id = person.position_id where per_id='$s_id'");
}
function SelectPerson(){
$this->dbms->SetQuery("select * from person order by per_id asc");
}
function NumRow(){
return $this->dbms->GetRow();
}
function SPerson($s_id){
// รีเทิร์นข้อมูลให้เป็นกลุ่มข้อมูลจากการเอ็กซีคิวคำสั่ง
$this->dbms->SetQuery("select * from person where per_id ='$s_id' ");
}
function GetRecord(){
if($this->result=$this->dbms->GetResult()){
$this->per_id=$this->result['per_id'];
$this->per_name= $this->result['per_name'];
$this->per_lasname= $this->result['per_lasname'];
$this->per_address= $this->result['per_address'];
$this->per_phone= $this->result['per_phone'];
$this->position_id=$this->result['position_id'];
$this->per_user= $this->result['per_user'];
$this->per_passwd=$this->result['per_passwd'];
$this->per_status=$this->result['per_status'];
return 1;
}
else{
return 0;
}
}
// ค้นหาข้อมูล
function Search1($per_name){
if($this->dbms->SetQuery("select * from person where per_name='$per_name'")){
return 1;
}
else{
return 0;
}
}
function Search($per_id){
if($this->dbms->SetQuery("select * from person where per_id='$per_id'")){
return 1;
}else{
return 0;
}
}
function SearchByID($per_search,$txtsearch){
// RStteacherinfoเป็นฟังก์ชั่นที่รีเทิร์นข้อมูลให้เป็นกลุ่มข้อมูลจากการเอ็กซีคิวคำสั่ง
$this->dbms->SetQuery("select * from person where $per_search like '%$txtsearch%' order by per_id ");
}
function SearchName($txtsearch){
$this->dbms->SetQuery("select * from person where per_name LIKE '%$txtsearch%'");
}
function GetNumRow(){
//GetCountIDเป็นฟังก์ชั่นที่รีเทิร์นค่าสูงสุดของตารางให้
$this->dbms->SetQuery("select count(per_id) as per_id from person ");
if($result = $this->dbms->GetResult()) {
return $result['per_id'];
}
}
function RSPerson2($PageSt,$PerPg){
// RStteacherinfoเป็นฟังก์ชั่นที่รีเทิร์นข้อมูลให้เป็นกลุ่มข้อมูลจากการเอ็กซีคิวคำสั่ง
$this->dbms->SetQuery("select * from person order by per_id limit $PageSt,$PerPg");
}
function PSPgSearch($type_search,$txtsearch,$PageSt,$PerPg){
$this->dbms->SetQuery("select * from person where $type_search like '%$txtsearch%' order by per_id limit $PageSt,$PerPg");
}
function PSPg($PageSt,$PerPg){
$this->dbms->SetQuery("select * from person order by per_id limit $PageSt,$PerPg");
}
//จบการคำนวณเรคคอร์ด
function RSBYPerson($per_search,$txtsearch){
$this->dbms->SetQuery("select * from person where $per_search like '%$txtsearch%' ");
}
function Query($con, $where){
$r= $this->dbms->SetQuery("$con $where");
}
function DisConnect(){
return $this->dbms->DisConnect();
}
}
?>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-09-20 04:51:56 |
By :
zadaharu |
View :
1021 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |