1 | <?php |
---|
2 | defined('USER_COLLEC_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | // collections orders |
---|
5 | if (isset($_GET['uc_collection_order'])) |
---|
6 | { |
---|
7 | if ( (int)$_GET['uc_collection_order'] > 0) |
---|
8 | { |
---|
9 | pwg_set_session_var('uc_collection_order', (int)$_GET['uc_collection_order']); |
---|
10 | } |
---|
11 | else |
---|
12 | { |
---|
13 | pwg_unset_session_var('uc_collection_order'); |
---|
14 | } |
---|
15 | redirect(USER_COLLEC_PUBLIC); |
---|
16 | } |
---|
17 | |
---|
18 | $col_order_id = pwg_get_session_var('uc_collection_order', 0); |
---|
19 | $orders = get_collections_preferred_orders(); |
---|
20 | |
---|
21 | |
---|
22 | // get sorted collections |
---|
23 | $query = ' |
---|
24 | SELECT * |
---|
25 | FROM '.COLLECTIONS_TABLE.' |
---|
26 | WHERE user_id = '.$user['id'].' |
---|
27 | ORDER BY '.$orders[$col_order_id][1].' |
---|
28 | '; |
---|
29 | $categories = hash_from_query($query, 'id'); |
---|
30 | |
---|
31 | |
---|
32 | // pagination |
---|
33 | $page['startcat'] = isset($_GET['startcat']) ? $_GET['startcat'] : 0; |
---|
34 | $page['total_categories'] = count($categories); |
---|
35 | |
---|
36 | $template->assign('COLLECTIONS_COUNT', $page['total_categories']); |
---|
37 | |
---|
38 | $categories = array_slice( |
---|
39 | $categories, |
---|
40 | $page['startcat'], |
---|
41 | $conf['nb_categories_page'] |
---|
42 | ); |
---|
43 | |
---|
44 | |
---|
45 | // order menu |
---|
46 | if ($page['total_categories']) |
---|
47 | { |
---|
48 | $url = add_url_params(USER_COLLEC_PUBLIC, array('uc_collection_order' => '')); |
---|
49 | |
---|
50 | foreach ($orders as $order_id => $order) |
---|
51 | { |
---|
52 | if ($order[2]) |
---|
53 | { |
---|
54 | $template->append( |
---|
55 | 'image_orders', |
---|
56 | array( |
---|
57 | 'DISPLAY' => $order[0], |
---|
58 | 'URL' => $url.$order_id, |
---|
59 | 'SELECTED' => ($col_order_id == $order_id ? true:false), |
---|
60 | ) |
---|
61 | ); |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | // collections details |
---|
68 | if ($page['total_categories']) |
---|
69 | { |
---|
70 | $categories_id = array_map(create_function('$c', 'return $c["id"];'), $categories); |
---|
71 | |
---|
72 | $query = ' |
---|
73 | SELECT * FROM ( |
---|
74 | SELECT |
---|
75 | i.*, |
---|
76 | ci.col_id |
---|
77 | FROM '.IMAGES_TABLE.' AS i |
---|
78 | INNER JOIN '.COLLECTION_IMAGES_TABLE.' AS ci |
---|
79 | ON i.id = ci.image_id |
---|
80 | WHERE col_id IN('.implode(',', $categories_id).') |
---|
81 | ORDER BY ci.add_date DESC |
---|
82 | ) AS t |
---|
83 | GROUP BY col_id |
---|
84 | ;'; |
---|
85 | $thumbnails = hash_from_query($query, 'col_id'); |
---|
86 | |
---|
87 | $thumbnails[0] = array( |
---|
88 | 'id' => 0, |
---|
89 | 'path' => 'themes/default/icon/img_small.png', |
---|
90 | 'picture_ext' => 'png', |
---|
91 | 'width' => 32, |
---|
92 | 'height' => 32, |
---|
93 | 'rotation' => 0, |
---|
94 | ); |
---|
95 | |
---|
96 | foreach ($thumbnails as &$info) |
---|
97 | { |
---|
98 | $info['src_image'] = new SrcImage($info); |
---|
99 | } |
---|
100 | unset($info); |
---|
101 | |
---|
102 | $tpl_thumbnails_var = array(); |
---|
103 | |
---|
104 | foreach ($categories as $category) |
---|
105 | { |
---|
106 | $thumb = empty($thumbnails[ $category['id'] ]) ? $thumbnails[0] : $thumbnails[ $category['id'] ]; |
---|
107 | $counter = get_display_images_count($category['nb_images'], $category['nb_images'], 0); |
---|
108 | |
---|
109 | $tpl_var = array_merge($category, array( |
---|
110 | 'representative' => $thumb, |
---|
111 | 'TN_ALT' => strip_tags($category['name']), |
---|
112 | 'URL' => USER_COLLEC_PUBLIC.'edit/'.$category['id'], |
---|
113 | 'CAPTION_NB_IMAGES' => empty($counter) ? l10n('%d photo', 0) : $counter, |
---|
114 | 'NAME' => trigger_change('render_category_name', $category['name']), |
---|
115 | 'DESCRIPTION' => trigger_change('render_category_description', $category['comment'], 'subcatify_category_description'), |
---|
116 | 'INFO_DATES' => format_date($category['date_creation'], true), |
---|
117 | 'U_DELETE' => add_url_params(USER_COLLEC_PUBLIC, array('action'=>'delete','col_id'=>$category['id'])), |
---|
118 | )); |
---|
119 | |
---|
120 | $tpl_thumbnails_var[] = $tpl_var; |
---|
121 | } |
---|
122 | |
---|
123 | $derivative_params = trigger_change('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_THUMB) ); |
---|
124 | $template->assign(array( |
---|
125 | 'maxRequests' => $conf['max_requests'], |
---|
126 | 'category_thumbnails' => $tpl_thumbnails_var, |
---|
127 | 'derivative_params' => $derivative_params, |
---|
128 | )); |
---|
129 | |
---|
130 | // navigation bar |
---|
131 | $page['cats_navigation_bar'] = array(); |
---|
132 | if ($page['total_categories'] > $conf['nb_categories_page']) |
---|
133 | { |
---|
134 | $page['cats_navigation_bar'] = create_navigation_bar( |
---|
135 | $self_url, |
---|
136 | $page['total_categories'], |
---|
137 | $page['startcat'], |
---|
138 | $conf['nb_categories_page'], |
---|
139 | false, 'startcat' |
---|
140 | ); |
---|
141 | |
---|
142 | $template->assign('cats_navbar', $page['cats_navigation_bar'] ); |
---|
143 | } |
---|
144 | |
---|
145 | $template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl'); |
---|
146 | $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails'); |
---|
147 | } |
---|