/**
 * Create the HTML to show a To-Do List Checkbox
 *
 * @since 3.4
 */
function ctdl_checkbox()
{
    global $CTDL_status;
    if (CTDL_Lib::check_permission('todo', 'complete')) {
        if ($CTDL_status == 0) {
            return sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-uncompleted" />', absint(get_the_ID()));
        } else {
            return sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-completed" checked="checked" />', absint(get_the_ID()));
        }
    }
    return null;
}
        do_action('post_planner_todo_meta', $pp_todo_id);
        ?>
</div>
				</li>
		<?php 
    }
} else {
    echo apply_filters('post_planner_no_todo_items', esc_html__('There are no items to do.', 'post-planner'));
}
wp_reset_query();
?>

	</ul>

	<?php 
$permission = CTDL_Lib::check_permission('todo', 'add');
if ($permission == true) {
    echo '<p>
		<a class="button-secondary floatright" href="' . admin_url('/admin.php?page=cleverness-to-do-list&planner=' . absint($planner_id)) . '#addtodo">' . apply_filters('post_planner_add_todo', esc_html__('Add New To-Do Item', 'post-planner')) . ' &raquo;</a></p>';
    echo '<div class="clear"></div>';
}
?>

	<?php 
if ($show_completed == 1) {
    ?>
		<ul id="post-planner-todolist-completed">
		<?php 
    $todo_items = PostPlanner_Lib::get_todos($planner_id, $user, -1, 1);
    if ($todo_items->have_posts()) {
        while ($todo_items->have_posts()) {
 /**
  * Setup the dashboard widget
  */
 public function dashboard_setup()
 {
     global $CTDL_status, $CTDL_category, $CTDL_category_id;
     $CTDL_status = 0;
     $CTDL_category = 0;
     $CTDL_category_id = 0;
     $heading = isset(CTDL_Loader::$dashboard_settings['dashboard_heading']) && CTDL_Loader::$dashboard_settings['dashboard_heading'] != '' ? CTDL_Loader::$dashboard_settings['dashboard_heading'] : __('To-Do List', 'cleverness-to-do-list');
     if (CTDL_Lib::check_permission('todo', 'view')) {
         wp_add_dashboard_widget('ctdl', apply_filters('ctdl_todo_list', esc_html($heading)) . ' <a href="admin.php?page=cleverness-to-do-list">&raquo;</a>', array($this, 'dashboard_widget'), array($this, 'dashboard_options'));
     }
 }
 /**
  * Delete To-Do Ajax
  * @static
  */
 public static function delete_todo_callback()
 {
     check_ajax_referer('ctdl-todo');
     $permission = CTDL_Lib::check_permission('todo', 'delete');
     $status = $permission === true ? CTDL_Lib::delete_todo(absint($_POST['cleverness_todo_id'])) : -1;
     echo $status;
     die;
     // this is required to return a proper result
 }
if (1 == CTDL_Loader::$dashboard_settings['show_completed']) {
    ?>
	<div class="completed-checklist">
		<?php 
    foreach ($cat_ids as $cat_id) {
        ?>
			<?php 
        $CTDL_Dashboard_Widget->loop_through_todos(1, $cat_id);
        ?>
		<?php 
    }
    ?>
	</div>
<?php 
}
?>

<?php 
if (CTDL_Lib::check_permission('todo', 'add')) {
    ?>
	<p class="add-todo">
		<a href="<?php 
    echo admin_url('?page=cleverness-to-do-list#addtodo');
    ?>
"><?php 
    echo apply_filters('ctdl_add_text', esc_attr__('Add To-Do Item', 'cleverness-to-do-list'));
    ?>
 &raquo;</a>
	</p>
<?php 
}
 /**
  * Create the HTML to show a To-Do List Checkbox
  * @param int $id
  * @param int $completed
  * @param string $layout
  * @param string $single
  */
 protected function show_checkbox($id, $completed = 0, $layout = 'table', $single = '')
 {
     $permission = CTDL_Lib::check_permission('todo', 'complete');
     if ($permission === true) {
         if (is_admin() || $layout == 'table') {
             $this->list .= '<td>';
         }
         if ($completed == 1) {
             $this->list .= sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-completed' . $single . '" checked="checked" />', esc_attr($id));
         } else {
             $this->list .= sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-uncompleted' . $single . '"/>', esc_attr($id));
         }
         $cleverness_todo_complete_nonce = wp_create_nonce('todocomplete');
         $this->list .= '<input type="hidden" name="cleverness_todo_complete_nonce" value="' . esc_attr($cleverness_todo_complete_nonce) . '" />';
         if (is_admin() || $layout == 'table') {
             $this->list .= '</td>';
         }
     }
 }
 /**
  * Delete a to-do list category using ajax
  * @static
  */
 public static function delete_category_callback()
 {
     check_ajax_referer('cleverness-todo-cat');
     $permission = CTDL_Lib::check_permission('category', 'add_cat');
     $status = $permission === true ? CTDL_Categories::delete_category() : 2;
     echo $status;
     die;
     // this is required to return a proper result
 }
    /**
     * Displays a To-Do List
     * @static
     * @param $planner_id
     * @since 1.1
     */
    public static function display_todolist($planner_id)
    {
        global $current_user, $userdata;
        echo '<div class="post-planner-box">';
        do_action('post_planner_before_todolist');
        echo '<ul id="post-planner-todolist">';
        $user = CTDL_Lib::get_user_id($current_user, $userdata);
        $todo_items = PostPlanner_Lib::get_todos($planner_id, $user);
        $show_completed = PostPlanner_Loader::$settings['ctdl_completed'];
        if ($todo_items->have_posts()) {
            while ($todo_items->have_posts()) {
                $todo_items->the_post();
                $id = get_the_ID();
                ?>
				<li class="post-planner-todolist-item" id="todo-<?php 
                echo esc_attr($id);
                ?>
">
					<input type="checkbox" id="<?php 
                echo esc_attr($id);
                ?>
" name="<?php 
                echo esc_attr($id);
                ?>
" <?php 
                if ($show_completed == 1) {
                    echo 'class="show-completed"';
                }
                ?>
 value="1" />
					<div><?php 
                echo apply_filters('the_content', get_the_content());
                do_action('post_planner_todo_meta', $id);
                ?>
</div>
				</li>
			<?php 
            }
        } else {
            echo apply_filters('post_planner_no_todo_items', esc_html__('There are no items to do.', 'post-planner'));
        }
        wp_reset_query();
        echo '</ul>';
        $permission = CTDL_Lib::check_permission('todo', 'add');
        if ($permission == true) {
            echo '<p><a class="button-secondary floatright" href="' . admin_url('/admin.php?page=cleverness-to-do-list&planner=' . absint($planner_id)) . '#addtodo">' . apply_filters('post_planner_add_todo', esc_html__('Add New To-Do Item', 'post-planner')) . ' &raquo;</a></p>';
            echo '<div class="clear"></div>';
        }
        if ($show_completed == 1) {
            ?>
		<ul id="post-planner-todolist-completed">
			<?php 
            $todo_items = PostPlanner_Lib::get_todos($planner_id, $user, -1, 1);
            if ($todo_items->have_posts()) {
                while ($todo_items->have_posts()) {
                    $todo_items->the_post();
                    $pp_todo_id = get_the_ID();
                    ?>
					<li class="post-planner-todolist-item" id="todo-<?php 
                    echo esc_attr($pp_todo_id);
                    ?>
">
						<input type="checkbox" id="<?php 
                    echo esc_attr($pp_todo_id);
                    ?>
" name="<?php 
                    echo esc_attr($pp_todo_id);
                    ?>
"
							<?php 
                    if ($show_completed == 1) {
                        echo 'class="show-completed"';
                    }
                    ?>
 value="0" checked="checked" />

						<div><?php 
                    echo apply_filters('the_content', get_the_content());
                    do_action('post_planner_todo_completed_meta', $pp_todo_id);
                    ?>
</div>
					</li>
				<?php 
                }
            } else {
                echo apply_filters('post_planner_no_completed_todo_items', esc_html__('There are no completed items.', 'post-planner'));
            }
            wp_reset_query();
            ?>
		</ul>
	<?php 
        }
        do_action('post_planner_after_todolist');
        echo '</div>';
    }
 /**
  * Update to-do list Ajax callback
  * @static
  * @since 1.1
  */
 public static function update_todolist_callback()
 {
     check_ajax_referer('postplanner');
     $todo_id = absint($_POST['postplanner_item_id']);
     $todo_status = absint($_POST['postplanner_item_status']);
     $permission = CTDL_Lib::check_permission('todo', 'complete');
     if ($permission === true) {
         CTDL_Lib::complete_todo(absint($todo_id), $todo_status);
         $status = 1;
     } else {
         $status = -1;
     }
     echo $status;
     die;
     // this is required to return a proper result
 }