summaryrefslogtreecommitdiff
path: root/portal/admin/news.php
blob: f54bb8ff1d08b09a0aa777c69b33116c1d81496c (plain)
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
<?php

//
// List of news items
//
// $Id: news.php,v 1.8 2007-03-12 14:51:43 mha Exp $
//
class Admin_News extends Admin_BasePage {
    function __construct() {
        $this->content_template = 'admin/news.html';
    }
    function Render() {
        global $_SETTINGS;
        global $_LANGUAGES;

        if (isset($_GET['action']) && $_GET['action'] == 'delete') {
            $this->pg_query_params("DELETE FROM news WHERE id=$1", array($_GET['id']));
            header('Location: /admin/news.php');
            exit(0);
        }

        $rs = $this->pg_query(
            "SELECT n.id, n.posted, n.posted_by, n.approved, n.active, nt.headline, nt.language,\n" .
            "       EXTRACT(EPOCH FROM nt.modified) AS modified\n" .
            "FROM news n, news_text nt\n" .
            "WHERE n.id = nt.newsid\n" .
            "ORDER BY n.approved, n.posted DESC, n.id DESC" .
            ((isset($_GET['all']) && $_GET['all']=='1')?'':' LIMIT 20')
        );

        $news      = array();
        $newsLangs = array();
        $newsId    = -1;

        for ($i = 0, $rows = pg_num_rows($rs); $i < $rows; $i++) {
            $ary = pg_fetch_array($rs, $i, PGSQL_ASSOC);
            if ($newsId != $ary['id']) {
                $news[] = array(
                    'id'        => $ary['id'],
                    'posted'    => $ary['posted'],
                    'posted_by' => $ary['posted_by'],
                    'approved'  => $ary['approved'],
                    'active'    => $ary['active']
                );
            }
            $newsId = $ary['id'];
            if ($ary['language'] == $_SETTINGS['defaultlanguage']) {
                $news[count($news) - 1]['headline'] = $ary['headline'];
            }
            $newsLangs[$newsId][$ary['language']] = $ary['modified'];
        }

        foreach ($news as $item) {
            $langs = $newsLangs[$item['id']];
            foreach ($_LANGUAGES as $handler => $name) {
                if ($handler != $_SETTINGS['defaultlanguage']) {
                    $this->tpl->setVariable(array(
                        'lang_name'     => $name,
                        'lang_handler'  => $handler,
                        'lang_exists'   => !empty($langs[$handler])? 't': 'f',
                        'lang_up2date'  => (empty($langs[$handler]) || $langs[$handler] >= $langs[$_SETTINGS['defaultlanguage']])? 't': 'f'
                    ));
                    $this->tpl->parse('news_translations_loop');
                }
            }
            $this->tpl->setVariable($item);
            $this->tpl->parse('news_loop');
        }
    }
}

?>