function view($id = FALSE) { $this->view_data['submenu'] = array($this->lang->line('application_back') => 'cprojects', $this->lang->line('application_overview') => 'cprojects/view/' . $id, $this->lang->line('application_media') => 'cprojects/media/' . $id); $this->view_data['project'] = Project::find($id); $this->view_data['project_has_invoices'] = Invoice::find('all', array('conditions' => array('project_id = ? AND company_id=? AND estimate != ? AND issue_date<=?', $id, $this->client->company->id, 1, date('Y-m-d', time())))); $tasks = ProjectHasTask::count(array('conditions' => 'project_id = ' . $id)); $tasks_done = ProjectHasTask::count(array('conditions' => array('status = ? AND project_id = ?', 'done', $id))); @($this->view_data['opentaskspercent'] = $tasks_done / $tasks * 100); $this->view_data['time_days'] = round((human_to_unix($this->view_data['project']->end . ' 00:00') - human_to_unix($this->view_data['project']->start . ' 00:00')) / 3600 / 24); $this->view_data['time_left'] = $this->view_data['time_days']; $this->view_data['timeleftpercent'] = 100; if (human_to_unix($this->view_data['project']->start . ' 00:00') < time() && human_to_unix($this->view_data['project']->end . ' 00:00') > time()) { $this->view_data['time_left'] = round((human_to_unix($this->view_data['project']->end . ' 00:00') - time()) / 3600 / 24); $this->view_data['timeleftpercent'] = $this->view_data['time_left'] / $this->view_data['time_days'] * 100; } if (human_to_unix($this->view_data['project']->end . ' 00:00') < time()) { $this->view_data['time_left'] = 0; $this->view_data['timeleftpercent'] = 0; } @($this->view_data['opentaskspercent'] = $tasks_done / $tasks * 100); $tracking = $this->view_data['project']->time_spent; if (!empty($this->view_data['project']->tracking)) { $tracking = time() - $this->view_data['project']->tracking + $this->view_data['project']->time_spent; } $this->view_data['timertime'] = $tracking; $this->view_data['time_spent_from_today'] = time() - $this->view_data['project']->time_spent; $tracking = floor($tracking / 60); $tracking_hours = floor($tracking / 60); $tracking_minutes = $tracking - $tracking_hours * 60; $this->view_data['time_spent'] = $tracking_hours . " " . $this->lang->line('application_hours') . " " . $tracking_minutes . " " . $this->lang->line('application_minutes'); $this->view_data['time_spent_counter'] = sprintf("%02s", $tracking_hours) . ":" . sprintf("%02s", $tracking_minutes); if (!isset($this->view_data['project_has_invoices'])) { $this->view_data['project_has_invoices'] = array(); } if ($this->view_data['project']->company_id != $this->client->company->id) { redirect('cprojects'); } $this->content_view = 'projects/client_views/view'; }
function tasks($id = FALSE, $condition = FALSE, $task_id = FALSE) { $this->view_data['submenu'] = array($this->lang->line('application_back') => 'projects', $this->lang->line('application_overview') => 'projects/view/' . $id); switch ($condition) { case 'add': $this->content_view = 'projects/_tasks'; if ($_POST) { unset($_POST['send']); unset($_POST['files']); $description = $_POST['description']; $_POST = array_map('htmlspecialchars', $_POST); $_POST['description'] = $description; $_POST['project_id'] = $id; $task = ProjectHasTask::create($_POST); if (!$task) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_save_task_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_save_task_success')); } redirect('projects/view/' . $id); } else { $this->theme_view = 'modal'; $this->view_data['project'] = Project::find($id); $this->view_data['title'] = $this->lang->line('application_add_task'); $this->view_data['form_action'] = 'projects/tasks/' . $id . '/add'; $this->content_view = 'projects/_tasks'; } break; case 'update': $this->content_view = 'projects/_tasks'; $this->view_data['task'] = ProjectHasTask::find($task_id); if ($_POST) { unset($_POST['send']); unset($_POST['files']); if (!isset($_POST['public'])) { $_POST['public'] = 0; } $description = $_POST['description']; $_POST = array_map('htmlspecialchars', $_POST); $_POST['description'] = $description; $task_id = $_POST['id']; $task = ProjectHasTask::find($task_id); $task->update_attributes($_POST); if (!$task) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_save_task_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_save_task_success')); } redirect('projects/view/' . $id); } else { $this->theme_view = 'modal'; $this->view_data['project'] = Project::find($id); $this->view_data['title'] = $this->lang->line('application_edit_task'); $this->view_data['form_action'] = 'projects/tasks/' . $id . '/update/' . $task_id; $this->content_view = 'projects/_tasks'; } break; case 'check': $task = ProjectHasTask::find($task_id); if ($task->status == 'done') { $task->status = 'open'; } else { $task->status = 'done'; } $task->save(); $project = Project::find($id); $tasks = ProjectHasTask::count(array('conditions' => 'project_id = ' . $id)); $tasks_done = ProjectHasTask::count(array('conditions' => array('status = ? AND project_id = ?', 'done', $id))); if ($project->progress_calc == 1) { if ($tasks) { $progress = round($tasks_done / $tasks * 100); } $attr = array('progress' => $progress); $project->update_attributes($attr); } if (!$task) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_save_task_error')); } $this->theme_view = 'ajax'; $this->content_view = 'projects'; break; case 'delete': $task = ProjectHasTask::find($task_id); $task->delete(); if (!$task) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_delete_task_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_delete_task_success')); } redirect('projects/view/' . $id); break; default: $this->view_data['project'] = Project::find($id); $this->content_view = 'projects/tasks'; break; } }