1 | <?php |
---|
2 | if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | // actions |
---|
5 | if (isset($_GET['delete'])) |
---|
6 | { |
---|
7 | $BatchDownloader = new BatchDownloader($_GET['delete']); |
---|
8 | $BatchDownloader->delete(); |
---|
9 | unset($BatchDownloader); |
---|
10 | } |
---|
11 | if (isset($_GET['cancel'])) |
---|
12 | { |
---|
13 | $BatchDownloader = new BatchDownloader($_GET['cancel']); |
---|
14 | $BatchDownloader->updateParam('total_size', $BatchDownloader->getEstimatedTotalSize()); |
---|
15 | $BatchDownloader->updateParam('status', 'done'); |
---|
16 | $BatchDownloader->deleteLastArchive(); |
---|
17 | $BatchDownloader->clearImages(); |
---|
18 | unset($BatchDownloader); |
---|
19 | } |
---|
20 | if (isset($_POST['delete_done'])) |
---|
21 | { |
---|
22 | $query = ' |
---|
23 | DELETE 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 | |
---|
39 | if (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 = ' |
---|
62 | SELECT |
---|
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 | |
---|
74 | foreach ($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 | 'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&delete='.$set->getParam('id'), |
---|
83 | 'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&cancel='.$set->getParam('id'), |
---|
84 | ) |
---|
85 | )); |
---|
86 | |
---|
87 | unset($set); |
---|
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('Number of images'), |
---|
118 | 'nb_archives' => l10n('Number of archives'), |
---|
119 | ); |
---|
120 | |
---|
121 | $page['direction_items'] = array( |
---|
122 | 'DESC' => l10n('descending'), |
---|
123 | 'ASC' => l10n('ascending'), |
---|
124 | ); |
---|
125 | |
---|
126 | $template->assign(array( |
---|
127 | 'status_options' => $page['status_items'], |
---|
128 | 'status_selected' => isset($_POST['status']) ? $_POST['status'] : '', |
---|
129 | 'type_options' => $page['type_items'], |
---|
130 | 'type_selected' => isset($_POST['type']) ? $_POST['type'] : '', |
---|
131 | 'order_options' => $page['order_by_items'], |
---|
132 | 'order_selected' => isset($_POST['order_by']) ? $_POST['order_by'] : '', |
---|
133 | 'direction_options' => $page['direction_items'], |
---|
134 | 'direction_selected' => isset($_POST['direction']) ? $_POST['direction'] : '', |
---|
135 | |
---|
136 | 'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'), |
---|
137 | 'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets', |
---|
138 | )); |
---|
139 | |
---|
140 | |
---|
141 | $template->set_filename('batch_download', dirname(__FILE__) . '/template/sets.tpl'); |
---|
142 | |
---|
143 | ?> |
---|