function updateRequestStatus()
{
    $userRequestID = trim($_REQUEST['user_request_id']);
    $requestStatus = trim($_REQUEST['status']);
    $lastInserted_payment_id = 0;
    $rm = new Response_Methods();
    if ($userRequestID == "" || $requestStatus == "") {
        $result = $rm->fields_validation();
        return $result;
    } else {
        if ($requestStatus == 'Accepted') {
            $fromBankID = $rm->idToValue('payment_from_bank_id', 'user_requests_t', 'user_request_id', $userRequestID);
            $toBankID = $rm->idToValue('payment_to_bank_id', 'user_requests_t', 'user_request_id', $userRequestID);
            $amount = $rm->idToValue('amount', 'user_requests_t', 'user_request_id', $userRequestID);
            $fromBankBalance = $rm->idToValue('initial_bank_balance', 'bank_details_t', 'bank_id', $fromBankID);
            $toBankBalance = $rm->idToValue('initial_bank_balance', 'bank_details_t', 'bank_id', $toBankID);
            if ($fromBankBalance < $amount) {
                $result = $rm->insufficient_balance();
                return $result;
            } else {
                if ($fromBankID != $toBankID) {
                    $fromBankBalance = $fromBankBalance - $amount;
                    $toBankBalance = $toBankBalance + $amount;
                }
                $updateFromBankBalance['initial_bank_balance'] = $fromBankBalance;
                $affectedRowsFrom = $rm->update_record($updateFromBankBalance, 'bank_details_t', 'bank_id', $fromBankID);
                $updateToBankBalance['initial_bank_balance'] = $toBankBalance;
                $affectedRowsTo = $rm->update_record($updateToBankBalance, 'bank_details_t', 'bank_id', $toBankID);
                $getInsertFieldValue['amount'] = $amount;
                $getInsertFieldValue['payment_from_bank_id'] = $fromBankID;
                $getInsertFieldValue['payment_to_bank_id'] = $toBankID;
                $getInsertFieldValue['user_request_id'] = $userRequestID;
                $lastInserted_payment_id = $rm->insert_record($getInsertFieldValue, 'payment_details_t');
                $login_user_id = $rm->idToValue('login_user_id', 'user_requests_t', 'user_request_id', $userRequestID);
                $gcm_regid = $rm->getUserGCMREGID($login_user_id);
                if ($gcm_regid != "" || $gcm_regid != "NA") {
                    $gcm = new GCM();
                    $registatoin_ids = array($gcm_regid);
                    $msg = "Request " . $requestStatus;
                    $message = array("Response" => $msg);
                    $resultPush = $gcm->send_notification($registatoin_ids, $message);
                }
                $getRegisterFieldValue['status'] = $requestStatus;
                $affectedRows = $rm->update_record($getRegisterFieldValue, 'user_requests_t', 'user_request_id', $userRequestID);
                if ($affectedRows >= 0) {
                    $result = $rm->requestStatusSuccess($lastInserted_payment_id);
                    return $result;
                } else {
                    $result = $rm->requestStatusFail();
                    return $result;
                }
            }
        }
    }
}
예제 #2
0
function editUserDetails()
{
    //$companyId = $_REQUEST['companyId'];
    $userFname = trim($_REQUEST['userFname']);
    $userLname = trim($_REQUEST['userLname']);
    $age = trim($_REQUEST['age']);
    $sex = trim($_REQUEST['sex']);
    $emailId = trim($_REQUEST['emailId']);
    $address = trim($_REQUEST['address']);
    $userType = trim($_REQUEST['userType']);
    $userID = trim($_REQUEST['userID']);
    /*
    $userImage = trim($_REQUEST['image']);		
    $userImage = trim($_REQUEST['image']['name']);		
    */
    $adminId = $_REQUEST['adminId'];
    $adminId = 'e-002';
    // need to be send in request..for time being using hardcoded values.
    $fullName = $userFname . ' ' . $userLname;
    //$Mobile = $_REQUEST['Phone'];
    $rm = new Response_Methods();
    if ($userFname == "" || $userLname == "" || $age == "" || $sex == "" || $emailId == "" || $address == "" || $userType == "" || $userID == "") {
        $result = $rm->fields_validation();
        return $result;
    } else {
        date_default_timezone_set('Asia/Calcutta');
        $createdDate = date('Y-m-d H:i:s');
        $getRegisterFieldValue['user_fname'] = $userFname;
        $getRegisterFieldValue['user_lname'] = $userLname;
        $getRegisterFieldValue['user_age'] = $age;
        $getRegisterFieldValue['user_sex'] = $sex;
        $getRegisterFieldValue['user_email_id'] = $emailId;
        $getRegisterFieldValue['user_address'] = $address;
        $getRegisterFieldValue['last_modified_date'] = $createdDate;
        //$lastInserted_user_id=$rm->insert_record($getRegisterFieldValue,'user_details_t');
        $affectedRows = $rm->update_record($getRegisterFieldValue, 'user_details_t', 'user_id', $userID);
        if ($affectedRows >= 0) {
            $result = $rm->userModifiedSuccess();
            return $result;
        } else {
            $result = $rm->userModifiedFail();
            return $result;
        }
    }
}
function updateComment()
{
    $rm = new Response_Methods();
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        $result = $rm->inValidServerMethod();
        return $result;
    }
    //Check request url is https or not
    if (!empty($_SERVER["HTTPS"])) {
        if ($_SERVER["HTTPS"] !== "off") {
            $comment = $rm->cleanData($_POST['comment']);
            //Get Request From Device
            $commentId = $rm->cleanData($_POST['commentId']);
            $getArrayList = array();
            //echo $ENCRYPTEDPWD = md5($PASSWORD);
            //echo $ENCRYPTEDPWD = base64_decode($PASSWORD);
            //$ENCRYPTEDPWD=$PASSWORD;
            if ($comment == "" || $commentId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $getInsertFieldValue['comment_text_f'] = $comment;
                $affectedRowsUpdateComment = $rm->update_record($getInsertFieldValue, 'comments_t', 'comment_id', $commentId);
                if ($affectedRowsUpdateComment > 0) {
                    $result = $rm->updateCommentSuccessJson($commentId);
                    return $result;
                } else {
                    $result = $rm->updateCommentFailJson();
                    return $result;
                }
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function changeLikeStatus()
{
    $rm = new Response_Methods();
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        $result = $rm->inValidServerMethod();
        return $result;
    }
    //Check request url is https or not
    if (!empty($_SERVER["HTTPS"])) {
        if ($_SERVER["HTTPS"] !== "off") {
            $postId = trim($_POST['postId']);
            //Get Request From Device
            $getArrayList = array();
            if ($postId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $getUpdateLike['like_status_f'] = "0";
                $updateResult = $rm->update_record($getUpdateLike, 'likes_t', 'post_id_fk', $postId);
                if ($updateResult) {
                    $result = $rm->changeLikeStatusSuccess();
                    return $result;
                } else {
                    $result = $rm->changeLikeStatusFail();
                    return $result;
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function addNewsFeeds()
{
    $rm = new Response_Methods();
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        $result = $rm->inValidServerMethod();
        return $result;
    }
    //Check request url is https or not
    if (!empty($_SERVER["HTTPS"])) {
        if ($_SERVER["HTTPS"] !== "off") {
            $userId = trim($_POST['userId']);
            $post_image = trim($_POST['post_image']);
            $post_description = $rm->cleanData(trim($_POST['post_description']));
            $location_lat = $rm->cleanData(trim($_POST['location_lat']));
            $location_lang = $rm->cleanData(trim($_POST['location_lang']));
            if ($userId == "" || $post_description == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                date_default_timezone_set('Asia/Calcutta');
                $createdDate = date('Y-m-d H:i:s');
                $getList = array();
                //preparing list and inserting values in news_feed_table table
                $getInsertFieldValue['user_id_fk'] = $userId;
                //$getInsertFieldValue['post_image_f']=$post_image;
                $getInsertFieldValue['post_description_f'] = $post_description;
                $getInsertFieldValue['location_lang_f'] = $location_lang;
                $getInsertFieldValue['location_lat_f'] = $location_lat;
                $getInsertFieldValue['post_date_f'] = $createdDate;
                $lastInserted_post_id = $rm->insert_record($getInsertFieldValue, 'news_feeds_t');
                if (!empty($lastInserted_post_id)) {
                    $IMAGEURLBASEURL = BASEURL . '/images/';
                    $userImageBaseURL = "images/{$username}";
                    $username = $rm->idToValue('user_name_f', 'user_details_t', 'user_id', $userId);
                    $userImageBaseURL = "images/{$username}";
                    if (!is_dir($userImageBaseURL)) {
                        //mkdir - tells that need to create a directory
                        mkdir($userImageBaseURL);
                        mkdir($userImageBaseURL . '/profile_pics/');
                        mkdir($userImageBaseURL . '/post_photos/');
                    }
                    $rand = rand(00, 99999);
                    $img = 'data:image/png;base64,' . $post_image . '';
                    $img = str_replace('data:image/png;base64,', '', $img);
                    $img = str_replace(' ', '+', $img);
                    $data = base64_decode($img);
                    $image = 'post_photos' . $rand . '.png';
                    file_put_contents($userImageBaseURL . '/post_photos/' . $image, $data);
                    //file_put_contents($userImageBaseURL.'/profile_pics/'.$image, $data);
                    $IMAGEURL = $IMAGEURLBASEURL . $username . '/post_photos/' . $image;
                    $dimensions = $rm->getImageDimensions($data);
                    $getUpdatePostPic['image_width_f'] = $dimensions["width"];
                    $getUpdatePostPic['image_height_f'] = $dimensions["height"];
                    $thumbNames = $rm->createThumbs($data, $userImageBaseURL, $image, 'news_feed_post');
                    $getUpdatePostPic['thumb1'] = $thumbNames[0]['filename'];
                    $getUpdatePostPic['thumb2'] = $thumbNames[1]['filename'];
                    $getUpdatePostPic['thumb3'] = $thumbNames[2]['filename'];
                    $getUpdatePostPic['thumb4'] = $thumbNames[3]['filename'];
                    $getUpdatePostPic['thumb5'] = $thumbNames[4]['filename'];
                    $getUpdatePostPic['ipad_portrait_width'] = $thumbNames[3]['width'];
                    $getUpdatePostPic['ipad_portrait_height'] = $thumbNames[3]['height'];
                    $getUpdatePostPic['ipad_landscape_width'] = $thumbNames[4]['width'];
                    $getUpdatePostPic['ipad_landscape_height'] = $thumbNames[4]['height'];
                    $getUpdatePostPic['post_image_f'] = $IMAGEURL;
                    $updateResult = $rm->update_record($getUpdatePostPic, 'news_feeds_t', 'post_id', $lastInserted_post_id);
                    //$result=$rm->getPosts($userId);
                    $result = $rm->postCreationSuccessJson();
                    return $result;
                } else {
                    $result = $rm->postCreationFailJson();
                    return $result;
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
예제 #6
0
function signUpProfile()
{
    $rm = new Response_Methods();
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        $result = $rm->inValidServerMethod();
        return $result;
    }
    //Check request url is https or not
    if (!empty($_SERVER["HTTPS"])) {
        if ($_SERVER["HTTPS"] !== "off") {
            $username = $rm->cleanData(trim($_POST['username']));
            $password = $rm->cleanData(trim($_POST['password']));
            $email = trim($_POST['email']);
            $deviceId = trim($_POST['deviceId']);
            $petType = $rm->cleanData(trim($_POST['petType']));
            $petBio = $rm->cleanData(trim($_POST['petBio']));
            $petName = $rm->cleanData(trim($_POST['petName']));
            $petDob = trim($_POST['petDob']);
            $petSpecies = $rm->cleanData(trim($_POST['petSpecies']));
            $notifyEvents = $rm->cleanData(trim($_POST['notifyEvents']));
            $profileId = $rm->rand_str(16, 4);
            if ($username == "" || $password == "" || $email == "" || $petType == "" || $petBio == "" || $petName == "" || $petDob == "" || $petSpecies == "" || $notifyEvents == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $checkUser = $rm->checkUserValidation($username, 'user_name_f');
                $checkEmail = $rm->checkUserValidation($email, 'email_f');
                if ($checkUser == 0) {
                    $result = $rm->userExistJson();
                    return $result;
                }
                if ($checkEmail == 0) {
                    $result = $rm->emailExistJson();
                    return $result;
                }
                $status = 0;
                date_default_timezone_set('Asia/Calcutta');
                $createdDate = date('Y-m-d H:i:s');
                $getList = array();
                //preparing list and inserting values in user_details table
                $getInsertFieldValue['user_name_f'] = $username;
                $getInsertFieldValue['email_f'] = $email;
                $getInsertFieldValue['device_id_f'] = $deviceId;
                $getInsertFieldValue['profile_id_f'] = $profileId;
                $getInsertFieldValue['join_date_f'] = $createdDate;
                $getInsertFieldValue['pet_type_f'] = $petType;
                $getInsertFieldValue['pet_name_f'] = $petName;
                $getInsertFieldValue['pet_dob_f'] = $petDob;
                $getInsertFieldValue['description_f'] = $petBio;
                $getInsertFieldValue['species_f'] = $petSpecies;
                $getInsertFieldValue['notify_events_f'] = $notifyEvents;
                $lastInserted_user_id = $rm->insert_record($getInsertFieldValue, 'user_details_t');
                if (!empty($lastInserted_user_id)) {
                    //preparing list and inserting values in login table
                    $getInsertLoginDetails['password_f'] = $password;
                    $getInsertLoginDetails['user_name_f'] = $username;
                    $getInsertLoginDetails['user_id_fk'] = $lastInserted_user_id;
                    $lastInserted_login_id = $rm->insert_record($getInsertLoginDetails, 'login_t');
                    if (empty($lastInserted_login_id)) {
                        $rm->delete('user_details_t', 'user_id', $lastInserted_user_id);
                        $result = $rm->userRegisterFailJson();
                        return $result;
                    }
                    //preparing list and inserting values in friends table
                    $getInsertFriendDetails['friend_one'] = $lastInserted_user_id;
                    $getInsertFriendDetails['friend_two'] = $lastInserted_user_id;
                    $getInsertFriendDetails['created_date_f'] = $createdDate;
                    $getInsertFriendDetails['status'] = 2;
                    $lastInserted_friend_id = $rm->insert_record($getInsertFriendDetails, 'friends_t');
                    if (empty($lastInserted_friend_id)) {
                        $rm->delete('login_t', 'login_id', $lastInserted_login_id);
                        $rm->delete('user_details_t', 'user_id', $lastInserted_user_id);
                        $result = $rm->userRegisterFailJson();
                        return $result;
                    }
                    $IMAGEURLBASEURL = BASEURL . '/images/';
                    $userImageBaseURL = "images/{$username}";
                    if (!is_dir($userImageBaseURL)) {
                        //mkdir - tells that need to create a directory
                        mkdir($userImageBaseURL);
                        mkdir($userImageBaseURL . '/profile_pics/');
                        mkdir($userImageBaseURL . '/post_photos/');
                    }
                    $rand = rand(00, 99999);
                    if (isset($_POST['profile_pic']) and $_POST['profile_pic'] != "") {
                        $profile_pic = trim($_POST['profile_pic']);
                        //blob image data
                        $img = 'data:image/png;base64,' . $profile_pic . '';
                        $img = str_replace('data:image/png;base64,', '', $img);
                        $img = str_replace(' ', '+', $img);
                        $data = base64_decode($img);
                        $image = 'petbestie_user_' . $rand . '.png';
                        file_put_contents($userImageBaseURL . '/profile_pics/' . $image, $data);
                        //file_put_contents($userImageBaseURL.'/profile_pics/'.$image, $data);
                        $IMAGEURL = $IMAGEURLBASEURL . $username . '/profile_pics/' . $image;
                        $getUpdateProfilePic['profile_pic_f'] = $IMAGEURL;
                    } else {
                        $getUpdateProfilePic['profile_pic_f'] = "null";
                    }
                    $updateResult = $rm->update_record($getUpdateProfilePic, 'user_details_t', 'user_id', $lastInserted_user_id);
                    $result = $rm->userRegisterSuccessJson($lastInserted_user_id);
                    return $result;
                } else {
                    $result = $rm->userRegisterFailJson();
                    return $result;
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function addPaymentDetails()
{
    //$companyId = $_REQUEST['companyId'];
    $companyID = trim($_REQUEST['companyID']);
    $fromBankID = trim($_REQUEST['fromBankID']);
    $toBankID = trim($_REQUEST['toBankID']);
    //$paymentDate = trim($_REQUEST['paymentDate']);
    $paymentReason = trim($_REQUEST['paymentReason']);
    $amount = trim($_REQUEST['amount']);
    $paymentType = trim($_REQUEST['paymentType']);
    $userType = trim($_REQUEST['userType']);
    $userID = trim($_REQUEST['userID']);
    $user_request_id = trim($_REQUEST['user_request_id']);
    $payment_id = trim($_REQUEST['payment_id']);
    // in case of user
    $affectedRowsPayment = -1;
    $rm = new Response_Methods();
    if ($companyID == "" || $fromBankID == "" || $paymentReason == "" || $amount == "" || $paymentType == "") {
        $result = $rm->fields_validation();
        return $result;
    } else {
        date_default_timezone_set('Asia/Calcutta');
        $createdDate = date('Y-m-d H:i:s');
        $getList = array();
        $mailData["paymentDetails"] = array();
        //inserting payment details
        $getInsertFieldValue['company_id'] = $companyID;
        $getInsertFieldValue['payment_from_bank_id'] = $fromBankID;
        $getInsertFieldValue['payment_to_bank_id'] = $toBankID;
        //$getInsertFieldValue['payment_date']=$paymentDate;
        $getInsertFieldValue['payment_reason'] = $paymentReason;
        $getInsertFieldValue['login_user_id'] = $userID;
        $getInsertFieldValue['amount'] = $amount;
        $getInsertFieldValue['payment_type'] = $paymentType;
        $getInsertFieldValue['payment_created_date'] = $createdDate;
        $checkRecords = mysql_query("SELECT user_request_id FROM user_requests_t WHERE user_request_id='{$user_request_id}'");
        $checkRecords = mysql_num_rows($checkRecords);
        if ($userType == 'Admin') {
            $checkRecords = 1;
        }
        if ($checkRecords > 0) {
            if (strtolower($userType) == "user") {
                $affectedRowsPayment = $rm->update_record($getInsertFieldValue, 'payment_details_t', 'payment_id', $payment_id);
            } else {
                if (strtolower($userType) == "admin") {
                    $lastInserted_payment_id = $rm->insert_record($getInsertFieldValue, 'payment_details_t');
                }
            }
            $mailData = $getInsertFieldValue;
            $mailData['userID'] = $userID;
            //array_push($mailData["paymentDetails"], $getInsertFieldValue);
            if (!empty($lastInserted_payment_id)) {
                //Do Transactions by updating banks current balance
                $fromBankBalance = $rm->idToValue('initial_bank_balance', 'bank_details_t', 'bank_id', $fromBankID);
                $toBankBalance = $rm->idToValue('initial_bank_balance', 'bank_details_t', 'bank_id', $toBankID);
                if ($fromBankBalance < $amount) {
                    $result = $rm->insufficient_balance();
                    return $result;
                }
                if ($fromBankID != $toBankID) {
                    $fromBankBalance = $fromBankBalance - $amount;
                    $toBankBalance = $toBankBalance + $amount;
                }
                $updateFromBankBalance['initial_bank_balance'] = $fromBankBalance;
                $affectedRowsFrom = $rm->update_record($updateFromBankBalance, 'bank_details_t', 'bank_id', $fromBankID);
                $updateToBankBalance['initial_bank_balance'] = $toBankBalance;
                $affectedRowsTo = $rm->update_record($updateToBankBalance, 'bank_details_t', 'bank_id', $toBankID);
            }
            //check payment type and insert details accordingly(cheque/net)
            if (strtolower($paymentType) == "cheque") {
                //insert cheque details
                $mailData["chequeDetails"] = array();
                if (!empty($lastInserted_payment_id)) {
                    $payment_id_inserted = $lastInserted_payment_id;
                } else {
                    $payment_id_inserted = $payment_id;
                }
                $getChequeDetails['payment_id'] = $payment_id_inserted;
                $getChequeDetails['cheque_number'] = trim($_REQUEST['chequeNo']);
                $getChequeDetails['cheque_date'] = trim($_REQUEST['chequeDate']);
                $getChequeDetails['to_whom_issued'] = trim($_REQUEST['chequeIssued']);
                //$getChequeDetails['cheque_amount']=trim($_REQUEST['chequeAmount']);
                $getChequeDetails['cheque_amount'] = $amount;
                $getChequeDetails['cheque_created_date'] = $createdDate;
                $lastInserted_cheque_id = $rm->insert_record($getChequeDetails, 'cheque_details_t');
                array_push($mailData["chequeDetails"], $getChequeDetails);
            } else {
                if (strtolower($paymentType) == "net") {
                    //insert NET Banking Details
                    $mailData["netDetails"] = array();
                    if (!empty($lastInserted_payment_id)) {
                        $payment_id_inserted = $lastInserted_payment_id;
                    } else {
                        $payment_id_inserted = $payment_id;
                    }
                    $getNetBankingDetails['payment_id'] = $payment_id_inserted;
                    //$getNetBankingDetails['type']=trim($_REQUEST['netBankingType']);
                    $getNetBankingDetails['nbd_created_date'] = $createdDate;
                    $lastInserted_cheque_id = $rm->insert_record($getNetBankingDetails, 'net_banking_details_t');
                    array_push($mailData["netDetails"], $getNetBankingDetails);
                    //print_r($getNetBankingDetails);
                }
            }
            if (strtolower($userType) == "user") {
                $adminId = 1;
                if ($adminId != 0) {
                    $adminEmail = $rm->getAdminEmailID($adminId);
                    //print_r($mailData);;
                    $sendMail = $rm->sendTransactionDetails($adminEmail, $mailData);
                }
            }
            if (strtolower($userType) == "user" && $affectedRowsPayment >= 0) {
                $result = $rm->paymentRegisterSuccessJson($payment_id);
                $sqlUpdate = "update user_requests_t set status='Paid' where user_request_id={$user_request_id}";
                mysql_query($sqlUpdate, $GLOBALS['link']);
                return $result;
            } else {
                if (strtolower($userType) == "admin" && !empty($lastInserted_payment_id)) {
                    $result = $rm->paymentRegisterSuccessJson($lastInserted_payment_id);
                    $sqlUpdate = "update user_requests_t set status='Paid' where user_request_id={$user_request_id}";
                    mysql_query($sqlUpdate, $GLOBALS['link']);
                    return $result;
                }
            }
            if (empty($lastInserted_payment_id) && strtolower($userType) == "admin") {
                $result = $rm->paymentRegisterFailJson();
                return $result;
            }
            if ($affectedRowsPayment < 0 && strtolower($userType) == "user") {
                $result = $rm->paymentRegisterFailJson();
                return $result;
            }
        } else {
            $errorCode = "2";
            $errorMsg = "User Request Not Exist";
            $newData = "{\"data\":{\"Error_Code\":\"" . $errorCode . "\",\"Error_Msg\":\"" . $errorMsg . "\"}}";
            //Json Format Response
            return $newData;
        }
    }
}
function addPaymentDetails()
{
    //$companyId = $_REQUEST['companyId'];
    $companyID = trim($_REQUEST['companyID']);
    $fromBankID = trim($_REQUEST['fromBankID']);
    $toBankID = trim($_REQUEST['toBankID']);
    //$paymentDate = trim($_REQUEST['paymentDate']);
    $paymentReason = trim($_REQUEST['paymentReason']);
    $amount = trim($_REQUEST['amount']);
    $paymentType = trim($_REQUEST['paymentType']);
    $rm = new Response_Methods();
    if ($companyID == "" || $fromBankID == "" || $toBankID == "" || $paymentReason == "" || $amount == "" || $paymentType == "") {
        $result = $rm->fields_validation();
        return $result;
    } else {
        date_default_timezone_set('Asia/Calcutta');
        $createdDate = date('Y-m-d H:i:s');
        $getList = array();
        //inserting payment details
        $getInsertFieldValue['company_id'] = $companyID;
        $getInsertFieldValue['payment_from_bank_id'] = $fromBankID;
        $getInsertFieldValue['payment_to_bank_id'] = $toBankID;
        //$getInsertFieldValue['payment_date']=$paymentDate;
        $getInsertFieldValue['payment_reason'] = $paymentReason;
        $getInsertFieldValue['amount'] = $amount;
        $getInsertFieldValue['payment_type'] = $paymentType;
        $getInsertFieldValue['payment_created_date'] = $createdDate;
        $lastInserted_payment_id = $rm->insert_record($getInsertFieldValue, 'payment_details_t');
        if (!empty($lastInserted_payment_id)) {
            //Do Transactions by updating bank current balance
            $fromBankBalance = $rm->idToValue('initial_bank_balance', 'bank_details_t', 'bank_id', $fromBankID);
            $toBankBalance = $rm->idToValue('initial_bank_balance', 'bank_details_t', 'bank_id', $toBankID);
            if ($fromBankID != $toBankID) {
                $fromBankBalance = $fromBankBalance - $amount;
                $toBankBalance = $toBankBalance + $amount;
            }
            $updateFromBankBalance['initial_bank_balance'] = $fromBankBalance;
            $affectedRowsFrom = $rm->update_record($updateFromBankBalance, 'bank_details_t', 'bank_id', $fromBankID);
            $updateToBankBalance['initial_bank_balance'] = $toBankBalance;
            $affectedRowsTo = $rm->update_record($updateToBankBalance, 'bank_details_t', 'bank_id', $toBankID);
            //check payment type and insert details accordingly(cheque/net)
            if (strtolower($paymentType) == "cheque") {
                //insert cheque details
                //echo 'test';
                $getChequeDetails['payment_id'] = $lastInserted_payment_id;
                $getChequeDetails['cheque_number'] = trim($_REQUEST['chequeNo']);
                $getChequeDetails['cheque_date'] = trim($_REQUEST['chequeDate']);
                $getChequeDetails['to_whom_issued'] = trim($_REQUEST['chequeIssued']);
                //$getChequeDetails['cheque_amount']=trim($_REQUEST['chequeAmount']);
                $getChequeDetails['cheque_amount'] = $amount;
                $getChequeDetails['cheque_created_date'] = $createdDate;
                $lastInserted_cheque_id = $rm->insert_record($getChequeDetails, 'cheque_details_t');
            } else {
                if (strtolower($paymentType) == "net") {
                    //insert NET Banking Details
                    $getNetBankingDetails['payment_id'] = $lastInserted_payment_id;
                    $getNetBankingDetails['type'] = trim($_REQUEST['netBankingType']);
                    $getNetBankingDetails['nbd_created_date'] = $createdDate;
                    $lastInserted_cheque_id = $rm->insert_record($getNetBankingDetails, 'net_banking_details_t');
                }
            }
            $result = $rm->paymentRegisterSuccessJson($lastInserted_payment_id);
            return $result;
        } else {
            $result = $rm->paymentRegisterFailJson();
            return $result;
        }
    }
}
function editProfile()
{
    $rm = new Response_Methods();
    if ($_SERVER['REQUEST_METHOD'] == "GET") {
        $result = $rm->inValidServerMethod();
        return $result;
    }
    //Check request url is https or not
    if (!empty($_SERVER["HTTPS"])) {
        if ($_SERVER["HTTPS"] !== "off") {
            $userId = $rm->cleanData(trim($_POST['userId']));
            $username = $rm->cleanData(trim($_POST['username']));
            $petType = $rm->cleanData(trim($_POST['petType']));
            $petBio = $rm->cleanData(trim($_POST['petBio']));
            $petName = $rm->cleanData(trim($_POST['petName']));
            $petDob = trim($_POST['petDob']);
            $petSpecies = $rm->cleanData(trim($_POST['petSpecies']));
            if ($userId == "" || $petType == "" || $petBio == "" || $petName == "" || $petDob == "" || $petSpecies == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $getList = array();
                $IMAGEURLBASEURL = BASEURL . '/images/';
                $userImageBaseURL = "images/{$username}";
                if (!is_dir($userImageBaseURL)) {
                    //mkdir - tells that need to create a directory
                    mkdir($userImageBaseURL);
                    mkdir($userImageBaseURL . '/profile_pics/');
                    //mkdir($userImageBaseURL.'/post_photos/');
                }
                $rand = rand(00, 99999);
                //$_REQUEST['profile_pic']=21;
                //echo 'test';
                if (isset($_POST['profile_pic']) and $_POST['profile_pic'] != "") {
                    $profile_pic = trim($_POST['profile_pic']);
                    //blob image data
                    $img = 'data:image/png;base64,' . $profile_pic . '';
                    $img = str_replace('data:image/png;base64,', '', $img);
                    $img = str_replace(' ', '+', $img);
                    $data = base64_decode($img);
                    $image = 'petbestie_user_' . $rand . '.png';
                    $target_dir = $userImageBaseURL . "/profile_pics/";
                    $test = $rm->emptyDirectory($target_dir);
                    file_put_contents($userImageBaseURL . '/profile_pics/' . $image, $data);
                    //file_put_contents($userImageBaseURL.'/profile_pics/'.$image, $data);
                    $IMAGEURL = $IMAGEURLBASEURL . $username . '/profile_pics/' . $image;
                    $getUpdateProfilePic['profile_pic_f'] = $IMAGEURL;
                }
                //echo $getUpdateProfilePic['profile_pic_f'];
                $getUpdateProfilePic['pet_type_f'] = $petType;
                $getUpdateProfilePic['pet_name_f'] = $petName;
                $getUpdateProfilePic['pet_dob_f'] = $petDob;
                $getUpdateProfilePic['description_f'] = $petBio;
                $getUpdateProfilePic['species_f'] = $petSpecies;
                $updateResult = $rm->update_record($getUpdateProfilePic, 'user_details_t', 'user_id', $userId);
                if ($updateResult > 0) {
                    $result = $rm->userRegisterSuccessJson($userId);
                    return $result;
                } else {
                    $result = $rm->userUpdateProfileFail();
                    return $result;
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}