[11423] | 1 | <?php |
---|
| 2 | |
---|
[11678] | 3 | // Add event handlers for the prefilter |
---|
[11621] | 4 | add_event_handler('loc_end_element_set_unit', 'CR_set_prefilter_batch_single', 55 ); |
---|
[11635] | 5 | add_event_handler('loc_begin_element_set_unit', 'CR_batch_single_submit', 50 ); |
---|
[11423] | 6 | |
---|
[11439] | 7 | // Change the variables used by the function that changes the template |
---|
[11623] | 8 | add_event_handler('loc_end_element_set_unit', 'CR_add_batch_single_vars_to_template'); |
---|
[11439] | 9 | |
---|
[11678] | 10 | // Add a prefilter to the template |
---|
[11621] | 11 | function CR_set_prefilter_batch_single() |
---|
[11423] | 12 | { |
---|
| 13 | global $template; |
---|
[11615] | 14 | $template->set_prefilter('batch_manager_unit', 'CR_batch_single'); |
---|
[11423] | 15 | } |
---|
| 16 | |
---|
[11678] | 17 | // Insert the copyright selector to the template |
---|
[11615] | 18 | function CR_batch_single($content, &$smarty) |
---|
[11439] | 19 | { |
---|
[11678] | 20 | $search = "#<td><strong>{'Creation date'#"; |
---|
[11488] | 21 | |
---|
[11621] | 22 | // We use the <tr> from the Creation date, and give them a new <tr> |
---|
| 23 | $replacement = '<td><strong>{\'Copyright\'|@translate}</strong></td> |
---|
[11505] | 24 | <td> |
---|
[11623] | 25 | <select id="copyright-{$element.ID}" name="copyright-{$element.ID}"> |
---|
[11794] | 26 | <option value="">--</option> |
---|
[11623] | 27 | {html_options options=$CRoptions selected=$CRcopyrights[$element.ID]} |
---|
| 28 | </select> |
---|
[11505] | 29 | </td> |
---|
| 30 | </tr> |
---|
| 31 | |
---|
| 32 | <tr> |
---|
| 33 | <td><strong>{\'Creation date\''; |
---|
[11488] | 34 | |
---|
[11678] | 35 | return preg_replace($search, $replacement, $content); |
---|
[11439] | 36 | } |
---|
| 37 | |
---|
[11678] | 38 | // Assign the variables to the Smarty template |
---|
[11621] | 39 | function CR_add_batch_single_vars_to_template() |
---|
[11439] | 40 | { |
---|
[11621] | 41 | global $template; |
---|
| 42 | |
---|
| 43 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
| 44 | |
---|
| 45 | // Fetch all the copyrights and assign them to the template |
---|
| 46 | $query = sprintf( |
---|
| 47 | 'SELECT `cr_id`,`name` |
---|
| 48 | FROM %s |
---|
| 49 | WHERE `visible`<>0 |
---|
[11794] | 50 | ORDER BY cr_id ASC |
---|
[11621] | 51 | ;', |
---|
| 52 | COPYRIGHTS_ADMIN); |
---|
| 53 | $result = pwg_query($query); |
---|
| 54 | |
---|
| 55 | $CRoptions = array(); |
---|
| 56 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 57 | $CRoptions[$row['cr_id']] = $row['name']; |
---|
| 58 | } |
---|
| 59 | $template->assign('CRoptions', $CRoptions); |
---|
[11623] | 60 | |
---|
| 61 | // Get the copyright for each element |
---|
| 62 | $query = sprintf( |
---|
| 63 | 'SELECT `media_id`, `cr_id` |
---|
| 64 | FROM %s |
---|
| 65 | ;', |
---|
| 66 | COPYRIGHTS_MEDIA); |
---|
| 67 | $result = pwg_query($query); |
---|
| 68 | |
---|
| 69 | $CRcopyrights = array(); |
---|
| 70 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 71 | $CRcopyrights[$row['media_id']] = $row['cr_id']; |
---|
[11678] | 72 | } |
---|
| 73 | |
---|
| 74 | // Assign the copyrights to the template |
---|
[11623] | 75 | $template->assign('CRcopyrights', $CRcopyrights); |
---|
[11439] | 76 | } |
---|
| 77 | |
---|
[11678] | 78 | // Catch the submit and update the copyrights tables |
---|
[11615] | 79 | function CR_batch_single_submit() |
---|
| 80 | { |
---|
[11623] | 81 | if (isset($_POST['submit'])) |
---|
| 82 | { |
---|
| 83 | // The image id's: |
---|
| 84 | $collection = explode(',', $_POST['element_ids']); |
---|
[11621] | 85 | |
---|
[11678] | 86 | // Delete all existing id's of which the copyright is going to be set |
---|
[11623] | 87 | if (count($collection) > 0) { |
---|
| 88 | $query = sprintf( |
---|
| 89 | 'DELETE |
---|
| 90 | FROM %s |
---|
| 91 | WHERE media_id IN (%s) |
---|
| 92 | ;', |
---|
| 93 | COPYRIGHTS_MEDIA, implode(',', $collection)); |
---|
| 94 | pwg_query($query); |
---|
[11794] | 95 | } |
---|
[11678] | 96 | |
---|
| 97 | // Add all copyrights to an array |
---|
[11623] | 98 | $edits = array(); |
---|
| 99 | foreach ($collection as $image_id) { |
---|
| 100 | // The copyright id's |
---|
| 101 | $crID = pwg_db_real_escape_string($_POST['copyright-'.$image_id]); |
---|
[11621] | 102 | |
---|
[11794] | 103 | // If you assign no copyright, dont put them in the table |
---|
| 104 | if ($crID != '') { |
---|
| 105 | array_push( |
---|
| 106 | $edits, |
---|
| 107 | array( |
---|
| 108 | 'media_id' => $image_id, |
---|
| 109 | 'cr_id' => $crID, |
---|
| 110 | ) |
---|
| 111 | ); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | if (count($edits) > 0) { |
---|
| 116 | // Insert the array to the database |
---|
| 117 | mass_inserts( |
---|
| 118 | COPYRIGHTS_MEDIA, // Table name |
---|
| 119 | array_keys($edits[0]), // Columns |
---|
| 120 | $edits // Data |
---|
[11623] | 121 | ); |
---|
[11794] | 122 | } |
---|
[11621] | 123 | } |
---|
[11615] | 124 | } |
---|
| 125 | |
---|
[11622] | 126 | ?> |
---|