<?php
	require_once('source/session.php');
	require_once('source/error.php');
	require_once('source/dbconfig.php');
	require_once('source/function.php');
	require_once('source/restrict_admin.php');
	
	if(isset($_POST['post_subject']))
	{
		try {
			$subject	= strip_tags($_POST['subject']);
			
			
			$STH 				= $DBH->prepare("SELECT count(*) FROM tbl_subject WHERE subject = ?");
			$result 	   		= $STH->execute(array($subject));
			$count	  	= $STH->fetchColumn();
			if($count > 0){
			sql($DBH, "UPDATE tbl_subject set subject = ? WHERE subject = ? ", array($subject));
			redirect('post_subjects.php?msg=post');
			exit;
			}else{
			sql($DBH, "INSERT INTO tbl_subject (subject) VALUES (?)", array($subject));
			redirect('post_subjects.php?msg=post');
			exit;
			}
		}
		catch(PDOException $e) { 
			file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); # Errors Log File
				redirect('post_subject.php?msg=failed');
		}
	}
	else
	{
				redirect('compose_email.php?msg=failed');
	}
?>