Mercurial > hg > extraction-interface
view 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 |
line wrap: on
line source
<?php header("Content-Type: text/html;charset=utf-8"); /** * "Lib_mb_utf8.php" is a set of common functions used to convert encode of text * "config.php" containing a system name variable. Please make it the same as the system's folder name. */ include_once('Lib_mb_utf8.php'); include_once('config.php'); if (isset($_GET['id'])) { $section_id = $_GET['id']; } include_once('Lib_mb_utf8.php'); include_once('config.php'); set_time_limit(0); ini_set('memory_limit', '-1'); $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); mysql_query("SET NAMES utf8"); if (!$link_mysql) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($mysql_database, $link_mysql); if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $wordlistArray = array(); $query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $systemNAME); $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $wordlistArray[$row['id']] = $row['name']; } ?> <html> <head> <title></title> <script src="jquery-1.10.2.min.js"></script> <style> dynasty { color:red; } nianhao { color:blue; } name { color:orange; } #editable-area { line-height:160%; letter-spacing:1.5px; font-size:21px; } </style> <script type="text/javascript"> function showListContent( id ) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = process; xhr.open("POST", "wordlist/"+id+".txt?t=" + Math.random(), true); xhr.send(); function process() { if (xhr.readyState == 4) { var el = document.getElementById("editable-area"); var str = xhr.responseText var regexText=/\n/g; var replaceText="<br>\n"; el.innerHTML = str.replace(regexText, replaceText); 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>"; } } } function replaceRegex() { var el = document.getElementById("editable-area"); var regexText=document.getElementById("regexText").value; var replaceText=document.getElementById("replaceText").value; var str="" + el.innerHTML; el.innerHTML = str.replace(new RegExp(regexText, "g"), replaceText); } function editText( id ) { var el = document.getElementById("editable-area"); el.contentEditable = true; } function saveText( id ) { var el = document.getElementById("editable-area"); $.ajax({ url : 'save_word_list.php', async : false, type : 'POST', data : 'text='+el.innerHTML+'&filename='+id }).done(function(result) { alert("Saved!"); }); } function addNewList( ) { var el = document.getElementById("listNameText"); $.ajax({ url : 'add_word_list.php', async : false, type : 'POST', data : 'text='+el.value }).done(function(result) { alert("Added!"); document.location.reload(true); }); } </script> </head> <body> <table width="98%" border="1"> <tr> <td width="20%" valign="top"> <?php foreach ( $wordlistArray as $nameId => $nameValue ) { echo " <a onclick=\"showListContent(".$nameId.")\" href=\"#\">".$nameValue."</a></br>"; } ?> <form action="javascript:void(0);"> <fieldset> <legend>Add List:</legend> List name: <input type="text" size="30" id="listNameText"><br> <button onclick="addNewList()">Add</button> </fieldset> </form> </td> <td width="60%"> <div id="editable-area"></div> </td> <td width="20%" valign="top" id="button-area"> </td> </tr> </table> </body> </html>