- function myplaylist_inner_sched_custom_box() {
- global $post;
- // Use nonce for verification
- wp_nonce_field( plugin_basename( __FILE__ ), 'dynamicMetaSched_noncename' );
- ?>
- <div id="meta_inner">
- <?php
- //get the saved meta as an array
- $shifts = get_post_meta($post->ID,'show_sched',false);
- //print_r($shifts);
- $c = 0;
- if (isset($shifts[0]) && is_array($shifts[0])){
- foreach($shifts[0] as $track ){
- if (isset($track['day']) || isset($track['time'])){
- ?>
- <p>
- <?php _e('Day', 'radio-station'); ?>:
- <select name="show_sched[<?php echo $c; ?>][day]">
- <option value=""></option>
- <option value="Monday"<?php if($track['day'] == "Monday") { echo ' selected="selected"'; } ?>><?php _e('Monday', 'radio-station'); ?></option>
- <option value="Tuesday"<?php if($track['day'] == "Tuesday") { echo ' selected="selected"'; } ?>><?php _e('Tuesday', 'radio-station'); ?></option>
- <option value="Wednesday"<?php if($track['day'] == "Wednesday") { echo ' selected="selected"'; } ?>><?php _e('Wednesday', 'radio-station'); ?></option>
- <option value="Thursday"<?php if($track['day'] == "Thursday") { echo ' selected="selected"'; } ?>><?php _e('Thursday', 'radio-station'); ?></option>
- <option value="Friday"<?php if($track['day'] == "Friday") { echo ' selected="selected"'; } ?>><?php _e('Friday', 'radio-station'); ?></option>
- <option value="Saturday"<?php if($track['day'] == "Saturday") { echo ' selected="selected"'; } ?>><?php _e('Saturday', 'radio-station'); ?></option>
- <option value="Sunday"<?php if($track['day'] == "Sunday") { echo ' selected="selected"'; } ?>><?php _e('Sunday', 'radio-station'); ?></option>
- </select>
- -
- <?php _e('Start Time', 'radio-station'); ?>:
- <select name="show_sched[<?php echo $c; ?>][start_hour]">
- <option value=""></option>
- <?php for($i=1; $i<=12; $i++): ?>
- <option value="<?php echo $i; ?>"<?php if($track['start_hour'] == $i) { echo ' selected="selected"'; } ?>><?php echo $i; ?></option>
- <?php endfor; ?>
- </select>
- <select name="show_sched[<?php echo $c; ?>][start_min]">
- <option value=""></option>
- <?php for($i=0; $i<60; $i++): ?>
- <?php
- $min = $i;
- if($i < 10) {
- $min = '0'.$i;
- }
- ?>
- <option value="<?php echo $min; ?>"<?php if($track['start_min'] == $min) { echo ' selected="selected"'; } ?>><?php echo $min; ?></option>
- <?php endfor; ?>
- </select>
- <select name="show_sched[<?php echo $c; ?>][start_meridian]">
- <option value=""></option>
- <option value="am"<?php if($track['start_meridian'] == "am") { echo ' selected="selected"'; } ?>>am</option>
- <option value="pm"<?php if($track['start_meridian'] == "pm") { echo ' selected="selected"'; } ?>>pm</option>
- </select>
- -
- <?php _e('End Time', 'radio-station'); ?>:
- <select name="show_sched[<?php echo $c; ?>][end_hour]">
- <option value=""></option>
- <?php for($i=1; $i<=12; $i++): ?>
- <option value="<?php echo $i; ?>"<?php if($track['end_hour'] == $i) { echo ' selected="selected"'; } ?>><?php echo $i; ?></option>
- <?php endfor; ?>
- </select>
- <select name="show_sched[<?php echo $c; ?>][end_min]">
- <option value=""></option>
- <?php for($i=0; $i<60; $i++): ?>
- <?php
- $min = $i;
- if($i < 10) {
- $min = '0'.$i;
- }
- ?>
- <option value="<?php echo $min; ?>"<?php if($track['end_min'] == $min) { echo ' selected="selected"'; } ?>><?php echo $min; ?></option>
- <?php endfor; ?>
- </select>
- <select name="show_sched[<?php echo $c; ?>][end_meridian]">
- <option value=""></option>
- <option value="am"<?php if($track['end_meridian'] == "am") { echo ' selected="selected"'; } ?>>am</option>
- <option value="pm"<?php if($track['end_meridian'] == "pm") { echo ' selected="selected"'; } ?>>pm</option>
- </select>
- <input type="checkbox" name="show_sched[<?php echo $c; ?>][encore]" <?php if(isset($track['encore']) && $track['encore'] == 'on') { echo 'checked="checked"'; } ?>/> <?php _e('Encore', 'radio-station'); ?>
- <span class="remove button-secondary" style="cursor: pointer;"><?php _e('Remove', 'radio-station'); ?></span>
- -
- <?php _e('Week', 'radio-station'); ?>:
- <select name="show_sched[<?php echo $c; ?>][frequency][]" multiple="multiple" size="4">
- <option value=""></option>
- <?php for($i=1; $i<=6; $i++): ?>
- <option value="<?php echo $i; ?>"<?php if($track['frequency'] == $i) { echo ' selected="selected"'; } ?>><?php echo $i; ?></option>
- <?php endfor; ?>
- </select>
- </p>
- <?php
- $c = $c +1;
- }
- }
- }
- ?>
- <span id="here"></span>
- <a class="add button-primary" style="cursor: pointer; display:block; width: 150px; padding: 8px; text-align: center; line-height: 1em;"><?php echo __('Add Shift', 'radio-station'); ?></a>
- <script>
- var shiftaddb =jQuery.noConflict();
- shiftaddb(document).ready(function() {
- var count = <?php echo $c; ?>;
- shiftaddb(".add").click(function() {
- count = count + 1;
- output = '<p><?php _e('Day', 'radio-station'); ?>: ';
- output += '<select name="show_sched[' + count + '][day]">';
- output += '<option value=""></option>';
- output += '<option value="Monday"><?php _e('Monday', 'radio-station'); ?></option>';
- output += '<option value="Tuesday"><?php _e('Tuesday', 'radio-station'); ?></option>';
- output += '<option value="Wednesday"><?php _e('Wednesday', 'radio-station'); ?></option>';
- output += '<option value="Thursday"><?php _e('Thursday', 'radio-station'); ?></option>';
- output += '<option value="Friday"><?php _e('Friday', 'radio-station'); ?></option>';
- output += '<option value="Saturday"><?php _e('Saturday', 'radio-station'); ?></option>';
- output += '<option value="Sunday"><?php _e('Sunday', 'radio-station'); ?></option>';
- output += '</select>';
- output += ' - <?php _e('Start Time', 'radio-station'); ?>: ';
- output += '<select name="show_sched[' + count + '][start_hour]">';
- output += '<option value=""></option>';
- <?php for($i=1; $i<=12; $i++): ?>
- output += '<option value="<?php echo $i; ?>"><?php echo $i; ?></option>';
- <?php endfor; ?>
- output += '</select> ';
- output += '<select name="show_sched[' + count + '][start_min]">';
- output += '<option value=""></option>';
- <?php for($i=0; $i<60; $i++): ?>
- <?php
- $min = $i;
- if($i < 10) {
- $min = '0'.$i;
- }
- ?>
- output += '<option value="<?php echo $min; ?>"><?php echo $min; ?></option>';
- <?php endfor; ?>
- output += '</select> ';
- output += '<select name="show_sched[' + count + '][start_meridian]">';
- output += '<option value=""></option>';
- output += '<option value="am">am</option>';
- output += '<option value="pm">pm</option>';
- output += '</select> ';
- output += ' - <?php _e('End Time', 'radio-station'); ?>: ';
- output += '<select name="show_sched[' + count + '][end_hour]">';
- output += '<option value=""></option>';
- <?php for($i=1; $i<=12; $i++): ?>
- output += '<option value="<?php echo $i; ?>"><?php echo $i; ?></option>';
- <?php endfor; ?>
- output += '</select> ';
- output += '<select name="show_sched[' + count + '][end_min]">';
- output += '<option value=""></option>';
- <?php for($i=0; $i<60; $i++): ?>
- <?php
- $min = $i;
- if($i < 10) {
- $min = '0'.$i;
- }
- ?>
- output += '<option value="<?php echo $min; ?>"><?php echo $min; ?></option>';
- <?php endfor; ?>
- output += '</select> ';
- output += '<select name="show_sched[' + count + '][end_meridian]">';
- output += '<option value=""></option>';
- output += '<option value="am">am</option>';
- output += '<option value="pm">pm</option>';
- output += '</select> ';
- output += '<input type="checkbox" name="show_sched[' + count + '][encore]" /> <?php _e('Encore', 'radio-station'); ?> ';
- output += '<span class="remove button-secondary" style="cursor: pointer;"><?php _e('Remove', 'radio-station'); ?></span>';
- output += ' - <?php _e('Week', 'radio-station'); ?>: ';
- output += '<select name="show_sched[' + count + '][show_frequency]" multiple="multiple" size="4">';
- output += '<option value=""></option>';
- <?php for($i=1; $i<=5; $i++): ?>
- output += '<option value="<?php echo $i; ?>"><?php echo $i; ?></option>';
- <?php endfor; ?>
- output += '</select></p> ';
- shiftaddb('#here').append( output );
- return false;
- });
- shiftaddb(".remove").live('click', function() {
- shiftaddb(this).parent().remove();
- });
- });
- </script>
- </div>
- <?php
- }
- //save the custom fields when a show is saved
- function myplaylist_save_showpostdata( $post_id ) {
- // verify if this is an auto save routine.
- // If it is our form has not been submitted, so we dont want to do anything
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if (isset($_POST['dynamicMetaUser_noncename'])){
- if ( !wp_verify_nonce( $_POST['dynamicMetaUser_noncename'], plugin_basename( __FILE__ ) ) )
- return;
- }else{return;
- }
- if (isset($_POST['dynamicMetaSched_noncename'])){
- if ( !wp_verify_nonce( $_POST['dynamicMetaSched_noncename'], plugin_basename( __FILE__ ) ) )
- return;
- }else{return;
- }
- // OK, we're authenticated: we need to find and save the data
- $djs = $_POST['show_user_list'];
- $sched = $_POST['show_sched'];
- $file = $_POST['show_file'];
- $email = $_POST['show_email'];
- $active = $_POST['show_active'];
- $link = $_POST['show_link'];
- update_post_meta($post_id,'show_user_list',$djs);
- update_post_meta($post_id,'show_sched',$sched);
- update_post_meta($post_id,'show_file',$file);
- update_post_meta($post_id,'show_email',$email);
- update_post_meta($post_id,'show_active',$active);
- update_post_meta($post_id,'show_link',$link);
- }
- add_action( 'save_post', 'myplaylist_save_showpostdata' );
Stikked
