| Current Path : /home/ereika83/public_html/wp-content/plugins/project-panorama/lib/pro/ |
| Current File : /home/ereika83/public_html/wp-content/plugins/project-panorama/lib/pro/psp-pro-shortcodes.php |
<?php
function psp_project_part($atts) {
psp_front_assets(1);
extract( shortcode_atts(
array(
'id' => '',
'display' => '',
'style' => ''
), $atts )
);
$project = get_post($id);
if($project):
$output = '<div id="psp-projects" class="psp-part-project">';
if($display == 'overview') {
$output .= psp_essentials($id,'psp-shortcode','none');
} elseif ($display == 'documents') {
$output .= '<div id="psp-essentials" class="psp-shortcode"><div id="psp-documents">';
$output .= psp_documents($id,'psp-shortcode');
$output .= '</div></div>';
} elseif ($display == 'progress') {
$output .= psp_total_progress($id,'psp-shortcode',$style);
} elseif ($display == 'phases') {
$output .= psp_phases($id,'psp-shortcode',$style);
} elseif ($display == 'tasks') {
$output .= psp_task_table($id,'psp-shortcode',$style);
}
$output .= '</div>';
return $output;
else:
return '<p>'.__('No project with that ID','psp_projects').'</p>';
endif;
}
add_shortcode('project_status_part','psp_project_part');
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 id="psp-projects" class="psp-single-project psp-reset">
<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-projects" class="psp-shortcode">
<div id="psp-login">
<?php if(($panorama_access == 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 endif; ?>
<?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 endif; ?>
</div>
</div>
<?php endif;
return ob_get_clean();
else:
return '<p>'.__('No project with that ID','psp_projects').'</p>';
endif;
}
add_shortcode('project_status','psp_single_project');
function psp_single_project_dialog() {
$output = '
<script>
function psp_full_project() {
jQuery("#psp-full-project-table").show();
jQuery("#psp-part-project-table").hide();
}
function psp_part_project() {
jQuery("#psp-full-project-table").hide();
jQuery("#psp-part-project-table").show();
}
function psp_part_change() {
target = jQuery("#psp-part-display").val();
jQuery("tr.psp-part-option-row").hide();
jQuery("#psp-part-" + target + "-option").show();
}
function psp_single_phases_select() {
target = jQuery("#psp-single-phases").val();
if(target == "yes") {
jQuery(".psp-single-tasks-row").show();
} else {
jQuery(".psp-single-tasks-row").hide();
}
}
jQuery(document).ready(function() {
jQuery("#psp-full-project").attr("checked",false);
jQuery("#psp-part-project").attr("checked",false);
psp_single_phases_select();
psp_part_change();
});
</script>
';
$output .= '<div class="psp-dialog" style="display:none">';
$output .= '<div id="psp-single-project-diaglog">';
$output .= '<h3>'.__('Insert a Project Overview','psp_projects').'</h3>';
$output .= '<p>'.__('Select a project below to add it to your post or page.','psp_projects').'</p>';
$output .= '<table class="form-table">';
$output .= '<tr><th>Project</th><td>';
$output .= '<div class="psp-loading"></div>';
$output .= '<div id="psp-single-project-list"></div>';
$output .= '</td></tr>';
$output .= '<tr><th><label for="psp-display-style">Style</label></th><td><label for="psp-display-style"><input unchecked type="radio" name="psp-display-style" onClick="psp_full_project();" id="psp-full-project" value="full"> '.__('Full Project','psp_projects').'</label> <label for="psp-display-style"><input type="radio" unchecked name="psp-display-style" onClick="psp_part_project()" id="psp-part-project" value="part"> '.__('Portion of Project','psp_projects').'</label></td></tr>';
$output .= '</table>';
$output .= '<table class="form-table psp-hide-table" id="psp-full-project-table">';
$output .= '<tr>
<th><label for="psp-single-overview">'.__('Overview','psp_projects').'</label></th>
<td>
<select id="psp-single-overview">
<option value="yes">'.__('Show Overview','psp_projects').'</option>
<option value="no">'.__('No Overview','psp_projects').'</option>
</select>
</td>
</tr>';
$output .= '<tr>
<th><label for="psp-single-progress">'.__('Progress Bar','psp_projects').'</label></th>
<td>
<select id="psp-single-progress">
<option value="yes">'.__('Show Progress Bar','psp_projects').'</option>
<option value="no">'.__('No Progress Bar','psp_projects').'</option>
</select>
</td>
</tr>';
$output .= '<tr>
<th><label for="psp-single-milestones">'.__('Milestones','psp_projects').'</label></th>
<td>
<select id="psp-single-milestones">
<option value="condensed">'.__('Condensed','psp_projects').'</option>
<option value="full">'.__('Full Width','psp_projects').'</option>
<option value="no">'.__('No Milestones','psp_projects').'</option>
</select>
</td>
</tr>';
$output .= '<tr>
<th><label for="psp-single-phases">Phases:</label></td>
<td>
<select id="psp-single-phases" onChange="psp_single_phases_select();">
<option value="yes">'.__('Show Phases','psp_projects').'</option>
<option value="no">'.__('No Phases','psp_projects').'</option>
</select>
</td>
</tr>';
$output .= '<tr class="psp-single-tasks-row">
<th><label for="psp-single-tasks">'.__('Tasks','psp_projects').'</label></th>
<td>
<select id="psp-single-tasks">
<option value="yes">'.__('All Tasks','psp_projects').'</option>
<option value="incomplete">'.__('Incomplete Only','psp_projects').'</option>
<option value="complete">'.__('Completed Only','psp_projects').'</option>
<option value="no">'.__('No Tasks','psp_projects').'</option>
</select>
</td>
<td colspan="2"> </td>
</tr>
</table>';
$output .= '<table class="form-table psp-hide-table" id="psp-part-project-table">
<tr>
<th><label for="psp-part-display">'.__('Display','psp_projects').'</label></th>
<td>
<select id="psp-part-display" onChange="psp_part_change();">
<option value="overview">'.__('Overview','psp_projects').'</option>
<option value="documents">'.__('Documents','psp_projects').'</option>
<option value="progress">'.__('Overall Progress','psp_projects').'</option>
<option value="phases">'.__('Phases','psp_projects').'</option>
<option value="tasks">'.__('Tasks','psp_projects').'</option>
</select>
</td>
</tr>
<tr id="psp-part-progress-option" class="psp-part-option-row">
<th><label for="psp-part-overview-progress-select">'.__('Milestones','psp_projects').'</label></th>
<td><select id="psp-part-overview-progress-select">
<option value="full">'.__('Full Width','psp_projects').'</option>
<option value="condensed">'.__('Condensed','psp_projects').'</option>
<option value="no">'.__('None','psp_projects').'</option>
</select>
</td>
</tr>
<tr id="psp-part-phases-option" class="psp-part-option-row">
<th><label for="psp-part-phases-select">'.__('Tasks','psp_projects').'</label></th>
<td><select id="psp-part-phases-select">
<option value="all">'.__('All Tasks','psp_projects').'</option>
<option value="complete">'.__('Completed Tasks','psp_projects').'</option>
<option value="incomplete">'.__('Incomplete Tasks','psp_projects').'</option>
<option value="no">'.__('None','psp_projects').'</option>
</select>
</td>
</tr>
<tr id="psp-part-tasks-option" class="psp-part-option-row">
<th><label for="psp-part-tasks-select">'.__('Show','psp_projects').'</label></th>
<td><select id="psp-part-tasks-select">
<option value="tasks">'.__('All Tasks','psp_projects').'</option>
<option value="completed">'.__('Completed','psp_projects').'</option>
<option value="open">'.__('Incomplete','psp_projects').'</option>
</select>
</td>
</tr>
</table>
';
$output .= '<p><input class="button-primary" type="button" onclick="InsertPspProject();" value="'.__('Insert Project','psp_projects').'"> <a class="button" onclick="tb_remove(); return false;" href="#">'.__('Cancel','psp_projects').'</a></p>';
$output .= '</div></div>';
echo $output;
}
add_action('admin_footer-post.php', 'psp_single_project_dialog'); // Fired on the page with the posts table
add_action('admin_footer-edit.php', 'psp_single_project_dialog'); // Fired on the page with the posts table
add_action('admin_footer-post-new.php', 'psp_single_project_dialog'); // Fired on the page with the posts table
add_action('admin_footer-post.php', 'psp_project_listing_dialog'); // Fired on the page with the posts table
add_action('admin_footer-edit.php', 'psp_project_listing_dialog'); // Fired on the page with the posts table
add_action('admin_footer-post-new.php', 'psp_project_listing_dialog'); // Fired on the page with the posts table
add_action('wp_ajax_psp_get_projects', 'psp_ajax_project_list');
function psp_ajax_project_list() {
$output = '<p><select id="psp-single-project-id">';
$projectQuery = new WP_Query(array('post_type'=>'psp_projects','posts_per_page' => '-1'));
while($projectQuery->have_posts()): $projectQuery->the_post();
global $post;
$output .= '<option value="'.$post->ID.'">'.get_the_title().'</option>';
endwhile;
$output .= '</select></p>';
echo $output;
}
add_shortcode('user-dashboard-widget','psp_populate_user_dashboard_widget');
function psp_populate_user_dashboard_widget() {
psp_front_assets(1);
$cuser = wp_get_current_user();
$cid = $cuser->ID;
$projects = get_posts(array('post_type' => 'psp_projects','posts_per_page' => '-1','meta_query' => array(
'relation' => 'OR',
array(
'key' => 'allowed_users_%_user',
'value' => $cid
),
array(
'key' => 'restrict_access_to_specific_users',
'value' => ''
)
)
));
$total_projects = count($projects);
$taxonomies = get_terms('psp_tax','fields=count');
// Calculate the number of completed projects
$completed_projects = 0;
$not_started =0;
$active = 0;
foreach($projects as $project):
if(get_post_meta($project->ID,'_psp_completed',true) == '1')
$completed_projects++;
if(psp_compute_progress($project->ID) == 0)
$not_started++;
else
$active++;
endforeach;
if(($completed_projects > 0) && ($total_projects > 0)) {
$percent_complete = floor($completed_projects/$total_projects * 100);
} else {
$percent_complete = 0;
}
if(($not_started > 0) && ($total_projects > 0)) {
$percent_not_started = floor($not_started/$total_projects * 100);
} else {
$percent_not_started = 0;
}
if(($percent_complete > 0) && ($total_projects > 0)) {
$percent_remaining = 100 - $percent_complete - $percent_not_started;
} else {
$percent_remaining = 100;
}
ob_start(); ?>
<div class="psp-chart">
<canvas id="psp-dashboard-chart" width="100%" height="150"></canvas>
</div>
<script>
jQuery(document).ready(function() {
var chartOptions = {
responsive: true
}
var data = [
{
value: <?php echo $percent_complete; ?>,
color: "#2a3542",
label: "Completed"
},
{
value: <?php echo $percent_remaining; ?>,
color: "#3299bb",
label: "In Progress"
},
{
value: <?php echo $percent_not_started; ?>,
color: "#666666",
label: "Not Started"
}
];
var psp_dashboard_chart = document.getElementById("psp-dashboard-chart").getContext("2d");
new Chart(psp_dashboard_chart).Doughnut(data,chartOptions);
});
</script>
<ul class="psp-projects-overview">
<li><span class="psp-dw-projects"><?php echo $total_projects; ?></span> <strong><?php _e('Projects','psp_projects'); ?></strong> </li>
<li><span class="psp-dw-completed"><?php echo $completed_projects; ?></span> <strong><?php _e('Completed','psp_projects'); ?></strong></li>
<li><span class="psp-dw-active"><?php echo $active; ?></span> <strong><?php _e('active','psp_projects'); ?></strong></li>
<li><span class="psp-dw-types"><?php echo $taxonomies; ?></span> <strong><?php _e('Types','psp_projects'); ?></strong></li>
</ul>
<?php
return ob_get_clean();
}
// custom filter to replace '=' with 'LIKE'
add_filter('posts_where', 'psp_posts_where_tasks');
function psp_posts_where_tasks( $where )
{
$where = str_replace("meta_key = 'tasks_%_assigned'", "meta_key LIKE 'tasks_%_assigned'", $where);
return $where;
}
add_shortcode('task-list','psp_output_my_tasks');
function psp_output_my_tasks() {
// Make sure the user is logged in first
if(is_user_logged_in()):
// Get the current logged in WordPress user object
$cuser = wp_get_current_user();
// Query all the projects where this user has been assigned a task
$args = array(
'post_type' => 'psp_projects',
'limit' => -1,
'tax_query' => array(
array(
'taxonomy' => 'psp_status',
'field' => 'slug',
'terms' => 'completed',
'operator' => 'NOT IN'
)
),
'meta_query' => array(
'key' => 'tasks_%_assigned',
'value' => $cuser->ID,
)
);
// Query with the above arguments
$projects = new WP_Query($args);
if($projects->have_posts()):
ob_start(); ?>
<div id="psp-projects" class="psp-my-tasks">
<?php
while($projects->have_posts()): $projects->the_post();
global $post;
$phases = NULL;
// Loop through the phases
while(have_rows('phases')): the_row();
$phase_name = get_sub_field('title');
$tasks = NULL;
// Loop through the tasks
while(have_rows('tasks')): the_row();
$assigned = get_sub_field('assigned');
if($assigned == $cuser->ID)
$tasks .= '<li>'.get_sub_field('task').' <span class="psp-task-bar"><em class="status psp-'.get_sub_field('status').'"></em></span>';
endwhile;
if(!empty($tasks)):
$phases .= '<div class="psp-tasks-phase">
<h3>'.$phase_name.'</h3>
</div>
<ul>
'.$tasks.'
</ul>';
endif;
endwhile; // End phases loop
if(!empty($phases)): ?>
<?php $phases_and_tasks = psp_get_item_count($post,$cuser->ID); ?>
<div class="psp-task-project psp-col-md-4">
<div class="psp-task-project-wrapper">
<h2 class="psp-project-title">
<a href="<?php the_permalink(); ?>"><strong><?php the_field('client'); ?></strong> <?php the_title(); ?></a>
</h2>
<div class="psp-task-project-details">
<h4><a href="#" class="psp-tpt-toggle psp-task-toggle psp-task-toggle-closed"><?php _e('Project Details','psp_projects'); ?></a></h4>
<div class="psp-tpd-content psp-task-content">
<p class="psp-progress"><span class="psp-<?php echo psp_compute_progress($post->ID); ?>"><b><?php echo psp_compute_progress($post->ID); ?>%</b></span></p>
<?php echo psp_the_timebar($post->ID); ?>
</div> <!--/.psp-tpd-content-->
</div> <!--/.psp-task-project-details-->
<div class="psp-task-project-tasks">
<h4 class="psp-open"><a href="#" class="psp-tpt-toggle psp-task-toggle"><?php _e('Your Tasks','psp_projects'); ?></a></h4>
<ul class="psp-grid-row cf">
<li class="psp-col-xs-4 psp-element-tally">
<strong><?php echo $phases_and_tasks['tasks']; ?></strong>
<span><?php _e('Assigned','psp_projects'); ?></span>
</li>
<li class="psp-col-xs-4 psp-element-tally">
<strong><?php echo $phases_and_tasks['started']; ?></strong>
<span><?php _e('Started','psp_projects'); ?></span>
</li>
<li class="psp-col-xs-4 psp-element-tally">
<strong><?php echo $phases_and_tasks['completed']; ?></strong>
<span><?php _e('Complete','psp_projects'); ?></span>
</li>
</ul>
<div class="psp-tpt-content psp-task-content">
<?php echo $phases; ?>
</div>
<p><a href="<?php the_permalink(); ?>" class="psp-btn-bar"><span class="psp-pull-right">→</span> <?php _e('View Project','psp_projects'); ?></a></p>
</div> <!--/.psp-task-project-tasks-->
</div>
</div>
<?php endif;
// End query loop
endwhile; ?>
</div>
<?php endif; ?>
<?php endif;
return ob_get_clean();
}
?>