165 lines
4.0 KiB
PHP
165 lines
4.0 KiB
PHP
|
<?php
|
||
|
include('application/config/config.php');
|
||
|
include('application/model/user.php');
|
||
|
include('func.php');
|
||
|
include('foto.php');
|
||
|
session_start();
|
||
|
|
||
|
//route
|
||
|
if( !isset($_SESSION['username'])){ //if not login
|
||
|
header('Location: index.php');
|
||
|
$_SESSION['alert']='Anda Harus Login Terlebih Dahulu';
|
||
|
}
|
||
|
|
||
|
if (isset($_GET['action'])){
|
||
|
switch($_GET['action']){
|
||
|
case 'update' :
|
||
|
update();
|
||
|
break;
|
||
|
case 'addfriend' :
|
||
|
if (isset($_GET['idprf'])){
|
||
|
addFriend($_GET['idprf']);
|
||
|
}
|
||
|
break;
|
||
|
case 'edit' :
|
||
|
if($_SESSION['username']==$_GET['id']){
|
||
|
$data = editProfile($_GET['id']);
|
||
|
include(view_file.'register.php');
|
||
|
}else header('Location: home.php');
|
||
|
break;
|
||
|
case 'cedit' :
|
||
|
cedit();
|
||
|
break;
|
||
|
case 'ajaxedit' :
|
||
|
ajaxedit();
|
||
|
break;
|
||
|
default :
|
||
|
echo not_found;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
elseif (isset($_GET['id'])){
|
||
|
$id = $_GET['id'];
|
||
|
$data = profile($id);
|
||
|
include(view_file.'profile.php');
|
||
|
}
|
||
|
else{
|
||
|
echo not_found;
|
||
|
}
|
||
|
|
||
|
//function
|
||
|
function profile($id){
|
||
|
$u = new User();
|
||
|
$data['info'] = $u->getProfil($id);
|
||
|
$data['info']['Fakultas'] = cvFakultas($data['info']['Fakultas']);
|
||
|
//all status
|
||
|
$data['post'] = $u->getStatus($id);
|
||
|
//count friend
|
||
|
$data['cFriend'] = $u->getcountfriend($id);
|
||
|
//list friend
|
||
|
$data['Friend'] = $u->getFriend($id);
|
||
|
//status friend
|
||
|
$a = $u->statusFriend($id);
|
||
|
if ($a<3){
|
||
|
if ($a==0)$data['sFriend']='Request Sent';
|
||
|
elseif ($a==1)$data['sFriend']='Friend';
|
||
|
else $data['sFriend']='Add Friend';
|
||
|
}
|
||
|
//community joined
|
||
|
$data['comm'] = $u->getCommunity($id);
|
||
|
|
||
|
//buat cek database error
|
||
|
unset($_SESSION['notif-warning']);
|
||
|
//$_SESSION['notif-warning'] = $u->getSqlerr();
|
||
|
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
function addFriend($id){
|
||
|
$u = new User();
|
||
|
if ($u->addFriend($id))header('Location: profile.php?id='.$id);
|
||
|
else echo 'gagal';
|
||
|
}
|
||
|
|
||
|
function update(){
|
||
|
$u = new User();
|
||
|
$data = array( 'status' => $_POST['status'],
|
||
|
'user' => $_SESSION['username']
|
||
|
);
|
||
|
if (isset($_POST['idu']))$data['to'] = $_POST['idu'];
|
||
|
if(empty($data['to'])){
|
||
|
if ($u->insertPost($data))header('Location: profile.php?id='.$_SESSION['username']);
|
||
|
else echo 'gagal';
|
||
|
}else{
|
||
|
if ($u->writetowall($data))header('Location: profile.php?id='.$data['to']);
|
||
|
else echo 'gagal';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function editProfile($id){
|
||
|
$u = new User();
|
||
|
return $u->getProfil($id);
|
||
|
}
|
||
|
|
||
|
function cedit(){
|
||
|
$u = new User();
|
||
|
$data = array( 'nama' => $_POST['name'],
|
||
|
'dob' => date("Y-m-d",strtotime($_POST['dob'])),
|
||
|
'telp' => $_POST['telp'],
|
||
|
'address' => $_POST['address'],
|
||
|
'hometown' => $_POST['hometown'],
|
||
|
'fakultas' => $_POST['fakultas'],
|
||
|
'jurusan' => $_POST['jurusan'],
|
||
|
'angkatan' => $_POST['angkatan'],
|
||
|
'kelas' => $_POST['kelas'],
|
||
|
'relationship' => $_POST['relati'],
|
||
|
'user' => $_SESSION['username'],
|
||
|
'id' => $_POST['idprof']
|
||
|
);
|
||
|
if ($u->updateProfil($data)){
|
||
|
//echo ' insert bisa ';
|
||
|
unset($_SESSION['notif-alert']);
|
||
|
if (!empty($_FILES['file']['name'])){
|
||
|
$foto = new Foto($_FILES);
|
||
|
if ($foto->update($_SESSION['username'])){
|
||
|
$hasil = $foto->getHasil();
|
||
|
$photo = $hasil['lokasi'];
|
||
|
//echo $photo;
|
||
|
if($u->inputAvatar($photo,$_POST['idprof']))header('Location: profile.php?id='.$_SESSION['username']);
|
||
|
}else {
|
||
|
$_SESSION['notif-alert'] = 'Foto yang anda Masukkan Salah';
|
||
|
header('Location: profile.php?action=edit&id='.$_SESSION['username']);
|
||
|
}
|
||
|
}
|
||
|
else header('Location: profile.php?id='.$_SESSION['username']);
|
||
|
}
|
||
|
else{
|
||
|
$_SESSION['notif-alert'] = 'Periksa kembali inputan';
|
||
|
header('Location: profile.php?action=edit&id='.$_SESSION['username']);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function isFriend($id1,$id2){
|
||
|
$u = new User();
|
||
|
return $u->isFriend($id1,$id2);
|
||
|
|
||
|
}
|
||
|
|
||
|
function ajaxedit(){
|
||
|
$data = array( 'nama' => $_POST['name'],
|
||
|
'dob' => date("Y-m-d",strtotime($_POST['dob'])),
|
||
|
'address' => $_POST['address'],
|
||
|
'hometown' => $_POST['hometown'],
|
||
|
'fakultas' => $_POST['fakultas'],
|
||
|
'jurusan' => $_POST['jurusan'],
|
||
|
'angkatan' => $_POST['angkatan'],
|
||
|
'user' => $_SESSION['username']
|
||
|
);
|
||
|
$u = new User();
|
||
|
if ($u->updtae($data))echo 'sukses';
|
||
|
}
|
||
|
|
||
|
function singleupdate($row){
|
||
|
|
||
|
}
|
||
|
?>
|