function geodir_manage_claim_listing_actions()
{
    global $wpdb, $plugin_prefix;
    if (isset($_REQUEST['_wpnonce']) && isset($_REQUEST['id']) && $_REQUEST['id'] != '' && current_user_can('manage_options')) {
        if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'claim_action_' . $_REQUEST['id'])) {
            return;
        }
        if (isset($_REQUEST['pagetype']) && $_REQUEST['pagetype'] == 'delete') {
            $pid = $_REQUEST['id'];
            $approvesql = $wpdb->prepare("select * from " . GEODIR_CLAIM_TABLE . " where pid=%d", array($pid));
            $approveinfo = $wpdb->get_results($approvesql);
            $post_id = $approveinfo[0]->list_id;
            $author_id = $approveinfo[0]->user_id;
            $post_id = $approveinfo[0]->list_id;
            $wpdb->query($wpdb->prepare("delete from " . GEODIR_CLAIM_TABLE . " where pid=%d", array($pid)));
            $change_clamed = $wpdb->get_row($wpdb->prepare("select pid from " . GEODIR_CLAIM_TABLE . " where list_id=%s and status='1'", array($post_id)));
            if (!$change_clamed) {
                geodir_save_post_meta($post_id, 'claimed', '0');
            }
            $msg = CLAIM_DELETED_SUCCESS;
            $msg = urlencode($msg);
            $location = admin_url('admin.php?page=geodirectory&tab=claimlisting_fields&subtab=manage_geodir_claim_listing&claim_success=' . $msg);
            wp_redirect($location);
            exit;
        }
        if (isset($_REQUEST['pagetype']) && $_REQUEST['pagetype'] == 'approve') {
            $pid = $_REQUEST['id'];
            $approvesql = $wpdb->prepare("select * from " . GEODIR_CLAIM_TABLE . " where pid=%d", array($pid));
            $approveinfo = $wpdb->get_results($approvesql);
            $post_id = $approveinfo[0]->list_id;
            $author_id = $approveinfo[0]->user_id;
            $wpdb->query($wpdb->prepare("update " . GEODIR_CLAIM_TABLE . " set status='2' where list_id=%s and user_id!=%s and status='1'", array($post_id, $author_id)));
            geodir_save_post_meta($post_id, 'claimed', '1');
            $wpdb->query($wpdb->prepare("update {$wpdb->posts} set post_author=%d where ID=%d", array($author_id, $post_id)));
            $wpdb->query($wpdb->prepare("update " . GEODIR_CLAIM_TABLE . " set status='1' where pid=%d", array($pid)));
            // Force to upgrade to complete claim listing
            $force_upgrade = geodir_claim_force_upgrade();
            $package_list = geodir_claim_payment_package_list(get_post_type($post_id));
            if ($force_upgrade && !empty($package_list) && !empty($approveinfo) && isset($approveinfo[0]->upgrade_pkg_id)) {
                $geodir_upgrade_pkg = $approveinfo[0]->upgrade_pkg_id;
                $package_info = geodir_get_package_info_by_id($geodir_upgrade_pkg);
                if (!empty($package_info)) {
                    $claim_post_info = array();
                    $claim_post_info['package_id'] = $geodir_upgrade_pkg;
                    geodir_save_listing_payment($post_id, $claim_post_info);
                    $wpdb->query($wpdb->prepare("UPDATE `" . GEODIR_CLAIM_TABLE . "` SET `upgrade_pkg_id`='' WHERE `pid`=%d", array($pid)));
                }
            }
            geodir_clientEmail($post_id, $author_id, 'claim_approved');
            /* email to client*/
            $msg = CLAIM_APPROVE_SUCCESS;
            $msg = urlencode($msg);
            $location = admin_url('admin.php?page=geodirectory&tab=claimlisting_fields&subtab=manage_geodir_claim_listing&claim_success=' . $msg);
            wp_redirect($location);
            exit;
        }
        if (isset($_REQUEST['pagetype']) && $_REQUEST['pagetype'] == 'reject') {
            $pid = $_REQUEST['id'];
            $wpdb->query($wpdb->prepare("update " . GEODIR_CLAIM_TABLE . " set status='2' where pid=%d", array($pid)));
            $approvesql = $wpdb->prepare("select * from " . GEODIR_CLAIM_TABLE . " where pid=%d", array($pid));
            $approveinfo = $wpdb->get_results($approvesql);
            $post_id = $approveinfo[0]->list_id;
            $author_id = $approveinfo[0]->user_id;
            geodir_clientEmail($post_id, $author_id, 'claim_rejected');
            /* email to client*/
            $msg = CLAIM_REJECT_SUCCESS;
            $msg = urlencode($msg);
            $location = admin_url('admin.php?page=geodirectory&tab=claimlisting_fields&subtab=manage_geodir_claim_listing&claim_success=' . $msg);
            wp_redirect($location);
            exit;
        }
        if (isset($_REQUEST['pagetype']) && $_REQUEST['pagetype'] == 'undo') {
            $pid = $_REQUEST['id'];
            $approvesql = $wpdb->prepare("select * from " . GEODIR_CLAIM_TABLE . " where pid=%d", array($pid));
            $approveinfo = $wpdb->get_results($approvesql);
            $post_id = $approveinfo[0]->list_id;
            $author_id = $approveinfo[0]->org_authorid;
            $wpdb->query($wpdb->prepare("update {$wpdb->posts} set post_author=%d where ID=%d", array($author_id, $post_id)));
            $wpdb->query($wpdb->prepare("update " . GEODIR_CLAIM_TABLE . " set status='2' where pid=%d", array($pid)));
            $change_clamed = $wpdb->get_row($wpdb->prepare("select pid from " . GEODIR_CLAIM_TABLE . " where list_id=%s and status='1'", array($post_id)));
            if (!$change_clamed) {
                geodir_save_post_meta($post_id, 'claimed', '0');
                /*update claimed post data.*/
            }
            $location = admin_url('admin.php?page=geodirectory&tab=claimlisting_fields&subtab=manage_geodir_claim_listing&msg=reject');
            wp_redirect($location);
            exit;
        }
    } else {
        wp_redirect(home_url() . '/?geodir_signup=true');
        exit;
    }
}
function geodir_claim_template_loader($template)
{
    global $wp_query, $current_user, $plugin_prefix, $wpdb;
    if (isset($_REQUEST['geodir_ptype'])) {
        global $information;
        if ($current_user->ID) {
            if (get_option('geodir_claim_auto_approve') == 'yes') {
                if (!isset($_REQUEST['rs']) || isset($_REQUEST['rs']) && $_REQUEST['rs'] == '') {
                    $information .= CLAIM_VARIFY_CODE_NOT_EXIST;
                } else {
                    $rand_string = isset($_REQUEST['rs']) ? $_REQUEST['rs'] : '';
                    $approvesql = $wpdb->prepare("select * from " . GEODIR_CLAIM_TABLE . " where rand_string=%s", array($rand_string));
                    $approveinfo = $wpdb->get_results($approvesql);
                    if ($approveinfo) {
                        $pid = $approveinfo[0]->pid;
                        $post_id = $approveinfo[0]->list_id;
                        $author_id = $approveinfo[0]->user_id;
                        $user_id = $current_user->ID;
                        $status = $approveinfo[0]->status;
                        if ($author_id == $user_id) {
                            if ($status == 1) {
                                $information .= CLAIM_LISTING_ALREADY_VARIFIED;
                            } elseif ($status == 2) {
                                $information .= CLAIM_LISTING_VERIFICATION_REJECTED;
                            } else {
                                $wpdb->query($wpdb->prepare("update {$wpdb->posts} set post_author=%d where ID=%d", array($author_id, $post_id)));
                                $wpdb->query($wpdb->prepare("update " . GEODIR_CLAIM_TABLE . " set status='1' where pid=%d", array($pid)));
                                geodir_save_post_meta($post_id, 'claimed', '1');
                                geodir_clientEmail($post_id, $author_id, 'claim_approved');
                                /* email to client */
                                $information .= CLAIM_LISTING_SUCCESS_VERIFIED . ' <a href="' . get_option('siteurl') . '/?p=' . $post_id . '">' . $approveinfo[0]->list_title . '</a>';
                            }
                        } else {
                            $information .= CLAIM_VARIFY_CODE_NOT_MATCH;
                        }
                    } else {
                        $information .= CLAIM_VARIFY_CODE_NOT_EXIST;
                    }
                }
            } else {
                $information .= CLAIM_AUTO_VARIFY_DISABLE;
            }
        } else {
            $site_login_url = get_option('siteurl') . '?geodir_signup=true';
            $information .= sprintf(CLAIM_LOGIN_REQUIRED, '<a href="' . $site_login_url . '" >');
        }
        $template = geodir_locate_template('information');
        if (!$template) {
            $template = geodir_plugin_path() . '/geodirectory-templates/geodir-information.php';
        }
        $template = apply_filters('geodir_template_information', $template);
    }
    return $template;
}