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

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

update for Piwigo 2.6 + code cleaning + fix unable to cancel set during generation

File size: 4.4 KB
RevLine 
[16379]1<?php
[25932]2defined('BATCH_DOWNLOAD_PATH') or die('Hacking attempt!');
[16379]3
[16400]4// actions
5if (isset($_GET['delete']))
6{
[23292]7  $set = new BatchDownloader($_GET['delete']);
8  $set->delete();
9  unset($set);
[16400]10}
11if (isset($_GET['cancel']))
12{
[25932]13  $set = new BatchDownloader($_GET['cancel']);
[23292]14  $set->updateParam('total_size', $set->getEstimatedTotalSize());
15  $set->updateParam('nb_zip', $set->getEstimatedArchiveNumber());
16  $set->updateParam('status', 'done');
[23383]17  $set->deleteArchives();
[23292]18  $set->clearImages();
19  unset($set);
[16400]20}
[16697]21if (isset($_POST['delete_done']))
22{
23  $query = '
[23292]24SELECT id
25  FROM '.BATCH_DOWNLOAD_TSETS.'
[16697]26  WHERE
27    status = "done" AND
28    date_creation < DATE_SUB(NOW(), INTERVAL 1 HOUR)
29;';
[25932]30
[23292]31  $sets = array_from_query($query, 'id');
[25932]32
[23292]33  foreach ($sets as $set_id)
34  {
35    $set = new BatchDownloader($set_id);
36    $set->delete();
37    unset($set);
38  }
[16697]39}
[16379]40
[16400]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  {
[25932]50    $where_clauses[] = 'username LIKE "%'.$_POST['username'].'%"';
[16400]51  }
[25932]52
[16400]53  if ($_POST['type'] != -1)
54  {
[25932]55    $where_clauses[] = 'type = "'.$_POST['type'].'"';
[16400]56  }
[25932]57
[16400]58  if ($_POST['status'] != -1)
59  {
[23317]60    if ($_POST['status'] == 'new')
[25932]61      $where_clauses[] = '(status = "new" OR status = "ready")';
[23317]62    else
[25932]63      $where_clauses[] = 'status = "'.$_POST['status'].'"';
[16400]64  }
[25932]65
[23318]66  if ($_POST['size'] != -1)
67  {
[25932]68    $where_clauses[] = 'size = "'.$_POST['size'].'"';
[23318]69  }
[25932]70
[23318]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  }
[16400]79}
80
81
82// get sets
83$query = '
[25932]84SELECT
[16400]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
96foreach ($sets as $set_id => $username)
97{
98  $set = new BatchDownloader($set_id);
[25932]99
[16400]100  $template->append('sets', array_merge(
101    $set->getSetInfo(),
102    array(
103      'USERNAME' => $username,
[16689]104      'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;delete='.$set->getParam('id'),
105      'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&amp;cancel='.$set->getParam('id'),
[16400]106    )
107    ));
[25932]108
[23280]109  unset($set);
[16400]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'),
[16598]133  'collection' => l10n('User collection'),
[16400]134  );
135
[23318]136$page['size_items'] = array(
137  -1 => '------------',
138  );
139foreach (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
[16400]145$page['order_by_items'] = array(
146  'date_creation' => l10n('Creation date'),
147  'total_size' => l10n('Total size'),
[18373]148  'nb_images' => l10n('Number of images'),
149  'nb_archives' => l10n('Number of archives'),
[23318]150  'size' => l10n('Photo sizes'),
[16400]151  );
152
153$page['direction_items'] = array(
154  'DESC' => l10n('descending'),
155  'ASC' => l10n('ascending'),
156  );
157
[21607]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'] : '',
[23318]163  'size_options' => $page['size_items'],
164  'size_selected' => isset($_POST['size']) ? $_POST['size'] : '',
[21607]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'] : '',
[16400]169
170  'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'),
171  'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets',
172  ));
173
174
[25932]175$template->set_filename('batch_download', realpath(BATCH_DOWNLOAD_PATH . 'admin/template/sets.tpl'));
Note: See TracBrowser for help on using the repository browser.