PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/masportales/application/controllers/agenda_datepicker.php

https://github.com/eloypineda/XHTMLized
PHP | 238 lines | 163 code | 35 blank | 40 comment | 15 complexity | 99206f12ab5739f31b19d042d512585a MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Agenda extends Front_Controller {
  3. public function _remap($method, $arguments = array())
  4. {
  5. global $class;
  6. $this->load->model('event_model');
  7. $this->load->model('companies_model');
  8. $this->load->library('form_validation');
  9. $this->registry->set('module', $class, 'request');
  10. $this->settings['module_url'] = _reg('site_url') . $class . '/';
  11. /*
  12. if (isset($_POST['pid'])) {
  13. $this->form_validation->set_error_delimiters('<div class="message error">', '</div>');
  14. $this->form_validation->set_message('required', 'Debe rellenar el campo: %s');
  15. $this->form_validation->set_message('valid_email', 'El campo \'%s\' debe contener un email vĂĄlido.');
  16. $this->form_validation->set_rules('name', 'Nombre', 'trim|required|xss_clean');
  17. $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|xss_clean');
  18. $this->form_validation->set_rules('web', 'Web', 'trim|prep_url|xss_clean');
  19. $this->form_validation->set_rules('message', 'Mensaje', 'trim|xss_clem|strip_tags');
  20. if ($this->form_validation->run()) {
  21. $this->_save_comment();
  22. }
  23. }
  24. */
  25. if ($method == 'index' and !$arguments) {
  26. $this->registry->set('section', 'eventos', 'request');
  27. $this->registry->set('event_id', false, 'request');
  28. } elseif ($event_id = $this->event_model->slugFor($method)) {
  29. $this->registry->set('section', 'evento', 'request');
  30. $this->registry->set('event_id', $event_id, 'request');
  31. } elseif (method_exists($this, '_' . $method) and is_callable(array($this, '_' . $method))) {
  32. $this->registry->set('section', $method, 'request');
  33. $this->registry->set('event_id', ($arguments) ? $arguments[0] : null, 'request');
  34. } else {
  35. show_404();
  36. }
  37. $function = '_' . $this->registry->request('section');
  38. if (method_exists($this, $function)) {
  39. $this->settings['data'] = $this->$function($this->registry->request('event_id'));
  40. } else {
  41. show_404();
  42. }
  43. $this->columns(); // TODO
  44. if ($this->uri->segment(2) != 'calendar') {
  45. $this->load->view('themes/default/layout', $this->settings);
  46. }
  47. }
  48. public function _evento($event_id)
  49. {
  50. $this->load->helper('captcha');
  51. $vals = array(
  52. 'img_path' => _reg('base_path') . 'usrs/captcha/',
  53. 'img_url' => _reg('base_url') . 'usrs/captcha/'
  54. );
  55. $cap = create_captcha($vals);
  56. $data = array(
  57. 'captcha_time' => $cap['time'],
  58. 'ip_address' => $this->input->ip_address(),
  59. 'word' => $cap['word']
  60. );
  61. $query = $this->db->insert_string('captcha', $data);
  62. $this->db->query($query);
  63. $event_data = $this->event_model->getEventEvent($event_id);
  64. $this->registry->set_meta('title', $this->registry->site_name() . ' . Agenda . ' . $event_data['title']);
  65. $this->registry->set_meta('keywords', $event_data['meta_keywords']);
  66. $this->registry->set_meta('description', $event_data['meta_description']);
  67. $comments_number = $this->event_model->getAgendaOwnComments($event_id, 'APPROVED');
  68. $comments = $this->event_model->getAgendaOwnCommentsDetail($event_id,'APPROVED');
  69. //var_dump($comments);exit();
  70. return array(
  71. 'event' => $event_data,
  72. 'captcha' => $cap,
  73. 'comments' => $comments,
  74. 'comments_number' => $comments_number
  75. );
  76. }
  77. public function _eventos()
  78. {
  79. $params = array(
  80. 'start' => 0,
  81. 'limit' => 10,
  82. 'from' => date('Y-m-d')
  83. );
  84. $this->registry->set_meta('title', $this->registry->site_name() . ' . Agenda');
  85. $this->registry->set_meta('keywords', $this->registry->site('event_keywords'));
  86. $this->registry->set_meta('description', $this->registry->site('event_description'));
  87. $comments_number = $this->event_model->getAgendaNComments('APPROVED');
  88. return array(
  89. 'events' => $this->event_model->getEventsByDays($params),
  90. 'search_query' => false,
  91. 'comments_number' => $comments_number
  92. );
  93. }
  94. public function _dia($date)
  95. {
  96. $this->registry->set_meta('title', $this->registry->site_name() . ' . Agenda . ' . fecha($date));
  97. $this->registry->set_meta('keywords', $this->registry->site('event_keywords'));
  98. $this->registry->set_meta('description', $this->registry->site('event_description'));
  99. return array(
  100. 'events' => $this->event_model->getEventsFromDate($date),
  101. 'dia' => $date
  102. );
  103. }
  104. public function _search()
  105. {
  106. $this->registry->set('section', 'eventos', 'request');
  107. $search_query = $this->input->post('searchquery', true);
  108. $params_events = array(
  109. 'start' => 0,
  110. 'limit' => 10,
  111. 'search_by' => ($search_query) ? array('title', 'content') : false,
  112. 'search' => array($search_query, $search_query),
  113. 'filter_by' => 'type',
  114. 'filter' => 'event'
  115. );
  116. $events = $this->event_model->getEventsByDays($params_events);
  117. $this->registry->set_meta('title', $this->registry->site_name() . ' . Agenda . Resultado para la bĂşsqueda: ' . $search_query);
  118. $this->registry->set_meta('keywords', $this->registry->site('event_keywords'));
  119. $this->registry->set_meta('description', $this->registry->site('event_description'));
  120. return array(
  121. 'events' => $events,
  122. 'search_query' => $search_query
  123. );
  124. }
  125. private function _save_comment()
  126. {
  127. $data = array();
  128. $data['comment'] = array(
  129. 'agenda_ID' => $this->input->post('agenda_id'),
  130. 'author' => $this->input->post('name'),
  131. 'author_email' => $this->input->post('email'),
  132. 'author_url' => $this->input->post('web'),
  133. 'author_IP' => $this->input->ip_address(),
  134. 'date_added' => date('Y-m-d H:i:s'),
  135. 'content' => $this->input->post('message'),
  136. 'approved' => 1,
  137. 'agent' => $this->input->user_agent()
  138. );
  139. if ($this->registry->user()) {
  140. $data['comment']['user_ID'] = $this->registry->user('user_ID');
  141. }
  142. $agenda = $this->event_model->getEventEvent($data['comment']["agenda_ID"]);
  143. if ($this->event_model->addAgendaComment($data)) {
  144. $this->event_model->updateNumberComment($data['comment']["agenda_ID"]);
  145. $this->session->set_flashdata('message', 'Nuevo comentario guardado correctamente.');
  146. mp_redirect('agenda/'.$agenda["slug"]);
  147. } else {
  148. $this->session->set_flashdata('message', 'Error al guardar el nuevo comentario.');
  149. mp_redirect('agenda/'.$agenda["slug"]);
  150. }
  151. }
  152. //http://www.php.net/manual/en/function.json-encode.php#95667
  153. public function _calendar()
  154. {
  155. $i = 0; // counter prevents infinite loop
  156. $cutoff = '31'; // limit on timespan (in days)
  157. $result = array();
  158. // if date is provided, use it, otherwise default to today
  159. $start_date = (!empty($start_date)) ? mysql_real_escape_string($start_date) : date('Y-m-d');
  160. $check_date = $start_date;
  161. $end_date = date('Y-m-d', strtotime("$start_date +$cutoff days")); // never retrieve more than 2 months
  162. //$result = "array (";
  163. $x=0;
  164. while ($check_date != $end_date)
  165. {
  166. // check if any incomplete todos exist on this date
  167. // if (mysql_result(mysql_query("SELECT COUNT(id) FROM " . DB_TODOS . " WHERE date_due = '$check_date'"), 0) == 0)
  168. if ($this->event_model->getEventEvents())
  169. {
  170. $result .= $check_date;
  171. $x++;
  172. }
  173. // +1 day to the check date
  174. $check_date = date('Y-m-d', strtotime("$check_date +1 day"));
  175. // break from loop if its looking like an infinite loop
  176. $i++;
  177. if ($i > $cutoff) break;
  178. }
  179. //$result .= ")";
  180. $result = explode(',', $result);
  181. //echo "AQUI";var_dump($result);
  182. // header('Content-type: application/json');
  183. // header ('Access-Control-Allow-Origin: *');
  184. //echo "llega"; var_dump($result);
  185. $arr = array ('freedate-1'=>"2012-06-29 00:00:00",'freedate-2'=>"2012-06-30 00:00:00",'freedate-3'=>"2012-07-01 00:00:00", 'freedate-1'=>"2012-06-28 00:00:00");
  186. //echo "ASI SI!";
  187. //$this->autoRender = false;
  188. $this->output
  189. ->set_content_type('application/json')
  190. ->set_output(json_encode($arr));
  191. //return json_encode($arr);
  192. //echo '(' . json_encode($result) . ')';
  193. //echo "FIN";
  194. //return '('.json_encode($result).');';
  195. //print_r($_GET['callback'].$json);
  196. //return json_encode($result);
  197. }
  198. }
  199. /* End of file agenda.php */
  200. /* Location: ./application/controllers/agenda.php */