<?
$SES_MEMBER_ID = $this->session->userdata('C_Member_Id');
$title = '';
$content = '';
$main_img = '';

$arr_search_keyword = array();
if ($search_keyword != '') {
	$arr_search_keyword = explode(" ", $search_keyword);
}

?>


<div class="contents">
	<div class="wrap">
		<? if ($total_count == 0) { ?>
			<div class="list_left">
				<div id="search" style="border-bottom: 0;">
					<div class="search_articles">
						<div id="notfound" class="noresult_type3">
							<div class="not_found02">
								<p>
									<em>'<?= $search_keyword ?>'</em>에 대한 검색결과가 없습니다.
								</p>
								<ul>
									<li>단어의 철자가 정확한지 확인해 보세요.</li>
									<li>한글을 영어로 혹은 영어를 한글로 입력했는지 확인해 보세요.</li>
									<li>검색어의 단어 수를 줄이거나, 보다 일반적인 검색어로 다시 검색해 보세요.</li>
									<li>두 단어 이상의 검색어인 경우, 띄어쓰기를 확인해 보세요.</li>
									<li>검색 옵션을 변경해서 다시 검색해 보세요.</li>
								</ul>
							</div>
						</div>
					</div>
				</div>
			</div>


		<? 	} else { ?>

			<div class="list_left">
				<div id="search">
					<? if (count($arr_search_keyword_relation) > 0) { ?>
						<div class="search_result">
							<div class="related_tit">관련</div>
							<div class="related_names">
								<? foreach ($arr_search_keyword_relation as $val) { ?>
									<a href="/web/search/?search_keyword=<?= $val['relation_keyword'] ?>"><?= $val['relation_keyword'] ?></a>
								<?	} ?>
							</div>
						</div>


					<?	} ?>

					<div class="search_articles">
						<? if (count($arr_life) > 0) { ?>

							<div class="search_cate">라이프</div>
							<?

							$i = 1;
							foreach ($arr_life as $key => $val) {
								$title = $val['title'];
								$content = strip_tags($val['content']);

								$title_txt = mb_strimwidth($title, '0', '60', '..', 'utf-8');
								$content_txt = mb_strimwidth($content, '0', '180', '..', 'utf-8');

								foreach ($arr_search_keyword as $val3) {
									$title_txt = str_replace($val3, '<b>' . $val3 . '</b>', $title_txt);
									$content_txt = str_replace($val3, '<b>' . $val3 . '</b>', $content_txt);
								}

								$display_date_txt = gf_article_date_text($val['display_date']);

								$share_title = str_replace("'", "\\'", $val['title']);
								$share_title = str_replace('"', '\\"', $share_title);
								$share_content = mb_strimwidth($content, '0', '250', '..', 'utf-8');
								$share_content = htmlspecialchars($share_content);
								$share_content = str_replace("'", "\\'", $share_content);
								$share_content = str_replace('”', '"', $share_content);

								$main_img = $val['main_img'];

								$life_class = '';
								if ($i == count($arr_life)) {
									$life_class = ' bb pdb20';
								}

							?>
								<div class="search_wrap<?= $life_class ?>">
									<input type="hidden" name="content_life_<?= $val['idx'] ?>" id="content_life_<?= $val['idx'] ?>" value="<?= $share_content ?>"> <input type="hidden" name="title_life_<?= $val['idx'] ?>" id="title_life_<?= $val['idx'] ?>" value="<?= $share_title ?>"> <input type="hidden" name="copy_url_life_<?= $val['idx'] ?>" id="copy_url_life_<?= $val['idx'] ?>" value="<?= WWW_CROSSMAP ?>/web/life/life_view/<?= $val['idx'] ?>"> <input type="hidden" name="img_url_life_<?= $val['idx'] ?>" id="img_url_life_<?= $val['idx'] ?>" value="<?= WWW_CROSSMAP ?><?= $main_img ?>"> <span class="search_img" onclick="location.href='/web/life/life_view/<?= $val['idx'] ?>'" style="cursor:pointer;width:137px;height:94px;background:url('<?= $val['main_img'] ?>') no-repeat center; background-size:cover;"></span>
									<h2 class="search_tit">
										<a href="/web/life/life_view/<?= $val['idx'] ?>"><?= $title_txt ?></a><span class="search_date"><?= $display_date_txt ?><span class="img_direct"><img src="/img/web/img_direct.gif" style="cursor: pointer" class="share_btn" strA="life_<?= $val['idx'] ?>"></span></span>
									</h2>
									<div class="search_txt">
										<?= $content_txt ?>
										<div class="search_info">
											<span class="profile"><a href="/web/life/editor/<?= $val['partner_idx'] ?>">
													<div style="float:left;border-radius: 21px;cursor:pointer;width:21px;height:21px;background:url('<?= $val['partner_img'] ?>') no-repeat center; background-size:cover;"></div>&nbsp;&nbsp;<?= $val['editor_name'] ?>
												</a></span>
											<span><img src="/img/web/search_bar.gif"></span> <span><img src="/img/web/img_heart.gif"><?= number_format($val['like_count']) ?></span>
											<span><img src="/img/web/search_bar.gif"></span> <span><img src="/img/web/img_comment.gif"><?= number_format($val['comment_count']) ?></span>
										</div>
										<? if ($i == count($arr_life)) { ?>
											<div class="s_seeall fr">
												<a href="/web/search/list?search_keyword=<?= $search_keyword ?>&content_type=3">라이프
													더보기<img src="/img/web/mypage_arrow_right.gif">
												</a>
											</div>
										<?	} ?>
									</div>
								</div>
							<?

								$i++;
							}
							?>

						<?	} ?>

						<? if (count($arr_news) > 0) { ?>
							<ul class="search_cate2">
								<li class="search_cate">뉴스</li>
							</ul>
							<?

							$i = 1;
							foreach ($arr_news as $key => $val) {
								$news_class = '';
								if ($i == count($arr_news)) {
									$news_class = 'bb pdb20';
								}

								$title = $val['title'];
								$content = strip_tags($val['content']);
								$title_txt = mb_strimwidth($title, '0', '60', '..', 'utf-8');
								$content_txt = mb_strimwidth($content, '0', '180', '..', 'utf-8');
								foreach ($arr_search_keyword as $val3) {
									$title_txt = str_replace($val3, '<b>' . $val3 . '</b>', $title_txt);
									$content_txt = str_replace($val3, '<b>' . $val3 . '</b>', $content_txt);
								}

								$share_title = str_replace("'", "\\'", $val['title']);
								$share_title = str_replace('"', '\\"', $share_title);
								$share_content = mb_strimwidth($content, '0', '250', '..', 'utf-8');
								$share_content = htmlspecialchars($share_content);
								$share_content = str_replace("'", "\\'", $share_content);
								$share_content = str_replace('”', '"', $share_content);

								$press_txt = $val['press_name'];
								if ($val['press_homepage'] != '') {
									$press_txt = '<a href="' . $val['press_homepage'] . '" target="_blank">' . $val['press_name'] . '</a>';
								}
								$display_date_txt = gf_article_date_text($val['display_date']);

							?>
								<div class="search_wrap <?= $news_class ?>">
									<input type="hidden" name="content_news_<?= $val['idx'] ?>" id="content_news_<?= $val['idx'] ?>" value="<?= $share_content ?>"> <input type="hidden" name="title_news_<?= $val['idx'] ?>" id="title_news_<?= $val['idx'] ?>" value="<?= $share_title ?>"> <input type="hidden" name="copy_url_news_<?= $val['idx'] ?>" id="copy_url_news_<?= $val['idx'] ?>" value="<?= WWW_CROSSMAP ?>/web/news/news_view/<?= $val['idx'] ?>"> <input type="hidden" name="img_url_news_<?= $val['idx'] ?>" id="img_url_news_<?= $val['idx'] ?>" value="<?= WWW_CROSSMAP ?><?= $main_img ?>"> <span class="search_img" onclick="location.href='/web/news/news_view/<?= $val['idx'] ?>'" style="cursor:pointer;width:137px;height:94px;background:url('<?= $val['main_img'] ?>') no-repeat center; background-size:cover;"></span>
									<div class="search_box">
										<h2 class="search_tit">
											<a href="/web/news/news_view/<?= $val['idx'] ?>"><?= $title_txt ?></a>
										</h2>
										<div class="search_info">
											<span><?= $press_txt ?></span> <span><img src="/img/web/search_bar.gif"></span> <span><?= $display_date_txt ?></span>
											<span><img src="/img/web/search_bar.gif"></span> <span><a href="/web/news/news_view/<?= $val['idx'] ?>">크로스맵뉴스</a></span> <span class="img_direct"><img src="/img/web/img_direct.gif" style="margin-top: 0 !important" style="cursor: pointer" class="share_btn" strA="news_<?= $val['idx'] ?>"></span>
										</div>
										<div class="search_txt">
											<?= $content_txt ?>
											<?

											if (count($arr_news_relation_article[$val['idx']]) > 0) {
											?>
												<?

												foreach ($arr_news_relation_article[$val['idx']] as $key1 => $val1) {

													$relation_title_txt = mb_strimwidth($val1['title'], '0', '55', '..', 'utf-8');
													$press_txt = $val1['press_name'];
													if ($val1['press_homepage'] != '') {
														$press_txt = '<a href="' . $val1['press_homepage'] . '" target="_blank">' . $val1['press_name'] . '</a>';
													}

													$display_date_txt = gf_article_date_text($val1['display_date']);

												?>
													<div class="search_info">
														<span class="s_reply"><img src="/img/web/search_reply.gif"><a href="/web/news/news_view/<?= $val1['idx'] ?>"><?= $relation_title_txt ?></a></span>
														<span><?= $press_txt ?></span> <span style="margin-right: 2px;"><img src="/img/web/search_bar.gif"></span> <span><?= $display_date_txt ?></span>
														<span style="margin-right: 2px;"><img src="/img/web/search_bar.gif"></span> <span><a href="/web/news/news_view/<?= $val1['idx'] ?>">크로스맵뉴스</a></span>

													</div>

												<?

													if ($key1 == 1)
														break;
												}
												?>


												<div class="search_all" style="margin-top: 5px;">
													<a href="/web/search/news?search_keyword=<?= $search_keyword ?>&content_idx=<?= $val['idx'] ?>" style="color: #767676">관련뉴스 <?= count($arr_news_relation_article[$val['idx']]) ?>건 전체보기&gt;</a>
												</div>
											<?	} ?>
										</div>
									</div>
									<? if ($i == count($arr_news)) { ?> <div class="s_seeall fr">
											<a href="/web/search/news?search_keyword=<?= $search_keyword ?>&content_type=1">뉴스
												더보기<img src="/img/web/mypage_arrow_right.gif">
											</a>
										</div><? } ?>

								</div>

							<?

								$i++;
							}
							?>

						<?	} ?>



						<!--div class="search_wrap bb pdb20">
							<div class="search_cate">위키 </div>

							<div class="search_wrap ">
								<?php
									foreach($wikiResult as $wiki) {
																		?>
									<div class="search_box" style="width:100%">
										<h2 class="search_tit">
											<a href="https://en.wikipedia.org/wiki/<?php echo str_replace(' ', '_', $wiki->title)?>" target="_blank"><?php echo $wiki->title?></a>
										</h2>

										<div class="search_txt">
										<?php echo $wiki->snippet?>
										</div>

									</div>
									<? } ?>
							</div>


						</div-->




						<div class="search_wrap bb pdb20">
							<div class="search_cate">이미지</div>
							<div class="video_box">
								<?

								foreach ($arr_img as $key => $val) {
									$title_text = $val['title'];
									if ($val['category_name'] != '')
										$title_text .= ' - ' . $val['category_name'];

									switch ($val['content_type']) {
										case '1':
											$img_view_url = '/web/news/news_view/' . $val['idx'];
											break;
										case '2':
											$img_view_url = '/web/news/column_view/' . $val['idx'];
											break;
										case '3':
											$img_view_url = '/web/life/life_view/' . $val['idx'];
											break;
									}

								?>
									<div class="video_list">
										<span class="photo"><a href="<?= $img_view_url ?>" title="<?= $title_text ?>">
												<p style="cursor:pointer;width:137px;height:94px;background:url('<?= $val['main_img'] ?>') no-repeat center; background-size:cover;"></p>
											</a><span class="img_spam_check_box" style="display: none;"><input type="checkbox" class="report" name="is_img_spam_check[]" value="<?= $val['content_type'] ?>_<?= $val['idx'] ?>" id="is_img_spam_check_<?= $val['content_type'] ?>_<?= $val['idx'] ?>" style="display: inline;" style="display:none"></span></span>
									</div>

								<?

									if ($key == 4)
										break;
								}
								?>

							</div>
							<div class="s_seeall fr">
								<a href="/web/search/image?search_keyword=<?= $search_keyword ?>">이미지
									더보기<img src="/img/web/mypage_arrow_right.gif">
								</a>
							</div>

						</div>

						<? if (count($arr_video) > 0) { ?>
							<div class="search_wrap bb pdb20">
								<div class="search_cate">동영상</div>

								<div class="video_box cm_earch_video">
									<?

									foreach ($arr_video as $key => $val) {
										$title_txt = mb_strimwidth($val['title'], '0', '35', '..', 'utf-8');
										switch ($val['content_type']) {
											case '1':
												$video_view_url = '/web/news/news_view/' . $val['idx'];
												$video_category_url = '/web/news/category/' . $val['category_code'];
												break;
											case '2':
												$video_view_url = '/web/news/column_view/' . $val['idx'];
												$video_category_url = '/web/news/columnist/' . $val['partner_idx'];
												break;
											case '3':
												$video_view_url = '/web/life/life_view/' . $val['idx'];
												$video_category_url = '/web/life/category/' . $val['category_idx'];
												break;
										}

										$display_date_txt = gf_article_date_text($val['display_date']);
									?>

										<div class="video_list">
											<span class="play"><a href="<?= $video_view_url ?>"><img src="/img/web/img_play.png"></a></span> <span class="playtime2"><?= $val['video_playtime'] ?></span> <span class="photo"><a href="<?= $video_view_url ?>">
													<p style="cursor:pointer;width:137px;height:94px;background:url('<?= $val['main_img'] ?>') no-repeat center; background-size:cover;"></p>
												</a><span class="video_spam_check_box" style="display: none;"><input type="checkbox" class="report" name="is_video_spam_check[]" value="<?= $val['content_type'] ?>_<?= $val['idx'] ?>" id="is_video_spam_check_<?= $val['content_type'] ?>_<?= $val['idx'] ?>" style="display: inline;" style="display:none"></span></span> <span class="tit"><a href="<?= $video_view_url ?>"><?= $title_txt ?></a>
												<span><img src="/img/web/search_bar.gif"> <?= $display_date_txt ?></span></span>
											<div class="search_info">
												<img src="/img/web/img_arrow.gif"><a href="<?= $video_category_url ?>"> <?= $val['category_name'] ?></a>
											</div>
										</div>

									<?	} ?>

								</div>
								<div class="s_seeall fr">
									<a href="/web/search/video?search_keyword=<?= $search_keyword ?>">동영상
										더보기<img src="/img/web/mypage_arrow_right.gif">
									</a>
								</div>

							</div>
						<?	} ?>

						<? if (count($arr_column) > 0) { ?>
							<div class="search_cate">칼럼</div>

							<?
							$i = 1;
							foreach ($arr_column as $val) {
								$column_class = '';
								if ($i == count($arr_column)) {
									$column_class = ' bb pdb20';
								}

								$title = '[' . $val['column_name'] . '] ' . $val['title'];
								$content = strip_tags($val['content']);

								$title_txt = mb_strimwidth($title, '0', '60', '..', 'utf-8');
								$content_txt = mb_strimwidth($content, '0', '180', '..', 'utf-8');

								foreach ($arr_search_keyword as $val3) {
									$title_txt = str_replace($val3, '<b>' . $val3 . '</b>', $title_txt);
									$content_txt = str_replace($val3, '<b>' . $val3 . '</b>', $content_txt);
								}

								$display_date_txt = gf_article_date_text($val['display_date']);

								$share_title = str_replace("'", "\\'", $val['title']);
								$share_title = str_replace('"', '\\"', $share_title);

								$share_content = mb_strimwidth($content, '0', '250', '..', 'utf-8');
								$share_content = htmlspecialchars($share_content);
								$share_content = str_replace("'", "\\'", $share_content);
								$share_content = str_replace('”', '"', $share_content);

								$main_img = $val['main_img'];

							?>
								<div class="search_wrap<?= $column_class ?>">
									<input type="hidden" name="content_column_<?= $val['idx'] ?>" id="content_column_<?= $val['idx'] ?>" value="<?= $share_content ?>">
									<input type="hidden" name="title_column_<?= $val['idx'] ?>" id="title_column_<?= $val['idx'] ?>" value="<?= $share_title ?>"> <input type="hidden" name="copy_url_column_<?= $val['idx'] ?>" id="copy_url_column_<?= $val['idx'] ?>" value="<?= WWW_CROSSMAP ?>/web/news/column_view/<?= $val['idx'] ?>">
									<input type="hidden" name="img_url_column_<?= $val['idx'] ?>" id="img_url_column_<?= $val['idx'] ?>" value="<?= WWW_CROSSMAP ?><?= $main_img ?>"> <span class="search_img" onclick="location.href='/web/news/column_view/<?= $val['idx'] ?>'" style="cursor:pointer;width:137px;height:94px;background:url('<?= $val['main_img'] ?>') no-repeat center; background-size:cover;"></span>
									<h2 class="search_tit">
										<a href=/web/news/column_view/<?= $val['idx'] ?>""><?= $title_txt ?> </a> <span class="search_date"><?= $display_date_txt ?><span class="img_direct"><img src="/img/web/img_direct.gif" style="cursor: pointer" class="share_btn" strA="column_<?= $val['idx'] ?>"></span></span>
									</h2>
									<div class="search_txt"><?= $content_txt ?></div>
									<div class="search_info search_url">
										<a href="/web/news/column_view/<?= $val['idx'] ?>"><?= WWW_CROSSMAP ?>/web/news/column_view/<?= $val['idx'] ?></a>
									</div>

									<? if ($i == count($arr_column)) { ?> <div class="s_seeall fr">
											<a href="/web/search/list?search_keyword=<?= $search_keyword ?>&content_type=2">칼럼
												더보기<img src="/img/web/mypage_arrow_right.gif">
											</a>
										</div><? } ?>
								</div>

							<?

								$i++;
							}
							?>

						<?	} ?>

						<? require_once(APPPATH . "views/web/search/search_footer_inc.php"); ?>

					</div>
				</div>
			</div>


		<? 	} ?>

		<? require_once(APPPATH . 'views/web/news/news_right_inc.php'); ?>


	</div>
