[16379] | 1 | <?php |
---|
| 2 | if (!defined('BATCH_DOWNLOAD_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[16400] | 4 | // actions |
---|
| 5 | if (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 | } |
---|
| 12 | if (isset($_GET['cancel'])) |
---|
| 13 | { |
---|
[16598] | 14 | $BatchDownloader = new BatchDownloader($_GET['cancel']); |
---|
| 15 | $BatchDownloader->updateParam('total_size', $BatchDownloader->getEstimatedTotalSize()); |
---|
| 16 | $BatchDownloader->updateParam('status', 'done'); |
---|
[16400] | 17 | $BatchDownloader->deleteLastArchive(); |
---|
| 18 | $BatchDownloader->clearImages(); |
---|
| 19 | } |
---|
[16697] | 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 | } |
---|
[16379] | 33 | |
---|
[16400] | 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); |
---|
[16697] | 77 | |
---|
[16400] | 78 | $template->append('sets', array_merge( |
---|
| 79 | $set->getSetInfo(), |
---|
| 80 | array( |
---|
| 81 | 'USERNAME' => $username, |
---|
[16689] | 82 | 'U_DELETE' => BATCH_DOWNLOAD_ADMIN . '-sets&delete='.$set->getParam('id'), |
---|
| 83 | 'U_CANCEL' => BATCH_DOWNLOAD_ADMIN . '-sets&cancel='.$set->getParam('id'), |
---|
[16400] | 84 | ) |
---|
| 85 | )); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | // filter options |
---|
| 90 | $page['status_items'] = array( |
---|
| 91 | -1 => '------------', |
---|
| 92 | 'new' => l10n('new'), |
---|
| 93 | 'download' => l10n('download'), |
---|
| 94 | 'done' => l10n('done'), |
---|
| 95 | ); |
---|
| 96 | |
---|
| 97 | $page['type_items'] = array( |
---|
| 98 | -1 => '------------', |
---|
| 99 | 'calendar' => l10n('Calendar'), |
---|
| 100 | 'category' => l10n('Album'), |
---|
| 101 | 'flat' => l10n('Whole gallery'), |
---|
| 102 | 'tags' => l10n('Tags'), |
---|
| 103 | 'search' => l10n('Search'), |
---|
| 104 | 'favorites' => l10n('Favorites'), |
---|
| 105 | 'most_visited' => l10n('Most visited'), |
---|
| 106 | 'best_rated' => l10n('Best rated'), |
---|
| 107 | 'list' => l10n('Random'), |
---|
| 108 | 'recent_pics' => l10n('Recent photos'), |
---|
[16598] | 109 | 'collection' => l10n('User collection'), |
---|
[16400] | 110 | ); |
---|
| 111 | |
---|
| 112 | $page['order_by_items'] = array( |
---|
| 113 | 'date_creation' => l10n('Creation date'), |
---|
| 114 | 'total_size' => l10n('Total size'), |
---|
[18373] | 115 | 'nb_images' => l10n('Number of images'), |
---|
| 116 | 'nb_archives' => l10n('Number of archives'), |
---|
[16400] | 117 | ); |
---|
| 118 | |
---|
| 119 | $page['direction_items'] = array( |
---|
| 120 | 'DESC' => l10n('descending'), |
---|
| 121 | 'ASC' => l10n('ascending'), |
---|
| 122 | ); |
---|
| 123 | |
---|
| 124 | $template->assign('status_options', $page['status_items']); |
---|
| 125 | $template->assign('status_selected', |
---|
| 126 | isset($_POST['status']) ? $_POST['status'] : ''); |
---|
| 127 | |
---|
| 128 | $template->assign('type_options', $page['type_items']); |
---|
| 129 | $template->assign('type_selected', |
---|
| 130 | isset($_POST['type']) ? $_POST['type'] : ''); |
---|
| 131 | |
---|
| 132 | $template->assign('order_options', $page['order_by_items']); |
---|
| 133 | $template->assign('order_selected', |
---|
| 134 | isset($_POST['order_by']) ? $_POST['order_by'] : ''); |
---|
| 135 | |
---|
| 136 | $template->assign('direction_options', $page['direction_items']); |
---|
| 137 | $template->assign('direction_selected', |
---|
| 138 | isset($_POST['direction']) ? $_POST['direction'] : ''); |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | $template->assign(array( |
---|
| 142 | 'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'), |
---|
| 143 | 'F_FILTER_ACTION' => BATCH_DOWNLOAD_ADMIN . '-sets', |
---|
| 144 | )); |
---|
| 145 | |
---|
| 146 | |
---|
[16379] | 147 | $template->set_filename('batch_download', dirname(__FILE__) . '/template/sets.tpl'); |
---|
| 148 | |
---|
| 149 | ?> |
---|