Example #1
0
/**
 * Get all the orders from a specific seller
 *
 * @global object $wpdb
 * @param int $seller_id
 * @return array
 */
function cpm_project_count()
{
    global $wpdb;
    $table = $wpdb->prefix . 'cpm_user_role';
    $user_id = get_current_user_id();
    $cache_key = 'cpm_project_count';
    $count = wp_cache_get($cache_key, 'cpm');
    if (isset($_GET['project_cat']) && !empty($_GET['project_cat']) && $_GET['project_cat'] != '-1') {
        $project_category = $_GET['project_cat'];
        $project_category_join = " LEFT JOIN {$wpdb->term_relationships} as term ON term.object_id = post.ID";
        $project_category = " AND term.term_taxonomy_id IN ({$project_category})";
    } else {
        $project_category = '';
        $project_category_join = '';
    }
    $project_category_join = apply_filters('cpm_project_activity_count_join', $project_category_join);
    $project_category = apply_filters('cpm_project_activity_count_where', $project_category);
    if (cpm_manage_capability() == false) {
        $role_join = "LEFT JOIN {$table} AS role ON role.project_id = post.ID";
        $role_where = "AND role.user_id = {$user_id}";
    } else {
        $role_join = '';
        $role_where = '';
    }
    if ($count === false) {
        $sql = "SELECT COUNT(post.ID) AS count, meta.meta_value AS type FROM {$wpdb->posts} AS post\r\n            LEFT JOIN {$wpdb->postmeta} AS meta on meta.post_id = post.ID\r\n            {$project_category_join}\r\n            {$role_join}\r\n            WHERE\r\n                post.post_type ='project'\r\n                AND post.post_status = 'publish'\r\n                {$project_category}\r\n                {$role_where}\r\n                AND meta.meta_key = '_project_active'\r\n                GROUP BY meta.meta_value";
        $count = $wpdb->get_results($sql);
        wp_cache_set($cache_key, $count, 'cpm');
    }
    if (is_array($count) && count($count)) {
        foreach ($count as $key => $obj) {
            if ($obj->type == 'yes') {
                $active = $obj->count;
            }
            if ($obj->type == 'no') {
                $archive = $obj->count;
            }
        }
    }
    $count['active'] = isset($active) ? $active : 0;
    $count['archive'] = isset($archive) ? $archive : 0;
    return $count;
}
Example #2
0
 function project_new()
 {
     $posted = $_POST;
     $pro_obj = CPM_Project::getInstance();
     //fail if current user is not editor or above
     if (!cpm_manage_capability('project_create_role')) {
         echo json_encode(array('success' => false));
         exit;
     }
     $posted = $_POST;
     $project_id = $pro_obj->create($project_id = 0, $posted);
     $project = $pro_obj->get($project_id);
     echo json_encode(array('success' => true, 'url' => cpm_url_project_details($project_id)));
     exit;
 }
Example #3
0
<?php

$project_obj = CPM_Project::getInstance();
$projects = $project_obj->get_projects();
$total_projects = $projects['total_projects'];
$pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1;
$db_limit = intval(cpm_get_option('pagination'));
$limit = $db_limit ? $db_limit : 10;
$status_class = isset($_GET['status']) ? $_GET['status'] : 'active';
$count = cpm_project_count();
$can_create_project = cpm_manage_capability('project_create_role');
$class = $can_create_project ? '' : ' cpm-no-nav';
unset($projects['total_projects']);
?>

<h2><?php 
_e('Project Manager', 'cpm');
?>
</h2>

<div class="cpm-projects<?php 
echo $class;
?>
">

    <div class="cpm-project-filter">
        <ul class="list-inline order-statuses-filter">
            <li<?php 
