1 | <?php |
---|
2 | if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | // actions |
---|
5 | if (isset($_GET['delete'])) |
---|
6 | { |
---|
7 | $set = new BatchDownloader($_GET['delete']); |
---|
8 | $set->delete(); |
---|
9 | unset($set); |
---|
10 | } |
---|
11 | if (isset($_GET['cancel'])) |
---|
12 | { |
---|
13 | $set = new BatchDownloader($_GET['cancel']); |
---|
14 | $set->updateParam('total_size', $set->getEstimatedTotalSize()); |
---|
15 | $set->updateParam('nb_zip', $set->getEstimatedArchiveNumber()); |
---|
16 | $set->updateParam('status', 'done'); |
---|
17 | $set->deleteArchives(); |
---|
18 | $set->clearImages(); |
---|
19 | unset($set); |
---|
20 | } |
---|
21 | if (isset($_POST['delete_done'])) |
---|
22 | { |
---|
23 | $query = ' |
---|
24 | SELECT id |
---|
25 | FROM '.BATCH_DOWNLOAD_TSETS.' |
---|
26 | WHERE |
---|
27 | status = "done" AND |
---|
28 | date_creation < DATE_SUB(NOW(), INTERVAL 1 HOUR) |
---|
29 | ;'; |
---|
30 | |
---|
31 | $sets = array_from_query($query, 'id'); |
---|
32 | |
---|
33 | foreach ($sets as $set_id) |
---|
34 | { |
---|
35 | $set = new BatchDownloader($set_id); |
---|
36 | $set->delete(); |
---|
37 | unset($set); |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | // filter |
---|
43 | $where_clauses = array('1=1'); |
---|
44 | $order_by = 'date_creation DESC, status DESC'; |
---|
45 | |
---|
46 | if (isset($_POST['filter'])) |
---|
47 | { |
---|
48 | if (!empty($_POST['username'])) |
---|
49 | { |
---|
50 | array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"'); |
---|
51 | } |
---|
52 | |
---|
53 | if ($_POST['type'] != -1) |
---|
54 | { |
---|
55 | array_push($where_clauses, 'type = "'.$_POST['type'].'"'); |
---|
56 | } |
---|
57 | |
---|
58 | if ($_POST['status'] != -1) |
---|
59 | { |
---|
60 | if ($_POST['status'] == 'new') |
---|
61 | array_push($where_clauses, '(status = "new" OR status = "ready")'); |
---|
62 | else |
---|
63 | array_push($where_clauses, 'status = "'.$_POST['status'].'"'); |
---|
64 | } |
---|
65 | |
---|
66 | if ($_POST['size'] != -1) |
---|
67 | { |
---|
68 | array_push($where_clauses, 'size = "'.$_POST['size'].'"'); |
---|
69 | } |
---|
70 | |
---|
71 | if ($_POST['order_by'] == 'size') |
---|
72 | { |
---|
73 | $order_by = 'FIND_IN_SET(size, "square,thumb,2small,xsmall,small,medium,large,xlarge,xxlarge,original") '.$_POST['direction']; |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | $order_by = $_POST['order_by'].' '.$_POST['direction']; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | // get sets |
---|
83 | $query = ' |
---|
84 | SELECT |
---|
85 | s.id, |
---|
86 | u.'.$conf['user_fields']['username'].' AS username |
---|
87 | FROM '.BATCH_DOWNLOAD_TSETS.' AS s |
---|
88 | INNER JOIN '.USERS_TABLE.' AS u |
---|
89 | ON s.user_id = u.'.$conf['user_fields']['id'].' |
---|
90 | WHERE |
---|
91 | '.implode("\n AND ", $where_clauses).' |
---|
92 | ORDER BY '.$order_by.' |
---|
93 | ;'; |
---|
94 | $sets = simple_hash_from_query($query, 'id', 'username'); |
---|
95 | |
---|
96 | foreach ($sets as $set_id => $username) |
---|
97 | { |
---|
98 | $set = new BatchDownloader($set_id); |
---|
99 | |
---|
100 | $template->append('sets', array_merge( |
---|
101 | $set->getSetInfo(), |
---|
102 | array( |
---|
103 | 'USERNAME' => $username, |
---|
104 | 'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&delete='.$set->getParam('id'), |
---|
105 | 'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&cancel='.$set->getParam('id'), |
---|
106 | ) |
---|
107 | )); |
---|
108 | |
---|
109 | unset($set); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | // filter options |
---|
114 | $page['status_items'] = array( |
---|
115 | -1 => '------------', |
---|
116 | 'new' => l10n('new'), |
---|
117 | 'download' => l10n('download'), |
---|
118 | 'done' => l10n('done'), |
---|
119 | ); |
---|
120 | |
---|
121 | $page['type_items'] = array( |
---|
122 | -1 => '------------', |
---|
123 | 'calendar' => l10n('Calendar'), |
---|
124 | 'category' => l10n('Album'), |
---|
125 | 'flat' => l10n('Whole gallery'), |
---|
126 | 'tags' => l10n('Tags'), |
---|
127 | 'search' => l10n('Search'), |
---|
128 | 'favorites' => l10n('Favorites'), |
---|
129 | 'most_visited' => l10n('Most visited'), |
---|
130 | 'best_rated' => l10n('Best rated'), |
---|
131 | 'list' => l10n('Random'), |
---|
132 | 'recent_pics' => l10n('Recent photos'), |
---|
133 | 'collection' => l10n('User collection'), |
---|
134 | ); |
---|
135 | |
---|
136 | $page['size_items'] = array( |
---|
137 | -1 => '------------', |
---|
138 | ); |
---|
139 | foreach (ImageStdParams::get_defined_type_map() as $params) |
---|
140 | { |
---|
141 | $page['size_items'][ $params->type ] = l10n($params->type); |
---|
142 | } |
---|
143 | $page['size_items']['original'] = l10n('Original'); |
---|
144 | |
---|
145 | $page['order_by_items'] = array( |
---|
146 | 'date_creation' => l10n('Creation date'), |
---|
147 | 'total_size' => l10n('Total size'), |
---|
148 | 'nb_images' => l10n('Number of images'), |
---|
149 | 'nb_archives' => l10n('Number of archives'), |
---|
150 | 'size' => l10n('Photo sizes'), |
---|
151 | ); |
---|
152 | |
---|
153 | $page['direction_items'] = array( |
---|
154 | 'DESC' => l10n('descending'), |
---|
155 | 'ASC' => l10n('ascending'), |
---|
156 | ); |
---|
157 | |
---|
158 | $template->assign(array( |
---|
159 | 'status_options' => $page['status_items'], |
---|
160 | 'status_selected' => isset($_POST['status']) ? $_POST['status'] : '', |
---|
161 | 'type_options' => $page['type_items'], |
---|
162 | 'type_selected' => isset($_POST['type']) ? $_POST['type'] : '', |
---|
163 | 'size_options' => $page['size_items'], |
---|
164 | 'size_selected' => isset($_POST['size']) ? $_POST['size'] : '', |
---|
165 | 'order_options' => $page['order_by_items'], |
---|
166 | 'order_selected' => isset($_POST['order_by']) ? $_POST['order_by'] : '', |
---|
167 | 'direction_options' => $page['direction_items'], |
---|
168 | 'direction_selected' => isset($_POST['direction']) ? $_POST['direction'] : '', |
---|
169 | |
---|
170 | 'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'), |
---|
171 | 'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets', |
---|
172 | )); |
---|
173 | |
---|
174 | |
---|
175 | $template->set_filename('batch_download', dirname(__FILE__) . '/template/sets.tpl'); |
---|
176 | |
---|
177 | ?> |
---|