Пример #1
0
 public function action_create()
 {
     if (Input::method() == 'POST') {
         $val = Model_Job::validate('create');
         /*$val->add_field('employer_name', 'Employer Name', 'required|max_length[255]');
           $val->add_field('employer_tel', 'Employer Tel', 'required');
           $val->add_field('employer_email', 'Employer E-Mail', 'required|valid_email');*/
         if (Input::post('job_type') == "fulltime") {
             $val->add_field('job_title_fulltime', 'Job Title', 'required|max_length[255]');
             $val->add_field('job_salary', 'Salary', 'required|is_numeric');
         } else {
             if (Input::post('job_type') == "project") {
                 $val->add_field('job_title_project', 'Job Title', 'required|max_length[255]');
                 $val->add_field('job_budget_type', 'Price offer', 'required');
                 $val->add_field('job_budget', 'Budget', 'required|is_numeric');
                 if (Input::post('job_budget_type') == "perunit") {
                     $val->add_field('job_budget_unit', 'Unit', 'required|max_length[255]');
                 }
             } else {
                 if (Input::post('job_type') == "contest") {
                     $val->add_field('job_title_contest', 'Job Title', 'required|max_length[255]');
                     $val->add_field('job_prize', 'Prize', 'required|max_length[255]');
                 }
             }
         }
         // $employer_id = 0;
         if ($val->run()) {
             $error = false;
             // $employer_photo = "";
             $job_attachment = "";
             /* upload employer logo */
             /*$file = Input::file('employer_photo_file');
             
                             $allowList = array(".jpeg", ".jpg", ".png");
             
                             $path = realpath(DOCROOT."/../../uploads/profile_photo/employer/").DS;
             
                             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()).$ext;
             
                                 if(@copy($file['tmp_name'],$path.$filename)){
                                     $employer_photo = $filename;
                                 } else {
                                     Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง');
                                     $error = true;
                                 }
             
                             }*/
             /* */
             /* upload job attachment */
             $file = Input::file('job_attachment_file');
             $allowList = array(".pdf", ".doc");
             $path = realpath(DOCROOT . "/../../uploads/job_attachment/") . DS;
             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)) {
                     $employer_photo = $filename . $ext;
                     /* retina */
                     parent::create_cropped_thumbnail($path . $filename . "-o" . $ext, 466, 360, "@2x");
                     /* */
                     /* normal */
                     parent::create_cropped_thumbnail($path . $filename . "-o" . $ext, 466, 360);
                     /* */
                 } else {
                     Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง');
                     $error = true;
                 }
             }
             /* */
             if (!$error) {
                 /*$old_employer = DB::select('*')->from('employers')
                                         ->where('employer_name','=',Input::post('employer_name'))
                                         ->execute()->as_array();
                 
                                     if(count($old_employer)){
                 
                                         $employer_id = $old_employer[0]['id'];
                 
                                     } else {
                 
                                         $employer = Model_Employer::forge(array(
                                             'user_id' => 0,
                                             'province_id' => Input::post('province_id'),
                                             'employer_name' => Input::post('employer_name'),
                                             'employer_desc' => Input::post('employer_desc'),
                                             'employer_addr' => Input::post('employer_addr'),
                                             'employer_tel' => Input::post('employer_tel'),
                                             'employer_fax' => Input::post('employer_fax'),
                                             'employer_email' => Input::post('employer_email'),
                                             'employer_website' => Input::post('employer_website'),
                                             'employer_photo' => $employer_photo,
                                             'created_at' => time()
                                         ));
                 
                                         if($employer->save()){
                                             $employer_id = $employer->id;
                                         }
                 
                                     }*/
                 $config = array('employer_id' => Input::post('employer_id'), 'job_desc' => Input::post('job_desc'), 'job_type' => Input::post('job_type'), 'cat_id' => Input::post('cat_id'), 'subcat_id' => Input::post('subcat_id'), 'job_qualifications' => Input::post('job_qualifications'), 'job_skills' => Input::post('job_skills'), 'job_tags' => Input::post('job_tags'), 'job_attachment' => $job_attachment, 'job_is_featured' => Input::post('job_is_featured'), 'job_is_urgent' => Input::post('job_is_urgent'), 'job_is_active' => Input::post('job_is_active'), 'job_is_paid' => 1, 'created_at' => time(), 'expired_at' => time() + 30 * 24 * 60 * 60);
                 if (Input::post('job_type') == "fulltime") {
                     $config['job_title'] = Input::post('job_title_fulltime');
                     $config['job_areas'] = Input::post('job_areas');
                     $config['job_position'] = Input::post('job_position');
                     $config['job_welfare'] = Input::post('job_welfare');
                     $config['job_salary'] = Input::post('job_salary');
                 } else {
                     if (Input::post('job_type') == "project") {
                         $config['job_title'] = Input::post('job_title_project');
                         $config['job_budget'] = Input::post('job_budget');
                         $config['job_budget_type'] = Input::post('job_budget_type');
                         $config['job_budget_unit'] = Input::post('job_budget_unit');
                     } else {
                         if (Input::post('job_type') == "contest") {
                             $config['job_title'] = Input::post('job_title_contest');
                             $config['job_prize'] = Input::post('job_prize');
                         }
                     }
                 }
                 $job = Model_Job::forge($config);
                 if ($job and $job->save()) {
                     /* generate tags */
                     $title = $job->job_title;
                     $title_tags = parent::split_tags($title);
                     if ($job->employer_id) {
                         $employer = Model_Employer::find($job->employer_id);
                         $company_tags = parent::split_tags($employer->employer_name);
                     } else {
                         $company_tags = array();
                     }
                     $tags = array_merge($title_tags, $company_tags);
                     foreach ($tags as $t) {
                         $t = strtolower(trim($t));
                         if (!strlen($t) || $t == " ") {
                             continue;
                         }
                         $tag = Model_JobTag::get_tag($job->id, $t);
                         if (!$tag) {
                             $tag = Model_JobTag::forge(array('job_id' => $job->id, 'tag_name' => $t, 'created_at' => time()));
                             $tag->save();
                         }
                     }
                     /* */
                     /* generate ref. no. */
                     if (!strlen($job->ref_no)) {
                         $job->job_tags = implode(",", Model_JobTag::get_tags_by_job($job->id));
                         $job->ref_no = "J" . str_pad($job->id, 7, "0", STR_PAD_LEFT);
                         $job->save();
                     }
                     $qualifications = explode(",", Input::post('job_qualifications'));
                     foreach ($qualifications as $q) {
                         if (!strlen(trim($q))) {
                             continue;
                         }
                         $qual = Model_JobQualification::get_qualification($job->id, trim($q));
                         if (!$qual) {
                             $qual = Model_JobQualification::forge(array('job_id' => $job->id, 'qualification_title' => trim($q), 'created_at' => time()));
                             $qual->save();
                         }
                     }
                     $skills = explode(",", Input::post('job_skills'));
                     foreach ($skills as $s) {
                         if (!strlen(trim($s))) {
                             continue;
                         }
                         $skill = Model_JobSkill::get_skill($job->id, trim($s));
                         if (!$skill) {
                             $skill = Model_JobSkill::forge(array('job_id' => $job->id, 'skill_title' => trim($s), 'created_at' => time()));
                             $skill->save();
                         }
                     }
                     Session::set_flash('success', 'Added job #' . $job->id . '.');
                     Response::redirect('job');
                 } else {
                     Session::set_flash('error', 'Could not save job.');
                 }
             }
         } 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', "Jobs", 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' => "Jobs", 'icon' => "fa-briefcase", 'link' => Uri::create('job/index'), 'active' => false), array('title' => "Create", 'icon' => "", 'link' => "", 'active' => true)));
     $this->theme->get_template()->set_global('cats', Model_Category::get_categories(), false);
     $this->theme->get_template()->set_global('subcats', json_encode(Model_Subcategory::get_all_subcats()), false);
     $this->theme->get_template()->set_global('current_subcats', array(), false);
     $this->theme->get_template()->set_global('provinces', Model_Province::get_provinces("th"), false);
     $this->theme->get_template()->set_global('employers', Model_Employer::get_employers_for_dropdown(), false);
     $this->theme->get_template()->set_global('page_specific_js', "form_job.js", false);
     $this->theme->set_partial('sidebar', 'common/sidebar');
     $this->theme->set_partial('left', 'job/create');
 }
