Fix translations for awards and award prizes

Also fix translations editor when the first language has an accent
This commit is contained in:
james 2010-03-03 19:25:19 +00:00
parent 217ce8e175
commit 6def9680bc
3 changed files with 21 additions and 11 deletions

View File

@ -31,6 +31,11 @@
$id = intval($_GET['id']); $id = intval($_GET['id']);
$q=mysql_query("SELECT * FROM award_awards WHERE id='$id'"); $q=mysql_query("SELECT * FROM award_awards WHERE id='$id'");
$ret = mysql_fetch_assoc($q); $ret = mysql_fetch_assoc($q);
//json_encode NEEDS UTF8 DATA, but we store it in the database as ISO :(
foreach($ret AS $k=>$v) {
$ret[$k]=iconv("ISO-8859-1","UTF-8",$v);
}
//echo iconv("ISO-8859-1","UTF-8",json_encode($ret));
echo json_encode($ret); echo json_encode($ret);
exit; exit;
@ -57,18 +62,18 @@
$q = "UPDATE award_awards SET $q = "UPDATE award_awards SET
award_types_id='".intval($_POST['award_types_id'])."', award_types_id='".intval($_POST['award_types_id'])."',
presenter='".mysql_escape_string(stripslashes($_POST['presenter']))."', presenter='".mysql_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['presenter'])))."',
excludefromac='".(($_POST['excludefromac'] == 1) ? 1 : 0)."', excludefromac='".(($_POST['excludefromac'] == 1) ? 1 : 0)."',
cwsfaward='".(($_POST['cwsfaward'] == 1) ? 1 : 0)."', cwsfaward='".(($_POST['cwsfaward'] == 1) ? 1 : 0)."',
self_nominate='".(($_POST['self_nominate'] == 'yes') ? 'yes' : 'no')."', self_nominate='".(($_POST['self_nominate'] == 'yes') ? 'yes' : 'no')."',
schedule_judges='".(($_POST['schedule_judges'] == 'yes') ? 'yes' : 'no')."', schedule_judges='".(($_POST['schedule_judges'] == 'yes') ? 'yes' : 'no')."',
description='".mysql_escape_string(stripslashes($_POST['description']))."' "; description='".mysql_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['description'])))."' ";
if(array_key_exists('name', $_POST)) { if(array_key_exists('name', $_POST)) {
/* These values may be disabled, if they name key exists, assume /* These values may be disabled, if they name key exists, assume
* they aren't disabled and save them too */ * they aren't disabled and save them too */
$q .= ",name='".mysql_escape_string(stripslashes($_POST['name']))."', $q .= ",name='".mysql_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['name'])))."',
criteria='".mysql_escape_string(stripslashes($_POST['criteria']))."', criteria='".mysql_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['criteria'])))."',
sponsors_id='".intval($_POST['sponsors_id'])."' "; sponsors_id='".intval($_POST['sponsors_id'])."' ";
} }
$q .= "WHERE id='$id'"; $q .= "WHERE id='$id'";
@ -157,6 +162,9 @@
$q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$id' ORDER BY `order`"); $q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$id' ORDER BY `order`");
} }
while($r=mysql_fetch_assoc($q)) { while($r=mysql_fetch_assoc($q)) {
foreach($r AS $k=>$v) {
$r[$k]=iconv("ISO-8859-1","UTF-8",$v);
}
$ret[] = $r; $ret[] = $r;
} }
echo json_encode($ret); echo json_encode($ret);
@ -165,6 +173,9 @@
$id = intval($_GET['id']); $id = intval($_GET['id']);
$q = mysql_query("SELECT * FROM award_prizes WHERE id='$id'"); $q = mysql_query("SELECT * FROM award_prizes WHERE id='$id'");
$ret=mysql_fetch_assoc($q); $ret=mysql_fetch_assoc($q);
foreach($ret AS $k=>$v) {
$ret[$k]=iconv("ISO-8859-1","UTF-8",$v);
}
echo json_encode($ret); echo json_encode($ret);
exit; exit;
@ -183,7 +194,7 @@
case 'prize_save': case 'prize_save':
$id = intval($_POST['id']); $id = intval($_POST['id']);
$q="UPDATE award_prizes SET $q="UPDATE award_prizes SET
prize='".mysql_escape_string(stripslashes($_POST['prize']))."', prize='".mysql_escape_string(stripslashes(iconv("UTF-8","ISO-8859-1",$_POST['prize'])))."',
cash='".intval($_POST['cash'])."', cash='".intval($_POST['cash'])."',
scholarship='".intval($_POST['scholarship'])."', scholarship='".intval($_POST['scholarship'])."',
value='".intval($_POST['value'])."', value='".intval($_POST['value'])."',

View File

@ -28,10 +28,9 @@ user_auth_required('committee', 'admin');
$ret=array(); $ret=array();
foreach($config['languages'] AS $l=>$ln) { foreach($config['languages'] AS $l=>$ln) {
if($l==$config['default_language']) continue; if($l==$config['default_language']) continue;
$q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='".md5(iconv("ISO-8859-1","UTF-8",$_GET['str']))."'");
$q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='".md5($_GET['str'])."'");
if($r=mysql_fetch_object($q)) if($r=mysql_fetch_object($q))
$ret[$l]=$r->val; $ret[$l]=iconv("ISO-8859-1","UTF-8",$r->val);
else else
$ret[$l]=""; $ret[$l]="";
} }

View File

@ -25,7 +25,6 @@
include "../common.inc.php"; include "../common.inc.php";
require_once("../user.inc.php"); require_once("../user.inc.php");
user_auth_required('committee', 'admin'); user_auth_required('committee', 'admin');
print_r($_POST);
foreach($config['languages'] AS $l=>$ln) { foreach($config['languages'] AS $l=>$ln) {
if($l==$config['default_language']) continue; if($l==$config['default_language']) continue;
@ -35,13 +34,14 @@ foreach($config['languages'] AS $l=>$ln) {
if($_POST['translate_'.$l]) { if($_POST['translate_'.$l]) {
$q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='$m'"); $q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='$m'");
if(mysql_num_rows($q)) if(mysql_num_rows($q))
mysql_query("UPDATE translations SET val='".mysql_real_escape_string(stripslashes($_POST['translate_'.$l]))."' WHERE lang='$l' AND strmd5='$m'"); mysql_query("UPDATE translations SET val='".mysql_real_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['translate_'.$l])))."' WHERE lang='$l' AND strmd5='$m'");
else else
mysql_query("INSERT INTO translations (lang,strmd5,str,val) VALUES ('$l','$m','".mysql_real_escape_string(stripslashes($_POST['translate_str_hidden']))."','".mysql_escape_string(stripslashes($_POST['translate_'.$l]))."')"); mysql_query("INSERT INTO translations (lang,strmd5,str,val) VALUES ('$l','$m','".mysql_real_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['translate_str_hidden'])))."','".mysql_escape_string(iconv("UTF-8","ISO-8859-1",stripslashes($_POST['translate_'.$l])))."')");
} }
else { else {
mysql_query("DELETE FROM translations WHERE lang='$l' AND strmd5='$m'"); mysql_query("DELETE FROM translations WHERE lang='$l' AND strmd5='$m'");
} }
} }
echo "ok";
?> ?>