require_once '../cmanager_email.php';
    $message = $_POST['newcomment'];
    // update the request record
    $newrec = new stdClass();
    $newrec->id = $mid;
    $newrec->status = 'REQUEST DENIED';
    $DB->update_record('block_cmanager_records', $newrec);
    // Add a comment to the module
    $userid = $USER->id;
    $newrec = new stdClass();
    $newrec->instanceid = $mid;
    $newrec->createdbyid = $userid;
    $newrec->message = $message;
    $newrec->dt = date("Y-m-d H:i:s");
    $DB->insert_record('block_cmanager_comments', $newrec, false);
    $currentRecord = $DB->get_record('block_cmanager_records', array('id' => $mid));
    $requesterId = $currentRecord->createdbyid;
    // Store the ID of the person who made the request
    $replaceValues = array();
    $replaceValues['[course_code'] = $currentRecord->modcode;
    $replaceValues['[course_name]'] = $currentRecord->modname;
    //$replaceValues['[p_code]'] = $currentRecord->progcode;
    //$replaceValues['[p_name]'] = $currentRecord->progname;
    $replaceValues['[e_key]'] = '';
    $replaceValues['[full_link]'] = $CFG->wwwroot . '/blocks/cmanager/comment.php?id=' . $mid;
    $replaceValues['[loc]'] = '';
    $replaceValues['[req_link]'] = $CFG->wwwroot . '/blocks/cmanager/view_summary.php?id=' . $mid;
    block_cmanager_send_deny_email_user($message, $requesterId, $mid, $replaceValues);
    block_cmanager_send_deny_email_admin($message, $mid, $replaceValues);
    echo "<script> window.location = '../cmanager_admin.php';</script>";
}
                //$replaceValues['[p_name]'] = $currentRecord->progname;
                $replaceValues['[e_key]'] = '';
                $replaceValues['[full_link]'] = $CFG->wwwroot . '/blocks/cmanager/comment.php?id=' . $cid;
                $replaceValues['[loc]'] = '';
                $replaceValues['[req_link]'] = $CFG->wwwroot . '/blocks/cmanager/view_summary.php?id=' . $cid;
                // update the request record
                $newrec = new stdClass();
                $newrec->id = $cid;
                $newrec->status = 'REQUEST DENIED';
                $DB->update_record('block_cmanager_records', $newrec);
                // Add a comment to the module
                $userid = $USER->id;
                $newrec = new stdClass();
                $newrec->instanceid = $cid;
                $newrec->createdbyid = $userid;
                $newrec->message = $message;
                $newrec->dt = date("Y-m-d H:i:s");
                $DB->insert_record('block_cmanager_comments', $newrec);
                block_cmanager_send_deny_email_admin($message, $cid, $replaceValues);
                block_cmanager_send_deny_email_user($message, $userid, $cid, $replaceValues);
                $_SESSION['mul'] = '';
            }
        }
        echo "<script> window.location = '../cmanager_admin.php';</script>";
    } else {
        $mform->focus();
        $mform->set_data($mform);
        $mform->display();
        echo $OUTPUT->footer();
    }
}