Exemplo n.º 1
0
 static function list_rows($condition = array(), $pager = array(), $order = array())
 {
     $sort_field = !in_array($order['sort_field'], array("id")) ? "id" : $order['sort_field'];
     $table_alias = "a";
     $sort_field = $table_alias . "." . $sort_field;
     $where = "where {$table_alias}.is_del = 0";
     $args = array();
     $table = self::TABLE;
     if (!empty($condition['name'])) {
         $where .= " and {$table_alias}.name like ?";
         $args[] = "%" . $condition['name'] . "%";
     }
     if (!empty($condition['charger_name'])) {
         $where .= " and {$table_alias}.charger_name like ?";
         $args[] = "%" . $condition['charger_name'] . "%";
     }
     if (!empty($condition['tel'])) {
         $where .= " and {$table_alias}.tel like ?";
         $args[] = "%" . $condition['tel'] . "%";
     }
     if (!empty($condition['zxs_uid'])) {
         $where .= " and {$table_alias}.zxs_uid like ?";
         $args[] = "%" . $condition['zxs_uid'] . "%";
     }
     if (!empty($condition['kf_uid'])) {
         $where .= " and {$table_alias}.kf_uid like ?";
         $args[] = "%" . $condition['kf_uid'] . "%";
     }
     if (!empty($condition['area_id'])) {
         $where .= " and {$table_alias}.area_id = ?";
         $args[] = $condition['area_id'];
     }
     if (!empty($condition['agent_id'])) {
         $where .= " and {$table_alias}.agent_id = ?";
         $args[] = $condition['agent_id'];
     }
     if (!empty($condition['start_time'])) {
         $where .= " and {$table_alias}.add_time >= ?";
         $args[] = $condition['start_time'] . " 00:01";
     }
     if (!empty($condition['end_time'])) {
         $where .= " and {$table_alias}.add_time <= ?";
         $args[] = $condition['end_time'] . " 23:59";
     }
     $user_id = Model_Admin_Auth::get_user_id();
     if ($user_id > 0) {
         $uids = Model_Admin_Staff::get_sub_position_uids($user_id);
         $uids[] = $user_id;
         $where .= " and ({$table_alias}.op_uid in (" . implode(",", $uids) . ") or\n                             {$table_alias}.zxs_uid = ? or\n                             {$table_alias}.zxz_uid = ?)";
         $args[] = $user_id;
         $args[] = $user_id;
     }
     $sort_type_tpl = array("ascend" => "asc", "descend" => "desc");
     $sort_type = !in_array($order['sort_type'], array_keys($sort_type_tpl)) ? "desc" : $sort_type_tpl[$order['sort_type']];
     //_throw($sort_type);
     $count_res = self::_db()->select_row("SELECT COUNT({$table_alias}.id) AS total FROM {$table} as {$table_alias} {$where}", $args);
     $records = $count_res['total'];
     $page = $pager['page'];
     $limit = $pager['limit'];
     if ($records > 0) {
         $total_pages = ceil($records / $limit);
     } else {
         $total_pages = 1;
     }
     $skip = ($page - 1) * $limit;
     $sql = "SELECT {$table_alias}.*,{$table_alias}.id as `key`,{$table_alias}.id FROM {$table} as {$table_alias}  {$where} ORDER BY {$sort_field} {$sort_type} LIMIT {$skip},{$limit} ";
     //_throw($sql);
     //self::_debug(array($sql,$args,$condition,$pager,$order,$sort_field,$sort_type));
     $rows = self::_db()->select_rows($sql, $args);
     foreach ($rows as &$row) {
         $row['key'] = $row['id'];
         if ($row['agent_id']) {
             $agent_info = Model_Crm_Agent::detail($row['agent_id']);
             if ($agent_info && $agent_info['is_del'] == 0) {
                 $row['agent_name'] = $agent_info['com_name'];
                 $row['area_id'] = $agent_info['area_id'];
                 $row['province_id'] = $agent_info['province_id'];
             } else {
                 $row['agent_name'] = "";
                 $row['area_id'] = "";
                 $row['province_id'] = "";
             }
         } else {
             $row['area_id'] = "";
             $row['province_id'] = "";
             $row['agent_name'] = "";
         }
         $row['area_name'] = Model_Crm_Area::detail($row['area_id']);
         $row['province_name'] = Model_Province::detail($row['province_id']);
         $op_uid = $row['op_uid'];
         $staff_info = Model_Admin_Staff::get_staff_info_by_uid_from_cache($op_uid);
         if ($staff_info) {
             $row['op_name'] = $staff_info['name'];
             $row['op_avatar'] = $staff_info['avatar'];
         } else {
             $row['op_name'] = "";
             $row['op_avatar'] = "";
         }
     }
     return array("total_pages" => $total_pages, "total" => $records, "rows" => $rows);
 }
