<?php
defined('BASEPATH') OR exit('No direct script access allowed');

include_once (APPPATH.'core/admin/cm_controller.php');

class maptoon_test extends cm_controller {

	var $tb_name_category = 'mt_categories';
	var $tb_name_episode = 'mt_episodes';
	var $tb_name_maptoon_list = 'mt_list';
	var $tb_name_notice = 'mt_notices';
	var $tb_name_cartoonist = 'mt_cartoonists';
	var $total_count = 20; // total # of list
	var $list_limit = 10; // total # of pages

	function __construct() {
		parent::__construct();
		$this->load->library('util');
	}

	/*
	@desc : list all the maptoon categories
	 */
	public function fn_category() {
		$idx = $this->input->get('idx');

		$this->load->database();
		if(is_numeric($idx)==TRUE && $idx>0) { 
			$query = $this->db->get_where($this->tb_name_category,['idx'=>$idx]);
			$row = $query->row_array();
			if($row!=FALSE) {
				$row['result'] = 'success';
			}
			echo json_encode($row);
			exit;
		} else {
	        $query = $this->db->get($this->tb_name_category);
	        $i = 0;
	        $return_data = array();
	        foreach($query->result_array() as $row) {
	            $return_data['list'][$i] = $row;
	            $i++;
	        }
			return $this->load->view('/admin/maptoon/category_list', $return_data, true);
		}
	}

	/*
	@desc : register category
	 */
	public function fn_category_proc() {
		$c_name = $this->input->post('c_name');
		$mode = $this->input->post('mode');
		$idx  = $this->input->post('idx');
		$c_name = trim($c_name);

		if($c_name!='') {
			if($mode=='upt') {
				if(is_numeric($idx)==TRUE && $idx>0) {
					$data = ['c_name'=>$c_name];
					$this->db->where('idx',$idx);
					$ret = $this->db->update($this->tb_name_category, $data);
					if($ret==TRUE) {
						$this->util->js_alert_parent_reload('수정되었습니다.');
					} else {
						$this->util->js_alert('DB error');
					}
				} else {
					$this->util->js_alert('키값이 입력되지 않았습니다.');
				}
			} else {
				$data = ['c_name' => $c_name];
				$ret = $this->db->insert($this->tb_name_category,$data);
				if($ret==TRUE) {
					$this->util->js_alert_parent_reload('등록되었습니다.');
				} else {
					$this->util->js_alert('DB error');
				}
			}
		} else {
			$this->util->js_alert('카테고리 이름을 입력해 주십시오');
		}
		exit;
	}

	public function fn_category_detail($idx) {
		if(is_numeric($idx)==TRUE && $idx>0) {

			$return_data = ['c_name' => ''];
			$this->load->model('admin/maptoon/m_maptoon');
			$data_category = $this->m_maptoon->get_category($idx);
			if($data_category!=FALSE && isset($data_category['c_name'])==TRUE) {
				$return_data['c_name'] = $data_category['c_name'];
			}			
			// get episodes in chosen category
			$data_episodes = $this->m_maptoon->get_episodes_by_category($idx);
			if($data_episodes!=FALSE) {
				$return_data['data'] = $data_episodes;
			} else {
				$return_data['data'] = '';
			}

			return $this->load->view('/admin/maptoon/category_detail', $return_data, true);
		} else {
			$this->util->js_alert_back('잘못된 접근입니다.'); exit;
		}
	}

	/*
	title: get list of maptoon episodes
	 */
	public function fn_get_episodes($str) {
		$str = trim($str);
		if($str!='') {

		}
	}

	/*
	@desc : delete category
	 */
	public function fn_category_del_proc() {
		$idx  = $this->input->post('idx');

		if(is_numeric($idx)==TRUE && $idx>0) {
			$this->db->where('idx',$idx);
			$ret = $this->db->delete($this->tb_name_category);
			if($ret==TRUE) {
				$this->db->where('mt_categories_idx',$idx);
				$data = ['mt_categories_idx' => 0];
				$ret = $this->db->update($this->tb_name_episode,$data);
				//echo $this->db->last_query();
				$this->util->js_alert_parent_reload('삭제되었습니다.');
			}
		} else {
			$this->util->js_alert('키값이 전달되지 않았습니다.');
		}
		exit;
	}


