PageRenderTime 56ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 1ms

/masportales/application/controllers/micuenta/empresa.php

https://github.com/eloypineda/XHTMLized
PHP | 421 lines | 319 code | 71 blank | 31 comment | 34 complexity | c2f06a39ea9e2f0d6c513ecb2d6043a8 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Empresa extends Account_Controller
  3. {
  4. public function _index_index()
  5. {
  6. }
  7. public function _perfil_index()
  8. {
  9. }
  10. public function _perfil_new()
  11. {
  12. $this->load->library('form_validation');
  13. }
  14. public function _perfil_add()
  15. {
  16. $this->load->model('companies_model');
  17. $this->load->library('form_validation');
  18. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  19. $this->form_validation->set_message('required', 'Debe rellenar el campo: %s');
  20. $this->form_validation->set_message('matches', '\'%s\' y \'%s\' son distintos.');
  21. $this->form_validation->set_message('valid_email', 'El campo \'%s\' debe contener un email válido.');
  22. $this->form_validation->set_message('exact_length', 'El campo \'%s\' debe tener 9 carácteres.');
  23. $this->form_validation->set_message('is_unique', 'Ya existe usuario con el \'%s\' indicado.');
  24. $this->form_validation->set_rules('name', 'Denominacion', 'trim|required|xss_clean');
  25. $this->form_validation->set_rules('nif', 'N.I.F.', 'trim|required|xss_clean');
  26. $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  27. $this->form_validation->set_rules('address', 'Direccion', 'trim|xss_clean');
  28. $this->form_validation->set_rules('zipcode', 'Codigo Postal', 'trim|xss_clean');
  29. $this->form_validation->set_rules('city', 'Ciudad', 'trim|xss_clean');
  30. $this->form_validation->set_rules('state', 'Provincia', 'trim|xss_clean');
  31. $this->form_validation->set_rules('country', 'Pais', 'trim|xss_clean');
  32. $this->form_validation->set_rules('phone', 'Telefono', 'trim|xss_clean');
  33. $this->form_validation->set_rules('web', 'Web', 'trim|xss_clean');
  34. if ($this->form_validation->run() == false) {
  35. $this->registry->set('action', 'new', 'request');
  36. } else {
  37. $data['company'] = $this->input->post();
  38. $data['company']['date_added'] = date('Y-m-d H:i:s');
  39. $data['company']['date_modified'] = date('Y-m-d H:i:s');
  40. $data['company']['status'] = 'pendiente';
  41. $data['company']['user_ID'] = $this->registry->user('user_ID');
  42. unset($data['company']['files'], $data['company']['umod']);
  43. if (!$this->companies_model->addCompany($data)) {
  44. $this->registry->set('action', 'new', 'request');
  45. } else {
  46. $this->registry->set('section', 'index', 'request');
  47. $this->registry->set('action', 'index', 'request');
  48. $this->registry->set_company($this->users_model->getUserCompany($this->registry->user('user_ID')));
  49. }
  50. }
  51. }
  52. public function _perfil_edit()
  53. {
  54. $this->load->library('form_validation');
  55. $this->load->model('companies_model');
  56. return array(
  57. 'company_images' => $this->companies_model->getCompanyImages($this->registry->company('company_ID'))
  58. );
  59. }
  60. public function _perfil_save()
  61. {
  62. $this->load->model('companies_model');
  63. $this->load->library('form_validation');
  64. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  65. $this->form_validation->set_message('required', 'Debe rellenar el campo: %s');
  66. $this->form_validation->set_message('matches', '\'%s\' y \'%s\' son distintos.');
  67. $this->form_validation->set_message('valid_email', 'El campo \'%s\' debe contener un email válido.');
  68. $this->form_validation->set_message('exact_length', 'El campo \'%s\' debe tener 9 carácteres.');
  69. $this->form_validation->set_message('is_unique', 'Ya existe usuario con el \'%s\' indicado.');
  70. $this->form_validation->set_rules('name', 'Denominacion', 'trim|required|xss_clean');
  71. $this->form_validation->set_rules('nif', 'N.I.F.', 'trim|required|xss_clean');
  72. $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  73. $this->form_validation->set_rules('address', 'Direccion', 'trim|xss_clean');
  74. $this->form_validation->set_rules('zipcode', 'Codigo Postal', 'trim|xss_clean');
  75. $this->form_validation->set_rules('city', 'Ciudad', 'trim|xss_clean');
  76. $this->form_validation->set_rules('state', 'Provincia', 'trim|xss_clean');
  77. $this->form_validation->set_rules('country', 'Pais', 'trim|xss_clean');
  78. $this->form_validation->set_rules('phone', 'Telefono', 'trim|xss_clean');
  79. $this->form_validation->set_rules('web', 'Web', 'trim|xss_clean');
  80. if ($this->form_validation->run() == false) {
  81. $this->registry->set('action', 'edit', 'request');
  82. } else {
  83. $data['company'] = $this->input->post();
  84. $data['company']['date_modified'] = date('Y-m-d H:i:s');
  85. $image_main = $this->input->post('image_main', true);
  86. $tmp_images = array(
  87. 'name' => $this->input->post('images_name', true),
  88. 'uri' => $this->input->post('images_uri', true),
  89. 'type' => $this->input->post('images_type', true)
  90. );
  91. $data['companies_images'] = array();
  92. if ($tmp_images['name']) {
  93. foreach ($tmp_images['name'] as $key => $image_name) {
  94. $data['companies_images'][$image_name] = array(
  95. 'name' => $image_name,
  96. 'uri' => $tmp_images['uri'][$key],
  97. 'mime_type' => $tmp_images['type'][$key],
  98. 'status' => 'publish',
  99. 'main' => ($image_name == $image_main) ? 1 : 0,
  100. 'date_added' => date('Y-m-d H:i:s')
  101. );
  102. }
  103. } else {
  104. $data['companies_images'] = false;
  105. }
  106. unset($data['company']['files'], $data['company']['umod'], $data['company']['image_main'], $data['company']['images_name'], $data['company']['images_uri'], $data['company']['images_type']);
  107. if ($this->companies_model->saveCompany($data, $this->registry->company('company_ID'))) {
  108. $this->registry->set('section', 'index', 'request');
  109. $this->registry->set('action', 'index', 'request');
  110. $this->registry->set_company(array_merge($this->registry->company(), $data['company']));
  111. } else {
  112. $this->registry->set('action', 'edit', 'request');
  113. }
  114. }
  115. }
  116. public function _upgrade_index()
  117. {
  118. $this->load->model('ecommerce_model');
  119. $this->load->library('form_validation');
  120. return array(
  121. 'payment' => $this->ecommerce_model->getPaymentGateways(false, 0)
  122. );
  123. }
  124. public function _upgrade_confirmation()
  125. {
  126. $this->load->model('ecommerce_model');
  127. $this->load->library('form_validation');
  128. return array(
  129. 'payment' => $this->ecommerce_model->getPaymentGateways(false, 0)
  130. );
  131. }
  132. public function _microsite_index()
  133. {
  134. $this->load->model('companies_model');
  135. $params = array(
  136. 'filter_by' => 'company_ID',
  137. 'filter' => $this->registry->company('company_ID')
  138. );
  139. return array(
  140. 'microsites_pages' => $this->companies_model->getMicrositePages($params)
  141. );
  142. }
  143. public function _microsite_pageedit($microsite_page_id)
  144. {
  145. $this->load->model('companies_model');
  146. $this->load->library('form_validation');
  147. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  148. return array(
  149. 'microsite_page' => $this->companies_model->getMicrositePage($microsite_page_id)
  150. );
  151. }
  152. public function _microsite_pagesave()
  153. {
  154. $this->load->model('companies_model');
  155. $this->load->library('form_validation');
  156. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  157. $this->form_validation->set_message('required', 'Debe rellenar el campo: %s');
  158. $this->form_validation->set_message('matches', '\'%s\' y \'%s\' son distintos.');
  159. $this->form_validation->set_message('valid_email', 'El campo \'%s\' debe contener un email válido.');
  160. $this->form_validation->set_message('exact_length', 'El campo \'%s\' debe tener 9 carácteres.');
  161. $this->form_validation->set_message('is_unique', 'Ya existe usuario con el \'%s\' indicado.');
  162. $this->form_validation->set_rules('title', 'Título', 'trim|required|xss_clean');
  163. $this->form_validation->set_rules('slug', 'URL amigable', 'trim|required|xss_clean');
  164. $this->form_validation->set_rules('content', 'Contenido', 'trim|xss_clean');
  165. $this->form_validation->set_rules('meta_keywords', 'Palabras claves', 'trim|xss_clean');
  166. $this->form_validation->set_rules('meta_description', 'Descripcion SEO', 'trim|xss_clean');
  167. $microsite_page_id = $this->input->post('upid', true);
  168. if ($this->form_validation->run() == false) {
  169. //$this->registry->set('action', 'edit', 'request');
  170. } else {
  171. $data['microsites_pages'] = $this->input->post();
  172. $data['microsites_pages']['company_ID'] = $this->registry->company('company_ID');
  173. $data['microsites_pages']['author'] = $this->registry->user('user_ID');
  174. $data['microsites_pages']['date_modified'] = date('Y-m-d H:i:s');
  175. unset($data['microsites_pages']['upid']);
  176. /*
  177. echo '<pre>';
  178. print_r($data);
  179. echo '</pre>';
  180. exit();
  181. */
  182. if ($microsite_page_id = $this->companies_model->saveMicrositePage($data, $microsite_page_id)) {
  183. $this->registry->set_message(array(
  184. 'class' => 'success',
  185. 'content' => 'Apartado guardado correctamente.'
  186. ));
  187. //$this->registry->set('section', 'index', 'request');
  188. //$this->registry->set('action', 'index', 'request');
  189. //$this->registry->set_company(array_merge($this->registry->company(), $data['company']));
  190. } else {
  191. $this->registry->set_message(array(
  192. 'class' => 'error',
  193. 'content' => 'Error al guardar el apartado.'
  194. ));
  195. //$this->registry->set('action', 'edit', 'request');
  196. }
  197. }
  198. $this->registry->set('action', 'pageedit', 'request');
  199. return array(
  200. 'microsite_page' => $this->companies_model->getMicrositePage($microsite_page_id)
  201. );
  202. }
  203. public function _microsite_banneredit($microsite_banner_id)
  204. {
  205. $this->load->model('companies_model');
  206. $this->load->library('form_validation');
  207. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  208. // get the ID of the banner
  209. if (!$microsite_banner_id) {
  210. $params = array(
  211. 'limit' => '1',
  212. 'filter_by' => 'company_ID',
  213. 'filter' => $this->registry->company('company_ID')
  214. );
  215. $banner = $this->companies_model->getMicrositeBanners($params);
  216. $microsite_banner_id = $banner[0]['microsite_banner_ID'];
  217. }
  218. return array(
  219. 'microsite_banner' => $this->companies_model->getMicrositeBanner($microsite_banner_id)
  220. );
  221. }
  222. public function _microsite_bannersave()
  223. {
  224. $this->load->model('companies_model');
  225. $this->load->library('form_validation');
  226. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  227. $this->form_validation->set_rules('name', 'Título', 'trim|xss_clean');
  228. $microsite_banner_id = $this->input->post('ubid', true);
  229. if ($this->form_validation->run() == false) {
  230. //$this->registry->set('action', 'edit', 'request');
  231. } else {
  232. $data['microsites_banners'] = $this->input->post();
  233. $data['microsites_banners']['company_ID'] = $this->registry->company('company_ID');
  234. //$data['microsites_banners']['author'] = $this->registry->user('user_ID');
  235. //$data['microsites_banners']['date_modified'] = date('Y-m-d H:i:s');
  236. unset($data['microsites_banners']['ubid'], $data['microsites_banners']['umod'], $data['microsites_banners']['files']);
  237. /*
  238. echo '<pre>';
  239. print_r($data);
  240. echo '</pre>';
  241. exit();
  242. */
  243. if ($microsite_banner_id = $this->companies_model->saveMicrositeBanner($data, $microsite_banner_id)) {
  244. $this->registry->set_message(array(
  245. 'class' => 'success',
  246. 'content' => 'Banner guardado correctamente.'
  247. ));
  248. //$this->registry->set('section', 'index', 'request');
  249. //$this->registry->set('action', 'index', 'request');
  250. //$this->registry->set_company(array_merge($this->registry->company(), $data['company']));
  251. } else {
  252. $this->registry->set_message(array(
  253. 'class' => 'error',
  254. 'content' => 'Error al guardar el banner.'
  255. ));
  256. //$this->registry->set('action', 'edit', 'request');
  257. }
  258. }
  259. $this->registry->set('action', 'banneredit', 'request');
  260. return array(
  261. 'microsite_banner' => $this->companies_model->getMicrositeBanner($microsite_banner_id)
  262. );
  263. }
  264. public function _banners_index()
  265. {
  266. $this->load->model('banners_model');
  267. // search
  268. $search = $this->input->post('search', true);
  269. $this->registry->set('search', $search, 'request');
  270. // load banners
  271. $params = array(
  272. 'search_by' => ($search) ? 'name' : false,
  273. 'search' => $search,
  274. 'filter_by' => 'user_ID',
  275. 'filter' => $this->registry->user('user_ID')
  276. );
  277. // pagination
  278. $pagination = (isset($params[1]) and $params[1] == 'page') ? true : false;
  279. $pagination_start = (isset($params[2])) ? $params[2] : 0;
  280. $per_page = 10;
  281. $config_pagination = array(
  282. 'base_url' => _reg('module_url') . 'banners/banner/page/',
  283. 'uri_segment' => 6,
  284. 'total_rows' => $this->banners_model->getNBanners($params),
  285. 'per_page' => $per_page
  286. );
  287. $this->pagination->initialize($config_pagination);
  288. return array(
  289. 'banners' => $this->banners_model->getBanners($params),
  290. 'pagination' => $this->pagination->create_links()
  291. );
  292. }
  293. public function _banners_edit($banner_id)
  294. {
  295. $this->load->model('banners_model');
  296. $this->load->library('form_validation');
  297. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  298. return array(
  299. 'banner' => $this->banners_model->getBanner($banner_id),
  300. 'banners_positions' => $this->banners_model->getBannersPositions(),
  301. 'banners_contracts' => $this->banners_model->getBannersContracts()
  302. );
  303. }
  304. public function _banners_save()
  305. {
  306. $this->load->model('banners_model');
  307. $banner_id = $this->input->post('bid', true);
  308. $this->load->library('form_validation');
  309. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  310. $this->form_validation->set_rules('name', 'Nombre', 'trim|required|xss_clean');
  311. $this->form_validation->set_rules('link', 'Enlace', 'trim|prep_url|xss_clean');
  312. if ($this->form_validation->run() == false) {
  313. $this->registry->set('action', 'edit', 'request');
  314. } else {
  315. $this->registry->set('action', 'edit', 'request');
  316. $data = array(
  317. 'banners' => array(
  318. 'user_ID' => $this->registry->user('user_ID'),
  319. 'name' => $this->input->post('name'),
  320. 'image_uri' => $this->input->post('image_uri'),
  321. 'image_mime_type' => $this->input->post('image_mime_type'),
  322. 'link' => $this->input->post('link'),
  323. 'date_modified' => date('Y-m-d H:i:s')
  324. )
  325. );
  326. //($this->input->post('contract')) ? $data['banners']['banner_contract_ID'] = $this->input->post('contract');
  327. if ($this->input->post('position')) $data['banners']['banner_position_ID'] = $this->input->post('position');
  328. if ($this->input->post('contract')) $data['banners']['banner_contract_ID'] = $this->input->post('contract');
  329. if (!$banner_id) $data['banners']['status'] = 'pendiente';
  330. if ($banner_id = $this->banners_model->saveBanner($data, $banner_id)) {
  331. $this->registry->set_message(array(
  332. 'class' => 'success',
  333. 'content' => 'Banner guardado correctamente.'
  334. ));
  335. } else {
  336. $this->registry->set_message(array(
  337. 'class' => 'error',
  338. 'content' => 'Error al guardar el banner.'
  339. ));
  340. }
  341. $this->registry->set('action','edit', 'request');
  342. return array(
  343. 'banner' => $this->banners_model->getBanner($banner_id),
  344. 'banners_positions' => $this->banners_model->getBannersPositions()
  345. );
  346. }
  347. }
  348. }
  349. /* End of file empresa.php */
  350. /* Location: ./application/controllers/micuenta/empresa.php */