238 lines
6.6 KiB
PHP
238 lines
6.6 KiB
PHP
|
<?php
|
||
|
class User extends Database{
|
||
|
|
||
|
function __construct(){
|
||
|
$this->connect();
|
||
|
}
|
||
|
|
||
|
///user
|
||
|
//read
|
||
|
function login($username,$pass){
|
||
|
$pass = md5($pass);
|
||
|
$where = "username='$username' and password='$pass'";
|
||
|
if ($this->select('user','*',$where)){
|
||
|
$result = $this->getQueryResult();
|
||
|
if (mysql_num_rows($result)==1) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
}
|
||
|
//create
|
||
|
function register($data){
|
||
|
$value = array($data['user'],md5($data['pass']),$data['email']);
|
||
|
if ($this->insert('user',$value)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
|
||
|
///profil
|
||
|
//read
|
||
|
function cekProfil($data){
|
||
|
$where = "username='$data'";
|
||
|
if ($this->select('profile','*',$where)){
|
||
|
$result = $this->getQueryResult();
|
||
|
if (mysql_num_rows($result)==1) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
}
|
||
|
//create
|
||
|
function inputProfil($data){
|
||
|
//INSERT INTO profile VALUES()
|
||
|
$rows = 'nama,dob,telp,address,hometown,fakultas,jurusan,angkatan,kelas,relationship,username';
|
||
|
$value = array( $data['nama'],
|
||
|
$data['dob'],
|
||
|
$data['telp'],
|
||
|
$data['address'],
|
||
|
$data['hometown'],
|
||
|
$data['Fakultas'],
|
||
|
$data['Jurusan'],
|
||
|
$data['Angkatan'],
|
||
|
$data['Kelas'],
|
||
|
$data['relationship'],
|
||
|
$data['user']
|
||
|
);
|
||
|
if ($this->insert('profile',$value,$rows)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//update
|
||
|
function inputAvatar($foto,$id){
|
||
|
$where = "id='".$id."'" ;
|
||
|
//echo $where;
|
||
|
$rows = array( 'avatar' => $foto
|
||
|
);
|
||
|
if ($this->update('profile',$rows,$where))return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//update
|
||
|
function updateProfil($data){
|
||
|
//UPDATE profil SET column1=value,... WHERE username=''
|
||
|
$rows = array( 'nama' => $data['nama'],
|
||
|
'dob' => $data['dob'],
|
||
|
'telp' => $data['telp'],
|
||
|
'address' => $data['address'],
|
||
|
'hometown' => $data['hometown'],
|
||
|
'fakultas' => $data['fakultas'],
|
||
|
'jurusan' => $data['jurusan'],
|
||
|
'angkatan' => $data['angkatan'],
|
||
|
'kelas' => $data['kelas'],
|
||
|
'relationship' => $data['relationship']
|
||
|
);
|
||
|
$where = 'id = '.$data['id'];
|
||
|
if ($this->update('profile',$rows,$where)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//update
|
||
|
function updateProfil2($data){
|
||
|
//UPDATE profil SET column1=value,... WHERE username=''
|
||
|
$rows = array( 'nama' => $data['nama'],
|
||
|
'dob' => $data['dob'],
|
||
|
'address' => $data['address'],
|
||
|
'hometown' => $data['hometown'],
|
||
|
'fakultas' => $data['fakultas'],
|
||
|
'jurusan' => $data['jurusan'],
|
||
|
'angkatan' => $data['angkatan']
|
||
|
);
|
||
|
$where = 'id = '.$data['id'];
|
||
|
if ($this->update('profile',$rows,$where)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//read
|
||
|
function getProfil($id){
|
||
|
//SELECT * FROM profile WHERE username=''
|
||
|
$where = "username='".$id."'";
|
||
|
if ($this->select('profile','*',$where)){
|
||
|
return $this->getResult();
|
||
|
}
|
||
|
}
|
||
|
//delete
|
||
|
function delProfil($id){
|
||
|
//DELETE profil WHERE id='id'
|
||
|
$where="id='".$id."'";
|
||
|
if ($this->delete('profile',$where)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
|
||
|
///Post
|
||
|
//create
|
||
|
function writetowall($data){
|
||
|
$rows = 'status,user,toUser';
|
||
|
$value = array( $data['status'],
|
||
|
$data['user'],
|
||
|
$data['to']
|
||
|
);
|
||
|
if ($this->insert('post',$value,$rows)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//create
|
||
|
function insertPost($data){
|
||
|
$rows = 'status,user';
|
||
|
$value = array( $data['status'],
|
||
|
$data['user']
|
||
|
);
|
||
|
if ($this->insert('post',$value,$rows)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//read
|
||
|
function getStatus($id){
|
||
|
//SELECT * FROM post WHERE username=''
|
||
|
$where = "(post.User = '".$id."' AND profile.username = post.User AND post.toUser IS NULL) OR (post.toUser = '".$id."' AND profile.username = post.User)";
|
||
|
if ($this->select('post,profile','*',$where, $limit = null, 'date desc')){
|
||
|
return $this->getQueryResult();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
///Friend
|
||
|
//create
|
||
|
function addFriend($id){
|
||
|
$rows = 'user1,user2';
|
||
|
$value = array( $_SESSION['username'],
|
||
|
$id
|
||
|
);
|
||
|
if ($this->insert('friend',$value,$rows)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//update
|
||
|
function aproveFriend($id){
|
||
|
//UPDATE friend SET status=1 WHERE username=''
|
||
|
$rows = array( 'status' => 1);
|
||
|
$where = 'id='.$id;
|
||
|
if ($this->update('friend',$rows,$where)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//delete
|
||
|
function rejectFriend($id){
|
||
|
//DELETE friend WHERE id='id'
|
||
|
$where="id='".$id."'";
|
||
|
if ($this->delete('friend',$where)) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
//read
|
||
|
function statusFriend($id){
|
||
|
$where = "(user1 = '".$_SESSION['username']."' AND user2 = '".$id."') OR (user1 = '".$id."' AND user2 = '".$_SESSION['username']."')";
|
||
|
if ($this->select('friend','status',$where)){
|
||
|
$result = $this->getQueryResult();
|
||
|
$row = mysql_num_rows($result);
|
||
|
if($_SESSION['username']==$id)return 3;
|
||
|
elseif ($row==0)return 2;
|
||
|
else{
|
||
|
$data=mysql_fetch_assoc($result);
|
||
|
return $data['status'];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//read
|
||
|
function getFriend($id){
|
||
|
//SELECT user1,user2 FROM friend WHERE user1='' or user2=''
|
||
|
$where = "(user1 = '".$id."'OR user2 = '".$id."') AND (friend.user1=profile.username OR friend.user2=profile.username) AND status=1";
|
||
|
if ($this->select('friend,profile','profile.avatar,profile.username,profile.nama',$where)){
|
||
|
return $this->getQueryResult();
|
||
|
}
|
||
|
}
|
||
|
//read
|
||
|
function getcountfriend($id){
|
||
|
$q="SELECT COUNT(id) as total FROM friend WHERE (user1='".$id."' OR user2='".$id."') AND status=1";
|
||
|
$result = $this->query($q);
|
||
|
$data=mysql_fetch_assoc($result);
|
||
|
return $data['total'];
|
||
|
}
|
||
|
//read
|
||
|
function isFriend($id1,$id2){
|
||
|
$where = "((user1='".$id1."' and user2='".$id2."') or (user1='".$id2."' and user2='".$id1."')) and status=1";
|
||
|
if ($this->select('friend','*',$where)){
|
||
|
$result = $this->getQueryResult();
|
||
|
if (mysql_num_rows($result)==1) return true;
|
||
|
else return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
///community
|
||
|
//read
|
||
|
function getCommunity($id){
|
||
|
//SELECT community.name, member.role FROM member community WHERE username='' and community.id=member.id_community
|
||
|
$where = "member.username='".$id."' AND community.id=member.id_community";
|
||
|
if ($this->select('member,community','community.name, member.role, community.id, community.photo',$where)){
|
||
|
return $this->getQueryResult();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function Search($key){
|
||
|
//SELECT nama FORM profil WHERE nama=$key
|
||
|
$where = "nama LIKE '%".$key."%' or username LIKE '%".$key."%'";
|
||
|
if ($this->select('profile','nama,username,avatar,angkatan',$where,'0,3')){
|
||
|
$cari['user'] = $this->getQueryResult();
|
||
|
}
|
||
|
$where2 = "name LIKE '%".$key."%'";
|
||
|
if ($this->select('community','id,photo,description,name,type',$where2,'0,3')){
|
||
|
$cari['community'] = $this->getQueryResult();
|
||
|
}
|
||
|
return $cari;
|
||
|
}
|
||
|
|
||
|
function cari(){
|
||
|
if ($this->select('profile','nama,username,avatar')){
|
||
|
$cari['user'] = $this->getQueryResult();
|
||
|
}
|
||
|
return $cari;
|
||
|
}
|
||
|
}
|
||
|
?>
|