[11819] | 1 | <?php |
---|
| 2 | |
---|
| 3 | // Add event handlers for the prefilter |
---|
| 4 | add_event_handler('loc_end_element_set_unit', 'EA_set_prefilter_batch_single', 55 ); |
---|
| 5 | add_event_handler('loc_begin_element_set_unit', 'EA_batch_single_submit', 50 ); |
---|
| 6 | |
---|
| 7 | // Change the variables used by the function that changes the template |
---|
| 8 | add_event_handler('loc_end_element_set_unit', 'EA_add_batch_single_vars_to_template'); |
---|
| 9 | |
---|
| 10 | // Add a prefilter to the template |
---|
| 11 | function EA_set_prefilter_batch_single() |
---|
| 12 | { |
---|
| 13 | global $template; |
---|
| 14 | $template->set_prefilter('batch_manager_unit', 'EA_batch_single'); |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | // Insert the copyright selector to the template |
---|
| 18 | function EA_batch_single($content, &$smarty) |
---|
| 19 | { |
---|
| 20 | // Replace the piwigo author by our own author stuff |
---|
| 21 | $search = '/<td><input type="text" class="large" name="author-.*?<\/td>/is'; |
---|
| 22 | |
---|
| 23 | $replacement = '<td> |
---|
| 24 | <select id="author-{$element.ID}" name="author-{$element.ID}"> |
---|
| 25 | <option value="">--</option> |
---|
| 26 | {foreach from=$EAoptions item=option} |
---|
| 27 | <option value="{$option}"{if $EAauthors[$element.ID] == $option} selected="selected"{/if}> |
---|
| 28 | {$option} |
---|
| 29 | </option> |
---|
| 30 | {/foreach} |
---|
| 31 | </select> |
---|
| 32 | </td>'; |
---|
| 33 | |
---|
| 34 | return preg_replace($search, $replacement, $content); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | // Assign the variables to the Smarty template |
---|
| 38 | function EA_add_batch_single_vars_to_template() |
---|
| 39 | { |
---|
| 40 | global $template; |
---|
| 41 | |
---|
| 42 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 43 | |
---|
| 44 | // Fetch all the author names and assign them to the template |
---|
| 45 | $query = sprintf( |
---|
| 46 | 'SELECT `author_id`,`name` |
---|
| 47 | FROM %s |
---|
| 48 | ;', |
---|
| 49 | AUTHORS); |
---|
| 50 | $result = pwg_query($query); |
---|
| 51 | |
---|
| 52 | $EAoptions = array(); |
---|
| 53 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 54 | $EAoptions[$row['author_id']] = $row['name']; |
---|
| 55 | } |
---|
| 56 | $template->assign('EAoptions', $EAoptions); |
---|
| 57 | |
---|
| 58 | // Get the author name for every image id |
---|
| 59 | $query = sprintf( |
---|
| 60 | 'SELECT `id`, `author` |
---|
| 61 | FROM %s |
---|
| 62 | ;', |
---|
| 63 | IMAGES); |
---|
| 64 | $result = pwg_query($query); |
---|
| 65 | |
---|
| 66 | // Get the author id for each element |
---|
| 67 | $EAauthors = array(); |
---|
| 68 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 69 | $EAauthors[$row['id']] = $row['author']; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | // Assign the copyrights to the template |
---|
| 73 | $template->assign('EAauthors', $EAauthors); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Catch the submit and update the copyrights tables |
---|
| 77 | function EA_batch_single_submit() |
---|
| 78 | { |
---|
| 79 | if (isset($_POST['submit'])) |
---|
| 80 | { |
---|
| 81 | // The image id's: |
---|
| 82 | $collection = explode(',', $_POST['element_ids']); |
---|
| 83 | |
---|
| 84 | // Check all authors, and give them defaults |
---|
| 85 | $edits = array(); |
---|
| 86 | foreach ($collection as $image_id) { |
---|
| 87 | // The copyright name's |
---|
| 88 | $name = pwg_db_real_escape_string($_POST['author-'.$image_id]); |
---|
| 89 | |
---|
| 90 | // Create the array to be updated |
---|
| 91 | array_push( |
---|
| 92 | $edits, |
---|
| 93 | array( |
---|
| 94 | 'id' => $image_id, |
---|
| 95 | 'author' => $name, |
---|
| 96 | ) |
---|
| 97 | ); |
---|
| 98 | |
---|
| 99 | // Add them to the images table |
---|
| 100 | // (yes, this is double work, since the author will be set by the piwigo core. But its not set right now, and insert_default_CR needs it...) |
---|
| 101 | mass_updates( |
---|
| 102 | IMAGES, |
---|
| 103 | array('primary' => array('id'), 'update' => array('author')), |
---|
| 104 | $edits |
---|
| 105 | ); |
---|
| 106 | |
---|
| 107 | // Insert the default copyrights |
---|
| 108 | insert_default_CR($name); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | ?> |
---|