Пример #1
0
 function get_events()
 {
     $projects = CPM_Project::getInstance()->get_projects();
     unset($projects['total_projects']);
     if (cpm_get_option('task_start_field') == 'on') {
         $enable_start = true;
     } else {
         $enable_start = false;
     }
     $events = array();
     if ($projects) {
         foreach ($projects as $project) {
             $project_id = $project->ID;
             if (absint($_POST['project_id']) && $project_id != absint($_POST['project_id'])) {
                 continue;
             }
             //Get Milestones
             $milestones = CPM_Milestone::getInstance()->get_by_project($project_id);
             if ($milestones) {
                 foreach ($milestones as $milestone) {
                     //Milestone Event
                     $events[] = array('id' => $milestone->ID, 'title' => $milestone->post_title, 'start' => $milestone->due_date, 'url' => cpm_url_milestone_index($project_id), 'color' => '#32b1c8', 'className' => $milestone->completed == 1 ? 'milestone competed' : 'milestone');
                 }
             }
             //Get Tasks
             if (cpm_user_can_access($project_id, 'tdolist_view_private')) {
                 $task_lists = CPM_Task::getInstance()->get_task_lists($project_id, true);
             } else {
                 $task_lists = CPM_Task::getInstance()->get_task_lists($project_id);
             }
             if ($task_lists) {
                 foreach ($task_lists as $task_list) {
                     $tasks = CPM_Task::getInstance()->get_tasks_by_access_role($task_list->ID, $project_id);
                     foreach ($tasks as $task) {
                         $image = '';
                         if (is_array($task->assigned_to)) {
                             foreach ($task->assigned_to as $key => $user_id) {
                                 $image .= get_avatar($user_id, 16);
                             }
                         } else {
                             $image .= get_avatar($task->assigned_to, 16);
                         }
                         //Tasks Event
                         if ($enable_start) {
                             if (isset($task->start_date) && !empty($task->start_date)) {
                                 $start_date = $task->start_date;
                             } else {
                                 $start_date = $task->due_date;
                             }
                             $events[] = array('id' => $task->ID, 'img' => $task->assigned_to == -1 ? '' : $image, 'title' => $task->post_title, 'start' => $start_date, 'end' => $task->due_date, 'complete_status' => $task->completed == 1 ? 'yes' : 'no', 'url' => cpm_url_single_task($project_id, $task_list->ID, $task->ID), 'color' => 'transparent', 'textColor' => '#c86432', 'className' => date('Y-m-d', time()) < $task->due_date ? 'cpm-calender-todo cpm-task-running' : 'cpm-calender-todo cpm-expire-task');
                         } else {
                             $events[] = array('id' => $task->ID, 'img' => $task->assigned_to == -1 ? '' : $image, 'title' => $task->post_title, 'start' => $task->due_date, 'complete_status' => $task->completed == 1 ? 'yes' : 'no', 'url' => cpm_url_single_task($project_id, $task_list->ID, $task->ID), 'color' => 'transparent', 'textColor' => '#c86432', 'className' => date('Y-m-d', time()) < $task->due_date ? 'cpm-calender-todo cpm-task-running' : 'cpm-calender-todo cpm-expire-task');
                         }
                     }
                 }
             }
         }
     }
     return $events;
 }
Пример #2
0
 /**
  * Mark a task as uncomplete/open
  *
  * @param int $task_id task id
  */
 function mark_open($milestone_id)
 {
     update_post_meta($milestone_id, '_completed', 0);
     update_post_meta($milestone_id, '_completed_on', current_time('mysql'));
     CPM_Project::getInstance()->new_project_item_complete_open($milestone_id);
     do_action('cpm_milestone_open', $milestone_id);
 }
Пример #3
0
 function project_delete()
 {
     $posted = $_POST;
     $project_id = isset($posted['project_id']) ? intval($posted['project_id']) : 0;
     CPM_Project::getInstance()->delete($project_id);
     echo json_encode(array('success' => true, 'url' => cpm_url_projects()));
     exit;
 }
Пример #4
0
 function instantiate()
 {
     $project = CPM_Project::getInstance();
     $message = CPM_Message::getInstance();
     $task = CPM_Task::getInstance();
     $milestone = CPM_Milestone::getInstance();
     $activity = new CPM_Activity();
     $ajax = new CPM_Ajax();
     $notification = new CPM_Notification();
 }
