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

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

load tags,themes,users,languages list in AJAX + move javascript code to external file

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