-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_class.php
138 lines (119 loc) · 3.23 KB
/
admin_class.php
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
138
<?php
session_start();
ini_set('display_errors', 1);
Class Action {
private $db;
public function __construct() {
ob_start();
include './lib/dbh.php';
$this->db = $conn;
}
function __destruct() {
$this->db->close();
ob_end_flush();
}
function login(){
extract($_POST);
$qry = $this->db->query("SELECT *,concat(lastname,', ',firstname,' ',middlename) as name FROM clients where (email = '".$uid."' OR contact = '".$uid."') and password = '".md5($password)."' ");
if($qry->num_rows > 0){
foreach ($qry->fetch_array() as $key => $value) {
if($key != 'password' && !is_numeric($key))
$_SESSION['user_'.$key] = $value;
}
$uip=$_SERVER['REMOTE_ADDR'];
$log = $this->db->query("INSERT INTO clientLog (client,ip)VALUES('$uid','$uip')");
return 1;
}else{
return 3;
}
}
function logout(){
session_destroy();
foreach ($_SESSION as $key => $value) {
date_default_timezone_set('Africa/Nairobi');
$ldate=date("Y-m-d H:i:s");
$log = $this->db->query("UPDATE clientLog SET logout = '$ldate' WHERE client = '".$_SESSION['user_email']."' ORDER BY id DESC LIMIT 1");
unset($_SESSION[$key]);
}
header("location:login.php");
}
function save_client(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass')) && !is_numeric($k)){
if($k =='password')
$v = md5($v);
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$check = $this->db->query("SELECT * FROM clients where email ='$email' ".(!empty($id) ? " and id != {$id} " : ''))->num_rows;
if($check > 0){
return 2;
}
if(empty($id)){
$save = $this->db->query("INSERT INTO clients set $data");
}else{
$save = $this->db->query("UPDATE clients set $data where id = $id");
}
if($save){
return 1;
}
}
function update_user(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id','cpass','table')) && !is_numeric($k)){
if($k =='password')
$v = md5($v);
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
$check = $this->db->query("SELECT * FROM clients where email ='$email' ".(!empty($id) ? " and id != {$_SESSION['user_id']} " : ''))->num_rows;
if($check > 0){
return 2;
}
if(empty($id)){
$save = $this->db->query("INSERT INTO clients set $data");
}else{
$save = $this->db->query("UPDATE clients set $data where id ={$_SESSION['user_id']}");
}
if($save){
foreach ($_POST as $key => $value) {
if($key != 'password' && !is_numeric($key))
$_SESSION['login_'.$key] = $value;
}
return 1;
}
}
function save_loan(){
extract($_POST);
$data = "";
foreach($_POST as $k => $v){
if(!in_array($k, array('id')) && !is_numeric($k)){
if(empty($data)){
$data .= " $k='$v' ";
}else{
$data .= ", $k='$v' ";
}
}
}
if(empty($id)){
$save = $this->db->query("INSERT INTO loan_list set $data");
}else{
$save = $this->db->query("UPDATE loan_list set $data where id = $id");
}
if ($save) {
return 1;
}
}
}