PageRenderTime 70ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. if ( ! class_exists('Controller'))
  3. {
  4. class Controller extends CI_Controller {}
  5. }
  6. class Content extends Controller {
  7. function __construct()
  8. {
  9. parent::__construct();
  10. //$this->load->model('m_category', 'm_category');
  11. $this->load->model('crud', 'crud');
  12. $this->load->library('session');
  13. $this->limit = 5;
  14. }
  15. function index(){
  16. if ($this->tank_auth->is_logged_in()) {
  17. $data['user_id'] = $this->tank_auth->get_user_id();
  18. $data['username'] = $this->tank_auth->get_username();
  19. //$sess_like = $this->session->flashdata('like');\
  20. $sess_cat = $this->session->userdata('sess_cat');
  21. $sess_field = $this->session->userdata('sess_field');
  22. $field = $sess_field != '' ? $sess_field : "type_name";
  23. $id_cat = $sess_cat != '' ? $sess_cat : "";
  24. if($sess_cat != ''){ $where = array('type_name'=>$sess_cat,'status'=>'1');
  25. } else { $where = array('status'=>'1'); }
  26. $table = "content_type";
  27. $page = $this->uri->segment(3);
  28. $per_page = 10;
  29. $offset = $this->crud->set_offset($page,$per_page,$where);
  30. $total_rows = $this->crud->get_total_record("",$table,$where);
  31. $set_config = array('base_url'=> base_url().'/content/index','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>3);
  32. $config = $this->crud->set_config($set_config);
  33. $this->load->library('pagination');
  34. $this->pagination->initialize($config);
  35. $paging = $this->pagination->create_links();
  36. $order = array('field'=>'created_date','order'=>'DESC');
  37. $data['pagination'] = $paging;
  38. $data['num'] = $offset;
  39. $select = "id,type_name,status,(SELECT username FROM users WHERE id=created_id)as created_id,created_date,last_updated";
  40. // if($sess_like){
  41. // $like = array('col'=>'type_name','field'=>$sess_like);
  42. // $browse = $this->crud->browse("",$table." l","","","true",$select,"","","",$like); } else {
  43. // $browse = $this->crud->browse_with_paging("",$table." l","","","true",$select,"",$order,$config['per_page'],$offset); }
  44. // $data['browse'] = $browse;
  45. $sessID = $this->session->flashdata('anID');
  46. $browse = $this->crud->browse_with_paging("",$table." l",$field,$id_cat,"true",$select,"",$order,$config['per_page'],$offset);
  47. if($sessID) $browse = $this->crud->browse("",$table,"id",$sessID,"true");
  48. else $browse = $this->crud->browse_with_paging("",$table." l",$field,$id_cat,"true",$select,"",$order,$config['per_page'],$offset);
  49. $data['browse'] = $browse;
  50. $content = $this->crud->browse("","content_type","","","true","id,type_name");
  51. if(!$content) $content = array();
  52. $select = array(''=>'All');
  53. $options = array();
  54. foreach($content as $val){ $options[$val->id] = $val->type_name; }
  55. $data['content'] = $select + $options;
  56. $data['view'] = "content/browse";
  57. $this->load->view('layout/template',$data);
  58. } else {
  59. $this->session->set_flashdata('message','user not authorized');
  60. redirect('/auth/login/');
  61. }
  62. }
  63. private function search_input($search_dateranges = array(),$search_conditions = array()){
  64. if ($this->session->userdata('search_dateranges') != $search_dateranges) {
  65. $this->session->set_userdata('search_dateranges',$search_dateranges);
  66. }else{
  67. $splits = $this->session->userdata('search_dateranges');
  68. foreach ($splits as $key => $value) {
  69. $search_dateranges[$key] = $splits[$key];
  70. }
  71. }
  72. if ($_POST['search_term'] != $this->session->userdata('search_conditions') && $_POST['search_term']!='') {
  73. $this->session->set_userdata('search_conditions',$search_conditions);
  74. }else{
  75. $splits = $this->session->userdata('search_conditions');
  76. foreach ($splits as $key => $value) {
  77. $search_conditions[$key] = $splits[$key];
  78. }
  79. }
  80. $getData = array($search_dateranges,$search_conditions);
  81. return $getData;
  82. }
  83. function search(){
  84. /* initiate search inputs */
  85. //$search_dateranges = array('publish_date',$_POST['start_date'],$_POST['end_date']);
  86. $search_conditions = array(
  87. 'type_name' => $_POST['search_term']
  88. );
  89. $where_conditions = $this->search_input("",$search_conditions);
  90. /* ==== */
  91. /* get data from defined function for table view */
  92. $extract = $this->getDataTablesSearch(10,$where_conditions[0],$where_conditions[1]);
  93. /* ==== */
  94. /* preparing data for display */
  95. $data['user_id'] = $this->tank_auth->get_user_id();
  96. $data['username'] = $this->tank_auth->get_username();
  97. $data['browse'] = $extract['getData'];
  98. $data['pagination'] = $extract['pagination'];
  99. $data['num'] = $extract['num'];
  100. $data['view'] = "content/browse";
  101. $this->load->view('layout/template',$data);
  102. /* ==== */
  103. }
  104. private function getDataTables($limit = NULL)
  105. {
  106. /* get data for table view from database with pagination */
  107. $table = "content_type t1";
  108. $select = "t1.id,type_name,status,(SELECT username FROM users WHERE id=created_id)as created_id,created_date,last_updated";
  109. $uri_segment = 3;
  110. $page = $this->uri->segment($uri_segment);
  111. $per_page = $limit;
  112. $offset = $this->crud->set_offset($page,$per_page);
  113. $count_rows = $this->crud->browse('',$table,'','','false',"COUNT(t1.id) AS COUNT",$where);
  114. $getData = $this->crud->browse_join_with_paging("",$table,$field,$id_cat,"true",$select,$joins,$where,"",$per_page,$offset,"t1.id");
  115. // }
  116. $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
  117. $set_config = array('base_url'=> base_url().'content/index','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
  118. $config = $this->crud->set_config($set_config);
  119. /** setup for pagination **/
  120. $this->load->library('pagination');
  121. $this->pagination->initialize($config);
  122. $paging = $this->pagination->create_links();
  123. /** ===== **/
  124. /* ===== */
  125. /* setup variable to used in another functions */
  126. $data['getData'] = $getData;
  127. $data['pagination'] = $paging;
  128. $data['num'] = $offset;
  129. /* ===== */
  130. return $data;
  131. }
  132. private function getDataTablesSearch($limit = NULL,$dateranges = array(),$wherearray = array())
  133. {
  134. /* get data for table view from database with pagination */
  135. $table = "content_type t1";
  136. $select = "t1.id,type_name,status,(SELECT username FROM users WHERE id=created_id)as created_id,created_date,last_updated";
  137. $uri_segment = 3;
  138. $page = $this->uri->segment($uri_segment);
  139. $per_page = $limit;
  140. $offset = $this->crud->set_offset($page,$per_page);
  141. $count_rows = $this->crud->search_browse('',$table,"COUNT(t1.id) AS COUNT",$where,$dateranges,$wherearray);
  142. $getData = $this->crud->search_browse_join_with_paging("",$table,$select,$joins,'t1.status = "1"',$dateranges,$wherearray,"",$per_page,$offset,"t1.id");
  143. $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
  144. $set_config = array('base_url'=> base_url().'content/search/','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
  145. $config = $this->crud->set_config($set_config);
  146. /** setup for pagination **/
  147. $this->load->library('pagination');
  148. $this->pagination->initialize($config);
  149. $paging = $this->pagination->create_links();
  150. /** ===== **/
  151. /* ===== */
  152. /* setup variable to used in another functions */
  153. $data['getData'] = $getData;
  154. $data['pagination'] = $paging;
  155. $data['num'] = $offset;
  156. /* ===== */
  157. return $data;
  158. }
  159. function get_cat_tags(){
  160. $term = $_GET['term'];
  161. $order = array('field'=>'type_name','sort'=>'ASC'); $select = "type_name as name";
  162. $result = $this->crud->autocomplete("","content_type",$select,"type_name",$term,"",$order);
  163. echo json_encode($result);
  164. }
  165. function get_tags(){
  166. $term = $_GET['term'];
  167. $order = array('field'=>'type_name','sort'=>'ASC'); $select = "type_name as name";
  168. $result = $this->crud->autocomplete("","content_type",$select,"type_name",$term,"",$order);
  169. echo json_encode($result);
  170. }
  171. function set_sess_search(){
  172. $like = $_POST['search'];
  173. $this->session->set_flashdata('like',$like);
  174. }
  175. function set_sess_content(){
  176. $type = $_POST['type_name'];
  177. if($type!='') { $this->session->set_userdata('sess_cat',$type);
  178. } else { $this->session->unset_userdata('sess_cat'); }
  179. $type = $_POST['field'];
  180. if($type!='') { $this->session->set_userdata('sess_field',$type);
  181. } else { $this->session->unset_userdata('sess_field'); }
  182. }
  183. function is_exist(){
  184. $content = $_POST['type_name'];
  185. $is_exist['1']= !$content ? "false" : "true";
  186. $msg['1'] = !$content ? "
  187. content name required" : "";
  188. if ($is_exist['1']=='true'){
  189. $where = array('type_name'=>$content,'status'=>'1');
  190. $checked = $this->crud->is_exist("","content_type","id",$where);
  191. $is_exist['1'] = !$checked ? "true" : "false";
  192. $msg['1'] = $checked ? "duplicate content name" : "";
  193. }
  194. $status = in_array('false', $is_exist) ? "false" : "true";
  195. $result = array('status'=>$status,'msg' =>$msg['1']);
  196. echo json_encode($result);
  197. }
  198. function create(){
  199. //$init_code = $this->m_category->category_code("category");
  200. $curr_date = date('Y-m-d H:i:s'); $userID = $this->tank_auth->get_user_id();
  201. $data = array('id'=>null,
  202. 'type_name'=>$_POST['type_name'],
  203. 'created_id'=>$userID,
  204. 'created_date'=>$curr_date,
  205. 'last_updated'=>$curr_date);
  206. $where = array('type_name'=>$_POST['type_name'],'status'=>'0');
  207. $checked = $this->crud->is_exist("","content_type","id",$where);
  208. if ($checked){
  209. $id = $this->crud->browse("","content_type","type_name",$_POST['type_name'],"false","id")->id;
  210. $update = array('status'=>'1','last_updated'=>$curr_date);
  211. $this->crud->update("","content_type","id",$id,$update);
  212. } else { $id = $this->crud->insert("","content_type",$data); }
  213. $this->session->set_flashdata('message','1 data success insert');
  214. }
  215. function form_update(){
  216. $id = $this->uri->segment(3);
  217. $select = "id,(SELECT id FROM content_type r WHERE r.id=l.content_id) as content_id, subtype_name,created_date,last_updated";
  218. $def = $this->crud->browse("","subcontent_type l","id",$id,"false",$select);
  219. $data['def'] = $def ;
  220. $content = $this->crud->browse("","content_type","","","true","id,type_name");
  221. //print_r($content);
  222. $id = $this->uri->segment(3);
  223. $select = "id,type_name,created_id,last_updated";
  224. $data ['def'] = $this->crud->browse ( "", "content_type", "id", $id, "false", $select);
  225. $this->load->view ('content/form_update', $data );
  226. }
  227. function form_update1(){
  228. $id = $this->uri->segment(3);
  229. $select = "id,init_code,(SELECT id FROM category r WHERE r.id=l.id_cat) as id_cat, subcategory,created_date,last_updated";
  230. $def = $this->crud->browse("","subcategory l","id",$id,"false",$select);
  231. $data['def'] = $def ;
  232. $category = $this->crud->browse("","category","","","true","id,category");
  233. $id = $this->uri->segment(3);
  234. $select = "id,init_code,category,created_id,last_updated";
  235. $data ['def'] = $this->crud->browse ( "", "category", "id", $id, "false", $select);
  236. $this->load->view ( 'supplier/category/form_update', $data );
  237. }
  238. function form_create(){
  239. $data ['user_id'] = $this->tank_auth->get_user_id ();
  240. $data ['username'] = $this->tank_auth->get_username ();
  241. $this->load->view('content/form_create', $data);
  242. }
  243. function update(){
  244. $curr_date = date('Y-m-d H:i:s'); $userID = $this->tank_auth->get_user_id();
  245. $data = array('type_name'=>$_POST['type_name'],'last_updated'=>$curr_date,'status'=>'1','created_id'=>$userID);
  246. $this->crud->update("","content_type","id",$_POST['id'],$data);
  247. $this->session->set_flashdata('message','1 data success update');
  248. }
  249. function delete_(){
  250. $id = $this->uri->segment(3);
  251. $where = array('content_id'=>$id);
  252. $checked = $this->crud->is_exist("","subcontent_type","id",$where);
  253. if ($checked) {
  254. $this->session->set_flashdata('msg_warning','This data is already in use');
  255. }
  256. else {
  257. $this->crud->delete("","content_type","id",$id);
  258. }
  259. $this->session->set_flashdata('message','1 data success deleted');
  260. redirect('content/','refresh');
  261. }
  262. function delete(){
  263. $id = $this->uri->segment(3);
  264. $status = array('status'=>'0');
  265. $this->crud->update('','content_type','id',$id,$status);
  266. $this->session->set_flashdata('message','1 data success deleted');
  267. redirect('content/','refresh');
  268. }
  269. function subcontent(){
  270. if ($this->tank_auth->is_logged_in()) {
  271. $data['user_id'] = $this->tank_auth->get_user_id();
  272. $data['username'] = $this->tank_auth->get_username();
  273. $sess_cat = $this->session->userdata('sess_cat');
  274. $sess_field = $this->session->userdata('sess_field');
  275. $field = $sess_field != '' ? $sess_field : "subtype_name";
  276. $id_cat = $sess_cat != '' ? $sess_cat : "";
  277. if($sess_cat != ''){ $where = array('subtype_name'=>$sess_cat,'is_active'=>'1');
  278. } else { $where = array('is_active'=>'1'); }
  279. $table = "subcontent_type";
  280. $page = $this->uri->segment(3);
  281. $per_page = 10;
  282. $offset = $this->crud->set_offset($page,$per_page,$where);
  283. $total_rows = $this->crud->get_total_record("",$table,$where);
  284. $set_config = array('base_url'=> base_url().'/content/subcontent','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>3);
  285. $config = $this->crud->set_config($set_config);
  286. $this->load->library('pagination');
  287. $this->pagination->initialize($config);
  288. $paging = $this->pagination->create_links();
  289. $order = array('field'=>'id','order'=>'ASC');
  290. $data['pagination'] = $paging;
  291. $data['num'] = $offset;
  292. $select = "id,(SELECT type_name FROM content_type r WHERE r.id=l.content_id)as content_id,
  293. subtype_name,(SELECT username FROM users WHERE id=created_id)as created_id,
  294. document_req_id,created_date,last_updated,is_active";
  295. // if($sess_like){
  296. // $like = array('col'=>'subtype_name','field'=>$sess_like);
  297. // $browse = $this->crud->browse("",$table." l","","","true",$select,"","","",$like); } else {
  298. // $browse = $this->crud->browse_with_paging("",$table." l","","","true",$select,"",$order,$config['per_page'],$offset); }
  299. // $data['browse'] = $browse;
  300. $sessID = $this->session->flashdata('anID');
  301. $browse = $this->crud->browse_with_paging("",$table." l",$field,$id_cat,"true",$select,$where,$order,$config['per_page'],$offset);
  302. if($sessID) $browse = $this->crud->browse("",$table,"id",$sessID,"true");
  303. else $browse = $this->crud->browse_with_paging("",$table." l",'is_active','1',"true",$select,$where,$order,$config['per_page'],$offset);
  304. $data['browse'] = $browse;
  305. //print_r($data['browse']);
  306. $subcontent = $this->crud->browse("","subcontent_type","","","true","id,subtype_name");
  307. if(!$subcontent) $subcontent = array();
  308. $select = array(''=>'All');
  309. $options = array();
  310. foreach($subcontent as $val){ $options[$val->id] = $val->subtype_name; }
  311. $data['subcontent'] = $select + $options;
  312. $data['view'] = "subcontent/browse";
  313. $this->load->view('layout/template',$data);
  314. } else {
  315. $this->session->set_flashdata('message','user not authorized');
  316. redirect('/auth/login/');
  317. }
  318. }
  319. function search2(){
  320. /* initiate search inputs */
  321. //$search_dateranges = array('publish_date',$_POST['start_date'],$_POST['end_date']);
  322. $search_conditions = array(
  323. 'type_name' => $_POST['search_term'],
  324. 'subtype_name' => $_POST['search_term']
  325. );
  326. $where_conditions = $this->search_input("",$search_conditions);
  327. /* ==== */
  328. /* get data from defined function for table view */
  329. $extract = $this->getDataTablesSearch2(10,$where_conditions[0],$where_conditions[1]);
  330. /* ==== */
  331. /* preparing data for display */
  332. $data['user_id'] = $this->tank_auth->get_user_id();
  333. $data['username'] = $this->tank_auth->get_username();
  334. $data['browse'] = $extract['getData'];
  335. $data['pagination'] = $extract['pagination'];
  336. $data['num'] = $extract['num'];
  337. // $data['category'] = $this->getCategories();
  338. // $data['subcategory'] = $this->getSubcategories();
  339. // $data['subcontent_type'] = $this->getSubcontentTypes();
  340. // $data['status_ref'] = $this->getStatusCondition();
  341. $data['view'] = "subcontent/browse";
  342. $this->load->view('layout/template',$data);
  343. /* ==== */
  344. }
  345. private function getDataTables2($limit = NULL)
  346. {
  347. /* get data for table view from database with pagination */
  348. $table = "subcontent_type t1";
  349. $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";
  350. $uri_segment = 3;
  351. $page = $this->uri->segment($uri_segment);
  352. $per_page = $limit;
  353. $offset = $this->crud->set_offset($page,$per_page);
  354. $count_rows = $this->crud->browse('',$table,'','','false',"COUNT(t1.id) AS COUNT",$where);
  355. // if($sessID) $getData = $this->crud->browse("",$table,"id",$sessID,"true",$select,$where);
  356. // else {
  357. $joins[0][0] = 'content_type t2';
  358. $joins[0][1] = 't2.id = t1.content_id';
  359. $joins[0][2] = 'left';
  360. //SELECT t1.id_country, t2.country_name FROM region t1 left join country t2 on t1.id_country = t2.id
  361. // $where = !$this->session->userdata('is_admin') ? "t1.subcontent_type IN ('4','5') AND t1.status = '3'":"";
  362. $getData = $this->crud->browse_join_with_paging("",$table,$field,$id_cat,"true",$select,$joins,$where,"",$per_page,$offset,"t1.id");
  363. // }
  364. $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
  365. $set_config = array('base_url'=> base_url().'/content/subcontent','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
  366. $config = $this->crud->set_config($set_config);
  367. /** setup for pagination **/
  368. $this->load->library('pagination');
  369. $this->pagination->initialize($config);
  370. $paging = $this->pagination->create_links();
  371. /** ===== **/
  372. /* ===== */
  373. /* setup variable to used in another functions */
  374. $data['getData'] = $getData;
  375. $data['pagination'] = $paging;
  376. $data['num'] = $offset;
  377. /* ===== */
  378. return $data;
  379. }
  380. private function getDataTablesSearch2($limit = NULL,$dateranges = array(),$wherearray = array())
  381. {
  382. $joins[0][0] = 'content_type t2';
  383. $joins[0][1] = 't2.id = t1.content_id';
  384. $joins[0][2] = 'left';
  385. /* get data for table view from database with pagination */
  386. $table = "subcontent_type t1";
  387. $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";
  388. //$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";
  389. //$order = array('field'=>'t1.publish_date','order'=>'DESC');
  390. $uri_segment = 3;
  391. $page = $this->uri->segment($uri_segment);
  392. $per_page = $limit;
  393. $offset = $this->crud->set_offset($page,$per_page);
  394. $count_rows = $this->crud->search_browse_join('',$table,"COUNT(t1.id) AS COUNT",$joins,$where,$dateranges,$wherearray);
  395. // $joins[0][0] = 'announcement_level_approval t2';
  396. // $joins[0][1] = 't2.id_announcement = t1.id';
  397. // $joins[0][2] = 'left';
  398. // $joins[1][0] = 'level t3';
  399. // $joins[1][1] = 't2.id_level = t3.id';
  400. // $joins[1][2] = 'left';
  401. $getData = $this->crud->search_browse_join_with_paging("",$table,$select,$joins,'t1.is_active = "1"',$dateranges,$wherearray,"",$per_page,$offset,"t1.id");
  402. $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
  403. $set_config = array('base_url'=> base_url().'content/search2/','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>$uri_segment);
  404. $config = $this->crud->set_config($set_config);
  405. /** setup for pagination **/
  406. $this->load->library('pagination');
  407. $this->pagination->initialize($config);
  408. $paging = $this->pagination->create_links();
  409. /** ===== **/
  410. /* ===== */
  411. /* setup variable to used in another functions */
  412. $data['getData'] = $getData;
  413. $data['pagination'] = $paging;
  414. $data['num'] = $offset;
  415. /* ===== */
  416. return $data;
  417. }
  418. function set_sess_subcategory(){
  419. $type = $_POST['subcategory'];
  420. if($type!='') { $this->session->set_userdata('sess_cat',$type);
  421. } else { $this->session->unset_userdata('sess_cat'); }
  422. $type = $_POST['field'];
  423. if($type!='') { $this->session->set_userdata('sess_field',$type);
  424. } else { $this->session->unset_userdata('sess_field'); }
  425. }
  426. function get_subcontent_tags(){
  427. $term = $_GET['term'];
  428. $order = array('field'=>'subtype_name','sort'=>'ASC'); $select = "subtype_name as name";
  429. $result = $this->crud->autocomplete("","subcontent_type",$select,"subtype_name",$term,"",$order);
  430. echo json_encode($result);
  431. }
  432. function set_sess_search_subcontent(){
  433. $like = $_POST['search'];
  434. $this->session->set_flashdata('like',$like);
  435. }
  436. function set_sess_subcontent(){
  437. $type = $_POST['subtype_name'];
  438. if($type!='') { $this->session->set_userdata('sess_cat',$type);
  439. } else { $this->session->unset_userdata('sess_cat'); }
  440. $type = $_POST['field'];
  441. if($type!='') { $this->session->set_userdata('sess_field',$type);
  442. } else { $this->session->unset_userdata('sess_field'); }
  443. }
  444. function is_exist_subcontent1(){
  445. $content = $_POST['content_id'];
  446. $subcontent = $_POST['subtype_name'];
  447. $is_exist['1']= !$content ? "false" : "true";
  448. $is_exist['2']= !$subcontent ? "false" : "true";
  449. $msg['1'] = !$content ? "content name required" : "";
  450. $msg['2'] = !$subcontent ? "subcontent name required" : "";
  451. if ($is_exist['1']=='true' && $is_exist['2']=='true'){
  452. $where = array('content_id'=>$content, 'subtype_name'=>$subcontent);
  453. $checked = $this->crud->is_exist("","subcontent_type","id",$where);
  454. $is_exist['1'] = !$checked ? "true" : "false";
  455. $is_exist['2'] = !$checked ? "true" : "false";
  456. $msg['1'] = $checked ? "duplicate content name" : "";
  457. $msg['2'] = $checked ? "duplicate subcontent name" : "";
  458. }
  459. $status = in_array('false', $is_exist) ? "false" : "true";
  460. $result = array('status'=>$status,'msg1' =>$msg['1'], 'msg2' =>$msg['2']);
  461. echo json_encode($result);
  462. }
  463. function is_exist_subcontent2(){
  464. $content = $_POST['content_id'];
  465. $subcontent = $_POST['subtype_name'];
  466. $is_exist['1']= !$content ? "false" : "true";
  467. $is_exist['2']= !$subcontent ? "false" : "true";
  468. $msg['1'] = !$content ? "content name required" : "";
  469. $msg['2'] = !$subcontent ? "subcontent name required" : "";
  470. if ($is_exist['1']=='true' && $is_exist['2']=='true'){
  471. $where = array('content_id'=>$content, 'subtype_name'=>$subcontent);
  472. $checked = $this->crud->is_exist("","subcontent_type","id",$where);
  473. $is_exist['1'] = !$checked ? "true" : "false";
  474. $is_exist['2'] = !$checked ? "true" : "false";
  475. $msg['1'] = $checked ? "duplicate content name" : "";
  476. $msg['2'] = $checked ? "duplicate subcontent name" : "";
  477. }
  478. $status = in_array('false', $is_exist) ? "false" : "true";
  479. $result = array('status'=>$status,'msg1' =>$msg['1'], 'msg2' =>$msg['2']);
  480. echo json_encode($result);
  481. }
  482. function form_create_subcontent(){
  483. $content = $this->crud->browse("","content_type","","","true","id,type_name");
  484. if(!$content) $content = array();
  485. $select = array(''=>'-- Select --');
  486. $options = array();
  487. foreach($content as $val){ $options[$val->id] = $val->type_name; }
  488. $data['content'] = $select + $options;
  489. $behavior = $this->crud->browse("","behavior","","","true","id,behavior");
  490. if(!$behavior) $behavior = array();
  491. $select2 = array(''=>'-- Select --');
  492. foreach($behavior as $val){ $options2[$val->id] = $val->behavior; }
  493. $data['behavior'] = $select2 + $options2;
  494. $data['doc'] = $this->crud->browse("","document_req","","","true","id,document_req");
  495. $this->load->view('subcontent/form_create',$data);
  496. }
  497. function create_subcontent(){
  498. /*$ttl = $_POST['ttl'];
  499. $subtype = $_POST['subtype_name'];
  500. $document_req = "";*/
  501. $where = array('subtype_name'=>$subtype);
  502. $is_exist = $this->crud->is_exist("","subcontent_type","id",$where);
  503. /*for ($i = 1; $i <= $ttl; $i++) {
  504. $value = $this->input->post('check'.$i);
  505. if($value) $doc[] = $value;
  506. }
  507. if($doc){ $document_req = implode(",",$doc); }*/
  508. $order = array('field'=>'id','sort'=>'DESC');
  509. $select = $this->crud->browse('','subcontent_type','','','true','','',$order,'','');
  510. $n = 0;
  511. $i = 0;
  512. foreach($select as $val){
  513. if ($i == 0){
  514. $n = $val->id + 1;
  515. break;
  516. }
  517. }
  518. //$n = ($n-2)+1;
  519. $data = array( 'id' => $n,
  520. 'content_id' => $_POST['content_id'],
  521. 'subtype_name' => $_POST['subtype_name'],
  522. 'behavior_id' => $_POST['behavior_id'],
  523. //'document_req_id' => $document_req,
  524. 'is_active' => '1',
  525. 'created_id' => $this->tank_auth->get_user_id(),
  526. 'created_date' => date('Y-m-d H:i:s'),
  527. 'last_updated' => date('Y-m-d H:i:s'));
  528. //print_r($ttl);exit;
  529. if(!$is_exist){
  530. $tes = $this->crud->insert("","subcontent_type",$data);
  531. $data2 = array('id' => null,
  532. 'type' => $n,
  533. //'title' => $_POST['title'],
  534. //'creator' => $_POST['creator'],
  535. //'activated' => '1',
  536. 'file' => strtolower(str_replace(' ', '_', $_POST['subtype_name'])),
  537. //'file_attach' => $ctpath,
  538. 'created_id' => $this->tank_auth->get_user_id(),
  539. 'created_date' => date('Y-m-d H:i:s'),
  540. 'last_updated' => date('Y-m-d H:i:s'));
  541. $this->crud->insert('','policy_agreement',$data2);
  542. }
  543. $msg1 = "succesfully add new document";
  544. $msg2 = "duplicate group document";
  545. $msg = !$is_exist ? $msg1 : $msg2;
  546. //print_r($_POST);exit;
  547. $this->session->set_flashdata('message','1 data success insert');
  548. }
  549. function form_update_subcontent(){
  550. $id = $this->uri->segment(3);
  551. $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";
  552. $def = $this->crud->browse("","subcontent_type l","id",$id,"false",$select);
  553. $data['def'] = $def ;
  554. $content = $this->crud->browse("","content_type","","","true","id,type_name");
  555. if(!$content) $content = array();
  556. $select = array(''=>'-- Select --');
  557. foreach($content as $val){ $options[$val->id] = $val->type_name; }
  558. $data['content'] = $select + $options;
  559. $order = array('field'=>'document_req','sort'=>'ASC');
  560. $data['doc'] = $this->crud->browse("","document_req","","","true","id,document_req","",$order);
  561. $this->load->view('subcontent/form_update',$data);
  562. }
  563. function update_subcontent_(){
  564. /*$ttl = $_POST['ttl'];
  565. $id = $_POST['id'];
  566. $doc = "";
  567. $document = "";
  568. for ($i = 1; $i <= $ttl; $i++) {
  569. $value = $this->input->post('check'.$i);
  570. if($value) $doc[] = $value; }
  571. if($doc) $document = implode(",",$doc);*/
  572. $id = $_POST['id'];
  573. $update = array('document_req_id' => !$document ? "" : $document,
  574. 'id' =>$id,
  575. 'content_id' =>$_POST['content_id'],
  576. 'subtype_name' =>$_POST['subtype_name'],
  577. 'is_active' => '1',
  578. 'last_updated' => date('Y-m-d H:i:s'));
  579. $this->crud->update("","subcontent_type","id",$id,$update);
  580. //print_r($update);
  581. $this->session->set_flashdata('message','1 data success update');
  582. redirect('content/','refresh');
  583. }
  584. function update_subcontent(){
  585. /*$ttl = $_POST['ttl'];
  586. $id = $_POST['id'];
  587. $curr_date = date('Y-m-d H:i:s');
  588. $this->crud->delete("","subcontent_type","id",$id);
  589. $userID = $this->tank_auth->get_user_id();
  590. $doc = "";
  591. $document_req = "";
  592. for ($i = 1; $i <= $ttl; $i++) {
  593. $value = $this->input->post('check'.$i);
  594. if($value) $doc[] = $value; }
  595. if($doc) $document_req = implode(",",$doc);
  596. //$userID = $this->tank_auth->get_user_id();*/
  597. $id = $_POST['id'];
  598. $data = array(//'document_req_id' => !$document ? "" : $document,
  599. 'id' => $id,
  600. 'content_id' => $_POST['content_id'],
  601. 'subtype_name' => $_POST['subtype_name'],
  602. 'behavior_id' => $_POST['behavior_id'],
  603. //'document_req_id' => $document_req,
  604. 'is_active' => '1',
  605. 'created_id' => $this->tank_auth->get_user_id(),
  606. 'created_date' => date('Y-m-d H:i:s'),
  607. 'last_updated' => date('Y-m-d H:i:s'));
  608. //$this->crud->update("","subcontent_type","id",$id,$update);
  609. $this->crud->update("","subcontent_type",'id',$id,$data);
  610. //print_r($update);
  611. $this->session->set_flashdata('message','1 data success update');
  612. redirect('content/','refresh');
  613. }
  614. function delete_subcontent(){
  615. $id = $this->uri->segment(3);
  616. $status = array('is_active'=>'0');
  617. $this->crud->update("","subcontent_type","id",$id,$status);
  618. $this->session->set_flashdata('message','1 data success deleted');
  619. redirect('content/subcontent/','refresh');
  620. }
  621. function delete_subcontent_(){
  622. $id = $this->uri->segment(3);
  623. $where = array('id_subcontent'=>$id);
  624. $checked = $this->crud->is_exist("","level","id",$where);
  625. if($checked){
  626. $this->session->set_flashdata('msg_warning','This data is already in use');
  627. } else {
  628. $this->crud->delete("","subcontent_type","id",$id);
  629. $msg = "succesfully delete subcontent";
  630. $this->session->set_flashdata('message',$msg);
  631. }
  632. redirect('content/subcontent','refresh');
  633. }
  634. }