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

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

big code cleaning

File size: 5.1 KB
Line 
1<?php
2/* Code adapted from admin/comments.php */
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5global $template, $conf;
6load_language('plugin.lang', COA_PATH);
7
8// +-----------------------------------------------------------------------+
9// |                               tabsheet                                |
10// +-----------------------------------------------------------------------+
11include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
12
13$tabs = array(
14  array(
15    'code' => 'pictures',
16    'label' => l10n('COA_comments_photos'),
17    ),
18  array(
19    'code' => 'albums',
20    'label' => l10n('COA_comments_albums'),
21    ),
22  );
23
24$tab_codes = array_map(create_function('$a', 'return $a["code"];'), $tabs);
25
26if (isset($_GET['section']) and in_array($_GET['section'], $tab_codes)) 
27{
28  $page['tab'] = $_GET['section'];
29} 
30else 
31{
32  $page['tab'] = $tabs[0]['code'];
33}
34
35$tabsheet = new tabsheet();
36foreach ($tabs as $tab) 
37{
38  $tabsheet->add(
39    $tab['code'],
40    $tab['label'],
41    get_root_url().'admin.php?page=comments&amp;section='.$tab['code']
42    );
43}
44$tabsheet->select($page['tab']);
45$tabsheet->assign();
46
47
48if ($page['tab'] == 'albums') 
49{
50  // clear template sended by original page
51  $template->clear_assign(array('ADMIN_CONTENT', 'comments', 'LIST', 'F_ACTION'));
52
53  // +-----------------------------------------------------------------------+
54  // |                                actions                                |
55  // +-----------------------------------------------------------------------+
56  if (!empty($_POST)) 
57  {
58    if (empty($_POST['comments']))
59    {
60      array_push(
61        $page['errors'],
62        l10n('Select at least one comment')
63        );
64    }
65    else
66    {
67      check_input_parameter('comments', $_POST, true, PATTERN_ID);
68
69      if (isset($_POST['validate_albums'])) 
70      {
71        $query = '
72UPDATE '.COA_TABLE.'
73  SET validated = \'true\',
74      validation_date = NOW()
75  WHERE id IN ('.implode(',', $_POST['comments']).')
76;';
77        pwg_query($query);
78
79        array_push(
80          $page['infos'], 
81          l10n_dec(
82            '%d user comment validated', '%d user comments validated',
83            count($_POST['comments'])
84            )
85          );
86      }
87
88      if (isset($_POST['reject_albums'])) 
89      {
90        $query = '
91DELETE
92  FROM '.COA_TABLE.'
93  WHERE id IN ('.implode(',', $_POST['comments']).')
94;';
95        pwg_query($query);
96
97        array_push(
98          $page['infos'], 
99          l10n_dec(
100            '%d user comment rejected', '%d user comments rejected',
101            count($_POST['comments'])
102            )
103          );
104      }
105    }
106  }
107
108  // +-----------------------------------------------------------------------+
109  // |                             template init                             |
110  // +-----------------------------------------------------------------------+
111
112  $template->set_filename('comments', dirname(__FILE__) .'/../template/admin_comments.tpl');
113
114  $template->assign(
115    array(
116      'F_ACTION' => get_root_url().'admin.php?page=comments&amp;section=albums'
117      )
118    );
119   
120  if (count($page['infos']) != 0) 
121  {
122    $template->assign('infos', $page['infos']);
123  }
124
125  // +-----------------------------------------------------------------------+
126  // |                           comments display                            |
127  // +-----------------------------------------------------------------------+
128  $list = array();
129
130  $query = '
131SELECT
132    com.id,
133    com.category_id,
134    com.date,
135    com.author,
136    '.$conf['user_fields']['username'].' AS username,
137    com.content,
138    cat.name
139  FROM '.COA_TABLE.' AS com
140    INNER JOIN '.CATEGORIES_TABLE.' AS cat
141      ON cat.id = com.category_id
142    LEFT JOIN '.USERS_TABLE.' AS u
143      ON u.'.$conf['user_fields']['id'].' = com.author_id
144  WHERE validated = \'false\'
145  ORDER BY com.date DESC
146;';
147  $result = pwg_query($query);
148
149  while ($row = pwg_db_fetch_assoc($result)) 
150  {
151    // author
152    if (empty($row['author_id'])) 
153    {
154      $author_name = $row['author'];
155    } 
156    else 
157    {
158      $author_name = stripslashes($row['username']);
159    }
160   
161    // comment content
162    $template->append(
163      'comments', 
164      array(
165        'CAT_URL' => PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$row['category_id'],
166        'CAT_NAME' => $row['name'],
167        'ID' => $row['id'],
168        'AUTHOR' => trigger_event('render_comment_author', $author_name),
169        'DATE' => format_date($row['date'], true),
170        'CONTENT' => trigger_event('render_comment_content',$row['content']),
171        )
172      );
173
174    array_push($list, $row['id']);
175  }
176
177  $template->assign('LIST', implode(',', $list));
178
179  // +-----------------------------------------------------------------------+
180  // |                           sending html code                           |
181  // +-----------------------------------------------------------------------+
182
183  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
184
185}
186
187?>
Note: See TracBrowser for help on using the repository browser.