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