1 | <?php |
---|
2 | |
---|
3 | // @Johan: Misschien een goed idee om dit ook in een apart php scriptje te zetten, voor de overzichtelijkheid. |
---|
4 | // En om deze reden (Citaat uit de piwigo docs http://piwigo.org/doc/doku.php?id=en:plugins): |
---|
5 | // Code size |
---|
6 | // When PWG loads the plugins, it will include every main.inc.php. |
---|
7 | // Don't put in your main.inc.php 3000 lines of code just to add a page on the administration menu. |
---|
8 | // Split you main.inc.php in several files and feel free to add include_once inside functions defined in main.inc.php as much as you want. |
---|
9 | |
---|
10 | |
---|
11 | // Add copyrights drop down menu to the batch manager |
---|
12 | add_event_handler('loc_end_element_set_global', 'copyrights_batch_global'); |
---|
13 | // Add handler to the submit event of the batch manager |
---|
14 | add_event_handler('element_set_global_action', 'copyrights_batch_global_submit', 50, 2); |
---|
15 | |
---|
16 | function copyrights_batch_global() |
---|
17 | { |
---|
18 | global $template; |
---|
19 | |
---|
20 | load_language('plugin.lang', dirname(__FILE__).'/'); // Engels is voorlopig goed zat |
---|
21 | |
---|
22 | // Assign the template for batch management |
---|
23 | $template->set_filename('batch_global', dirname(__FILE__).'/batch_global.tpl'); |
---|
24 | |
---|
25 | // Fetch all the copyrights and assign them to the template |
---|
26 | $query = sprintf( |
---|
27 | 'SELECT `cr_id`,`name` |
---|
28 | FROM %s |
---|
29 | WHERE `visible`<>0 |
---|
30 | ;', |
---|
31 | COPYRIGHTS_ADMIN); |
---|
32 | $result = pwg_query($query); |
---|
33 | $CRoptions = array(); |
---|
34 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
35 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
36 | } |
---|
37 | $template->assign('CRoptions', $CRoptions); |
---|
38 | |
---|
39 | |
---|
40 | // Goed, ik weet dus echt niet waarom dit hieronder gedaan wordt... |
---|
41 | // AHA!!!! - dit is er zodat de "choose action" optie deze plugin gebruikt.... |
---|
42 | $template->append('element_set_global_plugins_actions', array( |
---|
43 | 'ID' => 'copyrights', // ID of the batch manager action |
---|
44 | 'NAME' => l10n('Edit copyright'), // Description of the batch manager action |
---|
45 | 'CONTENT' => $template->parse('batch_global', true) |
---|
46 | ) |
---|
47 | ); |
---|
48 | } |
---|
49 | |
---|
50 | // * Deze functie wordt een keer aangeroepen, nadat de gebruiker submit. |
---|
51 | // * Fietst met een foreach loop over de geselecteerde fotos |
---|
52 | // * Rammelt alle toevoegingen in 1x met mass_updates naar de db. |
---|
53 | function copyrights_batch_global_submit($action, $collection) |
---|
54 | { |
---|
55 | if ($action == 'copyrights') |
---|
56 | { |
---|
57 | $crID = pwg_db_real_escape_string($_POST['copyrightID']); |
---|
58 | |
---|
59 | if (count($collection) > 0) { |
---|
60 | $query = sprintf( |
---|
61 | 'DELETE |
---|
62 | FROM %s |
---|
63 | WHERE media_id IN (%s) |
---|
64 | ;', |
---|
65 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
66 | pwg_query($query); |
---|
67 | } |
---|
68 | |
---|
69 | $edits = array(); |
---|
70 | foreach ($collection as $image_id) |
---|
71 | { |
---|
72 | array_push( |
---|
73 | $edits, |
---|
74 | array( |
---|
75 | 'media_id' => $image_id, |
---|
76 | 'cr_id' => $crID, |
---|
77 | ) |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | mass_inserts( |
---|
82 | COPYRIGHTS_MEDIA, // Table name |
---|
83 | array_keys($edits[0]), //Columns |
---|
84 | $edits // Data |
---|
85 | ); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | ?> |
---|