PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/type_campaign/controllers/Type_campaign.php

https://gitlab.com/estratega.pe/cc
PHP | 210 lines | 197 code | 13 blank | 0 comment | 23 complexity | 5591318eccd337bf9102e953069b6b91 MD5 | raw file
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Type_campaign extends MX_Controller {
  4. function __construct()
  5. {
  6. parent::__construct();
  7. $this->load->model('type_campaign/type_campaignModel', 'type');
  8. }
  9. public function index()
  10. {
  11. acl('ind_show', null, 403);
  12. $columnas = [
  13. ['data' => 'id_type_campaign']
  14. ,['data' => 'des_name']
  15. ];
  16. $show = (!acl('ind_show')) ? '' : createLink(base_url() . 'type_campaign/viewType_campaign/\'+data+\'', 'btn-info', 'icon-eye', 'Ver');
  17. $edit = (!acl('ind_edit')) ? '' : '&nbsp;' . createLink(base_url() . 'type_campaign/editType_campaign/\'+data+\'', 'btn-success', 'icon-edit', 'Editar');
  18. $del = (!acl('ind_del')) ? '' : '&nbsp;' . createLink(base_url() . 'type_campaign/deleteType_campaign/\'+data+\'', 'btn-danger', 'icon-close', 'Eliminar');
  19. $data['HEADER'] = ['PAGE_TITLE_HEADER' => 'Listado de Tipos de Campa&ntilde;as', 'BASE_URL' => base_url()];
  20. $data['BODY'] = $this->parser->parse('listGridAjax', ['BASE_URL' => base_url()
  21. ,'BODY_TITLE' => 'Tipos de Campa&ntilde;as'
  22. ,'URL_AJAX' => base_url() . 'type_campaign/getTypes/datatables'
  23. ,'BODY_DESCRIPTION' => 'Listado de Tipos de Campa&ntilde;as'
  24. ,'BODY_SUBTITLE' => ''
  25. ,'TARGETS' => count($columnas)
  26. ,'ID_TARGET' => 'id_type_campaign'
  27. ,'COLUMNAS' => json_encode($columnas)
  28. ,'BODY_MENU' => (!acl('ind_add')) ? '' : createLink(base_url() . 'type_campaign/addType_campaign', 'btn-blue-alt', 'icon-plus', 'Nuevo', true)
  29. ,'LINKS_ACTIONS' => $show . $edit . $del
  30. ,'TH_TABLE' => [['LABEL' => 'ID'], ['LABEL' => 'NOMBRE'], ['LABEL' => 'ACCIONES']]
  31. ], TRUE);
  32. renderPage($data);
  33. }
  34. public function addType_campaign() {
  35. acl('ind_add', null, 403);
  36. if( $this->input->post() ) {
  37. $newID = $this->type->savetype(['des_name' => $this->input->post('input_des_name', TRUE)]);
  38. if( is_numeric($newID) ) {
  39. redirect(base_url() . 'type_campaign/viewType_campaign/' . $newID);
  40. }
  41. }
  42. $data['HEADER'] = ['PAGE_TITLE_HEADER' => 'Nuevo Tipo de Campa&ntilde;a', 'BASE_URL' => base_url()];
  43. $data['BODY'] = $this->parser->parse('type_campaign/addType_campaign', ['BASE_URL' => base_url()
  44. ,'BODY_TITLE' => 'Nuevo Tipo de Campa&ntilde;a'
  45. ,'BODY_SUBTITLE' => ''
  46. ,'BODY_MENU' => ''
  47. ,'URL_POST' => base_url() .'type_campaign/addType_campaign/'
  48. ,'INPUT_DES_NAME' => form_input('input_des_name', '', 'class="form-control" required')
  49. ,'BUTTON_SUBMIT' => createSubmitButton('Crear', 'btn-blue-alt', 'icon-save')
  50. ,'BUTTON_CANCEL' => createLink(base_url() . 'type_campaign', 'btn-danger', 'icon-ban', 'Cancelar', true)
  51. ], TRUE);
  52. renderPage($data);
  53. }
  54. public function editType_campaign() {
  55. acl('ind_edit', null, 403);
  56. $ID = (sizeof(func_get_args()) >= 0x0001) ? func_get_arg(0): $this->uri->segment(3);
  57. $p = $this->type->getTypeRow(['id_type_campaign' => $ID]);
  58. if( $this->input->post() ) {
  59. $data = ['des_name' => $this->input->post('input_des_name', TRUE)];
  60. if( $this->type->updateType($data, $ID) === FALSE) {
  61. $this->db->trans_rollback();
  62. } else {
  63. redirect(base_url() . 'type_campaign/viewType_campaign/' . $ID);
  64. }
  65. }
  66. $data['HEADER'] = ['PAGE_TITLE_HEADER' => 'Editar Tipo de Campa&ntilde;a', 'BASE_URL' => base_url()];
  67. $data['BODY'] = $this->parser->parse('type_campaign/editType_campaign', ['BASE_URL' => base_url()
  68. ,'BODY_TITLE' => 'Editar Tipo de Campa&ntilde;a'
  69. ,'BODY_SUBTITLE' => '(' . $p->des_name . ')'
  70. ,'BODY_MENU' => ''
  71. ,'URL_POST' => base_url() .'type_campaign/editType_campaign/' . $p->id_type_campaign
  72. ,'INPUT_DES_NAME' => form_input('input_des_name', $p->des_name, 'class="form-control" required')
  73. ,'INPUT_ID_PERM' => form_hidden('input_id_type_campaign', $p->id_type_campaign)
  74. ,'BUTTON_SUBMIT' => createSubmitButton('Actualizar', 'btn-blue-alt', 'icon-save')
  75. ,'BUTTON_CANCEL' => createLink(base_url() . 'type_campaign', 'btn-danger', 'icon-ban', 'Cancelar', true)
  76. ], TRUE);
  77. renderPage($data);
  78. }
  79. public function viewType_campaign() {
  80. acl('ind_show', null, 403);
  81. $ID = (sizeof(func_get_args()) >= 0x0001) ? func_get_arg(0): $this->uri->segment(3);
  82. $ID = filter_var(intval($ID),FILTER_VALIDATE_INT) ? $ID : 0;
  83. if($ID == 0x0000 ) {
  84. header('Location: ' . base_url() . 'type_campaign');
  85. exit();
  86. }
  87. $p = $this->type->getTypeRow(['id_type_campaign' => $ID]);
  88. $data['HEADER'] = ['PAGE_TITLE_HEADER' => 'Ver Tipo de Campa&ntilde;a', 'BASE_URL' => base_url()];
  89. $data['BODY'] = $this->parser->parse('type_campaign/viewType_campaign', ['BASE_URL' => base_url()
  90. ,'BODY_TITLE' => 'Ver Tipo de Campa&ntilde;a'
  91. ,'BODY_SUBTITLE' => '(' . $p->des_name . ')'
  92. ,'BODY_MENU' => ''
  93. ,'INPUT_DES_NAME' => form_input('input_des_name', $p->des_name, 'class="form-control" readonly')
  94. ,'BUTTON_CANCEL' => createLink(base_url() . 'type_campaign', 'btn-danger', 'icon-ban', 'Volver', true)
  95. ], TRUE);
  96. renderPage($data);
  97. }
  98. public function deleteType_campaign() {
  99. acl('ind_del', null, 403);
  100. $ID = (sizeof(func_get_args()) >= 0x0001) ? func_get_arg(0): $this->uri->segment(3);
  101. $ID = filter_var(intval($ID),FILTER_VALIDATE_INT) ? $ID : 0;
  102. if($ID == 0x0000) {
  103. header('Location: ' . base_url() . 'type_campaign');
  104. exit();
  105. }
  106. $p = $this->type->getTypeRow(['id_type_campaign' => $ID]);
  107. if($this->input->post()) {
  108. if( $this->input->post('input_id_type_campaign', TRUE) == $ID) {
  109. if ($this->type->deleteType($this->input->post('input_id_type_campaign', TRUE)) === FALSE) {
  110. $this->db->trans_rollback();
  111. } else {
  112. redirect(base_url() . 'type_campaign');
  113. }
  114. }
  115. }
  116. $data['HEADER'] = ['PAGE_TITLE_HEADER' => 'Eliminar Tipo de Campa&ntilde;a ' . $p->des_name, 'BASE_URL' => base_url()];
  117. $data['BODY'] = $this->parser->parse('deleteForm', ['BASE_URL' => base_url()
  118. ,'BODY_TITLE' => 'Eliminar Tipo de Campa&ntilde;a - ' . $p->des_name
  119. ,'BODY_SUBTITLE' => 'No se puede deshacer la eliminaci&oacute;n'
  120. ,'BODY_MENU' => '(' . $p->id_type_campaign . ') ' . $p->des_name
  121. ,'BODY_DESCRIPTION' => 'Confirme eliminacion del Tipo de Campa&ntilde;a "' . $p->des_name . '"'
  122. ,'URL_POST' => base_url() . 'type_campaign/deleteType_campaign/' . $ID
  123. ,'INPUT_DELETE_ID' => form_hidden('input_id_type_campaign', $ID)
  124. ,'BUTTON_SUBMIT' => createSubmitButton('Eliminar', 'btn-blue-alt', 'icon-remove')
  125. ,'BUTTON_CANCEL' => createLink(base_url() . 'type_campaign', 'btn-danger', 'icon-ban', 'Cancelar', true)
  126. ], TRUE);
  127. renderPage($data);
  128. }
  129. public function getTypes() {
  130. $format = (sizeof(func_get_args()) >= 0x0001) ? func_get_arg(0): $this->uri->segment(3);
  131. if( $this->input->post() ) {
  132. $total = 0;
  133. $start = $this->input->post('start');
  134. $limit = $this->input->post('length');
  135. $draw = $this->input->post('draw');
  136. if($this->input->post('search')['value'] != '') {
  137. $search = $this->input->post('search')['value'];
  138. $like = ['des_name' => $search];
  139. $result = $this->type->getTypess(null, $like);
  140. $total = $this->type->getTotalType(null, $like);
  141. } else {
  142. if($this->input->post('q') != '') {
  143. $search = $this->input->post('q');
  144. $like = ['des_name' => $search];
  145. $result = $this->type->getTypes(null, $like, $start, $limit);
  146. $total = $this->type->getTotalType(null, $like);
  147. } else {
  148. $result = $this->type->getTypes(null, null, $start, $limit);
  149. $total = $this->type->getTotalType();
  150. }
  151. }
  152. } else {
  153. $result = $this->type->getTypes();
  154. }
  155. switch($format) {
  156. case 'object':
  157. return $result;
  158. break;
  159. case 'array':
  160. break;
  161. case 'datatables':
  162. $data = [];
  163. if($this->input->post()) {
  164. $records = [];
  165. foreach($result as $r) {
  166. array_push($records, [
  167. 'id_type_campaign' => $r->id_type_campaign
  168. ,'des_name' => $r->des_name
  169. ]);
  170. }
  171. $data = ['draw' => $draw
  172. ,'recordsTotal' => $total
  173. ,'recordsFiltered' => $total
  174. ,'data' => $records
  175. ];
  176. }
  177. $this->output
  178. ->set_content_type('application/json')
  179. ->set_output(json_encode( $data ));
  180. break;
  181. case 'json-ui':
  182. $rows = [];
  183. foreach($result as $k) {
  184. array_push($rows, [
  185. 'id' => $k->id_type_campaign
  186. ,'name' => $k->des_name
  187. ]);
  188. }
  189. $this->output
  190. ->set_content_type('application/json')
  191. ->set_output(json_encode( $rows ));
  192. break;
  193. default:
  194. break;
  195. }
  196. }
  197. }