echo $status_class == 'all' ? ' class="active"' : '';
?>
>
Example #4
0
 /**
  * Get all the projects
  *
  * @param int $count
  * @return object
  */
 function get_projects($count = -1)
 {
     $pagenum = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1;
     $limit = intval(cpm_get_option('pagination'));
     $offset = ($pagenum - 1) * $limit;
     $filters = $_GET;
     $project_category = isset($filters['project_cat']) ? $filters['project_cat'] : 0;
     $args = array('posts_per_page' => $count, 'post_type' => 'project', 'posts_per_page' => $limit, 'offset' => $offset);
     //Add Filtering
     if ($project_category != 0 && $project_category != '-1') {
         $args['tax_query'][] = array('taxonomy' => 'project_category', 'field' => 'term_id', 'terms' => array($project_category), 'operator' => 'IN');
     }
     if (isset($_GET['page']) && $_GET['page'] == 'cpm_projects' && isset($_GET['status'])) {
         if ($_GET['status'] == 'archive') {
             $args['meta_query'] = array(array('key' => '_project_active', 'value' => 'no', 'compare' => '='));
         } else {
             if ($_GET['status'] == 'active') {
                 $args['meta_query'] = array(array('key' => '_project_active', 'value' => 'yes', 'compare' => '='));
             } else {
                 if ($_GET['status'] == 'all') {
                     $args['meta_query'] = '';
                 }
             }
         }
     } else {
         $args['meta_query'] = array(array('key' => '_project_active', 'value' => 'yes', 'compare' => '='));
     }
     if (cpm_manage_capability() == false) {
         add_filter('posts_join', array($this, 'jonin_user_role_table'));
         add_filter('posts_where', array($this, 'get_project_where_user_role'), 10, 2);
     }
     $args = apply_filters('cpm_get_projects_argument', $args);
     $projects = new WP_Query($args);
     $total_projects = $projects->found_posts;
     $projects = $projects->posts;
     if (cpm_manage_capability() == false) {
         remove_filter('posts_join', array($this, 'jonin_user_role_table'));
         remove_filter('posts_where', array($this, 'get_project_where_user_role'), 10, 2);
     }
     foreach ($projects as &$project) {
         $project->info = $this->get_info($project->ID);
         $project->users = $this->get_users($project);
     }
     $projects['total_projects'] = $total_projects;
     return $projects;
 }
 /**
  * Create a new milestone.
  *
  * @param int $project_id
  * @param array $data
  *
  *  - milestone_name (string, required)
  *  - milestone_due (date format)
  *  - milestone_detail (string)
  *  - milestone_privacy (string)
  *
  *  - Method: POST
  *  - URL: http://example.com/cpm-json/projects/project_id/milestones
  *
  * @since 1.2
  * @return array $response
  */
 public function create_milestone($project_id, $data)
 {
     $project_id = intval($project_id);
     if (!$project_id) {
         return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404));
     }
     if (isset($data['milestone_name']) && empty($data['milestone_name'])) {
         return new WP_Error('milestone_name', __('Milestone Name Required', 'cpm'));
     }
     $manage_capability = cpm_manage_capability();
     if (!$manage_capability && !cpm_is_single_project_manager($project_id)) {
         if (!cpm_project_user_role_pre_chache($project_id)) {
             return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404));
         }
         if (!cpm_user_can_access($project_id, 'create_milestone')) {
             return new WP_Error('permission', __('Sorry! you do not have permission to create milestone', 'cpm'), array('status' => 404));
         }
     }
     $milestone_id = cpm()->milestone->create($project_id, $data);
     $get_milestone = cpm()->milestone->get($milestone_id);
     $response = new WP_JSON_Response();
     $response->set_data($get_milestone);
     return $response;
 }
 /**
  * Create a new todolist.
  *
  * @param int $project_id
  * @param array $data
  *
  *  - tasklist_name (string, required)
  *  - tasklist_detail (string)
  *  - tasklist_privacy (string)
  *  - tasklist_milestone (integer)
  *
  *  - Method: POST
  *  - URL: http://example.com/cpm-json/projects/project_id/lists
  *
  * @since 1.2
  * @return array $response
  */
 public function create_list($project_id, $data)
 {
     $project_id = (int) $project_id;
     $list_id = (int) $list_id;
     if (!$project_id) {
         return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404));
     }
     $manage_capability = cpm_manage_capability();
     if (!$manage_capability && !cpm_is_single_project_manager($project_id)) {
         if (!cpm_project_user_role_pre_chache($project_id)) {
             return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404));
         }
         if (!cpm_user_can_access($project_id, 'create_todolist')) {
             return new WP_Error('permission', __('Sorry! you do not have permission to create todo list', 'cpm'), array('status' => 404));
         }
     }
     if (empty($data['tasklist_name'])) {
         return new WP_Error('task_list_name', __('Task List Name Required', 'cpm'));
     }
     $data['tasklist_milestone'] = isset($data['tasklist_milestone']) ? $data['tasklist_milestone'] : '-1';
     $data['tasklist_privacy'] = isset($data['tasklist_privacy']) ? $data['tasklist_privacy'] : 'no';
     $list_id = cpm()->task->add_list($project_id, $data);
     $get_list = cpm()->task->get_task_list($list_id);
     $response = new WP_JSON_Response();
     $response->set_data($get_list);
     return $response;
 }
 /**
  * Check comment create permission
  *
  * @param int $project_id
  * @param int $post_id
  *
  * @since 1.2
  * @return boolen | array
  */
 function check_create_comment_permission($project_id, $post_id)
 {
     $post_id = intval($post_id);
     $project_id = intval($project_id);
     if (!$post_id) {
         return array('key' => 'json_post_invalid_id', 'message' => __('Invalid post ID.'));
     }
     if (!$project_id) {
         return array('key' => 'json_post_invalid_id', 'message' => __('Invalid project ID.'));
     }
     $post = get_post($post_id);
     $post_type = $post->post_type;
     switch ($post_type) {
         case 'message':
             $manage_capability = cpm_manage_capability();
             if ($manage_capability || cpm_is_single_project_manager($project_id)) {
                 return true;
             } else {
                 if (!cpm_project_user_role_pre_chache($project_id)) {
                     return array('key' => 'permission', 'message' => __('Sorry! you are not assigned in this project', 'cpm'));
                 } else {
                     if (!cpm_user_can_access($project_id, 'create_message')) {
                         return array('key' => 'permission', 'message' => __('Sorry! you do not have permission to view this comments', 'cpm'));
                     }
                 }
             }
             break;
         case 'task':
             $manage_capability = cpm_manage_capability();
             if ($manage_capability || cpm_is_single_project_manager($project_id)) {
                 $condition = true;
             } else {
                 if (!cpm_project_user_role_pre_chache($project_id)) {
                     return array('key' => 'permission', 'message' => __('Sorry! you are not assinged in this project', 'cpm'), array('status' => 404));
                 } else {
                     if (!cpm_user_can_access($project_id, 'tdolist_view_private')) {
                         return array('key' => 'permission', 'message' => __('Sorry! you do no have permission to view this comment', 'cpm'), array('status' => 404));
                     } else {
                         if (!cpm_user_can_access($project_id, 'create_todo')) {
                             return array('key' => 'permission', 'message' => __('Sorry! you do no have permission to view this comment', 'cpm'), array('status' => 404));
                         }
                     }
                 }
             }
             break;
         case 'task_list':
             $manage_capability = cpm_manage_capability();
             if ($manage_capability || cpm_is_single_project_manager($project_id)) {
                 return true;
             } else {
                 if (!cpm_project_user_role_pre_chache($project_id)) {
                     return array('key' => 'permission', 'message' => __('Sorry! you are not assinged in this project', 'cpm'), array('status' => 404));
                 } else {
                     if (!cpm_user_can_access($project_id, 'create_todolist')) {
                         return array('key' => 'permission', 'message' => __('Sorry! you do no have permission to view this comment', 'cpm'), array('status' => 404));
                     }
                 }
             }
             break;
     }
     return true;
 }
