<?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_pin']))
	{
		try {
			$pin	= strip_tags($_POST['pin']);
			
			
			$STH 				= $DBH->prepare("SELECT count(*) FROM tbl_pin WHERE pin = ?");
			$result 	   		= $STH->execute(array($pin));
			$count	  	= $STH->fetchColumn();
			if($count > 0){
			sql($DBH, "UPDATE tbl_class set class = ?, subclass =? WHERE class = ? ", array($class,$subclass,$class));
			redirect('post_classes.php?msg=post');
			exit;
			}else{
			sql($DBH, "INSERT INTO tbl_pin (pin) VALUES (?)", array($token));
			redirect('post_pin.php?msg=post');
			exit;
			}
		}
		catch(PDOException $e) { 
			file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND); # Errors Log File
				redirect('post_classes.php?msg=failed');
		}
	}
	else
	{
				redirect('compose_email.php?msg=failed');
	}
?>