public function action_edit($id = null) { if ($supplier = Model_Supplier::find($id)) { $val = Model_Supplier::validate('edit'); if ($val->run()) { $supplier->description = Input::post('description'); $supplier->contact_person = Input::post('contact_person'); $supplier->phone = Input::post('phone'); $supplier->email = Input::post('email'); if ($supplier->save()) { Session::set_flash('success', e('Updated supplier #' . $id)); Response::redirect('admin/suppliers/view/' . $supplier->id); } else { Session::set_flash('error', e('Could not update supplier #' . $id)); } } else { if (Input::method() == 'POST') { $supplier->description = $val->validated('description'); $supplier->contact_person = $val->validated('contact_person'); $supplier->phone = $val->validated('phone'); $supplier->email = $val->validated('email'); Session::set_flash('error', $val->error()); } $this->template->set_global('supplier', $supplier, false); } $this->template->title = "Suppliers » " . $supplier->description . " » Edit"; $this->template->content = View::forge('admin/suppliers/edit'); } else { Fuel\Core\Session::set_flash('error', 'Cannot find the selected supplier'); Fuel\Core\Response::redirect_back('admin/suppliers'); } }
public function action_edit($id = null) { if ($user_type = Model_User_Type::find($id)) { $val = Model_User_Type::validate('edit'); if ($val->run()) { $user_type->name = Input::post('name'); $user_type->group = Input::post('group'); if ($user_type->save()) { Session::set_flash('success', e('Updated user_type #' . $id)); Response::redirect('admin/user/types/view/' . $user_type->id); } else { Session::set_flash('error', e('Could not update user_type #' . $id)); } } else { if (Input::method() == 'POST') { $user_type->name = $val->validated('name'); $user_type->group = $val->validated('group'); Session::set_flash('error', $val->error()); } $this->template->set_global('user_type', $user_type, false); } $this->template->set_global('groups', $this->get_groups()); $this->template->title = "Employee Types » " . $user_type->name . " » Edit"; $this->template->content = View::forge('admin/user/types/edit'); } else { Fuel\Core\Session::set_flash('error', 'Cannot find the selected item'); Fuel\Core\Response::redirect('admin/user/types'); } }
public function action_edit($id = null) { if ($inventory_unit = Model_Inventory_Unit::find($id)) { $val = Model_Inventory_Unit::validate('edit'); if ($val->run()) { $inventory_unit->name = Input::post('name'); if ($inventory_unit->save()) { Session::set_flash('success', e('Updated inventory_unit #' . $id)); Response::redirect('admin/inventory/units/view/' . $inventory_unit->id); } else { Session::set_flash('error', e('Could not update inventory_unit #' . $id)); } } else { if (Input::method() == 'POST') { $inventory_unit->name = $val->validated('name'); Session::set_flash('error', $val->error()); } $this->template->set_global('inventory_unit', $inventory_unit, false); } $this->template->title = "Inventory Units » " . $inventory_unit->name . " » Edit"; $this->template->content = View::forge('admin/inventory/units/edit'); } else { Fuel\Core\Session::set_flash('error', 'The selected item could not be found'); Fuel\Core\Response::redirect_back('admin/inventory/units'); } }
public function action_view($id = null) { if ($setting = Model_Setting::find($id)) { $this->template->title = "Setting"; $this->template->content = View::forge('admin/settings/view', array('setting' => $setting)); } else { Fuel\Core\Session::set_flash('error', 'Cannot find the specified setting'); Fuel\Core\Response::redirect('admin/settings'); } }
public function action_view($project_id = null) { if (!($project = Model_Project::find($project_id))) { Fuel\Core\Session::set_flash('error', 'Cannot find project # ' . $project_id); Fuel\Core\Response::redirect('user/projects'); } $this->load_presenter($project); $this->template->title = 'My Projects'; $this->template->content = Fuel\Core\View::forge('user/projects/view'); }
public function action_view($id = null) { if ($user = Model_User::find($id)) { $this->template->title = "User"; $this->template->content = View::forge('admin/users/view', array('user' => $user)); } else { Fuel\Core\Session::set_flash('error', 'Cannot find the selected user'); Fuel\Core\Response::redirect_back('admin/users'); } }
public function action_view($id = null) { if (!($user = Model_User::find($id))) { Fuel\Core\Session::set_flash('error', 'Cannot find the selected user'); Fuel\Core\Response::redirect('admin/users'); } $data['user'] = $user; $data['groups'] = $this->get_groups_list(); $this->template->title = "User"; $this->template->content = View::forge('admin/users/view', $data); }
public function action_remove_fanpage($fanpage_id) { try { if (Model_UserPage::remove_fanpage(Session::get('user_id'), $fanpage_id)) { //Set flash session Session::set_flash('success', 'Remove the page successfully'); } else { Session::set_flash('error', 'Cannot remove the fanpage'); } Fuel\Core\Response::redirect('fanpage/index'); } catch (Exception $ex) { Session::set_flash('error', $ex->getMessage()); $this->log_error($ex); Response::redirect('fanpage/index'); } }
public function action_create($id = null) { if (Fuel\Core\Input::post()) { $comment = Model_Comment::forge(array('name' => Fuel\Core\Input::post('comment'), 'comment' => Fuel\Core\Input::post('comment'), 'message_id' => Fuel\Core\Input::post('message_id'))); if ($comment and $comment->save()) { Fuel\Core\Session::set_flash('success', 'Added comment #' . $comment->id . '.'); Fuel\Core\Response::redirect('messages/view/' . $comment->message_id); } else { Fuel\Core\Session::set_flash('error', 'Could not save comment'); } } else { $this->template->set_global('message', $id, false); } $data["subnav"] = array('create' => 'active'); $this->template->title = 'Comments » Create'; $data['form'] = View::forge('comments/_form'); $this->template->content = View::forge('comments/create', $data); }
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); }
public function action_logtimes($timestamp = null) { if (!Auth\Auth::has_access('timesheets.read')) { Fuel\Core\Session::set_flash('error', 'You do not have access to view timesheets'); Fuel\Core\Response::redirect('user'); } if (!$timestamp) { $timestamp = \Fuel\Core\Date::forge()->get_timestamp(); // today } if (Fuel\Core\Input::method() == 'POST') { try { // start a db transaction \Fuel\Core\DB::start_transaction(); // find all logs for this task for this day $date = date('Y-m-d', $timestamp); $starts = date('Y-m-d 00:00:00', $timestamp); $ends = date('Y-m-d 23:59:59', $timestamp); $project_task_logs = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('project_task.user_id', $this->current_user->id), array('task_started', 'BETWEEN', array($starts, $ends))))); foreach ($project_task_logs as $log) { $date_starts = date('Y-m-d', $timestamp); $date_ends = date('Y-m-d 23:59:59', $timestamp); if ($log->get_project_task()->user_id == $this->current_user->id) { if (in_array(strtotime($log->task_started), range(strtotime($date_starts), strtotime($date_ends)))) { // delete the logs $log->delete(); } } } // insert new logs if (Fuel\Core\Input::post('timeslots')) { $date = date('Y-m-d', $timestamp); $last_comment = ''; $last_task_id = ''; foreach (Fuel\Core\Input::post('timeslots') as $str) { $times = explode('_', $str); $is_billable = 0; $task_started = $date . ' ' . $times[0] . ':00'; $task_completed = $date . ' ' . $times[1] . ':00'; $project_task_id_array = Fuel\Core\Input::post('project_task_id'); $task_id = $project_task_id_array["'{$str}'"]; if (Fuel\Core\Input::post('comment_' . $str) != '') { $last_comment = Fuel\Core\Input::post('comment_' . $str); } if (intval(Fuel\Core\Input::post('is_billable_' . $str, '0')) == 1) { $is_billable = 1; } if (empty($task_id)) { $task_id = $last_task_id; } else { $last_task_id = $task_id; } if (empty($task_id)) { continue; // todo - display error } $task_log = Model_Projecttasklog::forge(array('project_task_id' => $task_id, 'comment' => $last_comment, 'task_started' => $task_started, 'task_completed' => $task_completed, 'is_billable' => $is_billable)); $task_log->save(); } } // commit to database \Fuel\Core\DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Time logs saved successfully.'); Fuel\Core\Response::redirect('user/timesheets/index/' . $timestamp); } catch (Exception $ex) { // rollback on error \Fuel\Core\DB::rollback_transaction(); \Fuel\Core\Session::set_flash('error', $ex->getMessage()); Fuel\Core\Response::redirect('user/timesheets/advanced/logtimes/' . $timestamp); } } $now = \Fuel\Core\Date::forge($timestamp)->format('mysql'); $day_starts = date('Y-m-d 00:00:00', strtotime($now)); $day_ends = date('Y-m-d 23:59:59', strtotime($now)); $today_logs = Model_Projecttasklog::find('all', array('related' => array('project_task', 'project_task.project', 'project_task.project_task_name', 'project_task.user'), 'where' => array(array('task_started', 'BETWEEN', array($day_starts, $day_ends)), array('project_task.user_id', $this->current_user->id)), 'order_by' => array(array('task_started', 'asc')))); // todo: use DB::query() instead $this->template->set_global('today_logs', $today_logs); $this->template->set_global('projects', Model_Project::find('all', array('order_by' => array(array('name', 'asc'))))); $this->template->set_global('timezones', Model_Timezone::find('all', array('order_by' => array(array('starts', 'asc'))))); $this->template->set_global('my_tasks', Model_Projecttask::find('all', array('where' => array(array('user_id', $this->current_user->id)), 'related' => array('project_task_name'), 'order_by' => array(array('project_task_description', 'asc'))))); $this->template->set_global('timestamp', $timestamp); $this->template->set_global('date', \Fuel\Core\Date::forge($timestamp)->format('mysql_date')); $this->template->title = 'Timesheets'; $this->template->content = View::forge('user/timesheets/advanced/_advanced_form'); }
public function action_deletetimes($task_log_id = null) { if (!($task_log = Model_Projecttasklog::find($task_log_id))) { Fuel\Core\Session::set_flash('error', 'Cannot delete task log # ' . $task_log_id); Fuel\Core\Response::redirect_back('user/timesheets'); } if ($task_log->delete()) { Fuel\Core\Session::set_flash('success', 'Deleted task log # ' . $task_log_id); } else { Fuel\Core\Session::set_flash('error', 'Cannot delete task log # ' . $task_log_id); } Fuel\Core\Response::redirect('user/timesheets/view/' . $task_log->project_task_id); }
/** * A typical "Hello, Bob!" type example. This uses a Presenter to * show how to use them. * * @access public * @return Response */ public function action_hello() { Fuel\Core\Response::redirect('user'); }
/** Create * * @return image response object * * Creates the captcha response */ public function create() { $this->image_type(); $this->image_captcha(); $this->image_font(); $this->set_margins(); $this->draw(); $this->distort(); $this->message(); $response = new \Fuel\Core\Response(); $response->set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); $response->set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT'); $response->set_header('Pragma', 'no-cache'); if ($this->image_type === 'png') { $response->set_header('Content-Type', 'image/png'); $response->body = imagepng($this->image_captcha); } else { if ($this->image_type === 'jpeg') { $response->set_header('Content-Type', 'image/jpeg'); $response->body = imagejpeg($this->image_captcha); } } imagedestroy($this->image_captcha); return $response; }