function getUserLoginDetails()
{
    $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 = trim($_REQUEST['userName']);
            //Get Request From Device
            $PASSWORD = trim($_REQUEST['passWord']);
            $getArrayList = array();
            //echo $ENCRYPTEDPWD = md5($PASSWORD);
            //echo $ENCRYPTEDPWD = base64_decode($PASSWORD);
            //$ENCRYPTEDPWD=$PASSWORD;
            if ($USERNAME == "" || $PASSWORD == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $result = $rm->login_success($USERNAME, $PASSWORD);
                return $result;
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function getUserPhotos()
{
    $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']);
            //Get Request From Device
            //die('test');
            $getArrayList = array();
            if ($USERID == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $result = $rm->getPhotos($USERID);
                return $result;
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function forgetPassword()
{
    $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") {
            $EMAILID = $_REQUEST['emailId'];
            if ($EMAILID == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $result = $rm->forgetPassword($EMAILID);
                return $result;
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function userSearchList()
{
    $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") {
            if (isset($_POST['searchType']) && $_POST['searchType'] != '') {
                $searchType = trim($_POST['searchType']);
                //Get Request From Device	(trending, userName, petType)
            } else {
                $searchType = "trending";
            }
            $USERID = $_POST['userId'];
            $getArrayList = array();
            if ($searchType == "" || $USERID == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $result = $rm->getAllUsers($searchType, $USERID);
                return $result;
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function getSingleUserSearchDetails()
{
    $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($_POST['userId']);
            $loggedInUserId = $rm->cleanData($_POST['loggedInUserId']);
            $getArrayList = array();
            if ($userId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $result = $rm->getSingleUserSearchDetails($userId, $loggedInUserId);
                return $result;
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function getPostComments()
{
    $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 = $rm->cleanData($_POST['postId']);
            $loggedInUserId = $rm->cleanData($_POST['userId']);
            $getArrayList = array();
            //echo $ENCRYPTEDPWD = md5($PASSWORD);
            //echo $ENCRYPTEDPWD = base64_decode($PASSWORD);
            //$ENCRYPTEDPWD=$PASSWORD;
            if ($postId == "" || $loggedInUserId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $result = $rm->getAllPostComments($postId, $loggedInUserId);
                return $result;
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function likePost()
{
    $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']);
            //Get Request From Device
            $POSTID = trim($_POST['postId']);
            //Get Request From Device
            $getArrayList = array();
            if ($USERID == "" || $POSTID == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $checkLike = $rm->checkAlreadyLiked($USERID, $POSTID);
                if ($checkLike > 0) {
                    $result = $rm->alreadyLiked();
                    return $result;
                }
                date_default_timezone_set('Asia/Calcutta');
                $user_owner_id = $rm->idToValue('user_id_fk', 'news_feeds_t', 'post_id', $POSTID);
                //getting user owner id
                $createdDate = date('Y-m-d H:i:s');
                $getInsertFieldValue['user_id_fk'] = $USERID;
                $getInsertFieldValue['post_id_fk'] = $POSTID;
                $getInsertFieldValue['user_owner_id_fk'] = $user_owner_id;
                $getInsertFieldValue['likeDate_f'] = $createdDate;
                $lastInserted_user_id = $rm->insert_record($getInsertFieldValue, 'likes_t');
                if (!empty($lastInserted_user_id)) {
                    $sqlLikeCountUpdate = "update news_feeds_t set like_count_f= like_count_f+1 where post_id={$POSTID}";
                    mysql_query($sqlLikeCountUpdate, $GLOBALS['link']);
                    $deviceId = $rm->idToValue('device_id_f', 'user_details_t', 'user_id', $user_owner_id);
                    //getting deviceId
                    if ($deviceId != '') {
                        $message = "You have received a like on your post.";
                        $rm->sendPushNotification($deviceId, $message);
                    }
                    $result = $rm->getParticularPost($POSTID, $USERID);
                    return $result;
                } else {
                    $result = $rm->likeUnSuccessful();
                    return $result;
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function addFriendRequest()
{
    $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']);
            $friendId = trim($_POST['friendId']);
            if ($userId == "" || $friendId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                if ($userId == $friendId) {
                    $result = $rm->friendRequestFailforSameUser();
                    return $result;
                } else {
                    $checkFriend = $rm->checkExistingFriendShip($userId, $friendId);
                    if ($checkFriend > 0) {
                        $result = $rm->friendshipAlreadyExists();
                        return $result;
                    }
                    date_default_timezone_set('Asia/Calcutta');
                    $createdDate = date('Y-m-d H:i:s');
                    $getList = array();
                    //preparing list and inserting values in friends_t table
                    $getInsertFieldValue['friend_one'] = $userId;
                    $getInsertFieldValue['friend_two'] = $friendId;
                    $getInsertFieldValue['created_date_f'] = $createdDate;
                    $lastInserted_friend_id = $rm->insert_record($getInsertFieldValue, 'friends_t');
                    if (!empty($lastInserted_friend_id)) {
                        $deviceId = $rm->idToValue('device_id_f', 'user_details_t', 'user_id', $friendId);
                        //getting deviceId
                        if ($deviceId) {
                            $message = "You have received a friend request in petbesties.";
                            $rm->sendPushNotification($deviceId, $message);
                        }
                        $result = $rm->friendRequestSuccess();
                        return $result;
                    } else {
                        $result = $rm->friendRequestFail();
                        return $result;
                    }
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function addComment()
{
    $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") {
            date_default_timezone_set('Asia/Calcutta');
            $comment = $rm->cleanData($_POST['comment']);
            //Get Request From Device
            $userId = $rm->cleanData($_POST['userId']);
            $postId = $rm->cleanData($_POST['postId']);
            $createdDate = date('Y-m-d H:i:s');
            $getArrayList = array();
            //echo $ENCRYPTEDPWD = md5($PASSWORD);
            //echo $ENCRYPTEDPWD = base64_decode($PASSWORD);
            //$ENCRYPTEDPWD=$PASSWORD;
            if ($comment == "" || $userId == "" || $postId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $user_owner_id = $rm->idToValue('user_id_fk', 'news_feeds_t', 'post_id', $postId);
                $getInsertFieldValue['comment_text_f'] = $comment;
                $getInsertFieldValue['user_id_fk'] = $userId;
                $getInsertFieldValue['post_id_fk'] = $postId;
                $getInsertFieldValue['comment_Date'] = $createdDate;
                $getInsertFieldValue['user_owner_id_fk'] = $user_owner_id;
                $lastInsertedCommentId = $rm->insert_record($getInsertFieldValue, 'comments_t');
                if ($lastInsertedCommentId) {
                    $deviceId = $rm->idToValue('device_id_f', 'user_details_t', 'user_id', $user_owner_id);
                    //getting deviceId
                    if ($deviceId != '') {
                        $message = "You have received a comment on your post.";
                        $rm->sendPushNotification($deviceId, $message);
                    }
                    $result = $rm->addCommentSuccessJson($postId);
                    return $result;
                } else {
                    $result = $rm->addCommentFailJson();
                    return $result;
                }
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function followFriend()
{
    $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']);
            $friendId = trim($_POST['friendId']);
            if ($userId == "" || $friendId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                if ($userId == $friendId) {
                    $result = $rm->friendFollowSame();
                    return $result;
                } else {
                    date_default_timezone_set('Asia/Calcutta');
                    $createdDate = date('Y-m-d H:i:s');
                    $getList = array();
                    $checkFollow = $rm->checkExistingFollow($userId, $friendId);
                    if ($checkFollow > 0) {
                        $result = $rm->followAlreadyExists();
                        return $result;
                    }
                    //preparing list and inserting values in friends_t table
                    $getInsertFieldValue['follower_user_id_fk'] = $userId;
                    $getInsertFieldValue['following_user_id_fk'] = $friendId;
                    $getInsertFieldValue['follow_date_f'] = $createdDate;
                    $lastInserted_follow_id = $rm->insert_record($getInsertFieldValue, 'follow_t');
                    if (!empty($lastInserted_follow_id)) {
                        $result = $rm->makeFollowSuccess($userId, $friendId);
                        return $result;
                    } else {
                        $result = $rm->makeFollowFail();
                        return $result;
                    }
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function validateEmaiUser()
{
    $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") {
            $emailId = $rm->cleanData($_POST['emailId']);
            $userName = $rm->cleanData($_POST['userName']);
            //die();
            $getArrayList = array();
            if ($emailId == "" || $userName == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $checkUser = $rm->checkUserValidation($userName, 'user_name_f');
                $checkEmail = $rm->checkUserValidation($emailId, 'email_f');
                if ($checkUser == 0) {
                    $result = $rm->userExistJson();
                    return $result;
                }
                if ($checkEmail == 0) {
                    $result = $rm->emailExistJson();
                    return $result;
                }
                if ($checkUser == 1 && $checkEmail == 1) {
                    $result = $rm->userEmailAvailable();
                    return $result;
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function denyFriendRequest()
{
    $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']);
            $friendId = trim($_POST['friendId']);
            if ($userId == "" || $friendId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                if ($userId == $friendId) {
                    $result = $rm->friendRequestFailforSameUser();
                    return $result;
                } else {
                    $sqlDenyFriend = "delete from friends_t where status='0' and (friend_one={$userId} OR friend_two={$userId})AND(friend_one={$friendId} OR friend_two={$friendId})";
                    mysql_query($sqlDenyFriend, $GLOBALS['link']);
                    $affectedRows = mysql_affected_rows();
                    if ($affectedRows > 0) {
                        $result = $rm->friendDeniedSuccess();
                        return $result;
                    } else {
                        $result = $rm->friendDeniedFailed();
                        return $result;
                    }
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function getUserPhotos()
{
    $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") {
            /* yahan se*/
            $USERID = trim($_POST['userId']);
            //Get Request From Device
            //die('test');
            if (isset($_POST['postId'])) {
                $postId = trim($_POST['postId']);
                if ($postId == "" || $USERID == "") {
                    $result = $rm->fields_validation();
                    return $result;
                } else {
                    $result = $rm->getNextPhotos($USERID, $postId);
                    return $result;
                }
            } else {
                if ($USERID == "") {
                    $result = $rm->fields_validation();
                    return $result;
                } else {
                    $result = $rm->getPhotos($USERID);
                    return $result;
                }
            }
            /* yahan tak*/
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        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 confirmFriendRequest()
{
    $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']);
            $friendId = trim($_POST['friendId']);
            if ($userId == "" || $friendId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                if ($userId == $friendId) {
                    $result = $rm->friendRequestFailforSameUser();
                    return $result;
                } else {
                    $sqlConfirmFriend = "UPDATE friends_t SET status='1' WHERE (friend_one={$userId} OR friend_two={$userId})AND(friend_one={$friendId} OR friend_two={$friendId})";
                    if (mysql_query($sqlConfirmFriend, $GLOBALS['link'])) {
                        $result = $rm->friendRequestConfirmed();
                        return $result;
                    } else {
                        $result = $rm->friendRequestFailed();
                        return $result;
                    }
                }
            }
            // end of else first
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        return $result;
    }
}
function deleteComment()
{
    //die('test');
    $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") {
            $commentId = $rm->cleanData($_POST['commentId']);
            $postId = $rm->cleanData($_POST['postId']);
            $getArrayList = array();
            //echo $ENCRYPTEDPWD = md5($PASSWORD);
            //echo $ENCRYPTEDPWD = base64_decode($PASSWORD);
            //$ENCRYPTEDPWD=$PASSWORD;
            if ($commentId == "" || $postId == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $affectedRowsDeleteComment = $rm->deleteComment($commentId);
                if ($affectedRowsDeleteComment > 0) {
                    $result = $rm->deleteCommentSuccessJson($postId);
                    return $result;
                } else {
                    $result = $rm->deleteCommentFailJson();
                    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 forgetPassword()
{
    //die('test');
    $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") {
            $EMAILID = $rm->cleanData(trim($_POST['emailId']));
            if ($EMAILID == "") {
                $result = $rm->fields_validation();
                return $result;
            } else {
                $checkEmail = $rm->checkUNEmail($EMAILID);
                if ($checkEmail['status'] == false) {
                    $result = $rm->emailNotAvailable();
                    return $result;
                } else {
                    //print_r($checkEmail);
                    //die();
                    $result = $rm->sendPasswordEmail($checkEmail['user_id']);
                    return $result;
                }
            }
        } else {
            $result = $rm->ssl_error();
            return $result;
        }
    } else {
        $result = $rm->ssl_error();
        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;
    }
}
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;
    }
}
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;
    }
}