1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<?php
//
// Translating a news item
//
// $Id: newstranslate.php,v 1.1 2007-03-12 14:51:43 mha Exp $
//
class Admin_NewsTranslate extends PgForm {
function __construct() {
$this->navsection = 'admin';
}
function SetupForm() {
$defaults = null;
if (!empty($_GET['id']) && !empty($_GET['lang']) && 'en' != $_GET['lang']) {
$id = intval($_GET['id']);
$lang = pg_escape_string($_GET['lang']);
$rs = $this->pg_query(
"SELECT ne.newsid AS id, '{$lang}' AS lang, nt.headline, nt.summary, nt.story,\n" .
" ne.headline_en, ne.summary_en, ne.story_en\n" .
"FROM (\n" .
" SELECT newsid, headline AS headline_en, summary AS summary_en, story AS story_en\n" .
" FROM news_text\n" .
" WHERE newsid = {$id} AND\n" .
" language = 'en'\n" .
") AS ne LEFT JOIN (\n" .
" SELECT newsid, headline, summary, story\n" .
" FROM news_text\n" .
" WHERE newsid = {$id} AND\n" .
" language = '{$lang}'\n" .
") AS nt ON (ne.newsid = nt.newsid)"
);
if (pg_num_rows($rs)) {
$defaults = pg_fetch_array($rs, 0, PGSQL_ASSOC);
}
}
if (!empty($defaults)) {
$this->form->setDefaults($defaults);
}
$en = array();
$this->form->addElement('hidden', 'id');
$this->form->addElement('hidden', 'lang');
$en[] =& $this->form->addElement('text', 'headline_en', 'English headline:');
$this->form->addElement('text', 'headline', 'Headline:', array('size' => 50, 'maxlength' => 100));
$en[] =& $this->form->addElement('textarea', 'summary_en', 'English summary:');
$this->form->addElement('textarea', 'summary', 'Summary:', array('rows' => 5, 'cols' => 50));
$en[] =& $this->form->addElement('textarea', 'story_en', 'English story:');
$this->form->addElement('textarea', 'story', 'Story:', array('rows' => 15, 'cols' => 50));
$buttons = array();
$buttons[] =& $this->form->createElement('button', null, 'Preview...', array('onclick' => "doPreview(this.form['headline'].value, this.form['summary'].value, this.form['story'].value);"));
$this->form->addGroup($buttons, null, null, ' ', false);
foreach (array_keys($en) as $key) {
$en[$key]->freeze();
}
$this->form->applyFilter('__ALL__', 'trim');
$this->form->applyFilter('id', 'intval');
$this->form->addRule('headline', 'The headline is required.', 'required', null, 'client');
$this->form->addRule('summary', 'The summary is required.', 'required', null, 'client');
$this->form->addRule('story', 'The story is required.', 'required', null, 'client');
$this->form->addRule('headline', 'The headline must be between 3 and 100 characters long.', 'rangelength', array(3, 100), 'client');
$this->form->addRule('summary', 'The summary must be between 3 and 500 characters long.', 'rangelength', array(3, 500), 'client');
$this->form->addRule('story', 'The story must be at least 3 characters long.', 'minlength', 3, 'client');
}
function ProcessForm($f) {
$f = array_map('pg_escape_string', $f);
$rs = $this->pg_query(
"UPDATE news_text SET headline = '{$f['headline']}', summary = '{$f['summary']}', story = '{$f['story']}'\n" .
"WHERE newsid = {$f['id']} AND language = '{$f['lang']}'"
);
if (0 == pg_affected_rows($rs)) {
$this->pg_query(
"INSERT INTO news_text\n" .
" (newsid, headline, summary, story, language)\n" .
"VALUES\n" .
" ({$f['id']}, '{$f['headline']}', '{$f['summary']}', '{$f['story']}', '{$f['lang']}')"
);
}
$this->redirect_relative='/admin/news.php';
}
function RenderThanks() {
}
}
?>
|