Пример #5
0
function cpm_task_assign_dropdown($project_id, $selected = '-1')
{
    $users = CPM_Project::getInstance()->get_users($project_id);
    if ($users) {
        echo '<select name="task_assign" id="task_assign">';
        echo '<option value="-1">' . __('-- assign to --', 'cpm') . '</option>';
        foreach ($users as $user) {
            printf('<option value="%s"%s>%s</opton>', $user['id'], selected($selected, $user['id']), $user['name']);
        }
        echo '</select>';
    }
}
Пример #6
0
/**
 * Upgrade to 0.5
 *
 * @return type
 */
function cpm_upgrade_to_0_5()
{
    global $wpdb;
    $table = $wpdb->prefix . 'cpm_user_role';
    $project_query = new WP_Query(array('post_type' => 'project', 'numberposts' => -1));
    $projects = $project_query->get_posts();
    if (!$projects) {
        return;
    }
    foreach ($projects as $project) {
        cpm_update_task_start_meta($project);
        update_post_meta($project->ID, '_project_active', 'yes');
        // add post author to manager
        $data = array('project_id' => $project->ID, 'user_id' => $project->post_author, 'role' => 'manager');
        $format = array('%d', '%d', '%s');
        $wpdb->insert($table, $data, $format);
        // If any coworkers found, add them too
        $co_workers = get_post_meta($project->ID, '_coworker', true);
        $co_workers = is_array($co_workers) ? $co_workers : array();
        if (count($co_workers)) {
            foreach ($co_workers as $user_id) {
                $data = array('project_id' => $project->ID, 'user_id' => $user_id, 'role' => 'co_worker');
                $format = array('%d', '%d', '%s');
                if ($user_id != $project->post_author) {
                    $wpdb->insert($table, $data, $format);
                }
                delete_post_meta($project->ID, '_coworker');
            }
        }
        //update user setting for all projectg
        $settings = CPM_Project::getInstance()->settings_user_permission();
        update_post_meta($project->ID, '_settings', $settings);
    }
    $tasks = get_posts(array('post_type' => 'task', 'numberposts' => -1));
    if ($tasks) {
        foreach ($tasks as $task) {
            update_post_meta($task->ID, '_task_privacy', 'no');
            update_post_meta($task->ID, '_start', '');
        }
    }
    $task_lists = get_posts(array('post_type' => 'task_list', 'numberposts' => -1));
    if ($task_lists) {
        foreach ($task_lists as $task_list) {
            update_post_meta($task_list->ID, '_tasklist_privacy', 'no');
        }
    }
    $messages = get_posts(array('post_type' => 'message', 'numberposts' => -1));
    if ($messages) {
        foreach ($messages as $message) {
            update_post_meta($message->ID, '_message_privacy', 'no');
        }
    }
}
Пример #7
0
 /**
  * Instantiate all the required classes
  *
  * @since 0.1
  */
 function instantiate()
 {
     CPM_Project::getInstance();
     CPM_Message::getInstance();
     CPM_Task::getInstance();
     CPM_Milestone::getInstance();
     new CPM_Activity();
     new CPM_Ajax();
     new CPM_Notification();
     // instantiate admin settings only on admin page
     if (is_admin()) {
         new CPM_Admin();
     }
 }
 function new_message($message_id, $project_id)
 {
     $users = $this->prepare_contacts();
     if (!$users) {
         return;
     }
     $pro_obj = CPM_Project::getInstance();
     $msg_obj = CPM_Message::getInstance();
     $project = $pro_obj->get($project_id);
     $msg = $msg_obj->get($message_id);
     $author = wp_get_current_user();
     $subject = sprintf(__('[%s] New message on project: %s', 'cpm'), __('Project Manager', 'cpm'), $project->post_title);
     $message = sprintf('New message on %s', $project->post_title) . "\r\n\n";
     $message .= sprintf('Author : %s', $author->display_name) . "\r\n";
     $message .= sprintf(__('Permalink : %s'), cpm_url_single_message($project_id, $message_id)) . "\r\n";
     $message .= sprintf("Message : \r\n%s", $msg->post_content) . "\r\n";
     $users = apply_filters('cpm_new_message_to', $users);
     $subject = apply_filters('cpm_new_message_subject', $subject);
     $message = apply_filters('cpm_new_message_message', $message);
     $this->send(implode(', ', $users), $subject, $message);
 }