Exemplo n.º 2
0
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('employer');
     $employer = Model_Employer::find($id);
     if (!$employer) {
         Session::set_flash('error', 'Could not find employer #' . $id);
         Response::redirect('employer');
     }
     if ($employer->user_id) {
         $user = Model_User::find($employer->user_id);
     } else {
         $user = null;
     }
     if (Input::method() == 'POST') {
         //print_r(Input::post()); exit();
         $val = Model_Employer::validate('edit');
         if ($user && strlen(Input::post('password'))) {
             $val->add_field('password', 'Password', 'required|min_length[8]|max_length[20]');
             $val->add_field('password_re', 'Re-type Password', 'required|min_length[8]|max_length[20]');
         }
         $file = Input::file('employer_photo_file');
         $error = false;
         if ($val->run()) {
             $employer_photo = "";
             if ($file['size'] > 0) {
                 $allowList = array(".gif", ".jpeg", ".jpg", ".png");
                 $ext = substr($file['name'], strrpos($file['name'], "."));
                 if (!in_array($ext, $allowList)) {
                     Session::set_flash('error', 'ชนิดของไฟล์ภาพไม่ถูกต้อง');
                     $error = true;
                 }
                 $path = realpath(DOCROOT . "/../../uploads/profile_photo/employer/") . DS;
                 $filename = md5($file['name']) . $ext;
                 if (strlen(Input::post('employer_photo_file'))) {
                     @unlink($path . Input::post('employer_photo_file'));
                 }
                 if (@copy($file['tmp_name'], $path . $filename)) {
                     $employer_photo = $filename;
                 }
             }
             if (strlen(Input::post('password')) && Input::post('password') != Input::post('password_re')) {
                 Session::set_flash('error', 'กรุณากรอก Password ทั้งสองช่องให้ตรงกัน');
                 $error = true;
             }
             if (!$error) {
                 if ($user) {
                     if (strlen(Input::post('password'))) {
                         $user->password = Auth::instance()->hash_password(Input::post('password'));
                     }
                     $user->save();
                 }
                 $employer->employer_name = Input::post('employer_name');
                 $employer->employer_desc = Input::post('employer_desc');
                 $employer->employer_addr = Input::post('employer_addr');
                 $employer->province_id = Input::post('province_id');
                 $employer->employer_tel = Input::post('employer_tel');
                 $employer->employer_fax = Input::post('employer_fax');
                 $employer->employer_email = Input::post('employer_email');
                 $employer->employer_website = Input::post('employer_website');
                 $employer->employer_is_active = Input::post('employer_is_active');
                 if (strlen($employer_photo)) {
                     $employer->employer_photo = $employer_photo;
                 }
                 if ($employer->save()) {
                     Session::set_flash('success', 'Updated employer #' . $id);
                     Response::redirect('employer');
                 } else {
                     Session::set_flash('error', 'Could not update employer #' . $id);
                 }
             }
         } else {
             $employer->username = $val->validated('username');
             $employer->employer_name = $val->validated('employer_name');
             $employer->employer_desc = $val->validated('employer_desc');
             $employer->employer_addr = $val->validated('employer_addr');
             $employer->employer_tel = $val->validated('employer_tel');
             $employer->employer_fax = $val->validated('employer_fax');
             $employer->employer_email = $val->validated('employer_email');
             $employer->employer_website = $val->validated('employer_website');
             $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('employer', $employer, false);
     $this->theme->get_template()->set_global('user', $user, false);
     $this->theme->get_template()->set('current_menu', "Employers");
     $this->theme->get_template()->set('current_menu_desc', "จัดการผู้ใช้งานที่เป็นผู้ว่าจ้างทั้งหมดในระบบ");
     $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "Employers", 'icon' => "fa-building-o", 'link' => Uri::create('employer/index'), 'active' => false), array('title' => "Edit", 'icon' => "", 'link' => "", 'active' => true)));
     $this->theme->get_template()->set_global('menu', "edit", false);
     $this->theme->set_partial('sidebar', 'common/sidebar');
     $this->theme->set_partial('left', 'employer/edit');
     $this->theme->get_template()->set_global('provinces', Model_Province::get_provinces("th"), false);
 }
