source: extensions/Copyrights/batch_global.php @ 11735

Last change on this file since 11735 was 11678, checked in by J.Commelin, 13 years ago

Finished adding comments to the code

File size: 2.6 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('CR_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('CR_batch_global', true)
45  )
46        );
47}
48
49// Process the submit action
50function copyrights_batch_global_submit($action, $collection)
51{
52        // If its our plugin that is called
53        if ($action == 'copyrights')
54        {
55                $crID = pwg_db_real_escape_string($_POST['copyrightID']);
56
57    // Delete any previously assigned copyrights
58    if (count($collection) > 0) {
59        $query = sprintf(
60                                'DELETE
61                                FROM %s
62                                WHERE media_id IN (%s)
63                                ;',
64                        COPYRIGHTS_MEDIA, implode(',', $collection));
65                        pwg_query($query);
66                }
67
68    // Add the copyrights from the submit form to an array
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    // Insert the array into the database
82                mass_inserts(
83                        COPYRIGHTS_MEDIA,                   // Table name
84                        array_keys($edits[0]),  // Columns
85                        $edits                                          // Data
86                );
87        }
88}
89
90?>
Note: See TracBrowser for help on using the repository browser.