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

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

include functions_mail.inc.php for switch_lang_to and switch_lang_back

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