<?php
    $conf_basedir	= "../../";	//相对主目录的位置
    $conf_where		= "admin";	//选择调用相应模块
    $directory		= basename(dirname(__FILE__));	//定义当前所在的目录，引入模块公用函数
    include_once($conf_basedir."base.inc.php");
    checkAuth('32');	//判断登录和权限


	if ($actiontype) doaction($actiontype,$actionid);
    $css="<link href='http://esfadmin.house365.com/script/css/autocomplete.css' rel='stylesheet' type='text/css' /><link rel='stylesheet' type='text/css' href='http://www.house365.com/public/js/swf/default1.css'  />";
    $js = "<script type='text/javascript' src='http://esfadmin.house365.com/script/js/showpic.js'></script>
    <script type='text/javascript' src='http://esfadmin.house365.com/script/js/public.js'></script>
    <script type='text/javascript' src='http://esfadmin.house365.com/script/js/formValidator.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.core.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.position.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.widget.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/jquery_ui_autocomplete/ui/jquery.ui.autocomplete.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/swf/swfupload.js'></script>
   <script type='text/javascript' src='http://esfadmin.house365.com/script/js/handlers.js'></script>
   ";
    $tbl='block_img';

    if ($action == "add") {

    if (count($blockid) == 0)
        echo "<script>alert('没有找到该小区');window.opener.location.reload();window.close();</script>";
    $block_info = $db->GetRow("select blockname,sd_mark from block where id='" . $blockid . "'"); //获取小区信息
    $data_info['blockname']=$block_info['blockname'];
    $data_info['sd_mark']=$block_info['sd_mark'];
}

    if ($action == "modify") {

        $q = "select * from $tbl where id=$id";
        if ($q_ext != "")
            $q.=" and " . $q_ext;
        $data_info = $db->GetRow($q);

        if (count($data_info) == 0)
            echo "<script>alert('没有发现您查询的记录');window.opener.location.reload();window.close();</script>";
        $data_info['blockname'] = $db->GetOne("select blockname from block where id='" . $blockid . "'"); //获取小区信息
        $img = $data_info["bi_img"] != "" ? "<a href=" . str_replace("thumb/", '', $data_info["bi_img"]) . " target=_blank>查看</a>&nbsp;" : '';
    }

    if ($action == 'insert') {
        if ($p_filename) {
            foreach ($p_filename as $key => $value) {
                //产生数据
                $ss = array();
                $ss["bi_title"] = $bi_title;
                $ss["bi_img"] = $value;
                $ss["bi_blockid"] = $bi_blockid;
                $ss["bi_type"] = $bi_type;
                $ss["bi_add_time"] = time();
                $ss["bi_room"] = intval($bi_room);
                $ss["bi_hall"] = intval($bi_hall);
                $data_info = $ss; //返回值
                //写入数据库
                $q = insert_sql($tbl, $ss);

                $db->Execute($q);
            }
        } else {
            echo "<script>alert('提交失败!请上传图片');window.opener.location.reload();window.close();</script>";
            exit;
        }
        echo "<script>alert('提交成功!');window.opener.location.reload();window.close();</script>";
    }

        if ($action == 'update') {
        //产生数据
        $ss = array();
        $ss["bi_title"] = $bi_title;
        $ss["bi_type"] = $bi_type;
        $ss["bi_room"] = intval($bi_room);
        $ss["bi_hall"] = intval($bi_hall);

        $data_info = $ss; //返回值
        //写入数据库
        $q = update_sql($tbl, $ss, " where id=" . intval($id) . "");
        $db->Execute($q);
        echo "<script>alert('提交成功!');location.href='/module/block/block_pic_add.php?action=modify&id=".$id."&blockid=".$blockid."';window.close();</script>";
    }

    //引用模版文件
    include_once(Template("header"));
    include_once(Template("block/block_pic_add"));
    include_once(Template("footer"));
?>