source: extensions/Copyrights/batch_global.php @ 11664

Last change on this file since 11664 was 11439, checked in by Mattias, 13 years ago

Small changes in comment's, removed unnescessary code

File size: 2.5 KB
Line 
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
12add_event_handler('loc_end_element_set_global', 'copyrights_batch_global');
13// Add handler to the submit event of the batch manager
14add_event_handler('element_set_global_action', 'copyrights_batch_global_submit', 50, 2);
15
16function copyrights_batch_global()
17{
18        global $template;
19
20        load_language('plugin.lang', dirname(__FILE__).'/');
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        // Add info on the "choose action" dropdown in the batch manager
41        $template->append('element_set_global_plugins_actions', array(
42                'ID' => 'copyrights',   // ID of the batch manager action
43                'NAME' => l10n('Edit copyright'), // Description of the batch manager action
44                'CONTENT' => $template->parse('batch_global', true)
45        )
46        );
47}
48
49// * Deze functie wordt een keer aangeroepen, nadat de gebruiker submit.
50// * Fietst met een foreach loop over de geselecteerde fotos
51// * Rammelt alle toevoegingen in 1x met mass_updates naar de db.
52function copyrights_batch_global_submit($action, $collection)
53{
54        // If its our plugin that is called
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?>
Note: See TracBrowser for help on using the repository browser.