/halogy/application/modules/events/controllers/admin.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 208 lines · 121 code · 38 blank · 49 comment · 13 complexity · 5b18854cd79097dee0e830fb8f519657 MD5 · raw file

  1. <?php
  2. /**
  3. * Halogy
  4. *
  5. * A user friendly, modular content management system for PHP 5.0
  6. * Built on CodeIgniter - http://codeigniter.com
  7. *
  8. * @package Halogy
  9. * @author Haloweb Ltd.
  10. * @copyright Copyright (c) 2008-2011, Haloweb Ltd.
  11. * @license http://halogy.com/license
  12. * @link http://halogy.com/
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. class Admin extends Controller {
  18. // set defaults
  19. var $includes_path = '/includes/admin'; // path to includes for header and footer
  20. var $redirect = '/admin/events/viewall'; // default redirect
  21. var $permissions = array();
  22. function Admin()
  23. {
  24. parent::Controller();
  25. // check user is logged in, if not send them away from this controller
  26. if (!$this->session->userdata('session_admin'))
  27. {
  28. redirect('/admin/login/'.$this->core->encode($this->uri->uri_string()));
  29. }
  30. // get permissions and redirect if they don't have access to this module
  31. if (!$this->permission->permissions)
  32. {
  33. redirect('/admin/dashboard/permissions');
  34. }
  35. if (!in_array($this->uri->segment(2), $this->permission->permissions))
  36. {
  37. redirect('/admin/dashboard/permissions');
  38. }
  39. // get siteID, if available
  40. if (defined('SITEID'))
  41. {
  42. $this->siteID = SITEID;
  43. }
  44. // load models and libs
  45. $this->load->library('tags');
  46. $this->load->model('events_model', 'events');
  47. }
  48. function index()
  49. {
  50. redirect($this->redirect);
  51. }
  52. function viewall()
  53. {
  54. // default where
  55. $where = array('siteID' => $this->siteID, 'deleted' => 0);
  56. // where event has not passed
  57. //$where['eventDate <'] = date("Y-m-d H:i:s", strtotime('-2 days', time()));
  58. // grab data and display
  59. $output = $this->core->viewall('events', $where, array('dateCreated', 'desc'));
  60. $this->load->view($this->includes_path.'/header');
  61. $this->load->view('admin/viewall',$output);
  62. $this->load->view($this->includes_path.'/footer');
  63. }
  64. function add_event()
  65. {
  66. // check permissions for this page
  67. if (!in_array('events_edit', $this->permission->permissions))
  68. {
  69. redirect('/admin/dashboard/permissions');
  70. }
  71. // required
  72. $this->core->required = array(
  73. 'eventTitle' => array('label' => 'Event title', 'rules' => 'required|trim'),
  74. 'description' => 'Description'
  75. );
  76. // get values
  77. $output['data'] = $this->core->get_values('events');
  78. if (count($_POST))
  79. {
  80. // set date
  81. $this->core->set['dateCreated'] = date("Y-m-d H:i:s");
  82. $this->core->set['tags'] = trim(strtolower($this->input->post('tags')));
  83. $this->core->set['userID'] = $this->session->userdata('userID');
  84. $this->core->set['eventDate'] = date("Y-m-d H:i:s", strtotime($this->input->post('eventDate').' 11.59PM'));
  85. $this->core->set['eventEnd'] = ($this->input->post('eventEnd')) ? date("Y-m-d H:i:s", strtotime($this->input->post('eventEnd').' 11.59PM')) : '';
  86. // update
  87. if ($this->core->update('events'))
  88. {
  89. $eventID = $this->db->insert_id();
  90. // update tags
  91. $this->events->update_tags($eventID, $this->input->post('tags'));
  92. // where to redirect to
  93. redirect($this->redirect);
  94. }
  95. }
  96. // set default date
  97. $output['data']['eventDate'] = ($this->input->post('eventDate')) ? $this->input->post('eventDate') : dateFmt(date("Y-m-d H:i:s"), 'd M Y');
  98. $output['data']['eventEnd'] = ($this->input->post('eventEnd')) ? $this->input->post('eventEnd') : dateFmt(date("Y-m-d H:i:s"), 'd M Y');
  99. // templates
  100. $this->load->view($this->includes_path.'/header');
  101. $this->load->view('admin/add_event', $output);
  102. $this->load->view($this->includes_path.'/footer');
  103. }
  104. function edit_event($eventID)
  105. {
  106. // check permissions for this page
  107. if (!in_array('events_edit', $this->permission->permissions))
  108. {
  109. redirect('/admin/dashboard/permissions');
  110. }
  111. // set object ID
  112. $objectID = array('eventID' => $eventID);
  113. // required
  114. $this->core->required = array(
  115. 'eventTitle' => array('label' => 'Event title', 'rules' => 'required|trim'),
  116. 'description' => 'Description'
  117. );
  118. // get values
  119. $output['data'] = $this->core->get_values('events', $objectID);
  120. if (count($_POST))
  121. {
  122. // set date
  123. $this->core->set['dateCreated'] = date("Y-m-d H:i:s");
  124. $this->core->set['tags'] = trim(strtolower($this->input->post('tags')));
  125. $this->core->set['eventDate'] = date("Y-m-d H:i:s", strtotime($this->input->post('eventDate').' 11.59PM'));
  126. $this->core->set['eventEnd'] = ($this->input->post('eventEnd')) ? date("Y-m-d H:i:s", strtotime($this->input->post('eventEnd').' 11.59PM')) : '';
  127. // update
  128. if ($this->core->update('events', $objectID))
  129. {
  130. // update tags
  131. $this->events->update_tags($eventID, $this->input->post('tags'));
  132. // set success message
  133. $this->session->set_flashdata('success', TRUE);
  134. // where to redirect to
  135. redirect($this->uri->uri_string());
  136. }
  137. }
  138. // set message
  139. if ($this->session->flashdata('success'))
  140. {
  141. $output['message'] = '<p>Your changes were saved.</p>';
  142. }
  143. // templates
  144. $this->load->view($this->includes_path.'/header');
  145. $this->load->view('admin/edit_event', $output);
  146. $this->load->view($this->includes_path.'/footer');
  147. }
  148. function delete_event($objectID)
  149. {
  150. // check permissions for this page
  151. if (!in_array('events_delete', $this->permission->permissions))
  152. {
  153. redirect('/admin/dashboard/permissions');
  154. }
  155. if ($this->core->soft_delete('events', array('eventID' => $objectID)))
  156. {
  157. // where to redirect to
  158. redirect($this->redirect);
  159. }
  160. }
  161. function preview()
  162. {
  163. // get parsed body
  164. $html = $this->template->parse_body($this->input->post('body'));
  165. // filter for scripts
  166. $html = preg_replace('/<script(.*)<\/script>/is', '<em>This block contained scripts, please refresh page.</em>', $html);
  167. // output
  168. $this->output->set_output($html);
  169. }
  170. }