public function action_create() { if (Input::method() == 'POST') { $val = Model_Client::validate('create'); if ($val->run()) { $file = Input::file('client_photo_file'); $error = false; $allowList = array(".jpeg", ".jpg", ".png"); $path = realpath(DOCROOT . "/../../uploads/client_photo/") . DS; $client_photo = ""; if ($file['size'] > 0) { $ext = strtolower(substr($file['name'], strrpos($file['name'], "."))); if (!in_array($ext, $allowList)) { Session::set_flash('error', 'ชนิดของไฟล์ภาพไม่ถูกต้อง'); $error = true; } $filename = md5(time()); if (@copy($file['tmp_name'], $path . $filename . '-o' . $ext)) { $client_photo = $filename . $ext; parent::create_cropped_thumbnail($path . $filename . "-o" . $ext, 330, 128); } else { Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง'); $error = true; } } if (!$error) { $client = Model_Client::forge(array('client_title' => Input::post('client_title'), 'client_url' => Input::post('client_url'), 'client_photo' => $client_photo, 'client_active' => 1, 'created_at' => time())); if ($client and $client->save()) { Session::set_flash('success', 'Added client #' . $client->id . '.'); Response::redirect('client'); } else { Session::set_flash('error', 'Could not save client.'); } } } else { $msg = '<ul>'; foreach ($val->error() as $field => $error) { $msg .= '<li>' . $error->get_message() . '</li>'; } $msg .= '</ul>'; Session::set_flash('error', $msg); } } $this->theme->set_template('edit'); $this->theme->get_template()->set_global('current_menu', "Clients", false); $this->theme->get_template()->set_global('current_menu_desc', "จัดการลูกค้าทั้งหมดในระบบ", false); $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "Clients", 'icon' => "fa-smile-o", 'link' => Uri::create('client/index'), 'active' => false), array('title' => "Create", 'icon' => "", 'link' => "", 'active' => true))); $this->theme->get_template()->set_global('menu', "create", false); $this->theme->get_template()->set('page_specific_js', "form_client.js"); $this->theme->set_partial('sidebar', 'common/sidebar'); $this->theme->set_partial('left', 'client/create'); }
public function action_create() { if (Input::method() == 'POST') { $val = Model_Client::validate('create'); if ($val->run()) { $client = Model_Client::forge(array('name' => Input::post('name'))); if ($client and $client->save()) { Session::set_flash('success', e('Added client #' . $client->id . '.')); Response::redirect('admin/clients'); } else { Session::set_flash('error', e('Could not save client.')); } } else { Session::set_flash('error', $val->error()); } } $this->template->title = "Clients"; $this->template->content = View::forge('admin/clients/create'); }
public function action_create($id = null) { $form = $this->setup_form(); if (Input::method() == 'POST') { if ($form->validation()->run() === true) { $fields = $form->validated(); $client = Model_Client::forge(array('code' => $fields['code'], 'name' => $fields['name'], 'name_en' => $fields['name_en'], 'status' => $fields['status'], 'created_at' => Date::forge()->get_timestamp())); if ($client and $client->save()) { Session::set_flash('success', 'Added client #' . $client->id . '.'); Response::redirect('clients'); } else { Session::set_flash('error', 'Could not create new client.'); } } else { $this->template->set_global('errors', $form->error(), false); } } $this->template->page_title = "New Client"; $this->template->set('content', $form->build(), false); }