first init

This commit is contained in:
alazhar
2020-01-02 21:48:25 +07:00
commit d286fda1df
97 changed files with 20403 additions and 0 deletions

View File

@ -0,0 +1,127 @@
<?php
//include('foto.php');
class Community extends Database{
function __construct(){
$this->connect();
}
///community
//create
function create($data){
//INSERT INTO community VALUES()
$rows = 'name,type,createdBy,description';
$value = array( $data['name'],
$data['type'],
$data['user'],
$data['desc']
);
if ($this->insert('community',$value,$rows))return true;
else return false;
}
//update
function inputPhotoComm($foto,$id){
$where = "id='".$id."'" ;
echo $where;
$rows = array( 'photo' => $foto
);
if ($this->update('community',$rows,$where))return true;
else return false;
}
//update
function updateComm($data){
//UPDATE community SET column1=value,... WHERE id_community=''
$rows = array( 'name' => $data['name'],
'description' => $data['desc'],
'photo' => $data['photo']
);
$where = 'id = '.$data['id'];
if ($this->update('community',$rows,$where)) return true;
else return false;
}
//read
function getComDesc($id){
//SELECT * FROM community WHERE id=''
$where = 'id='.$id;
if ($this->select('community','*',$where)){
return $this->getResult();
}
}
///member
//create
function inputMember($data){
//INSERT INTO member VALUES()
$rows = 'username,id_community,role';
$value = array( $data['user'],
$data['id_community'],
$data['role']
);
if ($this->insert('member',$value,$rows)) return true;
else return false;
}
//read
function getComMember($id){
//SELECT username FROM member WHERE id_community=''
$where = 'member.id_community='.$id.' and member.username=profile.username';
if ($this->select('member,profile','*',$where)){
return $this->getQueryResult();
}
}
//read
function ismember($idp,$idc){
$where = "username='".$idp."' and id_community='".$idc."'";
if ($this->select('member','*',$where)){
$result = $this->getQueryResult();
if (mysql_num_rows($result)==1) return true;
else return false;
}
}
///activities
//create
function createEvent($data){
//INSERT INTO activities VALUES()
$rows = 'name,type,desciption,date,community';
$value = array( $data['name'],
$data['type'],
$data['desc'],
$data['date'],
$data['community']
);
if ($this->insert('activities',$value,$rows)) return true;
else return false;
}
//update
function inputPhotoEve($foto,$id){
$where = "id='".$id."'" ;
echo $where;
$rows = array( 'poster' => $foto
);
if ($this->update('activities',$rows,$where))return true;
else return false;
}
//update
function updateEvent($data){
//UPDATE activities SET column1=value,... WHERE id_event=''
}
//read
function getEvent($id){
//SELECT * FROM activities WHERE community=''
$where = 'community='.$id;
if ($this->select('activities','*',$where)){
return $this->getQueryResult();
}
}
function getEvent2($id){
//SELECT * FROM activities WHERE community=''
$where = 'id='.$id;
if ($this->select('activities','*',$where)){
return $this->getResult();
}
}
}
?>

View File

@ -0,0 +1,34 @@
<?php
class Home extends Database{
function __construct(){
$this->connect();
}
function getAllmember(){
if ($this->select('profile','avatar,username',$where = null,'0,6')){
return $this->getQueryResult();
}
}
function getAllpost(){
$where='post.user = profile.username';
if ($this->select('profile,post','profile.avatar,post.status,profile.nama,post.date,profile.username,post.toUser',$where, $limit = null, 'date desc')){
return $this->getQueryResult();
}
}
function getAllcomm(){
if ($this->select('community','photo,id,type,name')){
return $this->getQueryResult();
}
}
function getNotiffriend(){
$where = "friend.user2='".$_SESSION['username']."' AND friend.status=0 AND friend.user1=profile.username";
if ($this->select('friend,profile','friend.id,profile.nama,profile.username',$where)){
return $this->getQueryResult();
}
}
}
?>

238
application/model/user.php Normal file
View File

@ -0,0 +1,238 @@
<?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;
}
}
?>