/**
 * Update the existing enrollment with an SQL Update
 */
function update_enrollment($enrollmentId, $data)
{
    global $wpdb;
    //$wpdb->show_errors();
    foreach ($data as $key => $value) {
        if (needs_encryption($key)) {
            $value = db_aes_encrypt($value);
        } else {
            $value = db_normal_field($value);
        }
        $values[] = "`" . $key . "` = " . $value;
    }
    $sql = "UPDATE enrollment set " . implode($values, ", ") . " where id = " . $enrollmentId;
    error_log($sql);
    $wpdb->query($sql);
}
$isCompletedUpload = isset($_REQUEST['uploadComplete']);
$isLookup = isset($_REQUEST['lEnrollmentId']);
$isLoad = isset($_REQUEST['uid']);
if ($isLoad && !$isReview && !$isUpload) {
    $enrollment = retrieve_enrollment_by_uid($_REQUEST['uid']);
    if ($enrollment) {
        $currentStep = $enrollment->step + 1;
        $enrollmentId = $enrollment->id;
        $_SESSION['enrollment_step'] = $currentStep;
        $_SESSION['enrollmentId'] = $enrollment->id;
    }
} else {
    if ($isLookup) {
        $enrollmentId = intval($_REQUEST['lEnrollmentId']);
        global $wpdb;
        $qry = "select uid from enrollment where id=" . $enrollmentId . " and ssn=" . db_aes_encrypt($_REQUEST["lSsn"]);
        $uid = $wpdb->get_var($qry);
        if ($uid == null) {
            header('Location: /enrollment-not-found');
        } else {
            header('Location: ?uid=' . $uid . '&enrollmentId=' . $enrollmentId);
        }
        die;
    } else {
        if ($isSubmission) {
            /* Send email */
            $enrollmentId = intval($_REQUEST['enrollmentId']);
            $enrollment = retrieve_enrollment($enrollmentId);
            $headers = 'From: info@assistwireless.com' . "rn" . 'Reply-To: info@assistwireless.com' . "rn" . 'X-Mailer: PHP/' . phpversion();
            //neworders@assistwireless.com
            mail("*****@*****.**", "Assist Sign-Up", "Account #" . $enrollment->id . " was just signed up on the Assist Wireless web site.", $headers);