<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

?>
<div id="ld_cms_wrapper" class="ARwebcrafts_addon">
<h1 class="ARwebcrafts_addon_main_heading"><?php echo __('LearnDash Course Planner Pro', 'wn-learndash-course-planner-pro'); ?></h1>
<div class="ARwebcrafts_addon_plnr-crse ARwebcrafts_addon_grid_two_str"> 
<div id="ld_cms_events"><!--SIDEBAR-->
        <div >
            <h2><?php echo \LearnDash_Custom_Label::get_label( 'courses' ); ?></h2>

            <div class="ld_cms_event_search" style="margin-bottom: 10px;">
                <input type="text" id="ld_cms_search_courses" name="ld_cms_search_courses" value="" placeholder="<?php echo __( 'Search Courses', 'cs_ld_addon' )?>" style="width: 100%;" />
            </div>

            <div id="ld_cms_course_list" style="display: none;"><?php echo __( 'Loading...', 'cs_ld_addon' )?></div>
            <div id="ld_cms_course_list_loader" class="spinner is-active" style="float: none; text-indent: -9999px;"><?php echo __( 'Loading...', 'cs_ld_addon' )?></div>

            <p><a href="#loadMore" id="ld_cms_load_more"><?php _e('Load more courses', 'cs_ld_addon'); ?></a></p>
            <div data-url="<?php echo admin_url( 'admin-ajax.php' ).'?action=cs_ld_load_courses';?>"></div>
            <?php if(current_user_can('manage_options')) :?>
                <div id="ld_cms_schedule_links"><!--SCHEDULE LINK-->
                    <ul>
                        <li><a href="#" data-object_type="schedule_courses" class="ld_cms_add_event_by_category_tag_link ld_cms_event_schedule_courses ARwebcrafts_crse-plnr_button "><?php echo __( 'Schedule ', 'cs_ld_addon' ) . \LearnDash_Custom_Label::get_label( 'course' ) . __( ' by Category/Tag', 'cs_ld_addon' ) ?></a></li>
                        <li><a href="#" data-object_type="schedule_lessons" class="ld_cms_add_event_by_category_tag_link ld_cms_event_schedule_lessons ARwebcrafts_crse-plnr_button "><?php echo __( 'Schedule ', 'cs_ld_addon' ) . \LearnDash_Custom_Label::get_label( 'lesson' ) . __( ' by Category/Tag', 'cs_ld_addon' ) ?></a></li>
                        <li><a href="#" data-object_type="schedule_topics" class="ld_cms_add_event_by_category_tag_link ld_cms_event_schedule_topics ARwebcrafts_crse-plnr_button "><?php echo __( 'Schedule ', 'cs_ld_addon' ) . \LearnDash_Custom_Label::get_label( 'topic' ) . __( ' by Category/Tag', 'cs_ld_addon' ) ?></a></li>
                    </ul>
                </div><!--SCHEDULE LINK-->
            <?php endif; ?>
        </div>
    </div><!--SIDEBAR-->
    <div id="ld_cms_calendar"><!--MAIN CALENDAR-->
        <div class="ld-cms-preloader-div ld-cms-preloader-div-admin"></div>
        <div id="ld_cms_calendar_wrap" data-caltype="default" data-type="admin" data-user-id="<?php echo $user_id; ?>"></div>
    </div><!--MAIN CALENDAR-->
    <div style="clear: both;"></div><!--FOOTER LEGENDS-->
</div>
    <div class="calendar-color-codes"><!--FOOTER LEGENDS-->
        <!-- <div> <span style="background:#808080"></span><?php _e( 'Group', 'cs_ld_addon' ) ?></div> -->
        <div > <span style="background:#FF0000"></span><?php _e( 'Hide', 'cs_ld_addon' ) ?></div>
        <div> <span  style="background:#00A300"></span><?php _e( 'Show', 'cs_ld_addon' ) ?></div>
    </div>
