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