class list_workflow_tasks extends listing { public $status; public function __construct($context) { $this->status = $context['status']; $this->main_status = $context['main_status']; $this->foreign_status = $context['foreign_status']; $this->foreign_id = $context['foreign_id']; $this->table = $context['table']; $this->readonly = $context['readonly']; $this->show_all = $context['show_all']; parent::set_data($context); $this->method = (empty($context['list_config']['method'])) ? "date_created" : $context['list_config']['method']; } public function get_data() { global $database; $status = $this->status; $main_status = $this->main_status; $foreign_id = $this->foreign_id; $table = $this->table; $active_status = $this->foreign_status; $show_all = $this->show_all; $readonly = $this->readonly; $foreign_types['quotes'] = "Quote"; $foreign_types['jobs'] = "Job"; $priorities[0] = "Medium"; $priorities[1] = "High"; $priorities[2] = "Medium"; $priorities[3] = "Low"; $my_user_id = $_SESSION['user']['id']; $my_departments = $_SESSION['user']['department_id']; $my_group = $_SESSION['user']['group_id']; $where_sql = ""; $where_sql .= (empty($status)) ? "AND project_tasks.status = '0' " : " AND project_tasks.status = '$status' "; $where_sql .= (empty($main_status)) ? "" : " AND project_tasks.main_status = '$main_status' "; $where_sql .= (empty($foreign_id)) ? "" : " AND project_workflow.foreign_id = '$foreign_id' "; $where_sql .= (empty($table)) ? "" : " AND project_workflow.table = '$table' "; $tasks_groups = common_workflow::get_all_groups("workflow_tasks_groups"); $tasks_departments = common_workflow::get_all_departments("workflow_tasks_departments"); $users = common_users::get_all_names(); $departments = common_department::get_all_department(); $initials_links = common_users::get_all_initials_links(); $sql =" SELECT project_tasks.*, project_workflow.table, project_workflow.foreign_id FROM project_tasks,project_workflow WHERE project_tasks.project_workflow_id = project_workflow.id $where_sql "; $results = $database->getAll($sql); $return_results = array(); foreach($results AS $result) { $current_status = ($result['table'] == "jobs") ? common_jobs::get_status($result['foreign_id']) : common_quotes::get_status($result['foreign_id']); if($current_status == $active_status) { $result['submitter'] = $users[$result['submitter']]; $result['type'] = $foreign_types[$result['table']]; $result['allocate_id'] = $result['user_alloc']; $result['allocate'] = $users[$result['user_alloc']]; $result['allocate_link'] = $initials_links[$result['user_alloc']]; $result['id_type'] = $foreign_types[$result['table']]." #".$result['foreign_id']; $foreign_details = common_project_actions::get_foreign_details($result['foreign_id'],$result['table']); if($result['table'] == "quotes") { $result['job_id'] = $foreign_details['job_id']; $result['quote_id'] = $result['foreign_id']; } else if($result['table'] == "jobs") { $result['job_id'] = $result['foreign_id']; $result['quote_id'] = $foreign_details['quote_id']; } $result['job_name'] = $foreign_details['job_name']; $result['job_type'] = $foreign_details['job_type']; $result['priority'] = $priorities[$foreign_details['priority']]; $result['client_name'] = common_project_actions::get_client_name($result['foreign_id'],$result['table']); $task_departments = $tasks_departments[$result['workflow_task_id']]; $task_groups = $tasks_groups[$result['workflow_task_id']]; /*2013-05-24*/ $task_department=0; if(is_array($task_departments)){ $task_department = $task_departments[0]; } $result['department_id'] = $task_department; $result['department'] = common_project_tasks::get_departments(array("task_departments" => $task_departments,"departments" => $departments)); $result['owner'] = common_project_tasks::get_owners(array("groups" => $task_groups,"departments" => $task_departments)); $job_allocate_to = common_quotes::get_sales_alloc($result['quote_id']); if($my_group==43){ $permission = true; }else{ $permission = common_project_tasks::check_permission(array("my_group" => $my_group, "my_departments" => $my_departments, "tasks_groups" => $task_groups, "tasks_departments" => $task_departments, "user_alloc"=>$job_allocate_to)); } if($show_all == false) { if(!empty($result['user_alloc'])) { if($my_user_id == $result['user_alloc']) { $return_results[] = $result; } } else { if($permission) $return_results[] = $result; } } else { if(!$permission) { if(empty($result['user_alloc'])) { $result['allocate'] = "Pending Allocation"; $result['action'] = "Pending Completion"; if($readonly) $result['allocate'] = ""; } else if(!empty($result['user_alloc'])) { if($my_user_id != $result['user_alloc']) { $result['action'] = "Pending Completion"; } } if($readonly) $result['action'] = ""; } else { if(!empty($result['user_alloc'])) { if($my_user_id != $result['user_alloc']) { $result['action'] = "Pending Completion"; if($readonly) $result['allocate'] = ""; } } if($readonly) $result['action'] = ""; } $return_results[] = $result; } } } $this->final_results = $return_results; self::prepare(); return $this; } public function list_body() { $results = $this->final_results; $avail_status = $this->avail_status; $avail_edit = $this->avail_edit; $link_view = $this->link_view; $link_edit = $this->link_edit; $columns = $this->columns; $sortable = $this->sortable; $pagination = $this->pagination; $start = $this->start; $size = $this->size; $total_results = $this->total_results; $max_size = $this->max_size; $normalise_get = $this->normalise_get; $new_normalised_results = $this->normalised_results; $count = 0; if(count($results) > 0) { ?>
for($i = $start; $i < $max_size; $i++) { $key = $new_normalised_results[$i]; $mod = $count%2; $class = ($mod == 0) ? "odd" : "even"; $count++; $results[$key]['date_submitted'] = dates::change_date_time($results[$key]['date_submitted']); $results[$key]['date_created'] = dates::change_date_time($results[$key]['date_created']); ?>