[20090] | 1 | <?php |
---|
| 2 | if (!defined('USER_COLLEC_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | // actions |
---|
| 5 | if (isset($_GET['delete'])) |
---|
| 6 | { |
---|
| 7 | pwg_query('DELETE FROM '.COLLECTIONS_TABLE.' WHERE id = '.$_GET['delete'].';'); |
---|
| 8 | pwg_query('DELETE FROM '.COLLECTION_IMAGES_TABLE.' WHERE col_id = '.$_GET['delete'].';'); |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | // filter |
---|
| 12 | $where_clauses = array('1=1'); |
---|
| 13 | $order_by = 'date_creation DESC, name ASC'; |
---|
| 14 | |
---|
| 15 | if (isset($_POST['filter'])) |
---|
| 16 | { |
---|
| 17 | if (!empty($_POST['username'])) |
---|
| 18 | { |
---|
| 19 | array_push($where_clauses, 'username LIKE "%'.$_POST['username'].'%"'); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | if (!empty($_POST['name'])) |
---|
| 23 | { |
---|
| 24 | array_push($where_clauses, 'name LIKE "%'.$_POST['name'].'%"'); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | $order_by = $_POST['order_by'].' '.$_POST['direction']; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | // get sets |
---|
| 32 | $query = ' |
---|
| 33 | SELECT |
---|
| 34 | c.*, |
---|
| 35 | u.'.$conf['user_fields']['username'].' AS username |
---|
| 36 | FROM '.COLLECTIONS_TABLE.' AS c |
---|
| 37 | INNER JOIN '.USERS_TABLE.' AS u |
---|
| 38 | ON c.user_id = u.'.$conf['user_fields']['id'].' |
---|
| 39 | WHERE |
---|
| 40 | '.implode("\n AND ", $where_clauses).' |
---|
| 41 | ORDER BY '.$order_by.' |
---|
| 42 | ;'; |
---|
| 43 | $sets = hash_from_query($query, 'id'); |
---|
| 44 | |
---|
| 45 | foreach ($sets as $row) |
---|
| 46 | { |
---|
| 47 | $template->append('sets', array( |
---|
| 48 | 'NAME' => $row['name'], |
---|
| 49 | 'NB_IMAGES' => $row['nb_images'], |
---|
| 50 | 'DATE_CREATION' => format_date($row['date_creation'], true), |
---|
| 51 | 'USERNAME' => $row['username'], |
---|
| 52 | 'IS_PUBLIC' => (bool)$row['public'], |
---|
| 53 | 'U_PUBLIC' => USER_COLLEC_PUBLIC . 'view/'.$row['public_id'], |
---|
| 54 | 'U_EDIT' => USER_COLLEC_PUBLIC . 'edit/'.$row['id'], |
---|
| 55 | 'U_EXPORT' => USER_COLLEC_ADMIN . '-export&col_id='.$row['id'], |
---|
| 56 | 'U_DELETE' => USER_COLLEC_ADMIN . '-sets&delete='.$row['id'], |
---|
| 57 | )); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | // filter options |
---|
| 62 | $page['order_by_items'] = array( |
---|
| 63 | 'date_creation' => l10n('Creation date'), |
---|
| 64 | 'nb_images' => l10n('Number of images'), |
---|
| 65 | ); |
---|
| 66 | |
---|
| 67 | $page['direction_items'] = array( |
---|
| 68 | 'DESC' => l10n('descending'), |
---|
| 69 | 'ASC' => l10n('ascending'), |
---|
| 70 | ); |
---|
| 71 | |
---|
| 72 | $template->assign('order_options', $page['order_by_items']); |
---|
| 73 | $template->assign('order_selected', |
---|
| 74 | isset($_POST['order_by']) ? $_POST['order_by'] : ''); |
---|
| 75 | |
---|
| 76 | $template->assign('direction_options', $page['direction_items']); |
---|
| 77 | $template->assign('direction_selected', |
---|
| 78 | isset($_POST['direction']) ? $_POST['direction'] : ''); |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | $template->assign(array( |
---|
| 82 | 'F_USERNAME' => @htmlentities($_POST['username'], ENT_COMPAT, 'UTF-8'), |
---|
| 83 | 'F_NAME' => @htmlentities($_POST['name'], ENT_COMPAT, 'UTF-8'), |
---|
| 84 | 'F_FILTER_ACTION' => USER_COLLEC_ADMIN . '-sets', |
---|
| 85 | )); |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | $template->set_filename('user_collections', dirname(__FILE__) . '/template/sets.tpl'); |
---|
| 89 | |
---|
| 90 | ?> |
---|