김재현

Merge branch 'master' of khuhub.khu.ac.kr:2013104063/open-source-project-2017-02

1 var express = require('express'); 1 var express = require('express');
2 -var mysql = require('mysql'); 2 +
3 var path = require('path'); 3 var path = require('path');
4 var favicon = require('serve-favicon'); 4 var favicon = require('serve-favicon');
5 var logger = require('morgan'); 5 var logger = require('morgan');
...@@ -11,12 +11,7 @@ var index = require('./routes/index'); ...@@ -11,12 +11,7 @@ var index = require('./routes/index');
11 var users = require('./routes/users'); 11 var users = require('./routes/users');
12 12
13 var app = express(); 13 var app = express();
14 -var connection = mysql.createConnection({ 14 +
15 - host : 'localhost',
16 - user : 'admin',
17 - password : 'admin',
18 - database : 'ossprojectdb'
19 -});
20 15
21 // view engine setup 16 // view engine setup
22 app.set('views', path.join(__dirname, 'views')); 17 app.set('views', path.join(__dirname, 'views'));
...@@ -54,24 +49,15 @@ app.use(function(err, req, res, next) { ...@@ -54,24 +49,15 @@ app.use(function(err, req, res, next) {
54 49
55 module.exports = app; 50 module.exports = app;
56 51
57 -/*
58 -var mysql = require('mysql');
59 -var connection = mysql.createConnection({
60 - host : 'localhost',
61 - user : 'admin',
62 - password : 'admin',
63 - database : 'ossprojectdb'
64 -});
65 -
66 52
67 -connection.connect();
68 53
69 -connection.query('SELECT * from users', function(err, rows, fields) {
70 - if (!err)
71 - console.log('The solution is: ', rows);
72 - else
73 - console.log('Error while performing Query.');
74 -});
75 54
76 - connection.end(); 55 +//
77 -*/ 56 +// connection.query('SELECT * from users', function(err, rows, fields) {
57 +// if (!err)
58 +// console.log('The solution is: ', rows);
59 +// else
60 +// console.log('Error while performing Query.');
61 +// });
62 +//
63 +// connection.end();
......
1 var express = require('express'); 1 var express = require('express');
2 +var mysql = require('mysql');
2 var router = express.Router(); 3 var router = express.Router();
3 4
5 +var connection = mysql.createConnection({
6 + host : 'localhost',
7 + user : 'root',
8 + password : 'qmfkdnsl',
9 + database : 'ossprojectdb'
10 +});
11 +
12 +connection.connect();
4 /* GET home page. */ 13 /* GET home page. */
5 router.get('/index', function(req, res, next) { 14 router.get('/index', function(req, res, next) {
6 res.render('index', { title: 'Express' }); 15 res.render('index', { title: 'Express' });
...@@ -13,15 +22,44 @@ router.get('/', function(req, res, next) { ...@@ -13,15 +22,44 @@ router.get('/', function(req, res, next) {
13 22
14 router.get('/map', function(req, res, next){ 23 router.get('/map', function(req, res, next){
15 24
16 - res.render('map', {title: '맛집 도장찍기'}); 25 + var user = {
26 + iduser : "abc",
27 + username : "김정은",
28 + password : "qmfkdnsl",
29 + email : "bfghg@naver.com"
30 +
31 + }
32 + res.render('map', {title: '맛집 도장찍기', user : user});
17 33
18 }); 34 });
35 +
19 router.get('/home', function(req,res,next){ 36 router.get('/home', function(req,res,next){
20 37
21 res.render('main', {title: '맛집견문록'}); 38 res.render('main', {title: '맛집견문록'});
22 }); 39 });
23 40
24 41
42 +router.post('/map', function(req, res){
43 +
44 +
45 + var tempuser ={
46 +
47 + 'idusers' : req.body.userid,
48 + 'address' : req.body.placeaddress,
49 + 'contendid' : req.body.placeid,
50 + 'title' : req.body.placename}
51 +
52 +
53 + console.log(tempuser);
54 + var query = connection.query('insert into users set ?',tempuser,function(err,result){
55 + if (err) {
56 + console.error(err);
57 + throw err;
58 + }
59 + console.log(query);
60 + });
61 +
62 +});
25 63
26 router.get('/mybook', function(req, res, next){ 64 router.get('/mybook', function(req, res, next){
27 65
...@@ -59,3 +97,4 @@ res.render('test', {title: 'test'}); ...@@ -59,3 +97,4 @@ res.render('test', {title: 'test'});
59 }); 97 });
60 98
61 module.exports = router; 99 module.exports = router;
100 +connection.end();
......
...@@ -6,6 +6,24 @@ ...@@ -6,6 +6,24 @@
6 <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBTR69UvS1403rvBcM64_8nlzpKLv23RIE&libraries=places"></script> 6 <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBTR69UvS1403rvBcM64_8nlzpKLv23RIE&libraries=places"></script>
7 <script> 7 <script>
8 8
9 + //표시하기 버튼 눌렀을 때 post보내는 함수
10 +
11 + function forming() {
12 +
13 +
14 + console.log(place)
15 +
16 +
17 + if(confirm("맛집견문록에 기록하겠습니까?")){
18 +
19 + document.forms["userform"].submit();
20 + return true;
21 + }else{
22 + return false;
23 + }
24 +
25 + }
26 +
9 27
10 function initMap(latitude, longitude) { 28 function initMap(latitude, longitude) {
11 var center = {lat: latitude, lng: longitude}; 29 var center = {lat: latitude, lng: longitude};
...@@ -59,15 +77,22 @@ ...@@ -59,15 +77,22 @@
59 '<h1 id="firstHeading" class="firstHeading">'+place.name+'</h1>'+ 77 '<h1 id="firstHeading" class="firstHeading">'+place.name+'</h1>'+
60 '<div id="bodyContent">'+ 78 '<div id="bodyContent">'+
61 '<p>주소: '+place.vicinity+'<br/>'+ 79 '<p>주소: '+place.vicinity+'<br/>'+
62 - '<a href="https://localhost:3000/id=' + place.id + '">'+ 80 + '<a href="#" onclick="forming();">'+
63 '표시하기</a> '+ 81 '표시하기</a> '+
64 '</p>'+ 82 '</p>'+
65 '</div>'+ 83 '</div>'+
66 '</div>'; 84 '</div>';
67 85
68 86
87 +
88 +
69 google.maps.event.addListener(marker1, 'click', function(e) { 89 google.maps.event.addListener(marker1, 'click', function(e) {
70 //console.log(place) 90 //console.log(place)
91 +
92 +
93 +
94 +
95 +
71 var infowindow = new google.maps.InfoWindow({ 96 var infowindow = new google.maps.InfoWindow({
72 content: contentString, 97 content: contentString,
73 maxWidth: 300 98 maxWidth: 300
...@@ -75,6 +100,13 @@ ...@@ -75,6 +100,13 @@
75 infowindow.open(map, this); 100 infowindow.open(map, this);
76 //marker1.setMap(null); 101 //marker1.setMap(null);
77 //marker2.setMap(map); 102 //marker2.setMap(map);
103 + console.log('<%=user.username%>');
104 +
105 +
106 +// console.log(document.getElementsByName('placeaddress').value);
107 +
108 +
109 +
78 }); 110 });
79 google.maps.event.addListener(marker2, 'click', function() { 111 google.maps.event.addListener(marker2, 'click', function() {
80 var infowindow = new google.maps.InfoWindow({ 112 var infowindow = new google.maps.InfoWindow({
...@@ -99,6 +131,8 @@ ...@@ -99,6 +131,8 @@
99 $nav.toggleClass('open'); 131 $nav.toggleClass('open');
100 }); 132 });
101 133
134 + $("input[name=first_name]");
135 +
102 if("geolocation" in navigator) { 136 if("geolocation" in navigator) {
103 navigator.geolocation.getCurrentPosition(function(position) { 137 navigator.geolocation.getCurrentPosition(function(position) {
104 //console.log(position.coords.latitude) 138 //console.log(position.coords.latitude)
...@@ -131,6 +165,16 @@ ...@@ -131,6 +165,16 @@
131 <div id ="content"> 165 <div id ="content">
132 <div id="map"></div> 166 <div id="map"></div>
133 <div id="popup"></div> 167 <div id="popup"></div>
168 + <div id="form">
169 + <form name="userform" method="POST" action="/map">
170 + <input type="hidden" name="userid"/>
171 + <input type="hidden" name="placeid"/>
172 + <input type="hidden" name="placename"/>
173 + <input type="hidden" name="placeaddress"/>
174 + </form>
175 +
176 +
177 + </div>
134 </div> 178 </div>
135 179
136 <div id ="footer"></div> 180 <div id ="footer"></div>
......