-
Notifications
You must be signed in to change notification settings - Fork 1
/
classes.php
131 lines (113 loc) · 3.32 KB
/
classes.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
<?php
class Database
{
function __construct(){
$this->connstring = "dbname=bt773 user=bt773 password=bt773";
$this->connection = pg_connect( "$this->connstring" ) or die("Connection failed: " . pg_last_error());
}
function queryTable($query){
$this->connection = pg_connect( "$this->connstring" ) or die("Connection failed: " . pg_last_error());
$result = pg_query($query) or die("Query failed: " . pg_last_error());
$fetch = pg_fetch_all($result);
return $fetch;
}
function queryArray($query){
$this->connection = pg_connect( "$this->connstring" ) or die("Connection failed: " . pg_last_error());
$result = pg_query($query) or die("Query failed: " . pg_last_error());
$fetch = pg_fetch_assoc($result);
return $fetch;
}
public function queryTrueFalse($query){
$this->connection = pg_connect( "$this->connstring" ) or die("Connection failed: " . pg_last_error());
$result = pg_query($query) or die("Query failed: " . pg_last_error());
$fetch = pg_fetch_row($result);
if ($fetch[0] == 't') {
return TRUE;
}
else{
return FALSE;
}
}
private $connstring;
private $connection;
}
class User
{
public function __construct($username, $password, $db){
$this->conn = $db;
$this->user = pg_escape_string($username);
if ($this->userAuth($this->user, $password)){
$this->isLoggedIn = TRUE;
}
}
private function userAuth($username, $password){
return $this->query( "select authUser('$username','$password');", "boolean" );
}
public function getInfo(){
$result = $conn->queryArray( "select * from users_public where username='$username';" ); echo "test";
foreach( $result as $data )
{
echo "field: $data<br/>";
}
}
public function getName(){
return $this->user;
}
public function isLoggedIn(){
return $this->isLoggedIn;
}
public function upProf($username, $name, $location, $lang, $prefCsv){
$this->updateProfile($username, $name, $location, $lang, $prefCsv);
}
private function updateProfile($username, $name, $location, $lang, $prefCsv){
echo "in updateProfile()";
echo "$username | $name | $location | $lang | $prefCsv ";
var_dump($this->conn);
$status = $this->conn->queryTrueFalse(
"select updateprofile('$username','$name','$location','$lang','$prefCsv');"
);
return $status;
}
public function sendMessage($otherUser, $text){
echo "here1";
echo $otherUser->getName();
$user2 = $otherUser->$user;
echo "here2";
$result = $conn->queryTrueFalse( "select messageUser( '$user', '$user2', '$text' ");
if( $result == "f" )
{
die("Message send failed from: $user to: $user2" );
}
}
public function getMessages($otherUser){
$user2 = $otherUser->$user;
$result = $conn->queryTable( "select * from users_message_users where (username1='$user' and username2='$user2') or (username2='$user' and username1='$user2');" );
echo "<table>";
foreach( $result as $row )
{
echo "<tr>";
foreach( $row as $col )
{
echo "<td>$col</td>";
}
echo "</tr>";
}
echo "</table>";
}
public function query($query, $type){
if ($type == "table"){
return $this->conn->queryTable($query);
}
elseif($type == "array"){
return $this->conn->queryArray($query);
}
elseif($type == "boolean"){
return $this->conn->queryTrueFalse($query);
}
else return NULL;
}
private $user;
private $conn;
private $isLoggedIn = FALSE;
}
?>