add_cap('active_menu_access'); //access pages
$admin->add_cap('active_menu_access'); //access pages
}
function a_collab_styles(){
wp_enqueue_style( 'bootstrap-css', plugins_url('assets/css/bootstrap.css', __FILE__));
wp_enqueue_style( 'custom-css', plugins_url('assets/css/custom.css', __FILE__));
}
function a_collab_custom_scripts(){
wp_enqueue_style( 'main-css', plugins_url('assets/css/main.css', __FILE__));
wp_enqueue_script('jquery-validate',plugins_url('assets/js/jquery.validate.min.js',__FILE__),array(),true,false);
wp_register_script('main-js',plugins_url('assets/js/main.js', __FILE__),array(),true,false);
wp_enqueue_script('main-js');
wp_localize_script( 'main-js', 'ajax_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' )) );
}
function a_collab_scripts(){
wp_register_script('bootstrap-js',plugins_url('assets/js/bootstrap.min.js', __FILE__),array(),true,false);
wp_enqueue_script('bootstrap-js');
wp_register_script('script-js',plugins_url('assets/js/script.js', __FILE__),array(),true,false);
wp_enqueue_script('script-js');
wp_localize_script( 'script-js', 'ajax_object',
array( 'ajax_url' => admin_url( 'admin-ajax.php' )) );
}
function a_toolbar_link_page($wp_admin_bar){
$args = array(
'id' => 'active_collab',
'title' => 'Active Collab',
'href' => admin_url('admin.php?page=a_collab_menu_slug'),
'meta' => array( 'class' => 'my-toolbar-page' )
);
$wp_admin_bar->add_node( $args );
$args = array(
'parent' => 'active_collab',
'id' => 'activecollab-setting',
'title' => 'Settings',
'href' => esc_url( admin_url( 'admin.php?page=a_collab_menu_settings' ) ),
'meta' => false
);
$wp_admin_bar->add_node( $args );
}
/**
* @return [type]
* Active Collab API Integration
*/
function a_collab_menu_page(){
$userId = get_current_user_id();
$optionName = 'active_collab_setting_'.$userId; //generating settings name
$option_exists = (get_option($optionName, null) !== null);
if($option_exists){
?>
get('projects/'.$token['1'])->getJson();
$user = $token['2'];
$token_Id = explode("-",$token['0']->getToken());//userid
}
?>
Active Collab -- --
get('projects/'.$token['1'].'/tasks')->getJson();
$taskarray = array();
foreach ($taskList['tasks'] as $tsklist) {
$taskarray[$tsklist['name']]['taskid'] = $tsklist['task_list_id'];
$taskarray[$tsklist['name']]['label'] = $tsklist['labels'][0]['name'];
$taskarray[$tsklist['name']]['color'] = $tsklist['labels'][0]['color'];
$taskarray[$tsklist['name']]['assignee_name'] = $tsklist['fake_assignee_name'];
$taskarray[$tsklist['name']]['open_sub_task'] = $tsklist['open_subtasks'];
$taskarray[$tsklist['name']]['url_path'] = $tsklist['url_path'];
$taskarray[$tsklist['name']]['close_sub_task'] = $tsklist['completed_subtasks'];
$taskarray[$tsklist['name']]['job_type_id'] = $tsklist['job_type_id'];
$taskarray[$tsklist['name']]['id'] = $tsklist['id'];
$taskarray[$tsklist['name']]['comments_count'] = $tsklist['comments_count'];
$taskarray[$tsklist['name']]['created_by_name'] = $tsklist['created_by_name'];
$taskarray[$tsklist['name']]['created_by_email'] = $tsklist['created_by_email'];
}
foreach ($taskList['task_lists'] as $list) {
?>
$value) {
if($value['taskid'] == $task_list_id){
$value['id']."taskid";
$url_path = "'".$value['url_path']."'";
$taskclass = str_replace(' ', '-', strtolower($key));
if(!empty($value['assignee_name'])){
$assignee = $value['assignee_name'];
}
if(!empty($value['created_by_name'])){
$created_by_name = $value['created_by_name'];
}
echo '';
echo ''.$key.'-'.$created_by_name.'';
echo '';
if(!empty($value['label'])){
echo ''.$value['label'].'';
}
if(!empty($value['open_sub_task'])){
echo '';
echo ''.$value['open_sub_task'].'';
}
if(!empty($value['close_sub_task'])){
echo '';
echo ''.$value['close_sub_task'].'';
}
if(!empty($value['comments_count'])){
echo '';
echo ''.$value['comments_count'].'';
}
echo '
';
}
}
?>
Update/Create Active Collab Settings
$taskListName,
);
$token = self::a_configuration_settings();
if($token){
$client = new \ActiveCollab\SDK\Client($token['0']);
$taskList = $client->post('/projects/'.$token['1'].'/task-lists',$params);
if($taskList){
print_r($taskList);
}
}
die();
}
/**
* Add Task List to Task
*/
function a_AddTaskToList(){
$taskName = sanitize_text_field($_POST['taskName']);
$taskList = sanitize_text_field($_POST['taskList']);
$taskAssign = sanitize_text_field($_POST['taskAssign']);
$taskLabel = sanitize_text_field($_POST['taskLabel']);
$taskDescription = sanitize_text_field($_POST['taskDescription']);
$token = self::a_configuration_settings();
if($token){
$client = new \ActiveCollab\SDK\Client($token['0']);
$taskLabelParams = $client->get('/labels/'.$taskLabel)->getJson();
//print_r($taskLabelParams);
$params = array(
"name" => $taskName,
"task_list_id" => $taskList,
"assignee_id" => $taskAssign,
"body" => $taskDescription,
"labels" => array(
"name" => $taskLabelParams['single']['name'],
)
);
$task = $client->post('/projects/'.$token['1'].'/tasks',$params);
if($task){
}
}
die();
}
/**
* Add Subtask To Task
*/
function a_AddSubTaskToList(){
$subTaskName = sanitize_text_field($_POST['subTaskName']);
$subTaskAssignId = sanitize_text_field($_POST['subTaskAssignId']);
$parentTaskId = sanitize_text_field($_POST['parentTaskId']);
$params = array(
"body" => $subTaskName,
"assignee_id" => $subTaskAssignId
);
$token = self::a_configuration_settings();
if($token){
$client = new \ActiveCollab\SDK\Client($token['0']);
$subtask = $client->post('/projects/'.$token['1'].'/tasks/'.$parentTaskId.'/subtasks',$params);
if($subtask){
}
}
die();
}
/**
* Log Time Record
*/
function a_registerTime(){
$projectId = sanitize_text_field($_POST['projectId']);
$userId = sanitize_text_field($_POST['userId']);
$taskId = sanitize_text_field($_POST['taskId']);
$time = sanitize_text_field($_POST['time']);
$description = sanitize_text_field($_POST['description']);
$jobId = sanitize_text_field($_POST['jobId']);
$token = self::a_configuration_settings();
$date = date("Y-m-d");
$params = array(
"task_id" => $taskId,
"value" => $time,
"user_id" => $userId,
"job_type_id" => $jobId,
"record_date" => $date,
"summary" => $description
);
if($token){
$client = new \ActiveCollab\SDK\Client($token['0']);
$logTime = $client->post('/projects/'.$projectId.'/time-records',$params);
if($logTime){
//print_r($logTime);
}
}
die();
}
/**
* Task List Details view
*/
function a_TaskListByDetailsId(){
$id = sanitize_text_field($_POST['id']);
$urlPath = sanitize_text_field($_POST['urlPath']);
$projectId = sanitize_text_field($_POST['projectId']);
$userId = sanitize_text_field($_POST['userId']);
$taskId = sanitize_text_field($_POST['taskId']);
$token = self::a_configuration_settings();
if($token){
$client = new \ActiveCollab\SDK\Client($token['0']);
$subtask_List = $client->get($urlPath)->getJson();
$time_records = $client->get('/projects/'.$projectId.'/tasks/'.$taskId.'/time-records')->getJson();
}
$totalTimeSpend = self::getTotalTimeRecordsByTask($time_records['time_records']);
$subtaskArray = array();
$commentsArray = array();
echo '';
echo $subtask_List['single']['name'];
if(!empty($totalTimeSpend)){
echo '('.$totalTimeSpend.'Hours)';
}
echo '
';
if(!empty($subtask_List['single']['body'])){
echo ''.$subtask_List['single']['body'].'
';
}
if(!empty($subtask_List['subtasks'])){
if(!empty($subtask_List['single']['open_subtasks'])){
echo 'Sub Tasks
';
echo '';
self::subtask_open($subtask_List['subtasks']);//opensubtask
echo '
';
}
if(!empty($subtask_List['single']['completed_subtasks'])){
echo 'Closed Tasks ('.$subtask_List['single']['completed_subtasks'].')';
echo '';
self::subtask_close($subtask_List['subtasks']);//closedsubtask
echo '
';
}
}
if(!empty($subtask_List['comments'])){
self::subtasks_comments($subtask_List['comments']);//discussion
}
?>
'.$slist['name'].'';
}
}
}
private function subtask_close($subtask_List){
//echo '' . print_r($subtask_List, true) . '
';
foreach ($subtask_List as $slist) {
if($slist['is_completed'] != ''){
echo ''.$slist['name'].'';
}
}
}
private function subtasks_comments($comments){
echo '';
echo '
Discussion
';
echo '';
echo '';
}
private function a_configuration_settings(){
global $wpdb;
$userId = get_current_user_id();
$optionName = 'active_collab_setting_'.$userId;
$settings =get_option($optionName, false);
if($settings){
$active_Unserilizedarry = unserialize($settings);
$authenticator = new \ActiveCollab\SDK\Authenticator\Cloud($active_Unserilizedarry['2'], 'My Awesome Application',$active_Unserilizedarry['3'],$active_Unserilizedarry['4']);
try{
$token = $authenticator->issueToken((int) $active_Unserilizedarry['1']);
if($token){
$user = $authenticator->getUser();
return array($token,$active_Unserilizedarry['5'],$user);
}
else{
print "Invalid response\n";
die();
}
}
catch(Exception $e){
echo $e->getMessage();
}
}
else{
echo "Update/Create Active Collab Settings";
}
}
//jobtypes
private function jobtypes($job_types,$current_job_id){
echo '';
foreach ($job_types as $jobs) {
?>
Choose Assignee';
foreach ($allMembers as $users) {
?>
';
foreach ($time_records as $time) {
echo '';
echo '
'.gmdate('M-d.Y', $time['record_date']).'
';
echo '
'.$time['value'].'
';
echo '
'.$time['created_by_name'].'
';
echo '
'.$time['summary'].'
';
echo '
';
}
echo '';
}
private function getTotalTimeRecordsByTask($time_records){
$total_time_records = array();
foreach ($time_records as $time) {
$total_time_records[] = $time['value'];
}
return array_sum($total_time_records);
}
private function getUserAvatar($userid){
$token = self::a_configuration_settings();
if($token){
$client = new \ActiveCollab\SDK\Client($token['0']);
$avatar_url = $client->get('users/'.$user_id)->getJson();
foreach ($avatar_url as $avatar) {
return $avatar['avatar_url'];
}
}
}
private function getProjectAllLabels($alllabels){
echo '';
foreach ($alllabels as $labels) {
?>
Choose Task List';
foreach ($allTaskList as $tList) {
?>
'.$cmts['created_by_email'].''; echo ''.gmdate('r', $cmts['updated_on']).''; //date and time echo '
'; echo ''.$cmts['body_formatted'].'
'; if(!empty($cmts['attachments'])){ //print_r($cmts['attachments']); foreach ($cmts['attachments'] as $value) { ?>Download
'; } echo '