Пример #9
0
 function new_message($message_id, $project_id)
 {
     $users = $this->prepare_contacts();
     if (!$users) {
         return;
     }
     $pro_obj = CPM_Project::getInstance();
     $msg_obj = CPM_Message::getInstance();
     $project = $pro_obj->get($project_id);
     $msg = $msg_obj->get($message_id);
     $author = wp_get_current_user();
     $template_vars = array('%SITE%' => wp_specialchars_decode(get_option('blogname'), ENT_QUOTES), '%PROJECT_NAME%' => $project->post_title, '%PROJECT_URL%' => cpm_url_project_details($project_id), '%AUTHOR%' => $author->display_name, '%AUTHOR_EMAIL%' => $author->user_email, '%MESSAGE_URL%' => cpm_url_single_message($project_id, $message_id), '%MESSAGE%' => $msg->post_content, '%IP%' => get_ipaddress());
     $subject = cpm_get_option('new_message_sub');
     $message = cpm_get_option('new_message_body');
     // subject
     foreach ($template_vars as $key => $value) {
         $subject = str_replace($key, $value, $subject);
     }
     // message
     foreach ($template_vars as $key => $value) {
         $message = str_replace($key, $value, $message);
     }
     $this->send(implode(', ', $users), $subject, $message);
 }
Пример #10
0
 /**
  * Instantiate all the required classes
  *
  * @since 0.1
  */
 function instantiate()
 {
     $this->project = CPM_Project::getInstance();
     $this->message = CPM_Message::getInstance();
     $this->task = CPM_Task::getInstance();
     $this->milestone = CPM_Milestone::getInstance();
     $this->activity = new CPM_Activity();
     $this->ajax = new CPM_Ajax();
     $this->notification = new CPM_Notification();
     // instantiate admin settings only on admin page
     if (is_admin()) {
         $this->admin = new CPM_Admin();
         $this->updates = new CPM_Updates();
         $this->upgrade = new CPM_Upgrade();
     }
 }
Пример #11
0
_e('Calendar', 'cpm');
?>
</h2>

<?php 
if (cpm_get_option('task_start_field') == 'on') {
    $eventDurationEditable = 'true';
} else {
    $eventDurationEditable = 'false';
}
if (!is_admin()) {
    $fornt_instant = 'cpmf_url:' . json_encode(get_permalink());
} else {
    $fornt_instant = 'url:' . json_encode(admin_url());
}
$porjects = CPM_Project::getInstance()->get_projects();
unset($porjects['total_projects']);
if (isset($_POST['calender-project'])) {
    $project_id = isset($_POST['project_id']) ? absint($_POST['project_id']) : '0';
} else {
    $project_id = '0';
}
?>

<form action="" method="post">
    <?php 
