source: extensions/change_who_added_photo/initadmin.php @ 31815

Last change on this file since 31815 was 31443, checked in by ddtddt, 8 years ago

[extensions] - change_who_added_photo

File size: 3.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Change who added photo plugin for piwigo                              |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2013-2016 ddtddt               http://temmii.com/piwigo/ |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
23
24load_language('plugin.lang', CWAP_PATH);
25
26global $prefilter;
27
28
29  add_event_handler('loc_end_element_set_global', 'CWAP_loc_end_element_set_global');
30  add_event_handler('element_set_global_action', 'CWAP_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
31 
32function CWAP_loc_end_element_set_global()
33 {
34 load_language('plugin.lang', CWAP_PATH);
35        global $template;
36  $userslist = array(); 
37  $query = '
38SELECT id, username
39  FROM '.USERS_TABLE.'
40  ORDER BY username ASC
41;';
42  $result = pwg_query($query);
43  while ($row = pwg_db_fetch_assoc($result))
44  {
45    $userslist[$row['username']] = $row['username'];
46  }
47$template->set_filename('CWAPPP', realpath(CWAP_PATH.'cwap.tpl'));
48$template->assign('userslist', $userslist);
49$template->append('element_set_global_plugins_actions', array(
50    'ID' => 'CWAP', 
51    'NAME' => l10n('Change who added photo'), 
52    'CONTENT' => $template->parse('CWAPPP', true)
53        ));
54 }
55
56
57 
58function CWAP_element_set_global_action($action, $collection)
59 {
60  load_language('plugin.lang', CWAP_PATH);
61        if ($action == 'CWAP')
62  {
63    global $page;
64   
65    if (empty($_POST['check_CWAP']))
66    {
67      array_push($page['warnings'], l10n('You need to confirm'));
68    }
69    else
70    {
71       
72         $query = '
73select id
74  FROM ' . USERS_TABLE . '
75  WHERE username = \''.$_POST['CWAP'].'\'
76  ;';
77$result = pwg_query($query);
78$row = pwg_db_fetch_assoc($result);
79$CWAP=$row['id'];
80$datas = array();
81    foreach ($collection as $image_id)
82    {
83      array_push(
84        $datas,
85        array(
86          'id' => $image_id,
87          'added_by' => $CWAP
88          )
89        );
90    }
91
92    mass_updates(
93      IMAGES_TABLE,
94      array('primary' => array('id'), 'update' => array('added_by')),
95      $datas
96      );
97    }
98  }
99 }
100?>
Note: See TracBrowser for help on using the repository browser.