	/*
	@desc : list all maptoons
	 */
	public function fn_maptoon_list() {
		$page = $this->input->get('page',TRUE);

		$this->load->model('admin/maptoon/m_maptoon');
		//$query_string = ['status'=>1, 'mt_cartoonists_idx'=>1];
		$query_string = [];
		$data = $this->m_maptoon->get_maptoon_list($query_string);
		$arr_cartoonist = $this->m_maptoon->get_cartoonist_list();

		# paging 설정
        if($page == '') $page = 1;
        $limit  = PAGE_SIZE;
        $offset = ($page-1) * $limit;

        # pagination
        $req_data = array();
        $req_data['total_count']    = $this->total_count;
        $req_data['limit']          = $this->list_limit;
        $req_data['base_url']       = '/admin/maptoon/maptoon_list/10/' ;
        $req_data['suffix']         = '?'.$_SERVER['QUERY_STRING'];

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);
        $return_data = $req_data;
		$return_data['list'] = $data;
		$return_data['page'] = $page;
		$return_data['cartoonist'] = $arr_cartoonist;
		return $this->load->view('/admin/maptoon/list', $return_data, true);
	}

	public function fn_maptoon_detail() {
		$idx = $this->input->get('idx');

		$this->load->model('/admin/maptoon/m_maptoon');
		$arr_cartoonist = $this->m_maptoon->get_cartoonist_list();
		$return_data['cartoonist'] = $arr_cartoonist;

		if(is_numeric($idx)==TRUE && $idx>0) {
			$row = $this->m_maptoon->get_maptoon_list(['idx' => $idx]);
			if(isset($row[0])==TRUE) {
				$return_data['data'] = $row[0];
			}
		} else {
			$return_data['data'] = [];
		}
		return $this->load->view('/admin/maptoon/maptoon_detail', $return_data, true);
	}

	/*
	@desc : register maptoon
	 */
	public function fn_maptoon_proc() {
		$idx = $this->input->post('idx');
		$mode = $this->input->post('mode');
		$mt_cartoonists_idx = $this->input->post('mt_cartoonists_idx');	//
		$name = $this->input->post('name');	//
		$status = $this->input->post('status');
		$date_sun = ($this->input->post('date_sun')=='') ? 0 : $this->input->post('date_sun');
		$date_mon = ($this->input->post('date_mon')=='') ? 0 : $this->input->post('date_mon');
		$date_tue = ($this->input->post('date_tue')=='') ? 0 : $this->input->post('date_tue');
		$date_wed = ($this->input->post('date_wed')=='') ? 0 : $this->input->post('date_wed');
		$date_thu = ($this->input->post('date_thu')=='') ? 0 : $this->input->post('date_thu');
		$date_fri = ($this->input->post('date_fri')=='') ? 0 : $this->input->post('date_fri');
		$date_sat = ($this->input->post('date_sat')=='') ? 0 : $this->input->post('date_sat');
		$description = $this->input->post('description');

		if($name=='') {
			$this->util->js_alert_back('맵툰명을 입력해주십시오'); exit;
		}
		if($mt_cartoonists_idx=='') {
			$this->util->js_alert_back('맵툰작가를 입력해주십시오'); exit;
		}

		//이미지 업로드
        if($_FILES['main_img']['name']!='') {
        	$mid_url_path = date("Y")."/".date("m");
	        $upload_path = MAPTOON_DIR_BACK.$mid_url_path;
	        if (!is_dir($upload_path)) {
	            umask(0);
	            mkdir($upload_path, 0777, TRUE);
	        } 
	        $config['max_size'] = 20*1024;
	        $config['upload_path'] = $upload_path;
	        $config['allowed_types'] = 'gif|jpg|png|jpeg';
	        $config['encrypt_name'] = TRUE;

	        $this->load->library('upload');
	        $this->upload->initialize($config);
	        
	        $file_name= date("H").date("i").date("s");
	        
	        if ( ! $this->upload->do_upload('main_img')) {
	            $error = array('error' => $this->upload->display_errors());
	            gf_alert("이미지 업로드에 실패했습니다.", 'back');
	        }
	        $arr_upload_data = $this->upload->data();
	        $img_data = (isset($arr_upload_data['file_name'])==TRUE) ? MAPTOON_DIR_FRONT.$mid_url_path.'/'.$arr_upload_data['file_name'] : '';
        } else {
        	$img_data = '';
        }

        if(is_numeric($idx)==TRUE && $idx>0) {	// update data
        	echo 'asdf'; exit;
        } else {	// insert data
        	$data = ['main_img' => $img_data,
    			'name' => $name,
    			'status' => $status,
    			'date_sun' => $date_sun,
    			'date_mon' => $date_mon,
    			'date_tue' => $date_tue,
        		'date_wed' => $date_wed,
        		'date_thu' => $date_thu,
        		'date_fri' => $date_fri,
        		'date_sat' => $date_sat,
        		'description' => $description,
        		'reg_date' => date("Y-m-d H:i:s"),
        		'mt_cartoonists_idx' => $mt_cartoonists_idx];

        	$this->load->model('admin/maptoon/m_maptoon');
        	$ret = $this->m_maptoon->insert_maptoon($data);
        	if($ret==TRUE) {
        		$this->util->js_alert_go('등록되었습니다','/admin/maptoon/maptoon_list/10');exit;
        	} else {
        		$this->util->js_alert_back('등록되지 않았습니다. 다시 시도해 주세요');exit;
        	}
        }
	}


	/*
	@desc : delete maptoon
	 */
	public function fn_maptoon_del_proc() {

	}

	/*
	@desc : show list of maptoon episodes
	 */
	public function fn_episode() {
		$return_data['list'] = $result = array();

		$this->load->model('/admin/maptoon/m_maptoon');
		$arr_cartoonist = $this->m_maptoon->get_cartoonist_list();  //작가 이름
		$arr_mt_title = $this->m_maptoon->get_mt_title(); //맵툰 이름 리스트
		$query = $this->db->get($this->tb_name_category);		
		$arr_category = $query->result_array(); //카테고리 리스트
		


		$page = $this->input->get('page',TRUE);

	
		$query_string = $_SERVER['QUERY_STRING'];
		parse_str($query_string);


		if(isset($author)) $arr_cartoonist_idx = $this->get_cartoonist_idx_by_name(urldecode($author));

		# 검색
		$req_data = array();
		isset($sort_list)?            $req_data['sort_list']=$sort_list             :$req_data['sort_list']=""; // 최신 조회
		isset($date_reg)?             $req_data['date_reg']=$date_reg               :$req_data['date_reg']="";  // 등록 날짜별
		isset($ca)?                   $req_data['category']=$ca                     :$req_data['category']="";  // 카테고리
		isset($sdate)?                $req_data['sdate']=$sdate                     :$req_data['sdate']="";     // 시작일
		isset($edate)?                $req_data['edate']=$edate                     :$req_data['edate']="";     // 종료일
		isset($mt_name)?              $req_data['mt_name']= urldecode($mt_name)     :$req_data['mt_name']="";   // 맵툰 이름
		isset($ep_title)?             $req_data['ep_title']= urldecode($ep_title)   :$req_data['ep_title']="";  // 맵툰 제목
		isset($arr_cartoonist_idx)?   $req_data['author']= urldecode($author)       :$req_data['author']="";    // 작가 번호
		

		# paging 설정
		if($page == '') $page = 1;
		$limit  = PAGE_SIZE;
		$offset = ($page-1) * $limit;

		$req_data['offset'] = $offset;
		$req_data['limit']  = $limit;

		//list 가져오기
		$this->load->model('/admin/maptoon/m_maptoon_test');
		$data = $this->m_maptoon_test->get_episode_list($req_data);

        # pagination
        $req_data = array();
        $req_data['total_count']    = $this->total_count;
        $req_data['limit']          = $this->list_limit;
        $req_data['base_url']       = '/admin/maptoon/episode/10/' ;
        $req_data['suffix']         = '?'.$query_string;

        $this->load->library('comm_admin');
        $pagination = $this->comm_admin->fn_pagination($req_data);
        $return_data = $req_data;
		$return_data['list']         = $data;
		$return_data['page']         = $page;
		$return_data['mt_title' ]    = $pagination;
		$return_data['cartoonist']   = $arr_cartoonist; // 작가 이름
		$return_data['mt_title' ]    = $arr_mt_title; // 맵툰 이름
		$return_data['category']     = $arr_category; // 카테고리 리스트
		
		return $this->load->view('/admin/maptoon/episode_list', $return_data, true);
	}

	/*
	@desc : register form for maptoon episode
	 */
	public function fn_episode_reg() {
		$this->load->model('admin/maptoon/m_maptoon');

		$return_data['cartoonist'] = $this->m_maptoon->get_cartoonist_list();
		$return_data['mt_title' ] = $this->m_maptoon->get_mt_title();

		if(empty($this->input->post('idx')==FALSE)){
			$query = $this->db->get_where($this->tb_name_episode,['idx'=>$idx]);
			$row = $query->row_array();
			$return_data['modify_data'] = $row;
		}


		$query = $this->db->get($this->tb_name_category);		
		$arr_category = $query->result_array();

		$return_data['category']=$arr_category;

		return $this->load->view('/admin/maptoon/episode_reg', $return_data, true);	
	}

	/*
	@desc : register maptoon episode
	 */
	public function fn_episode_reg_proc() {
		$mt_categories_idx = $this->input->post("mt_categories_idx");
		$mt_list_idx       = $this->input->post("mt_list_idx");
		$title             = $this->input->post("title");
		$display_date      = $this->input->post("display_date");
		$is_display        = $this->input->post("is_display"); //0: NO 1:YES

		//메인이미지 업로드
		if($_FILES['main_img']['name']!='') {
        	$mid_url_path = date("Y")."/".date("m");
	        $upload_path = MAPTOON_DIR_BACK.$mid_url_path;
	        if (!is_dir($upload_path)) {
	            umask(0);
	            mkdir($upload_path, 0777, TRUE);
	        } 
	        $config['max_size'] = 20*1024;
	        $config['upload_path'] = $upload_path;
	        $config['allowed_types'] = 'gif|jpg|png|jpeg';
	        $config['encrypt_name'] = TRUE;

	        $this->load->library('upload');
	        $this->upload->initialize($config);
	        
	        $file_name= date("H").date("i").date("s");
	        
	        if ( ! $this->upload->do_upload('main_img')) {
	            $error = array('error' => $this->upload->display_errors());
	            gf_alert("이미지 업로드에 실패했습니다.", 'back');
	        }
	        $arr_upload_data = $this->upload->data();
	        $main_img = (isset($arr_upload_data['file_name'])==TRUE) ? MAPTOON_DIR_FRONT.$mid_url_path.'/'.$arr_upload_data['file_name'] : '';
		} else {
			$main_img = '';
		}
			
		//맵툰이미지 업로드
		$data = array();
		$filesCount = count($_FILES['webtoon_images']['name']);
		if($filesCount>1){
			for($i =0; $i<$filesCount;$i++){
				$_FILES['webtoon_images'.$i]['name']     = $_FILES['webtoon_images']['name'][$i];
				$_FILES['webtoon_images'.$i]['type']     = $_FILES['webtoon_images']['type'][$i];
				$_FILES['webtoon_images'.$i]['tmp_name'] = $_FILES['webtoon_images']['tmp_name'][$i];
				$_FILES['webtoon_images'.$i]['error']     = $_FILES['webtoon_images']['error'][$i];
				$_FILES['webtoon_images'.$i]['size']     = $_FILES['webtoon_images']['size'][$i];
				//이미지 업로드
				if($_FILES['webtoon_images'.$i]['name']!='') {
					$mid_url_path = date("Y")."/".date("m");
					$upload_path = MAPTOON_DIR_BACK.$mid_url_path;
						if (!is_dir($upload_path)) {
							umask(0);
							mkdir($upload_path, 0777, TRUE);
						} 
						$config['max_size'] = 20*1024;
						$config['upload_path'] = $upload_path;
						$config['allowed_types'] = 'gif|jpg|png|jpeg';
						$config['encrypt_name'] = TRUE;

						$this->load->library('upload');
						$this->upload->initialize($config);
					
						$file_name= 'webtoon_images'.$i.date("H").date("i").date("s");
					
						if ( ! $this->upload->do_upload('webtoon_images'.$i)) {
							$error = array('error' => $this->upload->display_errors());
							gf_alert("이미지 업로드에 실패했습니다.", 'back');
						}
						$arr_upload_data = $this->upload->data();
						$webtoon_images[$i] = (isset($arr_upload_data['file_name'])==TRUE) ? MAPTOON_DIR_FRONT.$mid_url_path.'/'.$arr_upload_data['file_name'] : '';
				} else {
						$webtoon_images = '';
				}
			}
		}else if($filesCount==1){
			if($_FILES['webtoon_images']['name']!='') {
				$mid_url_path = date("Y")."/".date("m");
				$upload_path = MAPTOON_DIR_BACK.$mid_url_path;
				if (!is_dir($upload_path)) {
					umask(0);
					mkdir($upload_path, 0777, TRUE);
				} 
				$config['max_size'] = 20*1024;
				$config['upload_path'] = $upload_path;
				$config['allowed_types'] = 'gif|jpg|png|jpeg';
				$config['encrypt_name'] = TRUE;
	
				$this->load->library('upload');
				$this->upload->initialize($config);
				
				$file_name= date("H").date("i").date("s");
				
				if ( ! $this->upload->do_upload('webtoon_images')) {
					$error = array('error' => $this->upload->display_errors());
					gf_alert("이미지 업로드에 실패했습니다.", 'back');
				}
				$arr_upload_data = $this->upload->data();
				$webtoon_images = (isset($arr_upload_data['file_name'])==TRUE) ? MAPTOON_DIR_FRONT.$mid_url_path.'/'.$arr_upload_data['file_name'] : '';
			} else {
				$webtoon_images = '';
			}
		}

		$data=[ 
			'mt_categories_idx'  => $mt_categories_idx,
			'mt_list_idx'        => $mt_list_idx,
			'title'              => $title,
			'main_img'           => $main_img,
			'display_date'       => $display_date,
			'is_display'         => $is_display,
			'display_date'       => $display_date,
			'webtoon_images'     => json_encode($webtoon_images),
			'reg_date'           => date("Y-m-d H:i:s")
		];
		$ret = $this->db->insert($this->tb_name_episode,$data);
		if($ret==TRUE) {
			$this->util->js_alert_go('등록되었습니다','/admin/maptoon/episode/10');exit;
		} else {
			$this->util->js_alert('DB error');
		}

	}

	/*
	@desc : update maptoon episode
	 */
	public function fn_episode_upd_proc() {

	}

	/*
	@desc : delete maptoon episode
	 */
	public function fn_episode_del_proc() {
		$idx = $this->input->post('idx');
		if(is_numeric($idx)==TRUE && $idx>=0) {
			$this->load->database();
            $this->db->where_in('idx',$where_in);
			$ret = $this->db->delete($this->tb_name_episode);
			if($ret==TRUE) {
                $message = '삭제되었습니다.';
            } else {
                $message = '삭제되지 않았습니다.(디비 에러) 서버 관리자에게 문의해 주십시오.';
            }
		}else{
			$message = '인덱스 값이 잘못 입력되었습니다';
			exit;
		}
		echo "<script>alert('".$message."'); parent.location.reload();</script>";
	}

	/*
	@desc : show list of maptoon announcement
	@param: numeric; idx of announcement table
	 */
	public function fn_announcement() {
		$this->load->model('admin/maptoon/m_maptoon');
		$return_data['list']=$this->m_maptoon->get_announcement_list();
		$return_data['mt_title' ]=$this->m_maptoon->get_mt_title();
		return $this->load->view('/admin/maptoon/notice_list',$return_data,true);
	}

	/*
	@desc : register announcement
	 */
	public function fn_announcement_reg_proc() {
		$mt_list_idx = $this->input->post('mt_title');
		$mode = $this->input->post('mode');
		$idx  = $this->input->post('idx');
		$contents  = $this->input->post('contents');
		$s_date  = $this->input->post('s_date');
		$e_date  = $this->input->post('e_date');

		if($mode=='modify') {
			if(is_numeric($idx)==TRUE && $idx>0) {
					$data = [
							'contents'     => $contents,
							's_date'       => $s_date,
							'e_date'       => $e_date
						];
					$this->db->where('idx',$idx);
					$ret = $this->db->update($this->tb_name_notice, $data);
					if($ret==TRUE) {
						$this->util->js_alert_parent_reload('수정되었습니다.');
					} else {
						$this->util->js_alert('DB error');
					}
			} else {
				$this->util->js_alert('키값이 입력되지 않았습니다.');
			}
		} else {
				$data=[ 'mt_list_idx'  => $mt_list_idx,
						'contents'     => $contents,
						's_date'       => $s_date,
						'e_date'       => $e_date,
						'reg_date'     => date("Y-m-d H:i:s")
				];
				$ret = $this->db->insert($this->tb_name_notice,$data);
				if($ret==TRUE) {
					$this->util->js_alert_parent_reload('등록되었습니다.');
				} else {
					$this->util->js_alert('DB error');
				}
				// $this->util->js_alert('존재하지 않는 웹툰 제목입니다.');
		}
		exit;
	}

	/*
	@desc : update maptoon announcement NOT USE 
	 
	public function fn_announcement_upd_proc() {
		$idx= $this->input->post('idx');
		$contents= $this->input->post('contentes');
		$idx= $this->input->post('s_date');
		$idx= $this->input->post('e_date');
		$mode= $this->input->post('mode');
		if($mode==""){
			exit;
		}else{
			$data = [
				'contentes' => $contents, 
				's_date' => $s_date,
				'e_date' => $e_date];
			$this->db->where('idx',$idx);
			$ret = $this->db->update($this->tb_name_notice, $data);
			if($ret==TRUE) {
				$this->util->js_alert_parent_reload('수정되었습니다.');
			} else {
				$this->util->js_alert('DB error');
			}
		}

	}
	*/
	/*
	@desc : delete maptoon announcement
	 */
	public function fn_announcement_del_proc() {
		$idx = $this->input->get_post('idx');
		if(is_numeric($idx)==TRUE && $idx>0) {
			$this->load->database();
            $this->db->where('idx',$idx);
			$ret = $this->db->delete($this->tb_name_notice);
			echo $ret;
			if($ret==TRUE) {
                $message = '삭제되었습니다.';
            } else {
                $message = '삭제되지 않았습니다.(디비 에러) 서버 관리자에게 문의해 주십시오.';
            }
		}else{
			$message = '인덱스 값이 잘못 입력되었습니다';
			exit;
		}
		echo "<script>alert('".$message."'); parent.location.reload();</script>";
	}
	/*
	@desc : list all cartoonists
	 */
	public function fn_cartoonist() {
		$idx = $this->input->get('idx');
		$this->load->database();
		if(is_numeric($idx)==TRUE && $idx>0) { 
			$query = $this->db->get_where($this->tb_name_cartoonist,['idx'=>$idx]);
			$row = $query->row_array();
			if($row!=FALSE) {
				$row['result'] = 'success';
			}
			echo json_encode($row);
			exit;
		} else {
			$query = $this->db->get($this->tb_name_cartoonist);
	        $i = 0;
	        $return_data = array();
	        foreach($query->result_array() as $row) {
	            $return_data['list'][$i] = $row;
	            $i++;
	        }
			return $this->load->view('/admin/maptoon/cartoonist', $return_data, true);
		}
	}

	/*
	@desc : register & modify cartoonist info
	 */
	public function fn_cartoonist_proc() {
		$name = $this->input->post('name');
		$website = $this->input->post('website');
		$mode = $this->input->post('mode');
		$idx  = $this->input->post('idx');
		$name = trim($name);
		$website = trim($website);

		if($name!='' && $website!='') {
			if($mode=='upt') {
				if(is_numeric($idx)==TRUE && $idx>0) {
					$data = ['name' => $name, 
							'website' => $website];
					$this->db->where('idx',$idx);
					$ret = $this->db->update($this->tb_name_cartoonist, $data);
					if($ret==TRUE) {
						$this->util->js_alert_parent_reload('수정되었습니다.');
					} else {
						$this->util->js_alert('DB error');
					}
				} else {
					$this->util->js_alert('키값이 입력되지 않았습니다.');
				}
			} else {
				$data = ['name' => $name, 
							'website' => $website];
				$ret = $this->db->insert($this->tb_name_cartoonist,$data);
				if($ret==TRUE) {
					$this->util->js_alert_parent_reload('등록되었습니다.');
				} else {
					$this->util->js_alert('DB error');
				}
			}
		} else {
			$this->util->js_alert('카테고리 이름을 입력해 주십시오');
		}
		exit;
	}

	/*
	@desc : delete cartoonist info
	 */
	public function fn_cartoonist_del_proc() {
		$idx  = $this->input->post('idx');

		if(is_numeric($idx)==TRUE && $idx>0) {
			$this->db->where('idx',$idx);
			$ret = $this->db->delete($this->tb_name_cartoonist);
			if($ret==TRUE) {
				$this->db->where('mt_cartoonists_idx',$idx);
				$data = ['mt_cartoonists_idx' => 0];
				$ret = $this->db->update($this->tb_name_maptoon_list,$data);
				//echo $this->db->last_query();
				$this->util->js_alert_parent_reload('삭제되었습니다.');
			}
		} else {
			$this->util->js_alert('키값이 전달되지 않았습니다.');
		}
		exit;
	}
}