load->library(array('pagination', 'querystring')); } /** * 목록을 가져오는 메소드입니다 */ public function index() { $view = array(); $view['view'] = array(); /** * 페이지에 숫자가 아닌 문자가 입력되거나 1보다 작은 숫자가 입력되면 에러 페이지를 보여줍니다. */ $param =& $this->querystring; $page = (((int) $this->input->get('page')) > 0) ? ((int) $this->input->get('page')) : 1; $findex = $this->input->get('findex') ? $this->input->get('findex') : $this->{$this->modelname}->primary_key; $forder = $this->input->get('forder', null, 'desc'); $sfield = $this->input->get('sfield', null, ''); $skeyword = $this->input->get('skeyword', null, ''); $per_page = admin_listnum(); $offset = ($page - 1) * $per_page; /** * 게시판 목록에 필요한 정보를 가져옵니다. */ $this->{$this->modelname}->allow_search_field = array('id', 'user_id'); // 검색이 가능한 필드 $this->{$this->modelname}->search_field_equal = array('id'); // 검색중 like 가 아닌 = 검색을 하는 필드 $this->{$this->modelname}->allow_order_field = array('id'); // 정렬이 가능한 필드 $where = array(); $result = $this->{$this->modelname} ->get_admin_list($per_page, $offset, $where, '', $findex, $forder, $sfield, $skeyword); $list_num = $result['total_rows'] - ($page - 1) * $per_page; if (element('list', $result)) { foreach (element('list', $result) as $key => $val) { $result['list'][$key]['num'] = $list_num--; } } $view['view']['data'] = $result; /** * primary key 정보를 저장합니다 */ $view['view']['primary_key'] = $this->{$this->modelname}->primary_key; /** * 페이지네이션을 생성합니다 */ $config['base_url'] = admin_url($this->pagedir) . '?' . $param->replace('page'); $config['total_rows'] = $result['total_rows']; $config['per_page'] = $per_page; $this->pagination->initialize($config); $view['view']['paging'] = $this->pagination->create_links(); $view['view']['page'] = $page; /** * 쓰기 주소, 삭제 주소등 필요한 주소를 구합니다 */ $search_option = array('id' => '고유번호'); $view['view']['skeyword'] = ($sfield && array_key_exists($sfield, $search_option)) ? $skeyword : ''; $view['view']['search_option'] = search_option($search_option, $sfield); $view['view']['listall_url'] = admin_url($this->pagedir); $view['view']['write_url'] = admin_url($this->pagedir . '/write'); $view['view']['list_delete_url'] = admin_url($this->pagedir . '/listdelete/?' . $param->output()); /** * 어드민 레이아웃을 정의합니다 */ $layoutconfig = array('layout' => 'layout', 'skin' => 'index'); $view['layout'] = $this->layoutlib->admin($layoutconfig, $this->configlib->get_device_view_type()); $this->data = $view; $this->layout = element('layout_skin_file', element('layout', $view)); $this->view = element('view_skin_file', element('layout', $view)); } /** * 게시판 글쓰기 또는 수정 페이지를 가져오는 메소드입니다 */ public function write($pid = 0) { $view = array(); $view['view'] = array(); /** * 프라이머리키에 숫자형이 입력되지 않으면 에러처리합니다 */ if ($pid) { $pid = (int) $pid; if (empty($pid) OR $pid < 1) { show_404(); } } $primary_key = $this->{$this->modelname}->primary_key; /** * 수정 페이지일 경우 기존 데이터를 가져옵니다 */ $getdata = array(); if ($pid) { $getdata = $this->{$this->modelname}->get_one($pid); } /** * Validation 라이브러리를 가져옵니다 */ $this->load->library('form_validation'); if ( ! function_exists('password_hash')) { $this->load->helper('password'); } /** * 전송된 데이터의 유효성을 체크합니다 */ $config = array( array( 'field' => 'sendto', 'label' => '발송방법', 'rules' => 'trim|required', ), array( 'field' => 'user_token', 'label' => '토큰', 'rules' => 'trim', ), array( 'field' => 'title', 'label' => '제목', 'rules' => 'trim|required', ), array( 'field' => 'message', 'label' => '내용', 'rules' => 'trim', ) ); $this->form_validation->set_rules($config); //현재 설정 key 가져오기 $this->load->config('fcm'); $view['view']['fcm_api_key'] = $this->config->item('fcm_api_key'); /** * 유효성 검사를 하지 않는 경우, 또는 유효성 검사에 실패한 경우입니다. * 즉 글쓰기나 수정 페이지를 보고 있는 경우입니다 */ if ($this->form_validation->run() === false) { //기본값 if(!element('message', $getdata)) { $getdata['message'] = ''; } $view['view']['data'] = $getdata; //primary key 정보를 저장합니다 $view['view']['primary_key'] = $primary_key; //어드민 레이아웃을 정의합니다 $layoutconfig = array('layout' => 'layout', 'skin' => 'write'); $view['layout'] = $this->layoutlib->admin($layoutconfig, $this->configlib->get_device_view_type()); $this->data = $view; $this->layout = element('layout_skin_file', element('layout', $view)); $this->view = element('view_skin_file', element('layout', $view)); } else { /** * 유효성 검사를 통과한 경우입니다. * 즉 데이터의 insert 나 update 의 process 처리가 필요한 상황입니다 */ $updatedata = array( 'sendto' => $this->input->post('sendto', null, ''), 'topic' => $this->input->post('topic', null, ''), 'user_id' => $this->input->post('user_id', null, ''), 'user_token' => $this->input->post('user_token', null, ''), 'title' => $this->input->post('title', null, ''), 'message' => $this->input->post('message', null, ''), ); //게시물 수정 if ($this->input->post($primary_key)) { $as_id = $this->input->post($primary_key); $this->{$this->modelname}->update($as_id, $updatedata); $this->session->set_flashdata( 'message', '정상적으로 수정되었습니다' ); } else { //$this->accesslevel->check_admin('write');//20170602 에러 발생하여 주석처리 함 //푸시발송 $this->load->library('Fcm_library'); //변수 정리 $sendto = $this->input->post('sendto'); $topic = $this->input->post('topic'); $user_id = $this->input->post('user_id'); $user_token = $this->input->post('user_token'); $title = $this->input->post('title'); $message = $this->input->post('message'); //전체발송일 경우 처리 //앱에서 FCM 처리가 되지 않아 전체 FOR문을 돌리는 것으로 대체함 //20170420 if($sendto == 'topic') { $all_user_token = $this->db->select('user_userid, user_fcm_token')->where("user_fcm_token != ", "")->where("user_use_push", "1")->get("user")->result_array(); if($all_user_token) { foreach($all_user_token as $k => $v) { $sendto = 'token'; $topic = ''; $user_id = $v['user_userid']; $user_token = $v['user_fcm_token']; if(strlen($user_token) < 100) continue; $this->fcm_library->send($sendto, $topic, $user_id, $user_token, $title, $message); } } } else { $this->fcm_library->send($sendto, $topic, $user_id, $user_token, $title, $message); } $this->session->set_flashdata( 'message', '정상적으로 입력되었습니다' ); } /** * 게시물의 신규입력 또는 수정작업이 끝난 후 목록 페이지로 이동합니다 */ $param =& $this->querystring; $redirecturl = admin_url($this->pagedir . '?' . $param->output()); redirect($redirecturl); } } /** * 목록 페이지에서 선택삭제를 하는 경우 실행되는 메소드입니다 */ public function listdelete() { /** * 체크한 게시물의 삭제를 실행합니다 */ if ($this->input->post('chk') && is_array($this->input->post('chk'))) { foreach ($this->input->post('chk') as $val) { if ($val) { $this->Fcm_result_model->delete($val); } } } /** * 삭제가 끝난 후 목록페이지로 이동합니다 */ $this->session->set_flashdata( 'message', '정상적으로 삭제되었습니다' ); $param =& $this->querystring; $redirecturl = admin_url($this->pagedir . '?' . $param->output()); redirect($redirecturl); } }