Mercurial > hg > extraction-interface
comparison interface/exportTable.php @ 0:b12c99b7c3f0
commit for previous development
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 19 Jan 2015 17:13:49 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b12c99b7c3f0 |
---|---|
1 <?php | |
2 header("Content-Type: text/html;charset=utf-8"); | |
3 | |
4 if (isset($_POST['content'])) { | |
5 $content = $_POST['content']; | |
6 } | |
7 if (isset($_POST['sectionid'])) { | |
8 $sectionid = $_POST['sectionid']; | |
9 } | |
10 | |
11 include_once('./Lib_mb_utf8.php'); | |
12 include_once('config.php'); | |
13 | |
14 set_time_limit(0); | |
15 ini_set('memory_limit', '-1'); | |
16 | |
17 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
18 mysql_query("SET NAMES utf8"); | |
19 | |
20 if (!$link_mysql) { | |
21 die('Could not connect: ' . mysql_error()); | |
22 } | |
23 | |
24 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
25 if (!$db_selected) { | |
26 die ('Can\'t use foo : ' . mysql_error()); | |
27 } | |
28 | |
29 if (!function_exists("GetSQLValueString")) { | |
30 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") | |
31 { | |
32 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; | |
33 | |
34 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); | |
35 | |
36 switch ($theType) { | |
37 case "text": | |
38 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
39 break; | |
40 case "long": | |
41 case "int": | |
42 $theValue = ($theValue != "") ? intval($theValue) : "NULL"; | |
43 break; | |
44 case "double": | |
45 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; | |
46 break; | |
47 case "date": | |
48 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
49 break; | |
50 case "defined": | |
51 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; | |
52 break; | |
53 } | |
54 return $theValue; | |
55 } | |
56 } | |
57 | |
58 $query = sprintf("SELECT * FROM `sections` WHERE id=\"%s\"", $sectionid); | |
59 $result = mysql_query($query); | |
60 while ($row = mysql_fetch_assoc($result)) { | |
61 $sectionName = $row['name']; | |
62 $bookId = $row['books_id']; | |
63 } | |
64 | |
65 $query = sprintf("SELECT * FROM `books` WHERE id=\"%s\"", $bookId); | |
66 $result = mysql_query($query); | |
67 while ($row = mysql_fetch_assoc($result)) { | |
68 $bookName = $row['name']; | |
69 } | |
70 | |
71 $outputTableArray = array(); | |
72 | |
73 $taglistArray=""; | |
74 $query = sprintf("SELECT * FROM `taglist` ORDER BY `tag` ASC"); | |
75 $result = mysql_query($query); | |
76 while ($row = mysql_fetch_assoc($result)) { | |
77 $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); | |
78 } | |
79 | |
80 | |
81 $outputTableArray[0]=array(); | |
82 $outputTableArray[0][0]=array(); | |
83 $outputTableArray[0][1]=array(); | |
84 foreach ( $taglistArray as $value ) { | |
85 $outputTableArray[0][0][$value[2]] = $value[1]; | |
86 $outputTableArray[0][1][$value[2]] = $value[1]."(Title)"; | |
87 } | |
88 $outputTableArray[0]["other"] = "其他"; | |
89 $outputTableArray[0]["page"] = "頁數"; | |
90 $outputTableArray[0]["full"] = "全文"; | |
91 | |
92 foreach ( $taglistArray as $tagValue ) { | |
93 $content = preg_replace("/<\/".$tagValue[2].">○*<".$tagValue[2].">/u", "", $content); | |
94 $content = preg_replace("/<".$tagValue[2].">[ ]*<\/".$tagValue[2].">/u", "", $content); | |
95 } | |
96 | |
97 $contentLineArray = explode( "<br>", $content ); | |
98 | |
99 $count=0; | |
100 $pageNow=NULL; | |
101 foreach ( $contentLineArray as $value ) { | |
102 $count++; | |
103 $recordString = $value; | |
104 $otherString = $recordString; | |
105 //echo $recordString."<br>\n"; | |
106 if ( preg_match("/【<a(.*?)>(.*?)<\/a>】/u", $recordString, $matches) ) { | |
107 $pageNow = $matches[2]; | |
108 } | |
109 foreach ( $taglistArray as $tagValue ) { | |
110 if ( preg_match_all("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", $recordString, $matches, PREG_SET_ORDER) ) { | |
111 foreach ( $matches as $matchesValue ) { | |
112 $matchesValue[1] = preg_replace("/○/u", "", $matchesValue[1]); | |
113 if ( preg_match_all("/〈(.*?)〉/u", $matchesValue[1], $matches2, PREG_SET_ORDER) ) { | |
114 foreach ( $matches2 as $matches2Value ) { | |
115 if ( isset($outputTableArray[$count][0][$tagValue[2]]) ) { | |
116 $outputTableArray[$count][0][$tagValue[2]] .= ";".$matches2Value[1]; | |
117 } else { | |
118 $outputTableArray[$count][0][$tagValue[2]] = $matches2Value[1]; | |
119 } | |
120 } | |
121 } else { | |
122 if ( isset($outputTableArray[$count][0][$tagValue[2]]) ) { | |
123 $outputTableArray[$count][0][$tagValue[2]] .= ";".$matchesValue[1]; | |
124 } else { | |
125 $outputTableArray[$count][0][$tagValue[2]] = $matchesValue[1]; | |
126 } | |
127 } | |
128 } | |
129 $otherString = preg_replace("/<".$tagValue[2].">(.*?)<\/".$tagValue[2].">/u", " ", $otherString); | |
130 } | |
131 } | |
132 $otherString = preg_replace("/○/u", "", $otherString); | |
133 $outputTableArray[$count]["other"] = $otherString; | |
134 $outputTableArray[$count]["page"] = $pageNow; | |
135 $value = preg_replace("/>/u", ">", $value); | |
136 $value = preg_replace("/</u", "<", $value); | |
137 $outputTableArray[$count]["full"] = $value; | |
138 } | |
139 | |
140 foreach ( $outputTableArray as $arrayIndex => $arrayValue ) { | |
141 if ( !isset($arrayValue[0]["person"]) ) { | |
142 unset($outputTableArray[$arrayIndex]); | |
143 } | |
144 } | |
145 ?> | |
146 | |
147 <html> | |
148 <head> | |
149 <title></title> | |
150 <script src="./jquery-1.10.2.min.js"></script> | |
151 | |
152 </head> | |
153 | |
154 <body> | |
155 <table width="100%" border="1" id="tableMain"> | |
156 | |
157 <?php | |
158 $count=1; | |
159 foreach ( $outputTableArray as $trIndex =>$trValue ) { | |
160 echo "<tr>"; | |
161 if ( $trIndex==0 ) { | |
162 echo "<td>#</td>"; | |
163 echo "<td>Book ID</td>"; | |
164 echo "<td>Section ID</td>"; | |
165 echo "<td>方志</td>"; | |
166 echo "<td>部</td>"; | |
167 } else { | |
168 echo "<td>".$count++."</td>"; | |
169 echo "<td>".$bookId."</td>"; | |
170 echo "<td>".$sectionid."</td>"; | |
171 echo "<td>".$bookName."</td>"; | |
172 echo "<td>".$sectionName."</td>"; | |
173 } | |
174 if ( isset( $trValue["page"] ) ) { | |
175 echo "<td>".$trValue["page"]."</td>"; | |
176 } else { | |
177 echo "<td> </td>"; | |
178 } | |
179 /* | |
180 foreach ( $outputTableArray[0][1] as $index => $value ) { | |
181 if ( isset( $trValue[1][$index] ) ) { | |
182 echo "<td>".$trValue[1][$index]."</td>"; | |
183 } else { | |
184 echo "<td> </td>"; | |
185 } | |
186 } | |
187 */ | |
188 foreach ( $outputTableArray[0][0] as $index => $value ) { | |
189 if ( $index == "time" ) { | |
190 if ( isset( $trValue[0][$index] ) ) { | |
191 echo "<td>".$trValue[0][$index]."</td>"; | |
192 echo "<td>".$trValue[0][$index]."</td>"; | |
193 } else { | |
194 echo "<td> </td>"; | |
195 echo "<td> </td>"; | |
196 } | |
197 } else { | |
198 if ( isset( $trValue[0][$index] ) ) { | |
199 echo "<td>".$trValue[0][$index]."</td>"; | |
200 } else { | |
201 echo "<td> </td>"; | |
202 } | |
203 } | |
204 } | |
205 if ( isset( $trValue["other"] ) ) { | |
206 echo "<td>".$trValue["other"]."</td>"; | |
207 } else { | |
208 echo "<td> </td>"; | |
209 } | |
210 if ( isset( $trValue["full"] ) ) { | |
211 echo "<td>".$trValue["full"]."</td>"; | |
212 } else { | |
213 echo "<td> </td>"; | |
214 } | |
215 echo "</tr>"; | |
216 } | |
217 ?> | |
218 </table> | |
219 </body> | |
220 </html> |