<?php
session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:../../404.php');
}else{
include_once '../../../po-library/po-database.php';
include_once '../../../po-library/po-function.php';

$val = new Povalidasi;
$mod=$_POST[mod];
$act=$_POST[act];

if ($mod=='setting' AND $act=='website_name'){
	$post = $val->validasi($_POST['post'],'xss');
	$data = array(
		'website_name' => $post
	);
	$table = new PoTable('setting');
	$table->updateBy('id_setting', '1', $data);
	echo "$post";
}
elseif ($mod=='setting' AND $act=='website_url'){
	$post = $val->validasi($_POST['post'],'xss');
	$data = array(
		'website_url' => $post
	);
	$table = new PoTable('setting');
	$table->updateBy('id_setting', '1', $data);
	echo "$post";
}
elseif ($mod=='setting' AND $act=='meta_description'){
	$post = $val->validasi($_POST['post'],'xss');
	$data = array(
		'meta_description' => $post
	);
	$table = new PoTable('setting');
	$table->updateBy('id_setting', '1', $data);
	echo "$post";
}
elseif ($mod=='setting' AND $act=='meta_keyword'){
	$post = $val->validasi($_POST['post'],'xss');
	$data = array(
		'meta_keyword' => $post
	);
	$table = new PoTable('setting');
	$table->updateBy('id_setting', '1', $data);
	echo "$post";
}
elseif ($mod=='setting' AND $act=='favicon'){
$extensionList = array("jpg", "png", "ico");
$fileName = $_FILES['fupload']['name'];
$tmpName  = $_FILES['fupload']['tmp_name'];
$fileType = $_FILES['fupload']['type'];
$fileSize = $_FILES['fupload']['size'];
$pecah = explode(".", $fileName);
$ekstensi = $pecah[1];
$nama_file = "favicon.";
$nama_file_unik = $nama_file.$ekstensi;
$namaDir = '../../../';
$pathFile = $namaDir . $nama_file_unik;

if (!empty($tmpName)){
	if (in_array($ekstensi, $extensionList)){
		$table = new PoTable('setting');
		$currentSearch = $table->findBy(id_setting, '1');
		$currentSearch = $currentSearch->current();
		$favicon = $currentSearch->favicon;
		unlink("../../../$favicon");
		move_uploaded_file($tmpName, $pathFile);
		$data = array(
			'favicon' => $nama_file_unik
		);
		$table->updateBy('id_setting', '1', $data);
		header('location:../../admin.php?mod='.$mod);
	}else{
		header('location:../../404.php');
	}
}else{
	header('location:../../404.php');
}
}
elseif ($mod=='setting' AND $act=='email'){
	$post = $val->validasi($_POST['post'],'xss');
	$data = array(
		'website_email' => $post
	);
	$table = new PoTable('setting');
	$table->updateBy('id_setting', '1', $data);
	echo "$post";
}
elseif ($mod=='setting' AND $act=='editor'){
	$localEditor = $_POST['editor'];
	setcookie('Popoji_CMS_Editor',$_POST['editor'],1719241200,'/');
	$_COOKIE['Popoji_CMS_Editor'] = $_POST['editor'];
	header('location:../../admin.php?mod='.$mod);
}
elseif ($mod=='setting' AND $act=='timezone'){
	$post = $val->validasi($_POST['timezone'],'xss');
	$data = array(
		'timezone' => $post
	);
	$table = new PoTable('setting');
	$table->updateBy('id_setting', '1', $data);
	header('location:../../admin.php?mod='.$mod);
}
elseif ($mod=='setting' AND $act=='editoauthfb'){
	$oauth_key = $_POST['oauth_key'];
	$oauth_secret = $_POST['oauth_secret'];
	$data = array(
		'oauth_key' => $oauth_key,
		'oauth_secret' => $oauth_secret
	);
	$table = new PoTable('oauth');
	$table->updateBy('id_oauth', '1', $data);
	header('location:../../admin.php?mod='.$mod);
}
elseif ($mod=='setting' AND $act=='editoauthtw'){
	$oauth_key = $_POST['oauth_key'];
	$oauth_secret = $_POST['oauth_secret'];
	$data = array(
		'oauth_key' => $oauth_key,
		'oauth_secret' => $oauth_secret
	);
	$table = new PoTable('oauth');
	$table->updateBy('id_oauth', '2', $data);
	header('location:../../admin.php?mod='.$mod);
}
elseif ($mod=='setting' AND $act=='deloauthfb'){
	$data = array(
		'oauth_key' => '',
		'oauth_secret' => '',
		'oauth_id' => '',
		'oauth_user' => '',
		'oauth_token1' => '',
		'oauth_token2' => '',
		'oauth_fbtype' => ''
	);
	$table = new PoTable('oauth');
	$table->updateBy('id_oauth', '1', $data);
	header('location:../../admin.php?mod='.$mod);
}
elseif ($mod=='setting' AND $act=='deloauthtw'){
	$data = array(
		'oauth_key' => '',
		'oauth_secret' => '',
		'oauth_id' => '',
		'oauth_user' => '',
		'oauth_token1' => '',
		'oauth_token2' => ''
	);
	$table = new PoTable('oauth');
	$table->updateBy('id_oauth', '2', $data);
	header('location:../../admin.php?mod='.$mod);
}
}
?>