<?php
$conf_basedir	= "../../";	//相对主目录的位置
$conf_where		= "admin";	//选择调用相应模块
$directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
include_once($conf_basedir."base.inc.php");
checkAuth('89');	//判断登录和权限
$title = "房源竞投热搜词";
$growthBidHostSearchSet = new GrowthBidHotSearchSet();
function sendStatus($statusWords) {
    echo '<script type="text/javascript">alert("' . $statusWords
            .'");location.href="/module/growth_nj/bid_hot_search_manage.php";</script>';
}
$conf = array();
switch ($actiontype) {
    case '':
        $settingTypeSearch = array(0=>'请选择','1'=>'出售'/**, '2' => '出租'***/);
        $settingSearch = array(0=>'请选择','words'=>'热搜词', 'id' => '编号');
        if ($type) {
            $conf['type'] = $type;
        }
        if ($searchType && $keyword) {
            if ($searchType == 'words') {
                $conf[$searchType] = "like '%$keyword%'";
            } else {
                $conf[$searchType] = $keyword;
            }
        }
        $confWhere = array();
        foreach ($conf as $key => $value) {
            if(is_array($value)) {
                $confWhere[]= "$key in ('".  implode("','", $value)."')";
            } else if (strstr($value, 'like')) {
                 $confWhere[]= "$key $value";
            }else if(is_string($value)) {
                $confWhere[]= "$key = '$value'";
            }
        }
        if($confWhere) {
            $confWhere = implode(" and ", $confWhere);
        } else {
            $confWhere = '';
        }
        $data_info = $growthBidHostSearchSet->findWords($confWhere);
        //分页参数
        $pagesize	= $disp_rows ? intval($disp_rows) : 20;
        $page_now	= $page_now ? max(1, intval($page_now)) : 1 ; // 获取当前页数
        $offset  = ( $page_now - 1 ) * $pagesize;
        $pagenum = count($data_info);//当前页面数量
        $numrows = $numrows >0 ? $numrows : 0;
        $time = time();
        if( $numrows <= 0 || $pagenum <=0){
            $pages = 0 ;  //计算总页数
        }else{
            $pages = ceil($numrows/$pagesize) ;  //计算总页数
            $new_pagenavi = new_pagenavi2($page_now,$pages,$numrows);
        }
        break;
    case 'delete':
        if ($actionid) {
            $status = $growthBidHostSearchSet->delWords($actionid);
            $statusWords = $status ? '删除成功' : '删除失败';
            sendStatus($statusWords);
        }
        die();
        break;
    case 'add':
        $isExist = $growthBidHostSearchSet->findWordsExist($type, $words);
        if ($isExist) {
            sendStatus("此热搜词已经存在，请不要重复提交");
        } else {
            $status = $growthBidHostSearchSet->addWords($type, $words);
            $statusWords = $status ? '添加成功' : '添加失败';
            sendStatus($statusWords);
        }
        die();
        break;
    case 'modfiy':
        $isExist = $growthBidHostSearchSet->findWordsExist($type, $words, $actionid);
        if ($isExist) {
            sendStatus("此热搜词已经存在，请不要重复提交");
        } else {
            $status = $growthBidHostSearchSet->setWords($actionid, $words);
            $statusWords = $status ? '修改成功' : '修改失败';
            sendStatus($statusWords);
        }
        die();
        break;
    default:
        break;
}
include_once(Template("header"));
include_once(Template("growth_nj/bid_hot_search_manage"));
include_once(Template("footer"));
