function psp_single_project($atts)
{
    psp_front_assets(1);
    extract(shortcode_atts(array('id' => '', 'overview' => '', 'progress' => '', 'milestones' => '', 'phases' => '', 'tasks' => ''), $atts));
    // If attributes are not set, let's use defaults.
    if ($overview == '') {
        $overview = 'yes';
    }
    if ($progress == '') {
        $progress == 'yes';
    }
    if ($milestones == '') {
        $milestones = 'condensed';
    }
    if ($phases == '') {
        $phases = 'yes';
    }
    if ($tasks == '') {
        $tasks = 'yes';
    }
    $project = get_post($id);
    $panorama_access = panorama_check_access($id);
    if ($project) {
        ob_start();
        if ($panorama_access == 1) {
            ?>
			
					<div class="psp-single-project">
			
						<h1><?php 
            echo $project->post_title;
            ?>
</h1>
				
						<?php 
            // Is the overview to be displayed?
            if ($overview == 'yes') {
                echo psp_essentials($id, 'psp-shortcode');
            }
            if ($progress == 'yes') {
                echo psp_total_progress($id, 'psp-shortcode', $milestones);
            }
            if ($phases == 'yes') {
                ?>
										
								<div class="single-project-phases">
									<h2><?php 
                _e('Project Phases', 'psp_projects');
                ?>
</h2>
									<?php 
                echo psp_phases($id, 'psp-shortcode', $tasks);
                ?>
								</div>
						<?php 
            }
            ?>
				
						</div>
			
			<?php 
        } else {
            ?>
						
				<div id="psp-login">
					<?php 
            if ($access_granted == 0 && get_field('restrict_access_to_specific_users', $id)) {
                ?>
						<h2><?php 
                _e('This Project Requires a Login', 'psp_projects');
                ?>
</h2>
						<?php 
                if (!is_user_logged_in()) {
                    echo panorama_login_form();
                } else {
                    echo "<p>" . __('You don\'t have permission to access this project', 'psp_projects') . "</p>";
                }
                ?>
					<?php 
            }
            ?>
					<?php 
            if (post_password_required() && !current_user_can('manage_options')) {
                ?>
						<h2><?php 
                _e('This Project is Password Protected', 'psp_projects');
                ?>
</h2>
						<?php 
                echo get_the_password_form();
                ?>
					<?php 
            }
            ?>
				</div>

		<?php 
        }
        return ob_get_clean();
    } else {
        return '<p>' . __('No project with that ID', 'psp_projects') . '</p>';
    }
}
function psp_current_projects($atts)
{
    extract(shortcode_atts(array('type' => 'all', 'status' => 'all', 'access' => 'user', 'count' => '10', 'sort' => 'default', 'order' => 'ASC'), $atts));
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $cuser = wp_get_current_user();
    $cid = $cuser->ID;
    unset($meta_args);
    unset($status_args);
    // Determine the sorting
    if ($sort == 'start') {
        $meta_sort = 'start_date';
        $orderby = 'meta_value';
    } elseif ($sort == 'end') {
        $meta_sort = 'end_date';
        $order_by = 'meta_value';
    } else {
        $meta_sort = 'start_date';
        $order_by = 'menu_order';
    }
    // Set the initial arguments
    $args = array('post_type' => 'psp_projects', 'paged' => $paged, 'posts_per_page' => $count, 'meta_key' => $meta_sort, 'orderby' => $order_by, 'order' => $order);
    // If a type has been selected, add it to the argument
    if (!empty($type) && $type != 'all') {
        $tax_args = array('psp_tax' => $type);
        $args = array_merge($args, $tax_args);
    }
    if ($status == 'active') {
        $status_args = array('tax_query' => array(array('taxonomy' => 'psp_status', 'field' => 'slug', 'terms' => 'completed', 'operator' => 'NOT IN')));
        $args = array_merge($args, $status_args);
    }
    if ($status == 'completed') {
        $status_args = array('tax_query' => array(array('taxonomy' => 'psp_status', 'field' => 'slug', 'terms' => 'completed')));
        $args = array_merge($args, $status_args);
    }
    if ($access == 'user') {
        // Just restricting access, not worried about active or complete
        if (!current_user_can('manage_options')) {
            $cuser = wp_get_current_user();
            $cid = $cuser->ID;
            $meta_args = array('meta_query' => array('relation' => 'OR', array('key' => 'allowed_users_%_user', 'value' => $cid), array('key' => 'restrict_access_to_specific_users', 'value' => '')));
            $args = array_merge($args, $meta_args);
        }
    }
    $projects = new WP_Query($args);
    if ($access == 'user' && !is_user_logged_in()) {
        ?>
		
		<div id="psp-overview">
		
        	<div id="psp-login" class="shortcode-login">
        	
				<h2><?php 
        _e('Please Login to View Projects', 'psp_projects');
        ?>
</h2>
            
				<?php 
        echo panorama_login_form();
        ?>
			
			</div> <!--/#psp-login-->
		
		</div>
	
	<?php 
        psp_front_assets(1);
        return;
    }
    if ($projects->have_posts()) {
        ob_start();
        ?>

        <table class="psp_project_list">
            <thead>
            <tr>
                <th class="psp_pl_col1"><?php 
        _e('Project', 'psp_projects');
        ?>
</th>
                <th class="psp_pl_col2"><?php 
        _e('Progress', 'psp_projects');
        ?>
</th>
                <th class="psp_pl_col3"><?php 
        _e('Start', 'psp_projects');
        ?>
</th>
                <th class="psp_pl_col4"><?php 
        _e('End', 'psp_projets');
        ?>
</th>
            </tr>
            </thead>

            <?php 
        while ($projects->have_posts()) {
            $projects->the_post();
            global $post;
            ?>

                <tr>
                    <td>
                        <a href="<?php 
            the_permalink();
            ?>
"><?php 
            the_title();
            ?>
</a>
                        <div class="psp-table-meta">
                            <p><strong><?php 
            _e('Client', 'psp_projects');
            ?>
:</strong> <?php 
            the_field('client');
            ?>
<br> <strong><?php 
            _e('Last Updated', 'psp_projects');
            ?>
:</strong> <?php 
            the_modified_date();
            ?>
</p>
                        </div>
                    </td>
                    <td>
                        <?php 
            global $post;
            $completed = psp_compute_progress($post->ID);
            if (!empty($completed)) {
                echo '<p class="psp-progress"><span class="psp-' . $completed . '"><b>' . $completed . '%</b></span></p>';
            }
            ?>
                    </td>
                    <td>
                        <?php 
            psp_the_start_date($post->ID);
            ?>
                    </td>
                    <td>
                        <?php 
            psp_the_end_date($post->ID);
            ?>
                    </td>
                </tr>

            <?php 
        }
        ?>

        </table>

        <p><?php 
        echo get_next_posts_link('&laquo; More Projects', $projects->max_num_pages) . ' ' . get_previous_posts_link('Previous Projects &raquo;');
        ?>
</p>

        <?php 
        psp_front_assets(1);
        return ob_get_clean();
    } else {
        return '<p>' . __('No projects found', 'psp_projects') . '</p>';
    }
}