-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
247 lines (208 loc) · 7.63 KB
/
Copy pathmain.php
File metadata and controls
247 lines (208 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="skeleton.css">
<script src="javascript.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<meta charset = 'utf-8'>
</head>
<body>
<?php
$connect = mysqli_connect('localhost', 'tnwjd4623', '1q2w3e4r', 'tnwjd4623') or die ('connect fail');
//최신글 출력을 위한 구매 게시판, 판매 게시판 쿼리
$buy_query = "select * from board_buy order by number desc";
$sell_query = "select * from board_sell order by number desc";
$buy_result = $connect->query($buy_query);
$sell_result = $connect->query($sell_query);
$buy_total = mysqli_num_rows($buy_result);
$sell_total = mysqli_num_rows($sell_result);
$list = "select * from list where number=1";
$list_result = $connect->query($list);
$list_rows = mysqli_fetch_assoc($list_result);
$list_isbn = $list_rows['isbn'];
//네이버 API 호출
$client_id = "SFezXsTn6ehQdzFHwwp7"; //발급 받은 id
$client_secret = "KzKrnNFNu_"; //발급 받은 비밀 번호
$encText = urlencode($list_isbn);
//네이버 요청 쿼리
$url = "https://openapi.naver.com/v1/search/book.json?query=".$encText;
$is_post = false;
$ch = curl_init();
/*
접속할 url, 전송 메소드, 리턴 유무 옵션 세팅
*/
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-Naver-Client-Id: ".$client_id;
$headers[] = "X-Naver-Client-Secret: ".$client_secret;
/*
헤더 짖정, 인증서 검사 유무 세팅
*/
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
/*
exec 실행
*/
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
$img = $result[items][0][image];
?>
<header>
<div class="main_header">
<ul class="main_ul">
<li class="main_li"><img class="main_img" src="./book.PNG"></li>
<li class="main_li"><span class="main_text">webprogramming term proejct 2 <br/>201602042</span></li>
</ul>
</div>
<!-- 클릭시 페이지 이동-->
<div class="main_top">
<ul class="main_ul2">
<li class="main_li2" onclick="location.href='./sell.php'">Sell</li>
<li class="main_li2" onclick="location.href='./buy.php'">Buy</li>
<li class="main_li2" onclick="modal2()">책 추천</li>
</ul>
</div>
</header>
<!-- 회원가입 모달 창-->
<div class="modal" id="modal">
<div id="modal-content" class="modal-content">
<button id="Close" class="close" onclick="close_modal()">X</button>
<span> Join </span><br/>
<form method="get" action="join.php">
<span class="main_text2">Mail: </span><input name="email" class="main_input_email" type="email"><br/><br/>
<span class="main_text2">ID: </span><input name="id"class="main_input" type="text"><br/><br/>
<span class="main_text2">PW: </span><input name="pw"class="main_input" type ="password">
<br/><br/>
<input class="modal-content-button"type="submit" value="Join">
</form>
</div>
</div>
<!-- 책 추천 코달창 -->
<div class="modal2" id="modal2">
<div id="modal-content2" class="modal-content2">
<button id="Close2" class="close" onclick="close_modal2()">X</button>
<span> 랜덤 책추천 </span><br/>
<span><b>제목 :</b> <?=$list_rows['title'];?></span><br/>
<span><b>저자 :</b> <?=$result[items][0][author];?></span><br/><br/>
<span><img src="<?=$img?>" width="100" height="200"></span>
<span class="recommand"><?=$list_rows['content']?></span>
<iframe class="frame"width="500" height="400" src="<?=$list_rows['url'];?>" frameborder="0"></iframe>
</div>
</div>
<?php
//세션이 있으면 로그아웃, 세션이 없으면 로그인 폼 출력
session_start();
if(!isset($_SESSION['userid']))
{
?>
<!--로그인 폼 -->
<div class="main_login">
<span>Log in</span>
<form method = "get" action="login.php">
<span class="main_text2">ID: </span><input name="id" class="main_input" type="text"><br/>
<span class="main_text2">PW: </span><input name="pw"class="main_input" type = "password"><br/>
<input type="submit" value="login">
</form>
<br/><br/>
<span>회원이 아니신가요?</span>
<button id="join" onclick="modal()">Join</button>
</div>
<?php }
else {
?>
<!--로그인 성공시 -->
<div class="main_login">
<span>안녕하세요
<?=$_SESSION['userid']?>님</span>
<button id="logout" onclick="location.href='./logout.php'">로그아웃</button>
</div>
<?php }
?>
<!-- 최신 판매, 구매 글-->
<div class="main_wrap">
<ul class="main_ul3">
<li class="main_li3">
<div class="main_new">
최신 판매글
<table class="main_table">
<?php $total = 1;
if($sell_total > 5){ //글은 최대 5개까지 보여진다
while($rows = mysqli_fetch_assoc($sell_result)) {
if($total>5) break;
if($total%2==0) {
?> <tr class="main_tr_even">
<?php }
else {
?> <tr>
<?php }
?> <td class="main_td"><a href='./view.php?type=0&number=<?php echo $rows['number'];?>'><?php echo $rows['title']?></a></td>
<td class="main_td"><span class="main_date"><?php echo $rows['date'];?></span></td>
</tr>
<?php $total++;
}
}
else {
while($rows = mysqli_fetch_assoc($sell_result)) {
if($total%2==0) {
?> <tr class="main_tr_even">
<?php }
else {
?> <tr>
<?php }
?>
<td class="main_td"><a href="./view.php?type=0&number=<?php echo $rows['number'];?>"><?php echo $rows['title']?></a></td>
<td class="main_td"><span class="main_date"><?php echo $rows['date'];?></span></td>
</tr>
<?php $total++;
}
}
?>
</table>
</div>
</li>
<li class="main_li3">
<div class="main_new">
최신 구매글
<table class="main_table">
<?php $total = 1;
if($buy_total > 5){
while($rows = mysqli_fetch_assoc($buy_result)) {
if($total>5) break;
if($total%2==0){
?> <tr class="main_tr_even">
<?php }
else {
?> <tr>
<?php }
?> <td><a href='./view.php?type=1&number=<?php echo $rows['number'];?>'><?php echo $rows['title']?></a></td>
<td class="main_td"><span class="main_date"><?php echo $rows['date'];?></span></td>
</tr>
<?php $total++;
}
}
else {
while($rows = mysqli_fetch_assoc($buy_result)) {
if($total%2==0){
?> <tr class="main_tr_even">
<?php }
else{
?> <tr>
<?php }
?>
<td class="main_td"><a href="./view.php?type=1&number=<?php echo $rows['number'];?>"><?php echo $rows['title']?></a></td>
<td class="main_td"><span class="main_date"><?php echo $rows['date'];?></span></td>
</tr>
<?php $total++;
}
}
?>
</table>
</div>
</li>
</div>
</body>
</html>