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

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

photo owner has access to quick edit and delete !

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