<?php

/**********************
    最终页
 **********************/

if ($_REQUEST['username'] == 'jzabcdoc' && (int)$_REQUEST['id'] == 15503767) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://admin.dlszyht.com/help_detail.php?id=15517077&channel_id=13774427&parent_id=731970");
    exit();
}

require_once('./setting.php');
require_once(SYSTEM_ROOT . 'include/smarty_setting.php');
require_once(UPPER_ROOT . '/include/page_str.php');
$id          = (int)$_REQUEST['id']   ? (int)$_REQUEST['id'] : 0;
$page        = (int)$_REQUEST['page'] ? $_REQUEST['page']    : 1;
$user_name = $_REQUEST['username'] ? $_REQUEST['username'] : '';
if (!$id) {
    echo '<script lanaguage="javascript">location.href="/vip_' . $user_name . '.html";</script>';
    exit();
}

$doc_arr = get_doc($id, $userArr);

if ($doc_arr['check_status'] == 1) {
    echo '<script lanaguage="javascript">alert("参数有误！"); location.href="/vip_'.$user_name.'.html";</script>';
    exit();
} elseif ($doc_arr['check_status'] == 3) {
    echo '<script lanaguage="javascript">alert("参数有误！"); location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}

$channel_id = $doc_arr['channel_id'];
$big_id     = $doc_arr['big_id'];
$sub_id     = $doc_arr['sub_id'];

if ($doc_arr['content'] == "<div class='wap-add-img'><p> </p></div>" || is_null($doc_arr['content'])) {
    $doc_arr['content'] = '';
} else {
    $doc_arr['content'] = Model_Doc::re_reg($doc_arr['content']);
}
$tj_detail = 1;
require_once(SYSTEM_ROOT . 'include/public.php');
//用户信息
$sql = "select userid,oa_id,used_mobile,web_show_mobile from user where username = '" . $user_name . "'";
$userArr = $DB_Ev123->get_row($sql);
if (Job_Wap::check_wap() && $userArr['used_mobile'] && $userArr['web_show_mobile']) {
    $url = 'http://' . WAP_DOMAIN . $_SERVER['REQUEST_URI'];
    $url = str_replace('/vip_doc/', '/wap_doc/', $url);
    $url = str_replace('/doc_', '/wdoc_', $url);
    header('Location: ' . $url);
    exit();
}
if ($user_tag->is_tj == 1) {
    if ($doc_arr['is_del']) {
        @header("http/1.1 404 not found");
        @header("status: 404 not found");
        @header('Location: /nopage.php');
        exit();
    }

    $smarty->display('tjNew/index.tpl');
    exit();
}
$isFormLogin = 0;

// $sql="select id from ev_user_channel where id=".$channel_id." and is_del=0 and userid=".$user_id;
/*9-22*/
$sql = "select id from ev_user_channel where (id = " . $channel_id . " or parent_id = " . $channel_id . ") and is_del=0 and userid=" . $user_id;
/*9-22*/

$channel_id = $DB_Ev123->get_var($sql);
if (!$channel_id || $doc_arr['is_del']) {
    echo '<script lanaguage="javascript">alert("未找到相关信息！");location.href="/vip_' . $user_name . '.html";</script>';
    exit();
}

//用户VIP访问权限判断
if ($system_arr['set_vip']) {
    require($tmp_root . 'include/user_vip_set.php');
}

$big_name = get_class_name($big_id);
$sub_name = get_class_name($sub_id);
$back_str = '';
$back_str = '/' . $user_name . '/vip_doc/' . $channel_id . '_' . $big_id . '_' . $sub_id . '_1.html';

//获取内容
$tmp_table = get_doc_con_table($id, 1);
$conInfo = (array)Model_Doc::getDocContentInfo($tmp_table, $id);

if ($conInfo['content']) {
    $doc_arr['content'] = "<div class='wap-add-img'><p>{$conInfo['content']}</p>";
}

if ($conInfo['img_id']) {
    $sql = 'select * from ev_user_pic_data where id in (' . $conInfo['img_id'] . ')';
    $picList = $DB_Ev123->get_results($sql, 'O');

    if ($picList) {
        foreach ($picList as $k => $v) {
            // $v->url = str_replace('/own_pic_channel/', '/own_pic_channel/800_1500/', $v->url);
            $v->url = Job_Pic::format(
                [
                    'type'     => 10,
                    'pic'      => $v->url,
                    'width'    => 800,
                    'height'   => 1500,
                    'field'    => 'showPic'
                ]
            );
            $doc_arr['content'] .= '<img src="' . $v->url . '">';
        }
    }
}
if ($conInfo['content']) {
    $doc_arr['content'] .= "</div>";
}



$doc_arr['now']        = $doc_arr['input_time'];
$doc_arr['input_time'] = substr($doc_arr['input_time'], 0, 10);

if ($USERID != 1303752) {
    $doc_arr['pic1']       = str_replace('ev_user_doc_content/', 'ev_user_doc_content/600_600/', $doc_arr['pic']);
    $doc_arr['pic2']       = Job_Pic::changePicSize(0, $doc_arr['pic'], 280, 210);
}

//分页
$tmp_arr = explode('[page]', $doc_arr['content']);
$page_html = array();
foreach ($tmp_arr as $k => $v) {
    $page_html[$k] = Functions::closeHtmlTags($v);
}
$tmp_arr = $page_html;
$doc_arr['content'] = $tmp_arr[$page - 1];
$doc_arr['brief'] = get_info_con($doc_arr['brief']);
$page_str = '';
$doc_item = array();
if (count($tmp_arr) > 1) {
    $page_str = page_str4(count($tmp_arr), 1, $page, '/self_define/doc_detail.php?username=' . $user_name . '&id=' . $id . '&page=');
    if ($page_str) {
        $doc_arr['content'] .= '<div class="page" style="text-align:right;margin-top:20px;">' . $page_str . '</div>';
    }
} else {
    $pattern = '/<p>{(.*)}<\/p>/';
    $con_arr = preg_split($pattern, $doc_arr['content'], -1, PREG_SPLIT_DELIM_CAPTURE);
    $item_arr = array();
    if (count($con_arr) > 2) {
        foreach ($con_arr as $key => $val) {
            if ($key % 2 == 1) {
                $doc_item[trim($val)] = $con_arr[$key + 1];
            }
        }
    }
}

//得到频道名
$info_arr = get_chan_name(' where id=' . $channel_id);
$name = strip_tags($info_arr['name']);

//获得类信息
$sub_tmp_arr = get_class_arr($user_id, $channel_id);
$sub_class_arr = array();
$sub_name_arr = array();
$sub_num_arr = array();
if ($sub_tmp_arr) {
    $i = 1;
    foreach ($sub_tmp_arr as $sub) {
        $sub_class_arr[$sub['parentid']][$sub['id']] = cnsubstr($sub['name'], 50);
        $sub_num_arr[$sub['parentid']]['num'] = $i;
        $sub_name_arr[$sub['id']] = $sub['name'];
        $i++;
    }
}

//新的频道模板设置
//require(SYSTEM_ROOT.'include/set_new_model.php');

//类别---可以上传类别图片的时候
// $class_arr=get_doc_class($user_id,$channel_id,'','');
if (defined('PARENT_CHANNEL_ID')/* && $channel_arr['type'] == 11*/ && defined('PARENT_USER_ID')  && PARENT_CHANNEL_ID && PARENT_USER_ID) {
    $class_arr = get_doc_class(PARENT_USER_ID, PARENT_CHANNEL_ID, '', '');
    $sql = "select id from ev_user_channel where parent_id = " . PARENT_CHANNEL_ID . ' and userid = ' . $USERID;
    $selfChannelId = $DB_Ev123->get_var($sql);
    if (!empty($class_arr[0])) {
        foreach ($class_arr[0] as $key => $value) {
            $class_arr[0][$key]['link'] = str_replace(PARENT_CHANNEL_ID, $selfChannelId, $value['link']);
        }
    }
    if (!empty($class_arr[1])) {
        foreach ($class_arr[1] as $key => $value) {
            foreach ($value as $k => $v) {
                $class_arr[1][$key][$k]['link'] = str_replace(PARENT_CHANNEL_ID, $selfChannelId, $value['link']);
            }
        }
    }
} else {
    $class_arr = get_doc_class($user_id, $channel_id, '', '');
}

$big_class_arr = $class_arr[0];
$sub_class_arr2 = $class_arr[1];

$ser_id = 0;
//广告
$ad_arr = get_ad_info($user_id, $model_id, $channel_id, $ser_id);
if ($ad_arr) {
    foreach ($ad_arr as $key => $val) {
        $smarty->assign('ad_' . $key, $val);
    }
}
$css_filename = getDomTemplateColorById(getDomTemplateColorId((int)$user_id, 0, $channel_id));

//用户自定义参数
if ($model_css)
    $user_param = get_doc_forget_param($channel_id, $doc_arr);

if ($user_param) {
    $paramType17 = $paramType18 = $paramType19 = $paramType20 = 0;

    $guige = array();
    $doc_arr['paramType14'] = 0;
    foreach ($user_param as $k => $v) {
        if (!$v['value']) {
            unset($user_param[$k]);
            continue;
        }

        if ($v['type'] == 14) {
            $doc_arr['paramType14'] = 1;
        } else if ($v['type'] == 17) {
            $paramType17 = 1;
        } else if ($v['type'] == 18) {
            $paramType18 = 1;
        } else if ($v['type'] == 19) {
            $paramType19 = 1;

            $guige[] = $v;
            unset($user_param[$k]);
        } else if ($v['type'] == 20) {
            $paramType20 = 1;

            $guige[] = $v;
            unset($user_param[$k]);
        } else if ($v['type'] == 13) {
            if (strstr($v['value'], "#")) {
                $map_xy = explode("#", $v['value']);
                $map_xy[0] = $map_xy[0] ? $map_xy[0] : "116.404";
                $map_xy[1] = $map_xy[1] ? $map_xy[1] : "39.915";
            } elseif ($v['value']) {
                $map_XY = explode(",", $v['value']);
                $mapXY = Convert_BD09_To_GCJ02($map_XY[1], $map_XY[0]);
                $map_xy[0] = $mapXY['lng'] ? $mapXY['lng'] : "116.404";
                $map_xy[1] = $mapXY['lat'] ? $mapXY['lat'] : "39.915";
            } else {
                $map_xy[0] = "116.404";
                $map_xy[1] = "39.915";
            }
        } else if ($v['type'] == 3) {
            $user_param[$k] = Model_Doc::re_reg($v);
        } else if ($v['type'] == 30) {
            if ($v['value'] && strstr($v['value'], "#")) {
                $x_y = explode("#", $v['value']);
            } else {
                $x_y = explode(",", $v['value']);
            }

            $user_param[$k]['x_val'] = $v['value'] ? $x_y[0] : "116.404";
            $user_param[$k]['y_val'] = $v['value'] ? $x_y[1] : "39.915";
        }
    }

    if ($paramType20) {
        $guigePrice = Model_Doc::getDynamicPriceInfo(
            'id',
            'is_del=0 && doc_id=' . $doc_arr['id']
        );
        if (!$guigePrice) {
            unset($paramType20, $guige);
        }
    }
}

//非行业模块不显示导读图设置
$is_show_sql = 'select hy_id from ev_user_channel where userid=' . $USERID . ' and id=' . $channel_id . ' limit 0,1';
$is_hy = $DB_Ev123->get_var($is_show_sql);
$is_show_guid = $is_hy ? 1 : 0;

$is_special = 0;
if (!$is_show_guid || $paramType17 || $paramType18 || $paramType19) {
    $is_special = 1;
}
//获取是否有关联表单
$form_info = get_relation_form(11, $channel_id, $id, $is_special);
if ($form_info['is_member'] == 2 || $form_info['is_shopping_card'] == 1) {
    $isFormLogin = 1;

    if (!defined('USER_USER_ID')) {
        $isFormLogin = 0;
    }
} else {
    $isFormLogin = 1;
}


if ($paramType17) {
    $grogshopHtml = Model_HYGrogshop::getDocHtml(
        Model_HYGrogshop::getInfo($id),
        $form_info
    );
    $smarty->assign('grogshopHtml', $grogshopHtml);
    unset($form_info);
}
if ($paramType18) {
    $hourworkHtml = Model_HourlyWorker::getDocHtml(
        Model_HourlyWorker::getInfo($id),
        $form_info,
        $dom_detail_tmp_id
    );
    $hourworkUrl = '<a href="' . $form_info['url'] . '" class="SummaryList_but" style="display:block">' . $form_info['name'] . '</a>';

    if ($isFormLogin) {
        $hourworkUrl .= <<<EOT
    <script type="text/javascript">
        $(".SummaryList_but").on("click", function() {
            window.location.href = "{$form_info['url']}";
        });
    </script>
EOT;
    } else {
        $hourworkUrl .= <<<EOT
    <script type="text/javascript">
        $(".SummaryList_but").on("click", function() {
            alert(decodeHtmlEntity('{$LA['E_NinWeiDengLuQingDengLu']}!'));
            window.location.href = "/dom/denglu.php?username={$user_name}";
        });
    </script>
EOT;
    }

    $smarty->assign('hourworkUrl', $hourworkUrl);
    $smarty->assign('hourworkHtml', $hourworkHtml);
    unset($form_info);
}
if ($paramType19) {
    $roomorderHtml = Model_RoomOrder::getDocHtml(
        Model_RoomOrder::getInfo($id),
        $form_info,
        $dom_detail_tmp_id
    );
    $roomorderUrl = '<a href="###" class="SummaryList_but" style="display:block">' . $form_info['name'] . '</a>';

    if ($isFormLogin) {
        $roomorderUrl .= <<<EOT
    <script type="text/javascript">
        $(".SummaryList_but").on("click", function() {
            window.location.href = "{$form_info['url']}";
        });
    </script>
EOT;
    } else {
        $roomorderUrl .= <<<EOT
    <script type="text/javascript">
        $(".SummaryList_but").on("click", function() {
            alert(decodeHtmlEntity('{$LA['E_NinWeiDengLuQingDengLu']}!'));
            window.location.href = "/dom/denglu.php?username={$user_name}";
        });
    </script>
EOT;
    }

    $smarty->assign('roomorderHtml', $roomorderHtml);
    $smarty->assign('roomorderUrl', $roomorderUrl);
    unset($form_info);
}
// 规格参数
if ($paramType20 && $guige) {
    foreach ($guige as $k => $v) {
        $guige[$k]['value'] = array_intersect(
            $v['value'],
            explode('#', $v['default_val'])
        );

        $guige[$k]['firstValue'] = reset($guige[$k]['value']);

        $doc_arr['guigeIds'][] = $v['id'];
    }

    $doc_arr['guigeIds'] = implode('#', $doc_arr['guigeIds']);

    $buttonHtml = <<<EOT
      <a id="yuyueButton" class="SummaryList_but" style="display:inline-block; left:100px;"
        data-fail="1" data-id="0" data-url="{$form_info['url']}" href="###">{$form_info['name']}</a>
EOT;

    $guigeHtml = Model_Doc::guigeHtml(
        $guige,
        array(
            'buttonHtml'               => $buttonHtml,
            'guigeIds'                 => $doc_arr['guigeIds'],
            'id'                       => $doc_arr['id'],
            'price_unit'               => $doc_arr['price_unit'],
            'isFormLogin'              => $isFormLogin,
            'E_NinWeiDengLuQingDengLu' => $LA['E_NinWeiDengLuQingDengLu'],
        )
    );

    $smarty->assign('guigeHtml', $guigeHtml);
    $smarty->assign('guige',            $guige);
}

//获取文章的相关文章
$xiangguan_doc = $doc_arr['xiangguan_doc'];
if ($xiangguan_doc > 0) {
    if ($xiangguan_doc == 1) $tmp_r_doc = " big_id=" . $big_id;
    if ($xiangguan_doc == 2) $tmp_r_doc = " sub_id=" . $sub_id;
    $sql = "select * from ev_user_doc_content where  userid=" . $user_id . " and is_del=0 and channel_id=" . $channel_id . " and" . $tmp_r_doc . " and id !=" . $id . " order by id DESC limit 10";
    //print_r($sql);
    $relative_doc = $DB_User_Doc->get_results($sql);
    $relative_doc_list = get_new_doc_info($relative_doc, $model_id, $key, $user_name);
}

$res = explode(".", $doc_arr['doc_url']);
$res[count($res) - 1] = "swf";
$doc_arr['doc_url_swf'] = implode(".", $res);
if ($doc_arr['doc_url_swf']) {
    $tmp_str = str_replace('http://', '', trim($doc_arr['doc_url_swf']));
    $tmp_arr = explode('/', $tmp_str);
    $doc_arr['doc_url_swf_host'] = $tmp_arr[0];
}
$user_system = Model_Public::getRow('ev_user_system', 'userid=' . USER_ID);
$article_review = $user_system->article_review;
$guest_is_show = $user_system->guest_is_show;

//上一页和下一页
if ($doc_arr['is_next'] && !$is_show_guid) {
    Job_Doc::$user_name = $user_name;
    $pageArr = Job_Doc::getPreNext($doc_arr, $channel_id);
    $doc_arr['pre'] = $pageArr['preDoc'];
    $doc_arr['nex'] = $pageArr['nexDoc'];
}
//获取图片大图
$picArr = array('pic', 'pic2', 'pic3', 'pic4');
$picNums = 0;
foreach ($picArr as $key => $val) {
    if ($doc_arr[$val]) {
        $doc_arr[$val . '_small'] = Job_Pic::format(
            [
                'type'     => 11,
                'pic'      => $doc_arr[$val],
                'width'    => 90,
                'height'   => 90,
                'field'    => 'showPic',
                'sizeType'    => 1
            ]
        );
        $doc_arr[$val . '_big']   = Job_Pic::format(
            [
                'type'     => 11,
                'pic'      => $doc_arr[$val],
                'width'    => 280,
                'height'   => 210,
                'field'    => 'showPic',
                'sizeType'    => 1
            ]
        );
        $picNums++;
    }
}

if (defined('USER_USER_ID') && USER_USER_ID) {
    $sql1 = "select zf_state from ev_user_form_record where form_id=" . $form_info['formId'] . ' and user_user_id=' . USER_USER_ID . ' and zf_state=1 and doc_id=' . $doc_arr['id'];
    $orderInfo = $DB_Dom->get_row($sql1);
}

if (!$orderInfo['zf_state'] || !defined('USER_USER_ID')) {
    foreach ($user_param as $key => $val) {
        if (preg_match('/(.*?)联系(.*?)/', $val['name'])) {
            unset($user_param[$key]);
        }
    }
}

$smarty->assign('picNums', $picNums);
$smarty->assign('is_show_guid', $is_show_guid);
$smarty->assign('isFormLogin', $isFormLogin);
$smarty->assign('article_review', $article_review);
$smarty->assign('guest_is_show', $guest_is_show);
$smarty->assign('sub_name_arr', $sub_name_arr);
$smarty->assign('xiangguan_doc', $xiangguan_doc);
$smarty->assign('relative_doc_list', $relative_doc_list);
$smarty->assign('form_info', $form_info);
$smarty->assign('user_param', $user_param);
$smarty->assign('css_filename', $css_filename);
$smarty->assign("system_arr", $system_arr);
$smarty->assign('channel_info_arr', $channel_info);
$smarty->assign('channel_info_arr2', $channel_info11);
$smarty->assign('bottom_info_arr', $bottom_info_arr);
$smarty->assign('bottom_item_arr', $bottom_item_arr);
$smarty->assign('sub_class_arr', $sub_class_arr);
$smarty->assign('sub_class_arr2', $sub_class_arr2);
$smarty->assign('name', $name);
$smarty->assign('big_name', $big_name);
$smarty->assign('id', $doc_arr['id']);
$smarty->assign('sub_name', $sub_name);
$smarty->assign('doc_arr', $doc_arr);
$smarty->assign('doc_item', $doc_item);
$smarty->assign('channel_id', $channel_id);
$smarty->assign('big_id', $big_id);
$smarty->assign('sub_id', $sub_id);
$smarty->assign('user_name', $user_name);
$smarty->assign('guest_chan_id', $guest_chan_id);
$smarty->assign('line_jobs', $line_jobs);
$smarty->assign('ad_type1', $ad_type1);
$smarty->assign('big_class_arr', $big_class_arr);
$smarty->assign('sub_class_arr', $sub_class_arr);
$smarty->assign('ad_arr', $ad_arr);
$smarty->assign('map_xy', $map_xy);
$smarty->assign('back_str', $back_str);
if ($dec['detail_' . $model_id] == 'own_doc/44/') {
    $dec['detail_' . $model_id] = 'own_doc/40/';
}
$smarty->display($dec['detail_' . $model_id] . 'doc_detail.tpl');