Exemplo n.º 3
0
 public function action_edit($id = null)
 {
     try {
         is_null($id) and Response::redirect('job');
         $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' => "Edit", 'icon' => "", 'link' => "", 'active' => true)));
         if (!($job = Model_Job::find($id))) {
             Session::set_flash('error', 'Could not find job #' . $id);
             Response::redirect('job');
         }
         // $employer = Model_Employer::find($job->employer_id);
         if (Input::method() == 'POST') {
             $val = Model_Job::validate('edit');
             /*$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]');
                     }
                 }
             }
             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());
                 
                                     if(@copy($file['tmp_name'],$path.$filename."-o".$ext)){
                                         $employer_photo = $filename.$ext;
                                         parent::create_cropped_thumbnail($path.$filename."-o".$ext, 466, 360,"@2x");
                                         parent::create_cropped_thumbnail($path.$filename."-o".$ext, 466, 360);
                                     } else {
                                         Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง');
                                         $error = true;
                                     }
                 
                                 } */
                 /* */
                 /*if(strlen($employer_photo) && strlen($employer->employer_photo)){
                 
                                     $old_ext = strtolower(substr($employer->employer_photo,strrpos($employer->employer_photo,".")));
                 
                                     $old_filename = substr($employer->employer_photo,0,strrpos($employer->employer_photo,"."));
                 
                                     @unlink($path.$old_filename.$old_ext);
                                     @unlink($path.$old_filename."@2x".$old_ext);
                                     @unlink($path.$old_filename."-o".$old_ext);
                 
                                 }*/
                 /* 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()) . $ext;
                     if (@copy($file['tmp_name'], $path . $filename)) {
                         $job_attachment = $filename;
                     } else {
                         Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ได้ โปรดลองใหม่อีกครั้ง');
                         $error = true;
                     }
                 }
                 /* */
                 if (!$error) {
                     /*$employer->province_id = Input::post('province_id');
                                         $employer->employer_name = Input::post('employer_name');
                                         $employer->employer_desc = Input::post('employer_desc');
                                         $employer->employer_addr = Input::post('employer_addr');
                                         $employer->employer_tel = Input::post('employer_tel');
                                         $employer->employer_fax = Input::post('employer_fax');
                                         $employer->employer_email = Input::post('employer_email');
                                         $employer->employer_website = Input::post('employer_website');
                                         if(strlen($employer_photo)) $employer->employer_photo = $employer_photo;
                     
                                         $employer->save();*/
                     $job->employer_id = Input::post('employer_id');
                     $job->job_desc = Input::post('job_desc');
                     $job->job_type = Input::post('job_type');
                     $job->cat_id = Input::post('cat_id');
                     $job->subcat_id = Input::post('subcat_id');
                     $job->job_qualifications = Input::post('job_qualifications');
                     $job->job_skills = Input::post('job_skills');
                     $job->job_tags = Input::post('job_tags');
                     if (strlen($job_attachment)) {
                         $job->job_attachment = $job_attachment;
                     }
                     $job->job_is_featured = Input::post('job_is_featured');
                     $job->job_is_urgent = Input::post('job_is_urgent');
                     $job->job_is_active = Input::post('job_is_active');
                     if (Input::post('job_type') == "fulltime") {
                         $job->job_title = Input::post('job_title_fulltime');
                         $job->job_areas = Input::post('job_areas');
                         $job->job_position = Input::post('job_position');
                         $job->job_welfare = Input::post('job_welfare');
                         $job->job_salary = Input::post('job_salary');
                     } else {
                         if (Input::post('job_type') == "project") {
                             $job->job_title = Input::post('job_title_project');
                             $job->job_budget = Input::post('job_budget');
                             $job->job_budget_type = Input::post('job_budget_type');
                             $job->job_budget_unit = Input::post('job_budget_unit');
                         } else {
                             if (Input::post('job_type') == "contest") {
                                 $job->job_title = Input::post('job_title_contest');
                                 $job->job_prize = Input::post('job_prize');
                             }
                         }
                     }
                     if ($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', 'Updated job #' . $id);
                         Response::redirect('job');
                     } else {
                         Session::set_flash('error', 'Could not update job #' . $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('job', $job, false);
         // $this->theme->get_template()->set_global('employer', $employer, false);
         $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);
         $current_subcats = Model_Subcategory::get_subcats_by_category($job->cat_id);
         $this->theme->get_template()->set_global('current_subcats', $current_subcats, 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/edit');
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }
Exemplo n.º 4
0
 public function action_addStaffPick($id)
 {
     is_null($id) and Response::redirect('employee');
     $employee = Model_Employee::find($id);
     if (Input::method() == "POST") {
         try {
             $file = Input::file('pick_photo_file');
             $config = array('path' => "/var/www/html/uploads/staffpick_cover/", 'ext_whitelist' => array('jpg', 'jpeg', 'png'), 'file_chmod' => 0777, 'auto_rename' => true, 'overwrite' => true, 'randomize' => true, 'create_path' => true);
             Upload::process($config);
             if (Upload::is_valid()) {
                 Upload::save();
                 $pick_photo = Upload::get_files()[0];
                 $pick = Model_EmployeePick::forge(array('employee_id' => Input::post('employee_id'), 'pick_type' => Input::post('pick_type'), 'pick_date' => Input::post('pick_date'), 'pick_photo' => $pick_photo ? $pick_photo['saved_as'] : "", 'pick_is_active' => Input::post('pick_is_active'), 'created_at' => time()));
                 if ($pick && $pick->save()) {
                     $titles = Input::post('skill_title');
                     $levels = Input::post('skill_level');
                     foreach ($titles as $key => $val) {
                         if (!strlen($val)) {
                             continue;
                         }
                         $skill = Model_EmployeePickSkill::forge(array('pick_id' => $pick->id, 'skill_title' => $val, 'skill_level' => $levels[$key], 'created_at' => time()));
                         $skill->save();
                     }
                     Session::set_flash('success', 'Added employee #' . $id . ' to Staff Picks.');
                     Response::redirect('employee/staffPicks');
                 } else {
                     Session::set_flash('error', 'Could not save employee pick.');
                 }
             }
         } catch (Exception $e) {
             die($e->getMessage());
         }
     }
     $data['employee'] = $employee;
     $skills = Model_Skill::get_computer_skills($id);
     $data['skills'] = $skills;
     $this->theme->set_template('edit');
     $this->theme->get_template()->set_global('employee', $employee, false);
     $this->theme->get_template()->set_global('skills', $skills, false);
     $this->theme->get_template()->set_global('provinces', Model_Province::get_provinces('th'));
     $this->theme->get_template()->set_global('current_menu', "Employees");
     $this->theme->get_template()->set_global('current_menu_desc', "จัดการผู้ใช้งานที่เป็นผู้หางานทั้งหมดในระบบ");
     $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "Employees", 'icon' => "fa-users", 'link' => Uri::create('employee'), 'active' => false), array('title' => "Add Staff Pick", 'icon' => "fa-plus", 'link' => "", 'active' => true)));
     $this->theme->set_partial('sidebar', 'common/sidebar');
     $this->theme->set_partial('left', 'employee/add_staff_pick')->set($data);
 }