<?php	if(!defined('_source')) die("Error");

$act = (isset($_REQUEST['act'])) ? addslashes($_REQUEST['act']) : "";

switch($act){
	case "capnhat":
	get_gioithieu();
	$template = "setting/item_add";
	break;
	case "save":
	save_gioithieu();
	break;

	default:
	$template = "index";
}

function get_gioithieu(){
	global $d, $item;

	$sql = "select * from #_setting limit 0,1";
	$d->query($sql);
	//if($d->num_rows()==0) transfer("Dữ liệu chưa khởi tạo.", "index.php");
	$item = $d->fetch_array();
}

function save_gioithieu(){
	global $d,$config_lang;
	$file_name=images_name($_FILES['file']['name']);
	if(empty($_POST)) transfer("Không nhận được dữ liệu", "index.php?com=setting&act=capnhat");

	if($photo = upload_image("file", 'jpg|png|gif|JPG|jpeg|JPEG', _upload_hinhanh,$file_name)){
		$data['photo'] = $photo;	
	}
	
	foreach($config_lang as $key => $value){
		$data['ten_'.$key] = $_POST['ten_'.$key];
		$data['slogan_'.$key] = $_POST['slogan_'.$key];
		$data['diachi_'.$key] = $_POST['diachi_'.$key];
	}

	$data['sang'] = $_POST['sang'];
	$data['chieu'] = $_POST['chieu'];
	$data['chunhat'] = $_POST['chunhat'];
	$data['tenph'] = $_POST['tenph'];
	$data['dienthoaiph'] = $_POST['dienthoaiph'];
	$data['emailph'] = $_POST['emailph'];
	$data['tenmamnon'] = $_POST['tenmamnon'];
	$data['tenngoaingu'] = $_POST['tenngoaingu'];
	$data['tenbrain'] = $_POST['tenbrain'];
	$data['linkmamnon'] = $_POST['linkmamnon'];
	$data['linkngoaingu'] = $_POST['linkngoaingu'];
	$data['linkbrain'] = $_POST['linkbrain'];
	$data['datve'] = $_POST['datve'];
	upload_image("dongdau", 'png', '../upload/','watermark');


	$data['dienthoai'] = $_POST['dienthoai'];
	$data['email'] = $_POST['email'];
	$data['website'] = $_POST['website'];
	
	$data['facebook'] = $_POST['facebook'];
	$data['twitter'] = $_POST['twitter'];
	$data['google'] = $_POST['google'];
	$data['youtube'] = $_POST['youtube'];
	$data['zalo'] = $_POST['zalo'];
	$data['skype'] = $_POST['skype'];
	$data['hotline'] = $_POST['hotline'];
	$data['hotline2'] = $_POST['hotline2'];
	$data['facebook2'] = $_POST['facebook2'];
	$data['twitter2'] = $_POST['twitter2'];
	$data['google2'] = $_POST['google2'];
	$data['youtube2'] = $_POST['youtube2'];
	$data['zalo2'] = $_POST['zalo2'];
	$data['skype2'] = $_POST['skype2'];


	$data['toado'] = magic_quote($_POST['toado']);
	$data['toado1'] = $_POST['toado1'];
	$data['toado2'] = $_POST['toado2'];
	
	$data['sanpham'] = $_POST['sanpham'];
	
	$data['scriptcode'] = magic_quote($_POST['scriptcode']);
	$data['bodycode'] = magic_quote($_POST['bodycode']);
	$data['title'] = $_POST['title'];
	$data['keywords'] = $_POST['keywords'];
	$data['description'] = $_POST['description'];							

	$d->reset();
	$d->setTable('setting');
	if($d->update($data))
		header("Location:index.php?com=setting&act=capnhat");
	else
		transfer("Cập nhật dữ liệu bị lỗi", "index.php?com=setting&act=capnhat");
}

?>