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

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

fix batch deletion

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