Пример #2
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('news');
     $this->theme->set_template('edit');
     $this->theme->get_template()->set_global('current_menu', "News", 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' => "News", 'icon' => "eicon-newspaper", 'link' => Uri::create('news/index'), 'active' => false), array('title' => "Edit", 'icon' => "", 'link' => "", 'active' => true)));
     $this->theme->get_template()->set_global('mode', "edit", false);
     if (!($news = Model_News::find($id))) {
         Session::set_flash('error', 'Could not find news #' . $id);
         Response::redirect('news');
     }
     if (Input::method() == 'POST') {
         $file = Input::file('news_photo_file');
         $val = Model_News::validate('edit');
         if ($val->run()) {
             $allowList = array(".jpeg", ".jpg", ".png");
             $error = false;
             $path = realpath(DOCROOT . "/../../uploads/news_photo/") . DS;
             $news_photo = "";
             if ($file['size'] > 0) {
                 $ext = strtolower(substr($file['name'], strrpos($file['name'], ".")));
                 if (!in_array($ext, $allowList)) {
                     Session::set_flash('error', 'ชนิดของไฟล์ภาพไม่ถูกต้อง');
                     $error = true;
                 }
                 if (strlen($news->news_photo)) {
                     @unlink($path . $news->news_photo);
                 }
                 $filename = md5(time());
                 if (@copy($file['tmp_name'], $path . $filename . $ext)) {
                     $news_photo = $filename . $ext;
                     /* small thumbnail */
                     parent::create_cropped_thumbnail($path . $filename . $ext, 64, 64, "-s");
                     parent::create_cropped_thumbnail($path . $filename . $ext, 128, 128, "-s@2x");
                     /* */
                     /* medium thumbnail */
                     parent::create_cropped_thumbnail($path . $filename . $ext, 360, 240, "-m");
                     parent::create_cropped_thumbnail($path . $filename . $ext, 720, 480, "-m@2x");
                     /* */
                 } else {
                     Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง');
                     $error = true;
                 }
             }
             if (!$error) {
                 if (strlen($news_photo) && strlen($news->news_photo)) {
                     $old_ext = strtolower(substr($news->news_photo, strrpos($news->news_photo, ".")));
                     $old_filename = substr($news->news_photo, 0, strrpos($news->news_photo, "."));
                     @unlink($path . $old_filename . $old_ext);
                     @unlink($path . $old_filename . "-s" . $old_ext);
                     @unlink($path . $old_filename . "-s@2x" . $old_ext);
                     @unlink($path . $old_filename . "-m" . $old_ext);
                     @unlink($path . $old_filename . "-m@2x" . $old_ext);
                 }
                 $news->news_title = Input::post('news_title');
                 $news->news_short_detail = Input::post('news_short_detail');
                 $news->news_detail = Input::post('news_detail');
                 if (strlen($news_photo)) {
                     $news->news_photo = $news_photo;
                 }
                 $news->news_published = Input::post('news_published');
                 if ($news->published_at == 0 && Input::post('news_published') == 1) {
                     $news->published_at = time();
                 }
                 if ($news->save()) {
                     Session::set_flash('success', 'อัพเดตข้อมูลข่าว #' . $id . ' เรียบร้อยแล้ว');
                 } else {
                     Session::set_flash('error', 'Could not update news #' . $id);
                 }
             }
         } else {
             $msg = '<ul>';
             foreach ($val->error() as $field => $error) {
                 $msg .= '<li>' . $error->get_message() . '</li>';
             }
             $msg .= '</ul>';
             Session::set_flash('error', $msg);
         }
     }
     $this->theme->get_template()->set_global('news', $news, false);
     $this->theme->get_template()->set_global('path', "http://www.buffohero.com/uploads/news_photo/", false);
     $this->theme->set_partial('sidebar', 'common/sidebar');
     $this->theme->get_template()->set('page_specific_js', "form_news.js");
     $this->theme->set_partial('left', 'news/edit');
 }
Пример #3
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('client');
     $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' => "Edit", 'icon' => "", 'link' => "", 'active' => true)));
     if (!($client = Model_Client::find($id))) {
         Session::set_flash('error', 'Could not find client #' . $id);
         Response::redirect('client');
     }
     if (Input::method() == 'POST') {
         $val = Model_Client::validate('edit');
         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) {
                 if (strlen($client_photo) && strlen($client->client_photo)) {
                     $old_ext = strtolower(substr($client->client_photo, strrpos($client->client_photo, ".")));
                     $old_filename = substr($client->client_photo, 0, strrpos($client->client_photo, "."));
                     @unlink($path . $old_filename . $old_ext);
                     @unlink($path . $old_filename . "-o" . $old_ext);
                 }
                 $client->client_title = Input::post('client_title');
                 $client->client_url = Input::post('client_url');
                 if (strlen($client_photo)) {
                     $client->client_photo = $client_photo;
                 }
                 $client->client_active = Input::post('client_active');
                 if ($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->get_template()->set_global('client', $client, false);
     $this->theme->get_template()->set_global('menu', "edit", 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/edit');
 }