<?php
/*
Plugin Name: table_test
Version: 1.0
Plugin URI: http://www.u-gen.net
Author: U-GEN TECH.
Description: 自定义列表
*/


define('PLUGIN_DIR', dirname(__FILE__) . '\\');
add_action('init', 'tospur_init');

function tospur_init()
{
    require_once('consultant_score.php');
    require_once('view_house.php');
    require_once(PLUGIN_DIR . 'Tools\TCSync.php');
    require_once(PLUGIN_DIR . 'Dao\SearchDao.php');
    add_action('admin_menu', 'create_menu');
    tospur_ajax_set();
}

function tospur_ajax_set()
{
    add_action('wp_ajax_serachCity', 'SearchDao::ajax_serachCity');
    add_action('wp_ajax_nopriv_serachCity', 'SearchDao::ajax_serachCity');
    add_action('wp_ajax_searchArea', 'SearchDao::ajax_searchArea');
    add_action('wp_ajax_nopriv_searchArea', 'SearchDao::ajax_searchArea');
    add_action('wp_ajax_searchBuildProperty', 'SearchDao::ajax_searchBuildProperty');
    add_action('wp_ajax_nopriv_searchBuildProperty', 'SearchDao::ajax_searchBuildProperty');
    add_action('wp_ajax_searchRoom', 'SearchDao::ajax_searchRoom');
    add_action('wp_ajax_nopriv_searchRoom', 'SearchDao::ajax_searchRoom');
    add_action('wp_ajax_searchUnitPriceRange', 'SearchDao::ajax_searchUnitPriceRange');
    add_action('wp_ajax_nopriv_searchUnitPriceRange', 'SearchDao::ajax_searchUnitPriceRange');
    add_action('wp_ajax_searchTotalPrice', 'SearchDao::ajax_searchTotalPrice');
    add_action('wp_ajax_nopriv_searchTotalPrice', 'SearchDao::ajax_searchTotalPrice');
    add_action('wp_ajax_searchOrganization', 'SearchDao::ajax_searchOrganization');
    add_action('wp_ajax_nopriv_searchOrganization', 'SearchDao::ajax_searchOrganization');

    //后台处理 置业顾问评分
    add_action('wp_ajax_valid_consultant_score', 'valid_consultant_score');
    //后台处理 置业顾问
    add_action('wp_ajax_update_consultant', 'update_consultant');
}

function valid_consultant_score()
{
    $score_id = $_POST['id'];
    $valid = $_POST['valid'];
    if (isset($score_id) && isset($valid)) {
        $result = dao::update_consultant_score($score_id, $valid);
        $array = array();
        if ($result) {
            $array['code'] = 2000;
        } else {
            $array['code'] = 2001;
        }
        wp_send_json($array);
    }
}

function update_consultant()
{
    $house_id = $_POST['id'];
    $consultant_id = $_POST['consultant_id'];
    if (isset($consultant_id) && isset($house_id)) {
        $result = dao::update_view_house_consultant($house_id, $consultant_id);
        $array = array();
        if ($result) {
            $array['code'] = 2000;
        } else {
            $array['code'] = 2001;
        }
        wp_send_json($array);
    }
}

function create_menu()
{
    add_menu_page("talbe_test", "table_test", "manage_options", "1", "create_table");
}

function create_table()
{
    TCSync::user_sync();
    //TCSync::organization_sync();
}
