PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/masportales/application/controllers/empresas.php

https://github.com/eloypineda/XHTMLized
PHP | 251 lines | 189 code | 34 blank | 28 comment | 13 complexity | 77a90f701c1728da65df0a55f57e2906 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Empresas extends Front_Controller {
  3. public function _remap($method, $arguments = array())
  4. {
  5. global $class;
  6. $this->load->model('ecommerce_model');
  7. $this->load->model('companies_model');
  8. $this->load->library('form_validation');
  9. $this->registry->set('module', $class, 'request');
  10. $view = 'themes/default/layout';
  11. //$this->settings['module_url'] = _reg('site_url') . $class . '/';
  12. /*
  13. if (isset($_POST['pid'])) {
  14. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  15. $this->form_validation->set_message('required', 'Debe rellenar el campo: %s');
  16. $this->form_validation->set_message('valid_email', 'El campo \'%s\' debe contener un email válido.');
  17. $this->form_validation->set_rules('name', 'Nombre', 'trim|required|xss_clean');
  18. $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
  19. $this->form_validation->set_rules('web', 'Web', 'trim|prep_url|xss_clean');
  20. $this->form_validation->set_rules('message', 'Mensaje', 'trim|xss_clem|strip_tags');
  21. if ($this->form_validation->run()) {
  22. $this->_save_comment();
  23. }
  24. }
  25. */
  26. if ($method == 'index' and !$arguments) {
  27. $this->registry->set('section', 'empresas', 'request');
  28. $this->registry->set('company_id', false, 'request');
  29. } elseif ($company_id = $this->companies_model->slugFor($method)) {
  30. $this->registry->set('section', 'empresa', 'request');
  31. $this->registry->set('company_id', $company_id, 'request');
  32. } elseif (method_exists($this, '_' . $method) and is_callable(array($this, '_' . $method))) {
  33. $this->registry->set('section', $method, 'request');
  34. $this->registry->set('company_id', false, 'request');
  35. } else {
  36. show_404();
  37. }
  38. $function = '_' . $this->registry->request('section');
  39. if (method_exists($this, $function)) {
  40. $this->settings['data'] = $this->$function($this->registry->request('company_id'));
  41. } else {
  42. show_404();
  43. }
  44. $this->columns(); // TODO
  45. $this->load->view($view, $this->settings);
  46. }
  47. public function _empresas()
  48. {
  49. $params = array(
  50. 'start' => 0,
  51. 'limit' => 5,
  52. 'filter_by' => 'status',
  53. 'filter' => 'publicado'
  54. );
  55. $this->registry->set_meta('title', $this->registry->site_name() . ' . Guía Comercial');
  56. $this->registry->set_meta('keywords', $this->registry->site('companies_keywords'));
  57. $this->registry->set_meta('description', $this->registry->site('companies_description'));
  58. return array(
  59. 'companies' => $this->companies_model->getCompanies($params),
  60. 'search_query' => false
  61. );
  62. }
  63. public function _search()
  64. {
  65. $search_query = $this->input->post('searchquery', true);
  66. $params_companies = array(
  67. 'start' => 0,
  68. 'limit' => 10,
  69. 'search_by' => ($search_query) ? array('name', 'description') : false,
  70. 'search' => array($search_query, $search_query),
  71. 'filter_by' => 'status',
  72. 'filter' => 'publicado'
  73. );
  74. $companies = $this->companies_model->getCompanies($params_companies);
  75. $this->registry->set_meta('title', $this->registry->site_name() . ' . Guía Comercial . Resultado para la búsqueda: ' . $search_query);
  76. $this->registry->set_meta('keywords', $this->registry->site('companies_keywords'));
  77. $this->registry->set_meta('description', $this->registry->site('companies_description'));
  78. $this->registry->set('section', 'empresas', 'request');
  79. return array(
  80. 'companies' => $companies,
  81. 'search_query' => $search_query
  82. );
  83. }
  84. public function _empresa($company_id)
  85. {
  86. $this->load->helper('captcha');
  87. $vals = array(
  88. 'img_path' => _reg('base_path') . 'usrs/captcha/',
  89. 'img_url' => _reg('base_url') . 'usrs/captcha/'
  90. );
  91. $cap = create_captcha($vals);
  92. $data = array(
  93. 'captcha_time' => $cap['time'],
  94. 'ip_address' => $this->input->ip_address(),
  95. 'word' => $cap['word']
  96. );
  97. $query = $this->db->insert_string('captcha', $data);
  98. $this->db->query($query);
  99. $company_data = $this->companies_model->getCompany($company_id);
  100. $this->registry->set_meta('title', $this->registry->site_name() . ' . Guía Comercial . ' . $company_data['name']);
  101. $this->registry->set_meta('keywords', $company_data['meta_keywords']);
  102. $this->registry->set_meta('description', $company_data['meta_description']);
  103. return array(
  104. 'company' => $company_data,
  105. 'captcha' => $cap
  106. );
  107. }
  108. public function _microsite($company_id)
  109. {
  110. $company_data = $this->companies_model->getCompany($company_id);
  111. $microsite = $this->companies_model->getCompanyMicrosite($company_id);
  112. $this->registry->set_meta('title', $company_data['name'] . ' - Home');
  113. $this->registry->set_meta('keywords', $company_data['meta_keywords']);
  114. $this->registry->set_meta('description', $company_data['meta_description']);
  115. $params = array(
  116. 'limit' => '1',
  117. 'filter_by' => 'company_ID',
  118. 'filter' => $company_id
  119. );
  120. $banner = $this->companies_model->getMicrositeBanners($params);
  121. /*
  122. echo '<pre>';
  123. print_r($company_data);
  124. echo '</pre>';
  125. echo '<pre>';
  126. print_r($microsite);
  127. echo '</pre>';
  128. */
  129. return array(
  130. 'company' => $company_data,
  131. 'company_images' => $this->companies_model->getCompanyImages($company_id),
  132. 'microsite_pages' => $microsite,
  133. 'banner' => $banner[0]
  134. );
  135. }
  136. public function _registrarse()
  137. {
  138. }
  139. public function _confirmation()
  140. {
  141. $this->load->model('users_model');
  142. $this->load->library('form_validation');
  143. $this->form_validation->set_rules('name', 'Nombre', 'trim|required|xss_clean');
  144. $this->form_validation->set_rules('surname', 'Apellidos', 'trim|required|xss_clean');
  145. $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');
  146. $this->form_validation->set_rules('username', 'Nombre de usuario', 'trim|required|is_unique[users.username]|xss_clean');
  147. $this->form_validation->set_rules('password', 'Contraseña', 'trim|required|matches[password2]');
  148. $this->form_validation->set_rules('password2', 'Repite contraseña', 'trim|required');
  149. if ($this->form_validation->run() == false) {
  150. $this->registry->set('section', 'registrarse', 'request');
  151. } else {
  152. $data = array(
  153. 'users' => array(
  154. 'username' => $this->input->post('username'),
  155. 'display_name' => $this->input->post('username'),
  156. 'email' => $this->input->post('email'),
  157. 'nif' => $this->input->post('nif'),
  158. 'password' => sha1($this->input->post('password').$this->config->item('encryption_key')),
  159. 'status' => '0',
  160. 'IP' => $this->input->ip_address(),
  161. 'date_modified' => date('Y-m-d H:i:s'),
  162. 'date_added' => date('Y-m-d H:i:s')
  163. ),
  164. 'roles' => array('4'),
  165. 'users_address' => array(
  166. 'name' => $this->input->post('name'),
  167. 'surname' => $this->input->post('surname')
  168. )
  169. );
  170. if ($user_id = $this->users_model->saveUSer($data)) {
  171. $data['users']['user_ID'] = $user_id;
  172. $data['confirmation_hash'] = array(
  173. 'user_ID' => $user_id,
  174. 'meta_key' => 'confirmation_user_hash',
  175. 'meta_value' => random_string('unique')
  176. );
  177. $this->users_model->setUserMeta($data['confirmation_hash']);
  178. $data['company'] = array(
  179. 'user_ID' => $user_id,
  180. 'name' => $this->input->post('companyname'),
  181. 'slug' => url_title($this->input->post('companyname'), '-', true), // TODO. now there can be duplicated slugs
  182. 'address' => $this->input->post('address'),
  183. 'zipcode' => $this->input->post('zipcode'),
  184. 'city' => $this->input->post('city'),
  185. 'state' => $this->input->post('state'),
  186. 'country' => $this->input->post('country'),
  187. 'phone' => $this->input->post('phone'),
  188. 'email' => ($this->input->post('companyemail')) ? $this->input->post('companyemail') : $this->input->post('email'),
  189. 'web' => $this->input->post('web'),
  190. 'date_modified' => date('Y-m-d H:i:s')
  191. );
  192. if ($company_id = $this->companies_model->saveCompany($data)) {
  193. $this->companies_model->sendRegistrationEmail($data);
  194. $this->registry->set_message(array(
  195. 'class' => 'success',
  196. 'content' => 'Solicitud de suscripción recibida correctamente. Se le ha enviado un email para confirmar su cuenta.'
  197. ));
  198. } else {
  199. $this->registry->set_message(array(
  200. 'class' => 'error',
  201. 'content' => 'No se ha podido procesar su solicitd correctamente. Vuelva a intentarlo más tarde.'
  202. ));
  203. }
  204. } else {
  205. $this->registry->set_message(array(
  206. 'class' => 'error',
  207. 'content' => 'No se ha podido procesar su solicitd correctamente. Vuelva a intentarlo más tarde.'
  208. ));
  209. }
  210. }
  211. }
  212. }
  213. /* End of file empresas.php */
  214. /* Location: ./application/controllers/empresas.php */