[11423] | 1 | <?php |
---|
| 2 | |
---|
[11488] | 3 | // Add a prefilter |
---|
[11621] | 4 | add_event_handler('loc_end_element_set_unit', 'CR_set_prefilter_batch_single', 55 ); |
---|
[11615] | 5 | add_event_handler('loc_end_element_set_unit', 'CR_batch_single_submit', 55 ); |
---|
[11423] | 6 | |
---|
[11439] | 7 | // Change the variables used by the function that changes the template |
---|
[11621] | 8 | add_event_handler('loc_begin_admin', 'CR_add_batch_single_vars_to_template'); |
---|
[11439] | 9 | |
---|
[11621] | 10 | function CR_set_prefilter_batch_single() |
---|
[11423] | 11 | { |
---|
| 12 | global $template; |
---|
[11615] | 13 | $template->set_prefilter('batch_manager_unit', 'CR_batch_single'); |
---|
[11423] | 14 | } |
---|
| 15 | |
---|
[11615] | 16 | function CR_batch_single($content, &$smarty) |
---|
[11439] | 17 | { |
---|
[11621] | 18 | $search = "#<td><strong>{'Creation date'#"; // Not ideal, but ok for now :) |
---|
[11488] | 19 | |
---|
[11621] | 20 | // We use the <tr> from the Creation date, and give them a new <tr> |
---|
| 21 | $replacement = '<td><strong>{\'Copyright\'|@translate}</strong></td> |
---|
[11505] | 22 | <td> |
---|
[11621] | 23 | {html_options name=copyright-{$element.ID} options=$CRoptions} |
---|
[11505] | 24 | </td> |
---|
| 25 | </tr> |
---|
| 26 | |
---|
| 27 | <tr> |
---|
| 28 | <td><strong>{\'Creation date\''; |
---|
[11488] | 29 | |
---|
| 30 | return preg_replace($search, $replacement, $content); |
---|
[11505] | 31 | |
---|
| 32 | // Dit is een interresant testje - deze functie word dus een aantal keren (3) aangeroepen, |
---|
| 33 | // en pas de laatste keer is bevat $content meer dan een aantal enters... |
---|
[11621] | 34 | // return $content.'<div id="dwo_test" style="display: none;">'.$content.'</div>'; |
---|
[11439] | 35 | } |
---|
| 36 | |
---|
[11621] | 37 | function CR_add_batch_single_vars_to_template() |
---|
[11439] | 38 | { |
---|
[11621] | 39 | global $template; |
---|
| 40 | |
---|
| 41 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 42 | |
---|
| 43 | // Fetch all the copyrights and assign them to the template |
---|
| 44 | $query = sprintf( |
---|
| 45 | 'SELECT `cr_id`,`name` |
---|
| 46 | FROM %s |
---|
| 47 | WHERE `visible`<>0 |
---|
| 48 | ;', |
---|
| 49 | COPYRIGHTS_ADMIN); |
---|
| 50 | $result = pwg_query($query); |
---|
| 51 | |
---|
| 52 | $CRoptions = array(); |
---|
| 53 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 54 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
| 55 | } |
---|
| 56 | $template->assign('CRoptions', $CRoptions); |
---|
[11439] | 57 | } |
---|
| 58 | |
---|
[11615] | 59 | function CR_batch_single_submit() |
---|
| 60 | { |
---|
[11621] | 61 | // The image id's: |
---|
| 62 | $collection = explode(',', $_POST['element_ids']); |
---|
| 63 | |
---|
| 64 | // Delete all existing id's of which the Copyright is going to be set |
---|
| 65 | if (count($collection) > 0) { |
---|
| 66 | $query = sprintf( |
---|
| 67 | 'DELETE |
---|
| 68 | FROM %s |
---|
| 69 | WHERE media_id IN (%s) |
---|
| 70 | ;', |
---|
| 71 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
| 72 | pwg_query($query); |
---|
| 73 | } |
---|
| 74 | // Add all Copyrights to an array |
---|
| 75 | $edits = array(); |
---|
| 76 | foreach ($collection as $image_id) { |
---|
| 77 | // The copyright id's |
---|
| 78 | $crID = pwg_db_real_escape_string($_POST['copyrightID-'.$image_id]); |
---|
| 79 | |
---|
| 80 | array_push( |
---|
| 81 | $edits, |
---|
| 82 | array( |
---|
| 83 | 'media_id' => $image_id, |
---|
| 84 | 'cr_id' => $crID, |
---|
| 85 | ) |
---|
| 86 | ); |
---|
| 87 | } |
---|
| 88 | // Add the array to the database |
---|
| 89 | mass_inserts( |
---|
| 90 | COPYRIGHTS_MEDIA, // Table name |
---|
| 91 | array_keys($edits[0]), // Columns |
---|
| 92 | $edits // Data |
---|
| 93 | ); |
---|
[11615] | 94 | } |
---|
| 95 | |
---|
[11622] | 96 | ?> |
---|