if ($gid == 0) {
    unset($gid);
}
$guidelinesDAO = new GuidelinesDAO();
$guidelineGroupsDAO = new GuidelineGroupsDAO();
$guidelineSubgroupsDAO = new GuidelineSubgroupsDAO();
$subgroupChecksDAO = new SubgroupChecksDAO();
// handle submits
if (isset($_POST['cancel'])) {
    $msg->addFeedback('CANCELLED');
    header('Location: index.php');
    exit;
} else {
    if (isset($_POST['save_no_close']) || isset($_POST['save_and_close']) || $_POST['javascript_submit']) {
        if (isset($gid)) {
            $guidelinesDAO->update($gid, $_POST['user_id'], $_POST['title'], $_POST['abbr'], $_POST['long_name'], $_POST['published_date'], $_POST['earlid'], '', $_POST['status'], $_POST['open_to_public']);
        } else {
            $gid = $guidelinesDAO->Create($_SESSION['user_id'], $_POST['title'], $_POST['abbr'], $_POST['long_name'], $_POST['published_date'], $_POST['earlid'], '', $_POST['status'], $_POST['open_to_public']);
            if (intval($gid) == 0) {
                unset($gid);
            }
        }
        if (!$msg->containsErrors()) {
            // add checks
            if (is_array($_POST['add_checks_id'])) {
                $guidelinesDAO->addChecks($gid, $_POST['add_checks_id']);
            }
            $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
        }
        if (isset($_POST['save_and_close'])) {
            header('Location: index.php');