annotate search_function.php @ 1:38851c894301

path config
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 24 Mar 2015 16:27:18 +0100
parents c9363a90b8b5
children 45cbafdec56e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
2
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 include_once('config/Lib_mb_utf8.php');
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 include_once('config/config.php');
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
5
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
6 set_time_limit(0);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
7 ini_set('memory_limit', '-1');
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
8
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
9 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 mysql_query("SET NAMES utf8");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
11
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
12 if (!$link_mysql) {
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
13 die('Could not connect: ' . mysql_error());
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
15
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 $db_selected = mysql_select_db($mysql_database, $link_mysql);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 if (!$db_selected) {
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 die ('Can\'t use foo : ' . mysql_error());
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
19 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 function trimKeyword($keywords){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 $token=strtok($keywords,",");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 while($token!=false){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 $token=trim($token);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
24 $keywordArray[]=$token;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 $token=strtok(",");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 return $keywordArray;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
28 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
29
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
30 function search($keywordArray){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 $condition="";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 foreach($keywordArray as $i=>$keyword){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 if($i!=0){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 $condition.=" OR ";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 $condition.=" contents.content LIKE '%".$keyword."%' ";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
38 //books.name AS book_name, books.level1, books.level2, books.period, contents.books_id, contents.line, contents.content
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
39
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
40 // TODO: book_info is now merged to books table
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 $query="SELECT books.level1 AS LEVEL1, books.level2 AS LEVEL2,
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 books.name AS Name, books.period AS PERIOD,
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 books.start_year AS 'TimeSpan:begin', books.end_year AS 'TimeSpan:end',
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
44 books.id AS BOOK_ID, contents.line AS PAGE, contents.content AS CONTENT,
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
45 books.volume AS VOLUME, books.author AS AUTHOR, books.edition AS EDITION
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 FROM contents
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 JOIN books ON contents.books_id = books.id
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
48 WHERE ".$condition."
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
49 ORDER BY contents.books_id, contents.line";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 $result = mysql_query($query);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 if (!$result) {
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
52 echo mysql_error();
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
54 echo "result length: ".mysql_num_rows($result)."<br>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
55
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
56 while ($row = mysql_fetch_assoc($result)) { //Find the section(s) where the page belongs to
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
57 //$resultArray[$i]=$row;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 $query = "SELECT MAX(`id`) FROM `sections_versions` WHERE `books_id` ='".$row['BOOK_ID']."'";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
59
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
60 $r = mysql_fetch_row(mysql_query($query));
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 $max_version_id = $r[0];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
62
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 $subQuery = "";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 if ($max_version_id) {
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 $subQuery="SELECT id, name, start_page, end_page
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
66 FROM sections_revisions
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 WHERE books_id=".$row['BOOK_ID']." AND start_page<=".$row['PAGE']." AND end_page>=".$row['PAGE']." AND sections_revisions.deleted=0 AND sections_revisions.versions_id=".$max_version_id;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
68
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
69 } else {
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 $subQuery="SELECT id, name, start_page, end_page
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
71 FROM sections
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 WHERE books_id=".$row['BOOK_ID']." AND start_page<=".$row['PAGE']." AND end_page>=".$row['PAGE'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
73 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
74
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
75 $subResult=mysql_query($subQuery);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
76 $sectionArray=array();
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
77 while($subRow=mysql_fetch_assoc($subResult)){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 $sectionArray[]=$subRow;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 $row['SECTION']=$sectionArray;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
81
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
82 $resultArray[]=$row;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
84 //echo "array length: ".sizeof($resultArray)."<br>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 return $resultArray;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
86 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 $NO_TAG=0;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
88 $LOCUST_TEMPLE=1;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
89
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 function printTable($array,$keywordArray,$filename,$tag){ //print HTML
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
91 global $NO_TAG, $LOCUST_TEMPLE;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 $header='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
93 <html>
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
94 <head>
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
95 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
1
38851c894301 path config
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
96 <link href="../search.css" type="text/css" rel="stylesheet"/>
0
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
97 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
1
38851c894301 path config
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
98 <script src="../search.js" charset="utf-8"></script>
0
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
99 </head>
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
100 <body>';
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
101 $keywordStr="";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
102 foreach($keywordArray as $i=>$keyword){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
103 if($i!=0){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
104 $keywordStr.=", ";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
105 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
106 $keywordStr.=$keyword;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
107 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
108
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
109
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
110 global $system_root_url, $server_host, $lgserver_url;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
111
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
112 $fp=fopen("./search_results/".$filename.".html","w");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
113 fwrite($fp,$header);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
114 $str="<a href='".$server_host."LGMap/get_coordinates_for_listed_books.php?file=".$filename.".csv&name=".$keywordStr."' target='_blank'>view the distribution on the map</a><br><br>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
115 fwrite($fp,$str);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
116 $str.="<a href='".$system_root_url."search_results/".$filename.".html' target='_blank'>html version</a><br><br>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
117 // $str.="<a href='http://".$_SERVER['HTTP_HOST']."/LGSearch/search_results/".$filename.".html' target='_blank'>html version</a><br><br>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
118 echo $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
119 echo sizeof($array)." result(s) of \"".$keywordStr."\" ";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
120 fwrite($fp,sizeof($array)." result(s) of \"".$keywordStr."\"<br>");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
121 $str="<table>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
122 $str.="<tr>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
123 $str.="<td class='sequence'>#<td class='bookId'>book id<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='sectionName'>section info<td class='page'>page<td class='content'>content";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
124 fwrite($fp,$str);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
125 echo $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
126 $i=1;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
127 foreach($array as $row){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
128 $str="<tr>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
129 $str.="<td>".$i;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
130 $str.="<td>".$row['BOOK_ID'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
131 $str.="<td>".$row['Name'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
132 $str.="<td>".$row['LEVEL1'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
133 $str.="<td>".$row['LEVEL2'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
134 $str.="<td>".$row['PERIOD'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
135 $str.="<td>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
136 fwrite($fp,$str);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
137 echo $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
138 foreach($row['SECTION'] as $section){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
139 // TODO: config to current extraction-interface OR Toc OR not at all??
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
140 // redirect to LGServer
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
141 $str="<div class='section'><a href='".$lgserver_url."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
142 echo $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
143 $str="<div class='section'><a href='".$lgserver_url."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
144 fwrite($fp,$str);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
145 /*
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
146 $str="<div class='section'><a href='/interface/tagging_text.php?id=".$section['id']."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
147 echo $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
148 $str="<div class='section'><a href='/interface/tagging_text.php?id=".$section['id']."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
149 fwrite($fp,$str);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
150 */
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
151 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
152 $str="<td>".$row['PAGE'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
153 if($tag==$NO_TAG){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
154 $str.="<td>".$row['CONTENT'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
155 }else if($tag==$LOCUST_TEMPLE){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
156 $str.="<td>".findLocustTempleDescription($row['CONTENT'],$keywordArray,0);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
157 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
158 fwrite($fp,$str);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
159 echo $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
160 $i++;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
161 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
162
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
163 echo "</table>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
164 fwrite($fp,"</table></body></html>");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
165 fclose($fp);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
166 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
167
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
168 function findLocustTempleDescription($str,$keywordArray,$findUnknownTemple){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
169 $result="";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
170 $pattern[0]="/(.*)(";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
171 foreach($keywordArray as $i=>$keyword){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
172 $pattern[0].=$keyword;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
173 if($i!=sizeof($keywordArray)-1){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
174 $pattern[0].="|";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
175 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
176 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
177 $pattern[0].=")(.*)/u";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
178 //0=whole,1=text,2=locust temple,3=description
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
179 $pattern[1]="/(.*\s+)(\S{1,5}[廟寺祠])(.*)/u";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
180 //0=whole,1=descripption,2=unknown temple,3=text
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
181 $success=preg_match($pattern[$findUnknownTemple],$str,$match); //note that preg_match only matches the last match!
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
182 if($findUnknownTemple==0){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
183 if($success==1){//find string "locust temple"
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
184 $result=findLocustTempleDescription($match[1],$keywordArray,0);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
185 $result.="<keyword>".$match[2]."</keyword>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
186 $result.=findLocustTempleDescription($match[3],$keywordArray,1);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
187 return $result;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
188 }else{//no string "locust temple"
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
189 return "<irrelevant>".$str."</irrelevant>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
190 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
191 }else{
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
192 if($success==1){//find the pattern "locust temple......unknown temple"
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
193 $result=findLocustTempleDescription($match[1],$keywordArray,1);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
194 $result.="<irrelevant>".$match[2].$match[3]."</irrelevant>";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
195 //$result.="<keyword>".$match[2]."</keyword>".$match[3];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
196 return $result;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
197 }else{//can't find the pattern
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
198 return $str;
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
199 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
200
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
201 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
202 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
203
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
204 function writeCsvFile($array,$fileName){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
205 $columnNameArray=['BOOK_ID','LEVEL1','LEVEL2',
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
206 'Name','PERIOD','TimeSpan:begin','TimeSpan:end','PAGE','SECTION','CONTENT',
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
207 'Description'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
208 $fp=fopen("./csv_files/".$fileName.".csv","w");
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
209 fputcsv($fp,$columnNameArray);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
210 foreach($array as $row){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
211 $book=array();
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
212 $row['Description']='';
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
213 foreach($columnNameArray as $column){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
214 $book[$column]=$row[$column];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
215 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
216 $book['Name']="(".$row['PERIOD'].") ".$row['Name'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
217 $row['AUTHOR']=str_replace("(","(",$row['AUTHOR']);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
218 $row['AUTHOR']=str_replace(")",") ",$row['AUTHOR']);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
219 $book['Description']=$row['VOLUME']." ╱ ".$row['AUTHOR']." ╱ ".$row['EDITION'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
220 $book['SECTION']='';
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
221 foreach($row['SECTION'] as $idx=>$section){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
222 $book['SECTION'].=$section['name']." ".$section['start_page']."-".$section['end_page'];
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
223 if($idx!=sizeof($row['SECTION'])){
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
224 $book['SECTION'].=" ╱ ";
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
225 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
226 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
227 fputcsv($fp,$book);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
228 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
229 fclose($fp);
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
230 }
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
231
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
232 ?>
c9363a90b8b5 first commit to development server
Zoe Hong <zhong@mpiwg-berlin.mpg.de>
parents:
diff changeset
233