<?php

function check_group_by_name_handler(){

    if($_POST){
        if($_POST["action"]){
            $action = $_POST["action"];

            switch ($action){
                case "check_group" :{
                    $gid = $_POST["gid"];
                    $gname = str_replace("'", "", $_POST["gname"]);
                    if(ftm_geo_target_checkGroup($gname, $gid)){
                        echo "true";
                    }
                    else
                    {
                        echo "false";
                    }
                }
            }
        }
    }
    else
    {
        echo '-1';
    }

    wp_die();
}

function ftm_geo_target_checkGroup_service($groupName, $current_group_id){
    GLOBAL $wpdb;

    if ($current_group_id !== "0"){
        $result = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ftm_geo_target_groups WHERE LOWER(GroupName) = '" . strtolower($groupName) . "' AND GroupId != " . $current_group_id);
    }
    else {
        $result = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ftm_geo_target_groups WHERE LOWER(GroupName) = '" . strtolower($groupName) . "'");
    }

    if(sizeof($wpdb->last_result) > 0){
        return true;
    }
    else
    {
        return false;
    }
}

?>