1<?php 2 3$template['tid'] = isset($nparams['tid']) ? $nparams['tid'] : '-1'; 4$template['action'] = isset($nparams['action']) ? $nparams['action'] : '-default'; 5 6if (isset($_POST['tasktype'])) { 7 $tasktype = $_POST['tasktype']; 8} else { 9 $tasktype = $nparams['tasktype']; 10} 11$template['tasktype'] = $tasktype; 12 13try { 14 15 $task = $this->model->tasks->create_object( 16 array('tasktype' => $tasktype)); 17 $template['task'] = $task; 18 19 //$template['auth_level'] = $task->get_level(); 20 //$template['user'] = $task->get_user(); 21 $value['tasktype'] = $tasktype; 22 $value['executor'] = $this->model->user_nick; 23 24 if (count($_POST) > 0) { 25 //checkboxes 26 if (!isset($_POST['all_day_event'])) { 27 $_POST['all_day_event'] = '0'; 28 } 29 30 $task->set_data($_POST); 31 32 if ($task->issue == '') { 33 $task->add_subscribent($task->reporter); 34 $task->add_subscribent($task->executor); 35 } 36 37 $tid = $this->model->tasks->save($task); 38 39 40 //don't send notification when user binds himself to the task. 41 if ($task->reporter !== $task->executor) { 42 $task->mail_notify_add(NULL, array($task->executor), 43 array('action' => $bezlang['mail_task_added_programme'])); 44 } 45 header("Location: ?id=bez:task:tid:$tid"); 46 } else { 47 if (isset($nparams['duplicate'])) { 48 $tid = (int)$nparams['duplicate']; 49 $task = $this->model->tasks->get_one($tid); 50 $value = $task->get_assoc(); 51 } else { 52 $value['all_day_event'] = '1'; 53 } 54 } 55 56 $template['users'] = $this->model->users->get_all(); 57 $template['tasktypes'] = $this->model->tasktypes->get_all(); 58 59} catch (ValidationException $e) { 60 $errors = $e->get_errors(); 61 $value = $_POST; 62} catch (DBException $e) { 63 echo nl2br($e); 64// header("Location: ?id=bez:tasks"); 65} 66 67