Mercurial > hg > LGMap
annotate get_coordinates_for_listed_books.php @ 6:30b59e7b88c0
add php error log
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 25 Jun 2015 17:47:11 +0200 |
parents | b85894a9b2dc |
children |
rev | line source |
---|---|
0 | 1 <?php |
1
de2c442b6cbb
config to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
2 include_once('config/Lib_mb_utf8.php'); |
de2c442b6cbb
config to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
3 include_once('config/config.php'); |
0 | 4 |
5 set_time_limit(0); | |
6 ini_set('memory_limit', '-1'); | |
7 | |
8 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
9 mysql_query("SET NAMES utf8"); | |
10 | |
11 if (!$link_mysql) { | |
12 die('Could not connect: ' . mysql_error()); | |
13 } | |
14 | |
15 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
16 if (!$db_selected) { | |
17 die ('Can\'t use foo : ' . mysql_error()); | |
18 } | |
19 | |
20 function readCsvFile($fileName){ | |
1
de2c442b6cbb
config to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
0
diff
changeset
|
21 global $server_host; |
6 | 22 |
23 if ($fp = fopen($server_host."LGSearch/csv_files/".$fileName,"r") ) { | |
24 | |
25 // $fp=fopen($server_host."LGSearch/csv_files/".$fileName,"r"); | |
0 | 26 $data=fgetcsv($fp); |
6 | 27 $columnNameMappingArray=['BOOK_ID','LEVEL1','LEVEL2', |
28 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','PAGE','SECTION','CONTENT', | |
29 'Description']; //columns from input array/file | |
30 $columnNameArray=['Address','LEVEL1','LEVEL2', | |
31 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude', | |
32 'PAGE','SECTION','CONTENT', | |
33 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; //columns for output array/file (for map.php) | |
34 /* | |
35 $columnNameArray=['Address','ADMIN_TYPE','LEVEL1','LEVEL2', | |
36 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude', | |
37 'PAGE','SECTION','CONTENT', | |
38 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; //columns for output array/file (for map.php) | |
39 */ | |
40 $columnNameArray=array_flip($columnNameArray); //key, value swap in order to keep the order of the columns after merge | |
41 $bookArray=array(); | |
42 $count=0; | |
43 $line=0; | |
44 while(!feof($fp)){ | |
45 $data=fgetcsv($fp); | |
46 if(sizeof($data)<sizeof($columnNameMappingArray)){ | |
47 continue; | |
48 } | |
49 ///$bookId=$data[0]; | |
50 foreach($columnNameMappingArray as $idx=>$newName){ //use column names as the array indices (instead of 0,1,2,... as from $data) | |
51 $bookInfo[$newName]=$data[$idx]; | |
52 } | |
53 $bookId=$bookInfo['BOOK_ID']; | |
54 $coordinateArray=getCoordinateFromDatabase($bookId); | |
55 foreach($coordinateArray as $coordinate){ //merge a record from $booArray and ots cooresponding coordinateArray | |
56 $bookArray[$count]=array_merge($bookInfo,$coordinate); | |
57 $bookArray[$count]=array_merge($columnNameArray,$bookArray[$count]); | |
58 $count++; | |
59 } | |
0 | 60 } |
6 | 61 fclose($fp); |
62 | |
63 } else { | |
64 // file open failed | |
65 error_log("error when opening file: ".$server_host."LGSearch/csv_files/".$fileName, 0); | |
66 return array(); | |
0 | 67 } |
6 | 68 |
0 | 69 return $bookArray; |
70 } | |
71 function writeCsvFile($fileName,$bookArray){ | |
2
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
72 /* |
0 | 73 $columnNameArray=['Address','ADMIN_TYPE','LEVEL1','LEVEL2', |
74 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude', | |
75 'PAGE','SECTION','CONTENT', | |
76 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; | |
2
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
77 */ |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
78 $columnNameArray=['Address','LEVEL1','LEVEL2', |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
79 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','Longitude','Latitude', |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
80 'PAGE','SECTION','CONTENT', |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
81 'BOOK_ID','CHGIS_ID','1820_ID','1911_ID','CBDB_ID','Description']; |
6 | 82 |
83 if ($fp=fopen("./datasets/".$fileName,"w")) { | |
84 | |
85 //$fp=fopen("./datasets/".$fileName,"w"); | |
86 fputcsv($fp,$columnNameArray); | |
0 | 87 |
6 | 88 foreach($bookArray as $book){ |
89 fputcsv($fp,$book); | |
90 } | |
91 fclose($fp); | |
92 } else { | |
93 error_log("error when opening file: "."./datasets/".$fileName, 0); | |
0 | 94 } |
6 | 95 |
0 | 96 } |
97 function getCoordinateFromDatabase($bookId){ | |
2
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
98 /* |
0 | 99 $query="SELECT place_name AS Address, admin_type AS ADMIN_TYPE, x AS Longitude, y AS Latitude, |
100 chgis_id AS CHGIS_ID, 1820_id AS 1820_ID, 1911_id AS 1911_ID, cbdb_id AS CBDB_ID | |
101 FROM coordinates_books | |
102 WHERE books_id='".$bookId."'"; | |
2
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
103 */ |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
104 $query="SELECT place_name AS Address, x AS Longitude, y AS Latitude, |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
105 chgis_id AS CHGIS_ID, 1820_id AS 1820_ID, 1911_id AS 1911_ID, cbdb_id AS CBDB_ID |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
106 FROM coordinates_books |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
107 WHERE books_id='".$bookId."'"; |
0 | 108 $result = mysql_query($query); |
2
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
109 if (!$result) { |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
110 echo mysql_error(); |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
111 return; |
b85894a9b2dc
bug fixed: mysql query error due to updated coordinates_books table
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
1
diff
changeset
|
112 } |
0 | 113 $coordinateArray=array(); |
114 while ($row = mysql_fetch_assoc($result)) { | |
115 $coordinateArray[]=$row; | |
116 } | |
117 return $coordinateArray; | |
118 } | |
119 | |
120 $fileName=$_GET['file']; | |
121 $name=$_GET['name']; | |
122 $bookArray=readCsvFile($fileName); | |
123 writeCsvFile($fileName,$bookArray); | |
124 header("Location: map.php?mode=1&file=".$fileName."&name=".$name); | |
125 ?> |