Mercurial > hg > extraction-interface
comparison interface/edit_wordlist.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($_GET['id'])) { | |
11 $section_id = $_GET['id']; | |
12 } | |
13 | |
14 include_once('Lib_mb_utf8.php'); | |
15 include_once('config.php'); | |
16 | |
17 set_time_limit(0); | |
18 ini_set('memory_limit', '-1'); | |
19 | |
20 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
21 mysql_query("SET NAMES utf8"); | |
22 | |
23 if (!$link_mysql) { | |
24 die('Could not connect: ' . mysql_error()); | |
25 } | |
26 | |
27 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
28 if (!$db_selected) { | |
29 die ('Can\'t use foo : ' . mysql_error()); | |
30 } | |
31 | |
32 if (!function_exists("GetSQLValueString")) { | |
33 function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") | |
34 { | |
35 $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; | |
36 | |
37 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); | |
38 | |
39 switch ($theType) { | |
40 case "text": | |
41 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
42 break; | |
43 case "long": | |
44 case "int": | |
45 $theValue = ($theValue != "") ? intval($theValue) : "NULL"; | |
46 break; | |
47 case "double": | |
48 $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; | |
49 break; | |
50 case "date": | |
51 $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; | |
52 break; | |
53 case "defined": | |
54 $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; | |
55 break; | |
56 } | |
57 return $theValue; | |
58 } | |
59 } | |
60 | |
61 $wordlistArray = array(); | |
62 $query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $systemNAME); | |
63 $result = mysql_query($query); | |
64 while ($row = mysql_fetch_assoc($result)) { | |
65 $wordlistArray[$row['id']] = $row['name']; | |
66 } | |
67 ?> | |
68 | |
69 <html> | |
70 <head> | |
71 <title></title> | |
72 <script src="jquery-1.10.2.min.js"></script> | |
73 <style> | |
74 dynasty | |
75 { | |
76 color:red; | |
77 } | |
78 nianhao | |
79 { | |
80 color:blue; | |
81 } | |
82 name | |
83 { | |
84 color:orange; | |
85 } | |
86 #editable-area { | |
87 line-height:160%; | |
88 letter-spacing:1.5px; | |
89 font-size:21px; | |
90 } | |
91 </style> | |
92 <script type="text/javascript"> | |
93 | |
94 function showListContent( id ) { | |
95 var xhr = new XMLHttpRequest(); | |
96 xhr.onreadystatechange = process; | |
97 xhr.open("POST", "wordlist/"+id+".txt?t=" + Math.random(), true); | |
98 xhr.send(); | |
99 | |
100 function process() { | |
101 if (xhr.readyState == 4) { | |
102 var el = document.getElementById("editable-area"); | |
103 var str = xhr.responseText | |
104 var regexText=/\n/g; | |
105 var replaceText="<br>\n"; | |
106 el.innerHTML = str.replace(regexText, replaceText); | |
107 | |
108 document.getElementById("button-area").innerHTML="<form action=\"javascript:void(0);\"><fieldset><legend>Edit:</legend><button id=\"buttonEditText\" onclick=\"editText("+id+")\" style=\"height: 30px; width: 220px\">Edit the text</button></br><button id=\"buttonSaveText\" onclick=\"saveText("+id+")\" style=\"height: 30px; width: 220px\">Save the text</button></fieldset><fieldset><legend>Replace By Regex:</legend>Regex: <input type=\"text\" size=\"30\" id=\"regexText\"></br>Replace: <input type=\"text\" size=\"30\" id=\"replaceText\"><br><button onclick=\"replaceRegex()\">Replace!</button></fieldset></form>"; | |
109 } | |
110 } | |
111 | |
112 } | |
113 | |
114 function replaceRegex() { | |
115 var el = document.getElementById("editable-area"); | |
116 var regexText=document.getElementById("regexText").value; | |
117 var replaceText=document.getElementById("replaceText").value; | |
118 var str="" + el.innerHTML; | |
119 el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); | |
120 } | |
121 | |
122 function editText( id ) { | |
123 var el = document.getElementById("editable-area"); | |
124 el.contentEditable = true; | |
125 } | |
126 | |
127 function saveText( id ) { | |
128 var el = document.getElementById("editable-area"); | |
129 | |
130 $.ajax({ | |
131 url : 'save_word_list.php', | |
132 async : false, | |
133 type : 'POST', | |
134 data : 'text='+el.innerHTML+'&filename='+id | |
135 }).done(function(result) { | |
136 alert("Saved!"); | |
137 }); | |
138 | |
139 } | |
140 | |
141 function addNewList( ) { | |
142 var el = document.getElementById("listNameText"); | |
143 $.ajax({ | |
144 url : 'add_word_list.php', | |
145 async : false, | |
146 type : 'POST', | |
147 data : 'text='+el.value | |
148 }).done(function(result) { | |
149 alert("Added!"); | |
150 document.location.reload(true); | |
151 }); | |
152 | |
153 } | |
154 </script> | |
155 </head> | |
156 <body> | |
157 | |
158 <table width="98%" border="1"> | |
159 <tr> | |
160 <td width="20%" valign="top"> | |
161 <?php | |
162 foreach ( $wordlistArray as $nameId => $nameValue ) { | |
163 echo " <a onclick=\"showListContent(".$nameId.")\" href=\"#\">".$nameValue."</a></br>"; | |
164 } | |
165 ?> | |
166 <form action="javascript:void(0);"> | |
167 <fieldset> | |
168 <legend>Add List:</legend> | |
169 List name: <input type="text" size="30" id="listNameText"><br> | |
170 <button onclick="addNewList()">Add</button> | |
171 </fieldset> | |
172 </form> | |
173 </td> | |
174 <td width="60%"> | |
175 <div id="editable-area"></div> | |
176 </td> | |
177 <td width="20%" valign="top" id="button-area"> </td> | |
178 </tr> | |
179 </table> | |
180 | |
181 </body> | |
182 </html> |