SOCMED/community.php

139 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2020-01-02 21:48:25 +07:00
<?php
include('application/config/config.php');
include('application/model/community.php');
include('application/model/home.php');
include('foto.php');
include('func.php');
session_start();
//cek session
//route
if (isset($_GET['id']) && !isset($_GET['action'])){
$id = $_GET['id'];
$data = comm($id);
include(view_file.'community2.php');
}
else if (isset($_GET['action'])){
switch($_GET['action']){
//community
case 'create':
include(view_file.'createcommunity.php');
break;
case 'createAction':
addCommunity();
break;
case 'update':
echo "update";
break;
//event
case 'createEvent':
if (isset($_GET['id']))include(view_file.'createevent.php');
else echo not_found;
break;
case 'createEventAction':
addEvent();
break;
default:
echo not_found;
break;
}
}
else if (isset($_GET['event'])){
$data = event($_GET['event']);
include(view_file.'event.php');
}
else{
$data = commlist();
include(view_file.'communitylist.php');
}
//function
function addCommunity(){
$comm = new Community();
$data = array( 'name' => $_POST['name'],
'type' => $_POST['type'],
'location' => $_POST['location'],
'user' => $_SESSION['username'],
'desc' => $_POST['desc']
);
if ($comm->create($data)){
//echo ' insert bisa ';
$idp = $comm->getId();
mkdir(user_file . $idp, 0700);
//mkdir(user_file . $idp, 0777);
foreach($_POST['select3'] as $value){
$data['id_community'] = $idp;
$data['user'] = $value;
$data['role'] = 'Anggota';
$comm->inputmember($data);
}
if (!empty($_FILES['file']['name'])){
$foto = new Foto($_FILES);
$foto->insert($idp);
$hasil = $foto->getHasil();
$photo = $hasil['lokasi'];
//echo $photo;
if($comm->inputPhotoComm($photo,$idp))header('Location: community.php?id='.$idp);
else echo '</br> gagal foto';
}
header('Location: community.php?id='.$idp);
}
else echo '</br> gagal';
}
function updateCommunity(){
}
function comm($id){
$c = new Community();
$data['desc'] = $c->getComDesc($id);
//print_r($data['desc']);
$data['member'] = $c->getComMember($id);
$data['event'] = $c->getEvent($id);
$data['cEvent'] = mysql_num_rows($data['event']);
return $data;
}
function commlist(){
$h = new Home();
$data = $h->getAllcomm();
return $data;
}
function ismember($idp,$idc){
$c = new Community();
return $c->ismember($idp,$idc);
}
function event($id){
$comm = new Community();
return $comm->getEvent2($id);
}
function addEvent(){
$comm = new Community();
$data = array( 'name' => $_POST['name'],
'type' => $_POST['type'],
'desc' => $_POST['desc'],
'date' => $_POST['date'],
'community' => $_POST['idc']
);
if ($comm->createEvent($data)){
//echo ' insert bisa ';
$idp = $comm->getId();
if (!empty($_FILES['file']['name'])){
$foto = new Foto($_FILES);
$foto->insert($_POST['idc'],'Ev '.$_POST['name']);
$hasil = $foto->getHasil();
$photo = $hasil['lokasi'];
//echo $photo;
if($comm->inputPhotoEve($photo,$idp))header('Location: community.php?event='.$idp);
else echo '</br> gagal foto';
}
}
else echo '</br> gagal';
}
?>