forked from xTraRice/RiceCalc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.class.php
More file actions
137 lines (123 loc) · 3.2 KB
/
user.class.php
File metadata and controls
137 lines (123 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
session_start();
error_reporting(E_ALL);
ini_set( 'display_errors','1');
$db = new PDO("mysql:host=localhost;dbname=ricecalcdb","root","sniper");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
class user{
function __construct(){
//-- Construct ? --
}
function register($username,$password,$fn,$ln,$em,$contact){
global $db;
if($this->checkDup($username)){
return 99;
}else{
$s = $db->prepare("INSERT INTO irri_users (username, password, first_name, last_name, email, contact) VALUES (?,?,?,?,?,?)");
$arr = array($username,md5($password),$fn,$ln,$em,$contact);
$e = $s->execute($arr);
if($e === false):
return 0;;
else:
return 1;
endif;
}
}
function login($uName, $pass){
global $db;
$s = $db->prepare("SELECT * FROM irri_users WHERE userName=?");
$arr = array($uName);
$e = $s->execute($arr);
$f = $s->fetch();
if($f['password'] == md5($pass)){
$_SESSION['logged']=true;
$_SESSION['username'] = $f['username'];
$_SESSION['name'] = $f['first_name']." ".$f['last_name'];
return 1;
}else{
return 0;
}
}
function checkDup($username){
global $db;
$s = $db->prepare("SELECT * FROM irri_users WHERE userName=?");
$arr = array($username);
$e = $s->execute($arr);
if($s->rowCount > 0){
return 1;
}else{
return 0;
}
}
function logout(){
session_destroy();
foreach($_SESSION as $key=>$value){
unset($_SESSION['key']);
}
header("Location: index.php");
exit();
}
function checkAuth(){
return isset($_SESSION['name'])?1:0;
}
function changePassword($user, $password){
global $db;
$s = $db->prepare("SELECT * FROM irri_users WHERE username=?");
$arr = array($user);
$e = $s->execute($arr);
$f = $s->fetch();
if(md5($password) == $f['password']){
if(updatePass($user,$pass)){
return 1;
}else{
return 0;
}
}
}
function updatePass($user, $pass){
global $db;
$s = $db->prepare("UPDATE irri_users SET password=? WHERE username=?");
$arr = array(md5($pass),$user);
$e = $s->execute($arr);
if($e === false){
return 0;
}else{
return 1;
}
}
function getVariety($in){
global $db;
$s = $db->prepare("SELECT variety,averageYield,maxYield,maturity,height,tillers,id FROM rice_varieties WHERE ecosystem=?");
$arr = array($in);
$e = $s->execute($arr);
if($s->rowCount() > 0){
return $s->fetchAll();
}else{
return 0;
}
}
function getAllVariety(){
global $db;
$s = $db->prepare("SELECT variety,averageYield,maxYield,maturity,height,tillers,id FROM rice_varieties");
$e = $s->execute();
if($s->rowCount() > 0){
return $s->fetchAll();
}else{
return 0;
}
}
function getItemInfo($id){
global $db;
$s = $db->prepare("SELECT variety,averageYield,maxYield,maturity,height,tillers,blast,blb,tungro,bph,glh,stemborerDH,stemborerDHWSB,deadheartswhiteWSB,YSB FROM rice_varieties WHERE id=?");
$arr = array($id);
$e = $s->execute($arr);
if($s->rowCount() > 0){
return $s->fetch();
}else{
return 0;
}
}
}
?>