<div id="ld_cms_tooltip_template" style="display: none;"><!--TIPPY TOOLTIP TEMPLATE-->
    <strong><?php _e('Title', 'cs_ld_addon'); ?>:</strong> <span id="ld_cms_tt_title"></span><br>
    <strong><?php _e('Start', 'cs_ld_addon'); ?>:</strong> <span id="ld_cms_tt_start"></span><br>
    <strong><?php _e('End', 'cs_ld_addon'); ?>:</strong> <span id="ld_cms_tt_end"></span><br>

</div><!--TIPPY TOOLTIP TEMPLATE-->

<div id="ld_cms_event_edit_thickbox" style="display: none;"><!--EVENT THICKBOX FORM TEMPLATE-->

    <div class="ld-cms-thickbox">
        <div id="ld-cms-thickbox-message"></div>
        <form id="ld-cms-event-form" method="post">
            <div style="display: none;"><!--HIDDEN FIELDS-->
                <input type="text" id="ld-cms-event-action" name="action" value="ld_cms_update_event" />
                <input type="number" id="ld-cms-event-object-id" name="ld_cms_event[object_id]" value="0" />
                <input type="text" id="ld-cms-event-object-type" name="ld_cms_event[object_type]" value="" />
                <input type="number" id="ld-cms-event-rec-id" name="ld_cms_event[rec_id]" value="0" />
                <input type="number" id="ld-cms-event-course-id" name="ld_cms_event[course_id]" value="0" />
                <input type="number" id="ld-cms-event-lesson-id" name="ld_cms_event[lesson_id]" value="0" />
            </div>
            <table width="100%" cellpadding="5" cellspacing="5">
                <tr id="ld-cms-event-group-fields">
                    <td colspan="2">
                        <label><?php 
                         $groups = get_posts( array(
                            'post_type'      => 'groups',
                            'posts_per_page' => -1,
                        ) );
                        $options = '';
                        foreach ( $groups as $group ) {
                            $user_ids = learndash_get_groups_user_ids( $group->ID );
                            $user_string = implode(',', $user_ids);
                            if( !empty( $user_string ) ) {
                                $user_string = ",".$user_string.",";
                            }
                            $options .= '<option data-id="'.$user_string.'" value="'.$group->ID.'">'.$group->post_title.'</option>';
                        }
                        ?>
                        <span><?php _e( 'Course Group', 'cs_ld_addon' ) ?></span> 
                        <select id="ld-cms-event-groups" name="ld_cms_event[group]">
                            <option data-id="" value=""><?php echo __( 'Select', 'cs_ld_addon' ); ?></option>
                            <?php
                               echo $options;
                            ?>
                        </select>
                            
                        </label></td>
                </tr>
                <tr class="crse-enrlmnt-dte">
                    <td colspan="2" style="padding-bottom: 0px;">
                        <label><span><?php _e( 'Course enrollment date as start date?', 'cs_ld_addon' ) ?></span><input id="ld-cms-event-is-enrollment-start" name="ld_cms_event[is_subsdate_as_startdate]" value="Yes" type="checkbox">  </label>
                        <div id="ld-cms-event-duration-fields" style="display: none;">
                            <table width="100%" cellpadding="5" cellspacing="5">
                                <tr>
                                    <td width="50%"><label><span><?php _e( 'Interval', 'cs_ld_addon' ) ?></span> <input id="ld-cms-event-duration" class="input-field" name="ld_cms_event[duration]" min="1" value="1" type="number"></label></td>
                                    <td width="50%" style="text-align: right;"><label><span><?php _e( 'Days', 'cs_ld_addon' ) ?></span> <select id="ld-cms-event-duration-type" name="ld_cms_event[duration_type]" class="select-field">
                                                <option value="Day" selected><?php _e( 'Day(s)', 'cs_ld_addon' ) ?></option>
                                                <option value="Month"><?php _e( 'Month(s)', 'cs_ld_addon' ) ?></option>
                                                <option value="Year"><?php _e( 'Year(s)', 'cs_ld_addon' ) ?></option>
                                            </select>
                                            
                                        </label></td>
                                </tr>
                            </table>
                        </div>
                        <div id="ld-cms-event-start-fields">
                            <table width="100%" cellpadding="5" cellspacing="5">
                                <tr>
                                    <td width="50%"><label><span><?php _e( 'Start date', 'cs_ld_addon' ) ?></span> <input id="ld-cms-event-start-date" class="input-field ld-cms-event-date-field" name="ld_cms_event[start_date]" size="20" value="" type="text" autocomplete="off"></label></td>
                                    <td width="50%" style="text-align: right;"><label><span><?php _e( 'Start time', 'cs_ld_addon' ) ?></span> <input id="ld-cms-event-start-time" style="z-index:123050 !important;" class="input-field ld-cms-event-time-field" name="ld_cms_event[start_time]" size="20" value="" type="text" autocomplete="off"></label></td>
                                </tr>
                            </table>
                        </div>
                        
                    </td>
                </tr>
                <tr class="crse-mng-rdio">
                    <td colspan="2">
                        <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date2" name="ld_cms_event[is_end_date]" value="one_day_end_date" type="radio" checked="checked"> <span><?php _e( 'End after 24hrs?', "cs_ld_addon" ) ?></span> </label>
                        <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date1" name="ld_cms_event[is_end_date]" value="no_end_date" type="radio"> <span><?php _e( 'No end date/time?', "cs_ld_addon" ) ?></span> </label>
                        <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date" name="ld_cms_event[is_end_date]" value="end_date" type="radio"> <span><?php _e( 'Set the end date/time?', "cs_ld_addon" ) ?></span> </label>
                    <!-- nab** changes -->
                            <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date3" name="ld_cms_event[is_end_date]" value="end_date_yearly" type="radio"> <span><?php _e('Course enrollment date as end date?', "cs_ld_addon") ?></span> </label>
					</td>
                </tr>
                <!-- <tr>
                    <td colspan="2">
                        <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date2" name="ld_cms_event[is_end_date]" value="one_day_end_date" type="radio" checked="checked"> <span><?php _e( 'End after 24hrs?', "cs_ld_addon" ) ?></span> </label>
                        <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date1" name="ld_cms_event[is_end_date]" value="no_end_date" type="radio"> <span><?php _e( 'No end date/time?', "cs_ld_addon" ) ?></span> </label>
                        <label><input class="ld-cms-event-is-end-date" id="ld-cms-event-is-end-date" name="ld_cms_event[is_end_date]" value="end_date" type="radio"> <span><?php _e( 'Set the end date/time?', "cs_ld_addon" ) ?></span> </label>
                    </td>
                </tr> -->
                <tr>
                    <td colspan="2">
                        <div id="ld-cms-event-end-fields" style="display: none;">
                            <table width="100%" cellpadding="5" cellspacing="5">
                                <tr>
                                    <td width="50%"><label><span><?php _e( 'End date', 'cs_ld_addon' ) ?></span> <input id="ld-cms-event-end-date" class="input-field ld-cms-event-date-field" name="ld_cms_event[end_date]" size="20" value="" type="text" autocomplete="off"></label></td>
                                    <td width="50%" style="text-align: right;"><label><span><?php _e( 'End time', 'cs_ld_addon' ) ?></span> <input id="ld-cms-event-end-time" class="input-field ld-cms-event-time-field" name="ld_cms_event[end_time]" size="20" value="" type="text" autocomplete="off"></label></td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
				 <!-- nab*** changes yearly end date set -->

                    <tr>
                        <td colspan="2">
                            <div id="ld-cms-event-end-fields-yearly" style="display: none;">
                                <table width="100%" cellpadding="5" cellspacing="5">
                                    <tr>
                                        <td width="50%"><label><span><?php _e('Interval', 'cs_ld_addon') ?></span> <input id="ld-cms-event-duration-end-date" class="input-field" name="ld_cms_event[duration_end_date]" min="1" value="1" type="number"></label></td>
                                        <td width="50%" style="text-align: right;"><label><span><?php _e('Days', 'cs_ld_addon') ?></span> <select id="ld-cms-event-duration-type-end-date" name="ld_cms_event[duration_type_end_date]" class="select-field">
                                                    <option value="Day" selected><?php _e('Day(s)', 'cs_ld_addon') ?></option>
                                                    <option value="Month"><?php _e('Month(s)', 'cs_ld_addon') ?></option>
                                                    <option value="Year"><?php _e('Year(s)', 'cs_ld_addon') ?></option>
                                                </select>
                                            </label></td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <!-- nab*** end html yearly end date set -->
                <tr class="crse-mng-rdio">
                    <td colspan="2">
                        <label><input id="ld-cms-event-filter-type-include" name="ld_cms_event[filter_type]" type="radio" value="Include" checked="checked" > <span><?php _e( 'Include', "cs_ld_addon" ) ?></span></label>
                        <label><input id="ld-cms-event-filter-type-exclude" name="ld_cms_event[filter_type]" type="radio" value="Exclude"> <span><?php _e( 'Exclude', "cs_ld_addon" ) ?></span></label>
                        <p class="description" style="padding: 0px 10px 15px 5px; color: #999;"><i><?php _e('Set include/exclude following users/roles', "cs_ld_addon"); ?></i></p>
                    </td>
                </tr>
                <tr>
                    <?php if( current_user_can( 'administrator' )){ ?>
                    <td colspan="2">
                        <label> <span id="ld-cms-event-user-roles-label"><?php _e( 'User Roles', 'cs_ld_addon' ) ?></span> 
                         <div class="inside">
                            
                            <div class="sfwd sfwd_options learndash-course-users-settings"> 
                                <input id="ldcms_role_search">
                                    <select class="select-roles" id="select_roles_id" multiple="multiple">
                                    
                                    </select>
                                </input>

                                <a href="javascript:void(0)" id="role_down_btn"><span class="dashicons dashicons-arrow-down-alt2"></span></a>
                                <a href="javascript:void(0)" id="role_up_btn"><span class="dashicons dashicons-arrow-up-alt2"></span></a>


                            <br/>

                        <input id="ldcms_role_search1"/>

                        <select class="chosen-roles" id="chosen_roles_id" multiple="multiple"></select>

                        <div id="chosen_roles_h_inputs"></div>

                    </div>
                </div>
                </div>
                        </label></td>
                </tr> <?php } ?>
                    
                <tr>
                    <td colspan="2"><label> <span id="ld-cms-event-users-label"><?php _e( 'Users', 'cs_ld_addon' ) ?></span>
                  <div class="inside">
            <div class="sfwd sfwd_options learndash-course-users-settings">
              <div id="learndash_course_users_page_box" class="learndash_course_users_page_box"> 
                <input id="ldcms_user_search">
     
                <select class="select-users" id="select_users_id" multiple="multiple">
                   
                </select>
                </input>

                
                <a href="javascript:void(0)" id="user_down_btn"><span class="dashicons dashicons-arrow-down-alt2"></span></a>
                <a href="javascript:void(0)" id="user_up_btn"><span class="dashicons dashicons-arrow-up-alt2"></span></a>


            

                <input id="ldcms_user_search1"/>

                <select class="chosen-users"  id="chosen_users_id" multiple="multiple"></select>

                <div id="chosen_users_h_inputs"></div>
              </div>
            </div>
          </div>
          
                        </label></td>
                </tr>
                <tr id="ld-cms-event-category-tag-fields">
                    <td colspan="2">
                        <table width="100%" cellpadding="5" cellspacing="5">
                            <tr>
                                <td width="50%">
                                    <label><span><?php _e( 'Categories', 'cs_ld_addon') ?></span> <select id="ld-cms-event-categories" name="ld_cms_event[categories]" class="select-field">
                                            <option value=""><?php _e( 'Select Category', 'cs_ld_addon' ) ?></option>
                                        </select></label>
                                        
                                </td>
                                <td width="50%" >

                                    <label><span><?php _e( 'Tags', 'cs_ld_addon' ) ?></span> <select id="ld-cms-event-tags" name="ld_cms_event[tags]" class="select-field">
                                            <option value=""><?php _e( 'Select Tag', 'cs_ld_addon' ) ?></option>
                                        </select></label>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">  
                        <input type="submit" class="ARwebcrafts_crse-plnr_button" value="<?php _e( 'Save Schedule', 'cs_ld_addon' ) ?>" /> 
                        <a href="javascript:;" id="ldcms-view-detail-page" style="display:none"><?php _e( 'View', 'cs_ld_addon' ) ?></a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
