source: extensions/UserCollections/admin/sets.php @ 23551

Last change on this file since 23551 was 23551, checked in by mistic100, 11 years ago

many corrections & optimizations + remove useless code + clean

File size: 2.4 KB
Line 
1<?php
2if (!defined('USER_COLLEC_PATH')) die('Hacking attempt!');
3
4// actions
5if (isset($_GET['delete']))
6{
7  pwg_query('DELETE FROM '.COLLECTIONS_TABLE.' WHERE id = '.$_GET['delete'].';');
8  pwg_query('DELETE FROM '.COLLECTION_IMAGES_TABLE.' WHERE col_id = '.$_GET['delete'].';');
9}
10
11// filter
12$where_clauses = array('1=1');
13$order_by = 'date_creation DESC, name ASC';
14
15if (isset($_POST['filter']))
16{
17  if (!empty($_POST['username']))
18  {
19    array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"');
20  }
21 
22  if (!empty($_POST['name']))
23  {
24    array_push($where_clauses, 'name LIKE "%'.$_POST['name'].'%"');
25  }
26 
27  $order_by = $_POST['order_by'].' '.$_POST['direction'];
28}
29
30
31// get sets
32$query = '
33SELECT
34    c.*,
35    u.'.$conf['user_fields']['username'].' AS username
36  FROM '.COLLECTIONS_TABLE.' AS c
37    INNER JOIN '.USERS_TABLE.' AS u
38    ON c.user_id = u.'.$conf['user_fields']['id'].'
39  WHERE
40    '.implode("\n    AND ", $where_clauses).'
41  ORDER BY '.$order_by.'
42;';
43$sets = hash_from_query($query, 'id');
44
45foreach ($sets as $row)
46{
47  $template->append('sets', array(
48    'NAME' => trigger_event('render_category_name', $row['name']),
49    'NB_IMAGES' => $row['nb_images'],
50    'DATE_CREATION' => format_date($row['date_creation'], true),
51    'USERNAME' => $row['username'],
52    'IS_PUBLIC' => (bool)$row['public'],
53    'U_PUBLIC' => USER_COLLEC_PUBLIC . 'view/'.$row['public_id'],
54    'U_EDIT' => USER_COLLEC_PUBLIC . 'edit/'.$row['id'],
55    'U_EXPORT' => USER_COLLEC_ADMIN . '-export&amp;col_id='.$row['id'],
56    'U_DELETE' => USER_COLLEC_ADMIN . '-sets&amp;delete='.$row['id'],
57    ));
58}
59
60
61// filter options
62$page['order_by_items'] = array(
63  'date_creation' => l10n('Creation date'),
64  'nb_images' => l10n('Number of images'),
65  );
66
67$page['direction_items'] = array(
68  'DESC' => l10n('descending'),
69  'ASC' => l10n('ascending'),
70  );
71
72
73$template->assign(array(
74  'order_options' => $page['order_by_items'],
75  'order_selected' => isset($_POST['order_by']) ? $_POST['order_by'] : '',
76  'direction_options' => $page['direction_items'],
77  'direction_selected' => isset($_POST['direction']) ? $_POST['direction'] : '',
78 
79  'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'),
80  'F_NAME' => @htmlentities($_POST['name'], ENT_COMPAT, 'UTF-8'),
81  'F_FILTER_ACTION' => USER_COLLEC_ADMIN . '-sets',
82  ));
83
84
85$template->set_filename('user_collections', realpath(USER_COLLEC_PATH . 'admin/template/sets.tpl'));
86
87?>
Note: See TracBrowser for help on using the repository browser.