function make_trans($i, $wid, $trans, $word, $lang) { global $tbpref; $trans = trim($trans); $widset = is_numeric($wid); if ($widset) { $alltrans = get_first_value("select WoTranslation as value from " . $tbpref . "words where WoID = " . $wid); $transarr = preg_split('/[' . get_sepas() . ']/u', $alltrans); $r = ""; $set = false; foreach ($transarr as $t) { $tt = trim($t); if ($tt == '*' || $tt == '') { continue; } if (!$set && $tt == $trans) { $set = true; $r .= '<span class="nowrap"><input class="impr-ann-radio" checked="checked" type="radio" name="rg' . $i . '" value="' . tohtml($tt) . '" /> ' . tohtml($tt) . '</span> <br /> '; } else { $r .= '<span class="nowrap"><input class="impr-ann-radio" type="radio" name="rg' . $i . '" value="' . tohtml($tt) . '" /> ' . tohtml($tt) . '</span> <br /> '; } } if (!$set) { $r .= '<span class="nowrap"><input class="impr-ann-radio" checked="checked" type="radio" name="rg' . $i . '" value="" /> <input class="impr-ann-text" type="text" name="tx' . $i . '" id="tx' . $i . '" value="' . tohtml($trans) . '" maxlength="50" size="40" />'; } else { $r .= '<span class="nowrap"><input class="impr-ann-radio" type="radio" name="rg' . $i . '" value="" /> <input class="impr-ann-text" type="text" name="tx' . $i . '" id="tx' . $i . '" value="" maxlength="50" size="40" />'; } } else { $r = '<span class="nowrap"><input checked="checked" type="radio" name="rg' . $i . '" value="" /> <input class="impr-ann-text" type="text" name="tx' . $i . '" id="tx' . $i . '" value="' . tohtml($trans) . '" maxlength="50" size="40" />'; } $r .= ' <img class="click" src="icn/eraser.png" title="Erase Text Field" alt="Erase Text Field" onclick="$(\'#tx' . $i . '\').val(\'\').trigger(\'change\');" />'; $r .= ' <img class="click" src="icn/star.png" title="* (Set to Term)" alt="* (Set to Term)" onclick="$(\'#tx' . $i . '\').val(\'*\').trigger(\'change\');" />'; if ($widset) { $r .= ' <img class="click" src="icn/plus-button.png" title="Save another translation to existent term" alt="Save another translation to existent term" onclick="addTermTranslation(' . $wid . ', \'#tx' . $i . '\',\'\',' . $lang . ');" />'; } else { $r .= ' <img class="click" src="icn/plus-button.png" title="Save translation to new term" alt="Save translation to new term" onclick="addTermTranslation(0, \'#tx' . $i . '\',' . prepare_textdata_js($word) . ',' . $lang . ');" />'; } $r .= '</span>'; return $r; }
function get_first_translation($trans) { $arr = preg_split('/[' . get_sepas() . ']/u', $trans); if (count($arr) < 1) { return ''; } $r = trim($arr[0]); if ($r == '*') { $r = ""; } return $r; }
$data = trim(stripTheSlashesIfNeeded($_POST['data'])); // translation $text = trim(stripTheSlashesIfNeeded($_POST['text'])); // only wid=0 (new) $lang = $_POST['lang'] + 0; // only wid=0 (lang-id) // Save data $success = ""; if ($wid == 0) { $textlc = mb_strtolower($text, 'UTF-8'); $dummy = runsql('insert into ' . $tbpref . 'words (WoLgID, WoTextLC, WoText, ' . 'WoStatus, WoTranslation, WoSentence, WoRomanization, WoStatusChanged,' . make_score_random_insert_update('iv') . ') values( ' . $lang . ', ' . convert_string_to_sqlsyntax($textlc) . ', ' . convert_string_to_sqlsyntax($text) . ', 1, ' . convert_string_to_sqlsyntax($data) . ', ' . convert_string_to_sqlsyntax('') . ', ' . convert_string_to_sqlsyntax('') . ', NOW(), ' . make_score_random_insert_update('id') . ')', ""); if ($dummy == 1) { $success = $textlc; } } else { if (get_first_value("select count(WoID) as value from " . $tbpref . "words where WoID = " . $wid) == 1) { $oldtrans = get_first_value("select WoTranslation as value from " . $tbpref . "words where WoID = " . $wid); $oldtransarr = preg_split('/[' . get_sepas() . ']/u', $oldtrans); array_walk($oldtransarr, 'trim_value'); if (!in_array($data, $oldtransarr)) { if (trim($oldtrans) == '' || trim($oldtrans) == '*') { $oldtrans = $data; } else { $oldtrans .= ' ' . get_first_sepa() . ' ' . $data; } $dummy = runsql('update ' . $tbpref . 'words set ' . 'WoTranslation = ' . convert_string_to_sqlsyntax($oldtrans) . ' where WoID = ' . $wid, ""); } $success = get_first_value("select WoTextLC as value from " . $tbpref . "words where WoID = " . $wid); } } echo $success;