source: extensions/user_delete_photo/initpicture.php @ 26879

Last change on this file since 26879 was 26879, checked in by ddtddt, 10 years ago

[extensions] - user_delete_photo - redirection in the right section if the user isn't in album

File size: 2.2 KB
RevLine 
[21964]1<?php
[26879]2//Add prefilter
[21964]3add_event_handler('loc_begin_picture', 'udp', 55 );
[26879]4 function udp()
5  {
6  global $template;
7  $template->set_prefilter('picture', 'udpT');
8  }
[21964]9
[26879]10 function udpT($content, &$smarty)
11  {
12  global $conf;
[21964]13  $search = '#<div id="'.$conf['udp'].'" class="imageInfo">#';
14  $replacement = '
15{if $UDFA}
[26879]16 <div id="udp" class="imageInfo">
17  <form method="post">
18   <input class="submit" name="submitudpA" type="submit" value="{\'delete photo\'|@translate}">
19   <label><input type="checkbox" name="confirm_deletionudp" value="1"> {\'Are you sure?\'|@translate}</label>
20  </form>
21 </div>
[21964]22{/if}
[26879]23 <div id="'.$conf['udp'].'" class="imageInfo">';
[21964]24  return preg_replace($search, $replacement, $content);
[26879]25  }
[21964]26
27add_event_handler('loc_begin_picture', 'udpA');
28
[26879]29 function udpA()
[21964]30{
[26879]31  global $conf, $page, $template  ;
32  load_language('plugin.lang', UDP_PATH);
33  load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
34  global $conf, $user, $page;
[21964]35
36  $query = '
37select added_by
38  FROM ' . IMAGES_TABLE . '
39  WHERE id = \''.$page['image_id'].'\'
40  ;';
41$result = pwg_query($query);
42$row = pwg_db_fetch_assoc($result);
43$userudp=$row['added_by'];
[26879]44 
[21964]45  $query = '
[26561]46select '.$conf['user_fields']['username'].' AS username
[21964]47  FROM ' . USERS_TABLE . '
[26561]48  WHERE '.$conf['user_fields']['id'].' = \''.$userudp.'\'
[21964]49  ;';
50$result = pwg_query($query);
51$row = pwg_db_fetch_assoc($result);
52$udp=$row['username'];
53
54if (($udp == $user['username']))
55 {
[26879]56 $template->assign(
57 array  (
58 'UDFA' => 'udp',
59 ));
[21964]60 }
61
62if ((isset($_POST['submitudpA']) and ($udp == $user['username'])))
[26879]63 {
64  if (!(isset($_POST['confirm_deletionudp']) and 1 == $_POST['confirm_deletionudp']))
[21964]65  {
[26879]66  array_push($page['errors'], l10n('You need to confirm deletion'));
[21964]67  }
[26879]68  else
69  {
70  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
71  global $page;
72  $deletephotoudp =array($page['image_id']);
73  delete_elements($deletephotoudp, true);
74  invalidate_user_cache();
75   if (isset($page['category']['id']))
76   {
77   $redirect_url = get_root_url().'index.php?/category/'.($page['category']['id']);
78   }
79   else
80   {
81   $redirect_url = get_root_url().'index.php?/'.($page['section']);
82   }
83   $_SESSION['page_infos'] = array(l10n('Photo deleted'));
84   redirect($redirect_url);
85  }
86 }
[21964]87}
88?>
Note: See TracBrowser for help on using the repository browser.