source: extensions/AdminTools/include/events.inc.php @ 25655

Last change on this file since 25655 was 25655, checked in by mistic100, 10 years ago

quick edit for album
add language files
force default language for the toolbar
fix $_GET collision
orange save button
fix popup background color

File size: 7.0 KB
Line 
1<?php
2defined('ADMINTOOLS_PATH') or die('Hacking attempt!');
3
4/**
5 * Add main toolbar to current page
6 * @trigger loc_after_page_header
7 */
8function admintools_add_public_controller()
9{
10  global $MultiView, $conf;
11
12  if (!$MultiView->is_admin())
13  {
14    return;
15  }
16
17  global $template, $page, $user;
18
19  $url_root = get_root_url();
20
21  $tpl_vars = array(
22    'U_SITE_ADMIN' => $url_root . 'admin.php?page=',
23    'MULTIVIEW' => $MultiView->get_data(),
24    'U_SELF' => $MultiView->get_clean_url(true),
25    'USER' => $MultiView->get_user(),
26    'CURRENT_USERNAME' => $user['id']==$conf['guest_id'] ? l10n('guest') : $user['username'],
27    'PWG_TOKEN' => get_pwg_token(),
28    );
29
30  if (!is_admin())
31  {
32    load_language('admin.lang');
33  }
34
35  switch_lang_to(get_default_language());
36
37  // TODO : param to allow owner modification
38  if (script_basename() == 'picture')
39  {
40    global $picture;
41
42    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
43
44    $url_self = duplicate_picture_url();
45
46    $tpl_vars['IS_PICTURE'] = true;
47
48    $template->clear_assign(array(
49      'U_SET_AS_REPRESENTATIVE',
50      'U_PHOTO_ADMIN',
51      'U_CADDIE',
52      ));
53
54    $template->set_prefilter('picture', 'admintools_remove_privacy');
55
56    $query = 'SELECT element_id FROM ' . CADDIE_TABLE . '
57      WHERE element_id = ' . $page['image_id'] .';';
58    $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0;
59
60    if (isset($page['category']))
61    {
62      $tpl_vars['CATEGORY_ID'] = $page['category']['id'];
63
64      $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params(
65        $url_self,
66        array('action'=>'set_as_representative')
67        );
68
69      $query = 'SELECT id FROM ' . CATEGORIES_TABLE.'
70        WHERE id = ' . $page['category']['id'] .'
71        AND representative_picture_id = ' . $page['image_id'] .';';
72      $tpl_vars['IS_REPRESENTATIVE'] = pwg_db_num_rows(pwg_query($query)) > 0;
73    }
74
75    $tpl_vars['U_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id']
76      .(isset($page['category']) ? '&amp;cat_id=' . $page['category']['id'] : '');
77
78    $tpl_vars['U_CADDIE'] = add_url_params(
79      $url_self,
80      array('action'=>'add_to_caddie')
81      );
82
83    // gets tags
84    $query = '
85SELECT id, name
86  FROM '.IMAGE_TAG_TABLE.' AS it
87    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
88  WHERE image_id = '.$page['image_id'].'
89;';
90    $tag_selection = get_taglist($query);
91
92    $query = '
93SELECT id, name
94  FROM '.TAGS_TABLE.'
95;';
96    $tags = get_taglist($query, false);
97
98    $tpl_vars['QUICK_EDIT'] = array(
99      'img' => $picture['current']['derivatives']['square'],
100      'name' => $picture['current']['name'],
101      'comment' => $picture['current']['comment'],
102      'author' => $picture['current']['author'],
103      'level' => $picture['current']['level'],
104      'date_creation' => substr($picture['current']['date_creation'], 0, 10),
105      'date_creation_time' => substr($picture['current']['date_creation'], 11, 5),
106      'tag_selection' => $tag_selection,
107      'tags' => $tags,
108      );
109  }
110  else if (@$page['section'] = 'categories' and isset($page['category']))
111  {
112    $url_self = duplicate_index_url();
113
114    $tpl_vars['IS_CATEGORY'] = true;
115    $tpl_vars['CATEGORY_ID'] = $page['category']['id'];
116
117    $template->clear_assign(array(
118      'U_EDIT',
119      'U_CADDIE',
120      ));
121
122    $tpl_vars['U_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id'];
123
124    if (!empty($page['items']))
125    {
126      $tpl_vars['U_CADDIE'] = add_url_params(
127        $url_self,
128        array('caddie'=>1)
129        );
130    }
131
132    $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id = '. $page['category']['representative_picture_id'] .';';
133    $image_infos = pwg_db_fetch_assoc(pwg_query($query));
134
135    $tpl_vars['QUICK_EDIT'] = array(
136      'img' => DerivativeImage::get_one(IMG_SQUARE, $image_infos),
137      'name' => $page['category']['name'],
138      'comment' => $page['category']['comment'],
139      );
140  }
141
142
143  // get users
144  $query = '
145SELECT
146  '.$conf['user_fields']['id'].' AS id,
147  '.$conf['user_fields']['username'].' AS username
148FROM '.USERS_TABLE.'
149  ORDER BY CONVERT('.$conf['user_fields']['username'].', CHAR)
150;';
151  $tpl_vars['USERS'] = simple_hash_from_query($query, 'id', 'username');
152
153  // get themes
154  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
155  $themes = new themes();
156  foreach (array_keys($themes->db_themes_by_id) as $theme)
157  {
158    if (!empty($theme))
159    {
160      $tpl_vars['THEMES'][$theme] = $theme;
161    }
162  }
163
164  // get languages
165  foreach (get_languages() as $code => $name)
166  {
167    $tpl_vars['LANGS'][$code] = $name;
168  }
169
170
171  $template->assign(array(
172    'ADMINTOOLS_PATH' => ADMINTOOLS_PATH,
173    'ato' => $tpl_vars,
174  ));
175
176  $template->set_filename('ato', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl'));
177  $template->parse('ato');
178
179  switch_lang_back();
180}
181
182/**
183 * Disable privacy level switchbox
184 */
185function admintools_remove_privacy($content)
186{
187  $search = '{if $display_info.privacy_level and isset($available_permission_levels)}';
188  $replace = '{if false}';
189  return str_replace($search, $replace, $content);
190}
191
192/**
193 * Save picture form
194 * @trigger loc_begin_picture
195 */
196function admintools_save_picture()
197{
198  global $page, $conf;
199
200  if (isset($_GET['delete']) and get_pwg_token()==@$_GET['pwg_token'])
201  {
202    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
203
204    delete_elements(array($page['image_id']), true);
205    invalidate_user_cache();
206
207    if (isset($page['category']))
208    {
209      redirect(
210        make_index_url(
211          array(
212            'category' => $page['category']
213            )
214          )
215        );
216    }
217
218    redirect(make_index_url());
219  }
220
221  if (@$_POST['action'] == 'quick_edit')
222  {
223    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
224
225    $data = array(
226      'name' => $_POST['name'],
227      'author' => $_POST['author'],
228      'level' => $_POST['level'],
229      );
230
231    if ($conf['allow_html_descriptions'])
232    {
233      $data['comment'] = @$_POST['comment'];
234    }
235    else
236    {
237      $data['comment'] = strip_tags(@$_POST['comment']);
238    }
239
240    if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false)
241    {
242      $data['date_creation'] = $_POST['date_creation'] .' '. $_POST['date_creation_time'];
243    }
244
245    single_update(
246      IMAGES_TABLE,
247      $data,
248      array('id' => $page['image_id'])
249      );
250
251    $tag_ids = array();
252    if (!empty($_POST['tags']))
253    {
254      $tag_ids = get_tag_ids($_POST['tags']);
255    }
256    set_tags($tag_ids, $page['image_id']);
257  }
258}
259
260/**
261 * Save category form
262 * @trigger loc_begin_index
263 */
264function admintools_save_category()
265{
266  global $page, $conf;
267 
268  if (@$_POST['action'] == 'quick_edit')
269  {
270    $data = array(
271      'name' => $_POST['name'],
272      );
273
274    if ($conf['allow_html_descriptions'])
275    {
276      $data['comment'] = @$_POST['comment'];
277    }
278    else
279    {
280      $data['comment'] = strip_tags(@$_POST['comment']);
281    }
282
283    single_update(
284      CATEGORIES_TABLE,
285      $data,
286      array('id' => $page['category']['id'])
287      );
288     
289    redirect(duplicate_index_url());
290  }
291}
Note: See TracBrowser for help on using the repository browser.