From 3992b680299af68227961e3f50ab0611ee85d32b Mon Sep 17 00:00:00 2001 From: james Date: Mon, 18 Aug 2008 21:08:23 +0000 Subject: [PATCH] Update page text's to do multiple languages, instead of storign the text's in the separate language editor Also - force it to use the newly auto-installed fckeditor, and reduce the height a bit becuase there's now more than one per page. --- common.inc.php | 8 ++-- config/pagetexts.php | 94 ++++++++++++++++++++++++++++++-------------- 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/common.inc.php b/common.inc.php index 5523b21..9bd5022 100644 --- a/common.inc.php +++ b/common.inc.php @@ -991,21 +991,21 @@ function getEmailRecipientsForRegistration($reg_id) function output_page_text($textname) { global $config; - $q=mysql_query("SELECT * FROM pagetext WHERE textname='$textname' AND year='".$config['FAIRYEAR']."'"); + $q=mysql_query("SELECT * FROM pagetext WHERE textname='$textname' AND year='".$config['FAIRYEAR']."' AND lang='".$_SESSION['lang']."'"); if(mysql_num_rows($q)) $r=mysql_fetch_object($q); else { //not defined, lets grab the default text - $q=mysql_query("SELECT * FROM pagetext WHERE textname='$textname' AND year='-1'"); + $q=mysql_query("SELECT * FROM pagetext WHERE textname='$textname' AND year='-1' AND lang='".$config['default_language']."'"); $r=mysql_fetch_object($q); } //if it looks like we have HTML content, dont do a nl2br, if there's no html, then do the nl2br if(strlen($r->text)==strlen(strip_tags($r->text))) - echo nl2br(i18n($r->text)); + echo nl2br($r->text); else - echo i18n($r->text); + echo $r->text; } function generatePassword($pwlen=8) diff --git a/config/pagetexts.php b/config/pagetexts.php index b523d10..87c31c3 100644 --- a/config/pagetexts.php +++ b/config/pagetexts.php @@ -25,6 +25,12 @@ require("../common.inc.php"); require_once("../user.inc.php"); user_auth_required('committee', 'config'); + + //make sure storage folder exists + if(!file_exists("../data/userfiles")) + mkdir("../data/userfiles"); + + send_header("Page Texts", array('Committee Main' => 'committee_main.php', 'SFIAB Configuration' => 'config/index.php') @@ -42,66 +48,94 @@ if($_POST['action']=="save") { - mysql_query("UPDATE pagetext SET lastupdate=NOW(), text='".mysql_escape_string(stripslashes($_POST['text']))."' WHERE textname='".$_POST['textname']."' AND year='".$config['FAIRYEAR']."'"); + foreach($config['languages'] AS $lang=>$langname) { + $textvar="text_$lang"; + $text=mysql_escape_string(stripslashes($_POST[$textvar])); - echo happy(i18n("Page text successfully saved")); + mysql_query("UPDATE pagetext + SET + lastupdate=NOW(), + text='$text' + WHERE + textname='".mysql_escape_string($_POST['textname'])."' + AND year='".$config['FAIRYEAR']."' + AND lang='$lang'"); + } + echo happy(i18n("Page texts successfully saved")); } if($_GET['textname']) { - $q=mysql_query("SELECT * FROM pagetext WHERE textname='".$_GET['textname']."' AND year='".$config['FAIRYEAR']."'"); + $q=mysql_query("SELECT * FROM pagetext WHERE textname='".mysql_escape_string($_GET['textname'])."' AND year='".$config['FAIRYEAR']."'"); + //needs to be at least one entry in any languages if($r=mysql_fetch_object($q)) { - if($r->lastupdate=="0000-00-00 00:00:00") $lastupdate="Never"; - else $lastupdate=$r->lastupdate; - echo "$r->textname    Last updated: $lastupdate
"; echo "
"; echo "\n"; echo "textname\">\n"; - if(is_dir("../fckeditor") && file_exists("../fckeditor/fckeditor.php")) - { + + foreach($config['languages'] AS $lang=>$langname) { + $q=mysql_query("SELECT * FROM pagetext WHERE textname='".mysql_escape_string($_GET['textname'])."' AND year='".$config['FAIRYEAR']."' AND lang='$lang'"); + $r=mysql_fetch_object($q); + + if(!$r) + { + mysql_query("INSERT INTO pagetext (textname,year,lang) VALUES ('".mysql_escape_string($_GET['textname'])."','".$config['FAIRYEAR']."','$lang')"); + echo mysql_error(); + } + + if($r->lastupdate=="0000-00-00 00:00:00" || !$r->lastupdate) $lastupdate="Never"; + else $lastupdate=$r->lastupdate; + echo "".htmlspecialchars($_GET['textname'])." - $langname    ".i18n("Last updated").": $lastupdate
"; require_once("../fckeditor/fckeditor.php"); - $oFCKeditor = new FCKeditor('text') ; + $oFCKeditor = new FCKeditor("text_$lang") ; $oFCKeditor->BasePath = "../fckeditor/"; $oFCKeditor->Value = $r->text; $oFCKeditor->Width="100%"; - $oFCKeditor->Height=500; + $oFCKeditor->Height=300; $oFCKeditor->Create() ; + + echo "
"; } - else - { - echo ""; - echo "
"; - } - echo "\n"; + + echo "
"; + echo "\n"; echo ""; - echo "
"; + echo "
"; + echo "
"; + echo "\n"; + echo "
\n"; + echo "
\n"; + } else { echo error(i18n("Invalid text name")); } } - echo "
"; - echo i18n("Choose a page text to edit"); - echo ""; - - $q=mysql_query("SELECT * FROM pagetext WHERE year='".$config['FAIRYEAR']."' ORDER BY textname"); - echo ""; - while($r=mysql_fetch_object($q)) + else { - echo ""; - if($r->lastupdate=="0000-00-00 00:00:00") $lastupdate="Never"; - else $lastupdate=$r->lastupdate; - echo ""; - echo ""; + echo "
"; + echo i18n("Choose a page text to edit"); + echo "
".i18n("Page Text Name")."".i18n("Last Update")."
textname\">$r->textname$lastupdate
"; + + $q=mysql_query("SELECT * FROM pagetext WHERE year='".$config['FAIRYEAR']."' AND lang='".$config['default_language']."' ORDER BY textname"); + echo ""; + while($r=mysql_fetch_object($q)) + { + echo ""; + if($r->lastupdate=="0000-00-00 00:00:00") $lastupdate="Never"; + else $lastupdate=$r->lastupdate; + echo ""; + echo ""; + } + echo "
".i18n("Page Text Name")."".i18n("Last Update")."
textname\">$r->textname$lastupdate
"; } - echo ""; send_footer(); ?>