$sql = "update hangee_words set " . "word='{$word}', page={$page}, sense='{$sense}' " . "where id={$wid}"; $res = mysql_query($sql, $dbconn); if (!$res) { $msg = "query failed: {$sql} : " . mysql_error($dbconn); $response->assign("result", "innerHTML", $msg); $response->assign("result", "style.display", "block"); return $response; } $response->script("close_and_reload_parent()"); return $response; } if (!isset($_GET['id'])) { echo "<script language='javascript' type='text/javascript'><!--//\n" . "alert(\"Invalid access!\");\n" . "//--></script>"; die("Invalid access!"); } $grade = get_user_grade(); if ($grade != '0' && $grade != '1') { die("You do not have permission to edit the word record!"); } $wid = $_GET['id']; $sql = "select * from hangee_words where id={$wid}"; $res = mysql_query($sql, $dbconn); if (!$res) { die("query failed: {$sql} :" . mysql_error($dbconn)); } $row = mysql_fetch_array($res); $id = $row['id']; $page = $row['page']; $word = $row['word']; $sense = htmlspecialchars(stripslashes($row['sense'])); $dict = htmlspecialchars(stripslashes($row['dictionary']));
function browse_word($ch, $form = '') { global $dbconn; global $uid; $ch = strtolower($ch); $sql = ''; $num_res = 0; $response = new xajaxResponse(); connect_db(); $goman = substr($form, 0, 5) == 'goman' ? TRUE : FALSE; if ($form) { if ($goman) { $page = $ch + 500; $sql = "select * from hangee_words where page={$page}"; if (substr($form, -1) == 'm') { $sql .= " and id in (select wid from hangee_marked where uid={$uid})"; } $sql .= " order by word asc"; } else { $column = $form['column']; $key = trim($form['key']); if (strlen($key) == 0) { $response->assign("result", "innerHTML", "No search word is given!"); $response->assign("result", "style.display", "block"); return $response; } switch ($column) { case 'word': $sql = "select * from hangee_words where word like '%{$key}%' order by word asc"; break; case 'sense': $sql = "select * from hangee_words where sense like '%{$key}%' order by word asc"; break; case 'SQL': $sql = "select * from hangee_words where " . $key; break; default: $response->assign("result", "innerHTML", "Internal Error!"); $response->assign("result", "style.display", "block"); return $response; break; } } } else { if (strlen($ch) == 2) { $ch = substr($ch, 0, 1); $sql = "select * from hangee_words where word like '{$ch}%' and page < 300 " . "and id in (select wid from hangee_marked where uid = {$uid})"; } else { $sql = "select * from hangee_words where word like '{$ch}%' and page < 300 order by word asc"; } } $res = mysql_query($sql, $dbconn); if (!$res) { $response->assign("debug", "innerHTML", "query failed: {$sql}" . mysql_error($dbconn)); $response->assign("debug", "style.display", "block"); return $response; } if (($num_res = mysql_num_rows($res)) == 0) { $response->assign("word_browser", "innerHTML", "<strong>No words, lucky you!</strong>"); $response->assign("word_browser", "style.display", "block"); return $response; } $num = 0; if (isset($key)) { if ($column == 'SQL') { $caption = "Search result of SQL"; } else { $caption = "Search result of '<strong>" . htmlspecialchars($key) . "</strong>'"; } } else { if ($goman) { $caption = "GoMAN DAY {$ch}"; } else { $caption = "HanGEE words starting with '<strong>" . strtoupper($ch) . "</strong>'"; } } $pstr = $goman ? "Day" : "Page"; $html = "<p>{$num_res} words are found</p>" . "<p><a href='javascript:void(0);' onClick=\"show_sense({$num_res});\"><strong>Show Sense</strong></a> | " . "<a href='javascript:void(0);' onClick=\"hide_sense({$num_res});\"><strong>Hide Sense</strong></a> | " . "<a href='javascript:void(0);' onClick=\"words_upper({$num_res});\"><strong>Upper</strong></a> | " . "<a href='javascript:void(0);' onClick=\"words_lower({$num_res});\"><strong>Lower</strong></a></p>" . "<center>" . "<table id='word_table'>" . "<caption>{$caption}</caption>" . "<tr><th id='num' width='5%'>Num</th><th id='page' width='8%'>{$pstr}</th><th id='word' width='15%'>Word</th>" . "<th id='sense' width='40%'>Sense</th><th id='hint'>Hint</th>" . "<!-- <th id='edit'>Edit</th></tr> -->"; while ($row = mysql_fetch_array($res)) { $num++; $id = $row['id']; $page = $row['page']; $word = $row['word']; $sense = htmlspecialchars(stripslashes($row['sense'])); if (!$goman && $page < 500) { $pattern = '/((a|v|vi|n|ad|pre)\\.)/'; $replace = '<br>$1'; $sense = preg_replace($pattern, $replace, $sense); $sense = substr($sense, 4); // delete leading <br> } $grade = get_user_grade(); if ($grade == '1' || $grade == '0') { $numstr = "<a name='{$num}' href=\"javascript:openPopup('edit.php?id={$id}', 'editwin');\"><b>{$num}</b></a>"; } else { $numstr = "<a href='mailto:sandrain@gmail.com'><b>{$num}</b></a>"; } $word = "<a href=\"javascript:mark_word({$id}, {$num})\"><span id='w{$num}'>" . strtoupper($word) . "</span></a>"; $mcount = get_marked_count($id); if ($mcount > 0) { $wbackcolor = "#ffcc00"; $word .= " <a href=\"javascript:unmark_word({$id}, {$num})\"><font color='#cc0000'>"; while ($mcount--) { $word .= "*"; } $word .= "</font></a>"; } else { $wbackcolor = "#ffff99"; } $bgcolor = ''; if ($page > 500) { $page = "D - " . ($page - 500); $bgcolor = "bgcolor='#ccffff'"; } $dict = "<a href='javascript:void(0); return false;' onClick=\"openPopup('dict.php?id={$id}', 'dictwin')\">{$page}</a>"; $hint = get_hint($id); $hintlink = "<a href='javascript:void(0);' " . "onClick=\"javascript:openPopup('hint.php?id={$id}', 'hintwin');\">Edit</a>"; if ($hint) { $hint = htmlspecialchars(stripslashes($hint)) . " <span style='font-size:8pt;'>({$hintlink})</span>"; } else { $hint = $hintlink; } $html .= "<tr onMouseOver=\"this.bgColor='#ccff99'\" onMouseOut=\"this.bgColor='#ffffff'\">" . "<td headers='num' align='right' style='padding-right:10px;'>{$numstr}</td>" . "<td headers='page' align='center' {$bgcolor}>{$dict}</td>" . "<td headers='word' bgcolor='{$wbackcolor}' align='left'><p class='table_word'>{$word}</p></td>" . "<td headers='sense' align='left' id='td{$num}' class='answer_off' " . "onMouseOver=\"className='answer_on'\" onMouseOut=\"className='answer_off'\">" . "<p class='table_text'>{$sense}</p></td>" . "<td headers='hint' align='left'><p class='table_text'>{$hint}</p></td>"; } $html .= "</table></center>"; disconnect_db(); if (isset($column) && isset($key)) { $response->script("set_search_active('{$column}', '{$key}')"); } else { $response->script("update_current_ch('{$ch}');"); } $response->assign("word_browser", "innerHTML", $html); $response->assign("word_browser", "style.display", "block"); $response->script("num_res = {$num_res};"); return $response; }