358 lines
11 KiB
PHP
358 lines
11 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Appcats class
|
|
*/
|
|
|
|
class Appcats extends MY_Controller
|
|
{
|
|
|
|
/**
|
|
* 관리자 페이지 상의 현재 디렉토리입니다
|
|
* 페이지 이동시 필요한 정보입니다
|
|
*/
|
|
public $pagedir = 'appmanage/appcats';
|
|
|
|
/**
|
|
* 모델을 로딩합니다
|
|
*/
|
|
protected $models = array('Contents_category', 'Upload_file', 'Apps');
|
|
|
|
/**
|
|
* 이 컨트롤러의 메인 모델 이름입니다
|
|
*/
|
|
protected $modelname = 'Contents_category_model';
|
|
|
|
/**
|
|
* 헬퍼를 로딩합니다
|
|
*/
|
|
protected $helpers = array('form', 'array', 'dhtml_editor');
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
/**
|
|
* 라이브러리를 로딩합니다
|
|
*/
|
|
$this->load->library(array('pagination', 'querystring'));
|
|
}
|
|
|
|
/**
|
|
* 목록을 가져오는 메소드입니다
|
|
*/
|
|
public function index()
|
|
{
|
|
|
|
$view = array();
|
|
$view['view'] = array();
|
|
|
|
|
|
/**
|
|
* 페이지에 숫자가 아닌 문자가 입력되거나 1보다 작은 숫자가 입력되면 에러 페이지를 보여줍니다.
|
|
*/
|
|
$param =& $this->querystring;
|
|
|
|
$app_id = $this->input->get('app_id');
|
|
|
|
if ($app_id) {
|
|
$where = array(
|
|
'cat_parent' => '0',
|
|
'app_id' => $app_id,
|
|
);
|
|
$result = $this->{$this->modelname}->get('', '', $where, '', '', 'cat_sort', 'desc');
|
|
$view['view']['data'] = $result;
|
|
}
|
|
$view['view']['applist'] = $this->Apps_model->app_list();
|
|
|
|
|
|
/**
|
|
* primary key 정보를 저장합니다
|
|
*/
|
|
$view['view']['primary_key'] = $this->{$this->modelname}->primary_key;
|
|
|
|
/**
|
|
* 어드민 레이아웃을 정의합니다
|
|
*/
|
|
$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($app_id = 0, $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');
|
|
|
|
/**
|
|
* 전송된 데이터의 유효성을 체크합니다
|
|
*/
|
|
$config = array(
|
|
array(
|
|
'field' => 'cat_code',
|
|
'label' => '분류코드',
|
|
'rules' => 'trim|required|alpha_numeric',
|
|
),
|
|
array(
|
|
'field' => 'cat_name',
|
|
'label' => '카테고리명',
|
|
'rules' => 'trim|required',
|
|
),
|
|
array(
|
|
'field' => 'cat_parent',
|
|
'label' => 'Parent',
|
|
'rules' => 'trim|numeric',
|
|
),
|
|
array(
|
|
'field' => 'cat_sort',
|
|
'label' => '정렬순서',
|
|
'rules' => 'trim|numeric',
|
|
),
|
|
);
|
|
$this->form_validation->set_rules($config);
|
|
|
|
|
|
/**
|
|
* 유효성 검사를 하지 않는 경우, 또는 유효성 검사에 실패한 경우입니다.
|
|
* 즉 글쓰기나 수정 페이지를 보고 있는 경우입니다
|
|
*/
|
|
if ($this->form_validation->run() === false) {
|
|
|
|
$parent = '';
|
|
if ($cat_parent = (int) $this->input->get('cat_parent') OR $cat_parent = element('cat_parent', $getdata)) {
|
|
$pwhere = array(
|
|
'app_id' => $app_id,
|
|
'cat_id' => $cat_parent,
|
|
);
|
|
$parent = $this->{$this->modelname}->get_one('', '', $pwhere);
|
|
if ( ! element('cat_id', $parent)) {
|
|
alert_close('잘못된 접근입니다.');
|
|
}
|
|
}
|
|
|
|
$view['view']['data'] = $getdata;
|
|
$view['view']['parent'] = $parent;
|
|
|
|
/**
|
|
* primary key 정보를 저장합니다
|
|
*/
|
|
$view['view']['primary_key'] = $primary_key;
|
|
|
|
|
|
/**
|
|
* 어드민 레이아웃을 정의합니다
|
|
*/
|
|
$layoutconfig = array('layout' => 'layout_popup', '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 처리가 필요한 상황입니다
|
|
*/
|
|
|
|
|
|
/**
|
|
* 게시물을 수정하는 경우입니다
|
|
*/
|
|
if ($this->input->post($primary_key)) {
|
|
|
|
$uniqwhere = array(
|
|
'app_id' => $app_id,
|
|
'cat_code' => $this->input->post('cat_code'),
|
|
'cat_id <>' => $this->input->post($primary_key),
|
|
);
|
|
$uniqcheck = $this->{$this->modelname}->get_one('', '', $uniqwhere);
|
|
if (element('cat_id', $uniqcheck)) {
|
|
alert('중복된 코드가 존재합니다.');
|
|
}
|
|
|
|
$updatedata = array(
|
|
'cat_code' => $this->input->post('cat_code'),
|
|
'cat_name' => $this->input->post('cat_name'),
|
|
'cat_sort' => $this->input->post('cat_sort'),
|
|
'cat_publish_time' => $this->input->post('cat_publish_time'),
|
|
);
|
|
|
|
|
|
$this->{$this->modelname}->update($this->input->post($primary_key), $updatedata);
|
|
$cat_parent = (int) $this->input->post('cat_parent');
|
|
|
|
alert_refresh_close('정상적으로 수정되었습니다', admin_url('appmanage/appcats?app_id=' . $app_id . '&cat1_id=' . $cat_parent));
|
|
|
|
} else {
|
|
|
|
$uniqwhere = array(
|
|
'app_id' => $app_id,
|
|
'cat_code' => $this->input->post('cat_code'),
|
|
);
|
|
$uniqcheck = $this->{$this->modelname}->get_one('', '', $uniqwhere);
|
|
if (element('cat_id', $uniqcheck)) {
|
|
alert('중복된 코드가 존재합니다.');
|
|
}
|
|
|
|
$cat_parent = (int) $this->input->post('cat_parent');
|
|
|
|
if ($cat_parent) {
|
|
$pwhere = array(
|
|
'app_id' => $app_id,
|
|
'cat_id' => $cat_parent,
|
|
);
|
|
$parent = $this->{$this->modelname}->get_one('', '', $pwhere);
|
|
if ( ! element('cat_id', $parent)) {
|
|
alert_close('잘못된 접근입니다.');
|
|
}
|
|
$cat_depth = element('cat_depth', $parent) + 1;
|
|
} else {
|
|
$cat_depth = 1;
|
|
}
|
|
|
|
$updatedata = array(
|
|
'app_id' => $app_id,
|
|
'cat_parent' => $cat_parent,
|
|
'cat_depth' => $cat_depth,
|
|
'cat_code' => $this->input->post('cat_code'),
|
|
'cat_name' => $this->input->post('cat_name'),
|
|
'cat_sort' => $this->input->post('cat_sort'),
|
|
'cat_publish_time' => $this->input->post('cat_publish_time'),
|
|
);
|
|
|
|
|
|
/**
|
|
* 게시물을 새로 입력하는 경우입니다
|
|
*/
|
|
$insert_id = $this->{$this->modelname}->insert($updatedata);
|
|
|
|
alert_refresh_close('정상적으로 입력되었습니다', admin_url('appmanage/appcats?app_id=' . $app_id . '&cat1_id=' . $cat_parent));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getcategory($app_id= '', $parent_id = '', $depth = '')
|
|
{
|
|
if ( ! $app_id) show_404();
|
|
if ( ! $parent_id) show_404();
|
|
if ( ! $depth) show_404();
|
|
if ($depth != '2' && $depth != '3' && $depth != '4') show_404();
|
|
|
|
$view = array();
|
|
$view['view'] = array();
|
|
|
|
|
|
$where = array(
|
|
'app_id' => $app_id,
|
|
'cat_parent' => $parent_id,
|
|
'cat_depth' => $depth,
|
|
);
|
|
$result = $this->{$this->modelname}->get('', '', $where, '', '', 'cat_sort', 'desc');
|
|
|
|
$nextdepth = $depth + 1;
|
|
|
|
|
|
/**
|
|
* primary key 정보를 저장합니다
|
|
*/
|
|
$view['view']['primary_key'] = $this->{$this->modelname}->primary_key;
|
|
|
|
$html = '<div class="list-group"><li class="list-group-item active">';
|
|
$cattitle = '';
|
|
if ($depth == '2') {
|
|
$cattitle = '2차분류';
|
|
}
|
|
else if ($depth == '3') {
|
|
$cattitle = '소분류';
|
|
}
|
|
else if ($depth == '4') {
|
|
$cattitle = '세분류';
|
|
}
|
|
$html .= $cattitle . '<button type="button" class="btn btn-xs pull-right btn-default" onClick="add_category(\'' . $app_id . '\', \'' . $parent_id . '\');">추가</button></li>';
|
|
|
|
if ($result) {
|
|
foreach ($result as $key => $value) {
|
|
$html .= '<li class="list-group-item">';
|
|
if ($nextdepth < 5) {
|
|
$html .= '<a href="javascript:;" onclick="show_sub_category(\'' . $app_id . '\', \'' . element('cat_id', $value) . '\', \'' . $nextdepth . '\');">';
|
|
}
|
|
$html .= html_escape(element('cat_name', $value));
|
|
if ($nextdepth < 5) {
|
|
$html .= '</a>';
|
|
}
|
|
$html .= ' ('. html_escape(element('cat_code', $value)) . ')';
|
|
$html .= '<span class="label label-default">' . element('cat_sort', $value) . '</span>';
|
|
$html .= '<button type="button" class="btn btn-xs pull-right bg-olive" onClick="modify_category(\'' . $app_id . '\', \'' . $parent_id . '\', \'' . element('cat_id', $value) . '\');">수정</button></li>';
|
|
}
|
|
}
|
|
|
|
$html .= '</div>';
|
|
|
|
echo $html;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 삭제를 하는 경우 실행되는 메소드입니다
|
|
*/
|
|
public function delete($id='')
|
|
{
|
|
if ( ! $id) show_404();
|
|
|
|
$data = $this->{$this->modelname}->get_one($id);
|
|
if ( ! element('app_id', $data)) {
|
|
alert_close('잘못된 접근입니다.');
|
|
}
|
|
/**
|
|
* 체크한 게시물의 삭제를 실행합니다
|
|
*/
|
|
$this->_recursiveDelete(element('app_id', $data), $id);
|
|
alert_refresh_close('정상적으로 삭제되었습니다');
|
|
}
|
|
|
|
public function _recursiveDelete($app_id, $id) {
|
|
|
|
$result=$this->{$this->modelname}->get('', '', array('app_id' => $app_id, 'cat_parent' => $id));
|
|
if (count($result)) {
|
|
foreach($result as $current) {
|
|
$this->_recursiveDelete($app_id, element('cat_id', $current));
|
|
}
|
|
}
|
|
$this->{$this->modelname}->delete($id);
|
|
|
|
return true;
|
|
}
|
|
} |