$get_values = isset($_GET) ? $_GET : array();
foreach ($get_values as $name => $get_value) {
    ?>
            <!-- <input type="hidden" name="<?php 
    echo $name;
Пример #12
0
 /**
  * Delete a single task
  *
  * @param int $task_id
  * @param bool $force
  */
 function delete_task($task_id, $force = false)
 {
     do_action('cpm_task_delete', $task_id, $force);
     $item_id = $this->get_item_id($task_id);
     $this->delete_task_item($item_id);
     CPM_Project::getInstance()->delete_project_item($task_id);
     wp_delete_post($task_id, $force);
 }
Пример #13
0
<?php

$pro_obj = CPM_Project::getInstance();
$project = $pro_obj->get($project_id);
if (!$project) {
    echo '<h2>' . __('Error: Project not found', 'cpm') . '</h2>';
    die;
}
if (!$pro_obj->has_permission($project)) {
    echo '<h2>' . __('Error: Permission denied', 'cpm') . '</h2>';
    die;
}
?>
<div class="cpm-project-head">
    <div class="cpm-project-detail">
        <h2>
            <span class="cpm-project-title"><?php 
echo get_the_title($project_id);
?>
</span>

            <?php 
if (cpm_user_can_access($project_id)) {
    ?>
                <a href="#" class="cpm-icon-edit cpm-project-edit-link"><span class="dashicons dashicons-edit"></span> <span class="text"><?php 
    _e('Edit', 'cpm');
    ?>
</span></a>
            <?php 
}
?>
Пример #14
0
/**
 * Serve project files with proxy
 *
 * This function handles project files for privacy. It gets the file ID
 * and project ID as input. Checks if the current user has access on that
 * project and serves the attached file with right header type. If the
 * request is not from a user from this project, s/he will not be able to
 * see the file.
 *
 * @uses `wp_ajax_cpm_file_get` action
 * @since 0.3
 */
function cpm_serve_file()
{
    $file_id = isset($_GET['file_id']) ? intval($_GET['file_id']) : 0;
    $project_id = isset($_GET['project_id']) ? intval($_GET['project_id']) : 0;
    $type = isset($_GET['type']) ? $_GET['type'] : 'full';
    //check permission
    $pro_obj = CPM_Project::getInstance();
    $project = $pro_obj->get($project_id);
    if (!$pro_obj->has_permission($project)) {
        die('file access denied');
    }
    //get file path
    $file_path = get_attached_file($file_id);
    if (!file_exists($file_path)) {
        header("Status: 404 Not Found");
        die('file not found');
    }
    if ($type == 'thumb') {
        $metadata = wp_get_attachment_metadata($file_id);
        $filename = basename($file_path);
        //if thumbnail is found, replace file name with thumb file name
        if (array_key_exists('thumbnail', $metadata['sizes'])) {
            $file_path = str_replace($filename, $metadata['sizes']['thumbnail']['file'], $file_path);
        }
    }
    $extension = strtolower(substr(strrchr($file_path, '.'), 1));
    // get the file mime type using the file extension
    switch ($extension) {
        case 'jpeg':
        case 'jpg':
            $mime = 'image/jpeg';
            break;
        case 'png':
            $mime = 'image/png';
            break;
        case 'gif':
            $mime = 'image/gif';
            break;
        case 'bmp':
            $mime = 'image/bmp';
            break;
        default:
            $mime = 'application/force-download';
    }
    // serve the file with right header
    if (is_readable($file_path)) {
        header('Content-Type: ' . $mime);
        header('Content-Transfer-Encoding: binary');
        header('Content-Disposition: inline; filename=' . basename($file_path));
        readfile($file_path);
    }
    exit;
}
/**
 * Insert task type item
 *
 * @param init $item_id
 * @param init $task_list_id
 *
 * @since 1.1
 *
 * @return type
 */
function cpm_insert_tasks($project_id, $task_list_id)
{
    global $wpdb;
    $table_name = $wpdb->prefix . 'cpm_tasks';
    $tasks = CPM_Task::getInstance()->get_tasks($task_list_id, true);
    foreach ($tasks as $task) {
        $complete = $task->completed ? $task->completed_on : '0000-00-00 00:00:00';
        CPM_Project::getInstance()->new_project_item($project_id, $task->ID, $task->task_privacy, 'task', false, $complete, $task->completed, $task_list_id);
        $last_insert_id = $wpdb->insert_id;
        if (count($task->assigned_to)) {
            foreach ($task->assigned_to as $assigned) {
                if ($last_insert_id) {
                    $data = array('item_id' => $last_insert_id, 'user_id' => $assigned, 'start' => isset($task->start_date) && $task->start_date ? $task->start_date : $task->post_date, 'due' => $task->due_date ? $task->due_date : '0000-00-00 00:00:00');
                    $wpdb->insert($table_name, $data, array('%d', '%d', '%s', '%s'));
                }
            }
        } else {
            if ($last_insert_id) {
                $data = array('item_id' => $last_insert_id, 'user_id' => -1, 'start' => isset($task->start_date) && $task->start_date ? $task->start_date : $task->post_date, 'due' => $task->due_date ? $task->due_date : '0000-00-00 00:00:00');
                $wpdb->insert($table_name, $data, array('%d', '%d', '%s', '%s'));
            }
        }
    }
}
Пример #16
0
 /**
  * Instantiate all the required classes
  *
  * @since 0.1
  */
 function instantiate()
 {
     $this->project = CPM_Project::getInstance();
     $this->message = CPM_Message::getInstance();
     $this->task = CPM_Task::getInstance();
     $this->milestone = CPM_Milestone::getInstance();
     $this->activity = CPM_Activity::getInstance();
     $this->ajax = CPM_Ajax::getInstance();
     $this->notification = CPM_Notification::getInstance();
     if (function_exists('json_api_init')) {
         $this->api = CPM_API::instance();
     }
     // instantiate admin settings only on admin page
     if (is_admin()) {
         $this->admin = new CPM_Admin();
         $this->upgrade = new CPM_Upgrade();
     }
     do_action('cpm_instantiate', $this);
 }
Пример #17
0
 function delete($message_id, $force = false)
 {
     do_action('cpm_message_delete', $message_id, $force);
     CPM_Project::getInstance()->delete_project_item($message_id);
     wp_delete_post($message_id, $force);
 }
Пример #18
0
 function log($post_id, $message)
 {
     $user = wp_get_current_user();
     $commentdata = array('comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_agent' => substr($_SERVER['HTTP_USER_AGENT'], 0, 254), 'comment_type' => 'cpm_activity', 'comment_content' => $message, 'comment_post_ID' => $post_id, 'user_id' => $user->ID, 'comment_author' => $user->display_name, 'comment_author_email' => $user->user_email);
     wp_insert_comment($commentdata);
     //flush the project cache for new information
     CPM_Project::getInstance()->flush_cache($post_id);
 }
Пример #19
0
 function project_delete()
 {
     $posted = $_POST;
     $project_id = isset($posted['project_id']) ? intval($posted['project_id']) : 0;
     do_action('cpm_delete_project_prev', $project_id);
     CPM_Project::getInstance()->delete($project_id, true);
     do_action('cpm_delete_project_after', $project_id);
     echo json_encode(array('success' => true, 'url' => $_POST['url']));
     exit;
 }
Пример #20
0
 function insert_duplicate($args, $project_id, $new_milestone_id = array())
 {
     global $wpdb;
     /*
      * insert the post by wp_insert_post() function
      */
     $new_post_id = wp_insert_post($args);
     /*
      * get all current post terms ad set them to the new post draft
      */
     $taxonomies = get_object_taxonomies($args['post_type']);
     // returns array of taxonomy names for post type, ex array("category", "post_tag");
     foreach ($taxonomies as $taxonomy) {
         $post_terms = wp_get_object_terms($project_id, $taxonomy, array('fields' => 'slugs'));
         wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
     }
     /*
      * duplicate all post meta
      */
     $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id={$project_id}");
     if (count($post_meta_infos) != 0) {
         $sql_query = "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) ";
         foreach ($post_meta_infos as $meta_info) {
             $meta_key = $meta_info->meta_key;
             $meta_value = addslashes($meta_info->meta_value);
             if ($meta_key == '_milestone' && ($args['post_type'] == 'task_list' || $args['post_type'] == 'message')) {
                 $meta_info->meta_value = isset($new_milestone_id[$meta_info->meta_value]) ? $new_milestone_id[$meta_info->meta_value] : '';
                 $meta_value = addslashes($meta_info->meta_value);
             }
             $sql_query_sel[] = "SELECT {$new_post_id}, '{$meta_key}', '{$meta_value}'";
         }
         $sql_query .= implode(" UNION ALL ", $sql_query_sel);
         $wpdb->query($sql_query);
     }
     if ($args['post_type'] == 'project') {
         $get_all_user = CPM_Project::getInstance()->get_users($project_id);
         if (is_array($get_all_user) && count($get_all_user)) {
             foreach ($get_all_user as $user_id => $role_meta) {
                 CPM_Project::getInstance()->insert_user($new_post_id, $user_id, $role_meta['role']);
             }
         }
     }
     return $new_post_id;
 }
<?php

if (isset($_POST['project_notify']) && $_POST['project_notify'] == 'yes') {
    $project_users = CPM_Project::getInstance()->get_users($project_id);
    $users = array();
    if (is_array($project_users) && count($project_users)) {
        foreach ($project_users as $user_id => $role_array) {
            if ($this->filter_email($user_id)) {
                $users[$user_id] = sprintf('%s', $role_array['email']);
                // $users[$user_id] = sprintf( '%s (%s)', $role_array['name'], $role_array['email'] );
            }
        }
    }
    //if any users left, get their mail addresses and send mail
    if (!$users) {
        return;
    }
    cpm_get_email_header();
    $tpbk = CPM_URL . '/assets/images/tpbk.png';
    $author = wp_get_current_user();
    ?>

    <div style="width:600px;  background: #fff;">


            <div style="width: 600px;">
                <div style="background-image: url('<?php 
    echo $tpbk;
    ?>
'); background-repeat: no-repeat; height: 174px; width: 600px;">
                <div style="font-family: 'Lato', sans-serif; font-wight: bold; color: #fff; font-size: 30px; padding-top: 26px; text-align: center;">
Пример #22
0
    /**
     * Display activities for a project
     *
     * @since 1.0
     * @param int $project_id
     */
    function project_activity($project_id)
    {
        $pro_obj = CPM_Project::getInstance();
        ?>
        <ul class="cpm-activity dash">
            <?php 
        $count = get_comment_count($project_id);
        $activities = $pro_obj->get_activity($project_id, array());
        if ($activities) {
            echo cpm_activity_html($activities);
        }
        ?>
        </ul>

        <?php 
        if ($count['approved'] > count($activities)) {
            ?>
            <a href="#" <?php 
            cpm_data_attr(array('project_id' => $project_id, 'start' => count($activities) + 1, 'total' => $count['approved']));
            ?>
 class="button cpm-load-more"><?php 
            _e('Load More...', 'cpm');
            ?>
</a>
        <?php 
        }
        ?>

        <?php 
    }