source: extensions/Comments_on_Albums/include/coa_admin_comments.php @ 9634

Last change on this file since 9634 was 9634, checked in by mistic100, 13 years ago

[plugins] Comments on Albums

  • corrections
  • public list available
File size: 3.9 KB
Line 
1<?php
2/* Code adapted from admin/comments.php */
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5// +-----------------------------------------------------------------------+
6//                              Tabsheet
7// +-----------------------------------------------------------------------+
8include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
9
10$tabs = array(
11        array(
12                'code' => 'pictures',
13                'label' => l10n('Photos'),
14        ),
15        array(
16                'code' => 'albums',
17                'label' => l10n('Albums'),
18        ),
19);
20
21$tab_codes = array_map(create_function('$a', 'return $a["code"];'), $tabs);
22
23if (isset($_GET['section']) and in_array($_GET['section'], $tab_codes)) {
24        $page['tab'] = $_GET['section'];
25} else {
26        $page['tab'] = $tabs[0]['code'];
27}
28
29$tabsheet = new tabsheet();
30foreach ($tabs as $tab) {
31        $tabsheet->add(
32                $tab['code'],
33                $tab['label'],
34                get_root_url().'admin.php?page=comments&amp;section='.$tab['code']
35        );
36}
37$tabsheet->select($page['tab']);
38$tabsheet->assign();
39
40
41if ($page['tab'] == 'albums') {
42        $template->clear_assign(array('ADMIN_CONTENT', 'comments', 'LIST', 'F_ACTION'));
43
44        // +-----------------------------------------------------------------------+
45        //                              Actions
46        // +-----------------------------------------------------------------------+
47        if (!empty($_POST)) {
48                if (!empty($_POST['comments'])) {
49                        check_input_parameter('comments', $_POST, true, PATTERN_ID);
50
51                        if (isset($_POST['validate_albums'])) {
52                                $query = 'UPDATE '.COA_TABLE.' SET
53                                                validated = \'true\',
54                                                validation_date = NOW()
55                                        WHERE id IN ('.implode(',', $_POST['comments']).')
56                                ;';
57                                pwg_query($query);
58
59                                array_push($page['infos'], l10n_dec(
60                                        '%d user comment validated', '%d user comments validated',
61                                        count($_POST['comments'])
62                                ));
63                        }
64
65                        if (isset($_POST['reject_albums'])) {
66                                $query = 'DELETE FROM '.COA_TABLE.'
67                                        WHERE id IN ('.implode(',', $_POST['comments']).')
68                                ;';
69                                pwg_query($query);
70
71                                array_push($page['infos'], l10n_dec(
72                                        '%d user comment rejected', '%d user comments rejected',
73                                        count($_POST['comments'])
74                                ));
75                        }
76                }
77        }
78
79        // +-----------------------------------------------------------------------+
80        //                              Infos (re-assignation needed)
81        // +-----------------------------------------------------------------------+
82        if (count($page['infos']) != 0) {
83                $template->assign('infos', $page['infos']);
84        }
85
86        // +-----------------------------------------------------------------------+
87        //                              Comments display
88        // +-----------------------------------------------------------------------+
89        $list = array();
90
91        $query = 'SELECT
92                        c.id,
93                        c.category_id,
94                        c.date,
95                        c.author,
96                        '.$conf['user_fields']['username'].' AS username,
97                        c.content,
98                        i.name
99                FROM '.COA_TABLE.' AS c
100                INNER JOIN '.CATEGORIES_TABLE.' AS i
101                ON i.id = c.category_id
102                LEFT JOIN '.USERS_TABLE.' AS u
103                ON u.'.$conf['user_fields']['id'].' = c.author_id
104                WHERE validated = \'false\'
105                ORDER BY c.date DESC
106        ;';
107        $result = pwg_query($query);
108
109        while ($row = pwg_db_fetch_assoc($result)) {
110                if (empty($row['author_id'])) {
111                        $author_name = $row['author'];
112                } else {
113                        $author_name = stripslashes($row['username']);
114                }
115               
116                $template->append('comments', array(
117                        'CAT_URL' => PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$row['category_id'],
118                        'CAT_NAME' => $row['name'],
119                        'ID' => $row['id'],
120                        'AUTHOR' => trigger_event('render_comment_author', $author_name),
121                        'DATE' => format_date($row['date'], true),
122                        'CONTENT' => trigger_event('render_comment_content',$row['content']),
123                ));
124
125                array_push($list, $row['id']);
126        }
127
128        // template
129        $template->set_filename('comments', dirname(__FILE__) .'/../template/coa_admin_comments.tpl');
130        $template->assign(array(
131                'F_ACTION' => get_root_url().'admin.php?page=comments&amp;section=albums',
132                'LIST' => implode(',', $list),
133        ));
134        $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
135}
136
137?>
Note: See TracBrowser for help on using the repository browser.