memid = $user->id; $projects->find(false); while($projects->fetch()) $proj[$projects->id] = $projects->short; $form = new HTML_QuickForm('frmTest', 'post'); $form->addElement('header', 'hdrTesting', 'testing form'); $form->addElement('select', 'project', _("Project Name").":", $proj); $form->addElement('select', 'editlanguage', _("Project Language").":", $languages); $form->addElement('select', 'fileformat', _("File Format").":", array("1" => "UTF-8", "0" => "HTML Entities")); $form->addElement('file', 'pofile', _(".po file").":"); $form->addElement('submit', 'submit', _("Upload file")); $lang = "en_AU"; if($_GET['editlanguage'] != "") $lang = $_GET['editlanguage']; if($_POST['editlanguage'] != "") $lang = $_POST['editlanguage']; $form->setDefaults(array("project" => intval($_GET['pid']), "editlanguage" => $lang)); $renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty); $form->accept($renderer); $smarty->assign('form', $renderer->toArray()); $process = 0; if($form->validate()) $process = 1; if($process == 1) { $upload = new HTTP_Upload('en'); $file = $upload->getFiles('pofile'); if(!$file->isValid()) { $process = 0; $smarty->assign('errmsg', _("You didn't select a file to upload.")); } } if($process == 1) { $props = $file->getProp(); if($props['ext'] != "po" && $props['ext'] != "pot") { $process = 0; $smarty->assign('errmsg', _("You didn't upload a valid .po file.")); } } if($process == 1) { $fileformat = $form->exportValue('fileformat'); $lang = $form->exportValue('editlanguage'); $fuzzy = 0; $comments = $msgid = $msgstr = ""; $file->setName(gmdate("U").sprintf("%05d", "1")."-".$lang.".po"); $filename = "/home/duane/translingo.org/pofiles/".$file->moveTo('/home/duane/translingo.org/pofiles'); $fp = fopen($filename, "rb"); while(!feof($fp)) { $line = trim(fgets($fp, 4096)); if(substr($line, 0, 1) == "#") { $comments .= $line."\n"; if(strstr($comments, ", fuzzy")) $fuzzy = 1; } elseif(substr($line, 0, 5) == "msgid") { $last = "msgid"; $msgid .= $line."\n"; } elseif(substr($line, 0, 6) == "msgstr") { $last = "msgstr"; $msgstr .= $line."\n"; } elseif($line != "") { if($last == "msgid") $msgid .= $line."\n"; else $msgstr .= $line."\n"; } if($line == "" && $msgid != "") { $msgid = str_replace("msgid \"", "", $msgid); $msgid = str_replace("\"\n", "\n", $msgid); $msgid = str_replace("\n\"", "\n", $msgid); $msgid = str_replace("\n", "", $msgid); $msgid = trim($msgid); $msgstr = str_replace("msgstr \"", "", $msgstr); $msgstr = str_replace("\"\n", "\n", $msgstr); $msgstr = str_replace("\n\"", "\n", $msgstr); $msgstr = str_replace("\n", "", $msgstr); $msgstr = trim($msgstr); if($msgid == "" || $msgstr == "") { $fuzzy = 0; $comments = $msgid = $msgstr = ""; continue; } $base =&new DataObject_Base(); $base->pid = intval($form->exportValue('project')); $msgid = str_replace("\\n", "\\\\n", $msgid); $msgstr = str_replace("\\n", "\\\\n", $msgstr); $base->string = doit($msgid, $fileformat); if($base->count() > 0) { $updated++; $base->find(false); $base->fetch(); $baseid = $base->id; $trans =& new DataObject_Translations(); $trans->pid = intval($form->exportValue('project')); $trans->baseid = $baseid; $trans->language = $lang; $doupdate = $trans->count(); if($doupdate > 0) { $trans->find(false); $trans->fetch(); $transid = $trans->id; } $trans =& new DataObject_Translations(); $trans->memid = $user->id; $trans->revision = gmdate("Y-m-d H:i:s"); $trans->fuzzy = $fuzzy; $trans->string = doit($msgstr, $fileformat); if($doupdate > 0) { $trans->id = $transid; $trans->update(); } else { $trans->pid = intval($form->exportValue('project')); $trans->baseid = $baseid; $trans->language = $lang; $trans->insert(); } $rev =& new DataObject_Revisions(); $rev->pid = intval($form->exportValue('project')); $rev->baseid = $baseid; $rev->language = $lang; $rev->memid = $user->id; $rev->fuzzy = $fuzzy; $rev->revision = gmdate("Y-m-d H:i:s"); $rev->string = doit($msgstr, $fileformat); $rev->insert(); unset($rev); unset($trans); } else { $ignored++; continue; } $fuzzy = 0; $comments = $msgid = $msgstr = ""; } } $smarty->assign('ignored', intval($ignored)); $smarty->assign('updated', intval($updated)); $smarty->display('lheader.tpl'); $smarty->display('okpoupload.tpl'); $smarty->display('lfooter.tpl'); exit; } $smarty->display('lheader.tpl'); $smarty->display('poupload.tpl'); $smarty->display('lfooter.tpl'); ?>