| @@ -1,1214 +1,1392 @@ | ||
| 1 | -<?php | |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - exit; // Exit if accessed directly | |
| 4 | -} | |
| 5 | -if ( ! class_exists( 'WPPM_Functions' ) ) : | |
| 6 | - final class WPPM_Functions { | |
| 7 | - // Array sanitization | |
| 8 | - public static function sanitize_array($array) { | |
| 9 | - if(!empty($array)){ | |
| 10 | - foreach ( $array as $key => $value ) { | |
| 11 | - if ( is_array( $value ) ) { | |
| 12 | - $value = $this->sanitize_array($value); | |
| 13 | - } | |
| 14 | - else { | |
| 15 | - $value = sanitize_text_field( wp_unslash( $value ) ); | |
| 16 | - } | |
| 17 | - } | |
| 18 | - } | |
| 19 | - return $array; | |
| 20 | - } | |
| 21 | - | |
| 22 | - public static function create_project($args){ | |
| 23 | - global $wpdb,$current_user; | |
| 24 | - $default_proj_status = get_option('wppm_default_project_status'); | |
| 25 | - $values = array( | |
| 26 | - 'created_by'=>$current_user->ID, | |
| 27 | - 'project_name'=>$args['name'], | |
| 28 | - 'description'=>isset($args['wppm_proj_description']) ? $args['wppm_proj_description']:"", | |
| 29 | - 'start_date'=>isset($args['wppm_start_date']) ?$args['wppm_start_date']:"", | |
| 30 | - 'end_date'=>isset($args['wppm_end_date'])? $args['wppm_end_date']:"", | |
| 31 | - 'status'=>isset($args['status'])? $args['status']:$default_proj_status, | |
| 32 | - 'cat_id'=>isset($args['wppm_create_project_category']) ? $args['wppm_create_project_category']:"", | |
| 33 | - 'users'=>isset($args['user_names']) ? implode(",",$args['user_names']):"", | |
| 34 | - 'date_created'=>isset($args['date_created'])? $args['date_created']:wp_date("Y-m-d h:i:sa"), | |
| 35 | - ); | |
| 36 | - $wpdb->insert($wpdb->prefix .'wppm_project', $values); | |
| 37 | - $project_id = $wpdb->insert_id; | |
| 38 | - return $project_id; | |
| 39 | - } | |
| 40 | - | |
| 41 | - public static function create_task($args){ | |
| 42 | - global $wpdb,$current_user,$wppmfunction; | |
| 43 | - $default_task_status = get_option('wppm_default_task_status'); | |
| 44 | - $values = array( | |
| 45 | - 'created_by'=>(isset($args['created_by'])) ? $args['created_by']: $current_user->ID, | |
| 46 | - 'task_name'=>$args['name'], | |
| 47 | - 'description'=>(isset($args['wppm_task_description']))?$args['wppm_task_description']:"", | |
| 48 | - 'project'=>(isset($args['wppm_task_project']))?$args['wppm_task_project']:"", | |
| 49 | - 'start_date'=>(isset($args['wppm_task_start_date']))?$args['wppm_task_start_date']:"", | |
| 50 | - 'end_date'=>(isset($args['wppm_task_end_date']))?$args['wppm_task_end_date']:"", | |
| 51 | - 'status'=>(isset($args['status']))?$args['status']:$default_task_status, | |
| 52 | - 'priority'=>(isset($args['wppm_create_task_priority']))?$args['wppm_create_task_priority']:"", | |
| 53 | - 'users'=>(!empty($args['user_names']))?implode(",",$args['user_names']):"", | |
| 54 | - 'date_created'=>isset($args['date_created'])? $args['date_created']:wp_date("Y-m-d h:i:sa"), | |
| 55 | - 'task_auth_code'=> $wppmfunction->getRandomString(10), | |
| 56 | - 'active'=>1 | |
| 57 | - ); | |
| 58 | - $wpdb->insert($wpdb->prefix .'wppm_task', $values); | |
| 59 | - $task_id = $wpdb->insert_id; | |
| 60 | - return $task_id; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public static function create_checklist($args){ | |
| 64 | - global $wpdb,$current_user,$wppmfunction; | |
| 65 | - $values = array( | |
| 66 | - 'task_id'=>$args['task_id'], | |
| 67 | - 'checklist_name' => $args['checklist_name'], | |
| 68 | - 'created_by'=> $args['created_by'] | |
| 69 | - ); | |
| 70 | - $wpdb->insert($wpdb->prefix .'wppm_checklist', $values); | |
| 71 | - $checklist_id = $wpdb->insert_id; | |
| 72 | - return $checklist_id; | |
| 73 | - } | |
| 74 | - | |
| 75 | - public static function create_checklist_item($args){ | |
| 76 | - global $wpdb,$current_user,$wppmfunction; | |
| 77 | - $chk_items_values = array( | |
| 78 | - 'checklist_id' => $args['checklist_id'], | |
| 79 | - 'item_name' => $args['item_name'], | |
| 80 | - 'checked'=>$args['checked'], | |
| 81 | - 'members'=>$args['members'], | |
| 82 | - 'due_date'=> $args['due_date'] | |
| 83 | - ); | |
| 84 | - $wpdb->insert($wpdb->prefix .'wppm_checklist_items', $chk_items_values); | |
| 85 | - $checklist_item_id = $wpdb->insert_id; | |
| 86 | - return $checklist_item_id; | |
| 87 | - } | |
| 88 | - | |
| 89 | - public static function wppm_submit_task_comment($args){ | |
| 90 | - global $wpdb; | |
| 91 | - $wpdb->insert($wpdb->prefix.'wppm_task_comment',$args); | |
| 92 | - $comment_id = $wpdb->insert_id; | |
| 93 | - return $comment_id; | |
| 94 | - } | |
| 95 | - | |
| 96 | - public static function wppm_submit_task_comment_meta($args){ | |
| 97 | - global $wpdb; | |
| 98 | - $wpdb->insert($wpdb->prefix.'wppm_task_comment_meta',$args); | |
| 99 | - $comment_meta_id = $wpdb->insert_id; | |
| 100 | - return $comment_meta_id; | |
| 101 | - } | |
| 102 | - | |
| 103 | - public static function wppm_submit_proj_comment($args){ | |
| 104 | - global $wpdb; | |
| 105 | - $wpdb->insert($wpdb->prefix.'wppm_project_comment',$args); | |
| 106 | - $comment_id = $wpdb->insert_id; | |
| 107 | - return $comment_id; | |
| 108 | - } | |
| 109 | - | |
| 110 | - public static function wppm_submit_proj_comment_meta($args){ | |
| 111 | - global $wpdb; | |
| 112 | - $wpdb->insert($wpdb->prefix.'wppm_project_comment_meta',$args); | |
| 113 | - $comment_meta_id = $wpdb->insert_id; | |
| 114 | - return $comment_meta_id; | |
| 115 | - } | |
| 116 | - | |
| 117 | - // Random string | |
| 118 | - public static function getRandomString($length = 8) { | |
| 119 | - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
| 120 | - $string = ''; | |
| 121 | - for ($i = 0; $i < $length; $i++) { | |
| 122 | - $string .= $characters[wp_rand(0, strlen($characters) - 1)]; | |
| 123 | - } | |
| 124 | - return $string; | |
| 125 | - } | |
| 126 | - | |
| 127 | - public static function wppm_get_auth_code($id){ | |
| 128 | - global $wpdb; | |
| 129 | - $id = absint($id); | |
| 130 | - $auth_code = $wpdb->get_var( | |
| 131 | - $wpdb->prepare( | |
| 132 | - "SELECT task_auth_code | |
| 133 | - FROM {$wpdb->prefix}wppm_task | |
| 134 | - WHERE id = %d", | |
| 135 | - ($id) | |
| 136 | - ) | |
| 137 | - ); | |
| 138 | - $auth_code = isset($auth_code) ? $auth_code : ""; | |
| 139 | - return $auth_code; | |
| 140 | - } | |
| 141 | - | |
| 142 | - public static function get_task_fields($task_id,$select_field){ | |
| 143 | - global $wpdb; | |
| 144 | - $task_id = absint($task_id); | |
| 145 | - $task_field_value = ''; | |
| 146 | - $allowed_fields = array( | |
| 147 | - 'id', | |
| 148 | - 'created_by', | |
| 149 | - 'task_name', | |
| 150 | - 'description', | |
| 151 | - 'project', | |
| 152 | - 'start_date', | |
| 153 | - 'end_date', | |
| 154 | - 'status', | |
| 155 | - 'priority', | |
| 156 | - 'users', | |
| 157 | - 'date_created', | |
| 158 | - 'task_auth_code' | |
| 159 | - ); | |
| 160 | - | |
| 161 | - // Validate column name | |
| 162 | - if ( ! in_array( $select_field, $allowed_fields, true ) ) { | |
| 163 | - return ''; | |
| 164 | - } | |
| 165 | - if (apply_filters('wppm_get_select_field',true,$task_id,$select_field)) { | |
| 166 | - $get_task_field_value = $wpdb->get_var($wpdb->prepare("SELECT $select_field FROM {$wpdb->prefix}wppm_task WHERE id = %d", $task_id)); | |
| 167 | - $task_field_value = $get_task_field_value ? $get_task_field_value : ''; | |
| 168 | - } | |
| 169 | - return stripslashes($task_field_value); | |
| 170 | - } | |
| 171 | - | |
| 172 | - public static function get_project_fields($proj_id,$select_field){ | |
| 173 | - global $wpdb; | |
| 174 | - $proj_id = absint($proj_id); | |
| 175 | - $project_field_value = ''; | |
| 176 | - $allowed_fields = array( | |
| 177 | - 'id', | |
| 178 | - 'created_by', | |
| 179 | - 'project_name', | |
| 180 | - 'description', | |
| 181 | - 'start_date', | |
| 182 | - 'end_date', | |
| 183 | - 'status', | |
| 184 | - 'cat_id', | |
| 185 | - 'users', | |
| 186 | - 'date_created' | |
| 187 | - ); | |
| 188 | - | |
| 189 | - // Validate column name | |
| 190 | - if ( ! in_array( $select_field, $allowed_fields, true ) ) { | |
| 191 | - return ''; | |
| 192 | - } | |
| 193 | - if (apply_filters('wppm_get_select_proj_field',true,$proj_id,$select_field)) { | |
| 194 | - $get_project_field_value = $wpdb->get_var($wpdb->prepare("SELECT $select_field FROM {$wpdb->prefix}wppm_project WHERE id = %d", $proj_id)); | |
| 195 | - $project_field_value = $get_project_field_value ? $get_project_field_value : ''; | |
| 196 | - } | |
| 197 | - return stripslashes($project_field_value); | |
| 198 | - } | |
| 199 | - | |
| 200 | - public function get_task($task_id){ | |
| 201 | - global $wpdb; | |
| 202 | - $task_data = array(); | |
| 203 | - $task_id = absint($task_id); | |
| 204 | - $task = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task WHERE id = %d", $task_id)); | |
| 205 | - if( $task ){ | |
| 206 | - $task_data = json_decode(wp_json_encode($task), true); | |
| 207 | - } | |
| 208 | - return $task_data; | |
| 209 | - } | |
| 210 | - | |
| 211 | - public function get_checklist($task_id){ | |
| 212 | - global $wpdb; | |
| 213 | - $task_id = absint($task_id); | |
| 214 | - $checklist_data = array(); | |
| 215 | - $checklist = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d", $task_id)); | |
| 216 | - if( $checklist ){ | |
| 217 | - $checklist_data = json_decode(wp_json_encode($checklist), true); | |
| 218 | - } | |
| 219 | - return $checklist_data; | |
| 220 | - } | |
| 221 | - | |
| 222 | - public function get_checklist_items($checklist_id){ | |
| 223 | - global $wpdb; | |
| 224 | - $checklist_items_data = array(); | |
| 225 | - $checklist_id = absint($checklist_id); | |
| 226 | - $checklist_items = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = %d", $checklist_id)); | |
| 227 | - if( $checklist_items ){ | |
| 228 | - $checklist_items_data = json_decode(wp_json_encode($checklist_items), true); | |
| 229 | - } | |
| 230 | - return $checklist_items_data; | |
| 231 | - } | |
| 232 | - | |
| 233 | - public function get_project($project_id){ | |
| 234 | - global $wpdb; | |
| 235 | - $project_data = array(); | |
| 236 | - $project_id = absint($project_id); | |
| 237 | - $project = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 238 | - if( $project ){ | |
| 239 | - $project_data = json_decode(wp_json_encode($project), true); | |
| 240 | - } | |
| 241 | - return $project_data; | |
| 242 | - } | |
| 243 | - | |
| 244 | - public function get_attachment($attachment_id){ | |
| 245 | - global $wpdb; | |
| 246 | - $attachment_data = array(); | |
| 247 | - $attachment_id = absint($attachment_id); | |
| 248 | - $attachment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id)); | |
| 249 | - if( $attachment ){ | |
| 250 | - $attachment_data = json_decode(wp_json_encode($attachment), true); | |
| 251 | - } | |
| 252 | - return $attachment_data; | |
| 253 | - } | |
| 254 | - | |
| 255 | - public function has_permission($permission, $task_id){ | |
| 256 | - global $current_user,$wppmfunction,$wpdb; | |
| 257 | - $task_id = absint($task_id); | |
| 258 | - $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 259 | - $wppm_edit_tasks_permission = get_option('wppm_default_edit_tasks_permission'); | |
| 260 | - $wppm_allow_coworkers_add_checklist = get_option('wppm_allow_coworkers_add_checklist'); | |
| 261 | - $wppm_allow_coworkers_create_task = get_option('wppm_allow_coworkers_create_task'); | |
| 262 | - $wppm_allow_coworkers_change_status = get_option('wppm_allow_coworkers_change_status'); | |
| 263 | - $wppm_allow_coworkers_assign_users = get_option('wppm_allow_coworkers_assign_users'); | |
| 264 | - if(empty($comment_id)){ | |
| 265 | - $comment_id = 0; | |
| 266 | - } | |
| 267 | - $comment_id = absint($comment_id); | |
| 268 | - $task_data = $wppmfunction->get_task($task_id); | |
| 269 | - $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d AND id = %d", $task_id, $comment_id)); | |
| 270 | - | |
| 271 | - if(!empty($task_data['project'])){ | |
| 272 | - $project_id = $task_data['project']; | |
| 273 | - $project_id = absint($project_id); | |
| 274 | - $project_data = $wppmfunction->get_project($project_id); | |
| 275 | - $cu_user_id = absint($current_user->ID); | |
| 276 | - $project_user_role = $wpdb->get_var($wpdb->prepare("SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $project_id, $cu_user_id)); | |
| 277 | - $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 278 | - $project_users_arr = explode(',',(string)$project_users); | |
| 279 | - } | |
| 280 | - $response = false; | |
| 281 | - $flag = false; | |
| 282 | - if(!empty($task_data)){ | |
| 283 | - $co_worker = $task_data['users']; | |
| 284 | - $co_worker_array = explode(",",(string)$co_worker); | |
| 285 | - } | |
| 286 | - if((!empty($project_user_role)) && ($project_user_role == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 287 | - $flag= true; | |
| 288 | - } | |
| 289 | - if($wppm_current_user_capability=='wppm_admin'){ | |
| 290 | - $flag = true; | |
| 291 | - } | |
| 292 | - if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){ | |
| 293 | - $flag = true; | |
| 294 | - } | |
| 295 | - if(!empty($project_id)){ | |
| 296 | - $project_id = absint($project_id); | |
| 297 | - $public_proj_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta where project_id= %d AND meta_key='public_project'", $project_id)); | |
| 298 | - }else{ | |
| 299 | - $public_proj_meta =""; | |
| 300 | - } | |
| 301 | - switch ($permission) { | |
| 302 | - case 'change_status': | |
| 303 | - case 'view_task': | |
| 304 | - case 'add_task_comment': | |
| 305 | - ((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array )) )|| ($current_user->ID == $task_data['created_by']) || $public_proj_meta==1 || ($flag==true) || $current_user->has_cap('manage_options') ? $response = true: $response = false; | |
| 306 | - break; | |
| 307 | - case 'change_task_details': | |
| 308 | - (($flag==true) || ($current_user->ID == $task_data['created_by']) || $wppm_edit_tasks_permission == 1) ? $response = true: $response = false; | |
| 309 | - break; | |
| 310 | - case 'add_new_task': | |
| 311 | - (($flag==true) || $wppm_allow_coworkers_create_task == 1) ? $response = true: $response = false; | |
| 312 | - break; | |
| 313 | - case 'add_checklist': | |
| 314 | - (($flag==true) || $wppm_allow_coworkers_add_checklist == 1) ? $response = true: $response = false; | |
| 315 | - break; | |
| 316 | - case 'change_task_status': | |
| 317 | - (($flag==true) || $wppm_allow_coworkers_change_status == 1) ? $response = true: $response = false; | |
| 318 | - break; | |
| 319 | - case 'delete_task': | |
| 320 | - case 'clone_task': | |
| 321 | - (($flag==true) || ($current_user->ID == $task_data['created_by'])) ? $response = true: $response = false; | |
| 322 | - break; | |
| 323 | - case 'assign_task_users': | |
| 324 | - (($flag==true) || $wppm_allow_coworkers_assign_users == 1) ? $response = true: $response = false; | |
| 325 | - break; | |
| 326 | - case 'change_raised_by': | |
| 327 | - case 'edit_checklist': | |
| 328 | - case 'delete_checklist': | |
| 329 | - (($flag==true) ? $response = true: $response = false); | |
| 330 | - break; | |
| 331 | - } | |
| 332 | - return apply_filters( 'wppm_has_permission', $response, $task_id, $permission ); | |
| 333 | - } | |
| 334 | - | |
| 335 | - public function has_comment_permission($permission, $task_id,$comment_id){ | |
| 336 | - global $current_user,$wppmfunction,$wpdb; | |
| 337 | - $task_id = absint($task_id); | |
| 338 | - $comment_id = absint($comment_id); | |
| 339 | - $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 340 | - if(empty($comment_id)){ | |
| 341 | - $comment_id = 0; | |
| 342 | - } | |
| 343 | - $task_data = $wppmfunction->get_task($task_id); | |
| 344 | - $project_user = array(); | |
| 345 | - $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d AND id = %d", $task_id, $comment_id)); | |
| 346 | - | |
| 347 | - if(isset($task_data['project'])){ | |
| 348 | - $project_id = $task_data['project']; | |
| 349 | - $project_id = absint($project_id); | |
| 350 | - $cu_id = absint($current_user->ID); | |
| 351 | - $project_data = $wppmfunction->get_project($project_id); | |
| 352 | - $project_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $project_id, $cu_id)); | |
| 353 | - $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 354 | - $project_users_arr = explode(',',(string)$project_users); | |
| 355 | - } | |
| 356 | - $response = false; | |
| 357 | - $flag = false; | |
| 358 | - if(!empty($task_data)){ | |
| 359 | - $co_worker = $task_data['users']; | |
| 360 | - $co_worker_array = explode(",",(string)$co_worker); | |
| 361 | - } | |
| 362 | - if((!empty($project_user)) && ($project_user->role_id == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 363 | - $flag= true; | |
| 364 | - } | |
| 365 | - if($wppm_current_user_capability=='wppm_admin'){ | |
| 366 | - $flag = true; | |
| 367 | - } | |
| 368 | - | |
| 369 | - if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){ | |
| 370 | - $flag = true; | |
| 371 | - } | |
| 372 | - | |
| 373 | - switch ($permission) { | |
| 374 | - case 'delete_task_thread': | |
| 375 | - case 'edit_task_comment': | |
| 376 | - (($flag==true) || ($current_user->ID == $task_comment->created_by)) ? $response = true: $response = false; | |
| 377 | - break; | |
| 378 | - } | |
| 379 | - return apply_filters( 'wppm_has_comment_permission', $response, $task_id, $comment_id, $permission ); | |
| 380 | - } | |
| 381 | - | |
| 382 | - public function has_proj_comment_permission($permission, $proj_id,$comment_id){ | |
| 383 | - global $current_user,$wppmfunction,$wpdb; | |
| 384 | - $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 385 | - $proj_id = absint($proj_id); | |
| 386 | - $comment_id = absint($comment_id); | |
| 387 | - $cu_id = absint($current_user->ID); | |
| 388 | - if(empty($comment_id)){ | |
| 389 | - $comment_id = 0; | |
| 390 | - } | |
| 391 | - $project_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $proj_id, $cu_id)); | |
| 392 | - $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $proj_id)); | |
| 393 | - $project_users_arr = explode(',',(string)$project_users); | |
| 394 | - $proj_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_comment WHERE proj_id = %d AND id = %d", $proj_id, $comment_id)); | |
| 395 | - $response = false; | |
| 396 | - $flag = false; | |
| 397 | - $project_data = $wppmfunction->get_project($proj_id); | |
| 398 | - if((!empty($project_user)) && ($project_user->role_id == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 399 | - $flag= true; | |
| 400 | - } | |
| 401 | - if($wppm_current_user_capability=='wppm_admin'){ | |
| 402 | - $flag = true; | |
| 403 | - } | |
| 404 | - if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){ | |
| 405 | - $flag = true; | |
| 406 | - } | |
| 407 | - switch ($permission) { | |
| 408 | - case 'delete_proj_thread': | |
| 409 | - case 'edit_proj_comment': | |
| 410 | - (($flag==true) || ($current_user->ID == $proj_comment->created_by)) ? $response = true: $response = false; | |
| 411 | - break; | |
| 412 | - } | |
| 413 | - return apply_filters( 'wppm_has_proj_comment_permission', $response, $proj_id, $comment_id, $permission ); | |
| 414 | - } | |
| 415 | - | |
| 416 | - public function has_project_permission($permission,$project_id){ | |
| 417 | - global $current_user,$wppmfunction,$wpdb ; | |
| 418 | - $project_data = $wppmfunction->get_project($project_id); | |
| 419 | - $project_id = absint($project_id); | |
| 420 | - $cu_id = absint($current_user->ID); | |
| 421 | - $project_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $project_id, $cu_id)); | |
| 422 | - $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 423 | - $project_users_arr = explode(',',(string)$project_users); | |
| 424 | - $user = wp_get_current_user(); | |
| 425 | - $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 426 | - if(!empty($project_data)){ | |
| 427 | - $co_worker = $project_data['users']; | |
| 428 | - $co_worker_array = explode(",",(string)$co_worker); | |
| 429 | - } | |
| 430 | - if(!empty($project_id)){ | |
| 431 | - $public_proj_meta = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta where project_id= %d AND meta_key='public_project'", $project_id)); | |
| 432 | - }else{ | |
| 433 | - $public_proj_meta =""; | |
| 434 | - } | |
| 435 | - | |
| 436 | - switch ($permission) { | |
| 437 | - case 'view_project': | |
| 438 | - ((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array )) )? $response = true: $response = false; | |
| 439 | - break; | |
| 440 | - case 'add_proj_comment': | |
| 441 | - ( ((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array )) ) || ( $public_proj_meta == '1') || $current_user->has_cap('manage_options')|| $wppm_current_user_capability == 'wppm_admin' || $wppm_current_user_capability == 'wppm_manager')? $response = true: $response = false; | |
| 442 | - break; | |
| 443 | - case 'change_project_status': | |
| 444 | - case 'assign_project_users': | |
| 445 | - case 'change_project_raised_by': | |
| 446 | - case 'change_project_details': | |
| 447 | - case 'delete_project': | |
| 448 | - $flag = false; | |
| 449 | - if( (!empty($project_user)) && ($project_user->role_id == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 450 | - $flag = true; | |
| 451 | - } | |
| 452 | - | |
| 453 | - (((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array) && $flag==true) || $wppm_current_user_capability == 'wppm_admin')) ? $response = true: $response = false; | |
| 454 | - break; | |
| 455 | - } | |
| 456 | - return apply_filters( 'wppm_has_project_permission', $response, $project_id, $permission ); | |
| 457 | - } | |
| 458 | - | |
| 459 | - public function change_status($task_id, $status_id){ | |
| 460 | - global $wpdb,$wppmfunction; | |
| 461 | - $task_data = $wppmfunction->get_task($task_id); | |
| 462 | - $prev_status = $task_data['status']; | |
| 463 | - $values=array( | |
| 464 | - 'status'=>esc_sql($status_id) | |
| 465 | - ); | |
| 466 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>esc_sql($task_id))); | |
| 467 | - $old_task_status_meta = $wppmfunction->get_task_meta($task_id,'old_task_status',true); | |
| 468 | - if(!empty($old_task_status_meta)){ | |
| 469 | - $wppmfunction->delete_task_meta($task_id,'old_task_status'); | |
| 470 | - } | |
| 471 | - $wppmfunction->add_task_meta($task_id,'old_task_status',$prev_status); | |
| 472 | - | |
| 473 | - do_action('wppm_set_change_task_status', $task_id, $status_id, $prev_status); | |
| 474 | - } | |
| 475 | - | |
| 476 | - public function change_raised_by($task_id, $user_id){ | |
| 477 | - global $wpdb; | |
| 478 | - $values=array( | |
| 479 | - 'created_by'=>absint($user_id) | |
| 480 | - ); | |
| 481 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 482 | - } | |
| 483 | - | |
| 484 | - public function change_task_label($task_id, $task_label){ | |
| 485 | - global $wpdb; | |
| 486 | - $values=array( | |
| 487 | - 'task_name'=>stripslashes($task_label) | |
| 488 | - ); | |
| 489 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 490 | - } | |
| 491 | - | |
| 492 | - public function change_task_project_label($task_id, $project_label){ | |
| 493 | - global $wpdb; | |
| 494 | - $values=array( | |
| 495 | - 'project'=>absint($project_label) | |
| 496 | - ); | |
| 497 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 498 | - } | |
| 499 | - | |
| 500 | - public function change_start_date($task_id, $task_start_date){ | |
| 501 | - global $wpdb; | |
| 502 | - $values=array( | |
| 503 | - 'start_date'=>absint($task_start_date) | |
| 504 | - ); | |
| 505 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 506 | - } | |
| 507 | - | |
| 508 | - public function change_end_date($task_id, $task_end_date){ | |
| 509 | - global $wpdb; | |
| 510 | - $values=array( | |
| 511 | - 'end_date'=>absint($task_end_date) | |
| 512 | - ); | |
| 513 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 514 | - } | |
| 515 | - | |
| 516 | - public function change_priority($task_id, $task_priority){ | |
| 517 | - global $wpdb; | |
| 518 | - $values=array( | |
| 519 | - 'priority'=>absint($task_priority) | |
| 520 | - ); | |
| 521 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 522 | - } | |
| 523 | - | |
| 524 | - public function change_description($task_id, $task_description){ | |
| 525 | - global $wpdb; | |
| 526 | - $task_description = !empty($task_description) ? wp_kses_post($task_description) : ''; | |
| 527 | - $values=array( | |
| 528 | - 'description'=>$task_description | |
| 529 | - ); | |
| 530 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 531 | - } | |
| 532 | - | |
| 533 | - public function change_project($task_id,$proj_id){ | |
| 534 | - global $wpdb,$wppmfunction; | |
| 535 | - $task_data = $wppmfunction->get_task($task_id); | |
| 536 | - $old_proj = $task_data['project']; | |
| 537 | - $old_proj = absint( $old_proj); | |
| 538 | - $proj_id = absint( $proj_id); | |
| 539 | - $project_data = $wppmfunction->get_project($proj_id); | |
| 540 | - $task_assign_users = $task_data['users']; | |
| 541 | - $tusers_array = array(); | |
| 542 | - if(!empty($task_data['users'])){ | |
| 543 | - $task_users_array = explode(",",(string)$task_assign_users); | |
| 544 | - } | |
| 545 | - if(!empty($project_data['users'])){ | |
| 546 | - $project_users = explode(",",(string)$project_data['users']); | |
| 547 | - } | |
| 548 | - if(!empty($project_users)){ | |
| 549 | - if(!empty($task_users_array)){ | |
| 550 | - foreach($task_users_array as $tuser){ | |
| 551 | - if(!in_array($tuser,$project_users)){ | |
| 552 | - $wpdb->delete( $wpdb->prefix.'wppm_project_users', array( 'proj_id' => "$proj_id",'user_id'=>"$tuser") ); | |
| 553 | - } | |
| 554 | - elseif(in_array($tuser,$project_users)){ | |
| 555 | - $tusers_array[] = $tuser; | |
| 556 | - $tuser = absint($tuser); | |
| 557 | - $sql = $wpdb->prepare("SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $old_proj, $tuser); | |
| 558 | - $old_proj_user_role = $wpdb->get_var( $sql ); | |
| 559 | - $sql = $wpdb->prepare("SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $proj_id, $tuser); | |
| 560 | - $proj_users_role = $wpdb->get_var( $sql ); | |
| 561 | - if(!empty( $old_proj_user_role) && $old_proj_user_role!=$proj_users_role){ | |
| 562 | - $value=array( | |
| 563 | - 'role_id'=>absint($proj_users_role) | |
| 564 | - ); | |
| 565 | - $wpdb->update($wpdb->prefix.'wppm_project_users', $value, array('proj_id'=>"$proj_id", 'user_id'=>"$tuser")); | |
| 566 | - } | |
| 567 | - } | |
| 568 | - } | |
| 569 | - } | |
| 570 | - } | |
| 571 | - $tusers = implode(",",$tusers_array); | |
| 572 | - $values=array( | |
| 573 | - 'project'=>absint($proj_id), | |
| 574 | - 'users'=>absint($tusers) | |
| 575 | - ); | |
| 576 | - $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 577 | - } | |
| 578 | - | |
| 579 | - public function get_task_comment($comment_id){ | |
| 580 | - global $wpdb; | |
| 581 | - $task_comment_data = array(); | |
| 582 | - $comment_id = absint($comment_id); | |
| 583 | - $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE id=%d", $comment_id)); | |
| 584 | - if( $task_comment ){ | |
| 585 | - $task_comment_data = json_decode(wp_json_encode($task_comment), true); | |
| 586 | - } | |
| 587 | - return $task_comment_data; | |
| 588 | - } | |
| 589 | - | |
| 590 | - public function get_proj_comment($comment_id){ | |
| 591 | - global $wpdb; | |
| 592 | - $project_comment_data = array(); | |
| 593 | - $comment_id = absint($comment_id); | |
| 594 | - $project_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_comment WHERE id=%d", $comment_id)); | |
| 595 | - if( $project_comment ){ | |
| 596 | - $project_comment_data = json_decode(wp_json_encode($project_comment), true); | |
| 597 | - } | |
| 598 | - return $project_comment_data; | |
| 599 | - } | |
| 600 | - | |
| 601 | - public function change_task_comment($comment_id,$comment_body){ | |
| 602 | - global $wpdb; | |
| 603 | - $comment_id = absint($comment_id); | |
| 604 | - $comment_body = !empty($comment_body) ? wp_kses_post($comment_body) : ''; | |
| 605 | - $values=array( | |
| 606 | - 'body'=>$comment_body | |
| 607 | - ); | |
| 608 | - $wpdb->update($wpdb->prefix.'wppm_task_comment', $values, array('id'=>"$comment_id")); | |
| 609 | - } | |
| 610 | - | |
| 611 | - public function change_proj_comment($comment_id,$comment_body){ | |
| 612 | - global $wpdb; | |
| 613 | - $comment_id = absint($comment_id); | |
| 614 | - $comment_body = !empty($comment_body) ? wp_kses_post($comment_body) : ''; | |
| 615 | - $values=array( | |
| 616 | - 'body'=>$comment_body | |
| 617 | - ); | |
| 618 | - $wpdb->update($wpdb->prefix.'wppm_project_comment', $values, array('id'=>"$comment_id")); | |
| 619 | - } | |
| 620 | - | |
| 621 | - public function change_project_label($project_id,$project_label){ | |
| 622 | - global $wpdb; | |
| 623 | - $project_id = absint($project_id); | |
| 624 | - $values=array( | |
| 625 | - 'project_name'=>esc_sql($project_label) | |
| 626 | - ); | |
| 627 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 628 | - } | |
| 629 | - | |
| 630 | - public function change_project_start_date($project_id, $project_start_date){ | |
| 631 | - global $wpdb; | |
| 632 | - $project_id = absint($project_id); | |
| 633 | - $project_start_date = esc_sql($project_start_date); | |
| 634 | - $values=array( | |
| 635 | - 'start_date'=>$project_start_date | |
| 636 | - ); | |
| 637 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 638 | - } | |
| 639 | - | |
| 640 | - public function change_project_end_date($project_id, $project_end_date){ | |
| 641 | - global $wpdb; | |
| 642 | - $project_id = absint($project_id); | |
| 643 | - $project_end_date = esc_sql($project_end_date); | |
| 644 | - $values=array( | |
| 645 | - 'end_date'=>$project_end_date | |
| 646 | - ); | |
| 647 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>$project_id)); | |
| 648 | - } | |
| 649 | - | |
| 650 | - public function change_category($project_id, $project_category){ | |
| 651 | - global $wpdb; | |
| 652 | - $project_id = absint($project_id); | |
| 653 | - $project_category = absint($project_category); | |
| 654 | - $values=array( | |
| 655 | - 'cat_id'=>$project_category | |
| 656 | - ); | |
| 657 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 658 | - } | |
| 659 | - | |
| 660 | - public function change_project_description($project_id, $project_description){ | |
| 661 | - global $wpdb; | |
| 662 | - $project_id = absint($project_id); | |
| 663 | - $project_description = (string) ( $project_description ?? '' ); | |
| 664 | - $values = array( | |
| 665 | - 'description' => wp_kses_post( $project_description ) | |
| 666 | - ); | |
| 667 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 668 | - } | |
| 669 | - | |
| 670 | - public function change_project_status($project_id,$status_id){ | |
| 671 | - global $wpdb,$wppmfunction,$current_user; | |
| 672 | - $change_status_value= array(); | |
| 673 | - $proj_data = $wppmfunction->get_project($project_id); | |
| 674 | - $prev_status = $proj_data['status']; | |
| 675 | - $cu_id = absint($current_user->ID); | |
| 676 | - $values=array( | |
| 677 | - 'status'=>absint($status_id) | |
| 678 | - ); | |
| 679 | - $project_id = absint($project_id); | |
| 680 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>$project_id)); | |
| 681 | - $old_project_status_meta = $wppmfunction->get_project_meta($project_id,'old_project_status',true); | |
| 682 | - if(!empty($old_project_status_meta)){ | |
| 683 | - $wppmfunction->delete_project_meta($project_id,'old_project_status'); | |
| 684 | - } | |
| 685 | - $change_status_value = array('prev_status'=>"$prev_status",'new_status'=>"$status_id"); | |
| 686 | - $change_status_obj = serialize($change_status_value); | |
| 687 | - $log_values = array('proj_id'=>"$project_id",'body'=>$change_status_obj,'attachment_ids'=>"",'create_time'=>wp_date("Y-m-d h:i:sa"),'created_by'=>"$cu_id" ); | |
| 688 | - $wpdb->insert($wpdb->prefix . 'wppm_project_comment',$log_values); | |
| 689 | - $log_id = absint($wpdb->insert_id); | |
| 690 | - $proj_log_values = array('proj_id'=>"$project_id",'comment_id'=>"$log_id",'comment_type'=>'change_proj_status'); | |
| 691 | - $wpdb->insert($wpdb->prefix . 'wppm_project_comment_meta',$proj_log_values); | |
| 692 | - $wppmfunction->add_project_meta($project_id,'old_project_status',$prev_status); | |
| 693 | - do_action('wppm_set_change_project_status', $project_id, $status_id, $prev_status); | |
| 694 | - } | |
| 695 | - | |
| 696 | - public function change_project_raised_by($project_id, $user_id){ | |
| 697 | - global $wpdb; | |
| 698 | - $values=array( | |
| 699 | - 'created_by'=>absint($user_id) | |
| 700 | - ); | |
| 701 | - $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 702 | - } | |
| 703 | - | |
| 704 | - // Email Notification types | |
| 705 | - public function get_email_notification_types(){ | |
| 706 | - $notification_types = array( | |
| 707 | - 'new_project'=>esc_html__('New Project','taskbuilder'), | |
| 708 | - 'new_task'=>esc_html__('New Task','taskbuilder'), | |
| 709 | - 'change_project_status' => esc_html__('Change Project Status','taskbuilder'), | |
| 710 | - 'change_task_status' => esc_html__('Change Task Status','taskbuilder'), | |
| 711 | - 'change_project_assign_users' => esc_html__('Change Project Assign Users','taskbuilder'), | |
| 712 | - 'change_task_assign_users' => esc_html__('Change Task Assign Users','taskbuilder'), | |
| 713 | - 'new_discussion' => esc_html__('New Comment','taskbuilder'), | |
| 714 | - 'new_proj_discussion' =>esc_html__('New Project Comment','taskbuilder') | |
| 715 | - ); | |
| 716 | - return apply_filters('wppm_en_types',$notification_types); | |
| 717 | - } | |
| 718 | - | |
| 719 | - public function check_rtl(){ | |
| 720 | - $rtl_locale = array('ar','ary','ckb','haz','he_IL','fa_IR','ps','ur','ug_CN'); | |
| 721 | - if(in_array(get_locale(),$rtl_locale)){ | |
| 722 | - return 'rtl'; | |
| 723 | - }else{ | |
| 724 | - return 'ltr'; | |
| 725 | - } | |
| 726 | - } | |
| 727 | - | |
| 728 | - public function add_project_meta($proj_id,$meta_key,$meta_value){ | |
| 729 | - global $wpdb; | |
| 730 | - $wpdb->insert( | |
| 731 | - $wpdb->prefix . 'wppm_project_meta', | |
| 732 | - array( | |
| 733 | - 'project_id' =>$proj_id, | |
| 734 | - 'meta_key' => $meta_key, | |
| 735 | - 'meta_value' =>$meta_value | |
| 736 | - )); | |
| 737 | - } | |
| 738 | - | |
| 739 | - public function add_task_meta($task_id,$meta_key,$meta_value){ | |
| 740 | - global $wpdb; | |
| 741 | - $wpdb->insert( | |
| 742 | - $wpdb->prefix . 'wppm_task_meta', | |
| 743 | - array( | |
| 744 | - 'task_id' => $task_id, | |
| 745 | - 'meta_key' => $meta_key, | |
| 746 | - 'meta_value' =>$meta_value | |
| 747 | - )); | |
| 748 | - } | |
| 749 | - | |
| 750 | - public function get_project_meta($project_id,$meta_key,$flag = false){ | |
| 751 | - global $wpdb,$wppmfunction; | |
| 752 | - $project_id = absint($project_id); | |
| 753 | - $meta_key = esc_sql($meta_key); | |
| 754 | - if($flag){ | |
| 755 | - $get_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key = %s",$project_id,$meta_key)); | |
| 756 | - $project_meta = isset($get_meta) ? stripslashes($get_meta) : ''; | |
| 757 | - | |
| 758 | - } else { | |
| 759 | - $project_meta = array(); | |
| 760 | - $results = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key = %s",$project_id,$meta_key)); | |
| 761 | - if( (!empty($results)) ){ | |
| 762 | - foreach ($results as $result) { | |
| 763 | - if(!empty($result)){ | |
| 764 | - $project_meta[]= stripslashes($result->meta_value); | |
| 765 | - } | |
| 766 | - } | |
| 767 | - } | |
| 768 | - } | |
| 769 | - return $project_meta; | |
| 770 | - } | |
| 771 | - | |
| 772 | - public function get_task_meta($task_id,$meta_key,$flag = false){ | |
| 773 | - global $wpdb,$wppmfunction; | |
| 774 | - $task_id = absint($task_id); | |
| 775 | - $meta_key = esc_sql($meta_key); | |
| 776 | - if($flag){ | |
| 777 | - $get_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_task_meta WHERE task_id = %d AND meta_key = %s",$task_id,$meta_key)); | |
| 778 | - $task_meta = isset($get_meta) ? stripslashes($get_meta) : ''; | |
| 779 | - | |
| 780 | - } else { | |
| 781 | - $task_meta = array(); | |
| 782 | - $results = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_task_meta WHERE task_id = %d AND meta_key = %s",$task_id,$meta_key)); | |
| 783 | - if( (!empty($results)) ){ | |
| 784 | - foreach ($results as $result) { | |
| 785 | - if(!empty($result)){ | |
| 786 | - $task_meta[]= stripslashes($result->meta_value); | |
| 787 | - } | |
| 788 | - } | |
| 789 | - } | |
| 790 | - } | |
| 791 | - return $task_meta; | |
| 792 | - } | |
| 793 | - | |
| 794 | - public function get_previously_assigned_users($project_id){ | |
| 795 | - global $wpdb,$wppmfunction; | |
| 796 | - $prev_assigned_users = $wppmfunction->get_project_meta($project_id,'prev_assigned_users'); | |
| 797 | - $user_emails = array(); | |
| 798 | - if(!empty($prev_assigned_users)){ | |
| 799 | - foreach ($prev_assigned_users as $user) { | |
| 800 | - $userdata = get_userdata($user); | |
| 801 | - $user_emails[] = $userdata->user_email; | |
| 802 | - | |
| 803 | - } | |
| 804 | - } | |
| 805 | - return apply_filters( 'wppm_get_prev_assigned_users_emails', $user_emails ,$project_id); | |
| 806 | - } | |
| 807 | - | |
| 808 | - public function get_project_creator_email($project_id){ | |
| 809 | - global $wpdb,$wppmfunction; | |
| 810 | - $project_data = $wppmfunction->get_project($project_id,'created_by'); | |
| 811 | - $userdata = get_userdata($project_data['created_by']); | |
| 812 | - if(!empty( $userdata)){ | |
| 813 | - $proj_creator_email[] = $userdata->user_email; | |
| 814 | - } | |
| 815 | - return apply_filters( 'wppm_get_project_creator_email', $proj_creator_email ,$project_id); | |
| 816 | - } | |
| 817 | - | |
| 818 | - public function get_task_creator_email($task_id){ | |
| 819 | - global $wpdb,$wppmfunction; | |
| 820 | - $task_data = $wppmfunction->get_task($task_id,'created_by'); | |
| 821 | - $userdata = get_userdata($task_data['created_by']); | |
| 822 | - if(!empty( $userdata)){ | |
| 823 | - $task_creator_email[] = $userdata->user_email; | |
| 824 | - } | |
| 825 | - return apply_filters( 'wppm_get_task_creator_email', $task_creator_email ,$task_id); | |
| 826 | - } | |
| 827 | - | |
| 828 | - public function get_previously_assigned_task_users($task_id){ | |
| 829 | - global $wpdb,$wppmfunction; | |
| 830 | - $prev_assigned_task_users = $wppmfunction->get_task_meta($task_id,'prev_assigned_task_users'); | |
| 831 | - $user_emails = array(); | |
| 832 | - if(!empty($prev_assigned_task_users)){ | |
| 833 | - foreach ($prev_assigned_task_users as $user) { | |
| 834 | - if(!empty($user)){ | |
| 835 | - $userdata = get_userdata($user); | |
| 836 | - $user_emails[] = $userdata->user_email; | |
| 837 | - } | |
| 838 | - } | |
| 839 | - } | |
| 840 | - return apply_filters( 'wppm_get_prev_assigned_task_users_emails', $user_emails ,$task_id); | |
| 841 | - } | |
| 842 | - /** | |
| 843 | - * Update project meta for project | |
| 844 | - */ | |
| 845 | - function update_project_meta($project_id ,$meta_key ,$meta_value){ | |
| 846 | - global $wpdb; | |
| 847 | - $project_id = absint($project_id); | |
| 848 | - $meta_key = esc_sql($meta_key); | |
| 849 | - $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key = %s",$project_id,$meta_key)); | |
| 850 | - $wpdb->update($wpdb->prefix.'wppm_project_meta', $meta_value, array('project_id'=>$project_id,'meta_key' => "$meta_key")); | |
| 851 | - } | |
| 852 | - | |
| 853 | - /** | |
| 854 | - * Update task meta for task | |
| 855 | - */ | |
| 856 | - function update_task_meta($task_id ,$meta_key ,$meta_value){ | |
| 857 | - global $wpdb; | |
| 858 | - $task_id = absint($task_id); | |
| 859 | - $meta_key = esc_sql($meta_key); | |
| 860 | - $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_meta WHERE task_id = %d AND meta_key = %s",$task_id,$meta_key)); | |
| 861 | - $wpdb->update($wpdb->prefix.'wppm_task_meta', $meta_value, array('task_id'=>$task_id,'meta_key' => "$meta_key")); | |
| 862 | - } | |
| 863 | - | |
| 864 | - function delete_project_meta($project_id ,$meta_key){ | |
| 865 | - global $wpdb; | |
| 866 | - $project_id = absint($project_id); | |
| 867 | - $meta_key = ($meta_key); | |
| 868 | - $wpdb->delete( $wpdb->prefix.'wppm_project_meta', array( 'project_id' => "$project_id",'meta_key'=>"$meta_key") ); | |
| 869 | - } | |
| 870 | - | |
| 871 | - function delete_task_meta($task_id ,$meta_key){ | |
| 872 | - global $wpdb; | |
| 873 | - $task_id = absint($task_id); | |
| 874 | - $meta_key = ($meta_key); | |
| 875 | - $wpdb->delete( $wpdb->prefix.'wppm_task_meta', array( 'task_id' => "$task_id",'meta_key'=>"$meta_key") ); | |
| 876 | - } | |
| 877 | - | |
| 878 | - public function replace_macro($str,$project_id){ | |
| 879 | - include WPPM_ABSPATH . 'includes/replace_macro.php'; | |
| 880 | - return $str; | |
| 881 | - } | |
| 882 | - | |
| 883 | - public function replace_task_macro($str,$task_id){ | |
| 884 | - include WPPM_ABSPATH . 'includes/replace_task_macro.php'; | |
| 885 | - return $str; | |
| 886 | - } | |
| 887 | - | |
| 888 | - public function get_old_project_status_name($id){ | |
| 889 | - global $wppmfunction, $wpdb; | |
| 890 | - $old_project_status = $wppmfunction->get_project_meta($id,'old_project_status',true); | |
| 891 | - $old_project_status = absint($old_project_status); | |
| 892 | - $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_project_statuses WHERE id = %d",$old_project_status)); | |
| 893 | - return $status_name; | |
| 894 | - } | |
| 895 | - | |
| 896 | - public function get_new_project_status_name($status_id){ | |
| 897 | - global $wpdb; | |
| 898 | - $status_id = absint($status_id); | |
| 899 | - $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_project_statuses WHERE id = %d",$status_id)); | |
| 900 | - return $status_name; | |
| 901 | - } | |
| 902 | - | |
| 903 | - public function get_old_task_status_name($task_id){ | |
| 904 | - global $wppmfunction, $wpdb; | |
| 905 | - $old_task_status = $wppmfunction->get_task_meta($task_id,'old_task_status',true); | |
| 906 | - $old_task_status = absint($old_task_status); | |
| 907 | - $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_task_statuses WHERE id = %d",$old_task_status)); | |
| 908 | - return $status_name; | |
| 909 | - } | |
| 910 | - | |
| 911 | - public function get_new_task_status_name($status_id){ | |
| 912 | - global $wpdb; | |
| 913 | - $status_id = absint($status_id); | |
| 914 | - $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_task_statuses WHERE id = %d",$status_id)); | |
| 915 | - return $status_name; | |
| 916 | - } | |
| 917 | - | |
| 918 | - public function get_project_category_name($cat_id){ | |
| 919 | - global $wpdb; | |
| 920 | - $cat_id = absint($cat_id); | |
| 921 | - if(!empty($cat_id)){ | |
| 922 | - $cat_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_project_categories WHERE id = %d",$cat_id)); | |
| 923 | - }else{ | |
| 924 | - $cat_name = ""; | |
| 925 | - } | |
| 926 | - return $cat_name; | |
| 927 | - } | |
| 928 | - | |
| 929 | - public function get_project_assigned_users_names($project_id){ | |
| 930 | - global $wppmfunction; | |
| 931 | - $wppm_project_data = $wppmfunction->get_project($project_id); | |
| 932 | - if(!empty($wppm_project_data['users'])){ | |
| 933 | - $wppm_project_assign_users_array = explode(",", $wppm_project_data['users']); | |
| 934 | - }else{ | |
| 935 | - $wppm_project_assign_users_array = array(); | |
| 936 | - } | |
| 937 | - $users_names = array(); | |
| 938 | - if(!empty($wppm_project_assign_users_array)){ | |
| 939 | - foreach ($wppm_project_assign_users_array as $user_id) { | |
| 940 | - if(!empty($user_id)){ | |
| 941 | - $userdata = get_userdata( $user_id ); | |
| 942 | - if(!empty($userdata)){ | |
| 943 | - $users_names[] = $userdata->display_name; | |
| 944 | - } | |
| 945 | - } | |
| 946 | - } | |
| 947 | - } | |
| 948 | - return implode(', ', $users_names); | |
| 949 | - } | |
| 950 | - | |
| 951 | - public function get_task_assigned_users_names($task_id){ | |
| 952 | - global $wppmfunction; | |
| 953 | - $wppm_task_data = $wppmfunction->get_task($task_id); | |
| 954 | - $wppm_task_assign_users_array = explode(",", (string)$wppm_task_data['users']); | |
| 955 | - $users_names = array(); | |
| 956 | - if(!empty($wppm_task_assign_users_array)){ | |
| 957 | - foreach ($wppm_task_assign_users_array as $user_id) { | |
| 958 | - if(!empty($user_id)){ | |
| 959 | - $userdata = get_userdata( $user_id ); | |
| 960 | - if(!empty($userdata)){ | |
| 961 | - $users_names[] = $userdata->display_name; | |
| 962 | - } | |
| 963 | - } | |
| 964 | - } | |
| 965 | - } | |
| 966 | - return implode(', ', $users_names); | |
| 967 | - } | |
| 968 | - | |
| 969 | - public function get_project_previously_assigned_users_names($project_id){ | |
| 970 | - global $wppmfunction; | |
| 971 | - $wppm_project_assign_users = $wppmfunction->get_project_meta($project_id,'prev_assigned_users'); | |
| 972 | - $users_names = array(); | |
| 973 | - if(!empty($wppm_project_assign_users)){ | |
| 974 | - foreach ($wppm_project_assign_users as $user) { | |
| 975 | - if(!empty($user)){ | |
| 976 | - $userdata = get_userdata( $user ); | |
| 977 | - $users_names[] = $userdata->display_name; | |
| 978 | - } | |
| 979 | - } | |
| 980 | - } | |
| 981 | - return implode(', ', $users_names); | |
| 982 | - } | |
| 983 | - | |
| 984 | - public function get_task_previously_assigned_users_names($task_id){ | |
| 985 | - global $wppmfunction; | |
| 986 | - $wppm_task_assign_users = $wppmfunction->get_task_meta($task_id,'prev_assigned_task_users'); | |
| 987 | - $users_names = array(); | |
| 988 | - if(!empty($wppm_task_assign_users)){ | |
| 989 | - foreach ($wppm_task_assign_users as $user) { | |
| 990 | - if(!empty($user)){ | |
| 991 | - $userdata = get_userdata( $user ); | |
| 992 | - $users_names[] = $userdata->display_name; | |
| 993 | - } | |
| 994 | - } | |
| 995 | - } | |
| 996 | - return implode(', ', $users_names); | |
| 997 | - } | |
| 998 | - | |
| 999 | - public function get_task_priority_name($priority){ | |
| 1000 | - global $wpdb; | |
| 1001 | - $priority = absint($priority); | |
| 1002 | - $priority_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_task_priorities WHERE id = %d",$priority)); | |
| 1003 | - return $priority_name; | |
| 1004 | - } | |
| 1005 | - | |
| 1006 | - public function get_last_comment_user_name($task_id){ | |
| 1007 | - global $wpdb; | |
| 1008 | - $task_id = absint($task_id); | |
| 1009 | - $task_comment_creator = $wpdb->get_var($wpdb->prepare("SELECT created_by FROM {$wpdb->prefix}wppm_task_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_task_comment) AND task_id = %d)",$task_id)); | |
| 1010 | - if(!empty($task_comment_creator)){ | |
| 1011 | - $user = get_userdata( $task_comment_creator ); | |
| 1012 | - return $user->display_name; | |
| 1013 | - } | |
| 1014 | - } | |
| 1015 | - | |
| 1016 | - public function get_last_comment_body($task_id){ | |
| 1017 | - global $wpdb; | |
| 1018 | - $task_id = absint($task_id); | |
| 1019 | - $task_comment = $wpdb->get_var($wpdb->prepare("SELECT body FROM {$wpdb->prefix}wppm_task_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_task_comment) AND task_id = %d)",$task_id)); | |
| 1020 | - return $task_comment; | |
| 1021 | - } | |
| 1022 | - | |
| 1023 | - public function create_duplicate_task($ptask_id, $project_id,$ajax_nonce){ | |
| 1024 | - include WPPM_ABSPATH . 'includes/admin/tasks/open_task/wppm_set_clone_task.php'; | |
| 1025 | - } | |
| 1026 | - | |
| 1027 | - public function get_last_comment_proj_user_name($project_id){ | |
| 1028 | - global $wpdb; | |
| 1029 | - $project_id = absint($project_id); | |
| 1030 | - $proj_comment_creator = $wpdb->get_var($wpdb->prepare("SELECT created_by FROM {$wpdb->prefix}wppm_project_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_project_comment) AND proj_id = %d)",$project_id)); | |
| 1031 | - if(!empty($proj_comment_creator)){ | |
| 1032 | - $user = get_userdata( $proj_comment_creator ); | |
| 1033 | - return $user->display_name; | |
| 1034 | - } | |
| 1035 | - } | |
| 1036 | - | |
| 1037 | - public function get_proj_comment_body($project_id){ | |
| 1038 | - global $wpdb; | |
| 1039 | - $project_id = absint($project_id); | |
| 1040 | - $proj_comment = $wpdb->get_var($wpdb->prepare("SELECT body FROM {$wpdb->prefix}wppm_project_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_project_comment) AND proj_id = %d)",$project_id)); | |
| 1041 | - return $proj_comment; | |
| 1042 | - } | |
| 1043 | - | |
| 1044 | - public function get_project_url($project_id, $view){ | |
| 1045 | - global $wpdb,$wppmfunction; | |
| 1046 | - $project_id = absint($project_id); | |
| 1047 | - $page_settings = get_option( 'wppm-page-settings' ); | |
| 1048 | - if ( $view == '0' ) { | |
| 1049 | - $url = admin_url( 'admin.php?page=wppm-projects§ion=project-list&id=' . $project_id ); | |
| 1050 | - } else { | |
| 1051 | - $url = get_permalink( $page_settings['project-url-page'] ); | |
| 1052 | - $auth_id = $wppmfunction->get_project_meta($project_id,'project_auth_code',true); | |
| 1053 | - | |
| 1054 | - $url = add_query_arg( | |
| 1055 | - array( | |
| 1056 | - 'project-id' => $project_id, | |
| 1057 | - 'auth-code' => $auth_id, | |
| 1058 | - | |
| 1059 | - ), | |
| 1060 | - $url | |
| 1061 | - ); | |
| 1062 | - } | |
| 1063 | - | |
| 1064 | - return $url; | |
| 1065 | - } | |
| 1066 | - | |
| 1067 | - public function get_task_url($task_id, $view){ | |
| 1068 | - global $wpdb,$wppmfunction; | |
| 1069 | - $task_id = absint($task_id); | |
| 1070 | - $page_settings = get_option( 'wppm-page-settings' ); | |
| 1071 | - if ( $view == '0' ) { | |
| 1072 | - $url = admin_url( 'admin.php?page=wppm-tasks§ion=task-list&id=' . $task_id ); | |
| 1073 | - } else{ | |
| 1074 | - $url = get_permalink( $page_settings['task-url-page'] ); | |
| 1075 | - $auth_id = $this->wppm_get_auth_code($task_id); | |
| 1076 | - $url = add_query_arg( | |
| 1077 | - array( | |
| 1078 | - 'task-id' => $task_id, | |
| 1079 | - 'auth-code' => $auth_id, | |
| 1080 | - ), | |
| 1081 | - $url | |
| 1082 | - ); | |
| 1083 | - | |
| 1084 | - } | |
| 1085 | - | |
| 1086 | - return $url; | |
| 1087 | - } | |
| 1088 | - | |
| 1089 | - public function wppm_user_role(){ | |
| 1090 | - $user_role = array( | |
| 1091 | - 'wppm_admin' => array( | |
| 1092 | - 'label' => esc_html__('WPPM Administrator','taskbuilder'), | |
| 1093 | - ), | |
| 1094 | - 'wppm_manager' => array( | |
| 1095 | - 'label' => esc_html__('WPPM Manager','taskbuilder'), | |
| 1096 | - ) | |
| 1097 | - ); | |
| 1098 | - return $user_role; | |
| 1099 | - } | |
| 1100 | - | |
| 1101 | - public static function wppm_toolbar_options_setting() { | |
| 1102 | - $toolbar = array( | |
| 1103 | - array( | |
| 1104 | - 'name' => esc_attr__( 'Bold', 'taskbuilder' ), | |
| 1105 | - 'value' => 'bold', | |
| 1106 | - ), | |
| 1107 | - array( | |
| 1108 | - 'name' => esc_attr__( 'Italic', 'taskbuilder' ), | |
| 1109 | - 'value' => 'italic', | |
| 1110 | - ), | |
| 1111 | - array( | |
| 1112 | - 'name' => esc_attr__( 'Underline', 'taskbuilder' ), | |
| 1113 | - 'value' => 'underline', | |
| 1114 | - ), | |
| 1115 | - array( | |
| 1116 | - 'name' => esc_attr__( 'Blockquote', 'taskbuilder' ), | |
| 1117 | - 'value' => 'blockquote', | |
| 1118 | - ), | |
| 1119 | - array( | |
| 1120 | - 'name' => esc_attr__( 'Align', 'taskbuilder' ), | |
| 1121 | - 'value' => 'align', | |
| 1122 | - ), | |
| 1123 | - array( | |
| 1124 | - 'name' => esc_attr__( 'Bulleted list', 'taskbuilder' ), | |
| 1125 | - 'value' => 'bullist', | |
| 1126 | - ), | |
| 1127 | - array( | |
| 1128 | - 'name' => esc_attr__( 'Numbered list', 'taskbuilder' ), | |
| 1129 | - 'value' => 'numlist', | |
| 1130 | - ), | |
| 1131 | - array( | |
| 1132 | - 'name' => esc_attr__( 'Right to left', 'taskbuilder' ), | |
| 1133 | - 'value' => 'rtl', | |
| 1134 | - ), | |
| 1135 | - array( | |
| 1136 | - 'name' => esc_attr__( 'Link', 'taskbuilder' ), | |
| 1137 | - 'value' => 'link', | |
| 1138 | - ), | |
| 1139 | - array( | |
| 1140 | - 'name' => esc_attr__( 'Image', 'taskbuilder' ), | |
| 1141 | - 'value' => 'wppm_insert_editor_img', | |
| 1142 | - ), | |
| 1143 | - array( | |
| 1144 | - 'name' => esc_attr__( 'Text Color', 'taskbuilder' ), | |
| 1145 | - 'value' => 'forecolor', | |
| 1146 | - ), | |
| 1147 | - array( | |
| 1148 | - 'name' => esc_attr__( 'Text Background Color', 'taskbuilder' ), | |
| 1149 | - 'value' => 'backcolor', | |
| 1150 | - ), | |
| 1151 | - array( | |
| 1152 | - 'name' => esc_attr__( 'Strikethrough', 'taskbuilder' ), | |
| 1153 | - 'value' => 'strikethrough', | |
| 1154 | - ), | |
| 1155 | - ); | |
| 1156 | - return $toolbar; | |
| 1157 | - } | |
| 1158 | - | |
| 1159 | - public static function wppm_load_setting_header_html() { | |
| 1160 | - ?> | |
| 1161 | - <div class="wppm-header" style="padding-left:20px;margin:10px 0 10px 0;display: flex; justify-content: space-between; align-items: center; position: sticky;top: 0;background: #fff !important;z-index: 9999;width:99%; left: 0; "> | |
| 1162 | - <div class="wppm-header-title" style="display: flex; align-items: center; gap: 3px;"> | |
| 1163 | - <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/taskbuilder_logo.png'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 33px; height: 33px;margin-right:10px !important;"/> | |
| 1164 | - <h2 style="font-size: 30px; font-weight: 600; color: #333; margin: 0; font: 22px OpenSans-Light, Helvetica, Arial, sans-serif;"><?php esc_html_e( 'Taskbuilder', 'taskbuilder' )?></h2> | |
| 1165 | - </div> | |
| 1166 | - <div class="wppm-header-button" style="display: flex; justify-content: flex-end; gap: 3px;"> | |
| 1167 | - <div class="wppm-btn | |
| 1168 | - " style="background-color: #0052CC; color: #fff; padding: 8px 10px;margin: 35px 0px 14px 0px;text-decoration: none;border-radius: 5px;transition: background 0.3s ease;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);"> | |
| 1169 | - <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/help.svg'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 20px; height: 19px;margin-bottom: -5px;"/> | |
| 1170 | - <a href="https://taskbuilder.net/help/" target="__blank" style="color:#fff"><?php esc_html_e( 'Help', 'taskbuilder' )?></a> | |
| 1171 | - </div> | |
| 1172 | - <div class="wppm-btn" style="background-color: #0052CC; color: #fff; padding: 8px 10px;margin: 35px 0px 14px 0px;text-decoration: none;border-radius: 5px;transition: background 0.3s ease;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);"> | |
| 1173 | - <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/support.svg'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 15px; height: 19px;margin-bottom: -5px;"/> | |
| 1174 | - <a href="https://taskbuilder.net/support/?wpsc-section=ticket-list" target="__blank" style="color:#fff"><?php esc_html_e( 'Support', 'taskbuilder' )?></a> | |
| 1175 | - </div> | |
| 1176 | - <div class="wppm-btn" style="background-color: #0052CC; color: #fff; padding: 8px 10px;margin: 35px 10px 14px 0px;text-decoration: none;border-radius: 5px;transition: background 0.3s ease;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);"> | |
| 1177 | - <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/pro_features.svg'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 15px; height: 19px;margin-bottom: -5px;"/> | |
| 1178 | - <a href="https://taskbuilder.net/pricing/" target="__blank" style="color:#fff"><?php esc_html_e( 'Get pro', 'taskbuilder' )?></a> | |
| 1179 | - </div> | |
| 1180 | - </div> | |
| 1181 | - </div> | |
| 1182 | - <?php | |
| 1183 | - } | |
| 1184 | - | |
| 1185 | - public function wppm_get_duration($start_date, $end_date){ | |
| 1186 | - if ( empty($start_date) || empty($end_date) || $start_date=='0000-00-00 00:00:00' || $end_date =='0000-00-00 00:00:00') { | |
| 1187 | - return ''; | |
| 1188 | - } | |
| 1189 | - | |
| 1190 | - $start_ts = strtotime($start_date); | |
| 1191 | - $end_ts = strtotime($end_date); | |
| 1192 | - | |
| 1193 | - if ( $end_ts <= $start_ts ) { | |
| 1194 | - return '0 min'; | |
| 1195 | - } | |
| 1196 | - | |
| 1197 | - $diff = $end_ts - $start_ts; | |
| 1198 | - | |
| 1199 | - $days = floor($diff / 86400); | |
| 1200 | - $hours = floor(($diff % 86400) / 3600); | |
| 1201 | - $minutes = floor(($diff % 3600) / 60); | |
| 1202 | - | |
| 1203 | - $duration = []; | |
| 1204 | - | |
| 1205 | - if ($days > 0) $duration[] = $days . 'd'; | |
| 1206 | - if ($hours > 0) $duration[] = $hours . 'h'; | |
| 1207 | - if ($minutes > 0 || empty($duration)) $duration[] = $minutes . 'm'; | |
| 1208 | - | |
| 1209 | - return implode(' ', $duration); | |
| 1210 | - | |
| 1211 | - } | |
| 1212 | - } | |
| 1213 | -endif; | |
| 1 | +<?php | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | + exit; // Exit if accessed directly | |
| 4 | +} | |
| 5 | +if ( ! class_exists( 'WPPM_Functions' ) ) : | |
| 6 | + final class WPPM_Functions { | |
| 7 | + // Array sanitization | |
| 8 | + public static function sanitize_array($array) { | |
| 9 | + if(!empty($array)){ | |
| 10 | + foreach ( $array as $key => $value ) { | |
| 11 | + if ( is_array( $value ) ) { | |
| 12 | + $value = $this->sanitize_array($value); | |
| 13 | + } | |
| 14 | + else { | |
| 15 | + $value = sanitize_text_field( wp_unslash( $value ) ); | |
| 16 | + } | |
| 17 | + } | |
| 18 | + } | |
| 19 | + return $array; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public static function create_project($args){ | |
| 23 | + global $wpdb,$current_user; | |
| 24 | + $default_proj_status = get_option('wppm_default_project_status'); | |
| 25 | + $values = array( | |
| 26 | + 'created_by'=>$current_user->ID, | |
| 27 | + 'project_name'=>$args['name'], | |
| 28 | + 'description'=>isset($args['wppm_proj_description']) ? $args['wppm_proj_description']:"", | |
| 29 | + 'start_date'=>isset($args['wppm_start_date']) ?$args['wppm_start_date']:"", | |
| 30 | + 'end_date'=>isset($args['wppm_end_date'])? $args['wppm_end_date']:"", | |
| 31 | + 'status'=>isset($args['status'])? $args['status']:$default_proj_status, | |
| 32 | + 'cat_id'=>isset($args['wppm_create_project_category']) ? $args['wppm_create_project_category']:"", | |
| 33 | + 'users'=>isset($args['user_names']) ? implode(",",$args['user_names']):"", | |
| 34 | + 'date_created'=>isset($args['date_created'])? $args['date_created']:wp_date("Y-m-d h:i:sa"), | |
| 35 | + 'project_auth_code'=> self::getRandomString(10) | |
| 36 | + | |
| 37 | + ); | |
| 38 | + $wpdb->insert($wpdb->prefix .'wppm_project', $values); | |
| 39 | + $project_id = $wpdb->insert_id; | |
| 40 | + return $project_id; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public static function create_task($args){ | |
| 44 | + global $wpdb,$current_user; | |
| 45 | + $default_task_status = get_option('wppm_default_task_status'); | |
| 46 | + $values = array( | |
| 47 | + 'created_by'=>(isset($args['created_by'])) ? $args['created_by']: $current_user->ID, | |
| 48 | + 'task_name'=>$args['name'], | |
| 49 | + 'description'=>(isset($args['wppm_task_description']))?$args['wppm_task_description']:"", | |
| 50 | + 'project'=>(isset($args['wppm_task_project']))?$args['wppm_task_project']:"", | |
| 51 | + 'start_date'=>(isset($args['wppm_task_start_date']))?$args['wppm_task_start_date']:"", | |
| 52 | + 'end_date'=>(isset($args['wppm_task_end_date']))?$args['wppm_task_end_date']:"", | |
| 53 | + 'status'=>(isset($args['status']))?$args['status']:$default_task_status, | |
| 54 | + 'priority'=>(isset($args['wppm_create_task_priority']))?$args['wppm_create_task_priority']:"", | |
| 55 | + 'users'=>(!empty($args['user_names']))?implode(",",$args['user_names']):"", | |
| 56 | + 'date_created'=>isset($args['date_created'])? $args['date_created']:wp_date("Y-m-d h:i:sa"), | |
| 57 | + 'task_auth_code'=> self::getRandomString(10), | |
| 58 | + 'active'=>1, | |
| 59 | + 'parent_task_id'=>(isset($args['parent_task_id']))?absint($args['parent_task_id']):0 | |
| 60 | + ); | |
| 61 | + $wpdb->insert($wpdb->prefix .'wppm_task', $values); | |
| 62 | + $task_id = $wpdb->insert_id; | |
| 63 | + return $task_id; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public static function create_checklist($args){ | |
| 67 | + global $wpdb,$current_user,$wppmfunction; | |
| 68 | + $values = array( | |
| 69 | + 'task_id'=>$args['task_id'], | |
| 70 | + 'checklist_name' => $args['checklist_name'], | |
| 71 | + 'created_by'=> $args['created_by'] | |
| 72 | + ); | |
| 73 | + $wpdb->insert($wpdb->prefix .'wppm_checklist', $values); | |
| 74 | + $checklist_id = $wpdb->insert_id; | |
| 75 | + return $checklist_id; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public static function create_checklist_item($args){ | |
| 79 | + global $wpdb,$current_user,$wppmfunction; | |
| 80 | + $chk_items_values = array( | |
| 81 | + 'checklist_id' => $args['checklist_id'], | |
| 82 | + 'item_name' => $args['item_name'], | |
| 83 | + 'checked'=>$args['checked'], | |
| 84 | + 'members'=>$args['members'], | |
| 85 | + 'due_date'=> $args['due_date'] | |
| 86 | + ); | |
| 87 | + $wpdb->insert($wpdb->prefix .'wppm_checklist_items', $chk_items_values); | |
| 88 | + $checklist_item_id = $wpdb->insert_id; | |
| 89 | + return $checklist_item_id; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public static function wppm_submit_task_comment($args){ | |
| 93 | + global $wpdb; | |
| 94 | + $wpdb->insert($wpdb->prefix.'wppm_task_comment',$args); | |
| 95 | + $comment_id = $wpdb->insert_id; | |
| 96 | + return $comment_id; | |
| 97 | + } | |
| 98 | + | |
| 99 | + public static function wppm_submit_task_comment_meta($args){ | |
| 100 | + global $wpdb; | |
| 101 | + $wpdb->insert($wpdb->prefix.'wppm_task_comment_meta',$args); | |
| 102 | + $comment_meta_id = $wpdb->insert_id; | |
| 103 | + return $comment_meta_id; | |
| 104 | + } | |
| 105 | + | |
| 106 | + public static function wppm_submit_proj_comment($args){ | |
| 107 | + global $wpdb; | |
| 108 | + $wpdb->insert($wpdb->prefix.'wppm_project_comment',$args); | |
| 109 | + $comment_id = $wpdb->insert_id; | |
| 110 | + return $comment_id; | |
| 111 | + } | |
| 112 | + | |
| 113 | + public static function wppm_submit_proj_comment_meta($args){ | |
| 114 | + global $wpdb; | |
| 115 | + $wpdb->insert($wpdb->prefix.'wppm_project_comment_meta',$args); | |
| 116 | + $comment_meta_id = $wpdb->insert_id; | |
| 117 | + return $comment_meta_id; | |
| 118 | + } | |
| 119 | + | |
| 120 | + // Random string | |
| 121 | + public static function getRandomString($length = 8) { | |
| 122 | + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
| 123 | + $string = ''; | |
| 124 | + for ($i = 0; $i < $length; $i++) { | |
| 125 | + $string .= $characters[wp_rand(0, strlen($characters) - 1)]; | |
| 126 | + } | |
| 127 | + return $string; | |
| 128 | + } | |
| 129 | + | |
| 130 | + public static function wppm_get_auth_code($id){ | |
| 131 | + global $wpdb; | |
| 132 | + $id = absint($id); | |
| 133 | + $auth_code = $wpdb->get_var( | |
| 134 | + $wpdb->prepare( | |
| 135 | + "SELECT task_auth_code | |
| 136 | + FROM {$wpdb->prefix}wppm_task | |
| 137 | + WHERE id = %d", | |
| 138 | + ($id) | |
| 139 | + ) | |
| 140 | + ); | |
| 141 | + $auth_code = isset($auth_code) ? $auth_code : ""; | |
| 142 | + return $auth_code; | |
| 143 | + } | |
| 144 | + | |
| 145 | + public static function wppm_get_proj_auth_code($id){ | |
| 146 | + global $wpdb; | |
| 147 | + $id = absint($id); | |
| 148 | + $auth_code = $wpdb->get_var( | |
| 149 | + $wpdb->prepare( | |
| 150 | + "SELECT project_auth_code | |
| 151 | + FROM {$wpdb->prefix}wppm_project | |
| 152 | + WHERE id = %d", | |
| 153 | + ($id) | |
| 154 | + ) | |
| 155 | + ); | |
| 156 | + $auth_code = isset($auth_code) ? $auth_code : ""; | |
| 157 | + return $auth_code; | |
| 158 | + } | |
| 159 | + | |
| 160 | + public static function get_task_fields($task_id,$select_field){ | |
| 161 | + global $wpdb; | |
| 162 | + $task_id = absint($task_id); | |
| 163 | + $task_field_value = ''; | |
| 164 | + $allowed_fields = array( | |
| 165 | + 'id', | |
| 166 | + 'created_by', | |
| 167 | + 'task_name', | |
| 168 | + 'description', | |
| 169 | + 'project', | |
| 170 | + 'start_date', | |
| 171 | + 'end_date', | |
| 172 | + 'status', | |
| 173 | + 'priority', | |
| 174 | + 'users', | |
| 175 | + 'date_created', | |
| 176 | + 'task_auth_code' | |
| 177 | + ); | |
| 178 | + | |
| 179 | + // Validate column name | |
| 180 | + if ( ! in_array( $select_field, $allowed_fields, true ) ) { | |
| 181 | + return ''; | |
| 182 | + } | |
| 183 | + if (apply_filters('wppm_get_select_field',true,$task_id,$select_field)) { | |
| 184 | + $get_task_field_value = $wpdb->get_var($wpdb->prepare("SELECT $select_field FROM {$wpdb->prefix}wppm_task WHERE id = %d", $task_id)); | |
| 185 | + $task_field_value = $get_task_field_value ? $get_task_field_value : ''; | |
| 186 | + } | |
| 187 | + return stripslashes($task_field_value); | |
| 188 | + } | |
| 189 | + | |
| 190 | + public static function get_project_fields($proj_id,$select_field){ | |
| 191 | + global $wpdb; | |
| 192 | + $proj_id = absint($proj_id); | |
| 193 | + $project_field_value = ''; | |
| 194 | + $allowed_fields = array( | |
| 195 | + 'id', | |
| 196 | + 'created_by', | |
| 197 | + 'project_name', | |
| 198 | + 'description', | |
| 199 | + 'start_date', | |
| 200 | + 'end_date', | |
| 201 | + 'status', | |
| 202 | + 'cat_id', | |
| 203 | + 'users', | |
| 204 | + 'date_created', | |
| 205 | + 'project_auth_code' | |
| 206 | + ); | |
| 207 | + | |
| 208 | + // Validate column name | |
| 209 | + if ( ! in_array( $select_field, $allowed_fields, true ) ) { | |
| 210 | + return ''; | |
| 211 | + } | |
| 212 | + if (apply_filters('wppm_get_select_proj_field',true,$proj_id,$select_field)) { | |
| 213 | + $get_project_field_value = $wpdb->get_var($wpdb->prepare("SELECT $select_field FROM {$wpdb->prefix}wppm_project WHERE id = %d", $proj_id)); | |
| 214 | + $project_field_value = $get_project_field_value ? $get_project_field_value : ''; | |
| 215 | + } | |
| 216 | + return stripslashes($project_field_value); | |
| 217 | + } | |
| 218 | + | |
| 219 | + public function get_task($task_id){ | |
| 220 | + global $wpdb; | |
| 221 | + $task_data = array(); | |
| 222 | + $task_id = absint($task_id); | |
| 223 | + $task = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task WHERE id = %d", $task_id)); | |
| 224 | + if( $task ){ | |
| 225 | + $task_data = json_decode(wp_json_encode($task), true); | |
| 226 | + } | |
| 227 | + return $task_data; | |
| 228 | + } | |
| 229 | + | |
| 230 | + public function get_checklist($task_id){ | |
| 231 | + global $wpdb; | |
| 232 | + $task_id = absint($task_id); | |
| 233 | + $checklist_data = array(); | |
| 234 | + $checklist = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d", $task_id)); | |
| 235 | + if( $checklist ){ | |
| 236 | + $checklist_data = json_decode(wp_json_encode($checklist), true); | |
| 237 | + } | |
| 238 | + return $checklist_data; | |
| 239 | + } | |
| 240 | + | |
| 241 | + public function get_checklist_items($checklist_id){ | |
| 242 | + global $wpdb; | |
| 243 | + $checklist_items_data = array(); | |
| 244 | + $checklist_id = absint($checklist_id); | |
| 245 | + $checklist_items = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_checklist_items WHERE checklist_id = %d", $checklist_id)); | |
| 246 | + if( $checklist_items ){ | |
| 247 | + $checklist_items_data = json_decode(wp_json_encode($checklist_items), true); | |
| 248 | + } | |
| 249 | + return $checklist_items_data; | |
| 250 | + } | |
| 251 | + | |
| 252 | + public function get_subtasks($task_id){ | |
| 253 | + global $wpdb; | |
| 254 | + $task_id = absint($task_id); | |
| 255 | + $subtasks_data = array(); | |
| 256 | + $subtasks = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d ORDER BY id ASC", $task_id)); | |
| 257 | + if( $subtasks ){ | |
| 258 | + $subtasks_data = json_decode(wp_json_encode($subtasks), true); | |
| 259 | + } | |
| 260 | + return $subtasks_data; | |
| 261 | + } | |
| 262 | + | |
| 263 | + public function get_subtask_progress($task_id){ | |
| 264 | + global $wpdb; | |
| 265 | + $task_id = absint($task_id); | |
| 266 | + $completed_status_id = 4; | |
| 267 | + $total = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d", $task_id)); | |
| 268 | + $completed = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d AND status = %d", $task_id, $completed_status_id)); | |
| 269 | + return array('total'=>$total,'completed'=>$completed); | |
| 270 | + } | |
| 271 | + | |
| 272 | + // Deletes a task along with its subtasks (and each one's checklists/comments/attachments). | |
| 273 | + public static function delete_task_and_children($task_id){ | |
| 274 | + global $wpdb; | |
| 275 | + $task_id = absint($task_id); | |
| 276 | + $child_ids = $wpdb->get_col($wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_task WHERE parent_task_id = %d", $task_id)); | |
| 277 | + foreach($child_ids as $child_id){ | |
| 278 | + self::delete_task_and_children($child_id); | |
| 279 | + } | |
| 280 | + $thread_attachment_ids = $wpdb->get_results($wpdb->prepare("SELECT attachment_ids FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d", $task_id)); | |
| 281 | + if(!empty($thread_attachment_ids)){ | |
| 282 | + foreach ($thread_attachment_ids as $thread_attachment_id){ | |
| 283 | + $attachment_ids_temp = array(); | |
| 284 | + if($thread_attachment_id->attachment_ids){ | |
| 285 | + $attachment_ids_temp = explode(',', $thread_attachment_id->attachment_ids); | |
| 286 | + } | |
| 287 | + foreach ($attachment_ids_temp as $attachment_id){ | |
| 288 | + $attachment_id = absint($attachment_id); | |
| 289 | + $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id)); | |
| 290 | + if(!empty($result)){ | |
| 291 | + $attach_result = $wpdb->get_results($wpdb->prepare("SELECT file_path FROM {$wpdb->prefix}wppm_attachments WHERE file_path = %s", $result->file_path)); | |
| 292 | + if(file_exists($result->file_path) && count($attach_result) < 2){ | |
| 293 | + wp_delete_file($result->file_path); | |
| 294 | + } | |
| 295 | + $wpdb->delete($wpdb->prefix.'wppm_attachments', array('id' => $attachment_id)); | |
| 296 | + } | |
| 297 | + } | |
| 298 | + } | |
| 299 | + } | |
| 300 | + $checklists = $wpdb->get_results($wpdb->prepare("SELECT id FROM {$wpdb->prefix}wppm_checklist WHERE task_id = %d", $task_id)); | |
| 301 | + if(!empty($checklists)){ | |
| 302 | + foreach($checklists as $checklist){ | |
| 303 | + $checklist_id = absint($checklist->id); | |
| 304 | + $wpdb->delete($wpdb->prefix.'wppm_checklist_items', array('checklist_id'=>$checklist_id)); | |
| 305 | + $wpdb->delete($wpdb->prefix.'wppm_checklist', array('id'=>$checklist_id)); | |
| 306 | + } | |
| 307 | + } | |
| 308 | + $wpdb->delete($wpdb->prefix.'wppm_task', array('id'=>$task_id)); | |
| 309 | + $wpdb->delete($wpdb->prefix.'wppm_task_meta', array('task_id'=>$task_id)); | |
| 310 | + $wpdb->delete($wpdb->prefix.'wppm_task_comment', array('task_id'=>$task_id)); | |
| 311 | + $wpdb->delete($wpdb->prefix.'wppm_task_comment_meta', array('task_id'=>$task_id)); | |
| 312 | + do_action('wppm_after_delete_task', $task_id); | |
| 313 | + } | |
| 314 | + | |
| 315 | + public function get_project($project_id){ | |
| 316 | + global $wpdb; | |
| 317 | + $project_data = array(); | |
| 318 | + $project_id = absint($project_id); | |
| 319 | + $project = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 320 | + if( $project ){ | |
| 321 | + $project_data = json_decode(wp_json_encode($project), true); | |
| 322 | + } | |
| 323 | + return $project_data; | |
| 324 | + } | |
| 325 | + | |
| 326 | + public function get_attachment($attachment_id){ | |
| 327 | + global $wpdb; | |
| 328 | + $attachment_data = array(); | |
| 329 | + $attachment_id = absint($attachment_id); | |
| 330 | + $attachment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_attachments WHERE id = %d", $attachment_id)); | |
| 331 | + if( $attachment ){ | |
| 332 | + $attachment_data = json_decode(wp_json_encode($attachment), true); | |
| 333 | + } | |
| 334 | + return $attachment_data; | |
| 335 | + } | |
| 336 | + | |
| 337 | + public function has_permission($permission, $task_id){ | |
| 338 | + global $current_user,$wppmfunction,$wpdb; | |
| 339 | + $task_id = absint($task_id); | |
| 340 | + $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 341 | + $wppm_edit_tasks_permission = get_option('wppm_default_edit_tasks_permission'); | |
| 342 | + $wppm_allow_coworkers_add_checklist = get_option('wppm_allow_coworkers_add_checklist'); | |
| 343 | + $wppm_allow_coworkers_create_task = get_option('wppm_allow_coworkers_create_task'); | |
| 344 | + $wppm_allow_coworkers_change_status = get_option('wppm_allow_coworkers_change_status'); | |
| 345 | + $wppm_allow_coworkers_assign_users = get_option('wppm_allow_coworkers_assign_users'); | |
| 346 | + if(empty($comment_id)){ | |
| 347 | + $comment_id = 0; | |
| 348 | + } | |
| 349 | + $comment_id = absint($comment_id); | |
| 350 | + $task_data = $wppmfunction->get_task($task_id); | |
| 351 | + $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d AND id = %d", $task_id, $comment_id)); | |
| 352 | + | |
| 353 | + if(!empty($task_data['project'])){ | |
| 354 | + $project_id = $task_data['project']; | |
| 355 | + $project_id = absint($project_id); | |
| 356 | + $project_data = $wppmfunction->get_project($project_id); | |
| 357 | + $cu_user_id = absint($current_user->ID); | |
| 358 | + $project_user_role = $wpdb->get_var($wpdb->prepare("SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $project_id, $cu_user_id)); | |
| 359 | + $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 360 | + $project_users_arr = explode(',',(string)$project_users); | |
| 361 | + } | |
| 362 | + $response = false; | |
| 363 | + $flag = false; | |
| 364 | + if(!empty($task_data)){ | |
| 365 | + $co_worker = $task_data['users']; | |
| 366 | + $co_worker_array = explode(",",(string)$co_worker); | |
| 367 | + } | |
| 368 | + if((!empty($project_user_role)) && ($project_user_role == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 369 | + $flag= true; | |
| 370 | + } | |
| 371 | + if($wppm_current_user_capability=='wppm_admin'){ | |
| 372 | + $flag = true; | |
| 373 | + } | |
| 374 | + if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){ | |
| 375 | + $flag = true; | |
| 376 | + } | |
| 377 | + if($current_user->has_cap('manage_options')){ | |
| 378 | + $flag = true; | |
| 379 | + } | |
| 380 | + if(!empty($project_id)){ | |
| 381 | + $project_id = absint($project_id); | |
| 382 | + $public_proj_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta where project_id= %d AND meta_key='public_project'", $project_id)); | |
| 383 | + }else{ | |
| 384 | + $public_proj_meta =""; | |
| 385 | + } | |
| 386 | + switch ($permission) { | |
| 387 | + case 'change_status': | |
| 388 | + case 'view_task': | |
| 389 | + case 'add_task_comment': | |
| 390 | + ((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array )) )|| ($current_user->ID == $task_data['created_by']) || $public_proj_meta==1 || ($flag==true) || $current_user->has_cap('manage_options') ? $response = true: $response = false; | |
| 391 | + break; | |
| 392 | + case 'change_task_details': | |
| 393 | + (($flag==true) || ($current_user->ID == $task_data['created_by']) || $wppm_edit_tasks_permission == 1) ? $response = true: $response = false; | |
| 394 | + break; | |
| 395 | + case 'add_new_task': | |
| 396 | + (($flag==true) || $wppm_allow_coworkers_create_task == 1) ? $response = true: $response = false; | |
| 397 | + break; | |
| 398 | + case 'add_checklist': | |
| 399 | + (($flag==true) || $wppm_allow_coworkers_add_checklist == 1) ? $response = true: $response = false; | |
| 400 | + break; | |
| 401 | + case 'change_task_status': | |
| 402 | + (($flag==true) || $wppm_allow_coworkers_change_status == 1) ? $response = true: $response = false; | |
| 403 | + break; | |
| 404 | + case 'delete_task': | |
| 405 | + case 'clone_task': | |
| 406 | + (($flag==true) || ($current_user->ID == $task_data['created_by'])) ? $response = true: $response = false; | |
| 407 | + break; | |
| 408 | + case 'assign_task_users': | |
| 409 | + (($flag==true) || $wppm_allow_coworkers_assign_users == 1) ? $response = true: $response = false; | |
| 410 | + break; | |
| 411 | + case 'change_raised_by': | |
| 412 | + case 'edit_checklist': | |
| 413 | + case 'delete_checklist': | |
| 414 | + (($flag==true) ? $response = true: $response = false); | |
| 415 | + break; | |
| 416 | + } | |
| 417 | + return apply_filters( 'wppm_has_permission', $response, $task_id, $permission ); | |
| 418 | + } | |
| 419 | + | |
| 420 | + public function has_comment_permission($permission, $task_id,$comment_id){ | |
| 421 | + global $current_user,$wppmfunction,$wpdb; | |
| 422 | + $task_id = absint($task_id); | |
| 423 | + $comment_id = absint($comment_id); | |
| 424 | + $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 425 | + if(empty($comment_id)){ | |
| 426 | + $comment_id = 0; | |
| 427 | + } | |
| 428 | + $task_data = $wppmfunction->get_task($task_id); | |
| 429 | + $project_user = array(); | |
| 430 | + $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE task_id = %d AND id = %d", $task_id, $comment_id)); | |
| 431 | + | |
| 432 | + if(isset($task_data['project'])){ | |
| 433 | + $project_id = $task_data['project']; | |
| 434 | + $project_id = absint($project_id); | |
| 435 | + $cu_id = absint($current_user->ID); | |
| 436 | + $project_data = $wppmfunction->get_project($project_id); | |
| 437 | + $project_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $project_id, $cu_id)); | |
| 438 | + $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 439 | + $project_users_arr = explode(',',(string)$project_users); | |
| 440 | + } | |
| 441 | + $response = false; | |
| 442 | + $flag = false; | |
| 443 | + if(!empty($task_data)){ | |
| 444 | + $co_worker = $task_data['users']; | |
| 445 | + $co_worker_array = explode(",",(string)$co_worker); | |
| 446 | + } | |
| 447 | + if((!empty($project_user)) && ($project_user->role_id == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 448 | + $flag= true; | |
| 449 | + } | |
| 450 | + if($wppm_current_user_capability=='wppm_admin'){ | |
| 451 | + $flag = true; | |
| 452 | + } | |
| 453 | + | |
| 454 | + if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){ | |
| 455 | + $flag = true; | |
| 456 | + } | |
| 457 | + | |
| 458 | + switch ($permission) { | |
| 459 | + case 'delete_task_thread': | |
| 460 | + case 'edit_task_comment': | |
| 461 | + (($flag==true) || ($current_user->ID == $task_comment->created_by)) ? $response = true: $response = false; | |
| 462 | + break; | |
| 463 | + } | |
| 464 | + return apply_filters( 'wppm_has_comment_permission', $response, $task_id, $comment_id, $permission ); | |
| 465 | + } | |
| 466 | + | |
| 467 | + public function has_proj_comment_permission($permission, $proj_id,$comment_id){ | |
| 468 | + global $current_user,$wppmfunction,$wpdb; | |
| 469 | + $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 470 | + $proj_id = absint($proj_id); | |
| 471 | + $comment_id = absint($comment_id); | |
| 472 | + $cu_id = absint($current_user->ID); | |
| 473 | + if(empty($comment_id)){ | |
| 474 | + $comment_id = 0; | |
| 475 | + } | |
| 476 | + $project_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $proj_id, $cu_id)); | |
| 477 | + $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $proj_id)); | |
| 478 | + $project_users_arr = explode(',',(string)$project_users); | |
| 479 | + $proj_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_comment WHERE proj_id = %d AND id = %d", $proj_id, $comment_id)); | |
| 480 | + $response = false; | |
| 481 | + $flag = false; | |
| 482 | + $project_data = $wppmfunction->get_project($proj_id); | |
| 483 | + if((!empty($project_user)) && ($project_user->role_id == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 484 | + $flag= true; | |
| 485 | + } | |
| 486 | + if($wppm_current_user_capability=='wppm_admin'){ | |
| 487 | + $flag = true; | |
| 488 | + } | |
| 489 | + if(!empty($project_data) && $project_data['created_by']==$current_user->ID && $wppm_current_user_capability=='wppm_manager'){ | |
| 490 | + $flag = true; | |
| 491 | + } | |
| 492 | + switch ($permission) { | |
| 493 | + case 'delete_proj_thread': | |
| 494 | + case 'edit_proj_comment': | |
| 495 | + (($flag==true) || ($current_user->ID == $proj_comment->created_by)) ? $response = true: $response = false; | |
| 496 | + break; | |
| 497 | + } | |
| 498 | + return apply_filters( 'wppm_has_proj_comment_permission', $response, $proj_id, $comment_id, $permission ); | |
| 499 | + } | |
| 500 | + | |
| 501 | + public function has_project_permission($permission,$project_id){ | |
| 502 | + global $current_user,$wppmfunction,$wpdb ; | |
| 503 | + $project_data = $wppmfunction->get_project($project_id); | |
| 504 | + $project_id = absint($project_id); | |
| 505 | + $cu_id = absint($current_user->ID); | |
| 506 | + $project_user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $project_id, $cu_id)); | |
| 507 | + $project_users = $wpdb->get_var($wpdb->prepare("SELECT users FROM {$wpdb->prefix}wppm_project WHERE id = %d", $project_id)); | |
| 508 | + $project_users_arr = explode(',',(string)$project_users); | |
| 509 | + $user = wp_get_current_user(); | |
| 510 | + $wppm_current_user_capability = get_user_meta( $current_user->ID, 'wppm_capability', true ); | |
| 511 | + if(!empty($project_data)){ | |
| 512 | + $co_worker = $project_data['users']; | |
| 513 | + $co_worker_array = explode(",",(string)$co_worker); | |
| 514 | + } | |
| 515 | + if(!empty($project_id)){ | |
| 516 | + $public_proj_meta = $wpdb->get_var( $wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta where project_id= %d AND meta_key='public_project'", $project_id)); | |
| 517 | + }else{ | |
| 518 | + $public_proj_meta =""; | |
| 519 | + } | |
| 520 | + | |
| 521 | + switch ($permission) { | |
| 522 | + case 'view_project': | |
| 523 | + ((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array )) )? $response = true: $response = false; | |
| 524 | + break; | |
| 525 | + case 'add_proj_comment': | |
| 526 | + ( ((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array )) ) || ( $public_proj_meta == '1') || $current_user->has_cap('manage_options')|| $wppm_current_user_capability == 'wppm_admin' || $wppm_current_user_capability == 'wppm_manager')? $response = true: $response = false; | |
| 527 | + break; | |
| 528 | + case 'change_project_status': | |
| 529 | + case 'assign_project_users': | |
| 530 | + case 'change_project_raised_by': | |
| 531 | + case 'change_project_details': | |
| 532 | + case 'delete_project': | |
| 533 | + $flag = false; | |
| 534 | + if( (!empty($project_user)) && ($project_user->role_id == 1) && in_array($current_user->ID,$project_users_arr)){ | |
| 535 | + $flag = true; | |
| 536 | + } | |
| 537 | + | |
| 538 | + (((!empty($co_worker_array)) && (in_array($current_user->ID,$co_worker_array) && $flag==true) || $wppm_current_user_capability == 'wppm_admin')) ? $response = true: $response = false; | |
| 539 | + break; | |
| 540 | + } | |
| 541 | + return apply_filters( 'wppm_has_project_permission', $response, $project_id, $permission ); | |
| 542 | + } | |
| 543 | + | |
| 544 | + public function change_status($task_id, $status_id){ | |
| 545 | + global $wpdb,$wppmfunction; | |
| 546 | + $task_data = $wppmfunction->get_task($task_id); | |
| 547 | + $prev_status = $task_data['status']; | |
| 548 | + $values=array( | |
| 549 | + 'status'=>esc_sql($status_id) | |
| 550 | + ); | |
| 551 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>esc_sql($task_id))); | |
| 552 | + $old_task_status_meta = $wppmfunction->get_task_meta($task_id,'old_task_status',true); | |
| 553 | + if(!empty($old_task_status_meta)){ | |
| 554 | + $wppmfunction->delete_task_meta($task_id,'old_task_status'); | |
| 555 | + } | |
| 556 | + $wppmfunction->add_task_meta($task_id,'old_task_status',$prev_status); | |
| 557 | + | |
| 558 | + do_action('wppm_set_change_task_status', $task_id, $status_id, $prev_status); | |
| 559 | + } | |
| 560 | + | |
| 561 | + public function change_raised_by($task_id, $user_id){ | |
| 562 | + global $wpdb; | |
| 563 | + $values=array( | |
| 564 | + 'created_by'=>absint($user_id) | |
| 565 | + ); | |
| 566 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 567 | + } | |
| 568 | + | |
| 569 | + public function change_task_label($task_id, $task_label){ | |
| 570 | + global $wpdb; | |
| 571 | + $values=array( | |
| 572 | + 'task_name'=>stripslashes($task_label) | |
| 573 | + ); | |
| 574 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 575 | + } | |
| 576 | + | |
| 577 | + public function change_task_project_label($task_id, $project_label){ | |
| 578 | + global $wpdb; | |
| 579 | + $values=array( | |
| 580 | + 'project'=>absint($project_label) | |
| 581 | + ); | |
| 582 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 583 | + } | |
| 584 | + | |
| 585 | + public function change_start_date($task_id, $task_start_date){ | |
| 586 | + global $wpdb; | |
| 587 | + $values=array( | |
| 588 | + 'start_date'=>$task_start_date | |
| 589 | + ); | |
| 590 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 591 | + } | |
| 592 | + | |
| 593 | + public function change_end_date($task_id, $task_end_date){ | |
| 594 | + global $wpdb; | |
| 595 | + $values=array( | |
| 596 | + 'end_date'=>$task_end_date | |
| 597 | + ); | |
| 598 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 599 | + } | |
| 600 | + | |
| 601 | + public function change_priority($task_id, $task_priority){ | |
| 602 | + global $wpdb; | |
| 603 | + $values=array( | |
| 604 | + 'priority'=>absint($task_priority) | |
| 605 | + ); | |
| 606 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 607 | + } | |
| 608 | + | |
| 609 | + public function change_description($task_id, $task_description){ | |
| 610 | + global $wpdb; | |
| 611 | + $task_description = !empty($task_description) ? wp_kses_post($task_description) : ''; | |
| 612 | + $values=array( | |
| 613 | + 'description'=>$task_description | |
| 614 | + ); | |
| 615 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 616 | + } | |
| 617 | + | |
| 618 | + public function change_project($task_id,$proj_id){ | |
| 619 | + global $wpdb,$wppmfunction; | |
| 620 | + $task_data = $wppmfunction->get_task($task_id); | |
| 621 | + $old_proj = $task_data['project']; | |
| 622 | + $old_proj = absint( $old_proj); | |
| 623 | + $proj_id = absint( $proj_id); | |
| 624 | + $project_data = $wppmfunction->get_project($proj_id); | |
| 625 | + $task_assign_users = $task_data['users']; | |
| 626 | + $tusers_array = array(); | |
| 627 | + if(!empty($task_data['users'])){ | |
| 628 | + $task_users_array = explode(",",(string)$task_assign_users); | |
| 629 | + } | |
| 630 | + if(!empty($project_data['users'])){ | |
| 631 | + $project_users = explode(",",(string)$project_data['users']); | |
| 632 | + } | |
| 633 | + if(!empty($project_users)){ | |
| 634 | + if(!empty($task_users_array)){ | |
| 635 | + foreach($task_users_array as $tuser){ | |
| 636 | + if(!in_array($tuser,$project_users)){ | |
| 637 | + $wpdb->delete( $wpdb->prefix.'wppm_project_users', array( 'proj_id' => "$proj_id",'user_id'=>"$tuser") ); | |
| 638 | + } | |
| 639 | + elseif(in_array($tuser,$project_users)){ | |
| 640 | + $tusers_array[] = $tuser; | |
| 641 | + $tuser = absint($tuser); | |
| 642 | + $sql = $wpdb->prepare("SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $old_proj, $tuser); | |
| 643 | + $old_proj_user_role = $wpdb->get_var( $sql ); | |
| 644 | + $sql = $wpdb->prepare("SELECT role_id FROM {$wpdb->prefix}wppm_project_users WHERE proj_id = %d AND user_id = %d", $proj_id, $tuser); | |
| 645 | + $proj_users_role = $wpdb->get_var( $sql ); | |
| 646 | + if(!empty( $old_proj_user_role) && $old_proj_user_role!=$proj_users_role){ | |
| 647 | + $value=array( | |
| 648 | + 'role_id'=>absint($proj_users_role) | |
| 649 | + ); | |
| 650 | + $wpdb->update($wpdb->prefix.'wppm_project_users', $value, array('proj_id'=>"$proj_id", 'user_id'=>"$tuser")); | |
| 651 | + } | |
| 652 | + } | |
| 653 | + } | |
| 654 | + } | |
| 655 | + } | |
| 656 | + $tusers = implode(",",$tusers_array); | |
| 657 | + $values=array( | |
| 658 | + 'project'=>absint($proj_id), | |
| 659 | + 'users'=>absint($tusers) | |
| 660 | + ); | |
| 661 | + $wpdb->update($wpdb->prefix.'wppm_task', $values, array('id'=>absint($task_id))); | |
| 662 | + } | |
| 663 | + | |
| 664 | + public function get_task_comment($comment_id){ | |
| 665 | + global $wpdb; | |
| 666 | + $task_comment_data = array(); | |
| 667 | + $comment_id = absint($comment_id); | |
| 668 | + $task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment WHERE id=%d", $comment_id)); | |
| 669 | + if( $task_comment ){ | |
| 670 | + $task_comment_data = json_decode(wp_json_encode($task_comment), true); | |
| 671 | + } | |
| 672 | + return $task_comment_data; | |
| 673 | + } | |
| 674 | + | |
| 675 | + public function get_proj_comment($comment_id){ | |
| 676 | + global $wpdb; | |
| 677 | + $project_comment_data = array(); | |
| 678 | + $comment_id = absint($comment_id); | |
| 679 | + $project_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_comment WHERE id=%d", $comment_id)); | |
| 680 | + if( $project_comment ){ | |
| 681 | + $project_comment_data = json_decode(wp_json_encode($project_comment), true); | |
| 682 | + } | |
| 683 | + return $project_comment_data; | |
| 684 | + } | |
| 685 | + | |
| 686 | + public function change_task_comment($comment_id,$comment_body){ | |
| 687 | + global $wpdb; | |
| 688 | + $comment_id = absint($comment_id); | |
| 689 | + $comment_body = !empty($comment_body) ? wp_kses_post($comment_body) : ''; | |
| 690 | + $values=array( | |
| 691 | + 'body'=>$comment_body | |
| 692 | + ); | |
| 693 | + $wpdb->update($wpdb->prefix.'wppm_task_comment', $values, array('id'=>"$comment_id")); | |
| 694 | + } | |
| 695 | + | |
| 696 | + public function change_proj_comment($comment_id,$comment_body){ | |
| 697 | + global $wpdb; | |
| 698 | + $comment_id = absint($comment_id); | |
| 699 | + $comment_body = !empty($comment_body) ? wp_kses_post($comment_body) : ''; | |
| 700 | + $values=array( | |
| 701 | + 'body'=>$comment_body | |
| 702 | + ); | |
| 703 | + $wpdb->update($wpdb->prefix.'wppm_project_comment', $values, array('id'=>"$comment_id")); | |
| 704 | + } | |
| 705 | + | |
| 706 | + public function change_project_label($project_id,$project_label){ | |
| 707 | + global $wpdb; | |
| 708 | + $project_id = absint($project_id); | |
| 709 | + $values=array( | |
| 710 | + 'project_name'=>esc_sql($project_label) | |
| 711 | + ); | |
| 712 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 713 | + } | |
| 714 | + | |
| 715 | + public function change_project_start_date($project_id, $project_start_date){ | |
| 716 | + global $wpdb; | |
| 717 | + $project_id = absint($project_id); | |
| 718 | + $project_start_date = esc_sql($project_start_date); | |
| 719 | + $values=array( | |
| 720 | + 'start_date'=>$project_start_date | |
| 721 | + ); | |
| 722 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 723 | + } | |
| 724 | + | |
| 725 | + public function change_project_end_date($project_id, $project_end_date){ | |
| 726 | + global $wpdb; | |
| 727 | + $project_id = absint($project_id); | |
| 728 | + $project_end_date = esc_sql($project_end_date); | |
| 729 | + $values=array( | |
| 730 | + 'end_date'=>$project_end_date | |
| 731 | + ); | |
| 732 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>$project_id)); | |
| 733 | + } | |
| 734 | + | |
| 735 | + public function change_category($project_id, $project_category){ | |
| 736 | + global $wpdb; | |
| 737 | + $project_id = absint($project_id); | |
| 738 | + $project_category = absint($project_category); | |
| 739 | + $values=array( | |
| 740 | + 'cat_id'=>$project_category | |
| 741 | + ); | |
| 742 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 743 | + } | |
| 744 | + | |
| 745 | + public function change_project_description($project_id, $project_description){ | |
| 746 | + global $wpdb; | |
| 747 | + $project_id = absint($project_id); | |
| 748 | + $project_description = (string) ( $project_description ?? '' ); | |
| 749 | + $values = array( | |
| 750 | + 'description' => wp_kses_post( $project_description ) | |
| 751 | + ); | |
| 752 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 753 | + } | |
| 754 | + | |
| 755 | + public function change_project_status($project_id,$status_id){ | |
| 756 | + global $wpdb,$wppmfunction,$current_user; | |
| 757 | + $change_status_value= array(); | |
| 758 | + $proj_data = $wppmfunction->get_project($project_id); | |
| 759 | + $prev_status = $proj_data['status']; | |
| 760 | + $cu_id = absint($current_user->ID); | |
| 761 | + $values=array( | |
| 762 | + 'status'=>absint($status_id) | |
| 763 | + ); | |
| 764 | + $project_id = absint($project_id); | |
| 765 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>$project_id)); | |
| 766 | + $old_project_status_meta = $wppmfunction->get_project_meta($project_id,'old_project_status',true); | |
| 767 | + if(!empty($old_project_status_meta)){ | |
| 768 | + $wppmfunction->delete_project_meta($project_id,'old_project_status'); | |
| 769 | + } | |
| 770 | + $change_status_value = array('prev_status'=>"$prev_status",'new_status'=>"$status_id"); | |
| 771 | + $change_status_obj = serialize($change_status_value); | |
| 772 | + $log_values = array('proj_id'=>"$project_id",'body'=>$change_status_obj,'attachment_ids'=>"",'create_time'=>wp_date("Y-m-d h:i:sa"),'created_by'=>"$cu_id" ); | |
| 773 | + $wpdb->insert($wpdb->prefix . 'wppm_project_comment',$log_values); | |
| 774 | + $log_id = absint($wpdb->insert_id); | |
| 775 | + $proj_log_values = array('proj_id'=>"$project_id",'comment_id'=>"$log_id",'comment_type'=>'change_proj_status'); | |
| 776 | + $wpdb->insert($wpdb->prefix . 'wppm_project_comment_meta',$proj_log_values); | |
| 777 | + $wppmfunction->add_project_meta($project_id,'old_project_status',$prev_status); | |
| 778 | + do_action('wppm_set_change_project_status', $project_id, $status_id, $prev_status); | |
| 779 | + } | |
| 780 | + | |
| 781 | + public function change_project_raised_by($project_id, $user_id){ | |
| 782 | + global $wpdb; | |
| 783 | + $values=array( | |
| 784 | + 'created_by'=>absint($user_id) | |
| 785 | + ); | |
| 786 | + $wpdb->update($wpdb->prefix.'wppm_project', $values, array('id'=>"$project_id")); | |
| 787 | + } | |
| 788 | + | |
| 789 | + // Email Notification types | |
| 790 | + public function get_email_notification_types(){ | |
| 791 | + $notification_types = array( | |
| 792 | + 'new_project'=>esc_html__('New Project','taskbuilder'), | |
| 793 | + 'new_task'=>esc_html__('New Task','taskbuilder'), | |
| 794 | + 'change_project_status' => esc_html__('Change Project Status','taskbuilder'), | |
| 795 | + 'change_task_status' => esc_html__('Change Task Status','taskbuilder'), | |
| 796 | + 'change_project_assign_users' => esc_html__('Change Project Assign Users','taskbuilder'), | |
| 797 | + 'change_task_assign_users' => esc_html__('Change Task Assign Users','taskbuilder'), | |
| 798 | + 'new_discussion' => esc_html__('New Comment','taskbuilder'), | |
| 799 | + 'new_proj_discussion' =>esc_html__('New Project Comment','taskbuilder') | |
| 800 | + ); | |
| 801 | + return apply_filters('wppm_en_types',$notification_types); | |
| 802 | + } | |
| 803 | + | |
| 804 | + public function check_rtl(){ | |
| 805 | + $rtl_locale = array('ar','ary','ckb','haz','he_IL','fa_IR','ps','ur','ug_CN'); | |
| 806 | + if(in_array(get_locale(),$rtl_locale)){ | |
| 807 | + return 'rtl'; | |
| 808 | + }else{ | |
| 809 | + return 'ltr'; | |
| 810 | + } | |
| 811 | + } | |
| 812 | + | |
| 813 | + public function add_project_meta($proj_id,$meta_key,$meta_value){ | |
| 814 | + global $wpdb; | |
| 815 | + $wpdb->insert( | |
| 816 | + $wpdb->prefix . 'wppm_project_meta', | |
| 817 | + array( | |
| 818 | + 'project_id' =>$proj_id, | |
| 819 | + 'meta_key' => $meta_key, | |
| 820 | + 'meta_value' =>$meta_value | |
| 821 | + )); | |
| 822 | + } | |
| 823 | + | |
| 824 | + public function add_task_meta($task_id,$meta_key,$meta_value){ | |
| 825 | + global $wpdb; | |
| 826 | + $wpdb->insert( | |
| 827 | + $wpdb->prefix . 'wppm_task_meta', | |
| 828 | + array( | |
| 829 | + 'task_id' => $task_id, | |
| 830 | + 'meta_key' => $meta_key, | |
| 831 | + 'meta_value' =>$meta_value | |
| 832 | + )); | |
| 833 | + } | |
| 834 | + | |
| 835 | + public function get_project_meta($project_id,$meta_key,$flag = false){ | |
| 836 | + global $wpdb,$wppmfunction; | |
| 837 | + $project_id = absint($project_id); | |
| 838 | + $meta_key = esc_sql($meta_key); | |
| 839 | + if($flag){ | |
| 840 | + $get_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key = %s",$project_id,$meta_key)); | |
| 841 | + $project_meta = isset($get_meta) ? stripslashes($get_meta) : ''; | |
| 842 | + | |
| 843 | + } else { | |
| 844 | + $project_meta = array(); | |
| 845 | + $results = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key = %s",$project_id,$meta_key)); | |
| 846 | + if( (!empty($results)) ){ | |
| 847 | + foreach ($results as $result) { | |
| 848 | + if(!empty($result)){ | |
| 849 | + $project_meta[]= stripslashes($result->meta_value); | |
| 850 | + } | |
| 851 | + } | |
| 852 | + } | |
| 853 | + } | |
| 854 | + return $project_meta; | |
| 855 | + } | |
| 856 | + | |
| 857 | + public function get_task_meta($task_id,$meta_key,$flag = false){ | |
| 858 | + global $wpdb,$wppmfunction; | |
| 859 | + $task_id = absint($task_id); | |
| 860 | + $meta_key = esc_sql($meta_key); | |
| 861 | + if($flag){ | |
| 862 | + $get_meta = $wpdb->get_var($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_task_meta WHERE task_id = %d AND meta_key = %s",$task_id,$meta_key)); | |
| 863 | + $task_meta = isset($get_meta) ? stripslashes($get_meta) : ''; | |
| 864 | + | |
| 865 | + } else { | |
| 866 | + $task_meta = array(); | |
| 867 | + $results = $wpdb->get_results($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}wppm_task_meta WHERE task_id = %d AND meta_key = %s",$task_id,$meta_key)); | |
| 868 | + if( (!empty($results)) ){ | |
| 869 | + foreach ($results as $result) { | |
| 870 | + if(!empty($result)){ | |
| 871 | + $task_meta[]= stripslashes($result->meta_value); | |
| 872 | + } | |
| 873 | + } | |
| 874 | + } | |
| 875 | + } | |
| 876 | + return $task_meta; | |
| 877 | + } | |
| 878 | + | |
| 879 | + public function get_previously_assigned_users($project_id){ | |
| 880 | + global $wpdb,$wppmfunction; | |
| 881 | + $prev_assigned_users = $wppmfunction->get_project_meta($project_id,'prev_assigned_users'); | |
| 882 | + $user_emails = array(); | |
| 883 | + if(!empty($prev_assigned_users)){ | |
| 884 | + foreach ($prev_assigned_users as $user) { | |
| 885 | + $userdata = get_userdata($user); | |
| 886 | + $user_emails[] = $userdata->user_email; | |
| 887 | + | |
| 888 | + } | |
| 889 | + } | |
| 890 | + return apply_filters( 'wppm_get_prev_assigned_users_emails', $user_emails ,$project_id); | |
| 891 | + } | |
| 892 | + | |
| 893 | + public function get_project_creator_email($project_id){ | |
| 894 | + global $wpdb,$wppmfunction; | |
| 895 | + $project_data = $wppmfunction->get_project($project_id,'created_by'); | |
| 896 | + $userdata = get_userdata($project_data['created_by']); | |
| 897 | + if(!empty( $userdata)){ | |
| 898 | + $proj_creator_email[] = $userdata->user_email; | |
| 899 | + } | |
| 900 | + return apply_filters( 'wppm_get_project_creator_email', $proj_creator_email ,$project_id); | |
| 901 | + } | |
| 902 | + | |
| 903 | + public function get_task_creator_email($task_id){ | |
| 904 | + global $wpdb,$wppmfunction; | |
| 905 | + $task_data = $wppmfunction->get_task($task_id,'created_by'); | |
| 906 | + $userdata = get_userdata($task_data['created_by']); | |
| 907 | + if(!empty( $userdata)){ | |
| 908 | + $task_creator_email[] = $userdata->user_email; | |
| 909 | + } | |
| 910 | + return apply_filters( 'wppm_get_task_creator_email', $task_creator_email ,$task_id); | |
| 911 | + } | |
| 912 | + | |
| 913 | + public function get_previously_assigned_task_users($task_id){ | |
| 914 | + global $wpdb,$wppmfunction; | |
| 915 | + $prev_assigned_task_users = $wppmfunction->get_task_meta($task_id,'prev_assigned_task_users'); | |
| 916 | + $user_emails = array(); | |
| 917 | + if(!empty($prev_assigned_task_users)){ | |
| 918 | + foreach ($prev_assigned_task_users as $user) { | |
| 919 | + if(!empty($user)){ | |
| 920 | + $userdata = get_userdata($user); | |
| 921 | + $user_emails[] = $userdata->user_email; | |
| 922 | + } | |
| 923 | + } | |
| 924 | + } | |
| 925 | + return apply_filters( 'wppm_get_prev_assigned_task_users_emails', $user_emails ,$task_id); | |
| 926 | + } | |
| 927 | + /** | |
| 928 | + * Update project meta for project | |
| 929 | + */ | |
| 930 | + function update_project_meta($project_id ,$meta_key ,$meta_value){ | |
| 931 | + global $wpdb; | |
| 932 | + $project_id = absint($project_id); | |
| 933 | + $meta_key = esc_sql($meta_key); | |
| 934 | + $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_project_meta WHERE project_id = %d AND meta_key = %s",$project_id,$meta_key)); | |
| 935 | + $wpdb->update($wpdb->prefix.'wppm_project_meta', $meta_value, array('project_id'=>$project_id,'meta_key' => "$meta_key")); | |
| 936 | + } | |
| 937 | + | |
| 938 | + /** | |
| 939 | + * Update task meta for task | |
| 940 | + */ | |
| 941 | + function update_task_meta($task_id ,$meta_key ,$meta_value){ | |
| 942 | + global $wpdb; | |
| 943 | + $task_id = absint($task_id); | |
| 944 | + $meta_key = esc_sql($meta_key); | |
| 945 | + $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_meta WHERE task_id = %d AND meta_key = %s",$task_id,$meta_key)); | |
| 946 | + $wpdb->update($wpdb->prefix.'wppm_task_meta', $meta_value, array('task_id'=>$task_id,'meta_key' => "$meta_key")); | |
| 947 | + } | |
| 948 | + | |
| 949 | + function delete_project_meta($project_id ,$meta_key){ | |
| 950 | + global $wpdb; | |
| 951 | + $project_id = absint($project_id); | |
| 952 | + $meta_key = ($meta_key); | |
| 953 | + $wpdb->delete( $wpdb->prefix.'wppm_project_meta', array( 'project_id' => "$project_id",'meta_key'=>"$meta_key") ); | |
| 954 | + } | |
| 955 | + | |
| 956 | + function delete_task_meta($task_id ,$meta_key){ | |
| 957 | + global $wpdb; | |
| 958 | + $task_id = absint($task_id); | |
| 959 | + $meta_key = ($meta_key); | |
| 960 | + $wpdb->delete( $wpdb->prefix.'wppm_task_meta', array( 'task_id' => "$task_id",'meta_key'=>"$meta_key") ); | |
| 961 | + } | |
| 962 | + | |
| 963 | + public function replace_macro($str,$project_id){ | |
| 964 | + include WPPM_ABSPATH . 'includes/replace_macro.php'; | |
| 965 | + return $str; | |
| 966 | + } | |
| 967 | + | |
| 968 | + public function replace_task_macro($str,$task_id){ | |
| 969 | + include WPPM_ABSPATH . 'includes/replace_task_macro.php'; | |
| 970 | + return $str; | |
| 971 | + } | |
| 972 | + | |
| 973 | + public function get_old_project_status_name($id){ | |
| 974 | + global $wppmfunction, $wpdb; | |
| 975 | + $old_project_status = $wppmfunction->get_project_meta($id,'old_project_status',true); | |
| 976 | + $old_project_status = absint($old_project_status); | |
| 977 | + $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_project_statuses WHERE id = %d",$old_project_status)); | |
| 978 | + return $status_name; | |
| 979 | + } | |
| 980 | + | |
| 981 | + public function get_new_project_status_name($status_id){ | |
| 982 | + global $wpdb; | |
| 983 | + $status_id = absint($status_id); | |
| 984 | + $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_project_statuses WHERE id = %d",$status_id)); | |
| 985 | + return $status_name; | |
| 986 | + } | |
| 987 | + | |
| 988 | + public function get_old_task_status_name($task_id){ | |
| 989 | + global $wppmfunction, $wpdb; | |
| 990 | + $old_task_status = $wppmfunction->get_task_meta($task_id,'old_task_status',true); | |
| 991 | + $old_task_status = absint($old_task_status); | |
| 992 | + $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_task_statuses WHERE id = %d",$old_task_status)); | |
| 993 | + return $status_name; | |
| 994 | + } | |
| 995 | + | |
| 996 | + public function get_new_task_status_name($status_id){ | |
| 997 | + global $wpdb; | |
| 998 | + $status_id = absint($status_id); | |
| 999 | + $status_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_task_statuses WHERE id = %d",$status_id)); | |
| 1000 | + return $status_name; | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + public function get_project_category_name($cat_id){ | |
| 1004 | + global $wpdb; | |
| 1005 | + $cat_id = absint($cat_id); | |
| 1006 | + if(!empty($cat_id)){ | |
| 1007 | + $cat_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_project_categories WHERE id = %d",$cat_id)); | |
| 1008 | + }else{ | |
| 1009 | + $cat_name = ""; | |
| 1010 | + } | |
| 1011 | + return $cat_name; | |
| 1012 | + } | |
| 1013 | + | |
| 1014 | + public function get_project_assigned_users_names($project_id){ | |
| 1015 | + global $wppmfunction; | |
| 1016 | + $wppm_project_data = $wppmfunction->get_project($project_id); | |
| 1017 | + if(!empty($wppm_project_data['users'])){ | |
| 1018 | + $wppm_project_assign_users_array = explode(",", $wppm_project_data['users']); | |
| 1019 | + }else{ | |
| 1020 | + $wppm_project_assign_users_array = array(); | |
| 1021 | + } | |
| 1022 | + $users_names = array(); | |
| 1023 | + if(!empty($wppm_project_assign_users_array)){ | |
| 1024 | + foreach ($wppm_project_assign_users_array as $user_id) { | |
| 1025 | + if(!empty($user_id)){ | |
| 1026 | + $userdata = get_userdata( $user_id ); | |
| 1027 | + if(!empty($userdata)){ | |
| 1028 | + $users_names[] = $userdata->display_name; | |
| 1029 | + } | |
| 1030 | + } | |
| 1031 | + } | |
| 1032 | + } | |
| 1033 | + return implode(', ', $users_names); | |
| 1034 | + } | |
| 1035 | + | |
| 1036 | + public function get_task_assigned_users_names($task_id){ | |
| 1037 | + global $wppmfunction; | |
| 1038 | + $wppm_task_data = $wppmfunction->get_task($task_id); | |
| 1039 | + $wppm_task_assign_users_array = explode(",", (string)$wppm_task_data['users']); | |
| 1040 | + $users_names = array(); | |
| 1041 | + if(!empty($wppm_task_assign_users_array)){ | |
| 1042 | + foreach ($wppm_task_assign_users_array as $user_id) { | |
| 1043 | + if(!empty($user_id)){ | |
| 1044 | + $userdata = get_userdata( $user_id ); | |
| 1045 | + if(!empty($userdata)){ | |
| 1046 | + $users_names[] = $userdata->display_name; | |
| 1047 | + } | |
| 1048 | + } | |
| 1049 | + } | |
| 1050 | + } | |
| 1051 | + return implode(', ', $users_names); | |
| 1052 | + } | |
| 1053 | + | |
| 1054 | + public function get_project_previously_assigned_users_names($project_id){ | |
| 1055 | + global $wppmfunction; | |
| 1056 | + $wppm_project_assign_users = $wppmfunction->get_project_meta($project_id,'prev_assigned_users'); | |
| 1057 | + $users_names = array(); | |
| 1058 | + if(!empty($wppm_project_assign_users)){ | |
| 1059 | + foreach ($wppm_project_assign_users as $user) { | |
| 1060 | + if(!empty($user)){ | |
| 1061 | + $userdata = get_userdata( $user ); | |
| 1062 | + $users_names[] = $userdata->display_name; | |
| 1063 | + } | |
| 1064 | + } | |
| 1065 | + } | |
| 1066 | + return implode(', ', $users_names); | |
| 1067 | + } | |
| 1068 | + | |
| 1069 | + public function get_task_previously_assigned_users_names($task_id){ | |
| 1070 | + global $wppmfunction; | |
| 1071 | + $wppm_task_assign_users = $wppmfunction->get_task_meta($task_id,'prev_assigned_task_users'); | |
| 1072 | + $users_names = array(); | |
| 1073 | + if(!empty($wppm_task_assign_users)){ | |
| 1074 | + foreach ($wppm_task_assign_users as $user) { | |
| 1075 | + if(!empty($user)){ | |
| 1076 | + $userdata = get_userdata( $user ); | |
| 1077 | + $users_names[] = $userdata->display_name; | |
| 1078 | + } | |
| 1079 | + } | |
| 1080 | + } | |
| 1081 | + return implode(', ', $users_names); | |
| 1082 | + } | |
| 1083 | + | |
| 1084 | + public function get_task_priority_name($priority){ | |
| 1085 | + global $wpdb; | |
| 1086 | + $priority = absint($priority); | |
| 1087 | + $priority_name = $wpdb->get_var($wpdb->prepare("SELECT name FROM {$wpdb->prefix}wppm_task_priorities WHERE id = %d",$priority)); | |
| 1088 | + return $priority_name; | |
| 1089 | + } | |
| 1090 | + | |
| 1091 | + public function get_last_comment_user_name($task_id){ | |
| 1092 | + global $wpdb; | |
| 1093 | + $task_id = absint($task_id); | |
| 1094 | + $task_comment_creator = $wpdb->get_var($wpdb->prepare("SELECT created_by FROM {$wpdb->prefix}wppm_task_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_task_comment) AND task_id = %d)",$task_id)); | |
| 1095 | + if(!empty($task_comment_creator)){ | |
| 1096 | + $user = get_userdata( $task_comment_creator ); | |
| 1097 | + return $user->display_name; | |
| 1098 | + } | |
| 1099 | + } | |
| 1100 | + | |
| 1101 | + public function get_last_comment_body($task_id){ | |
| 1102 | + global $wpdb; | |
| 1103 | + $task_id = absint($task_id); | |
| 1104 | + $task_comment = $wpdb->get_var($wpdb->prepare("SELECT body FROM {$wpdb->prefix}wppm_task_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_task_comment) AND task_id = %d)",$task_id)); | |
| 1105 | + return $task_comment; | |
| 1106 | + } | |
| 1107 | + | |
| 1108 | + public function create_duplicate_task($ptask_id, $project_id,$internal_code_flag=false){ | |
| 1109 | + include WPPM_ABSPATH . 'includes/admin/tasks/open_task/wppm_set_clone_task.php'; | |
| 1110 | + } | |
| 1111 | + | |
| 1112 | + public function get_last_comment_proj_user_name($project_id){ | |
| 1113 | + global $wpdb; | |
| 1114 | + $project_id = absint($project_id); | |
| 1115 | + $proj_comment_creator = $wpdb->get_var($wpdb->prepare("SELECT created_by FROM {$wpdb->prefix}wppm_project_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_project_comment) AND proj_id = %d)",$project_id)); | |
| 1116 | + if(!empty($proj_comment_creator)){ | |
| 1117 | + $user = get_userdata( $proj_comment_creator ); | |
| 1118 | + return $user->display_name; | |
| 1119 | + } | |
| 1120 | + } | |
| 1121 | + | |
| 1122 | + public function get_proj_comment_body($project_id){ | |
| 1123 | + global $wpdb; | |
| 1124 | + $project_id = absint($project_id); | |
| 1125 | + $proj_comment = $wpdb->get_var($wpdb->prepare("SELECT body FROM {$wpdb->prefix}wppm_project_comment WHERE (id=(select MAX(id) from {$wpdb->prefix}wppm_project_comment) AND proj_id = %d)",$project_id)); | |
| 1126 | + return $proj_comment; | |
| 1127 | + } | |
| 1128 | + | |
| 1129 | + public function get_project_url($project_id, $view){ | |
| 1130 | + global $wpdb,$wppmfunction; | |
| 1131 | + $project_id = absint($project_id); | |
| 1132 | + $page_settings = get_option( 'wppm-page-settings' ); | |
| 1133 | + if ( $view == '0' ) { | |
| 1134 | + $url = admin_url( 'admin.php?page=wppm-projects§ion=project-list&id=' . $project_id ); | |
| 1135 | + } else { | |
| 1136 | + $url = get_permalink( $page_settings['project-url-page'] ); | |
| 1137 | + $auth_id = $wppmfunction->get_project_meta($project_id,'project_auth_code',true); | |
| 1138 | + | |
| 1139 | + $url = add_query_arg( | |
| 1140 | + array( | |
| 1141 | + 'project-id' => $project_id, | |
| 1142 | + 'auth-code' => $auth_id, | |
| 1143 | + | |
| 1144 | + ), | |
| 1145 | + $url | |
| 1146 | + ); | |
| 1147 | + } | |
| 1148 | + | |
| 1149 | + return $url; | |
| 1150 | + } | |
| 1151 | + | |
| 1152 | + public function get_task_url($task_id, $view){ | |
| 1153 | + global $wpdb,$wppmfunction; | |
| 1154 | + $task_id = absint($task_id); | |
| 1155 | + $page_settings = get_option( 'wppm-page-settings' ); | |
| 1156 | + if ( $view == '0' ) { | |
| 1157 | + $url = admin_url( 'admin.php?page=wppm-tasks§ion=task-list&id=' . $task_id ); | |
| 1158 | + } else{ | |
| 1159 | + $url = get_permalink( $page_settings['task-url-page'] ); | |
| 1160 | + $auth_id = $this->wppm_get_auth_code($task_id); | |
| 1161 | + $url = add_query_arg( | |
| 1162 | + array( | |
| 1163 | + 'task-id' => $task_id, | |
| 1164 | + 'auth-code' => $auth_id, | |
| 1165 | + ), | |
| 1166 | + $url | |
| 1167 | + ); | |
| 1168 | + | |
| 1169 | + } | |
| 1170 | + | |
| 1171 | + return $url; | |
| 1172 | + } | |
| 1173 | + | |
| 1174 | + public function wppm_user_role(){ | |
| 1175 | + $user_role = array( | |
| 1176 | + 'wppm_admin' => array( | |
| 1177 | + 'label' => esc_html__('WPPM Administrator','taskbuilder'), | |
| 1178 | + ), | |
| 1179 | + 'wppm_manager' => array( | |
| 1180 | + 'label' => esc_html__('WPPM Manager','taskbuilder'), | |
| 1181 | + ) | |
| 1182 | + ); | |
| 1183 | + return $user_role; | |
| 1184 | + } | |
| 1185 | + | |
| 1186 | + public static function wppm_toolbar_options_setting() { | |
| 1187 | + $toolbar = array( | |
| 1188 | + array( | |
| 1189 | + 'name' => esc_attr__( 'Bold', 'taskbuilder' ), | |
| 1190 | + 'value' => 'bold', | |
| 1191 | + ), | |
| 1192 | + array( | |
| 1193 | + 'name' => esc_attr__( 'Italic', 'taskbuilder' ), | |
| 1194 | + 'value' => 'italic', | |
| 1195 | + ), | |
| 1196 | + array( | |
| 1197 | + 'name' => esc_attr__( 'Underline', 'taskbuilder' ), | |
| 1198 | + 'value' => 'underline', | |
| 1199 | + ), | |
| 1200 | + array( | |
| 1201 | + 'name' => esc_attr__( 'Blockquote', 'taskbuilder' ), | |
| 1202 | + 'value' => 'blockquote', | |
| 1203 | + ), | |
| 1204 | + array( | |
| 1205 | + 'name' => esc_attr__( 'Align', 'taskbuilder' ), | |
| 1206 | + 'value' => 'align', | |
| 1207 | + ), | |
| 1208 | + array( | |
| 1209 | + 'name' => esc_attr__( 'Bulleted list', 'taskbuilder' ), | |
| 1210 | + 'value' => 'bullist', | |
| 1211 | + ), | |
| 1212 | + array( | |
| 1213 | + 'name' => esc_attr__( 'Numbered list', 'taskbuilder' ), | |
| 1214 | + 'value' => 'numlist', | |
| 1215 | + ), | |
| 1216 | + array( | |
| 1217 | + 'name' => esc_attr__( 'Right to left', 'taskbuilder' ), | |
| 1218 | + 'value' => 'rtl', | |
| 1219 | + ), | |
| 1220 | + array( | |
| 1221 | + 'name' => esc_attr__( 'Link', 'taskbuilder' ), | |
| 1222 | + 'value' => 'link', | |
| 1223 | + ), | |
| 1224 | + array( | |
| 1225 | + 'name' => esc_attr__( 'Image', 'taskbuilder' ), | |
| 1226 | + 'value' => 'wppm_insert_editor_img', | |
| 1227 | + ), | |
| 1228 | + array( | |
| 1229 | + 'name' => esc_attr__( 'Text Color', 'taskbuilder' ), | |
| 1230 | + 'value' => 'forecolor', | |
| 1231 | + ), | |
| 1232 | + array( | |
| 1233 | + 'name' => esc_attr__( 'Text Background Color', 'taskbuilder' ), | |
| 1234 | + 'value' => 'backcolor', | |
| 1235 | + ), | |
| 1236 | + array( | |
| 1237 | + 'name' => esc_attr__( 'Strikethrough', 'taskbuilder' ), | |
| 1238 | + 'value' => 'strikethrough', | |
| 1239 | + ), | |
| 1240 | + ); | |
| 1241 | + return $toolbar; | |
| 1242 | + } | |
| 1243 | + | |
| 1244 | + public static function wppm_load_setting_header_html() { | |
| 1245 | + ?> | |
| 1246 | + <div class="wppm-header" style="padding-left:20px;margin:10px 0 10px 0;display: flex; justify-content: space-between; align-items: center; position: sticky;top: 0;background: #fff !important;z-index: 9999;width:99%; left: 0; "> | |
| 1247 | + <div class="wppm-header-title" style="display: flex; align-items: center; gap: 3px;"> | |
| 1248 | + <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/taskbuilder_logo.png'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 33px; height: 33px;margin-right:10px !important;"/> | |
| 1249 | + <h2 style="font-size: 30px; font-weight: 600; color: #333; margin: 0; font: 22px OpenSans-Light, Helvetica, Arial, sans-serif;"><?php esc_html_e( 'Taskbuilder', 'taskbuilder' )?></h2> | |
| 1250 | + </div> | |
| 1251 | + <div class="wppm-header-button" style="display: flex; justify-content: flex-end; gap: 3px;"> | |
| 1252 | + <div class="wppm-btn | |
| 1253 | + " style="background-color: #0052CC; color: #fff; padding: 8px 10px;margin: 35px 0px 14px 0px;text-decoration: none;border-radius: 5px;transition: background 0.3s ease;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);"> | |
| 1254 | + <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/help.svg'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 20px; height: 19px;margin-bottom: -5px;"/> | |
| 1255 | + <a href="https://taskbuilder.net/help/" target="__blank" style="color:#fff"><?php esc_html_e( 'Help', 'taskbuilder' )?></a> | |
| 1256 | + </div> | |
| 1257 | + <div class="wppm-btn" style="background-color: #0052CC; color: #fff; padding: 8px 10px;margin: 35px 0px 14px 0px;text-decoration: none;border-radius: 5px;transition: background 0.3s ease;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);"> | |
| 1258 | + <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/support.svg'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 15px; height: 19px;margin-bottom: -5px;"/> | |
| 1259 | + <a href="https://taskbuilder.net/support/?wpsc-section=ticket-list" target="__blank" style="color:#fff"><?php esc_html_e( 'Support', 'taskbuilder' )?></a> | |
| 1260 | + </div> | |
| 1261 | + <div class="wppm-btn" style="background-color: #0052CC; color: #fff; padding: 8px 10px;margin: 35px 10px 14px 0px;text-decoration: none;border-radius: 5px;transition: background 0.3s ease;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);"> | |
| 1262 | + <img src="<?php echo esc_url( WPPM_PLUGIN_URL . 'asset/images/pro_features.svg'); ?>" class="wppm-header-icon" alt="taskbuilder Icon" style="width: 15px; height: 19px;margin-bottom: -5px;"/> | |
| 1263 | + <a href="https://taskbuilder.net/pricing/" target="__blank" style="color:#fff"><?php esc_html_e( 'Get pro', 'taskbuilder' )?></a> | |
| 1264 | + </div> | |
| 1265 | + </div> | |
| 1266 | + </div> | |
| 1267 | + <?php | |
| 1268 | + } | |
| 1269 | + | |
| 1270 | + public function wppm_get_duration($start_date, $end_date){ | |
| 1271 | + if ( empty($start_date) || empty($end_date) || $start_date=='0000-00-00 00:00:00' || $end_date =='0000-00-00 00:00:00') { | |
| 1272 | + return ''; | |
| 1273 | + } | |
| 1274 | + | |
| 1275 | + $start_ts = strtotime($start_date); | |
| 1276 | + $end_ts = strtotime($end_date); | |
| 1277 | + | |
| 1278 | + if ( $end_ts <= $start_ts ) { | |
| 1279 | + return '0 min'; | |
| 1280 | + } | |
| 1281 | + | |
| 1282 | + $diff = $end_ts - $start_ts; | |
| 1283 | + | |
| 1284 | + $days = floor($diff / 86400); | |
| 1285 | + $hours = floor(($diff % 86400) / 3600); | |
| 1286 | + $minutes = floor(($diff % 3600) / 60); | |
| 1287 | + | |
| 1288 | + $duration = []; | |
| 1289 | + | |
| 1290 | + if ($days > 0) $duration[] = $days . 'd'; | |
| 1291 | + if ($hours > 0) $duration[] = $hours . 'h'; | |
| 1292 | + if ($minutes > 0 || empty($duration)) $duration[] = $minutes . 'm'; | |
| 1293 | + | |
| 1294 | + return implode(' ', $duration); | |
| 1295 | + | |
| 1296 | + } | |
| 1297 | + | |
| 1298 | + public function wppm_highlight_user_mentions($content, $current_user_id) { | |
| 1299 | + | |
| 1300 | + return preg_replace_callback( | |
| 1301 | + '/<span[^>]*class="wppm-mention"[^>]*data-user-id="(\d+)"[^>]*>(.*?)<\/span>/is', | |
| 1302 | + function($matches) use ($current_user_id) { | |
| 1303 | + | |
| 1304 | + $user_id = intval($matches[1]); | |
| 1305 | + $text = $matches[2]; | |
| 1306 | + | |
| 1307 | + // already processed → skip | |
| 1308 | + if (strpos($matches[0], 'wppm-mention-me') !== false) { | |
| 1309 | + return $matches[0]; | |
| 1310 | + } | |
| 1311 | + | |
| 1312 | + if ($user_id === $current_user_id) { | |
| 1313 | + return '<span class="wppm-mention wppm-mention-me" data-user-id="' . esc_attr($user_id) . '">' . $text . '</span>'; | |
| 1314 | + } | |
| 1315 | + | |
| 1316 | + return '<span class="wppm-mention" data-user-id="' . esc_attr($user_id) . '">' . $text . '</span>'; | |
| 1317 | + }, | |
| 1318 | + $content | |
| 1319 | + ); | |
| 1320 | + } | |
| 1321 | + function wppm_clean_mentions_html($content) { | |
| 1322 | + // Remove dropdown items | |
| 1323 | + $content = preg_replace('/<div[^>]*class="mention-item"[^>]*>.*?<\/div>/is', '', $content); | |
| 1324 | + | |
| 1325 | + // Remove mention dropdown container | |
| 1326 | + $content = preg_replace('/<div[^>]*id="wppm_mention_list"[^>]*>.*?<\/div>/is', '', $content); | |
| 1327 | + | |
| 1328 | + return $content; | |
| 1329 | + } | |
| 1330 | + | |
| 1331 | + function wppm_extract_mentions($comment) { | |
| 1332 | + preg_match_all('/data-user-id="(\d+)"/', $comment, $matches); | |
| 1333 | + return $matches[1]; | |
| 1334 | + } | |
| 1335 | + | |
| 1336 | + function wppm_get_users_from_mentions($user_ids) { | |
| 1337 | + $users = []; | |
| 1338 | + foreach ($user_ids as $user_id) { | |
| 1339 | + $user = get_user_by('id', intval($user_id)); | |
| 1340 | + if ($user) { | |
| 1341 | + $users[] = $user; | |
| 1342 | + } | |
| 1343 | + } | |
| 1344 | + return $users; | |
| 1345 | + } | |
| 1346 | + | |
| 1347 | + function wppm_send_mention_email($email_addresses, $comment, $task_id) { | |
| 1348 | + $page_setting = get_option('wppm-page-settings'); | |
| 1349 | + $from_name = get_option('wppm_en_from_name'); | |
| 1350 | + $from_email = get_option('wppm_en_from_email'); | |
| 1351 | + $view = $page_setting['task-url-page']; | |
| 1352 | + $subject = esc_html__("You were mentioned in a comment", "taskbuilder"); | |
| 1353 | + $to = isset($email_addresses[0]) ? $email_addresses[0] : ''; | |
| 1354 | + if (!$to) { | |
| 1355 | + return; | |
| 1356 | + } | |
| 1357 | + unset($email_addresses[0]); | |
| 1358 | + $headers = "From: {$from_name} <{$from_email}>\r\n"; | |
| 1359 | + foreach ($email_addresses as $email_address) { | |
| 1360 | + $headers .= "BCC: {$email_address}\r\n"; | |
| 1361 | + } | |
| 1362 | + $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; | |
| 1363 | + $task_url = $this->get_task_url($task_id, $view); | |
| 1364 | + $message = esc_html__("Hello,", "taskbuilder"); | |
| 1365 | + $message .= "<br><br>"; | |
| 1366 | + $message .= esc_html__("You were mentioned in a comment:", "taskbuilder"); | |
| 1367 | + $message .= "<br><br>"; | |
| 1368 | + $message .= nl2br(esc_html(strip_tags($comment))); | |
| 1369 | + $message .= "<br><br>"; | |
| 1370 | + $message .= esc_html__("View Task:", "taskbuilder") . " "; | |
| 1371 | + $message .= '<a class="wppm_link" href="' . esc_url($task_url) . '" target="_blank">' . esc_html__("View Task", "taskbuilder") . '</a>'; | |
| 1372 | + wp_mail($to, $subject, $message, $headers); | |
| 1373 | + do_action('wppm_after_sent_mention_mail', $email_addresses, $comment, $task_id); | |
| 1374 | + } | |
| 1375 | + | |
| 1376 | + function wppm_insert_notification($user_id, $message, $link,$is_read,$type) { | |
| 1377 | + global $wpdb; | |
| 1378 | + $wpdb->insert( | |
| 1379 | + $wpdb->prefix . 'wppm_notifications', | |
| 1380 | + [ | |
| 1381 | + 'user_id' => $user_id, | |
| 1382 | + 'message' => $message, | |
| 1383 | + 'link' => $link, | |
| 1384 | + 'is_read' => $is_read, | |
| 1385 | + 'notification_type'=>$type, | |
| 1386 | + 'created_at' => current_time('mysql') | |
| 1387 | + ] | |
| 1388 | + ); | |
| 1389 | + } | |
| 1390 | + } | |
| 1391 | +endif; | |
| 1214 | 1392 | $GLOBALS['wppmfunction'] = new WPPM_Functions(); |