Example #8
0
<?php

global $current_user;
$this_user = true;
$disabled = '';
if (isset($_GET['user_id']) && !empty($_GET['user_id'])) {
    if (!cpm_manage_capability() && $current_user->ID != $_GET['user_id']) {
        printf('<h1>%s</h1>', __('You do no have permission to access this page', 'cpm'));
        return;
    }
    if ($current_user->ID != $_GET['user_id']) {
        $this_user = false;
    }
    $current_user = get_user_by('id', $_GET['user_id']);
    $title = sprintf("%s's tasks", $current_user->display_name);
} else {
    $title = __('My Tasks', 'cpm');
}
$task = CPM_Task::getInstance();
$project = $task->get_mytasks($current_user->ID);
$count = $task->mytask_count();
if (isset($_GET['tab']) && $_GET['tab'] == 'outstanding') {
    $page_status = 'outstanding';
} else {
    if (isset($_GET['tab']) && $_GET['tab'] == 'complete') {
        $page_status = 'complete';
    } else {
        $page_status = '';
    }
}
?>
 /**
  * Delete project
  *
  * @param int $project_id
  * @param boolen $force
  *
  * - URL: http://example.com/cpm-json/projects/project_id/?force=1
  * - Method: DELETE
  *
  * @since 1.2
  * @return array
  */
 public function delete_project($project_id, $force = false)
 {
     $id = intval($project_id);
     if (!$id) {
         return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404));
     }
     $manage_capability = cpm_manage_capability();
     if (!$manage_capability && !cpm_project_user_role_pre_chache($id)) {
         return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404));
     }
     if (!cpm_user_can_access($id)) {
         return new WP_Error('project_edit_capability', __('You do not have permission to delete this project', 'cpm'));
     }
     $post = get_post($id, ARRAY_A);
     if (empty($post['ID'])) {
         return new WP_Error('json_post_invalid_id', __('Invalid post ID.'), array('status' => 404));
     }
     cpm()->project->delete($id, $force);
     if ($force) {
         return array('message' => __('Permanently deleted post'));
     } else {
         return array('message' => __('Deleted post'));
     }
 }
 /**
  * Create a new task.
  *
  * @param int $project_id
  * @param int $list_id
  * @param array $data
  *
  *  - task_text (string, required)
  *  - task_privacy (string)
  *  - task_assign (array)
  *  - task_due (date format)
  *  - task_start (date format)
  *
  *  - Method: POST
  *  - URL: http://example.com/cpm-json/projects/project_id/lists/list_id/tasks
  *
  * @since 1.2
  * @return array $response
  */
 public function create_task($project_id, $list_id, $data)
 {
     $project_id = (int) $project_id;
     $list_id = (int) $list_id;
     if (!$project_id) {
         return new WP_Error('json_post_invalid_id', __('Invalid project ID.'), array('status' => 404));
     }
     if (!$list_id) {
         return new WP_Error('json_post_invalid_id', __('Invalid todo list ID.'), array('status' => 404));
     }
     if (empty($data['task_text'])) {
         return new WP_Error('task_text', __('Task Name Required', 'cpm'));
     }
     $posts_list = cpm()->task->get_task_list($list_id);
     $manage_capability = cpm_manage_capability();
     if (!$manage_capability && !cpm_is_single_project_manager($project_id)) {
         if (!cpm_project_user_role_pre_chache($project_id)) {
             return new WP_Error('permission', __('Sorry! you are not assigned in this project', 'cpm'), array('status' => 404));
         }
         if (!cpm_user_can_access($project_id, 'create_todolist')) {
             return new WP_Error('permission', __('Sorry! you do not have permission to create todo list', 'cpm'), array('status' => 404));
         }
         if (!cpm_user_can_access($project_id, 'create_todo')) {
             return new WP_Error('permission', __('Sorry! you do not have permission to create todo', 'cpm'), array('status' => 404));
         }
     }
     add_filter('cpm_new_task_notification', array($this, 'change_notification_status'));
     $task_id = cpm()->task->add_task($list_id, $data);
     $get_task = cpm()->task->get_task($task_id);
     $response = new WP_JSON_Response();
     $response->set_data($get_task);
     return $response;
 }
