PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/projects.php

https://github.com/mariuscwium/Consensus
PHP | 799 lines | 680 code | 85 blank | 34 comment | 91 complexity | 236b71da694d98ef5d0693c41977a5cd MD5 | raw file
  1. <?php
  2. class Projects extends Controller{
  3. function __construct(){
  4. parent::Controller();
  5. $this->is_logged_in();
  6. }
  7. function super_unique($array){
  8. //ripped super_unique($array) off from http://www.php.net/manual/en/function.array-unique.php#97285
  9. $result = array_map("unserialize", array_unique(array_map("serialize", $array)));
  10. foreach ($result as $key => $value){
  11. if (is_array($value)){
  12. $result[$key] = super_unique($value);
  13. }
  14. }
  15. return $result;
  16. }
  17. function index($welcome='', $all = ''){
  18. $this->load->model('projects_model');
  19. //two queries: projects and tasks
  20. $projects = $this->projects_model->fetchproject();
  21. $tasks = $this->projects_model->fetchAllTasks();
  22. //defining some variables
  23. $userID = $this->session->userdata('userid');
  24. $user_projects = false;
  25. $projects_created_by = false;
  26. $projects_managed = false;
  27. $data['today'] = mktime(0,0,0);
  28. $data['upcoming'] = (mktime(0,0,0)+(5*24*60*60));
  29. //weed out completed tasks and sort into $project_tasks[project name], $user_projects
  30. foreach($projects as $project){
  31. $all_clients[$project->project_client_id] = $project->organisation_name;
  32. //find projects managed by this user
  33. if($project->project_manager == $userID){
  34. $user_projects[] = $project;
  35. $user_clients[$project->project_client_id] = $project->organisation_name;
  36. }
  37. //sorting tasks into project name arrays
  38. $project_tasks[$project->projects_id] = false;
  39. $completed_tasks[$project->projects_id] = false;
  40. $count_completed_tasks[$project->projects_id] = 0;
  41. $count_total_tasks[$project->projects_id] = 1;
  42. foreach($tasks as $task){
  43. if($project->projects_id == $task->task_project_id){
  44. $count_total_tasks[$project->projects_id] = $count_total_tasks[$project->projects_id]+1;
  45. }
  46. if($task->task_status !== "Completed"){
  47. if($project->projects_id == $task->task_project_id){
  48. $project_tasks[$project->projects_id][] = $task;
  49. }
  50. }elseif($task->task_status == "Completed"){
  51. if($project->projects_id == $task->task_project_id){
  52. $completed_tasks[$project->projects_id][] = $task;
  53. $count_completed_tasks[$project->projects_id] = count($completed_tasks[$project->projects_id]);
  54. }
  55. }
  56. }
  57. $count1 = $count_completed_tasks[$project->projects_id]/$count_total_tasks[$project->projects_id];
  58. $count2 = $count1*100;
  59. $count = number_format($count2, 0);
  60. $data['completion'][$project->projects_id] = $count;
  61. //finding projects in which the user has a task.
  62. if($project_tasks[$project->projects_id]){
  63. foreach($project_tasks[$project->projects_id] as $task){
  64. if($task->task_user_id == $userID){
  65. $user_projects[] = $project;
  66. $user_clients[$project->project_client_id] = $project->organisation_name;
  67. }
  68. }
  69. }
  70. }
  71. if($user_projects){
  72. $user_projects = $this->super_unique($user_projects);
  73. }
  74. asort($user_clients);
  75. asort($all_clients);
  76. $data['projects'] = $projects;
  77. $data['project_tasks'] = $project_tasks;
  78. $data['user_projects'] = $user_projects;
  79. $current_projects = false;
  80. $overdue_projects = false;
  81. $today = mktime(0,0,0);
  82. $data['user_clients'] = array_unique($user_clients);
  83. $data['all_clients'] = array_unique($all_clients);
  84. $data['overdue_projects'] = $overdue_projects;
  85. $data['user_projects'] = $user_projects;
  86. $data['projects_created_by'] = $projects_created_by;
  87. $data['current_projects'] = $current_projects;
  88. $data['sidebar'] = "sidebar/dashboard_sidebar";
  89. if(!empty($all)){
  90. $data['main_content'] = "main_content/all_projects_view";
  91. }else{
  92. $data['main_content'] = "main_content/projects_view";
  93. }
  94. $this->load->view('includes/template', $data);
  95. }
  96. function all(){
  97. }
  98. function is_logged_in(){
  99. if (!($this->session->userdata('is_logged_in'))){
  100. redirect('intrangu');
  101. }
  102. }
  103. function userdashboard($welcome='', $all = ''){
  104. $this->load->model('projects_model');
  105. //two queries: projects and tasks
  106. $projects = $this->projects_model->fetchproject();
  107. $tasks = $this->projects_model->fetchAllTasks();
  108. //defining some variables
  109. $userID = $this->session->userdata('userid');
  110. $user_projects = false;
  111. $projects_created_by = false;
  112. $projects_managed = false;
  113. $data['today'] = mktime(0,0,0);
  114. $data['upcoming'] = (mktime(0,0,0)+(5*24*60*60));
  115. //weed out completed tasks and sort into $project_tasks[project name], $user_projects
  116. foreach($projects as $project){
  117. $all_clients[$project->project_client_id] = $project->organisation_name;
  118. //find projects managed by this user
  119. if($project->project_manager == $userID){
  120. $user_projects[] = $project;
  121. $user_clients[$project->project_client_id] = $project->organisation_name;
  122. }
  123. //sorting tasks into project name arrays
  124. $project_tasks[$project->projects_id] = false;
  125. $completed_tasks[$project->projects_id] = false;
  126. $count_completed_tasks[$project->projects_id] = 0;
  127. $count_total_tasks[$project->projects_id] = 1;
  128. foreach($tasks as $task){
  129. if($project->projects_id == $task->task_project_id){
  130. $count_total_tasks[$project->projects_id] = $count_total_tasks[$project->projects_id]+1;
  131. }
  132. if($task->task_status !== "Completed"){
  133. if($project->projects_id == $task->task_project_id){
  134. $project_tasks[$project->projects_id][] = $task;
  135. }
  136. }elseif($task->task_status == "Completed"){
  137. if($project->projects_id == $task->task_project_id){
  138. $completed_tasks[$project->projects_id][] = $task;
  139. $count_completed_tasks[$project->projects_id] = count($completed_tasks[$project->projects_id]);
  140. }
  141. }
  142. }
  143. $count1 = $count_completed_tasks[$project->projects_id]/$count_total_tasks[$project->projects_id];
  144. $count2 = $count1*100;
  145. $count = number_format($count2, 0);
  146. $data['completion'][$project->projects_id] = $count;
  147. //finding projects in which the user has a task.
  148. if($project_tasks[$project->projects_id]){
  149. foreach($project_tasks[$project->projects_id] as $task){
  150. if($task->task_user_id == $userID){
  151. $user_projects[] = $project;
  152. $user_clients[$project->project_client_id] = $project->organisation_name;
  153. }
  154. }
  155. }
  156. }
  157. if($user_projects){
  158. $user_projects = $this->super_unique($user_projects);
  159. }
  160. asort($user_clients);
  161. asort($all_clients);
  162. $data['projects'] = $projects;
  163. $data['project_tasks'] = $project_tasks;
  164. $data['user_projects'] = $user_projects;
  165. $current_projects = false;
  166. $overdue_projects = false;
  167. $today = mktime(0,0,0);
  168. $data['user_clients'] = array_unique($user_clients);
  169. $data['all_clients'] = array_unique($all_clients);
  170. $data['overdue_projects'] = $overdue_projects;
  171. $data['user_projects'] = $user_projects;
  172. $data['projects_created_by'] = $projects_created_by;
  173. $data['current_projects'] = $current_projects;
  174. $this->load->model('projects_model');
  175. $news = $this->projects_model->fetch_changes_2();
  176. $data['news'] = $news;
  177. $data['sidebar'] = "sidebar/dashboard_sidebar";
  178. $data['main_content'] = "main_content/user_dashboard";
  179. $this->load->view('includes/template', $data);
  180. }
  181. function viewProject($project_id = "",$message = ""){
  182. if(empty($project_id)){
  183. $project_id = $this->uri->segment(3);
  184. }
  185. if(empty($message)){
  186. $message = false;
  187. }
  188. $this->load->model('projects_model');
  189. $data['project'] = $this->projects_model->fetchProject($project_id);
  190. $data['tasks'] = false;
  191. $today = mktime(0,0,0);
  192. $five_days_from_now = (mktime(0,0,0)+(5*24*60*60));
  193. $tasks = $this->projects_model->fetchTasks($project_id);
  194. $files = $this->projects_model->fetchFiles($project_id);
  195. if($files){
  196. $this->load->helper('file');
  197. $info = array('name','size','date');
  198. foreach($files as $file){
  199. $file_infos[] = get_file_info($file->file_path, $info);
  200. }
  201. }else{
  202. $file_infos = false;
  203. }
  204. //var_dump($file_infos);
  205. $current_tasks = false;
  206. $overdue_tasks = false;
  207. $upcoming_deadlines = false;
  208. $completed_tasks = false;
  209. $completed = 0;
  210. $total_tasks = count($tasks);
  211. if($tasks){
  212. foreach($tasks as $project_task){
  213. if ($project_task->task_status !== "Completed"){
  214. if ($project_task->task_deadline < $today){
  215. $overdue_tasks[] = $project_task;
  216. $current_tasks[] = $project_task;
  217. }else{
  218. $current_tasks[] = $project_task;
  219. if (($project_task->task_deadline < $five_days_from_now) && ($project_task->task_deadline >= mktime(0,0,0))){
  220. $upcoming_deadlines[] = $project_task;
  221. };
  222. };
  223. }elseif($project_task->task_status == "Completed"){
  224. $completed_tasks[]= $project_task;
  225. $completed = $completed+1;
  226. };
  227. };
  228. };
  229. $count1 = $completed/($total_tasks);
  230. $count2 = $count1*100;
  231. $count = number_format($count2, 0);
  232. $data['today'] = $today;
  233. $data['files'] = $file_infos;
  234. $data['upcoming'] = $five_days_from_now;
  235. $data['completion'] = $count;
  236. $data['overdue_tasks'] = $overdue_tasks;
  237. $data['current_tasks'] = $current_tasks;
  238. $data['completed_tasks'] = $completed_tasks;
  239. $data['upcoming_deadlines'] = $upcoming_deadlines;
  240. $data['sidebar'] = "sidebar/dashboard_sidebar";
  241. if($tasks){
  242. $data['tasks'] = $tasks;
  243. }
  244. $data['call_reports'] = $this->projects_model->fetchProjectCallReports($project_id);
  245. $data['message'] = $message;
  246. $data['sidebar'] = "sidebar/dashboard_sidebar";
  247. $data['main_content'] = "main_content/single_project";
  248. $this->load->view('includes/template', $data);
  249. }
  250. function newProject(){
  251. $this->load->model('projects_model');
  252. $this->load->model('users_model');
  253. $this->load->model('contacts_model');
  254. if ($this->input->post('submit')){
  255. $org = $this->input->post('project_client');
  256. if (!empty($org)){
  257. if ($this->contacts_model->getOrgID($org)){
  258. $orgID = $this->contacts_model->getOrgID($org);
  259. }else{
  260. $this->contacts_model->addOrg($org);
  261. $orgID = mysql_insert_id();
  262. }
  263. }else{
  264. $orgID = '0';
  265. }
  266. $manager = $this->input->post('project_manager');
  267. $this->projects_model->addProject($orgID);
  268. $newProjectID = mysql_insert_id();
  269. $project = $this->projects_model->fetchProject($newProjectID);
  270. $this->projects_model->addProjectMeta($newProjectID);
  271. redirect("projects/projectsteptwo/$project->projects_id");
  272. }else{
  273. //display form
  274. $data['users'] = $this->users_model->fetchUser();
  275. $data['sidebar'] = "sidebar/dashboard_sidebar";
  276. $data['main_content'] = "main_content/add_project_form";
  277. $this->load->view('includes/template', $data);
  278. }
  279. }
  280. function projectStepTwo($id){
  281. $this->load->model('projects_model');
  282. $this->load->model('contacts_model');
  283. $this->load->model('users_model');
  284. $project=$this->projects_model->fetchproject($id);
  285. if($this->input->post('submit')){
  286. $num_o_tasks=$this->input->post('num_o_tasks');
  287. $real_num_o_tasks=0;
  288. for($i=0;$i<$num_o_tasks;$i++){
  289. $j=$i+1;
  290. $task['project'] = $id;
  291. $task['name'] = $this->input->post("task_name_$j");
  292. $task['status']=$this->input->post("task_status_$j");
  293. $task['user']=$this->input->post("resp_user_$j");
  294. $task['deadline']= mktime(0,0,0,$this->input->post("month_$j"),$this->input->post("day_$j"),$this->input->post("year_$j"));
  295. if(($task['name']!=='Task name') && ($task['status'] !== 'Please select...')&&($task['user']!=='Please select...')){
  296. $task_id[$j]=$this->projects_model->bulkAddTasks($task);
  297. $real_num_o_tasks++;
  298. }
  299. }
  300. $change = "<h3>New project: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  301. if($real_num_o_tasks !==0){
  302. $change .= ucwords($this->session->userdata('username'))." added $i task(s):<ul>";
  303. for($i=0;$i<$num_o_tasks;$i++){
  304. $j=$i+1;
  305. $change .= "<li>".anchor("projects/viewtask/$task_id[$i]",$this->input->post("task_name_$j"))."</li>";
  306. }
  307. $change .= "</ul>";
  308. }else{
  309. $change .= ucwords($this->session->userdata('username'))." added no tasks to this project.";
  310. }
  311. $this->projects_model->simplerChanges($id, $change);
  312. $this->mailTeam($id,"New project: $project->project_name",$change);
  313. redirect("projects/viewproject/$id");
  314. }else{
  315. $this->load->model('projects_model');
  316. $data['users'] = $this->users_model->fetchUser();
  317. $data['project']=$project;
  318. $data['sidebar'] = "sidebar/dashboard_sidebar";
  319. $data['main_content'] = "main_content/add_project_step_two";
  320. $this->load->view("includes/template",$data);
  321. }
  322. }
  323. function updateProject($id){
  324. $this->load->model('projects_model');
  325. $this->load->model('contacts_model');
  326. $this->load->model('users_model');
  327. $project = $this->projects_model->fetchProject($id);
  328. if ($this->input->post('submit')){
  329. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  330. $change .= ucwords($this->session->userdata('username'))." updated information about this project:<ul>";
  331. $changed=false;
  332. $org = $this->input->post('project_client');
  333. if (!empty($org)){
  334. //an organisation has been entered
  335. if ($this->contacts_model->getOrgID($org)){
  336. //organisation is in DB
  337. $orgID = $this->contacts_model->getOrgID($org);
  338. }else{
  339. //organisation isn't in DB
  340. $this->contacts_model->addOrg($org);
  341. $orgID = mysql_insert_id();
  342. }
  343. }else{
  344. $orgID = '0';
  345. }
  346. if($project->project_name != $this->input->post('project_name')){
  347. $new_name = $this->input->post('project_name');
  348. $change .= "<li>New project name: $new_name</li>";
  349. $changed=true;
  350. }
  351. if($project->project_status != $this->input->post('project_status')){
  352. $new_status = $this->input->post('project_status');
  353. $change .= "<li>New project status: $new_status</li>";
  354. $changed=true;
  355. }
  356. if($project->project_manager != $this->input->post('project_manager')){
  357. $new_manager= $this->input->post('project_manager');
  358. $new_manager = $this->users_model->fetchUser($new_manager);
  359. $new_manager = ucwords($new_manager->username);
  360. $change .= "<li>New project manager: $new_manager</li>";
  361. $changed=true;
  362. }
  363. $deadline = mktime(0,0,0,$this->input->post('month'),$this->input->post('day'),$this->input->post('year'));
  364. if($project->project_deadline != $deadline){
  365. $new_deadline = $deadline;
  366. $change .= "<li>New project deadline: ". date('j F', $new_deadline)."</li>";
  367. $changed=true;
  368. }
  369. if($project->project_brief != $this->input->post('project_brief')){
  370. $new_brief = $this->input->post('project_brief');
  371. $change .= "<li>New project brief: <br /> $new_brief</li>";
  372. $changed=true;
  373. }
  374. $change .= "</ul>";
  375. if($changed){
  376. $this->projects_model->updateProject($id, $orgID);
  377. $this->projects_model->simplerChanges($id, $change);
  378. $this->mailTeam($id,"Project update: $project->project_name",$change);
  379. $message = "Project updated.";
  380. }else{
  381. $message = "No changes made.";
  382. }
  383. redirect("projects/viewproject/$id/$message");
  384. }else{
  385. //display form
  386. $data['project'] = $project;
  387. $data['users'] = $this->users_model->fetchUser();
  388. $data['sidebar'] = "sidebar/dashboard_sidebar";
  389. $data['main_content'] = "main_content/edit_project_form";
  390. $this->load->view('includes/template', $data);
  391. }
  392. }
  393. function attachFile($id){
  394. $this->load->model('projects_model');
  395. $this->load->model('users_model');
  396. $project=$this->projects_model->fetchProject($id);
  397. if(!($this->input->post('submit'))){
  398. $data['error'] = '';
  399. $data['project'] = $project;
  400. $data['users'] = $this->users_model->fetchUser();
  401. $data['sidebar'] = "sidebar/dashboard_sidebar";
  402. $data['main_content'] = "main_content/project_attach_file_view";
  403. $this->load->view('includes/template', $data);
  404. }else{
  405. $config['upload_path'] = '../consensus/uploads/';
  406. $config['allowed_types'] = 'pdf|doc|png|gif|jpg|jpeg|doc|xls|idd|psd|bmp|pdf|application|application/vnd.ms-excel|docx|xlsx';
  407. $this->load->library('upload', $config);
  408. if ( ! $this->upload->do_upload())
  409. {
  410. $error = array('error' => $this->upload->display_errors());
  411. $data['error'] = $config['upload_path'];
  412. $data['error'] = $error['error'];
  413. $data['project'] = $this->projects_model->fetchProject($id);
  414. $data['users'] = $this->users_model->fetchUser();
  415. $data['sidebar'] = "sidebar/dashboard_sidebar";
  416. $data['main_content'] = "main_content/project_attach_file_view";
  417. $this->load->view('includes/template', $data);
  418. }
  419. else
  420. {
  421. $filepath = $this->upload->data();
  422. $filepath = $filepath['full_path'];
  423. var_dump($filepath);
  424. $this->projects_model->linkFile($id,$filepath);
  425. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  426. $change .= "<p>".ucwords($this->session->userdata('username'))." attached ".anchor($filepath,"a new file")." to this project.</p>";
  427. $this->projects_model->simplerChanges($id,$change);
  428. $this->mailTeam($id,"Project update: $project->project_name",$change);
  429. redirect("projects/viewproject/$id");
  430. }
  431. }
  432. }
  433. function addTask($project_id){
  434. $this->load->model('projects_model');
  435. $this->load->model('contacts_model');
  436. $this->load->model('users_model');
  437. $project=$this->projects_model->fetch_project($project_id);
  438. if ($this->input->post('submit')){
  439. $this->projects_model->addTask($project->projects_id);
  440. $newTaskID = mysql_insert_id();
  441. $this->projects_model->addTaskMeta($newTaskID);
  442. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  443. $change .= "<p>".ucwords($this->session->userdata('username'))." added a ".anchor("projects/viewtask/$newTaskID", 'new task').".</p>";
  444. $this->projects_model->simplerChanges($project_id,$change);
  445. $this->mailTeam($id,"Project update: $project->project_name",$change);
  446. $message = "Task added";
  447. redirect("projects/viewproject/$project_id");
  448. }else{
  449. $data['project'] = $this->projects_model->fetchProject($project_id);
  450. $data['users'] = $this->users_model->fetchUser();
  451. $data['sidebar'] = false;
  452. $data['main_content'] = "main_content/add_task_form";
  453. $this->load->view('includes/template', $data);
  454. }
  455. }
  456. function viewTask($task_id,$message =""){
  457. if(empty($message)){
  458. $task = false;
  459. }
  460. $this->load->model('projects_model');
  461. $task = $this->projects_model->fetchTask($task_id);
  462. $data['notes'] = $task['notes'];
  463. $task = $task['task'];
  464. $data['task'] = $task;
  465. $data['message']= $message;
  466. $data['sidebar'] = "sidebar/dashboard_sidebar";
  467. $data['main_content'] = "main_content/single_task";
  468. $this->load->view('includes/template', $data);
  469. }
  470. function addnote($task_id){
  471. $this->load->model('projects_model');
  472. $task=$this->projects_model->fetchTask($task_id);
  473. $task=$task['task'];
  474. $project=$this->projects_model->fetchProject($task->task_project_id);
  475. $note = $this->input->post('note');
  476. $cancel= $this->input->post('cancel');
  477. if($cancel == '' && $note !== ''){
  478. $this->projects_model->addnote();
  479. }
  480. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  481. $change .= "<p>".ucwords($this->session->userdata('username'))." added a new note to the task ".anchor("projects/viewtask/$task->task_id", $task->task_name).":</p>";
  482. $change .= "<p><em>$note</em></p>";
  483. $this->projects_model->simplerChanges($project->projects_id,$change);
  484. $this->mailTeam($project->projects_id,"Project update: $project->project_name",$change);
  485. redirect("projects/viewtask/$task_id");
  486. }
  487. function updateTask($task_id){
  488. $this->load->model('projects_model');
  489. $this->load->model('contacts_model');
  490. $this->load->model('users_model');
  491. $task = $this->projects_model->fetchTask($task_id);
  492. $task = $task['task'];
  493. if ($this->input->post('submit')){
  494. $project_id = $this->input->post('project_id');
  495. $project=$this->projects_model->fetchProject($project_id);
  496. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  497. $change .= ucwords($this->session->userdata('username'))." updated the task ".anchor("projects/viewtask/$task->task_id",$task->task_name).":";
  498. $changed=false;
  499. if($task->task_name != $this->input->post('task_name')){
  500. $changed =true;
  501. $change .= "<li>New name: ".$this->input->post('task_name')."</li>";
  502. }
  503. if($task->task_status != $this->input->post('task_status')){
  504. $changed =true;
  505. $change .= "<li>New status: ".$this->input->post('task_status')."</li>";
  506. }
  507. if($task->task_user_id != $this->input->post('resp_user')){
  508. $changed =true;
  509. $new_user= $this->input->post('resp_user');
  510. $new_user = $this->users_model->fetchUser($new_user);
  511. $new_user = ucwords($new_user->username);
  512. $change .= "<li>New responsible person: ".$new_user."</li>";
  513. }
  514. $new_deadline = mktime(0,0,0,$this->input->post('month'),$this->input->post('day'),$this->input->post('year'));
  515. if($task->task_deadline != $new_deadline){
  516. $changed =true;
  517. $change .= "<li>New deadline: ".date('j F', $new_deadline)."</li>";
  518. }
  519. if($task->task_brief != $this->input->post('task_brief')){
  520. $changed =true;
  521. $change .= "<li>New brief: ".$this->input->post('task_brief')."</li>";
  522. }
  523. if($changed){
  524. $this->projects_model->updateTask($task_id);
  525. $this->projects_model->simplerChanges($project_id, $change);
  526. $message = $this->mailTeam($project_id,"Project update: $project->project_name",$change);
  527. }else{
  528. $message = "No changes made.";
  529. }
  530. redirect("projects/viewproject/$project_id/$message");
  531. }else{
  532. $data['task'] = $task;
  533. $data['users'] = $this->users_model->fetchUser();
  534. $data['sidebar'] = "sidebar/dashboard_sidebar";
  535. $data['main_content'] = "main_content/edit_task_form";
  536. $this->load->view('includes/template', $data);
  537. }
  538. }
  539. function mailTeam($project_id, $subject, $message){
  540. $this->load->model('projects_model');
  541. $team = $this->projects_model->fetchTeam($project_id);
  542. $this->load->helper('email');
  543. if(is_array($team)){
  544. $team=array_unique($team);
  545. }
  546. $data['message'] = $message;
  547. $html_message = $this->load->view('main_content/html_email_message', $data, true);
  548. foreach($team as $email){
  549. $to = $email;
  550. $subject = $subject;
  551. $headers = "From: " . strip_tags($this->session->userdata('email')) . "\r\n";
  552. $headers .= "Reply-To: ". strip_tags($this->session->userdata('email')) . "\r\n";
  553. $headers .= "MIME-Version: 1.0\r\n";
  554. $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  555. mail($to, $subject, $html_message, $headers);
  556. }
  557. //$this->email->from($this->session->userdata('email'),$this->session->userdata('username'));
  558. //$this->email->to($team);
  559. //$this->email->subject($subject);
  560. //$data['message'] = $message;
  561. //$html_message = $this->load->view('main_content/html_email_message', $data, true);
  562. //$this->email->message($html_message);
  563. //if(!($this->email->send())){
  564. // $message = "Team members could not be notified due to an email error.";
  565. //
  566. //}else{
  567. // $message = "Team members have been notified.";
  568. //
  569. //}
  570. //return $message;
  571. }
  572. function changeTaskStatus($task_id){
  573. $this->load->model('projects_model');
  574. $task = $this->projects_model->fetchTask($task_id);
  575. $task = $task['task'];
  576. $project_id = $this->input->post('project_id');;
  577. $project=$this->projects_model->fetchProject($project_id);
  578. $result = $this->input->post('task_status');
  579. $this->projects_model->updatetaskStatus($task_id, $result);
  580. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  581. $change .= ucwords($this->session->userdata('username'))." updated the status of the task ".anchor("projects/viewtask/$task->task_id",$task->task_name)." to ".$result.".";
  582. $this->projects_model->simplerChanges($project_id, $change);
  583. $this->mailTeam($project_id,"Project update: $project->project_name",$change);
  584. $message = "Task status changed to <strong>$result</strong>.";
  585. redirect("projects/viewproject/$project_id");
  586. }
  587. function deleteTask(){
  588. }
  589. function completedTasks($project_id = ""){
  590. if(empty($project_id)){
  591. $project_id = $this->uri->segment(3);
  592. }
  593. $this->load->model('projects_model');
  594. $data['project'] = $this->projects_model->fetchProject($project_id);
  595. $data['tasks'] = $this->projects_model->fetchTasks($project_id);
  596. $data['sidebar'] = "sidebar/dashboard_sidebar";
  597. $data['main_content'] = "main_content/completed_tasks";
  598. $this->load->view('includes/template', $data);
  599. }
  600. function newsFeed(){
  601. $this->load->model('projects_model');
  602. $news = $this->projects_model->fetch_changes_2();
  603. $data['news'] = $news;
  604. $data['sidebar'] = "sidebar/dashboard_sidebar";
  605. $data['main_content'] = "main_content/newsfeed2";
  606. $this->load->view('includes/template', $data);
  607. }
  608. function userProjects(){
  609. $this->load->model('projects_model');
  610. $userID = $this->session->userdata('userid');
  611. $data['user_projects'] = $this->projects_model->fetchuserprojects($userID);
  612. $data['sidebar'] = "sidebar/dashboard_sidebar";
  613. $data['main_content'] = "main_content/user_projects";
  614. $this->load->view('includes/template', $data);
  615. }
  616. function userCompletedTasks(){
  617. $this->load->model('projects_model');
  618. $userID = $this->session->userdata('userid');
  619. $data['user_tasks'] = $this->projects_model->fetchusertasks($userID);
  620. $data['sidebar'] = "sidebar/dashboard_sidebar";
  621. $data['main_content'] = "main_content/user_completed_tasks";
  622. $this->load->view('includes/template', $data);
  623. }
  624. function upcomingDeadlines(){
  625. $this->load->model('projects_model');
  626. $userID = $this->session->userdata('userid');
  627. $five_days_from_now = (mktime(0,0,0)+(5*24*60*60));
  628. $user_tasks = $this->projects_model->fetchusertasks($userID);
  629. $upcoming_deadlines = false;
  630. if($user_tasks){
  631. foreach($user_tasks as $user_task){
  632. if (($user_task->task_deadline < $five_days_from_now) && ($user_task->task_deadline >= mktime(0,0,0))){
  633. $upcoming_deadlines[] = $user_task;
  634. };
  635. };
  636. };
  637. $data['user_tasks'] = $upcoming_deadlines;
  638. $data['sidebar'] = "sidebar/dashboard_sidebar";
  639. $data['main_content'] = "main_content/upcoming_deadlines_user";
  640. $this->load->view('includes/template', $data);
  641. }
  642. function addCallReport($project_id){
  643. $this->load->model('projects_model');
  644. $this->load->model('contacts_model');
  645. $project = $this->projects_model->fetchproject($project_id);
  646. if ($this->input->post('submit')){
  647. $callID = $this->projects_model->addCallReport($project->projects_id);
  648. $change = "<h3>Project update: ".anchor("projects/viewproject/$project->projects_id",$project->project_name)."</h3>";
  649. $change .= "<p>".ucwords($this->session->userdata('username'))." added ".anchor("projects/viewcallreport/$callID",'a new call report').".";
  650. $this->projects_model->simplerChanges($change);
  651. redirect("projects/viewproject/$project_id");
  652. }else{
  653. if(empty($project_id)){
  654. $userprojects = $this->projects_model->fetchUserProjects($this->session->userdata('userid'));
  655. foreach($userprojects as $p){
  656. if($p->project_status !== "Completed"){
  657. $uprojects[] = $p;
  658. }
  659. }
  660. $data['userprojects'] = $userprojects;
  661. }else{
  662. $data['userprojects'] = false;
  663. $data['project_id'] = $project_id;
  664. }
  665. //display form
  666. $data['sidebar'] = "sidebar/dashboard_sidebar";
  667. $data['main_content'] = "main_content/add_call_report_form";
  668. $this->load->view('includes/template', $data);
  669. }
  670. }
  671. function viewCallReport($call_id){
  672. $this->load->model('projects_model');
  673. $data['call_report'] = $this->projects_model->fetchCallReport($call_id);
  674. $data['sidebar'] = "sidebar/dashboard_sidebar";
  675. $data['main_content'] = "main_content/single_call_report";
  676. $this->load->view('includes/template', $data);
  677. }
  678. function projectReports(){
  679. $data['main_content'] = "main_content/manager_reports";
  680. $data['sidebar'] = "sidebar/dashboard_sidebar";
  681. $this->load->view('includes/template', $data);
  682. }
  683. function reportByUser(){
  684. $this->load->model('projects_model');
  685. $this->load->model('users_model');
  686. $users = $this->users_model->fetchuser();
  687. foreach($users as $user){
  688. $data["$user->username"] = $this->projects_model->fetchUserTasks($user->id);
  689. }
  690. $data['users'] = $this->users_model->fetchuser();
  691. $data['main_content'] = "main_content/report_by_user";
  692. $data['sidebar'] = "sidebar/dashboard_sidebar";
  693. $this->load->view('includes/template', $data);
  694. }
  695. function reportByProject(){
  696. $this->load->model('projects_model');
  697. }
  698. function gantt($project_id = ""){
  699. $this->load->model('projects_model');
  700. $project = $this->projects_model->fetchProject($project_id);
  701. $start = $project->time_added;
  702. $end = $project->project_deadline;
  703. $length_in_days=round(($end-$start)/60/60/24);
  704. $data['project'] = $project;
  705. $data['tasks'] = $this->projects_model->fetchtasks($project_id);
  706. $data['length'] = $length_in_days;
  707. $data['start'] = $start;
  708. $data['end'] = $end;
  709. $data['sidebar'] = "sidebar/dashboard_sidebar";
  710. $data['main_content'] = "main_content/project_gantt_view";
  711. $this->load->view('includes/template', $data);
  712. }
  713. }
  714. ?>