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

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

fix typo + indent code

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