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

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

better control over session cache for multiview data

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