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

Last change on this file since 25654 was 25654, checked in by mistic100, 10 years ago
  • add quick edit form for picture (todo: album)
  • add "Delete photo" button
File size: 5.7 KB
Line 
1<?php
2defined('ADMINTOOLS_PATH') or die('Hacking attempt!');
3
4function admintools_add_public_controller()
5{
6  global $MultiView, $conf;
7
8  if (!$MultiView->is_admin())
9  {
10    return;
11  }
12
13  global $template, $page, $user;
14
15  $url_root = get_root_url();
16
17  $tpl_vars = array(
18    'U_SITE_ADMIN' => $url_root . 'admin.php?page=',
19    'MULTIVIEW' => $MultiView->get_data(),
20    'U_SELF' => $MultiView->get_clean_url(true),
21    'USER' => $MultiView->get_user(),
22    'CURRENT_USERNAME' => $user['id']==$conf['guest_id'] ? l10n('guest') : $user['username'],
23    'PWG_TOKEN' => get_pwg_token(),
24    );
25
26  // TODO : param to allow owner modification
27  if (script_basename() == 'picture')
28  {
29    global $picture;
30
31    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
32
33    $url_self = duplicate_picture_url();
34
35    $tpl_vars['IS_PICTURE'] = true;
36
37    $template->clear_assign(array(
38      'U_SET_AS_REPRESENTATIVE',
39      'U_PHOTO_ADMIN',
40      'U_CADDIE',
41      ));
42
43    $template->set_prefilter('picture', 'admintools_remove_privacy');
44
45    $query = 'SELECT element_id FROM ' . CADDIE_TABLE . '
46      WHERE element_id = ' . $page['image_id'] .';';
47    $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0;
48
49    if (isset($page['category']))
50    {
51      $tpl_vars['CATEGORY_ID'] = $page['category']['id'];
52
53      $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params(
54        $url_self,
55        array('action'=>'set_as_representative')
56        );
57
58      $query = 'SELECT id FROM ' . CATEGORIES_TABLE.'
59        WHERE id = ' . $page['category']['id'] .'
60        AND representative_picture_id = ' . $page['image_id'] .';';
61      $tpl_vars['IS_REPRESENTATIVE'] = pwg_db_num_rows(pwg_query($query)) > 0;
62    }
63
64    $tpl_vars['U_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id']
65      .(isset($page['category']) ? '&amp;cat_id=' . $page['category']['id'] : '');
66
67    $tpl_vars['U_CADDIE'] = add_url_params(
68      $url_self,
69      array('action'=>'add_to_caddie')
70      );
71
72    // gets tags
73    $query = '
74SELECT id, name
75  FROM '.IMAGE_TAG_TABLE.' AS it
76    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
77  WHERE image_id = '.$page['image_id'].'
78;';
79    $tag_selection = get_taglist($query);
80
81    $query = '
82SELECT id, name
83  FROM '.TAGS_TABLE.'
84;';
85    $tags = get_taglist($query, false);
86
87    $tpl_vars['QUICK_EDIT'] = array(
88      'file' => $picture['current']['file'],
89      'name' => $picture['current']['name'],
90      'comment' => $picture['current']['comment'],
91      'author' => $picture['current']['author'],
92      'level' => $picture['current']['level'],
93      'date_creation' => substr($picture['current']['date_creation'], 0, 10),
94      'date_creation_time' => substr($picture['current']['date_creation'], 11, 5),
95      'tag_selection' => $tag_selection,
96      'tags' => $tags,
97      );
98  }
99  else if (@$page['section'] = 'categories' and isset($page['category']))
100  {
101    $url_self = duplicate_index_url();
102
103    $tpl_vars['IS_CATEGORY'] = true;
104    $tpl_vars['CATEGORY_ID'] = $page['category']['id'];
105
106    $template->clear_assign(array(
107      'U_EDIT',
108      'U_CADDIE',
109      ));
110
111    $tpl_vars['U_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id'];
112
113    if (!empty($page['items']))
114    {
115      $tpl_vars['U_CADDIE'] = add_url_params(
116        $url_self,
117        array('caddie'=>1)
118        );
119    }
120  }
121
122
123  // get users
124  $query = '
125SELECT
126  '.$conf['user_fields']['id'].' AS id,
127  '.$conf['user_fields']['username'].' AS username
128FROM '.USERS_TABLE.'
129  ORDER BY CONVERT('.$conf['user_fields']['username'].', CHAR)
130;';
131  $tpl_vars['USERS'] = simple_hash_from_query($query, 'id', 'username');
132
133  // get themes
134  include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
135  $themes = new themes();
136  foreach (array_keys($themes->fs_themes) as $theme)
137  {
138    $tpl_vars['THEMES'][$theme] = $theme;
139  }
140
141  // get languages
142  foreach (get_languages() as $code => $name)
143  {
144    $tpl_vars['LANGS'][$code] = $name;
145  }
146
147
148  $template->assign(array(
149    'ADMINTOOLS_PATH' => ADMINTOOLS_PATH,
150    'ato' => $tpl_vars,
151  ));
152
153  $template->set_filename('ato', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl'));
154  $template->parse('ato');
155}
156
157function admintools_remove_privacy($content)
158{
159  $search = '{if $display_info.privacy_level and isset($available_permission_levels)}';
160  $replace = '{if false}';
161  return str_replace($search, $replace, $content);
162}
163
164function admintools_save_picture()
165{
166  global $page, $conf;
167
168  if (isset($_GET['delete']) and get_pwg_token()==@$_GET['pwg_token'])
169  {
170    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
171
172    delete_elements(array($page['image_id']), true);
173    invalidate_user_cache();
174
175    if (isset($page['category']))
176    {
177      redirect(
178        make_index_url(
179          array(
180            'category' => $page['category']
181            )
182          )
183        );
184    }
185
186    redirect(make_index_url());
187  }
188
189  if (@$_POST['action'] == 'quick_edit')
190  {
191    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
192
193    $data = array(
194      'name' => $_POST['name'],
195      'author' => $_POST['author'],
196      'level' => $_POST['level'],
197      );
198
199    if ($conf['allow_html_descriptions'])
200    {
201      $data['comment'] = @$_POST['comment'];
202    }
203    else
204    {
205      $data['comment'] = strip_tags(@$_POST['comment']);
206    }
207
208    if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false)
209    {
210      $data['date_creation'] = $_POST['date_creation'] .' '. $_POST['date_creation_time'];
211    }
212
213    single_update(
214      IMAGES_TABLE,
215      $data,
216      array('id' => $page['image_id'])
217      );
218
219    $tag_ids = array();
220    if (!empty($_POST['tags']))
221    {
222      $tag_ids = get_tag_ids($_POST['tags']);
223    }
224    set_tags($tag_ids, $page['image_id']);
225  }
226}
Note: See TracBrowser for help on using the repository browser.