<?php

include_once $_SERVER['DOCUMENT_ROOT'] . '/../inc/application_top.php';
// Create the category class
$myCategory = new Category();
try {
    // If they are saving the Information
    if ($_POST['submit'] == 'save') {
        // Get all the Form Data
        $myCategory->SetValues($_POST);
        $myCategory->SetValue('user_id', $myUser->GetPrimary());
        // Save the Make
        if ($myCategory->Save()) {
            SetAlert('Category Successfully Saved.', 'success');
            LogAction('Saved Category: ' . stripslashes($myCategory->GetValue('category')), 1);
            header('location:' . PATH . 'categories');
            die;
        }
    }
    // If Deleting
    if ($_POST['submit'] == 'delete') {
        $myCategory->SetValues($_POST);
        $name = stripslashes($myCategory->GetValue('category'));
        // Remove from the DB
        if (!$myCategory->Delete()) {
            throw new SimplException('Error deleting from the database, please try again.');
        }
        // Everything went fine
        SetAlert('Category Deleted Successfully', 'success');
        LogAction('Deleted Category: ' . $name, 1);
        header('location:' . PATH . 'categories');