/application/controllers/projects.php
PHP | 799 lines | 680 code | 85 blank | 34 comment | 91 complexity | 236b71da694d98ef5d0693c41977a5cd MD5 | raw file
- <?php
- class Projects extends Controller{
-
- function __construct(){
- parent::Controller();
- $this->is_logged_in();
- }
-
- function super_unique($array){
- //ripped super_unique($array) off from http://www.php.net/manual/en/function.array-unique.php#97285
- $result = array_map("unserialize", array_unique(array_map("serialize", $array)));
- foreach ($result as $key => $value){
- if (is_array($value)){
- $result[$key] = super_unique($value);
- }
- }
- return $result;
- }
-
- function index($welcome='', $all = ''){
- $this->load->model('projects_model');
-
- //two queries: projects and tasks
- $projects = $this->projects_model->fetchproject();
- $tasks = $this->projects_model->fetchAllTasks();
-
- //defining some variables
- $userID = $this->session->userdata('userid');
- $user_projects = false;
- $projects_created_by = false;
- $projects_managed = false;
- $data['today'] = mktime(0,0,0);
- $data['upcoming'] = (mktime(0,0,0)+(5*24*60*60));
- //weed out completed tasks and sort into $project_tasks[project name], $user_projects
- foreach($projects as $project){
- $all_clients[$project->project_client_id] = $project->organisation_name;
- //find projects managed by this user
- if($project->project_manager == $userID){
- $user_projects[] = $project;
- $user_clients[$project->project_client_id] = $project->organisation_name;
- }
-
- //sorting tasks into project name arrays
- $project_tasks[$project->projects_id] = false;
- $completed_tasks[$project->projects_id] = false;
- $count_completed_tasks[$project->projects_id] = 0;
- $count_total_tasks[$project->projects_id] = 1;
- foreach($tasks as $task){
- if($project->projects_id == $task->task_project_id){
- $count_total_tasks[$project->projects_id] = $count_total_tasks[$project->projects_id]+1;
- }
- if($task->task_status !== "Completed"){
- if($project->projects_id == $task->task_project_id){
- $project_tasks[$project->projects_id][] = $task;
- }
- }elseif($task->task_status == "Completed"){
- if($project->projects_id == $task->task_project_id){
- $completed_tasks[$project->projects_id][] = $task;
- $count_completed_tasks[$project->projects_id] = count($completed_tasks[$project->projects_id]);
- }
- }
- }
- $count1 = $count_completed_tasks[$project->projects_id]/$count_total_tasks[$project->projects_id];
- $count2 = $count1*100;
- $count = number_format($count2, 0);
- $data['completion'][$project->projects_id] = $count;
- //finding projects in which the user has a task.
- if($project_tasks[$project->projects_id]){
- foreach($project_tasks[$project->projects_id] as $task){
- if($task->task_user_id == $userID){
- $user_projects[] = $project;
- $user_clients[$project->project_client_id] = $project->organisation_name;
- }
- }
-
- }
- }
- if($user_projects){
- $user_projects = $this->super_unique($user_projects);
- }
- asort($user_clients);
- asort($all_clients);
- $data['projects'] = $projects;
- $data['project_tasks'] = $project_tasks;
- $data['user_projects'] = $user_projects;
- $current_projects = false;
- $overdue_projects = false;
- $today = mktime(0,0,0);
- $data['user_clients'] = array_unique($user_clients);
- $data['all_clients'] = array_unique($all_clients);
- $data['overdue_projects'] = $overdue_projects;
- $data['user_projects'] = $user_projects;
- $data['projects_created_by'] = $projects_created_by;
- $data['current_projects'] = $current_projects;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- if(!empty($all)){
- $data['main_content'] = "main_content/all_projects_view";
- }else{
- $data['main_content'] = "main_content/projects_view";
- }
-
- $this->load->view('includes/template', $data);
- }
-
- function all(){
-
- }
-
- function is_logged_in(){
- if (!($this->session->userdata('is_logged_in'))){
- redirect('intrangu');
- }
- }
-
-
-
- function userdashboard($welcome='', $all = ''){
- $this->load->model('projects_model');
-
- //two queries: projects and tasks
- $projects = $this->projects_model->fetchproject();
- $tasks = $this->projects_model->fetchAllTasks();
-
- //defining some variables
- $userID = $this->session->userdata('userid');
- $user_projects = false;
- $projects_created_by = false;
- $projects_managed = false;
- $data['today'] = mktime(0,0,0);
- $data['upcoming'] = (mktime(0,0,0)+(5*24*60*60));
- //weed out completed tasks and sort into $project_tasks[project name], $user_projects
- foreach($projects as $project){
- $all_clients[$project->project_client_id] = $project->organisation_name;
- //find projects managed by this user
- if($project->project_manager == $userID){
- $user_projects[] = $project;
- $user_clients[$project->project_client_id] = $project->organisation_name;
- }
-
- //sorting tasks into project name arrays
- $project_tasks[$project->projects_id] = false;
- $completed_tasks[$project->projects_id] = false;
- $count_completed_tasks[$project->projects_id] = 0;
- $count_total_tasks[$project->projects_id] = 1;
- foreach($tasks as $task){
- if($project->projects_id == $task->task_project_id){
- $count_total_tasks[$project->projects_id] = $count_total_tasks[$project->projects_id]+1;
- }
- if($task->task_status !== "Completed"){
- if($project->projects_id == $task->task_project_id){
- $project_tasks[$project->projects_id][] = $task;
- }
- }elseif($task->task_status == "Completed"){
- if($project->projects_id == $task->task_project_id){
- $completed_tasks[$project->projects_id][] = $task;
- $count_completed_tasks[$project->projects_id] = count($completed_tasks[$project->projects_id]);
- }
- }
- }
- $count1 = $count_completed_tasks[$project->projects_id]/$count_total_tasks[$project->projects_id];
- $count2 = $count1*100;
- $count = number_format($count2, 0);
- $data['completion'][$project->projects_id] = $count;
- //finding projects in which the user has a task.
- if($project_tasks[$project->projects_id]){
- foreach($project_tasks[$project->projects_id] as $task){
- if($task->task_user_id == $userID){
- $user_projects[] = $project;
- $user_clients[$project->project_client_id] = $project->organisation_name;
- }
- }
-
- }
- }
- if($user_projects){
- $user_projects = $this->super_unique($user_projects);
- }
- asort($user_clients);
- asort($all_clients);
- $data['projects'] = $projects;
- $data['project_tasks'] = $project_tasks;
- $data['user_projects'] = $user_projects;
- $current_projects = false;
- $overdue_projects = false;
- $today = mktime(0,0,0);
- $data['user_clients'] = array_unique($user_clients);
- $data['all_clients'] = array_unique($all_clients);
- $data['overdue_projects'] = $overdue_projects;
- $data['user_projects'] = $user_projects;
- $data['projects_created_by'] = $projects_created_by;
- $data['current_projects'] = $current_projects;
- $this->load->model('projects_model');
- $news = $this->projects_model->fetch_changes_2();
- $data['news'] = $news;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/user_dashboard";
-
-
- $this->load->view('includes/template', $data);
- }
-
-
-
-
- function viewProject($project_id = "",$message = ""){
- if(empty($project_id)){
- $project_id = $this->uri->segment(3);
- }
- if(empty($message)){
- $message = false;
- }
- $this->load->model('projects_model');
- $data['project'] = $this->projects_model->fetchProject($project_id);
- $data['tasks'] = false;
- $today = mktime(0,0,0);
- $five_days_from_now = (mktime(0,0,0)+(5*24*60*60));
- $tasks = $this->projects_model->fetchTasks($project_id);
- $files = $this->projects_model->fetchFiles($project_id);
- if($files){
- $this->load->helper('file');
- $info = array('name','size','date');
- foreach($files as $file){
- $file_infos[] = get_file_info($file->file_path, $info);
- }
- }else{
- $file_infos = false;
- }
- //var_dump($file_infos);
- $current_tasks = false;
- $overdue_tasks = false;
- $upcoming_deadlines = false;
- $completed_tasks = false;
- $completed = 0;
- $total_tasks = count($tasks);
- if($tasks){
- foreach($tasks as $project_task){
- if ($project_task->task_status !== "Completed"){
- if ($project_task->task_deadline < $today){
- $overdue_tasks[] = $project_task;
- $current_tasks[] = $project_task;
- }else{
- $current_tasks[] = $project_task;
- if (($project_task->task_deadline < $five_days_from_now) && ($project_task->task_deadline >= mktime(0,0,0))){
- $upcoming_deadlines[] = $project_task;
- };
- };
- }elseif($project_task->task_status == "Completed"){
- $completed_tasks[]= $project_task;
- $completed = $completed+1;
- };
- };
- };
- $count1 = $completed/($total_tasks);
- $count2 = $count1*100;
- $count = number_format($count2, 0);
- $data['today'] = $today;
- $data['files'] = $file_infos;
- $data['upcoming'] = $five_days_from_now;
- $data['completion'] = $count;
- $data['overdue_tasks'] = $overdue_tasks;
- $data['current_tasks'] = $current_tasks;
- $data['completed_tasks'] = $completed_tasks;
- $data['upcoming_deadlines'] = $upcoming_deadlines;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- if($tasks){
- $data['tasks'] = $tasks;
- }
- $data['call_reports'] = $this->projects_model->fetchProjectCallReports($project_id);
- $data['message'] = $message;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/single_project";
- $this->load->view('includes/template', $data);
- }
-
-
- function newProject(){
- $this->load->model('projects_model');
- $this->load->model('users_model');
- $this->load->model('contacts_model');
- if ($this->input->post('submit')){
- $org = $this->input->post('project_client');
- if (!empty($org)){
- if ($this->contacts_model->getOrgID($org)){
- $orgID = $this->contacts_model->getOrgID($org);
- }else{
- $this->contacts_model->addOrg($org);
- $orgID = mysql_insert_id();
- }
- }else{
- $orgID = '0';
- }
- $manager = $this->input->post('project_manager');
- $this->projects_model->addProject($orgID);
- $newProjectID = mysql_insert_id();
- $project = $this->projects_model->fetchProject($newProjectID);
- $this->projects_model->addProjectMeta($newProjectID);
- redirect("projects/projectsteptwo/$project->projects_id");
- }else{
- //display form
- $data['users'] = $this->users_model->fetchUser();
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/add_project_form";
- $this->load->view('includes/template', $data);
- }
- }
-
- function projectStepTwo($id){
- $this->load->model('projects_model');
- $this->load->model('contacts_model');
- $this->load->model('users_model');
- $project=$this->projects_model->fetchproject($id);
- if($this->input->post('submit')){
- $num_o_tasks=$this->input->post('num_o_tasks');
- $real_num_o_tasks=0;
- for($i=0;$i<$num_o_tasks;$i++){
- $j=$i+1;
- $task['project'] = $id;
- $task['name'] = $this->input->post("task_name_$j");
- $task['status']=$this->input->post("task_status_$j");
- $task['user']=$this->input->post("resp_user_$j");
- $task['deadline']= mktime(0,0,0,$this->input->post("month_$j"),$this->input->post("day_$j"),$this->input->post("year_$j"));
- if(($task['name']!=='Task name') && ($task['status'] !== 'Please select...')&&($task['user']!=='Please select...')){
- $task_id[$j]=$this->projects_model->bulkAddTasks($task);
- $real_num_o_tasks++;
- }
- }
-
- $change = "<h3>New project: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- if($real_num_o_tasks !==0){
- $change .= ucwords($this->session->userdata('username'))." added $i task(s):<ul>";
- for($i=0;$i<$num_o_tasks;$i++){
- $j=$i+1;
- $change .= "<li>".anchor("projects/viewtask/$task_id[$i]",$this->input->post("task_name_$j"))."</li>";
- }
- $change .= "</ul>";
- }else{
- $change .= ucwords($this->session->userdata('username'))." added no tasks to this project.";
- }
-
-
- $this->projects_model->simplerChanges($id, $change);
- $this->mailTeam($id,"New project: $project->project_name",$change);
- redirect("projects/viewproject/$id");
- }else{
- $this->load->model('projects_model');
- $data['users'] = $this->users_model->fetchUser();
- $data['project']=$project;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/add_project_step_two";
- $this->load->view("includes/template",$data);
- }
-
- }
- function updateProject($id){
- $this->load->model('projects_model');
- $this->load->model('contacts_model');
- $this->load->model('users_model');
- $project = $this->projects_model->fetchProject($id);
- if ($this->input->post('submit')){
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= ucwords($this->session->userdata('username'))." updated information about this project:<ul>";
- $changed=false;
- $org = $this->input->post('project_client');
- if (!empty($org)){
- //an organisation has been entered
- if ($this->contacts_model->getOrgID($org)){
- //organisation is in DB
- $orgID = $this->contacts_model->getOrgID($org);
- }else{
- //organisation isn't in DB
- $this->contacts_model->addOrg($org);
- $orgID = mysql_insert_id();
- }
-
- }else{
- $orgID = '0';
- }
- if($project->project_name != $this->input->post('project_name')){
- $new_name = $this->input->post('project_name');
- $change .= "<li>New project name: $new_name</li>";
- $changed=true;
- }
- if($project->project_status != $this->input->post('project_status')){
- $new_status = $this->input->post('project_status');
- $change .= "<li>New project status: $new_status</li>";
- $changed=true;
- }
- if($project->project_manager != $this->input->post('project_manager')){
- $new_manager= $this->input->post('project_manager');
- $new_manager = $this->users_model->fetchUser($new_manager);
- $new_manager = ucwords($new_manager->username);
- $change .= "<li>New project manager: $new_manager</li>";
- $changed=true;
- }
- $deadline = mktime(0,0,0,$this->input->post('month'),$this->input->post('day'),$this->input->post('year'));
- if($project->project_deadline != $deadline){
- $new_deadline = $deadline;
- $change .= "<li>New project deadline: ". date('j F', $new_deadline)."</li>";
- $changed=true;
- }
- if($project->project_brief != $this->input->post('project_brief')){
- $new_brief = $this->input->post('project_brief');
- $change .= "<li>New project brief: <br /> $new_brief</li>";
- $changed=true;
- }
- $change .= "</ul>";
- if($changed){
- $this->projects_model->updateProject($id, $orgID);
- $this->projects_model->simplerChanges($id, $change);
- $this->mailTeam($id,"Project update: $project->project_name",$change);
- $message = "Project updated.";
- }else{
- $message = "No changes made.";
- }
- redirect("projects/viewproject/$id/$message");
- }else{
- //display form
- $data['project'] = $project;
- $data['users'] = $this->users_model->fetchUser();
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/edit_project_form";
- $this->load->view('includes/template', $data);
- }
- }
-
-
- function attachFile($id){
- $this->load->model('projects_model');
- $this->load->model('users_model');
- $project=$this->projects_model->fetchProject($id);
- if(!($this->input->post('submit'))){
- $data['error'] = '';
- $data['project'] = $project;
- $data['users'] = $this->users_model->fetchUser();
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/project_attach_file_view";
- $this->load->view('includes/template', $data);
- }else{
- $config['upload_path'] = '../consensus/uploads/';
- $config['allowed_types'] = 'pdf|doc|png|gif|jpg|jpeg|doc|xls|idd|psd|bmp|pdf|application|application/vnd.ms-excel|docx|xlsx';
- $this->load->library('upload', $config);
- if ( ! $this->upload->do_upload())
- {
- $error = array('error' => $this->upload->display_errors());
- $data['error'] = $config['upload_path'];
- $data['error'] = $error['error'];
- $data['project'] = $this->projects_model->fetchProject($id);
- $data['users'] = $this->users_model->fetchUser();
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/project_attach_file_view";
- $this->load->view('includes/template', $data);
- }
- else
- {
-
- $filepath = $this->upload->data();
- $filepath = $filepath['full_path'];
- var_dump($filepath);
- $this->projects_model->linkFile($id,$filepath);
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= "<p>".ucwords($this->session->userdata('username'))." attached ".anchor($filepath,"a new file")." to this project.</p>";
- $this->projects_model->simplerChanges($id,$change);
- $this->mailTeam($id,"Project update: $project->project_name",$change);
- redirect("projects/viewproject/$id");
- }
- }
-
- }
- function addTask($project_id){
- $this->load->model('projects_model');
- $this->load->model('contacts_model');
- $this->load->model('users_model');
- $project=$this->projects_model->fetch_project($project_id);
- if ($this->input->post('submit')){
- $this->projects_model->addTask($project->projects_id);
- $newTaskID = mysql_insert_id();
- $this->projects_model->addTaskMeta($newTaskID);
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= "<p>".ucwords($this->session->userdata('username'))." added a ".anchor("projects/viewtask/$newTaskID", 'new task').".</p>";
- $this->projects_model->simplerChanges($project_id,$change);
- $this->mailTeam($id,"Project update: $project->project_name",$change);
- $message = "Task added";
- redirect("projects/viewproject/$project_id");
- }else{
- $data['project'] = $this->projects_model->fetchProject($project_id);
- $data['users'] = $this->users_model->fetchUser();
- $data['sidebar'] = false;
- $data['main_content'] = "main_content/add_task_form";
- $this->load->view('includes/template', $data);
- }
- }
- function viewTask($task_id,$message =""){
- if(empty($message)){
- $task = false;
- }
- $this->load->model('projects_model');
- $task = $this->projects_model->fetchTask($task_id);
- $data['notes'] = $task['notes'];
- $task = $task['task'];
- $data['task'] = $task;
- $data['message']= $message;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/single_task";
- $this->load->view('includes/template', $data);
-
- }
-
- function addnote($task_id){
- $this->load->model('projects_model');
- $task=$this->projects_model->fetchTask($task_id);
- $task=$task['task'];
- $project=$this->projects_model->fetchProject($task->task_project_id);
- $note = $this->input->post('note');
- $cancel= $this->input->post('cancel');
- if($cancel == '' && $note !== ''){
- $this->projects_model->addnote();
- }
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= "<p>".ucwords($this->session->userdata('username'))." added a new note to the task ".anchor("projects/viewtask/$task->task_id", $task->task_name).":</p>";
- $change .= "<p><em>$note</em></p>";
- $this->projects_model->simplerChanges($project->projects_id,$change);
- $this->mailTeam($project->projects_id,"Project update: $project->project_name",$change);
- redirect("projects/viewtask/$task_id");
- }
-
- function updateTask($task_id){
- $this->load->model('projects_model');
- $this->load->model('contacts_model');
- $this->load->model('users_model');
- $task = $this->projects_model->fetchTask($task_id);
- $task = $task['task'];
- if ($this->input->post('submit')){
- $project_id = $this->input->post('project_id');
- $project=$this->projects_model->fetchProject($project_id);
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= ucwords($this->session->userdata('username'))." updated the task ".anchor("projects/viewtask/$task->task_id",$task->task_name).":";
- $changed=false;
- if($task->task_name != $this->input->post('task_name')){
- $changed =true;
- $change .= "<li>New name: ".$this->input->post('task_name')."</li>";
- }
- if($task->task_status != $this->input->post('task_status')){
- $changed =true;
- $change .= "<li>New status: ".$this->input->post('task_status')."</li>";
- }
- if($task->task_user_id != $this->input->post('resp_user')){
- $changed =true;
- $new_user= $this->input->post('resp_user');
- $new_user = $this->users_model->fetchUser($new_user);
- $new_user = ucwords($new_user->username);
- $change .= "<li>New responsible person: ".$new_user."</li>";
- }
- $new_deadline = mktime(0,0,0,$this->input->post('month'),$this->input->post('day'),$this->input->post('year'));
- if($task->task_deadline != $new_deadline){
- $changed =true;
- $change .= "<li>New deadline: ".date('j F', $new_deadline)."</li>";
- }
- if($task->task_brief != $this->input->post('task_brief')){
- $changed =true;
- $change .= "<li>New brief: ".$this->input->post('task_brief')."</li>";
- }
- if($changed){
- $this->projects_model->updateTask($task_id);
- $this->projects_model->simplerChanges($project_id, $change);
- $message = $this->mailTeam($project_id,"Project update: $project->project_name",$change);
- }else{
- $message = "No changes made.";
-
- }
- redirect("projects/viewproject/$project_id/$message");
-
-
- }else{
- $data['task'] = $task;
- $data['users'] = $this->users_model->fetchUser();
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/edit_task_form";
- $this->load->view('includes/template', $data);
- }
- }
-
- function mailTeam($project_id, $subject, $message){
- $this->load->model('projects_model');
- $team = $this->projects_model->fetchTeam($project_id);
- $this->load->helper('email');
- if(is_array($team)){
- $team=array_unique($team);
- }
- $data['message'] = $message;
- $html_message = $this->load->view('main_content/html_email_message', $data, true);
- foreach($team as $email){
- $to = $email;
- $subject = $subject;
- $headers = "From: " . strip_tags($this->session->userdata('email')) . "\r\n";
- $headers .= "Reply-To: ". strip_tags($this->session->userdata('email')) . "\r\n";
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
- mail($to, $subject, $html_message, $headers);
- }
- //$this->email->from($this->session->userdata('email'),$this->session->userdata('username'));
- //$this->email->to($team);
- //$this->email->subject($subject);
- //$data['message'] = $message;
- //$html_message = $this->load->view('main_content/html_email_message', $data, true);
- //$this->email->message($html_message);
- //if(!($this->email->send())){
- // $message = "Team members could not be notified due to an email error.";
- //
- //}else{
- // $message = "Team members have been notified.";
- //
- //}
- //return $message;
-
- }
-
- function changeTaskStatus($task_id){
- $this->load->model('projects_model');
- $task = $this->projects_model->fetchTask($task_id);
- $task = $task['task'];
- $project_id = $this->input->post('project_id');;
- $project=$this->projects_model->fetchProject($project_id);
- $result = $this->input->post('task_status');
- $this->projects_model->updatetaskStatus($task_id, $result);
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= ucwords($this->session->userdata('username'))." updated the status of the task ".anchor("projects/viewtask/$task->task_id",$task->task_name)." to ".$result.".";
- $this->projects_model->simplerChanges($project_id, $change);
- $this->mailTeam($project_id,"Project update: $project->project_name",$change);
- $message = "Task status changed to <strong>$result</strong>.";
- redirect("projects/viewproject/$project_id");
- }
-
-
-
- function deleteTask(){
-
- }
-
-
- function completedTasks($project_id = ""){
- if(empty($project_id)){
- $project_id = $this->uri->segment(3);
- }
- $this->load->model('projects_model');
- $data['project'] = $this->projects_model->fetchProject($project_id);
- $data['tasks'] = $this->projects_model->fetchTasks($project_id);
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/completed_tasks";
- $this->load->view('includes/template', $data);
- }
-
-
-
-
- function newsFeed(){
- $this->load->model('projects_model');
- $news = $this->projects_model->fetch_changes_2();
- $data['news'] = $news;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/newsfeed2";
- $this->load->view('includes/template', $data);
- }
-
-
- function userProjects(){
- $this->load->model('projects_model');
- $userID = $this->session->userdata('userid');
- $data['user_projects'] = $this->projects_model->fetchuserprojects($userID);
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/user_projects";
- $this->load->view('includes/template', $data);
- }
-
-
- function userCompletedTasks(){
- $this->load->model('projects_model');
- $userID = $this->session->userdata('userid');
- $data['user_tasks'] = $this->projects_model->fetchusertasks($userID);
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/user_completed_tasks";
- $this->load->view('includes/template', $data);
- }
-
-
- function upcomingDeadlines(){
- $this->load->model('projects_model');
- $userID = $this->session->userdata('userid');
- $five_days_from_now = (mktime(0,0,0)+(5*24*60*60));
- $user_tasks = $this->projects_model->fetchusertasks($userID);
- $upcoming_deadlines = false;
- if($user_tasks){
- foreach($user_tasks as $user_task){
- if (($user_task->task_deadline < $five_days_from_now) && ($user_task->task_deadline >= mktime(0,0,0))){
- $upcoming_deadlines[] = $user_task;
- };
- };
- };
- $data['user_tasks'] = $upcoming_deadlines;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/upcoming_deadlines_user";
- $this->load->view('includes/template', $data);
- }
-
-
-
- function addCallReport($project_id){
- $this->load->model('projects_model');
- $this->load->model('contacts_model');
- $project = $this->projects_model->fetchproject($project_id);
- if ($this->input->post('submit')){
- $callID = $this->projects_model->addCallReport($project->projects_id);
- $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
- $change .= "<p>".ucwords($this->session->userdata('username'))." added ".anchor("projects/viewcallreport/$callID",'a new call report').".";
- $this->projects_model->simplerChanges($change);
-
- redirect("projects/viewproject/$project_id");
- }else{
- if(empty($project_id)){
- $userprojects = $this->projects_model->fetchUserProjects($this->session->userdata('userid'));
- foreach($userprojects as $p){
- if($p->project_status !== "Completed"){
- $uprojects[] = $p;
- }
- }
- $data['userprojects'] = $userprojects;
- }else{
- $data['userprojects'] = false;
- $data['project_id'] = $project_id;
- }
- //display form
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/add_call_report_form";
- $this->load->view('includes/template', $data);
- }
- }
-
-
- function viewCallReport($call_id){
- $this->load->model('projects_model');
- $data['call_report'] = $this->projects_model->fetchCallReport($call_id);
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/single_call_report";
- $this->load->view('includes/template', $data);
- }
-
-
- function projectReports(){
- $data['main_content'] = "main_content/manager_reports";
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $this->load->view('includes/template', $data);
- }
-
-
- function reportByUser(){
- $this->load->model('projects_model');
- $this->load->model('users_model');
- $users = $this->users_model->fetchuser();
- foreach($users as $user){
- $data["$user->username"] = $this->projects_model->fetchUserTasks($user->id);
- }
- $data['users'] = $this->users_model->fetchuser();
- $data['main_content'] = "main_content/report_by_user";
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $this->load->view('includes/template', $data);
-
- }
-
- function reportByProject(){
- $this->load->model('projects_model');
-
- }
-
- function gantt($project_id = ""){
- $this->load->model('projects_model');
- $project = $this->projects_model->fetchProject($project_id);
- $start = $project->time_added;
- $end = $project->project_deadline;
- $length_in_days=round(($end-$start)/60/60/24);
- $data['project'] = $project;
- $data['tasks'] = $this->projects_model->fetchtasks($project_id);
- $data['length'] = $length_in_days;
- $data['start'] = $start;
- $data['end'] = $end;
- $data['sidebar'] = "sidebar/dashboard_sidebar";
- $data['main_content'] = "main_content/project_gantt_view";
- $this->load->view('includes/template', $data);
- }
- }
- ?>