[11423] | 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 | { |
---|
[11439] | 10 | global $template; |
---|
[11423] | 11 | |
---|
[11439] | 12 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
[11423] | 13 | |
---|
[11439] | 14 | // Assign the template for batch management |
---|
[11678] | 15 | $template->set_filename('CR_batch_global', dirname(__FILE__).'/batch_global.tpl'); |
---|
[11423] | 16 | |
---|
[11439] | 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 |
---|
[11794] | 22 | ORDER BY cr_id ASC |
---|
[11439] | 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); |
---|
[11423] | 31 | |
---|
[11439] | 32 | |
---|
| 33 | // Add info on the "choose action" dropdown in the batch manager |
---|
[11794] | 34 | $template->append('element_set_global_plugins_actions', array( |
---|
| 35 | 'ID' => 'copyrights', // ID of the batch manager action |
---|
[11836] | 36 | 'NAME' => l10n('Set copyright'), // Description of the batch manager action |
---|
[11794] | 37 | 'CONTENT' => $template->parse('CR_batch_global', true) |
---|
| 38 | ) |
---|
[11439] | 39 | ); |
---|
[11423] | 40 | } |
---|
| 41 | |
---|
[11678] | 42 | // Process the submit action |
---|
[11423] | 43 | function copyrights_batch_global_submit($action, $collection) |
---|
| 44 | { |
---|
[11439] | 45 | // If its our plugin that is called |
---|
| 46 | if ($action == 'copyrights') |
---|
| 47 | { |
---|
| 48 | $crID = pwg_db_real_escape_string($_POST['copyrightID']); |
---|
[11423] | 49 | |
---|
[11794] | 50 | // Delete any previously assigned copyrights |
---|
| 51 | if (count($collection) > 0) { |
---|
| 52 | $query = sprintf( |
---|
[11439] | 53 | 'DELETE |
---|
| 54 | FROM %s |
---|
| 55 | WHERE media_id IN (%s) |
---|
| 56 | ;', |
---|
| 57 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
| 58 | pwg_query($query); |
---|
| 59 | } |
---|
[11423] | 60 | |
---|
[11794] | 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 |
---|
[11439] | 80 | ); |
---|
| 81 | } |
---|
| 82 | } |
---|
[11423] | 83 | } |
---|
| 84 | |
---|
[11794] | 85 | ?> |
---|