소스 파일 : /view/view_utils.php (2020-11-29)     소스 설명 : (용어보기) ... 작성중
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php // (2020.11.29, 차재복, Cha Jae Bok, cjbword@gmailcom) 

function multi_path_rows($id,$m_temp1,$dbi) {

# 해당 no 및 id 유무 별로 multi cur_path 찾기
	// 용어 항목
//	if (!empty($m_temp1) and !empty($id)) {
	if (!empty($m_temp1) ) {
		$query = "select id,path2node from (select no,tree_id from book_idx where no=$m_temp1) a left join gubun_tree_v2 b on a.tree_id=b.id";
		$result=mysqli_query($dbi,$query);
			if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
		$multi_rows=array();
		while ( $matched=mysqli_fetch_assoc($result) ) {
			if (!empty($id) and $id == $matched[id]) { 
				array_unshift($multi_rows,$matched);
			} else {
				$multi_rows[] = $matched;
			}
		}

	// 분류 항목 (1개)
	} else if (empty($m_temp1) and !empty($id)) {
//		$query = "select id,path2node from gubun_tree_v2 where id=$id";
		$query = "select id,concat('0,',replace(substring_index(getpath_v2(id),'|',-1),'::',',')) as path2node from gubun_tree_v2 where id=$id";
		$result=mysqli_query($dbi,$query);
			if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
		$matched=mysqli_fetch_assoc($result);
		$multi_rows[0] = $matched;

	// 에러 방지
	} else if (empty($m_temp1) and empty($id)) {
		$multi_rows[0] = array('id'=>0,'path2node'=>'0');
	}

// echo 'count($multi_rows)='.count($multi_rows)."<br>";
// echo "<pre>";print_r($multi_rows);echo "</pre>";
	return $multi_rows;

}


# 각 id별 세부 용어 항목명 보이기
function detail_items_display($id,$temp,$m_temp1,$dbi,$choice) {

		$query="select titlename,no,list_ord,tree_id as id from book_idx where tree_id=$id order by list_ord, titlename";
		$result = mysqli_query($dbi,$query);
		$cnt = mysqli_num_rows($result);
		$n=1;
		while ( $matched=mysqli_fetch_assoc($result) ) {
            if(!empty($choice)) {
			    echo ($choice=='contents' ? "&nbsp;&nbsp;&nbsp;" : "&nbsp;");
    			echo " $n. ";
	    		if ( $matched[no] == $m_temp1 ) echo "<b>";
		    		echo "<a href='view.php?nav=2&id=".$id."&m_temp1=".$matched[no]."'>";
			    		echo $matched[titlename];
				    echo "</a>";
    			if ( $matched[no] == $m_temp1 ) echo "</b>";
	    		echo "<br>";
            }
			$arr[] = array('no'=>$matched[no],'titlename'=>$matched[titlename]);
			$n=$n+1;
		}
		return $arr;
}


function db_qry ($cur_path,$cur_id,$dbi) {

// echo '$cur_path='.$cur_path."<br>";

# 쿼리문
	// 각 레별별 해당 노드들 쿼리
	$query = "select a.id,a.parent,a.sub_seq,a.name,a.linked_num,@path:=getpath_v2(a.id),
					@pre_ord:=substring_index(substring_index(@path,'|',2),'|',-1) as pre_ord, 
					char_length(@pre_ord)-char_length(replace(@pre_ord,'.','')) as depth,
					substring_index(@path,'|',-1) as path_id,
					substring_index(substring_index(@path,'|',-2),'|',1) as path_str
					,count(b.id) as sub_cnt
				from gubun_tree_v2 a 
					left join gubun_tree_v2 b on a.id=b.parent
				where a.id<>0 and a.parent in (".$cur_path.")
				group by a.id
				order by pre_ord"
				;

		$result=mysqli_query($dbi,$query);
			if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}

		$prev=1; $i=0;
		while ( $matched = mysqli_fetch_assoc($result) ) {

			// 쿼리 결과 레코드를 배열화
			$set[] = $matched;

			// $set에서 현재 $cur_id의 배열 index 확인
			if ($cur_id == $matched[id]) $cur_row = $matched;

			// cur_path 항목별로, 직속 자식들 별도 array 확보
			if ( strpos($cur_path.',',$matched[parent].',') !== false ) {
				$per_parent_rows[$matched[parent]][] = $matched;
			} 
			// 마지막 cur_id도 포함
//			if ($matched[id]==$cur_id and $matched[depth]) $per_parent_rows[$matched[id]][] = $matched;

			$i=$i+1;
		}
//echo $cur_id."<br>";
//echo $cur_path."<br>";
//echo 'count($per_parent_rows)='.count($per_parent_rows)."<br>";

//		return array('set' => $set, 'cur_idx' => $cur_idx, 'parent_idx_list' => $parent_idx_list);
		return array('set' => $set, 'cur_row'=> $cur_row,'per_parent_rows' => $per_parent_rows);

}

# 각 path별 1 라인 출력
function path2line ($per_parent_rows,$row,$m_temp1,$dbi) {

		// path to node 의 id,str 추출
		$pid_list = explode('::',$row[path_id]);
		array_unshift($pid_list,'0'); // 루트 id도 포함시킴
		$pstr_list = explode('::',$row[path_str]);
		array_unshift($pstr_list,'Top'); // 루트 str도 포함시킴

		// path to node ( Top > 타이틀1 > ... ) 형태로 Tooltip 구현
				for ($i=0;$i<=$row[depth];$i++) {
					echo "<span class='sub_list_container'>";

						// ( Top > 타이틀1 > ... ) 형태로 클릭 대상 보여줌
						echo "<a href='view.php?nav=2&id=".$pid_list[$i]."'  >";
							echo $pstr_list[$i];
						echo "</a>";
						if ($i<$row[depth]) echo " > ";

						// Tooltip
							echo "<span class='sub_list_text'>"; 
								if ($row[linked_num] > 0) {
									$temp_arr = detail_items_display($pid_list[$i],$num,$m_temp1,$dbi,"path");
									if ($i==$row[depth]) $cur_sub_list = $temp_arr;
								}
								if (count($per_parent_rows[$pid_list[$i]]) > 0) {
									foreach($per_parent_rows[$pid_list[$i]] as $key => $value) {
										echo " [<a href='view.php?nav=2&id=".$value[id]."'	>".$value[name]."</a>]";
										echo "<br>";
									}
								}
							echo "</span>";
//						}
					echo "</span>";
				}
		return $cur_sub_list;
}


?>


Copyrightⓒ written by 차재복 (Cha Jae Bok)
"본 웹사이트 내 모든 저작물은 원출처를 밝히는 한 자유롭게 사용(상업화포함) 가능합니다"