/** Bundle Content Editor */ function ym_bundle_edit_content($bundle) { if (isset($_POST['ym_remove_post_id']) && $_POST['ym_remove_post_id']) { ym_remove_post_from_bundle($_POST['ym_remove_post_id'], $bundle->id); echo '<div id="message" class="updated"><p>' . __('Removed Post from Bundle', 'ym') . '</p></div>'; ym_box_bottom(); ym_box_top(); } if (isset($_POST['add_posts']) && $_POST['add_posts']) { foreach ($_POST['post_ids'] as $id) { if (ym_add_post_to_bundle($id, $bundle->id)) { echo '<p>' . sprintf(__('Added post ID: %s to bundle ID: %s', 'ym'), $id, $bundle->id) . '</p>'; } } ym_box_bottom(); ym_box_top(); } $posts = ym_get_bundle_posts($bundle->id); echo '<table style="width: 100%;">'; $post_ids = array(); foreach ($posts as $post) { $post_ids[] = $post->post_id; echo '<tr>'; echo '<td>(' . $post->post_id . ') ' . get_the_title($post->post_id) . '</td>'; echo '<td> <form action="" method="post"> <input type="hidden" name="bundle_id" value="' . $bundle->id . '" /> <input type="hidden" name="posts" value="1" /> <input type="hidden" name="ym_remove_post_id" value="' . $post->post_id . '" /> <input type="submit" class="button-secondary deletelink" value="' . __('Remove Post from Bundle', 'ym') . '" /> </form> </td>'; echo '</tr>'; } echo '</table>'; ym_box_bottom(); ym_box_top(__('Add new Item(s) to bundle', 'ym')); echo '<form action="" method="post"> <input type="hidden" name="bundle_id" value="' . $bundle->id . '" /> <input type="hidden" name="posts" value="1" /> <input type="hidden" name="add_posts" value="1" /> <table id="ym_posts_space" style="width: 100%;"> '; $max = 15; $posts = ym_bundle_get_some_posts(0, $post_ids, $max); $total = count($posts); foreach ($posts as $post) { echo '<tr>'; echo '<td>(' . $post->ID . ' - ' . $post->post_type . ') ' . $post->post_title . '</td>'; echo '<td><input type="checkbox" name="post_ids[]" value="' . $post->ID . '" /></td>'; echo '</tr>'; } echo ' </table> '; if ($total == $max) { echo '<a href="#nowhere" id="ym_next_page" class="button-secondary" style="float: right;">' . __('Load More Posts', 'ym') . '</a>'; } echo ' <input type="hidden" name="offset" id="offset" value="5" /> <input type="hidden" name="current_post_ids" id="current_post_ids" value="' . implode(',', $post_ids) . '" /> <br /> <input type="submit" class="button-primary" value="' . __('Add Selected Item(s) to Bundle', 'ym') . '" /> </form> <script type="text/javascript">' . "\njQuery(document).ready(function() {\n\tjQuery('#ym_next_page').click(function() {\n\t\tvar count = 0;\n\t\tjQuery(this).html('" . __('Loading...', 'ym') . "');\n\t\tjQuery.getJSON('" . YM_ADMIN_URL . "&ym_page=ym-content-bundles&do_munch=1&offset=' + jQuery('#offset').val() + '&post_ids=' + jQuery('#current_post_ids').val() + '&max=" . $max . "', function(data) {\n\t\t\t\tjQuery('#ym_posts_space input').each(function() {\n\t\t\t\t\tif (!jQuery(this).is(':checked')) {\n\t\t\t\t\t\tjQuery(this).parents('tr').remove();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tjQuery.each(data, function(key, val) {\n\t\t\t\t\tcount++;\n\t\t\t\t\tjQuery(val).appendTo('#ym_posts_space');\n\t\t\t\t});\n\t\t\t\tif (count == " . $max . ") {\n\t\t\t\t\tjQuery('#ym_next_page').html('" . __('Load More Posts', 'ym') . "');\n\t\t\t\t} else {\n\t\t\t\t\tjQuery('#ym_next_page').remove();\n\t\t\t\t}\n\t\t\t\tjQuery('#offset').val(jQuery('#offset').val() + " . $max . ");\n\t\t});\n\t});\n});\n</script>\n"; }
<?php if (ym_request('do_munch') && ym_request('offset')) { $max = ym_request('max'); $offset = ym_request('offset'); $post_ids = explode(',', ym_request('post_ids')); $posts = ym_bundle_get_some_posts($offset, $post_ids, $max); $total = count($posts); if (!$total) { echo '<tr><td>' . __('No Posts', 'ym') . '</td></tr>'; } $more = array(); foreach ($posts as $post) { $line = '<tr>'; $line .= '<td>(' . $post->ID . ' - ' . $post->post_type . ') ' . addslashes($post->post_title) . '</td>'; $line .= '<td><input type="checkbox" name="post_ids[]" value="' . $post->ID . '" /></td>'; $line .= '</tr>'; $more[] = $line; } echo json_encode($more); exit; } echo '<div class="wrap" id="poststuff">'; ym_bundle_update(); echo __('<p>Bundles are groups of purchasable posts which can be sold as one item. Previously known as Pay Per Post Packs</p>', 'ym'); if ($bundle_id = ym_post('bundle_id')) { $bundle = ym_get_bundle($bundle_id); if (ym_post('edit')) { echo ym_start_box(__('Edit Bundle: "', 'ym') . $bundle->name . '"'); ym_bundle_form($bundle, __('Update Bundle', 'ym')); echo '<form action="" method="post"><input class="button-secondary" type="submit" name="submit" value="' . __('Cancel Edit Bundle', 'ym') . '" /></form>';