Example #11
0
    /**
     * List all projects
     *
     * @since 1.0
     */
    function list_projects()
    {
        $project_obj = CPM_Project::getInstance();
        $projects = $project_obj->get_projects();
        $status_class = isset($_GET['status']) ? $_GET['status'] : 'active';
        if (function_exists('cpm_project_count')) {
            $count = cpm_project_count();
        }
        ?>

        <div class="icon32" id="icon-themes"><br></div>
        <h2><?php 
        _e('Project Manager', 'cpm');
        ?>
</h2>

        <?php 
        if (function_exists('cpm_project_filters')) {
            cpm_project_filters();
        }
        ?>

        <div class="cpm-projects">

            <?php 
        if (function_exists('cpm_project_filters')) {
            ?>
                <ul class="list-inline order-statuses-filter">
                    <li<?php 
            echo $status_class == 'all' ? ' class="active"' : '';
            ?>
>
                        <a href="<?php 
            echo cpm_url_all();
            ?>
"><?php 
            _e('All', 'cpm');
            ?>
</a>
                    </li>
                    <li<?php 
            echo $status_class == 'active' ? ' class="active"' : '';
            ?>
>
                        <a class="cpm-active" href="<?php 
            echo cpm_url_active();
            ?>
"><?php 
            printf(__('Active (%d)', 'cpm'), $count['active']);
            ?>
</a>
                    </li>
                    <li<?php 
            echo $status_class == 'archive' ? ' class="active"' : '';
            ?>
>
                        <a class="cpm-archive-head" href="<?php 
            echo cpm_url_archive();
            ?>
"><?php 
            printf(__('Completed (%d)', 'cpm'), $count['archive']);
            ?>
</a>
                    </li>
                </ul>
            <?php 
        }
        ?>

            <?php 
        if (cpm_manage_capability('project_create_role')) {
            ?>
                <nav class="cpm-new-project">
                    <a href="#" id="cpm-create-project"><span><?php 
            _e('New Project', 'cpm');
            ?>
</span></a>
                </nav>
            <?php 
        }
        ?>

            <?php 
        foreach ($projects as $project) {
            if (!$project_obj->has_permission($project)) {
                continue;
            }
            ?>
                <article class="cpm-project">
                    <?php 
            if (cpm_is_project_archived($project->ID)) {
                ?>
                        <div class="cpm-completed-wrap"><div class="ribbon-green"><?php 
                _e('Completed', 'cpm');
                ?>
</div></div>
                    <?php 
            }
            ?>

                    <a href="<?php 
            echo cpm_url_project_details($project->ID);
            ?>
">
                        <h5><?php 
            echo get_the_title($project->ID);
            ?>
</h5>

                        <div class="cpm-project-detail"><?php 
            echo cpm_excerpt($project->post_content, 55);
            ?>
</div>
                        <div class="cpm-project-meta">
                            <?php 
            echo cpm_project_summary($project->info);
            ?>
                        </div>

                        <footer class="cpm-project-people">
                            <div class="cpm-scroll">
                            <?php 
            if (count($project->users)) {
                foreach ($project->users as $id => $user_meta) {
                    echo get_avatar($id, 48, '', $user_meta['name']);
                }
            }
            ?>
                            </div>
                        </footer>
                    </a>

                    <?php 
            $progress = $project_obj->get_progress_by_tasks($project->ID);
            echo cpm_task_completeness($progress['total'], $progress['completed']);
            if (cpm_user_can_access($project->ID)) {
                cpm_project_actions($project->ID);
            }
            ?>


                </article>

            <?php 
        }
        ?>

        </div>

        <div id="cpm-project-dialog" title="<?php 
        _e('Start a new project', 'cpm');
        ?>
" style="display: none;">
            <?php 
        if ($project_obj->has_admin_rights()) {
            ?>
                <?php 
            cpm_project_form();
            ?>
            <?php 
        }
        ?>
        </div>

        <div id="cpm-create-user-wrap">
            <?php 
        if ($project_obj->has_admin_rights()) {
            ?>
                <?php 
            cpm_user_create_form();
            ?>
            <?php 
        }
        ?>
        </div>


        <script type="text/javascript">
            jQuery(function($) {
                $( "#cpm-project-dialog, #cpm-create-user-wrap" ).dialog({
                    autoOpen: false,
                    modal: true,
                    dialogClass: 'cpm-ui-dialog',
                    width: 485,
                    height: 425,
                    position:['middle', 100]
                });
            });

            jQuery(function($) {
                $( "#cpm-create-user-wrap" ).dialog({
                    autoOpen: false,
                    modal: true,
                    dialogClass: 'cpm-ui-dialog',
                    width: 400,
                    height: 353,
                    position:['middle', 100]
                });
            });
        </script>
        <?php 
    }