source: extensions/BatchDownloader/admin/sets.php @ 16731

Last change on this file since 16731 was 16697, checked in by mistic100, 12 years ago

-button on admin page to purge download list
-confirmation is properly updated on UserCollection page

File size: 3.9 KB
Line 
1<?php
2if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!');
3
4// actions
5if (isset($_GET['delete']))
6{
7  $BatchDownloader = new BatchDownloader($_GET['delete']);
8  $BatchDownloader->deleteLastArchive();
9  $BatchDownloader->clearImages();
10  pwg_query('DELETE FROM '.BATCH_DOWNLOAD_TSETS.' WHERE id = '.$_GET['delete'].';');
11}
12if (isset($_GET['cancel']))
13{
14  $BatchDownloader = new BatchDownloader($_GET['cancel']); 
15  $BatchDownloader->updateParam('total_size', $BatchDownloader->getEstimatedTotalSize());
16  $BatchDownloader->updateParam('status', 'done');
17  $BatchDownloader->deleteLastArchive();
18  $BatchDownloader->clearImages();
19}
20if (isset($_POST['delete_done']))
21{
22  $query = '
23DELETE s, i
24  FROM '.BATCH_DOWNLOAD_TSETS.' AS s
25    LEFT JOIN '.BATCH_DOWNLOAD_TIMAGES.' AS i
26    ON i.set_id = s.id
27  WHERE
28    status = "done" AND
29    date_creation < DATE_SUB(NOW(), INTERVAL 1 HOUR)
30;';
31  pwg_query($query);
32}
33
34
35// filter
36$where_clauses = array('1=1');
37$order_by = 'date_creation DESC, status DESC';
38
39if (isset($_POST['filter']))
40{
41  if (!empty($_POST['username']))
42  {
43    array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"');
44  }
45 
46  if ($_POST['type'] != -1)
47  {
48    array_push($where_clauses, 'type = "'.$_POST['type'].'"');
49  }
50 
51  if ($_POST['status'] != -1)
52  {
53    array_push($where_clauses, 'status = "'.$_POST['status'].'"');
54  }
55 
56  $order_by = $_POST['order_by'].' '.$_POST['direction'];
57}
58
59
60// get sets
61$query = '
62SELECT
63    s.id,
64    u.'.$conf['user_fields']['username'].' AS username
65  FROM '.BATCH_DOWNLOAD_TSETS.' AS s
66    INNER JOIN '.USERS_TABLE.' AS u
67    ON s.user_id = u.'.$conf['user_fields']['id'].'
68  WHERE
69    '.implode("\n    AND ", $where_clauses).'
70  ORDER BY '.$order_by.'
71;';
72$sets = simple_hash_from_query($query, 'id', 'username');
73
74foreach ($sets as $set_id => $username)
75{
76  $set = new BatchDownloader($set_id);
77 
78  $template->append('sets', array_merge(
79    $set->getSetInfo(),
80    array(
81      'USERNAME' => $username,
82      'STATUS' => $set->getParam('status'),
83      'LAST_ZIP' => $set->getParam('last_zip'),
84      'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;delete='.$set->getParam('id'),
85      'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;cancel='.$set->getParam('id'),
86    )
87    ));
88}
89
90
91// filter options
92$page['status_items'] = array(
93  -1 => '------------',
94  'new' => l10n('new'),
95  'download' => l10n('download'),
96  'done' => l10n('done'),
97  );
98
99$page['type_items'] = array(
100  -1 => '------------',
101  'calendar' => l10n('Calendar'),
102  'category' => l10n('Album'),
103  'flat' => l10n('Whole gallery'),
104  'tags' => l10n('Tags'),
105  'search' => l10n('Search'),
106  'favorites' => l10n('Favorites'),
107  'most_visited' => l10n('Most visited'),
108  'best_rated' => l10n('Best rated'),
109  'list' => l10n('Random'),
110  'recent_pics' => l10n('Recent photos'),
111  'collection' => l10n('User collection'),
112  );
113
114$page['order_by_items'] = array(
115  'date_creation' => l10n('Creation date'),
116  'total_size' => l10n('Total size'),
117  'nb_images' => l10n('Nb images'),
118  'nb_archives' => l10n('Nb archives'),
119  );
120
121$page['direction_items'] = array(
122  'DESC' => l10n('descending'),
123  'ASC' => l10n('ascending'),
124  );
125
126$template->assign('status_options', $page['status_items']);
127$template->assign('status_selected',
128    isset($_POST['status']) ? $_POST['status'] : '');
129
130$template->assign('type_options', $page['type_items']);
131$template->assign('type_selected',
132    isset($_POST['type']) ? $_POST['type'] : '');
133
134$template->assign('order_options', $page['order_by_items']);
135$template->assign('order_selected',
136    isset($_POST['order_by']) ? $_POST['order_by'] : '');
137
138$template->assign('direction_options', $page['direction_items']);
139$template->assign('direction_selected',
140    isset($_POST['direction']) ? $_POST['direction'] : '');
141
142
143$template->assign(array(
144  'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'),
145  'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets',
146  ));
147
148
149$template->set_filename('batch_download', dirname(__FILE__) . '/template/sets.tpl');
150
151?>
Note: See TracBrowser for help on using the repository browser.