public function action_addtask($project_id) { if (!($project = Model_Project::find($project_id))) { \Fuel\Core\Session::set_flash('error', "Cannot find the selected project # {$project_id}"); \Fuel\Core\Response::redirect_back('user/projects'); } $val = Model_Projecttask::validate('create'); if (\Fuel\Core\Input::method() == 'POST') { if ($val->run()) { $projecttask = Model_Projecttask::forge(array('project_id' => Input::post('project_id'), 'user_id' => Input::post('user_id'), 'project_task_name_id' => Input::post('project_task_name_id'), 'hourly_rate' => Input::post('hourly_rate'), 'task_status' => 0, 'task_due' => Input::post('task_due'), 'project_task_description' => Input::post('project_task_description'), 'comment' => Input::post('comment'), 'priority' => Input::post('priority'))); if ($projecttask and $projecttask->save()) { Session::set_flash('success', e('Added task #' . $projecttask->id . '.')); Response::redirect('user/projects/view/' . $project_id); } else { Session::set_flash('error', e('Could not save task.')); } } else { \Fuel\Core\Session::set_flash('error', $val->error()); } } $this->load_presenter($project, Model_Projecttask::forge(array('id' => 0, 'project_id' => $project->id, 'user_id' => $this->current_user->id, 'task_status' => 0, 'hourly_rate' => 456, 'task_due' => date('Y-m-d')))); $this->template->set_global('project_task_names', Model_Projecttaskname::find('all', array('order_by' => array(array('name', 'asc'))))); $this->template->set_global('users', array(Model_User::find($this->current_user->id))); $this->template->set_global('priorities', THelper::get_priorities()); $this->template->title = 'My Projects'; $this->template->content = Fuel\Core\View::forge('user/projects/addtask'); }
public function action_learn_view_m1() { $view = Fuel\Core\View::forge('layout'); $view->set_global('username', 'Joe14'); $view->set_global('title', 'Home'); $view->set_global('site_title', 'My website'); $view->head = Fuel\Core\View::forge('head'); $view->header = Fuel\Core\View::forge('header'); $view->content = Fuel\Core\View::forge('content'); $view->footer = Fuel\Core\View::forge('footer'); //return view object to the request return $view; }
public function action_register() { if (Auth\Auth::check()) { Fuel\Core\Session::set_flash('error', 'You cannot register as a user whilst you are logged in.'); Fuel\Core\Response::redirect('/'); } $val = Fuel\Core\Validation::forge('user_registration_validator'); // add validation rules $val->add('fullname', 'Your fullname')->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 255); $val->add('password', 'Your password')->add_rule('required')->add_rule('min_length', 5); $val->add('confirm_password', 'Confirm password')->add_rule('required'); if (\Fuel\Core\Input::method() == 'POST') { // run validation on POST if ($val->run(\Fuel\Core\Input::post())) { try { $created = Auth\Auth::create_user(\Fuel\Core\Input::post('username'), \Fuel\Core\Input::post('password'), \Fuel\Core\Input::post('email'), 1, array('fullname' => \Fuel\Core\Input::post('fullname'))); if ($created) { Fuel\Core\Session::set_flash('success', 'New account created.'); Fuel\Core\Response::redirect('user'); } else { Fuel\Core\Session::set_flash('error', 'Registration error: Failed to create account.'); } } catch (\SimpleUserUpdateException $ex) { // duplicate email address if ($ex->getCode() == 2) { Fuel\Core\Session::set_flash('error', 'Email already exists.'); } elseif ($ex->getCode() == 3) { Fuel\Core\Session::set_flash('error', 'Username already exists.'); } else { Fuel\Core\Session::set_flash('error', $ex->getMessage()); } } } else { // validation failed Fuel\Core\Session::set_flash('registration_error', 'Registration error: Invalid user data.'); } } $this->template->user_is_admin = $this->check_user_is_admin(); $this->template->title = 'Register'; $this->template->content = Fuel\Core\View::forge('user/register', array('val' => $val), false); }
/** * * @param type $task_id Identifies the task to be edited */ public function action_addtimes($task_id = null) { if (Fuel\Core\Input::method() == 'POST') { $task_id = Fuel\Core\Input::post('project_task_id'); } if (!($task = Model_Projecttask::find($task_id))) { Fuel\Core\Session::set_flash('error', 'Cannot find task # ' . $task_id); Fuel\Core\Response::redirect_back('admin/timesheets'); } if (Fuel\Core\Input::method() == 'POST') { $val = Model_Projecttasklog::validate('create'); if ($val->run()) { $task_log = Model_Projecttasklog::forge(array('project_task_id' => Fuel\Core\Input::post('project_task_id'), 'task_started' => Fuel\Core\Input::post('task_started') . ' ' . Fuel\Core\Input::post('task_started_hr') . ':' . Fuel\Core\Input::post('task_started_min') . ':00', 'task_completed' => Fuel\Core\Input::post('task_completed') . ' ' . Fuel\Core\Input::post('task_completed_hr') . ':' . Fuel\Core\Input::post('task_completed_min') . ':00', 'comment' => Fuel\Core\Input::post('comment'))); if ($task_log->save()) { Fuel\Core\Session::set_flash('success', 'Saved time log for task # ' . $task_id); Fuel\Core\Response::redirect('user/timesheets/view/' . $task_id); } else { Fuel\Core\Session::set_flash('error', 'Cannot save time log for task # ' . $task_id); } } else { Fuel\Core\Session::set_flash('error', $val->error()); } } $view = Fuel\Core\View::forge('user/timesheets/addtimes'); $view->set_global('task', $task); $view->set_global('task_log', Model_Projecttasklog::forge(array('id' => 0, 'project_task_id' => $task_id))); $this->template->user_is_admin = $this->check_user_is_admin(); $this->template->title = 'Timesheets'; $this->template->content = $view; }