</div>
<? require_once(APPPATH . "views/web/comm/share_box_inc.php"); ?>
<script>
	var share_key = '';
	$('.share_btn').click(function(e) {
		$("#share_box").toggle();
		var key = $(this).attr('strA');

		$("#share_content").val($("#content_" + key).val());
		$("#share_title").val($("#title_" + key).val());
		$("#share_copy_url").val($("#copy_url_" + key).val());
		$("#share_img_url").val($("#img_url_" + key).val());
		$("#copy_url").val($("#copy_url_" + key).val());

		var popH = $(this).offset().top;
		var popL = $(this).offset().left;

		$('.popup_share').css('left', popL - 160 + 'px');
		$('.popup_share').css('top', popH - 200 + 'px');

		share_key = key;

	});




	function bookmark() {
		if ("<?= $SES_MEMBER_ID ?>" == "") {
			alert("로그인 후에 이용가능합니다.");
			return;
		}
		var str_temp = share_key.split('_');
		var content_type = '';
		if (str_temp[0] == 'column') {
			content_type = '2';
		} else if (str_temp[0] == 'news') {
			content_type = '1';
		} else if (str_temp[0] == 'life') {
			content_type = '3';
		}

		var form_data = {
			"content_idx": str_temp[1],
			"content_type": content_type
		};
		$.ajax({
			url: '/web/comm/bookmark_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function(rtnJson) {
				if (rtnJson.code == "0000") {
					$("#share_box").hide();
				} else {
					alert("북마크에 실패했습니다.");
					return false;
				}
			},
			error: function(rtnJson) {
				alert('북마크에 실패했습니다.');
				return false;
			}
		});

	}
</script>