1 | <?php |
---|
2 | |
---|
3 | // Add copyrights drop down menu to the batch manager |
---|
4 | add_event_handler('loc_end_element_set_global', 'copyrights_batch_global'); |
---|
5 | // Add handler to the submit event of the batch manager |
---|
6 | add_event_handler('element_set_global_action', 'copyrights_batch_global_submit', 50, 2); |
---|
7 | |
---|
8 | function copyrights_batch_global() |
---|
9 | { |
---|
10 | global $template; |
---|
11 | |
---|
12 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
13 | |
---|
14 | // Assign the template for batch management |
---|
15 | $template->set_filename('CR_batch_global', dirname(__FILE__).'/batch_global.tpl'); |
---|
16 | |
---|
17 | // Fetch all the copyrights and assign them to the template |
---|
18 | $query = sprintf( |
---|
19 | 'SELECT `cr_id`,`name` |
---|
20 | FROM %s |
---|
21 | WHERE `visible`<>0 |
---|
22 | ORDER BY cr_id ASC |
---|
23 | ;', |
---|
24 | COPYRIGHTS_ADMIN); |
---|
25 | $result = pwg_query($query); |
---|
26 | $CRoptions = array(); |
---|
27 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
28 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
29 | } |
---|
30 | $template->assign('CRoptions', $CRoptions); |
---|
31 | |
---|
32 | |
---|
33 | // Add info on the "choose action" dropdown in the batch manager |
---|
34 | $template->append('element_set_global_plugins_actions', array( |
---|
35 | 'ID' => 'copyrights', // ID of the batch manager action |
---|
36 | 'NAME' => l10n('Set copyright'), // Description of the batch manager action |
---|
37 | 'CONTENT' => $template->parse('CR_batch_global', true) |
---|
38 | ) |
---|
39 | ); |
---|
40 | } |
---|
41 | |
---|
42 | // Process the submit action |
---|
43 | function copyrights_batch_global_submit($action, $collection) |
---|
44 | { |
---|
45 | // If its our plugin that is called |
---|
46 | if ($action == 'copyrights') |
---|
47 | { |
---|
48 | $crID = pwg_db_real_escape_string($_POST['copyrightID']); |
---|
49 | |
---|
50 | // Delete any previously assigned copyrights |
---|
51 | if (count($collection) > 0) { |
---|
52 | $query = sprintf( |
---|
53 | 'DELETE |
---|
54 | FROM %s |
---|
55 | WHERE media_id IN (%s) |
---|
56 | ;', |
---|
57 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
58 | pwg_query($query); |
---|
59 | } |
---|
60 | |
---|
61 | // If you assign no copyright, dont put them in the table |
---|
62 | if ($crID != '') { |
---|
63 | // Add the copyrights from the submit form to an array |
---|
64 | $edits = array(); |
---|
65 | foreach ($collection as $image_id) { |
---|
66 | array_push( |
---|
67 | $edits, |
---|
68 | array( |
---|
69 | 'media_id' => $image_id, |
---|
70 | 'cr_id' => $crID, |
---|
71 | ) |
---|
72 | ); |
---|
73 | } |
---|
74 | |
---|
75 | // Insert the array into the database |
---|
76 | mass_inserts( |
---|
77 | COPYRIGHTS_MEDIA, // Table name |
---|
78 | array_keys($edits[0]), // Columns |
---|
79 | $edits // Data |
---|
80 | ); |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | ?> |
---|