PageRenderTime 413ms CodeModel.GetById 202ms app.highlight 9ms RepoModel.GetById 134ms app.codeStats 0ms

/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// ------------------------------------------------------------------------
 18
 19class Admin extends Controller {
 20
 21	// set defaults
 22	var $includes_path = '/includes/admin';				// path to includes for header and footer
 23	var $redirect = '/admin/events/viewall';				// default redirect
 24	var $permissions = array();
 25
 26	function Admin()
 27	{
 28		parent::Controller();
 29
 30		// check user is logged in, if not send them away from this controller
 31		if (!$this->session->userdata('session_admin'))
 32		{
 33			redirect('/admin/login/'.$this->core->encode($this->uri->uri_string()));
 34		}
 35		
 36		// get permissions and redirect if they don't have access to this module
 37		if (!$this->permission->permissions)
 38		{
 39			redirect('/admin/dashboard/permissions');
 40		}
 41		if (!in_array($this->uri->segment(2), $this->permission->permissions))
 42		{
 43			redirect('/admin/dashboard/permissions');
 44		}	
 45		
 46		// get siteID, if available
 47		if (defined('SITEID'))
 48		{
 49			$this->siteID = SITEID;
 50		}
 51		
 52		//  load models and libs
 53		$this->load->library('tags');		
 54		$this->load->model('events_model', 'events');
 55	}
 56	
 57	function index()
 58	{
 59		redirect($this->redirect);
 60	}
 61	
 62	function viewall()
 63	{
 64		// default where
 65		$where = array('siteID' => $this->siteID, 'deleted' => 0);
 66
 67		// where event has not passed
 68		//$where['eventDate <'] = date("Y-m-d H:i:s", strtotime('-2 days', time()));
 69		
 70		// grab data and display
 71		$output = $this->core->viewall('events', $where, array('dateCreated', 'desc'));
 72
 73		$this->load->view($this->includes_path.'/header');
 74		$this->load->view('admin/viewall',$output);
 75		$this->load->view($this->includes_path.'/footer');
 76	}
 77
 78	function add_event()
 79	{
 80		// check permissions for this page
 81		if (!in_array('events_edit', $this->permission->permissions))
 82		{
 83			redirect('/admin/dashboard/permissions');
 84		}
 85		
 86		// required
 87		$this->core->required = array(
 88			'eventTitle' => array('label' => 'Event title', 'rules' => 'required|trim'),
 89			'description' => 'Description'
 90		);
 91
 92		// get values
 93		$output['data'] = $this->core->get_values('events');	
 94
 95		if (count($_POST))
 96		{
 97			// set date
 98			$this->core->set['dateCreated'] = date("Y-m-d H:i:s");
 99			$this->core->set['tags'] = trim(strtolower($this->input->post('tags')));
100			$this->core->set['userID'] = $this->session->userdata('userID');
101			$this->core->set['eventDate'] = date("Y-m-d H:i:s", strtotime($this->input->post('eventDate').' 11.59PM'));
102			$this->core->set['eventEnd'] = ($this->input->post('eventEnd')) ? date("Y-m-d H:i:s", strtotime($this->input->post('eventEnd').' 11.59PM')) : '';
103			
104			// update
105			if ($this->core->update('events'))
106			{
107				$eventID = $this->db->insert_id();
108					
109				// update tags
110				$this->events->update_tags($eventID, $this->input->post('tags'));
111							
112				// where to redirect to
113				redirect($this->redirect);
114			}
115		}
116		
117		// set default date
118		$output['data']['eventDate'] = ($this->input->post('eventDate')) ? $this->input->post('eventDate') : dateFmt(date("Y-m-d H:i:s"), 'd M Y');
119		$output['data']['eventEnd'] = ($this->input->post('eventEnd')) ? $this->input->post('eventEnd') : dateFmt(date("Y-m-d H:i:s"), 'd M Y');
120
121		// templates
122		$this->load->view($this->includes_path.'/header');
123		$this->load->view('admin/add_event', $output);
124		$this->load->view($this->includes_path.'/footer');
125	}
126
127	function edit_event($eventID)
128	{
129		// check permissions for this page
130		if (!in_array('events_edit', $this->permission->permissions))
131		{
132			redirect('/admin/dashboard/permissions');
133		}
134		
135		// set object ID
136		$objectID = array('eventID' => $eventID);
137				
138		// required
139		$this->core->required = array(
140			'eventTitle' => array('label' => 'Event title', 'rules' => 'required|trim'),
141			'description' => 'Description'
142		);
143
144		// get values
145		$output['data'] = $this->core->get_values('events', $objectID);	
146
147		if (count($_POST))
148		{
149			// set date
150			$this->core->set['dateCreated'] = date("Y-m-d H:i:s");
151			$this->core->set['tags'] = trim(strtolower($this->input->post('tags')));
152			$this->core->set['eventDate'] = date("Y-m-d H:i:s", strtotime($this->input->post('eventDate').' 11.59PM'));
153			$this->core->set['eventEnd'] = ($this->input->post('eventEnd')) ? date("Y-m-d H:i:s", strtotime($this->input->post('eventEnd').' 11.59PM')) : '';
154			
155			// update
156			if ($this->core->update('events', $objectID))
157			{		
158				// update tags
159				$this->events->update_tags($eventID, $this->input->post('tags'));
160
161				// set success message
162				$this->session->set_flashdata('success', TRUE);
163				
164				// where to redirect to
165				redirect($this->uri->uri_string());
166			}
167		}
168
169		// set message
170		if ($this->session->flashdata('success'))
171		{
172			$output['message'] = '<p>Your changes were saved.</p>';
173		}
174
175		// templates
176		$this->load->view($this->includes_path.'/header');
177		$this->load->view('admin/edit_event', $output);
178		$this->load->view($this->includes_path.'/footer');
179	}
180
181	function delete_event($objectID)
182	{
183		// check permissions for this page
184		if (!in_array('events_delete', $this->permission->permissions))
185		{
186			redirect('/admin/dashboard/permissions');
187		}		
188		
189		if ($this->core->soft_delete('events', array('eventID' => $objectID)))
190		{
191			// where to redirect to
192			redirect($this->redirect);
193		}
194	}
195
196	function preview()
197	{
198		// get parsed body
199		$html = $this->template->parse_body($this->input->post('body'));
200
201		// filter for scripts
202		$html = preg_replace('/<script(.*)<\/script>/is', '<em>This block contained scripts, please refresh page.</em>', $html);
203
204		// output
205		$this->output->set_output($html);
206	}
207	
208}