/application/controllers/content.php
https://gitlab.com/wildanoo/E-procurement · PHP · 836 lines · 523 code · 200 blank · 113 comment · 55 complexity · 6dd02a62c0cc8345cbf5da3011c800af MD5 · raw file
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- if ( ! class_exists('Controller'))
- {
- class Controller extends CI_Controller {}
- }
- class Content extends Controller {
- function __construct()
- {
- parent::__construct();
- //$this->load->model('m_category', 'm_category');
- $this->load->model('crud', 'crud');
- $this->load->library('session');
- $this->limit = 5;
- }
-
- function index(){
- if ($this->tank_auth->is_logged_in()) {
-
- $data['user_id'] = $this->tank_auth->get_user_id();
- $data['username'] = $this->tank_auth->get_username();
-
- //$sess_like = $this->session->flashdata('like');\
-
- $sess_cat = $this->session->userdata('sess_cat');
- $sess_field = $this->session->userdata('sess_field');
-
-
- $field = $sess_field != '' ? $sess_field : "type_name";
- $id_cat = $sess_cat != '' ? $sess_cat : "";
-
- if($sess_cat != ''){ $where = array('type_name'=>$sess_cat,'status'=>'1');
- } else { $where = array('status'=>'1'); }
-
- $table = "content_type";
- $page = $this->uri->segment(3);
- $per_page = 10;
- $offset = $this->crud->set_offset($page,$per_page,$where);
- $total_rows = $this->crud->get_total_record("",$table,$where);
- $set_config = array('base_url'=> base_url().'/content/index','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>3);
- $config = $this->crud->set_config($set_config);
-
- $this->load->library('pagination');
- $this->pagination->initialize($config);
- $paging = $this->pagination->create_links();
-
- $order = array('field'=>'created_date','order'=>'DESC');
- $data['pagination'] = $paging;
- $data['num'] = $offset;
- $select = "id,type_name,status,(SELECT username FROM users WHERE id=created_id)as created_id,created_date,last_updated";
-
- // if($sess_like){
- // $like = array('col'=>'type_name','field'=>$sess_like);
- // $browse = $this->crud->browse("",$table." l","","","true",$select,"","","",$like); } else {
- // $browse = $this->crud->browse_with_paging("",$table." l","","","true",$select,"",$order,$config['per_page'],$offset); }
-
- // $data['browse'] = $browse;
- $sessID = $this->session->flashdata('anID');
- $browse = $this->crud->browse_with_paging("",$table." l",$field,$id_cat,"true",$select,"",$order,$config['per_page'],$offset);
-
- if($sessID) $browse = $this->crud->browse("",$table,"id",$sessID,"true");
- else $browse = $this->crud->browse_with_paging("",$table." l",$field,$id_cat,"true",$select,"",$order,$config['per_page'],$offset);
- $data['browse'] = $browse;
-
- $content = $this->crud->browse("","content_type","","","true","id,type_name");
- if(!$content) $content = array();
- $select = array(''=>'All');
- $options = array();
- foreach($content as $val){ $options[$val->id] = $val->type_name; }
- $data['content'] = $select + $options;
-
- $data['view'] = "content/browse";
- $this->load->view('layout/template',$data);
-
-
- } else {
- $this->session->set_flashdata('message','user not authorized');
- redirect('/auth/login/');
- }
- }
-
- private function search_input($search_dateranges = array(),$search_conditions = array()){
-
- if ($this->session->userdata('search_dateranges') != $search_dateranges) {
- $this->session->set_userdata('search_dateranges',$search_dateranges);
- }else{
- $splits = $this->session->userdata('search_dateranges');
-
- foreach ($splits as $key => $value) {
- $search_dateranges[$key] = $splits[$key];
- }
- }
-
- if ($_POST['search_term'] != $this->session->userdata('search_conditions') && $_POST['search_term']!='') {
- $this->session->set_userdata('search_conditions',$search_conditions);
- }else{
- $splits = $this->session->userdata('search_conditions');
-
- foreach ($splits as $key => $value) {
- $search_conditions[$key] = $splits[$key];
- }
- }
-
- $getData = array($search_dateranges,$search_conditions);
-
- return $getData;
- }
-
-
- function search(){
-
- /* initiate search inputs */
-
- //$search_dateranges = array('publish_date',$_POST['start_date'],$_POST['end_date']);
- $search_conditions = array(
- 'type_name' => $_POST['search_term']
- );
-
- $where_conditions = $this->search_input("",$search_conditions);
-
- /* ==== */
-
- /* get data from defined function for table view */
-
- $extract = $this->getDataTablesSearch(10,$where_conditions[0],$where_conditions[1]);
-
- /* ==== */
-
- /* preparing data for display */
-
- $data['user_id'] = $this->tank_auth->get_user_id();
- $data['username'] = $this->tank_auth->get_username();
-
- $data['browse'] = $extract['getData'];
- $data['pagination'] = $extract['pagination'];
- $data['num'] = $extract['num'];
-
- $data['view'] = "content/browse";
-
- $this->load->view('layout/template',$data);
-
- /* ==== */
-
- }
-
- private function getDataTables($limit = NULL)
- {
-
- /* get data for table view from database with pagination */
-
- $table = "content_type t1";
- $select = "t1.id,type_name,status,(SELECT username FROM users WHERE id=created_id)as created_id,created_date,last_updated";
- $uri_segment = 3;
- $page = $this->uri->segment($uri_segment);
- $per_page = $limit;
- $offset = $this->crud->set_offset($page,$per_page);
-
- $count_rows = $this->crud->browse('',$table,'','','false',"COUNT(t1.id) AS COUNT",$where);
-
- $getData = $this->crud->browse_join_with_paging("",$table,$field,$id_cat,"true",$select,$joins,$where,"",$per_page,$offset,"t1.id");
- // }
-
- $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
- $set_config = array('base_url'=> base_url().'content/index','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
- $config = $this->crud->set_config($set_config);
-
- /** setup for pagination **/
-
- $this->load->library('pagination');
- $this->pagination->initialize($config);
-
- $paging = $this->pagination->create_links();
-
- /** ===== **/
- /* ===== */
-
- /* setup variable to used in another functions */
-
- $data['getData'] = $getData;
- $data['pagination'] = $paging;
- $data['num'] = $offset;
-
- /* ===== */
-
- return $data;
-
- }
-
- private function getDataTablesSearch($limit = NULL,$dateranges = array(),$wherearray = array())
- {
-
- /* get data for table view from database with pagination */
-
- $table = "content_type t1";
- $select = "t1.id,type_name,status,(SELECT username FROM users WHERE id=created_id)as created_id,created_date,last_updated";
- $uri_segment = 3;
- $page = $this->uri->segment($uri_segment);
- $per_page = $limit;
- $offset = $this->crud->set_offset($page,$per_page);
-
- $count_rows = $this->crud->search_browse('',$table,"COUNT(t1.id) AS COUNT",$where,$dateranges,$wherearray);
-
- $getData = $this->crud->search_browse_join_with_paging("",$table,$select,$joins,'t1.status = "1"',$dateranges,$wherearray,"",$per_page,$offset,"t1.id");
-
- $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
- $set_config = array('base_url'=> base_url().'content/search/','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
- $config = $this->crud->set_config($set_config);
-
- /** setup for pagination **/
-
- $this->load->library('pagination');
- $this->pagination->initialize($config);
-
- $paging = $this->pagination->create_links();
-
- /** ===== **/
- /* ===== */
-
- /* setup variable to used in another functions */
-
- $data['getData'] = $getData;
- $data['pagination'] = $paging;
- $data['num'] = $offset;
-
- /* ===== */
-
- return $data;
-
- }
-
- function get_cat_tags(){
- $term = $_GET['term'];
- $order = array('field'=>'type_name','sort'=>'ASC'); $select = "type_name as name";
- $result = $this->crud->autocomplete("","content_type",$select,"type_name",$term,"",$order);
- echo json_encode($result);
- }
-
- function get_tags(){
- $term = $_GET['term'];
- $order = array('field'=>'type_name','sort'=>'ASC'); $select = "type_name as name";
- $result = $this->crud->autocomplete("","content_type",$select,"type_name",$term,"",$order);
- echo json_encode($result);
- }
-
- function set_sess_search(){
- $like = $_POST['search'];
- $this->session->set_flashdata('like',$like);
- }
-
- function set_sess_content(){
-
- $type = $_POST['type_name'];
- if($type!='') { $this->session->set_userdata('sess_cat',$type);
- } else { $this->session->unset_userdata('sess_cat'); }
-
- $type = $_POST['field'];
- if($type!='') { $this->session->set_userdata('sess_field',$type);
- } else { $this->session->unset_userdata('sess_field'); }
-
- }
-
- function is_exist(){
- $content = $_POST['type_name'];
- $is_exist['1']= !$content ? "false" : "true";
- $msg['1'] = !$content ? "
- content name required" : "";
-
- if ($is_exist['1']=='true'){
- $where = array('type_name'=>$content,'status'=>'1');
- $checked = $this->crud->is_exist("","content_type","id",$where);
- $is_exist['1'] = !$checked ? "true" : "false";
- $msg['1'] = $checked ? "duplicate content name" : "";
-
- }
- $status = in_array('false', $is_exist) ? "false" : "true";
- $result = array('status'=>$status,'msg' =>$msg['1']);
-
- echo json_encode($result);
- }
-
- function create(){
- //$init_code = $this->m_category->category_code("category");
- $curr_date = date('Y-m-d H:i:s'); $userID = $this->tank_auth->get_user_id();
- $data = array('id'=>null,
- 'type_name'=>$_POST['type_name'],
- 'created_id'=>$userID,
- 'created_date'=>$curr_date,
- 'last_updated'=>$curr_date);
- $where = array('type_name'=>$_POST['type_name'],'status'=>'0');
- $checked = $this->crud->is_exist("","content_type","id",$where);
-
- if ($checked){
- $id = $this->crud->browse("","content_type","type_name",$_POST['type_name'],"false","id")->id;
- $update = array('status'=>'1','last_updated'=>$curr_date);
- $this->crud->update("","content_type","id",$id,$update);
- } else { $id = $this->crud->insert("","content_type",$data); }
-
- $this->session->set_flashdata('message','1 data success insert');
- }
-
- function form_update(){
- $id = $this->uri->segment(3);
- $select = "id,(SELECT id FROM content_type r WHERE r.id=l.content_id) as content_id, subtype_name,created_date,last_updated";
- $def = $this->crud->browse("","subcontent_type l","id",$id,"false",$select);
- $data['def'] = $def ;
- $content = $this->crud->browse("","content_type","","","true","id,type_name");
- //print_r($content);
- $id = $this->uri->segment(3);
- $select = "id,type_name,created_id,last_updated";
- $data ['def'] = $this->crud->browse ( "", "content_type", "id", $id, "false", $select);
- $this->load->view ('content/form_update', $data );
- }
-
- function form_update1(){
- $id = $this->uri->segment(3);
- $select = "id,init_code,(SELECT id FROM category r WHERE r.id=l.id_cat) as id_cat, subcategory,created_date,last_updated";
- $def = $this->crud->browse("","subcategory l","id",$id,"false",$select);
- $data['def'] = $def ;
- $category = $this->crud->browse("","category","","","true","id,category");
-
- $id = $this->uri->segment(3);
- $select = "id,init_code,category,created_id,last_updated";
- $data ['def'] = $this->crud->browse ( "", "category", "id", $id, "false", $select);
- $this->load->view ( 'supplier/category/form_update', $data );
- }
-
- function form_create(){
- $data ['user_id'] = $this->tank_auth->get_user_id ();
- $data ['username'] = $this->tank_auth->get_username ();
- $this->load->view('content/form_create', $data);
- }
-
- function update(){
- $curr_date = date('Y-m-d H:i:s'); $userID = $this->tank_auth->get_user_id();
- $data = array('type_name'=>$_POST['type_name'],'last_updated'=>$curr_date,'status'=>'1','created_id'=>$userID);
- $this->crud->update("","content_type","id",$_POST['id'],$data);
- $this->session->set_flashdata('message','1 data success update');
- }
-
- function delete_(){
-
- $id = $this->uri->segment(3);
- $where = array('content_id'=>$id);
- $checked = $this->crud->is_exist("","subcontent_type","id",$where);
- if ($checked) {
- $this->session->set_flashdata('msg_warning','This data is already in use');
- }
- else {
- $this->crud->delete("","content_type","id",$id);
- }
- $this->session->set_flashdata('message','1 data success deleted');
- redirect('content/','refresh');
-
- }
-
- function delete(){
- $id = $this->uri->segment(3);
- $status = array('status'=>'0');
- $this->crud->update('','content_type','id',$id,$status);
- $this->session->set_flashdata('message','1 data success deleted');
- redirect('content/','refresh');
- }
-
- function subcontent(){
- if ($this->tank_auth->is_logged_in()) {
-
- $data['user_id'] = $this->tank_auth->get_user_id();
- $data['username'] = $this->tank_auth->get_username();
-
- $sess_cat = $this->session->userdata('sess_cat');
- $sess_field = $this->session->userdata('sess_field');
-
-
- $field = $sess_field != '' ? $sess_field : "subtype_name";
- $id_cat = $sess_cat != '' ? $sess_cat : "";
-
- if($sess_cat != ''){ $where = array('subtype_name'=>$sess_cat,'is_active'=>'1');
- } else { $where = array('is_active'=>'1'); }
-
- $table = "subcontent_type";
- $page = $this->uri->segment(3);
- $per_page = 10;
- $offset = $this->crud->set_offset($page,$per_page,$where);
- $total_rows = $this->crud->get_total_record("",$table,$where);
- $set_config = array('base_url'=> base_url().'/content/subcontent','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>3);
- $config = $this->crud->set_config($set_config);
-
- $this->load->library('pagination');
- $this->pagination->initialize($config);
- $paging = $this->pagination->create_links();
-
- $order = array('field'=>'id','order'=>'ASC');
- $data['pagination'] = $paging;
- $data['num'] = $offset;
- $select = "id,(SELECT type_name FROM content_type r WHERE r.id=l.content_id)as content_id,
- subtype_name,(SELECT username FROM users WHERE id=created_id)as created_id,
- document_req_id,created_date,last_updated,is_active";
-
- // if($sess_like){
- // $like = array('col'=>'subtype_name','field'=>$sess_like);
- // $browse = $this->crud->browse("",$table." l","","","true",$select,"","","",$like); } else {
- // $browse = $this->crud->browse_with_paging("",$table." l","","","true",$select,"",$order,$config['per_page'],$offset); }
-
- // $data['browse'] = $browse;
- $sessID = $this->session->flashdata('anID');
- $browse = $this->crud->browse_with_paging("",$table." l",$field,$id_cat,"true",$select,$where,$order,$config['per_page'],$offset);
-
- if($sessID) $browse = $this->crud->browse("",$table,"id",$sessID,"true");
- else $browse = $this->crud->browse_with_paging("",$table." l",'is_active','1',"true",$select,$where,$order,$config['per_page'],$offset);
- $data['browse'] = $browse;
- //print_r($data['browse']);
- $subcontent = $this->crud->browse("","subcontent_type","","","true","id,subtype_name");
- if(!$subcontent) $subcontent = array();
- $select = array(''=>'All');
- $options = array();
- foreach($subcontent as $val){ $options[$val->id] = $val->subtype_name; }
- $data['subcontent'] = $select + $options;
-
- $data['view'] = "subcontent/browse";
- $this->load->view('layout/template',$data);
-
-
- } else {
- $this->session->set_flashdata('message','user not authorized');
- redirect('/auth/login/');
- }
- }
-
- function search2(){
-
- /* initiate search inputs */
-
- //$search_dateranges = array('publish_date',$_POST['start_date'],$_POST['end_date']);
- $search_conditions = array(
- 'type_name' => $_POST['search_term'],
- 'subtype_name' => $_POST['search_term']
- );
-
- $where_conditions = $this->search_input("",$search_conditions);
-
- /* ==== */
-
- /* get data from defined function for table view */
-
- $extract = $this->getDataTablesSearch2(10,$where_conditions[0],$where_conditions[1]);
-
- /* ==== */
-
- /* preparing data for display */
-
- $data['user_id'] = $this->tank_auth->get_user_id();
- $data['username'] = $this->tank_auth->get_username();
-
- $data['browse'] = $extract['getData'];
- $data['pagination'] = $extract['pagination'];
- $data['num'] = $extract['num'];
-
- // $data['category'] = $this->getCategories();
- // $data['subcategory'] = $this->getSubcategories();
- // $data['subcontent_type'] = $this->getSubcontentTypes();
- // $data['status_ref'] = $this->getStatusCondition();
-
-
- $data['view'] = "subcontent/browse";
-
- $this->load->view('layout/template',$data);
-
- /* ==== */
-
- }
-
- private function getDataTables2($limit = NULL)
- {
- /* get data for table view from database with pagination */
-
- $table = "subcontent_type t1";
- $select = "t1.id,content_id,subtype_name,is_active,(SELECT type_name FROM content_type r WHERE r.id=t1.content_id) as content_id,document_req_id,(SELECT username FROM users WHERE id=t1.created_id)as created_id,created_date,last_updated";
- $uri_segment = 3;
- $page = $this->uri->segment($uri_segment);
- $per_page = $limit;
- $offset = $this->crud->set_offset($page,$per_page);
-
- $count_rows = $this->crud->browse('',$table,'','','false',"COUNT(t1.id) AS COUNT",$where);
-
- // if($sessID) $getData = $this->crud->browse("",$table,"id",$sessID,"true",$select,$where);
- // else {
- $joins[0][0] = 'content_type t2';
- $joins[0][1] = 't2.id = t1.content_id';
- $joins[0][2] = 'left';
-
- //SELECT t1.id_country, t2.country_name FROM region t1 left join country t2 on t1.id_country = t2.id
-
- // $where = !$this->session->userdata('is_admin') ? "t1.subcontent_type IN ('4','5') AND t1.status = '3'":"";
-
- $getData = $this->crud->browse_join_with_paging("",$table,$field,$id_cat,"true",$select,$joins,$where,"",$per_page,$offset,"t1.id");
- // }
-
- $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
- $set_config = array('base_url'=> base_url().'/content/subcontent','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
- $config = $this->crud->set_config($set_config);
-
- /** setup for pagination **/
-
- $this->load->library('pagination');
- $this->pagination->initialize($config);
-
- $paging = $this->pagination->create_links();
-
- /** ===== **/
- /* ===== */
-
- /* setup variable to used in another functions */
-
- $data['getData'] = $getData;
- $data['pagination'] = $paging;
- $data['num'] = $offset;
-
- /* ===== */
-
- return $data;
-
- }
-
- private function getDataTablesSearch2($limit = NULL,$dateranges = array(),$wherearray = array())
- {
- $joins[0][0] = 'content_type t2';
- $joins[0][1] = 't2.id = t1.content_id';
- $joins[0][2] = 'left';
- /* get data for table view from database with pagination */
-
- $table = "subcontent_type t1";
- $select = "t1.id,is_active,content_id,subtype_name,(SELECT type_name FROM content_type r WHERE r.id=t1.content_id) as content_id,document_req_id,(SELECT username FROM users WHERE id=t1.created_id)as created_id,t1.created_date,t1.last_updated";
- //$select = "t1.id,(SELECT country_name FROM country WHERE id=id_country) as t1.country_name,region_name,t1.remark,(SELECT username FROM users WHERE id=created_id)as t1.created_id,t1.created_date,t1.last_updated";
- //$order = array('field'=>'t1.publish_date','order'=>'DESC');
- $uri_segment = 3;
- $page = $this->uri->segment($uri_segment);
- $per_page = $limit;
- $offset = $this->crud->set_offset($page,$per_page);
-
- $count_rows = $this->crud->search_browse_join('',$table,"COUNT(t1.id) AS COUNT",$joins,$where,$dateranges,$wherearray);
-
- // $joins[0][0] = 'announcement_level_approval t2';
- // $joins[0][1] = 't2.id_announcement = t1.id';
- // $joins[0][2] = 'left';
- // $joins[1][0] = 'level t3';
- // $joins[1][1] = 't2.id_level = t3.id';
- // $joins[1][2] = 'left';
-
-
- $getData = $this->crud->search_browse_join_with_paging("",$table,$select,$joins,'t1.is_active = "1"',$dateranges,$wherearray,"",$per_page,$offset,"t1.id");
-
- $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
- $set_config = array('base_url'=> base_url().'content/search2/','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
- $config = $this->crud->set_config($set_config);
-
- /** setup for pagination **/
-
- $this->load->library('pagination');
- $this->pagination->initialize($config);
-
- $paging = $this->pagination->create_links();
-
- /** ===== **/
- /* ===== */
-
- /* setup variable to used in another functions */
-
- $data['getData'] = $getData;
- $data['pagination'] = $paging;
- $data['num'] = $offset;
-
- /* ===== */
- return $data;
-
- }
-
- function set_sess_subcategory(){
-
- $type = $_POST['subcategory'];
- if($type!='') { $this->session->set_userdata('sess_cat',$type);
- } else { $this->session->unset_userdata('sess_cat'); }
-
- $type = $_POST['field'];
- if($type!='') { $this->session->set_userdata('sess_field',$type);
- } else { $this->session->unset_userdata('sess_field'); }
-
- }
-
- function get_subcontent_tags(){
- $term = $_GET['term'];
- $order = array('field'=>'subtype_name','sort'=>'ASC'); $select = "subtype_name as name";
- $result = $this->crud->autocomplete("","subcontent_type",$select,"subtype_name",$term,"",$order);
- echo json_encode($result);
- }
-
- function set_sess_search_subcontent(){
- $like = $_POST['search'];
- $this->session->set_flashdata('like',$like);
- }
-
- function set_sess_subcontent(){
-
- $type = $_POST['subtype_name'];
- if($type!='') { $this->session->set_userdata('sess_cat',$type);
- } else { $this->session->unset_userdata('sess_cat'); }
-
- $type = $_POST['field'];
- if($type!='') { $this->session->set_userdata('sess_field',$type);
- } else { $this->session->unset_userdata('sess_field'); }
-
- }
-
- function is_exist_subcontent1(){
- $content = $_POST['content_id'];
- $subcontent = $_POST['subtype_name'];
- $is_exist['1']= !$content ? "false" : "true";
- $is_exist['2']= !$subcontent ? "false" : "true";
- $msg['1'] = !$content ? "content name required" : "";
- $msg['2'] = !$subcontent ? "subcontent name required" : "";
-
- if ($is_exist['1']=='true' && $is_exist['2']=='true'){
- $where = array('content_id'=>$content, 'subtype_name'=>$subcontent);
- $checked = $this->crud->is_exist("","subcontent_type","id",$where);
- $is_exist['1'] = !$checked ? "true" : "false";
- $is_exist['2'] = !$checked ? "true" : "false";
- $msg['1'] = $checked ? "duplicate content name" : "";
- $msg['2'] = $checked ? "duplicate subcontent name" : "";
-
- }
- $status = in_array('false', $is_exist) ? "false" : "true";
- $result = array('status'=>$status,'msg1' =>$msg['1'], 'msg2' =>$msg['2']);
-
- echo json_encode($result);
- }
-
- function is_exist_subcontent2(){
- $content = $_POST['content_id'];
- $subcontent = $_POST['subtype_name'];
- $is_exist['1']= !$content ? "false" : "true";
- $is_exist['2']= !$subcontent ? "false" : "true";
- $msg['1'] = !$content ? "content name required" : "";
- $msg['2'] = !$subcontent ? "subcontent name required" : "";
-
- if ($is_exist['1']=='true' && $is_exist['2']=='true'){
- $where = array('content_id'=>$content, 'subtype_name'=>$subcontent);
- $checked = $this->crud->is_exist("","subcontent_type","id",$where);
- $is_exist['1'] = !$checked ? "true" : "false";
- $is_exist['2'] = !$checked ? "true" : "false";
- $msg['1'] = $checked ? "duplicate content name" : "";
- $msg['2'] = $checked ? "duplicate subcontent name" : "";
-
- }
- $status = in_array('false', $is_exist) ? "false" : "true";
- $result = array('status'=>$status,'msg1' =>$msg['1'], 'msg2' =>$msg['2']);
-
- echo json_encode($result);
- }
-
- function form_create_subcontent(){
- $content = $this->crud->browse("","content_type","","","true","id,type_name");
- if(!$content) $content = array();
- $select = array(''=>'-- Select --');
- $options = array();
- foreach($content as $val){ $options[$val->id] = $val->type_name; }
- $data['content'] = $select + $options;
-
- $behavior = $this->crud->browse("","behavior","","","true","id,behavior");
- if(!$behavior) $behavior = array();
- $select2 = array(''=>'-- Select --');
- foreach($behavior as $val){ $options2[$val->id] = $val->behavior; }
- $data['behavior'] = $select2 + $options2;
-
- $data['doc'] = $this->crud->browse("","document_req","","","true","id,document_req");
- $this->load->view('subcontent/form_create',$data);
- }
-
- function create_subcontent(){
- /*$ttl = $_POST['ttl'];
- $subtype = $_POST['subtype_name'];
- $document_req = "";*/
- $where = array('subtype_name'=>$subtype);
- $is_exist = $this->crud->is_exist("","subcontent_type","id",$where);
-
- /*for ($i = 1; $i <= $ttl; $i++) {
- $value = $this->input->post('check'.$i);
- if($value) $doc[] = $value;
- }
- if($doc){ $document_req = implode(",",$doc); }*/
- $order = array('field'=>'id','sort'=>'DESC');
- $select = $this->crud->browse('','subcontent_type','','','true','','',$order,'','');
- $n = 0;
- $i = 0;
- foreach($select as $val){
- if ($i == 0){
- $n = $val->id + 1;
- break;
- }
- }
- //$n = ($n-2)+1;
- $data = array( 'id' => $n,
- 'content_id' => $_POST['content_id'],
- 'subtype_name' => $_POST['subtype_name'],
- 'behavior_id' => $_POST['behavior_id'],
- //'document_req_id' => $document_req,
- 'is_active' => '1',
- 'created_id' => $this->tank_auth->get_user_id(),
- 'created_date' => date('Y-m-d H:i:s'),
- 'last_updated' => date('Y-m-d H:i:s'));
-
- //print_r($ttl);exit;
- if(!$is_exist){
- $tes = $this->crud->insert("","subcontent_type",$data);
- $data2 = array('id' => null,
- 'type' => $n,
- //'title' => $_POST['title'],
- //'creator' => $_POST['creator'],
- //'activated' => '1',
- 'file' => strtolower(str_replace(' ', '_', $_POST['subtype_name'])),
- //'file_attach' => $ctpath,
- 'created_id' => $this->tank_auth->get_user_id(),
- 'created_date' => date('Y-m-d H:i:s'),
- 'last_updated' => date('Y-m-d H:i:s'));
- $this->crud->insert('','policy_agreement',$data2);
- }
- $msg1 = "succesfully add new document";
- $msg2 = "duplicate group document";
- $msg = !$is_exist ? $msg1 : $msg2;
- //print_r($_POST);exit;
-
- $this->session->set_flashdata('message','1 data success insert');
- }
-
- function form_update_subcontent(){
- $id = $this->uri->segment(3);
- $select = "id,(SELECT id FROM content_type WHERE id=content_id) as content_id,subtype_name,document_req_id,created_id,created_date,last_updated";
- $def = $this->crud->browse("","subcontent_type l","id",$id,"false",$select);
- $data['def'] = $def ;
- $content = $this->crud->browse("","content_type","","","true","id,type_name");
- if(!$content) $content = array();
- $select = array(''=>'-- Select --');
- foreach($content as $val){ $options[$val->id] = $val->type_name; }
- $data['content'] = $select + $options;
-
- $order = array('field'=>'document_req','sort'=>'ASC');
-
- $data['doc'] = $this->crud->browse("","document_req","","","true","id,document_req","",$order);
-
- $this->load->view('subcontent/form_update',$data);
- }
-
- function update_subcontent_(){
- /*$ttl = $_POST['ttl'];
- $id = $_POST['id'];
- $doc = "";
- $document = "";
- for ($i = 1; $i <= $ttl; $i++) {
- $value = $this->input->post('check'.$i);
- if($value) $doc[] = $value; }
-
- if($doc) $document = implode(",",$doc);*/
- $id = $_POST['id'];
- $update = array('document_req_id' => !$document ? "" : $document,
- 'id' =>$id,
- 'content_id' =>$_POST['content_id'],
- 'subtype_name' =>$_POST['subtype_name'],
- 'is_active' => '1',
- 'last_updated' => date('Y-m-d H:i:s'));
- $this->crud->update("","subcontent_type","id",$id,$update);
- //print_r($update);
-
- $this->session->set_flashdata('message','1 data success update');
- redirect('content/','refresh');
- }
-
- function update_subcontent(){
- /*$ttl = $_POST['ttl'];
- $id = $_POST['id'];
- $curr_date = date('Y-m-d H:i:s');
- $this->crud->delete("","subcontent_type","id",$id);
- $userID = $this->tank_auth->get_user_id();
- $doc = "";
- $document_req = "";
- for ($i = 1; $i <= $ttl; $i++) {
- $value = $this->input->post('check'.$i);
- if($value) $doc[] = $value; }
-
- if($doc) $document_req = implode(",",$doc);
- //$userID = $this->tank_auth->get_user_id();*/
- $id = $_POST['id'];
- $data = array(//'document_req_id' => !$document ? "" : $document,
- 'id' => $id,
- 'content_id' => $_POST['content_id'],
- 'subtype_name' => $_POST['subtype_name'],
- 'behavior_id' => $_POST['behavior_id'],
- //'document_req_id' => $document_req,
- 'is_active' => '1',
- 'created_id' => $this->tank_auth->get_user_id(),
- 'created_date' => date('Y-m-d H:i:s'),
- 'last_updated' => date('Y-m-d H:i:s'));
- //$this->crud->update("","subcontent_type","id",$id,$update);
- $this->crud->update("","subcontent_type",'id',$id,$data);
- //print_r($update);
-
- $this->session->set_flashdata('message','1 data success update');
- redirect('content/','refresh');
- }
-
- function delete_subcontent(){
-
- $id = $this->uri->segment(3);
- $status = array('is_active'=>'0');
- $this->crud->update("","subcontent_type","id",$id,$status);
- $this->session->set_flashdata('message','1 data success deleted');
- redirect('content/subcontent/','refresh');
-
- }
-
- function delete_subcontent_(){
- $id = $this->uri->segment(3);
- $where = array('id_subcontent'=>$id);
- $checked = $this->crud->is_exist("","level","id",$where);
- if($checked){
- $this->session->set_flashdata('msg_warning','This data is already in use');
- } else {
- $this->crud->delete("","subcontent_type","id",$id);
- $msg = "succesfully delete subcontent";
- $this->session->set_flashdata('message',$msg);
- }
- redirect('content/subcontent','refresh');
- }
- }