</div>   
<!--EVENT THICKBOX FORM TEMPLATE-->
<script>

  jQuery(function ($) {

    select_roles_list = $('#select_roles_id option').map(function () {
        return [[this.value, $(this).text()]];
    });
    chosen_roles_list = $('#chosen_roles_id option').map(function () {
        return [[this.value, $(this).text()]];
    });

    $('#ldcms_role_search').keyup(function () {
        select_roles_list = $('#select_roles_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
            
        var rxp = new RegExp($('#ldcms_role_search').val(), 'i');
        var select_roles_id = $('#select_roles_id').empty();
        var selected_group_id = $('#ld-cms-event-groups option:selected').data('id');
        select_roles_list.each(function () {
            
            if (rxp.test(this[1]) ) {
                select_roles_id.append($('<option/>').attr('value', this[0]).text(this[1]));
            } else{
                select_roles_id.append($('<option/>').attr('value', this[0]).text(this[1]).addClass("hidden"));
            }
        });
        $(".hidden").toggleOption(false);
    
    });
    $('#ldcms_role_search1').keyup(function () {
        chosen_roles_list = $('#chosen_roles_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        
        var rxp = new RegExp($('#ldcms_role_search1').val(), 'i');
        var select_roles_id = $('#chosen_roles_id').empty();
        chosen_roles_list.each(function () {
            if (rxp.test(this[1])) {
                select_roles_id.append($('<option/>').attr('value', this[0]).text(this[1]));
            } else{
                select_roles_id.append($('<option/>').attr('value', this[0]).text(this[1]).addClass("hidden"));
            }
        });
        $(".hidden").toggleOption(false);
    
    });
    $('#role_down_btn').click(function () {
        var chosen_roles_hidden_inputs = '';
        $('.select-roles option:selected').remove().appendTo('.chosen-roles');
        select_roles_list = $('#select_roles_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        chosen_roles_list = $('#chosen_roles_id option').map(function () {
        chosen_roles_hidden_inputs+= '<input type="hidden" name="ld_cms_event[user_roles][]" value="'+this.value+'">';
        return [[this.value, $(this).text()]];
    });
        $('#chosen_roles_h_inputs').html(chosen_roles_hidden_inputs);
    });

    $('#role_up_btn').click(function () {
        var chosen_roles_hidden_inputs = '';
        $('.chosen-roles option:selected').remove().appendTo('.select-roles');
        select_roles_list = $('#select_roles_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        chosen_roles_list = $('#chosen_roles_id option').map(function () {
            chosen_roles_hidden_inputs+= '<input type="hidden" name="ld_cms_event[user_roles][]" value="'+this.value+'">';
        return [[this.value, $(this).text()]];
    });
        $('#chosen_roles_h_inputs').html(chosen_roles_hidden_inputs);
    });



    // ==============================================

    select_users_list = $('#select_users_id option').map(function () {
        return [[this.value, $(this).text()]];
    });
    chosen_users_list = $('#chosen_users_id option').map(function () {
        return [[this.value, $(this).text()]];
    });
     
    $('#ldcms_user_search').keyup(function () {
        select_users_list = $('#select_users_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        var selected_group_users = $('#ld-cms-event-groups option:selected').data('id');
        var rxp = new RegExp($('#ldcms_user_search').val(), 'i');
        $('#select_users_id').empty();
        var select_users_id = $('#select_users_id')
        select_users_list.each(function () {
            if( $('#ld-cms-event-groups option:selected').val() != '' ) {
                if (rxp.test(this[1]) && selected_group_users.indexOf(','+this[0].trim()+',') >= 0) {
                    select_users_id.append($('<option/>').attr('value', this[0]).text(this[1]));
                } else {
                    select_users_id.append($('<option/>').attr('value', this[0]).text(this[1]).addClass("hidden"));
                }
            } else {
                if (rxp.test(this[1])) {
                    select_users_id.append($('<option/>').attr('value', this[0]).text(this[1]));
                } else{
                    select_users_id.append($('<option/>').attr('value', this[0]).text(this[1]).addClass("hidden"));
                } 
            }
        });
        $(".hidden").toggleOption(false);

    });
        
    $('#ldcms_user_search1').keyup(function () {

        chosen_users_list = $('#chosen_users_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        
        var rxp = new RegExp($('#ldcms_user_search1').val(), 'i');
        var select_users_id = $('#chosen_users_id').empty();
        chosen_users_list.each(function () {
            if (rxp.test(this[1])) {
                select_users_id.append($('<option/>').attr('value', this[0]).text(this[1]));
            } else{
                select_users_id.append($('<option/>').attr('value', this[0]).text(this[1]).addClass("hidden"));
            }
        });
        $(".hidden").toggleOption(false);
    
    });
    $('#user_down_btn').click(function () {
        var chosen_users_hidden_inputs = '';
        $('.select-users option:selected').remove().appendTo('.chosen-users');
        select_users_list = $('#select_users_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        chosen_users_list = $('#chosen_users_id option').map(function () {
             chosen_users_hidden_inputs+= '<input type="hidden" name="ld_cms_event[users][]" value="'+this.value+'">';
        return [[this.value, $(this).text()]];
    });
       $('#chosen_users_h_inputs').html(chosen_users_hidden_inputs); 
    });

    $('#user_up_btn').click(function () {
        var chosen_users_hidden_inputs = '';
        $('.chosen-users option:selected').remove().appendTo('.select-users');
        select_users_list = $('#select_users_id option').map(function () {
            return [[this.value, $(this).text()]];
        });
        chosen_users_list = $('#chosen_users_id option').map(function () {
            chosen_users_hidden_inputs+= '<input type="hidden" name="ld_cms_event[users][]" value="'+this.value+'">';
        return [[this.value, $(this).text()]];
    });
       $('#chosen_users_h_inputs').html(chosen_users_hidden_inputs);  
    });
  });

  jQuery.fn.toggleOption = function( show ) {
      jQuery( this ).toggle( show );
      if( show ) {
          if( jQuery( this ).parent( 'span.toggleOption' ).length )
              jQuery( this ).unwrap( );
      } else {
          if( jQuery( this ).parent( 'span.toggleOption' ).length == 0 )
              jQuery( this ).wrap( '<span class="toggleOption" style="display: none;" />' );
      }
  };
  

</script>
<script>
	jQuery( document ).ready(function() { 
			jQuery('.ld-cms-thickbox').scroll(function() {
  if (jQuery(this).scrollTop() > 0) {
    jQuery('.ui-timepicker-standard').hide();
    jQuery('#ui-datepicker-div').hide();
  } 
});
	})
</script>