function editVehicleComplaint()
{
    $table = "complaint";
    $cond = "`complaint_no` = " . $_POST["complaintNumber"];
    $paid = $warranty = 0;
    if ($_POST["cr_txtrtype_edit"] == "1") {
        $paid = 1;
    } else {
        $warranty = 1;
    }
    $col_val = "`model` = '" . htmlspecialchars($_POST['cr_txtModel_edit'], ENT_QUOTES) . "',`veh_reg_no` = '" . htmlspecialchars($_POST['cr_txtregno_edit'], ENT_QUOTES) . "',`frame_vin_no` = '" . htmlspecialchars($_POST['cr_txtVinno_edit'], ENT_QUOTES) . "',`engine_no` = '" . htmlspecialchars($_POST['cr_txtEngno_edit'], ENT_QUOTES) . "',`date_of_sale` = '" . htmlspecialchars($_POST['cr_txtDOP_edit'], ENT_QUOTES) . "',`km_reading` = '" . htmlspecialchars($_POST['cr_txtKMR_edit'], ENT_QUOTES) . "',`warranty` = '" . $warranty . "',`paid` = '" . $paid . "'";
    if (updaterecs($table, $col_val, $cond)) {
        $arr = array('status' => 1, 'message' => 'Success');
    } else {
        $arr = array('status' => 0, 'message' => 'Failure');
    }
    echo json_encode($arr);
}
function insertUpdate($table, $cols, $vals, $compField, $compCond)
{
    if (singlefield($compField, $table, $compCond)) {
        // echo $compField.",".$compCond;
        $col_val = arrayToQuery($cols, $vals);
        if (updaterecs($table, $col_val, $compCond)) {
            $arr = array('status' => 1, 'message' => 'Sync Success', 'sync_time' => date("d/m/Y h:i:sa"));
        } else {
            $arr = array('status' => 0, 'message' => 'Sync Failure. Please try again');
        }
    } else {
        $fields = rtrim(implode(',', $cols), ',');
        $vals = rtrim(implode(',', $vals), ',');
        if (insertrec($table, $fields, $vals)) {
            $arr = array('status' => 1, 'message' => 'Sync Success', 'sync_time' => date("d/m/Y h:i:sa"));
        } else {
            $arr = array('status' => 0, 'message' => 'Sync Failure. Please try again');
        }
    }
    return $arr;
}
function update_profile_details()
{
    $name = $_POST['name'];
    $update_name = 0;
    $uploadOk = 1;
    if ($name && strlen($name) < 8 && strcmp($name, $_SESSION['name']) && ctype_alnum($name)) {
        $update_name = 1;
    } else {
        $update_name = 0;
    }
    //Update profile name
    if ($update_name) {
        $row = "name = " . '"' . $name . '"';
        $cond = "Email=" . $_SESSION['email'];
        updaterecs('users', $row, $cond);
        $_SESSION['name'] = $name;
        $pname_errmsg = "Profile Name Changed Successfully";
    } else {
        $pname_errmsg = 'Failure';
    }
    if (is_uploaded_file($_FILES['imgfile']['tmp_name'])) {
        $target_dir = "../services/";
        $target_file = $target_dir . basename($_FILES["imgfile"]["name"]);
        $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
        $check = getimagesize($_FILES["imgfile"]["tmp_name"]);
        if ($check !== false) {
            $msg = "File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            $msg = "Please upload valid image file";
            $uploadOk = 0;
        }
        // Check file size
        if ($_FILES["imgfile"]["size"] > 500000) {
            $msg = "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        // Allow certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG") {
            $msg = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
        $sourcePath = $_FILES['imgfile']['tmp_name'];
        $targetPath = $target_file;
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            if (!$msg) {
                $msg = "Sorry, your file was not uploaded.";
            }
            // if everything is ok, try to upload file
        } else {
            $temp = explode(".", $_FILES["imgfile"]["name"]);
            //                $newfilename = '../services/'.substr($_SESSION['profile_image'], 0, -4 ) . '.' . end($temp);
            $newfilename = '../services/' . $_SESSION['profile_image'];
            $img = substr($_SESSION['profile_image'], 0, -4) . '.' . end($temp);
            if (move_uploaded_file($sourcePath, $newfilename)) {
                $_SESSION['profile_image'] = $img;
                $msg = "Profile image changed successfully";
            } else {
                $msg = "Sorry, there was an error uploading your file.";
            }
        }
    } else {
        if (!$msg) {
            $msg = "Failure";
        }
    }
    $str = '{';
    $str .= '"pname_errmsg" : "' . $pname_errmsg . '",';
    $str .= '"msg" : "' . $msg . '"';
    $str .= '}';
    echo $str;
}